?? executive.c
字號:
/***********************************************************
Module Name: Executive.c
Module Date: 04/12/2004
Module Auth: John Orlando
Copyright (c) 2004 John Orlando All Rights Reserved
Description: This file is responsible for implementing a
minimalist event dispatcher. It keeps track of an event
fifo that waits for new events to come in, and dispatches
them to any entities that care about them.
***********************************************************/
/* 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_run
Function Description: This function is responsible for
running the main control loop. The control loop is
based on checking both the fast-event bitmask (for high
priority events) and the event FIFO to determine if an
event needs to be handled. The event is then dispatched
to the appropriate handler.
Inputs: none
Outputs: 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...this
needs to be processed as quickly as possible */
if (fastEventBitmask & FEV_ACQUIRE_LINE_COMPLETE)
{
fastEventBitmask &= ~FEV_ACQUIRE_LINE_COMPLETE;
FrameMgr_processLine();
/* also check if serial data needs to be sent
out through UIMgr */
UIMgr_transmitPendingData();
/* we can't just call acquire line again here,
since we don't know if we need to acquire another
line or not (it depends on the FrameMgr to figure
this out) */
}
if (fastEventBitmask & FEV_PROCESS_LINE_COMPLETE)
{
fastEventBitmask &= ~FEV_PROCESS_LINE_COMPLETE;
FrameMgr_acquireLine();
}
}
else if (IS_DATA_IN_EVENT_FIFO() == TRUE)
{
DISABLE_INTS();
eventGenerated = Exec_readEventFifo();
ENABLE_INTS();
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;
}
}
}
}
/***********************************************************
Function Name: Exec_readEventFifo
Function Description: This function is responsible for
reading a single event out of the event fifo.
Inputs: none
Outputs: 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_writeEventFifo
Function Description: This function is responsible for
writing a single event to the event fifo and
updating the appropriate pointers.
Inputs: data - the byte to write to the Fifo
Outputs: 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();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -