Beispiel #1
0
/*********************************************************************
 * @fn      Util_constructClock
 *
 * @brief   Initialize a TIRTOS Clock instance.
 *
 * @param   pClock        - pointer to clock instance structure.
 * @param   clockCB       - callback function upon clock expiration.
 * @param   clockDuration - longevity of clock timer in milliseconds
 * @param   clockPeriod   - if set to a value other than 0, the first
 *                          expiry is determined by clockDuration.  All
 *                          subsequent expiries use the clockPeriod value.
 * @param   startFlag     - TRUE to start immediately, FALSE to wait.
 * @param   arg           - argument passed to callback function.
 *
 * @return  Clock_Handle  - a handle to the clock instance.
 */
Clock_Handle Util_constructClock(Clock_Struct *pClock,
                                 Clock_FuncPtr clockCB,
                                 uint32_t clockDuration,
                                 uint32_t clockPeriod,
                                 uint8_t startFlag,
                                 UArg arg)
{
  Clock_Params clockParams;

  // Convert clockDuration in milliseconds to ticks.
  uint32_t clockTicks = clockDuration * (1000 / Clock_tickPeriod);

  // Setup parameters.
  Clock_Params_init(&clockParams);

  // Setup argument.
  clockParams.arg = arg;

  // If period is 0, this is a one-shot timer.
  clockParams.period = clockPeriod * (1000 / Clock_tickPeriod);

  // Starts immediately after construction if true, otherwise wait for a call
  // to start.
  clockParams.startFlag = startFlag;

  // Initialize clock instance.
  Clock_construct(pClock, clockCB, clockTicks, &clockParams);

  return Clock_handle(pClock);
}
Beispiel #2
0
/*
 *  ======== main ========
 */
Void main()
{       
    Swi_Params swiParams;
    Task_Params taskParams;
    Clock_Params clkParams;

    Swi_Params_init(&swiParams);
    swiParams.arg0 = 1;
    swiParams.arg1 = 0;
    swiParams.priority = 2;
    swiParams.trigger = 0;

    swi0 = Swi_create(swi0Fxn, &swiParams, NULL);

    swiParams.arg0 = 2;
    swiParams.arg1 = 0;
    swiParams.priority = 1;
    swiParams.trigger = 3;

    swi1 = Swi_create(swi1Fxn, &swiParams, NULL);

    Task_Params_init(&taskParams);
    taskParams.priority = 1;
    Task_create (tsk0Fxn, &taskParams, NULL);

    Clock_Params_init(&clkParams);
    clkParams.startFlag = TRUE;
    Clock_create(clk0Fxn, 2, &clkParams, NULL);

    sem0 = Semaphore_create(0, NULL, NULL);

    BIOS_start();
}
void lcdSetup() {
    Semaphore_Params mySemParams;
    Clock_Params myClkParams;

    /* Use pull up on button inputs to save power */  
    pinMode(PUSH1, INPUT_PULLUP);
    pinMode(PUSH2, INPUT_PULLUP);

    /* Both buttons post the semaphore */
    attachInterrupt(PUSH1, button1Interrupt, FALLING);
    attachInterrupt(PUSH2, button2Interrupt, FALLING);

    /* set LCD's EXTMODE low (sadly this is the UART Rx pin too) */
    digitalWrite(12, 0);

    /* turn off MPU power */
    digitalWrite(22, 0);

    /* put flash into power down mode */
    SPI.begin();
    SPI.transfer((uint8_t)32, 0xb9);
    SPI.end();

    /* power down the tmp007 */
    Wire.begin();
    tmp007.begin(TMP007_CFG_1SAMPLE);
    tmp007.write16(TMP007_CONFIG, TMP007_CFG_ALERTEN | TMP007_CFG_TRANSC | TMP007_CFG_1SAMPLE);
    Wire.end();
  
    Semaphore_Params_init(&mySemParams);

    mySem = Semaphore_create(0, &mySemParams, NULL);
  
    Clock_Params_init(&myClkParams);

    myClkParams.period = 100000; /* one second */
    myClkParams.startFlag = true;

    /* comment out for steady state power testing */
    Clock_create(myClkFunc, 0, &myClkParams, NULL); 
  
    /* set to 1970 plus 45 years */
    Seconds_set(secondsOffset);
  
    myScreen.begin(); /* also calls SPI.begin() */

    myScreen.setFont(1);
    myScreen.text(10, 10, "Hello!");
    myScreen.flush(); 

    SPI.end(); /* to save power */

    /* Say Hello for 1 second */
    delay(1000);

    SPI.begin();
    myScreen.clear();
    SPI.end(); /* to save Power */
}
/*
 *  ======== main ========
 */
Int main()
{       
    Clock_Params     clkParams;
    Task_Params      tskParams;
    Mailbox_Params   mbxParams;
    Semaphore_Params semParams;
    
    /* Create a one-shot Clock Instance with timeout = 5 system time units */
    Clock_Params_init(&clkParams);
    clkParams.startFlag = TRUE;
    clk1 = Clock_create(clk0Fxn, 5, &clkParams, NULL);
    
    /* Create an one-shot Clock Instance with timeout = 10 system time units */
    Clock_Params_init(&clkParams);
    clkParams.startFlag = TRUE;
    clk2 = Clock_create(clk1Fxn, 10, &clkParams, NULL);

    /* create an Event Instance */
    evt = Event_create(NULL, NULL);
    
    /* create a Semaphore Instance */
    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_BINARY;
    semParams.event = evt;
    semParams.eventId = Event_Id_01;
    sem = Semaphore_create(0, &semParams, NULL);

    /* create a Mailbox Instance */
    Mailbox_Params_init(&mbxParams);
    mbxParams.readerEvent = evt;
    mbxParams.readerEventId = Event_Id_02;
    mbx = Mailbox_create(sizeof(MsgObj), 2, &mbxParams, NULL);

    /* create a writer task */
    Task_Params_init(&tskParams);
    tskParams.priority = 1;
    tskParams.arg0 = (UArg) mbx;
    Task_create(writer, &tskParams, NULL);

    /* create a reader task */
    Task_create(reader, &tskParams, NULL);

    BIOS_start();    /* does not return */
    return(0);
}
Beispiel #5
0
int main(void)
{
    /* Call board init functions. */
    Board_initGeneral();
    Board_initGPIO();
    // Board_initI2C();
    // Board_initSDSPI();
    // Board_initSPI();
    // Board_initUART();
    // Board_initWatchdog();

    Clock_Params clockParams;
    Clock_Handle myClock;
    Error_Block eb;
    Task_Handle task0;

    Task_Params taskParams;
    Task_Params_init(&taskParams);

    int j;
    for(j=0; j<17; j++) {
    	buff1[j] = ' ';
    	buff2[j] = ' ';
    }
    Error_init(&eb);
    Clock_Params_init(&clockParams);
    clockParams.period = 100;
    clockParams.startFlag = TRUE;
    myClock = Clock_create(LCD_print, 10, &clockParams, &eb);
    if(myClock == 0)
    {
    	System_abort("F****n clock");
    }

    LCD_init();

    task0 = Task_create(heartBeatFxn, &taskParams, &eb);
   // sample_screen();F
    /* Turn on user LED */
    GPIO_write(Board_LED0, Board_LED_ON);



    System_printf("Starting the example\nSystem provider is set to SysMin. "
                  "Halt the target to view any SysMin contents in ROV.\n");

    //GPIO_write(4,1);
    /* SysMin will only print to the console when you call flush or exit */
    System_flush();

    /* Start BIOS */
    BIOS_start();

    return (0);
}
/*
 *  ======== PowerCC3200_initPolicy ========
 */
void PowerCC3200_initPolicy()
{
    Clock_Params clockParams;

    /* construct Clock object */
    Clock_Params_init(&clockParams);
    clockParams.period = 0;
    clockParams.startFlag = FALSE;
    Clock_construct(&clockObj, &PowerCC3200_dummyClockFunc,
                    0, &clockParams);
}
Beispiel #7
0
/*
 *  ======== Task_sleep ========
 */
Void Task_sleep(UInt timeout)
{
    Task_PendElem elem;
    UInt hwiKey, tskKey;
    Clock_Struct clockStruct;

    if (timeout == BIOS_NO_WAIT) {
        return;
    }

    Assert_isTrue((timeout != BIOS_WAIT_FOREVER), Task_A_badTimeout);

    /* add Clock event if timeout is not FOREVER */
    if (BIOS_clockEnabled) {
        Clock_Params clockParams;
        Clock_Params_init(&clockParams);
        clockParams.arg = (UArg)&elem;
        clockParams.startFlag = FALSE;  /* will start when necessary, thankyou */
        Clock_construct(&clockStruct, (Clock_FuncPtr)Task_sleepTimeout, timeout, &clockParams);
        elem.clock = Clock_handle(&clockStruct);
    }

    hwiKey = Hwi_disable();

    /* lock scheduler */
    tskKey = Task_disable();

    /* get task handle and block tsk */
    elem.task = Task_self();

    Task_blockI(elem.task);

    if (BIOS_clockEnabled) {
        Clock_startI(elem.clock);
    }

    /* Only needed for Task_delete() */
    Queue_elemClear(&elem.qElem);

    elem.task->pendElem = (Ptr)(&elem);

    Hwi_restore(hwiKey);

    Log_write3(Task_LM_sleep, (UArg)elem.task, (UArg)elem.task->fxn, 
               (UArg)timeout);

    Task_restore(tskKey);       /* the calling task will block here */

    /* deconstruct Clock if appropriate */
    if (BIOS_clockEnabled) {
        Clock_destruct(Clock_struct(elem.clock));
    }
}
void OneMsTaskTimer::start(uint32_t timer_index) {
    Clock_Params clockParams;
    Error_Block eb;
    Error_init(&eb);

    if (myClock == NULL){
        Clock_Params_init(&clockParams);
        clockParams.period = (uint32_t)1000 / (uint64_t)Clock_tickPeriod;
        clockParams.startFlag = FALSE;
        clockParams.arg = (UArg)0x5555;

		myClock = Clock_create(OneMsTaskTimer_int, clockParams.period, &clockParams, &eb);
	}
    Clock_start(myClock);
}
static Int32 IpcFramesInLink_createPrdObj(IpcFramesInLink_Obj * pObj)
{
    Clock_Params clockParams;

    Clock_Params_init(&clockParams);
    clockParams.arg = (UArg) pObj;
    UTILS_assert(pObj->prd.clkHandle == NULL);

    Clock_construct(&(pObj->prd.clkStruct),
                    IpcFramesInLink_prdCalloutFcn, 1, &clockParams);

    pObj->prd.clkHandle = Clock_handle(&pObj->prd.clkStruct);
    pObj->prd.clkStarted = FALSE;

    return IPC_FRAMES_IN_LINK_S_SUCCESS;

}
/*********************************************************************
 * @fn      initBuzzTimer
 *
 * @brief   Set up timer for buzz generation (use PWM when RTOS driver in place)
 *
 * @param   none
 *
 * @return  none
 */
static void initBuzzTimer(void)
{
  Clock_Params clockParams;
  
  // Setup parameters.
  Clock_Params_init(&clockParams);
  
  // Setup argument.
  clockParams.arg = 0;
  
  // Period
  clockParams.period = BUZZER_PERIOD;
  
  // Do not start until called.
  clockParams.startFlag = false;
  
  // Initialize clock instance.
  Clock_construct(&buzzClockStruct, timerIsr, BUZZER_PERIOD, &clockParams);
  buzzClockHandle = Clock_handle(&buzzClockStruct);
}
Beispiel #11
0
void Clock::begin(void (*ClockFunction)(void), uint32_t ClockTimeOut_ms, uint32_t ClockPeriod_ms)
{
    Error_Block eb;
    Error_init(&eb);

    Clock_Params_init(&ClockParams);
    ClockParams.startFlag = false; // Requires Clock_start

    // ClockParams.period = microsecondsToClockCycles(ClockPeriod_ms); // ms to be translated into ticks
    // ClockHandle = Clock_create( (Clock_FuncPtr)ClockFunction, microsecondsToClockCycles(ClockTimeOut_ms), &ClockParams, &eb);

    // Surprisingly, period already defined in ms for ClockParams.period andClockTimeOut_ms
    ClockParams.period = ClockPeriod_ms;
    ClockHandle = Clock_create( (Clock_FuncPtr)ClockFunction, ClockTimeOut_ms, &ClockParams, &eb);

    if (ClockHandle == NULL)
    {
        // Serial.println("*** Clock create failed");
        System_abort("Clock create failed");
    }
}
Beispiel #12
0
/*
 *  ======== main ========
 */
Void main()
{
    Clock_Handle clk2;       
    Clock_Params clkParams;

    /* Create a periodic Clock Instance with period = 5 system time units */
    Clock_Params_init(&clkParams);
    clkParams.period = 5;
    clkParams.startFlag = TRUE;
    clkParams.arg = (UArg)0x5555;
    Clock_create(clk0Fxn, 5, &clkParams, NULL);
    
    /* Create an one-shot Clock Instance with timeout = 11 system time units */
    clkParams.period = 0;
    clkParams.startFlag = FALSE;
    clkParams.arg = (UArg)0x6666;
    clk2 = Clock_create(clk1Fxn, 11, &clkParams, NULL);

    Clock_start(clk2);
                
    BIOS_start();
}
Beispiel #13
0
/*
 *  ======== main ========
 */
