Exemplo n.º 1
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();
}
Exemplo n.º 2
0
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 */
}
Exemplo n.º 3
0
/*
 *  ======== 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);
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
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();
}
Exemplo n.º 6
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);
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
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");
    }
}
/**************************************************************************************************
 * @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);
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
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);
}
Exemplo n.º 12
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);
	}
}
Exemplo n.º 13
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();
}
Exemplo n.º 14
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();

}