##############################################################################
#                                                                            #
# IAR ARM ANSI C/C++ Compiler V4.11A/W32               20/Jul/2004  18:58:52 #
# Copyright 1999-2004 IAR Systems. All rights reserved.                      #
#                                                                            #
#    Cpu mode        =  arm                                                  #
#    Endian          =  little                                               #
#    Stack alignment =  4                                                    #
#    Source file     =  C:\medusa\eventq.c                                   #
#    Command line    =  -I "C:\Program Files\IAR Systems\Embedded Workbench  #
#                       4.0\ARM\INC\" -lc C:\medusa\Debug\List\ -la          #
#                       C:\medusa\Debug\List\ -o C:\medusa\Debug\Obj\ -s2    #
#                       --no_cse --no_unroll --no_inline --no_code_motion    #
#                       --no_tbaa --no_clustering --no_scheduling --debug    #
#                       --cpu_mode arm --endian little --cpu ARM7TDMI-S      #
#                       --stack_align 4 -e --fpu None                        #
#                       "-D_DLIB_CONFIG_FILE=C:\Program Files\IAR            #
#                       Systems\Embedded Workbench                           #
#                       4.0\ARM\LIB\dl4tpannl8n.h" C:\medusa\eventq.c        #
#    List file       =  C:\medusa\Debug\List\eventq.lst                      #
#    Object file     =  C:\medusa\Debug\Obj\eventq.r79                       #
#                                                                            #
#                                                                            #
##############################################################################