int main(void)
{
    Clock_Handle clkHandle;
    Clock_Params clkParams;
    
    /* Call board init functions */
    Board_initGeneral();
    Board_initGPIO();
    Board_initUART();

    /* Turn on user LED */
    GPIO_write(Board_LED0, Board_LED_OFF);
    GPIO_write(Board_LED1, Board_LED_ON);   
    
    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);

    System_printf("Hello World\n");
    
    /* SysMin will only print to the console when you call flush or exit */
    System_flush();

    /* Create a periodic Clock Instance with period = 5 system time units */
    Clock_Params_init(&clkParams);
    clkParams.period = 1000;
    clkParams.startFlag = TRUE;
    Clock_create(clk0Fxn, 5, &clkParams, NULL);

    /* Create an one-shot Clock Instance with timeout = 11 system time units */
    clkParams.period = 0;
    clkParams.startFlag = FALSE;
    clkHandle = Clock_create(clk1Fxn, 11, &clkParams, NULL);
    Clock_start(clkHandle);

    /* Start BIOS */
    BIOS_start();

    return (0);
}
/**************************************************************************************************
 * @fn          macBackoffTimerInit
 *
 * @brief       Intializes backoff timer.
 *
 * @param       none
 *
 * @return      none
 **************************************************************************************************
 */
MAC_INTERNAL_API void macBackoffTimerInit(void)
{
  macPrevPeriodRatCount = macBackoffTimerRollover = 0;

  /* backoffTimerTrigger has to be set to maximum possible value of
   * macBackoffTimerRollover value initially.
   * Otherwise, incorrect backoffTimerTrigger value shall be compared
   * all the time in macBackoffTimerUpdateWakeup() function, casting
   * incorrect vote.
   */
  backoffTimerTrigger = MAC_BACKOFF_TIMER_DEFAULT_NONBEACON_ROLLOVER;

  MAC_RADIO_CLEAR_BACKOFF_COUNT();
#if defined USE_ICALL || defined OSAL_PORT2TIRTOS
  // Clear events
  macBackoffTimerEvents = 0;

#ifdef USE_ICALL
  // Register hook function to handle events.
  if (!osal_eventloop_hook)
  {
    /* Don't overwrite if the hook is already set up.
     * Note that the hook might have been set up to perform other things
     * as well in which case the other hook function has to call
     * macBackoffTimerEventHandler.
     */
    osal_eventloop_hook = macBackoffTimerEventHandler;
  }
#endif /* USE_ICALL */

  macBackoffTimerImpending = FALSE;

#ifdef USE_ICALL
  /* Start timer just to initialize the timer ID to reuse in the module.
   * This also serves the purpose of allocating resources upfront,
   * in order to prevent a case of running out of timer resource
   * when the timer has to be started.
   * Note that macBackoffTimerSetRollover() may trigger setting timer
   * and hence the timer set up must happen before macBackoffTimerSetRollover()
   * call. */
  if (ICall_setTimer(1, macBackoffTimerICallTimerCback, NULL,
                     &macBackoffTimerICallTimerID) != ICALL_ERRNO_SUCCESS)
  {
    MAC_ASSERT(0);
  }
#endif /* USE_ICALL */
#ifdef OSAL_PORT2TIRTOS
  if (!macBackoffWakeupClock)
  {
    /* Creates a wakeup clock */
    Clock_Params params;
    Clock_Params_init(&params);
    params.startFlag = FALSE;
    params.period = 0;
    macBackoffWakeupClock =
      Clock_create((Clock_FuncPtr) macBackoffTimerICallTimerCback,
                   1, &params, NULL);
    MAC_ASSERT(macBackoffWakeupClock);
    /* No need to stop clock, the clock event will reprogram next wake time */
  }
#endif /* OSAL_PORT2TIRTOS */

  /* Note that macPwrVote() is called done from macBackoffTimerSetRollover()
   * call and hence there is no need to make the call here. */
#endif /* defined USE_ICALL || defined OSAL_PORT2TIRTOS */

  macBackoffTimerSetRollover(MAC_BACKOFF_TIMER_DEFAULT_NONBEACON_ROLLOVER);

  /* Since interrupt disable/enable mechanism is not implemented for backoff
   * timer trigger interrupt for CC26xx, comparator value has to be set
   * so that the timer trigger interrupt is not triggered.
   * See comment inside macBackoffTimerCancelTrigger() for relevant
   * information */
  MAC_RADIO_BACKOFF_SET_COMPARE(backoffTimerTrigger);
}
Beispiel #15
0
/*
 *  ======== Semaphore_pend ========
 */
