The SPARK Real-time Kernel
by Anatoly Kotlarsky 

Listing One
TASKS
{
        TASK_MAIN_MENU: taskMainMenu
        TASK_HELP: taskHelp
        TASK_LIST_DECODERS: taskListDecoders
        TASK_ENABLE_DECODER: taskEnableDecoder
        TASK_DISABLE_DECODER: taskDisableDecoder
        TASK_DECODE: taskDecode
        TASK_RUN_SCANNER: taskRunScanner
} 
STATES
{
        STATE_POWER_UP
        STATE_IDLE
        EVENTS
        {
                SYSEVENT_VIDEOINP_REQUEST: evRunScanner
        }
        STATE_GET_VIDEO
        EVENTS
        {
                SYSEVENT_VIDEOINP_REQUEST: evRerunScanner
        }
        STATE_DECODE
        EVENTS
        {
                SYSEVENT_VIDEOINP_REQUEST: evRerunScanner
                SYSEVENT_READ_TIMEOUT: evScannerReadTimeOut
        }
        STATE_MMENU
}
SYSTEM_WIDE_EVENTS
{
        EVENT_POWER_UP: evPowerUp
        SYSEVENT_NOWAIT_IN: evNoWaitIn
        SYSEVENT_BREAK: evBreak
}


Listing Two
#ifndef SYSEVENT_H
#define SYSEVENT_H

#include "spark.h"
#define FIRST_SYSEVENT        LAST_SPARK_SYSTEM_EVENT + 1
enum {
        SYSEVENT_NOWAIT_IN = FIRST_SYSEVENT,
        SYSEVENT_BREAK,
        SYSEVENT_VIDEOINP_REQUEST,
        SYSEVENT_READ_TIMEOUT, 
        LAST_SYSEVENT = SYSEVENT_READ_TIMEOUT
};
#endif /* SYSEVENT_H */


Listing Three
#include "spark.h"
#include "sparkhks.h"
#include "id4100.h"

/*****************************************************************\
 EVENT_POWER_UP event-function.
\*****************************************************************/
int
evPowerUp(void * par)
{
        sparkSetAppState(STATE_POWER_UP);
        ID4100SystemInit();
        sparkKill(0);
        return 1;
}
/*****************************************************************\
   This is an override of the sparkIdle() SPARK hook.
\*****************************************************************/
void
sparkIdle(int first_call)
{
        if (first_call)
        {
                sparkSetAppState(STATE_IDLE);
        }
}
/*****************************************************************\
   This function handles the "Video Input Request" event when the
   system is in the idle loop.
\*****************************************************************/
int
evRunScanner(void * par)
{
        sparkExec(TASK_RUN_SCANNER, 0, (char *) 0);
        return 1;
}
EXIT_CODE
taskRunScanner(char * cmd_line)
{
        sparkSetAppState(STATE_GET_VIDEO);
        ID4100GetVideo();
        sparkExec(TASK_DECODE, 0, (char *) 0);
        return 0;
}
/*****************************************************************\
   This function handles the "Video Input Request" event when the
   system is busy decoding the previously entered data.
\*****************************************************************/
int
evRerunScanner(void * par)
{
        ID4100RTEMsg();
        sparkExec(TASK_RUN_SCANNER, 0, (char *) 0);
        return 1;
}
/*****************************************************************\
   This function handles the "Read Time Out" event when the
   system is decoding the previously entered data.
\*****************************************************************/
int
evScannerReadTimeOut(void * par)
{
        ID4100NoReadMsg();
        sparkKill(ERR_READ_TIMEOUT);
        return 1;
}






1