C:\medusa\eventq.c
      1          #include "archinc.h"
      2          #include "board.h"
      3          #include "eventq.h"
      4          
      5          static unsigned int maxEvents = 0;
      6          static unsigned int maxUrgentEvents = 0;
      7          
      8          static unsigned int eventsDropped = 0;
      9          static unsigned int urgentEventsDropped = 0;
     10          
     11          static unsigned int bogusEvents = 0;
     12          
     13          static unsigned char eventQueue[CONFIG_EVENTQ_MAX_EVENTS];
     14          static unsigned char urgentEventQueue[CONFIG_EVENTQ_MAX_URGENT_EVENTS];
     15          
     16          // TODO: make this into a const table to move out of data seg
     17          static eventHandler eventFuncs[CONFIG_EVENTQ_MAX_HANDLERS];
     18          
     19          static int qHead = 0;
     20          static int qTail = 0;
     21          static int qSize = 0;
     22          
     23          static int qUrgentHead = 0; 
     24          static int qUrgentTail = 0;
     25          static int qUrgentSize = 0;
     26          
     27          int eventqInit(void) 
     28          {
     29            int i;
     30            
     31            for (i=0; i<CONFIG_EVENTQ_MAX_HANDLERS; i++)
     32              eventFuncs[i] = NULL;
     33              
     34            for (i=0; i<CONFIG_EVENTQ_MAX_EVENTS; i++)
     35              eventQueue[i] = 0;
     36              
     37            for (i=0; i<CONFIG_EVENTQ_MAX_URGENT_EVENTS; i++)
     38              urgentEventQueue[i] = 0;
     39              
     40            return 0;
     41          }
     42          
     43          void eventqPut(int addEvent)
     44          {
     45            if (qSize == CONFIG_EVENTQ_MAX_EVENTS) {
     46              eventsDropped++;
     47              return;
     48              }
     49          
     50            IRQ_DISABLE();
     51            eventQueue[qHead] = (unsigned char)addEvent;
     52            circInc(qHead, 0, (CONFIG_EVENTQ_MAX_EVENTS-1));
     53            qSize++;
     54            IRQ_ENABLE();
     55            if (qSize > maxEvents) {
     56              maxEvents = qSize;
     57              }
     58          }
     59          
     60          void eventqUrgentPut(int addUrgentEvent)
     61          {
     62            if (qUrgentSize == CONFIG_EVENTQ_MAX_URGENT_EVENTS) {
     63              eventqPut(addUrgentEvent); // queue the event in the normal queue
     64              urgentEventsDropped++;
     65              return;
     66              }
     67          
     68            IRQ_DISABLE();
     69            urgentEventQueue[qUrgentHead] = (unsigned char)addUrgentEvent;
     70            circInc(qUrgentHead, 0, (CONFIG_EVENTQ_MAX_URGENT_EVENTS-1));
     71            qUrgentSize++;
     72            IRQ_ENABLE();
     73            if (qUrgentSize > maxUrgentEvents) {
     74              maxUrgentEvents = qUrgentSize;
     75              }    
     76          }
     77          
     78          #ifdef CONFIG_TOOLCHAIN_IAR
     79          #pragma inline
     80          #endif
     81          int INLINE_KEYWORD eventqGet(void)
     82          {
     83            int retVal = -1;
     84          
     85            if (qUrgentSize > 0) {
     86              retVal = (int)urgentEventQueue[qUrgentTail];
     87              circInc(qUrgentTail, 0, (CONFIG_EVENTQ_MAX_URGENT_EVENTS-1));
     88              IRQ_DISABLE();
     89              qUrgentSize--;
     90              IRQ_ENABLE();
     91              }
     92            else if (qSize > 0) {
     93              retVal = (int)eventQueue[qTail];
     94              circInc(qTail, 0, (CONFIG_EVENTQ_MAX_EVENTS-1));
     95              IRQ_DISABLE();
     96              qSize--;
     97              IRQ_ENABLE();
     98              }
     99            else {
    100              return retVal;
    101              }
    102          
    103            return retVal;
    104          }
    105           
    106          int eventqRegisterHandler(int evType, eventHandler handler)
    107          {
    108            if ((evType < 0) || (evType >= CONFIG_EVENTQ_MAX_HANDLERS))
    109              return -1;
    110          
    111            eventFuncs[evType] = handler;
    112              
    113            return 0;
    114          }
    115          
    116          int eventqGetHandler(int evType, eventHandler *pHandler)
    117          {
    118            if ((evType < 0) || (evType >= CONFIG_EVENTQ_MAX_HANDLERS))
    119              return -1;
    120          
    121            if (pHandler == NULL)
    122              return -1;
    123            
    124            *pHandler = eventFuncs[evType];
    125            
    126            return 0;
    127          }
    128          
    129          // the event queue dispatcher
    130          
    131          void eventqDispatch(void)
    132          {
    133            int currentEvent = eventqGet();
    134          
    135            while (currentEvent != -1) {
    136          #ifdef CONFIG_EVENTQ_BUSY_LED
    137              boardSetBusyLed(true);
    138          #endif
    139              // dispatch event
    140              if ((currentEvent >=0) && (currentEvent < CONFIG_EVENTQ_MAX_HANDLERS)) {
    141                if (eventFuncs[currentEvent] != NULL) {
    142                  (eventFuncs[currentEvent])();
    143                  }
    144                }
    145              else {
    146                bogusEvents++;
    147              }
    148              
    149              currentEvent = eventqGet();
    150              }
    151          #ifdef CONFIG_EVENTQ_BUSY_LED
    152            boardSetBusyLed(false);
    153          #endif
    154          
    155          } // eventqDispatch()

   Maximum stack usage in bytes:

     Function              CSTACK
     --------              ------
     eventqDispatch            8
     eventqGet                 4
     eventqGetHandler          0
     eventqInit                0
     eventqPut                 4
     eventqRegisterHandler     0
     eventqUrgentPut           8


   Segment part sizes:

     Function/Label        Bytes
     --------------        -----
     maxEvents                4
     maxUrgentEvents          4
     eventsDropped            4
     urgentEventsDropped      4
     bogusEvents              4
     eventQueue              64
     urgentEventQueue        16
     eventFuncs              48
     qHead                    4
     qTail                    4
     qSize                    4
     qUrgentHead              4
     qUrgentTail              4
     qUrgentSize              4
     eventqInit             124
     eventqPut              212
     eventqUrgentPut        224
     eventqGet              308
     eventqRegisterHandler   52
     eventqGetHandler        72
     eventqDispatch         144
     ??DataTable3             4
     ??DataTable4             4
     ??DataTable8             4
      Others                 60

 
 1 196 bytes in segment CODE
   172 bytes in segment DATA_Z
    12 bytes in segment INITTAB
 
 840 bytes of CODE memory (+ 368 bytes shared)
 172 bytes of DATA memory

Errors: none
Warnings: none