Bool Semaphore_pend(Semaphore_Object *sem, UInt timeout)
{
    UInt hwiKey, tskKey;
    Semaphore_PendElem elem;
    Queue_Handle pendQ;
    Clock_Struct clockStruct;

    Log_write3(Semaphore_LM_pend, (IArg)sem, (UArg)sem->count, (IArg)((Int)timeout));

    /*
     *  Consider fast path check for count != 0 here!!!
     */

    /* 
     *  elem is filled in entirely before interrupts are disabled.
     *  This significantly reduces latency.
     */

    /* add Clock event if timeout is not FOREVER nor NO_WAIT */
    if (BIOS_clockEnabled
            && (timeout != BIOS_WAIT_FOREVER) 
            && (timeout != BIOS_NO_WAIT)) {
        Clock_Params clockParams;
        Clock_Params_init(&clockParams);
        clockParams.arg = (UArg)&elem;
        clockParams.startFlag = FALSE;  /* will start when necessary, thankyou */
        Clock_construct(&clockStruct, (Clock_FuncPtr)Semaphore_pendTimeout, 
                                        timeout, &clockParams);
        elem.tpElem.clock = Clock_handle(&clockStruct);
        elem.pendState = Semaphore_PendState_CLOCK_WAIT;
    }
    else {
        elem.tpElem.clock = NULL;
        elem.pendState = Semaphore_PendState_WAIT_FOREVER;
    }

    pendQ = Semaphore_Instance_State_pendQ(sem);

    hwiKey = Hwi_disable();

    /* check semaphore count */
    if (sem->count == 0) {

        if (timeout == BIOS_NO_WAIT) {
            Hwi_restore(hwiKey);
            return (FALSE);
        }

        Assert_isTrue((BIOS_getThreadType() == BIOS_ThreadType_Task),
                        Semaphore_A_badContext);

        /* lock task scheduler */
        tskKey = Task_disable();

        /* get task handle and block tsk */
        elem.tpElem.task = Task_self();

        /* leave a pointer for Task_delete() */
        elem.tpElem.task->pendElem = (Task_PendElem *)&(elem);

        Task_blockI(elem.tpElem.task);

        if (((UInt)sem->mode & 0x2) != 0) {    /* if PRIORITY bit is set */
            Semaphore_PendElem *tmpElem;
            Task_Handle tmpTask;
            UInt selfPri;
            
            tmpElem = Queue_head(pendQ);
            selfPri = Task_getPri(elem.tpElem.task);

            while (tmpElem != (Semaphore_PendElem *)pendQ) {
                tmpTask = tmpElem->tpElem.task;
                /* use '>' here so tasks wait FIFO for same priority */
                if (selfPri > Task_getPri(tmpTask)) {
                    break;
                }
                else {
                    tmpElem = Queue_next((Queue_Elem *)tmpElem);
                }
            }
            
            Queue_insert((Queue_Elem *)tmpElem, (Queue_Elem *)&elem);
        }
        else {      
            /* put task at the end of the pendQ */
            Queue_enqueue(pendQ, (Queue_Elem *)&elem);
        }

        /* start Clock if appropriate */
        if (BIOS_clockEnabled && 
                (elem.pendState == Semaphore_PendState_CLOCK_WAIT)) {
            Clock_startI(elem.tpElem.clock);
        }

        Hwi_restore(hwiKey);

        Task_restore(tskKey);   /* the calling task will block here */

        /* Here on unblock due to Semaphore_post or timeout */

        if (Semaphore_supportsEvents && (sem->event != NULL)) {
            /* synchronize Event state */
            hwiKey = Hwi_disable();
            Semaphore_eventSync(sem->event, sem->eventId, sem->count);
            Hwi_restore(hwiKey);
        }

        /* deconstruct Clock if appropriate */
        if (BIOS_clockEnabled && (elem.tpElem.clock != NULL)) {
            Clock_destruct(Clock_struct(elem.tpElem.clock));
        }

        elem.tpElem.task->pendElem = NULL;

        return ((Bool)(elem.pendState));
    }
    else {
        --sem->count;

        if (Semaphore_supportsEvents && (sem->event != NULL)) {
            /* synchronize Event state */
            Semaphore_eventSync(sem->event, sem->eventId, sem->count);
        }

        Hwi_restore(hwiKey);

        /* deconstruct Clock if appropriate */
        if (BIOS_clockEnabled && (elem.tpElem.clock != NULL)) {
            Clock_destruct(Clock_struct(elem.tpElem.clock));
        }

        return (TRUE);
    }
}
Beispiel #16
0
Int32 NullSrcLink_drvCreate(NullSrcLink_Obj * pObj,
                            NullSrcLink_CreateParams * pPrm)
{
    Int32 status;
    UInt32 chId, frameId;
    Clock_Params clockParams;
    System_LinkChInfo *pChInfo;
    FVID2_Frame *pFrame;

#ifdef SYSTEM_DEBUG_SWMS
    Vps_printf(" %d: NULL_SRC: Create in progress !!!\n", Utils_getCurTimeInMsec());
#endif

    memcpy(&pObj->createArgs, pPrm, sizeof(pObj->createArgs));

    UTILS_assert(pPrm->inputInfo.numCh <= SYSTEM_MAX_CH_PER_OUT_QUE);

    status = Utils_bufCreate(&pObj->bufOutQue, FALSE, FALSE);
    UTILS_assert(status == FVID2_SOK);

    if (pPrm->timerPeriod == 0 || pPrm->timerPeriod > 200)
        pPrm->timerPeriod = 16;

    Clock_Params_init(&clockParams);
    clockParams.period = pPrm->timerPeriod;
    clockParams.arg = (UArg) pObj;

    pObj->timer = Clock_create(NullSrcLink_drvTimerCb,
                               pPrm->timerPeriod, &clockParams, NULL);
    UTILS_assert(pObj->timer != NULL);

    pObj->info.numQue = 1;
    pObj->info.queInfo[0].numCh = pPrm->inputInfo.numCh;

    pChInfo = &pPrm->inputInfo.chInfo[0];

    pObj->outFormat.channelNum = 0;
    pObj->outFormat.width = pChInfo->width;
    pObj->outFormat.height = pChInfo->height;
    pObj->outFormat.pitch[0] = pChInfo->pitch[0];
    pObj->outFormat.pitch[1] = pChInfo->pitch[1];
    pObj->outFormat.pitch[2] = pChInfo->pitch[2];
    pObj->outFormat.fieldMerged[0] = FALSE;
    pObj->outFormat.fieldMerged[1] = FALSE;
    pObj->outFormat.fieldMerged[2] = FALSE;
    pObj->outFormat.dataFormat = pChInfo->dataFormat;
    pObj->outFormat.scanFormat = pChInfo->scanFormat;
    pObj->outFormat.bpp = FVID2_BPP_BITS16;
    pObj->outFormat.reserved = NULL;

    status = Utils_memFrameAlloc(&pObj->outFormat, pObj->outFrames, 1);
    UTILS_assert(status == FVID2_SOK);

    NullSrcLink_fillDataPattern(&pObj->outFormat, pObj->outFrames, 1);

    #ifndef SYSTEM_USE_TILER
    if (pObj->createArgs.tilerEnable)
    {
        Vps_printf("NULLSRC:!!WARNING.FORCIBLY DISABLING TILER since tiler is disabled at build time");
        pObj->createArgs.tilerEnable = FALSE;
    }
    #endif

    for (chId = 0; chId < pPrm->inputInfo.numCh; chId++)
    {
        memcpy(&pObj->info.queInfo[0].chInfo[chId],
               &pPrm->inputInfo.chInfo[chId],
               sizeof(pPrm->inputInfo.chInfo[chId]));

        pObj->info.queInfo[0].chInfo[chId].memType = VPS_VPDMA_MT_NONTILEDMEM;
        if (pObj->createArgs.tilerEnable)
        {
            pObj->info.queInfo[0].chInfo[chId].memType = VPS_VPDMA_MT_TILEDMEM;
        }
        pObj->chNextFid[chId] = 0;
    }

    for (frameId = 0;
         frameId < pPrm->inputInfo.numCh * SYSTEM_LINK_FRAMES_PER_CH; frameId++)
    {
        pFrame = &pObj->outFrames[frameId];

        memcpy(pFrame, &pObj->outFrames[0], sizeof(*pFrame));

        pFrame->appData = &pObj->frameInfo[frameId];

        memset(&pObj->frameInfo[frameId], 0, sizeof(pObj->frameInfo[frameId]));

        status = Utils_bufPutEmptyFrame(&pObj->bufOutQue, pFrame);
        UTILS_assert(status == FVID2_SOK);
    }

#ifdef SYSTEM_DEBUG_SWMS
    Vps_printf(" %d: NULL_SRC: Create Done !!!\n", Utils_getCurTimeInMsec());
#endif

    return FVID2_SOK;
}
Beispiel #17
0
/* Function: main =============================================================
 *
 * Abstract:
 *   Execute model on a generic target such as a workstation.
 */
