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: Executive.cModule Date: 04/12/2004Module Auth: John OrlandoDescription: This file is responsible for implementing aminimalist event dispatcher. It keeps track of an eventfifo that waits for new events to come in, and dispatchesthem to any entities that care about them.Revision History:Date Rel Ver. Notes4/10/2004 0.1 Module created6/30/2004 1.0 Initial release for Circuit Cellarcontest.1/16/2005 1.4 Fixed issue where the interrupts weren'tbeing turned off when the fastEventBitmaskwas being accessed. Also removed redundantinterrupt masking when accessing themain event fifo. Also fixed issue wherethe main event fifo wasn't being checkedfor events if an event was pending inthe fast event fifo.***********************************************************//* Includes */#include <stdlib.h>#include "CommonDefs.h"#include "Executive.h"#include "FrameMgr.h"#include "CamInterface.h"#include "UIMgr.h"#include "UartInterface.h"#include "CamConfig.h"#include "Utility.h"/* Local Variables */unsigned char Exec_eventFifo[EXEC_EVENT_FIFO_SIZE];unsigned char Exec_eventFifoHead=0;unsigned char Exec_eventFifoTail=0;/* Local Function Definitions */static unsigned char Exec_readEventFifo(void);/* Local Structures and Typedefs *//* Extern Variables *//* This bitmask holds events that need to be processed as fast as possible */unsigned char fastEventBitmask = 0x00;/* Definitions */#define IS_DATA_IN_EVENT_FIFO() (!(Exec_eventFifoHead == Exec_eventFifoTail))/***********************************************************Function Name: Exec_runFunction Description: This function is responsible forrunning the main control loop. The control loop isbased on checking both the fast-event bitmask (for highpriority events) and the event FIFO to determine if anevent needs to be handled. The event is then dispatchedto the appropriate handler.Inputs: noneOutputs: none***********************************************************/void Exec_run(void){unsigned char eventGenerated;while(1){if (fastEventBitmask){/* an event needing fast processing has been received *//* a received line needs to be processed...thisneeds to be processed as quickly as possible */if (fastEventBitmask & FEV_ACQUIRE_LINE_COMPLETE){DISABLE_INTS();fastEventBitmask &= ~FEV_ACQUIRE_LINE_COMPLETE;ENABLE_INTS();FrameMgr_processLine();/* also check if serial data needs to be sentout through UIMgr */UIMgr_transmitPendingData();/* we can't just call acquire line again here,since we don't know if we need to acquire anotherline or not (it depends on the FrameMgr to figurethis out) */}if (fastEventBitmask & FEV_PROCESS_LINE_COMPLETE){DISABLE_INTS();fastEventBitmask &= ~FEV_PROCESS_LINE_COMPLETE;ENABLE_INTS();FrameMgr_acquireLine();}}if (IS_DATA_IN_EVENT_FIFO() == TRUE){eventGenerated = Exec_readEventFifo();switch(eventGenerated){case (EV_DUMP_FRAME):FrameMgr_dispatchEvent(eventGenerated);break;case (EV_ENABLE_TRACKING):FrameMgr_dispatchEvent(eventGenerated);break;case (EV_DISABLE_TRACKING):FrameMgr_dispatchEvent(eventGenerated);break;case (EV_ACQUIRE_LINE_COMPLETE):FrameMgr_dispatchEvent(eventGenerated);UIMgr_dispatchEvent(eventGenerated);break;case (EV_ACQUIRE_FRAME_COMPLETE):FrameMgr_dispatchEvent(eventGenerated);break;case (EV_PROCESS_LINE_COMPLETE):FrameMgr_dispatchEvent(eventGenerated);break;case (EV_PROCESS_FRAME_COMPLETE):FrameMgr_dispatchEvent(eventGenerated);break;case (EV_SERIAL_DATA_RECEIVED):UIMgr_dispatchEvent(eventGenerated);FrameMgr_dispatchEvent(eventGenerated);break;case (EV_SERIAL_DATA_PENDING_TX):UIMgr_dispatchEvent(eventGenerated);break;default:break;}}/* toggle the debug line */}}/***********************************************************Function Name: Exec_readEventFifoFunction Description: This function is responsible forreading a single event out of the event fifo.Inputs: noneOutputs: unsigned char-the data read***********************************************************/static unsigned char Exec_readEventFifo(void){unsigned char dataByte, tmpTail;DISABLE_INTS();/* just return the current tail from the tx fifo */dataByte = Exec_eventFifo[Exec_eventFifoTail];tmpTail = (Exec_eventFifoTail+1) & (EXEC_EVENT_FIFO_MASK);Exec_eventFifoTail = tmpTail;ENABLE_INTS();return(dataByte);}/***********************************************************Function Name: Exec_writeEventFifoFunction Description: This function is responsible forwriting a single event to the event fifo andupdating the appropriate pointers.Inputs: data - the byte to write to the FifoOutputs: none***********************************************************/void Exec_writeEventFifo(unsigned char event){unsigned char tmpHead;DISABLE_INTS();Exec_eventFifo[Exec_eventFifoHead] = event;/* now move the head up */tmpHead = (Exec_eventFifoHead + 1) & (EXEC_EVENT_FIFO_MASK);Exec_eventFifoHead = tmpHead;ENABLE_INTS();}