Blame | Last modification | View Log | Download
/*Copyright (C) 2004 John OrlandoAVRcam: a small real-time image processing engine.This program is free software; you can redistribute it and/ormodify it under the terms of the GNU General PublicLicense as published by the Free Software Foundation; eitherversion 2 of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General PublicLicense along with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USAFor more information on the AVRcam, please contact:john@jrobot.netor go to www.jrobot.net for more details regarding the system.*//***********************************************************Module Name: UartInterface.cModule Date: 04/10/2004Module Auth: John OrlandoDescription: This module is responsible for providing aninterface to the UART hardware available on the mega8.This interface is an interrupt-driven interface.Revision History:Date Rel Ver. Notes4/10/2004 0.1 Module created6/30/2004 1.0 Initial release for Circuit Cellarcontest.11/15/2004 1.2 Updated UART baud rate regs so thatit runs at 115.2 kbps when the inputcrystal is at 17.7 MHz (which is thespeed of the OV6620's crystal).1/16/2005 1.4 Moved the serial received ISR tothis file, instead of having itin its own UartInterfaceAsm.S filewritten in assembly.***********************************************************//* Includes */#include <avr/io.h>#include <avr/interrupt.h>#include <avr/signal.h>#include "CommonDefs.h"#include "UartInterface.h"#include "UIMgr.h"#include "Executive.h"/* Local Variables *//* Local Structures and Typedefs *//* Extern Variables *//* Definitions *//***********************************************************Function Name: UartInt_initFunction Description: This function is responsible forinitializing the UART interface on the mega8. Thisinterface is set to communicate at 115.2 Kbps, with an8N1 protocol.Inputs: noneOutputs: none***********************************************************/void UartInt_init(void){/* set up the baud rate registers so the UART will operateat 115.2 Kbps */UBRRH = 0x00;#ifdef NO_CRYSTALUBRRL = 18; /* 18 for double clocking at 115.2 kbps */#elseUBRRL = 0x08; /* for 16 MHz crystal at 115.2 kbps */#endif/* enable the tx and rx capabilities of the UART...as wellas the receive complete interrupt */UCSRB = (1<<RXCIE)|(1<<RXEN)|(1<<TXEN);/* set up the control registers so the UART works at 8N1 */UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);#ifdef NO_CRYSTAL/* set the baud rate to use the double-speed */UCSRA = (1<<U2X);#endif}/***********************************************************Function Name: UartInt_txByteFunction Description: This function is responsible fortransmitting a single byte on the uart.Inputs: txByte - the byte to sendOutputs: noneNOTES: When the TX UDRE (data register empty) is set, thereis puposefully no interrupt...thus, to send a string ofdata out, the calling routine needs to hold up the entireapplication while this takes place (or just send onebyte at a time at strtegically timed intervals, likethe stats data is sent out :-)***********************************************************/void UartInt_txByte(unsigned char txByte){/* Wait for empty transmit buffer */while ( !( UCSRA & (1<<UDRE)) );/* Put data into buffer, sends the data */UDR = txByte;}/***********************************************************Function Name: SIG_UART_RECV ISRFunction Description: This function is responsible forhandling the interrupt caused when a data byte isreceived by the UART.Inputs: noneOutputs: noneNOTES: This function was originally written in assembly,but moved over to C when the setting of the "T" bit atthe end of the routine was no longer necessary (thistheoretically allowed the AVRcam to respond to serialbytes in the middle of tracking or dumping a frame.But it wasn't really needed, and understanding the Cis easier :-)***********************************************************/SIGNAL(SIG_UART_RECV){unsigned char tmpHead;/* read the data byte, put it in the serial queue, andpost the event */UIMgr_rxFifo[UIMgr_rxFifoHead] = UDR;/* now move the head up */tmpHead = (UIMgr_rxFifoHead + 1) & (UI_MGR_RX_FIFO_MASK);UIMgr_rxFifoHead = tmpHead;/* write the serial received event to the event fifo */Exec_eventFifo[Exec_eventFifoHead] = EV_SERIAL_DATA_RECEIVED;/* now move the head up */tmpHead = (Exec_eventFifoHead + 1) & (EXEC_EVENT_FIFO_MASK);Exec_eventFifoHead = tmpHead;}