int_T main(int_T argc, const char *argv[])
{
    /* External mode */
//     rtParseArgsForExtMode(argc, argv);
 
    /*******************************************
     * warn if the model will run indefinitely *
     *******************************************/
#if MAT_FILE==0 && EXT_MODE==0
    printf("warning: the simulation will run with no stop time; "
           "to change this behavior select the 'MAT-file logging' option\n");
    fflush(NULL);
#endif

    (void)printf("\n** starting the model **\n");

    /************************
     * Initialize the model *
     ************************/
    rt_InitModel();

    /* External mode */
    rtSetTFinalForExtMode(&rtmGetTFinal(RT_MDL));
    rtExtModeCheckInit(NUMST);
    Clock_Params clkParams;

    Timer_Params user_sys_tick_params;
    Timer_Handle user_sys_tick_timer;

    /* Create timer for user system tick */
    Timer_Params_init(&user_sys_tick_params);
    user_sys_tick_params.period = STEP_SIZE;
    user_sys_tick_params.periodType = Timer_PeriodType_MICROSECS;
    user_sys_tick_params.arg = 1;

    user_sys_tick_timer = Timer_create(1,
    		(ti_sysbios_hal_Timer_FuncPtr)Clock_tick, &user_sys_tick_params, NULL);

    if(user_sys_tick_timer == NULL)
    {
    	System_abort("Unable to create user system tick timer!");
    }

    /* Create a periodic Clock Instance with period = 1 system time units */
    Clock_Params_init(&clkParams);
    clkParams.period = 1;
    clkParams.startFlag = TRUE;
    Clock_create(clk0Fxn, 10, &clkParams, NULL);
    
//     rtExtModeWaitForStartPkt(rtmGetRTWExtModeInfo(RT_MDL),
//                              NUMST,
//                              (boolean_T *)&rtmGetStopRequested(RT_MDL));

    /***********************************************************************
     * Execute (step) the model.  You may also attach rtOneStep to an ISR, *
     * in which case you replace the call to rtOneStep with a call to a    *
     * background task.  Note that the generated code sets error status    *
     * to "Simulation finished" when MatFileLogging is specified in TLC.   *
     ***********************************************************************/
//     while (rtmGetErrorStatus(RT_MDL) == NULL &&
//            !rtmGetStopRequested(RT_MDL)) {
// 
// //         rtExtModePauseIfNeeded(rtmGetRTWExtModeInfo(RT_MDL),
// //                                NUMST,
// //                                (boolean_T *)&rtmGetStopRequested(RT_MDL));
// 
//         if (rtmGetStopRequested(RT_MDL)) break;
// 
//         /* external mode */
//         rtExtModeOneStep(rtmGetRTWExtModeInfo(RT_MDL),
//                          NUMST,
//                          (boolean_T *)&rtmGetStopRequested(RT_MDL));
//         
//         rt_OneStep();
//     }
    rtExtModeC6000Startup(rtmGetRTWExtModeInfo(RT_MDL),
                          NUMST,
                          (boolean_T *)&rtmGetStopRequested(RT_MDL));
    BIOS_start();

}
Beispiel #18
0
Int main()
{   
    Task_Handle signal_task;    
    Clock_Params clkParams;
    Timer_Params user_sys_tick_params;
    Timer_Handle user_sys_tick_timer;
    Error_Block eb;

#ifdef MODEL_PROFILING
    int32_t t_begin, t_end;
#endif 

    Error_init(&eb);

    /* Create a periodic Clock Instance with period = 1 system time units */
    Clock_Params_init(&clkParams);      
    clkParams.period = 1;
    clkParams.startFlag = TRUE;
    Clock_create(rt_task, 2, &clkParams, NULL);

    /* Create timer for user system tick */
    Timer_Params_init(&user_sys_tick_params);

    model_is_running = 0.0;

    if(model_tsamp <= 0.0)
		model_tsamp = MODEL_TSAMP;

	user_sys_tick_params.period = (uint32_t)(model_tsamp * USEC_PER_SEC);

    user_sys_tick_params.periodType = Timer_PeriodType_MICROSECS;
    user_sys_tick_params.arg = 1;
    user_sys_tick_timer = Timer_create(1, 
            (ti_sysbios_hal_Timer_FuncPtr)Clock_tick, 
            &user_sys_tick_params, NULL);

    if (user_sys_tick_timer == NULL) 
        System_abort("Unable to create user system tick timer!");

    signal_task = (Task_Handle)signal_init(&eb);
    if (signal_task == NULL) 
        System_abort("Signal task: Task_create() failed!\n");

#ifdef MODEL_PROFILING
    mdaq_profile_init(); 
    t_begin = mdaq_profile_read_timer32(); 
#endif 

    /* Init model */ 
    NAME(MODEL, _init)();

#ifdef MODEL_PROFILING
    t_end = mdaq_profile_read_timer32(); 
    mdaq_profile_save(t_end - t_begin,0);
#endif

    /* Open mdaqnet and wait for connection */ 
    mdaqnet_open();
    model_is_running = 1.0;

    BIOS_start();
}
Beispiel #19
0
/*
 *  ======== main ========
 */
Int main(Void) {
	/*Task_Handle taskHandle;
	 Task_Params taskParams;
	 Error_Block eb;*/
	short merge = 0;
	char *temp = (char *) &merge;

	Get_EvnString();					/// got enviroment form flash 0x80000

	/* Call board init functions */
	Board_initGeneral();
	Board_initGPIO();
	Board_initEMAC();
	Board_initUART();




	INIT_UART1_Printf();

	System_printf("Starting the Array Mang\nSystem provider is set to "
			"SysMin. Halt the target and use ROV to view output.\n");
	/* SysMin will only print to the console when you call flush or exit */
	System_flush();

	Log_info0("Create TCP task");

	// Create TCP task
	Task_Handle TCP_taskHandle;
	Task_Params TCP_taskParams;
	Error_Block TCP_eb;
	Task_Params_init(&TCP_taskParams);
	Error_init(&TCP_eb);
	TCP_taskParams.stackSize = 10240;					//8192;
	TCP_taskParams.priority = 2;
	TCP_taskHandle = Task_create((Task_FuncPtr) tcpHandler, &TCP_taskParams,
			&TCP_eb);
	if (TCP_taskHandle == NULL) {
		UARTprintf("main: Failed to create tcpHandler Task\n");
	}

	TCP_Periodic_Link_time.Updata_Period[1] = G_ENVCONFIG.Pollingtime[0];
	TCP_Periodic_Link_time.Updata_Period[0] = G_ENVCONFIG.Pollingtime[1];
	*temp = TCP_Periodic_Link_time.Updata_Period[0];
	*(temp + 1) = TCP_Periodic_Link_time.Updata_Period[1];

	test_merge = merge;
	//UARTprintf((const char*)"\n\n\n\n----Array Pollingtime = %d----\n\n\n\n\n",merge);

	TCP_Periodic_Link_time.TCP_Link_Period[0] = 0x3c;	// TCP LINK Period
	TCP_Periodic_Link_time.TCP_Link_Period[1] = 0x00;

	//Timer-periodic
	Clock_Params clockParams;
	Error_Block eb_timer;
	Error_init(&eb_timer);
	Clock_Params_init(&clockParams);
	clockParams.period = merge * Time_Tick;
	clockParams.startFlag = TRUE;
	Periodic_Handle = Clock_create(TimeTick_Periodic, First_Periodic_time,
			&clockParams, &eb_timer);
	if (Periodic_Handle == NULL) {
		System_abort("Clock create failed");
	}

	//Timer-Time_Stamp
	Clock_Params_init(&clockParams);
	clockParams.period = TimeStamp_time;
	clockParams.startFlag = TRUE;
	AM_Timer_Handle = Clock_create(TimeTick_TimeStamp, 1, &clockParams,
			&eb_timer);
	if (AM_Timer_Handle == NULL) {
		System_abort("Clock create failed");
	}

	/* Start BIOS */
	BIOS_start();

	return (0);
}
Beispiel #20
0
//*****************************************************************************
//
//! Festo Station Task.
//!
//! This task function do all the work related to controlling the Festo
//! Station. The task will first initialize the Driver and then run a infinite
//! loop, waiting and processing external events.
//!
//! \return None.
//
//*****************************************************************************
Void _task_FESTO(UArg arg0, UArg arg1)
{
	// initialize driver
	FestoStationDriver DriverInstance;
	FestoStationDriver* Driver = &DriverInstance;

    Festo_Driver_Init(Driver);

	uint32_t EventPosted;
	DisplayMessage MessageObject;

	MessageObject.ScreenID = 0;
	MessageObject.uptimeSeconds = 0;
	MessageObject.piecesProcessed = 0;
	MessageObject.blackAccepted = 0;
	MessageObject.blackRejected = 0;
	MessageObject.plasticAccepted = 0;
	MessageObject.plasticRejected = 0;
	MessageObject.orangeAccepted = 0;
	MessageObject.orangeRejected = 0;
	MessageObject.piecesProcessedPerSecond = 0;
	MessageObject.heightCalibrated = 230;
	MessageObject.upperHeightCalibrated = 245;
	MessageObject.lowerHeightCalibrated = 227;

	time_t t1 = time(NULL);
	strcpy((char*) MessageObject.timeString, asctime(localtime(&t1)));


	uint32_t uptimeSeconds = 0;
	uint32_t piecesProcessed = 0;
	uint32_t blackAccepted = 0;
	uint32_t blackRejected = 0;
	uint32_t plasticAccepted = 0;
	uint32_t plasticRejected = 0;
	uint32_t orangeAccepted = 0;
	uint32_t orangeRejected = 0;
	uint32_t metallicAccepted = 0;
	uint32_t metallicRejected = 0;
	uint32_t piecesProcessedPerSecond = 0;


	uint32_t *ColourAccepted;
	uint32_t *ColourRejected;
	uint32_t *MaterialAccepted;
	uint32_t *MaterialRejected;

	uint8_t colour = 0;
	uint8_t material = 0;

	uint32_t i = 0;

	uint32_t FestoState = 0;
	// 0 = stopped
	// 1 = idle
	// 2 = initial state
	// 10 = cal

	int32_t LowerLimit = 1200;
	int32_t UpperLimit = 1500;

	int32_t Uptime = 0;
	int32_t Time0 = 0;
	int32_t Time1 = 0;
	uint8_t Running = 0;

	Clock_Params clockParams;
	Clock_Handle myClock;
	Clock_Params_init(&clockParams);
	clockParams.arg = (UArg) Board_ACTUATOR_EJECTOR;
	myClock = Clock_create(_Festo_Deactivate_Ejector, 200, &clockParams, NULL);

	uint32_t heightMeasured = 0;
	uint32_t heightCalibratedADC = 1380;
	uint32_t heightCalibrated10mm = 225;

	//float ConvertFactor = 0.1*MessageObject.heightCalibrated/1200;

    GPIO_write(Board_LED0, Board_LED_OFF);
    GPIO_write(Board_LED1, Board_LED_OFF);
    GPIO_write(Board_LED2, Board_LED_ON);

    Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);

	Clock_start(Clock_1_sec);

	while(1)
	{
		EventPosted = Event_pend(FestoEvents,
						Event_Id_NONE,
						FESTO_EVENT_BUTTON_UP + FESTO_EVENT_BUTTON_DOWN +
						FESTO_EVENT_BUTTON_SELECT + FESTO_EVENT_RISER_DOWN +
						FESTO_EVENT_RISER_UP + FESTO_EVENT_ADC_FINISH +
						FESTO_EVENT_PIECE_IN_PLACE + FESTO_EVENT_EJECTOR_FINISHED +
						FESTO_EVENT_TICK + FESTO_EVENT_COOLDOWN +
						FESTO_EVENT_PIECE_NOT_IN_PLACE,
						FESTO_TIMEOUT);

		if (EventPosted & FESTO_EVENT_BUTTON_UP)
		{
			if (FestoState == 0)
			{
				Festo_Control_Driver(Driver, FESTO_ENABLED);
				FestoState = 1;
				Running = 1;
				GPIO_write(Board_LED0, Board_LED_ON);
				GPIO_write(Board_LED1, Board_LED_OFF);
				GPIO_write(Board_LED2, Board_LED_OFF);
				MessageObject.ScreenID = 1;
				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
				Time0 = Clock_getTicks();
			}
			else if (FestoState == 12)
			{
				MessageObject.heightCalibrated++;
				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
			}
			else if (FestoState == 13)
			{
				MessageObject.upperHeightCalibrated++;
				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
			}
			else if (FestoState == 14)
			{
				MessageObject.lowerHeightCalibrated++;
				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
			}
		}
		else if (EventPosted & FESTO_EVENT_BUTTON_DOWN)
		{
			if (FestoState == 1)
			{
				Festo_Control_Ejector(Driver, FESTO_EJECTOR_RETRACT);
				Festo_Control_Platform(Driver, FESTO_PLATFORM_LOWER);
				Festo_Control_Driver(Driver, FESTO_DISABLED);
				FestoState = 0;
				Running = 0;
				GPIO_write(Board_LED0, Board_LED_OFF);
				GPIO_write(Board_LED1, Board_LED_OFF);
				GPIO_write(Board_LED2, Board_LED_ON);
				MessageObject.ScreenID = 0;
				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
			}
			else if (FestoState == 12)
			{
				MessageObject.heightCalibrated--;
				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
			}
			else if (FestoState == 13)
			{
				MessageObject.upperHeightCalibrated--;
				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
			}
			else if (FestoState == 14)
			{
				MessageObject.lowerHeightCalibrated--;
				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
			}
		}
		else if (EventPosted & FESTO_EVENT_BUTTON_SELECT)
		{
			if (FestoState == 0)
			{
				GPIO_write(Board_LED0, Board_LED_OFF);
				GPIO_write(Board_LED1, Board_LED_ON);
				GPIO_write(Board_LED2, Board_LED_OFF);

				Festo_Control_Driver(Driver, FESTO_ENABLED);
				FestoState = 10;

				MessageObject.ScreenID = 2;

				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);

				Festo_Control_Ejector(Driver, FESTO_EJECTOR_RETRACT);
				if (Festo_Sense_Riser_Down(Driver) != 1)
				{
					Festo_Control_Platform(Driver, FESTO_PLATFORM_LOWER);
				}
				else
				{
					FestoState = 11;
					MessageObject.ScreenID = 3;
					Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
				}
			}
			else if (FestoState == 11)
			{
				FestoState = 12;
				MessageObject.ScreenID = 4;
				MessageObject.heightCalibrated = 230;

				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
			}
			else if (FestoState == 12)
			{
				FestoState = 13;

				Festo_Control_Platform(Driver, FESTO_PLATFORM_RAISE);

				Event_post(FestoEvents, FESTO_EVENT_ADC_START);
			}
			else if (FestoState == 13)
			{
				FestoState = 14;
				MessageObject.ScreenID = 6;
				MessageObject.lowerHeightCalibrated = 227;
				UpperLimit = MessageObject.upperHeightCalibrated *
						(1.0 * heightCalibratedADC)/(1.0 * heightCalibrated10mm);

				System_printf("Upper Limit Cal: %d for %d *0.1 mm\n", UpperLimit, MessageObject.upperHeightCalibrated);
				System_flush();

				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
			}
			else if (FestoState == 14)
			{
				FestoState = 15;
				MessageObject.ScreenID = 7;

				LowerLimit = MessageObject.lowerHeightCalibrated *
						(1.0 * heightCalibratedADC)/(1.0 * heightCalibrated10mm);

				System_printf("Lower Limit Cal: %d for %d *0.1 mm\n", LowerLimit, MessageObject.lowerHeightCalibrated);
				System_flush();

				Festo_Control_Ejector(Driver, FESTO_EJECTOR_RETRACT);
				Festo_Control_Platform(Driver, FESTO_PLATFORM_LOWER);

				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
			}
			else if (FestoState == 15)
			{
				FestoState = 0;
				MessageObject.ScreenID = 0;

				GPIO_write(Board_LED0, Board_LED_OFF);
				GPIO_write(Board_LED1, Board_LED_OFF);
				GPIO_write(Board_LED2, Board_LED_ON);

				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
			}
			else
			{

			}
		}
		else if (EventPosted & FESTO_EVENT_RISER_UP)
		{
			if (FestoState == 3)
			{
				if (Festo_Sense_Piece_Placed(Driver) == 1)
				{
					FestoState = 4;
					// wait estabilize
					for (i = 0; i < 1000000; i++);
					Event_post(FestoEvents, FESTO_EVENT_ADC_START);
				}
				else
				{
					FestoState = 1;
					Festo_Control_Ejector(Driver, FESTO_EJECTOR_RETRACT);
					Festo_Control_Platform(Driver, FESTO_PLATFORM_LOWER);
				}
			}
			else if (FestoState == 13)
			{
				Event_post(FestoEvents, FESTO_EVENT_ADC_START);
			}
			else
			{

			}
		}
		else if (EventPosted & FESTO_EVENT_RISER_DOWN)
		{
			if (FestoState == 2)
			{
				if (Festo_Sense_Piece_Placed(Driver) == 1)
				{
					// get a lot of samples
					for (i = 0; i < 1200; i++)
					{
						// this waits to get a reliable reading. If the reading is different from before, reset.
						if (colour != Festo_Sense_Piece_Colour(Driver) ||
								material != Festo_Sense_Piece_Material(Driver))
						{
							i = 0;
						}
						colour = Festo_Sense_Piece_Colour(Driver);
						material = Festo_Sense_Piece_Material(Driver);
					}

					FestoState = 3;
					Festo_Control_Platform(Driver, FESTO_PLATFORM_RAISE);
				}
				else
				{
					FestoState = 1;
				}
			}
			if (FestoState == 5)
			{
				Festo_Control_Ejector(Driver, FESTO_EJECTOR_EXTEND);
				Clock_start(myClock);
			}
			if (FestoState == 6)
			{
				Festo_Control_Ejector(Driver, FESTO_EJECTOR_RETRACT);
				Clock_start(myClock);
				FestoState = 7;
			}
			if (FestoState == 10)
			{
				FestoState = 11;
				MessageObject.ScreenID = 3;
				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
			}
		}
		else if (EventPosted & FESTO_EVENT_ADC_FINISH)
		{
		    if (Mailbox_pend(ADCMailbox, &heightMeasured, BIOS_NO_WAIT))
		    {
		    	Festo_Sense_Set_Piece_Height(Driver, heightMeasured);
		    }
		    else
		    {
		    	Event_post(FestoEvents, FESTO_EVENT_ADC_START);
		    }
			if (FestoState == 4)
			{
				if (colour == FESTO_COLOR_ORANGE && material == FESTO_PIECE_OTHER)
				{
					ColourAccepted = &orangeAccepted;
					ColourRejected = &orangeRejected;
					MaterialAccepted = &plasticAccepted;
					MaterialRejected = &plasticRejected;
				}
				else if (colour == FESTO_COLOR_OTHER && material == FESTO_PIECE_OTHER)
				{
					ColourAccepted = &blackAccepted;
					ColourRejected = &blackRejected;
					MaterialAccepted = &plasticAccepted;
					MaterialRejected = &plasticRejected;
				}
				else if (material == FESTO_PIECE_METALLIC)
				{
					ColourAccepted = NULL;
					ColourRejected = NULL;
					MaterialAccepted = &metallicAccepted;
					MaterialRejected = &metallicRejected;
				}
				else
				{
					ColourAccepted = NULL;
					ColourRejected = NULL;
					MaterialAccepted = NULL;
					MaterialRejected = NULL;
				}

				if (heightMeasured < UpperLimit && heightMeasured > LowerLimit)//withn range
				{
					if (ColourAccepted != NULL)
					{
						(*ColourAccepted)++;
					}
					if (MaterialAccepted != NULL)
					{
						(*MaterialAccepted)++;
						piecesProcessed++;
					}
					FestoState = 6;
					System_printf("Piece is acceptable\n");
					System_flush();

					Festo_Control_Ejector(Driver, FESTO_EJECTOR_EXTEND);
					Clock_start(myClock);
				}
				else // out of range
				{
					if (ColourAccepted != NULL)
					{
						(*ColourRejected)++;
					}
					if (MaterialAccepted != NULL)
					{
						(*MaterialRejected)++;
						piecesProcessed++;
					}
					System_printf("Piece is NOT acceptable\n");
					System_flush();
					FestoState = 5;
					Festo_Control_Platform(Driver, FESTO_PLATFORM_LOWER);
				}
			}
			else if (FestoState == 13)
			{
				heightCalibratedADC = heightMeasured;
				heightCalibrated10mm = MessageObject.heightCalibrated;

				System_printf("ADC Cal: %d for %d *0.1 mm\n", heightCalibratedADC, heightCalibrated10mm);
				System_flush();

				MessageObject.ScreenID = 5;
				MessageObject.upperHeightCalibrated = 245;

				Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);
			}
		}
		else if (EventPosted & FESTO_EVENT_EJECTOR_FINISHED)
		{
			if (FestoState == 6)
			{
				Festo_Control_Platform(Driver, FESTO_PLATFORM_LOWER);
				Clock_start(myClock);
			}
			else if (FestoState == 7)
			{
				FestoState = 1;
			}
			else
			{
				Festo_Control_Ejector(Driver, FESTO_EJECTOR_RETRACT);
				Clock_start(myClock);
				FestoState = 7;
			}
		}
		else if (EventPosted & FESTO_EVENT_TICK)
		{
			if (Running)
			{
				Time1 = Clock_getTicks();
				Uptime += (Time1 - Time0);
				Time0 = Time1;
				uptimeSeconds = Uptime * 0.001;

				piecesProcessedPerSecond = 100 * piecesProcessed/(0.016667*uptimeSeconds);

				MessageObject.piecesProcessed = piecesProcessed;
				MessageObject.blackAccepted = blackAccepted;
				MessageObject.blackRejected = blackRejected;
				MessageObject.plasticAccepted = plasticAccepted;
				MessageObject.plasticRejected = plasticRejected;
				MessageObject.orangeAccepted = orangeAccepted;
				MessageObject.orangeRejected = orangeRejected;
				MessageObject.piecesProcessedPerSecond = piecesProcessedPerSecond;
				MessageObject.uptimeSeconds = uptimeSeconds;
				MessageObject.metalAccepted = metallicAccepted;
				MessageObject.metalRejected = metallicRejected;
			}

			Seconds_set(Seconds_get()+1);
			t1 = time(NULL);
			strcpy((char*) MessageObject.timeString, asctime(localtime(&t1)));
			Mailbox_post(DisplayMailbox, &MessageObject, BIOS_NO_WAIT);

		}
		else if (EventPosted & FESTO_EVENT_PIECE_NOT_IN_PLACE)
		{
			if (FestoState <= 4)
			{
				FestoState = 1;
				Festo_Control_Ejector(Driver, FESTO_EJECTOR_RETRACT);
				Festo_Control_Platform(Driver, FESTO_PLATFORM_LOWER);
			}
		}
		else
		{
			if (FestoState == 1)
			{
				if (Festo_Sense_Piece_Placed(Driver) == 1)
				{
					FestoState = 2;
					if (Festo_Sense_Riser_Down(Driver) == 0)
					{
						Festo_Control_Platform(Driver, FESTO_PLATFORM_LOWER);
					}
					else
					{
					    Event_post(FestoEvents, FESTO_EVENT_RISER_DOWN);
					}
				}
			}
		}
		Task_sleep(100);
	}
}
Beispiel #21
0
/*
 *  ======== Event_pend ========
 */
UInt Event_pend(Event_Object *event, UInt andMask, UInt orMask, UInt timeout)
{
    UInt hwiKey, tskKey;
    Event_PendElem elem;
    UInt matchingEvents;
    Queue_Handle pendQ;
    Clock_Struct clockStruct;

    Assert_isTrue(((andMask | orMask) != 0), Event_A_nullEventMasks);

    Log_write5(Event_LM_pend, (UArg)event, (UArg)event->postedEvents,
                (UArg)andMask, (UArg)orMask, (IArg)((Int)timeout));

    /* 
     * elem is filled in entirely before interrupts are disabled.
     * This significantly reduces latency at the potential cost of wasted time
     * if it turns out that there is already an event match.
     */

    /* add Clock event if timeout is not FOREVER nor NO_WAIT */
    if (BIOS_clockEnabled 
            && (timeout != BIOS_WAIT_FOREVER)
            && (timeout != BIOS_NO_WAIT)) {
        Clock_Params clockParams;
        Clock_Params_init(&clockParams);
        clockParams.arg = (UArg)&elem;
        clockParams.startFlag = FALSE;  /* will start when necessary, thankyou */
        Clock_construct(&clockStruct, (Clock_FuncPtr)Event_pendTimeout, 
                                        timeout, &clockParams);
        elem.tpElem.clock = Clock_handle(&clockStruct);
        elem.pendState = Event_PendState_CLOCK_WAIT;
    }
    else {
        elem.tpElem.clock = NULL;
        elem.pendState = Event_PendState_WAIT_FOREVER;
    }

    /* fill in this task's Event_PendElem */
    elem.andMask = andMask;
    elem.orMask = orMask;

    pendQ = Event_Instance_State_pendQ(event);

    /* get task handle */
    elem.tpElem.task = Task_self();

    /* leave a pointer for Task_delete() */
    elem.tpElem.task->pendElem = (Task_PendElem *)&(elem);

    /* Atomically check for a match and block if none */
    hwiKey = Hwi_disable();

    /* check if events are already available */
    matchingEvents = checkEvents(event, andMask, orMask);

    if (matchingEvents != 0) {
        Hwi_restore(hwiKey);

        /* deconstruct Clock if appropriate */
        if (BIOS_clockEnabled && (elem.tpElem.clock != NULL)) {
            Clock_destruct(Clock_struct(elem.tpElem.clock));
        }

        return (matchingEvents);/* yes, then return with matching bits */
    }

    if (timeout == BIOS_NO_WAIT) {
        Hwi_restore(hwiKey);
        return (0);             /* No match, no wait */
    }

    Assert_isTrue((BIOS_getThreadType() == BIOS_ThreadType_Task),
                        Event_A_badContext);

    /* lock scheduler */
    tskKey = Task_disable();

    /* only one Task allowed!!! */
    Assert_isTrue(Queue_empty(pendQ), Event_A_eventInUse);

    /* add it to Event_PendElem queue */
    Queue_enqueue(pendQ, (Queue_Elem *)&elem);

    Task_blockI(elem.tpElem.task);

    if (BIOS_clockEnabled && 
            (elem.pendState == Event_PendState_CLOCK_WAIT)) {
        Clock_startI(elem.tpElem.clock);
    }

    Hwi_restore(hwiKey);

    /* unlock task scheduler and block */
    Task_restore(tskKey);       /* the calling task will switch out here */

    /* Here on unblock due to Event_post or Event_pendTimeout */

    /* deconstruct Clock if appropriate */
    if (BIOS_clockEnabled && (elem.tpElem.clock != NULL)) {
        Clock_destruct(Clock_struct(elem.tpElem.clock));
    }

    elem.tpElem.task->pendElem = NULL;

    /* event match? */
    if (elem.pendState != Event_PendState_TIMEOUT) {
        return (elem.matchingEvents);
    }
    else {
        return (0);             /* timeout */
    }
}