Exemple #1
0
static  void  AppTaskStart (void *p_arg)
{
   (void)p_arg;

    BSP_Init();                                                 /* Initialize BSP functions                             */
    CPU_Init();                                                 /* Initialize the uC/CPU services                       */
    
    BSP_Tick_Init();                                            /* Start Tick Initialization                            */

    Mem_Init();                                                 /* Initialize memory managment module                   */
    Math_Init();                                                /* Initialize mathematical module                       */


#if (OS_TASK_STAT_EN > 0)
    OSStatInit();                                               /* Determine CPU capacity                               */
#endif

    BSP_LED_Off(0);
    
#if (APP_CFG_SERIAL_EN == DEF_ENABLED)    
    App_SerialInit();                                           /* Initialize Serial communication for application ...  */
#endif

    APP_TRACE_INFO(("Creating Application Events...\n\r"));
    AppEventCreate();                                          /* Create Application Events                            */

    APP_TRACE_INFO(("Creating Application Tasks...\n\r"));
    AppTaskCreate();                                           /* Create application tasks                             */
    
    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.       */
        BSP_LED_Toggle(0);
        OSTimeDlyHMSM(0, 0, 0, 100);
    }
}
/*
*********************************************************************************************************
*                                              STARTUP TASK
*********************************************************************************************************
*/
void  TaskStart (void *pdata)
{
#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr;
#endif
    char       s[100];
    INT16S     key;


    pdata = pdata;                                         /* Prevent compiler warning                 */

    TaskStartDispInit();                                   /* Initialize the display                   */

    OS_ENTER_CRITICAL();								   /* Used to disable interrupts (see chapter 13)*/
    PC_VectSet(0x08, OSTickISR);                           /* Install uC/OS-II's clock tick ISR        */
    PC_SetTickRate(OS_TICKS_PER_SEC);                      /* Reprogram tick rate                      */
    OS_EXIT_CRITICAL();									   /* Re-enable interrupts*/

    OSStatInit();                                          /* Initialize uC/OS-II's statistics         */

    TaskStartCreateTasks();                                /* Create all the application tasks         */

    for (;;) {


        if (PC_GetKey(&key) == TRUE) {                     /* See if key has been pressed              */
            if (key == 0x1B) {                             /* Yes, see if it's the ESCAPE key          */
                PC_DOSReturn();                            /* Return to DOS                            */
            }
        }

        OSCtxSwCtr = 0;                                    /* Clear context switch counter             */
        OSTimeDlyHMSM(0, 0, 1, 0);                         /* Wait one second                          */
    }
}
void  AppTask3 (void *p_arg)
{
    while (1) {
        AppUpdatePB(PB_Rd());                                           /* Update the PB layout to be displayed on the LCD          */
        OSTimeDlyHMSM(0, 0, 0, 100);
    }
}
Exemple #4
0
/*
*********************************************************************************************************
*                                       AnalogCaptureTask TASK
*
*********************************************************************************************************
*/
void  AnalogCaptureTask (void *p_arg)
{
  (void)p_arg;                                                /* Prevent compiler warning                                 */
  
  OS_ERR      err = 0;
  CPU_INT32U  uCount = 0;  
  
  static      ADC_CONTROL_BLOCK_t strAdcControlBlock;
  InitAdcControlBlock(&strAdcControlBlock);                  /* Initialize ADC control structures                        */
  InitADCPort();                                              /* Initialize the ADC                                       */
  
  OSSemCreate(&semAdcIntSignal,"ADC EOC Int signal",0,&err);
  OSSemCreate(&semADC_Complete,"ADC completed semaphore",0,&err); 
  OSMutexCreate(&mutADC,"ADC value",&err);
  OSMutexCreate(&mutTMR3,"PWM in",&err);
  
  while (TRUE) {
    OSTimeDlyHMSM(0, 0, 0, 50,                             /* Performs conversions every 100 ms.                       */
                  OS_OPT_TIME_HMSM_STRICT,
                  &err);
    ADC1->CR2 |= 1<<21;                                     /* Trigger the conversion                                   */
    OSSemPend(&semAdcIntSignal,                             /* Wait for the end of conversion                           */
              0,                                            /* (This semaphore is posted by the ADC1_ISR)               */
              OS_OPT_PEND_BLOCKING,
              (CPU_TS*)NULL,&err);
    
    ReportAdcSample(ADC_CHANNEL_1, &strAdcControlBlock);
    if (++uCount > 5)
    {
      BSP_LED_Toggle(2);                                  /* Toggle the BSP Led #3                                    */
      uCount = 0;
    }
  }
}
static  void  AppTaskFirst (void *p_arg)
{
	if (DEBUG)
		xil_printf("DEBUG: INSIDE AppTaskFirst\n\r");

	p_arg = p_arg;				/* Prevent compiler warning by doing something with argument */
	
	BSP_InitIO();				/* Initialize the I/Os                                       */

#if OS_TASK_STAT_EN > 0
    OSStatInit();				/* Initialize uC/OS-II's statistics                          */
#endif

    AppTaskCreate();            /* La resta de tasques de l'aplicació es crean normalment       */
                                /* dins d'una altra funció per tal de mantenir neta la secció  */
                                /* de codi corresponent a la funció m                           */

	int	led = 0; // S3A400 - initialize LED selector

    while (1) {
		if (DEBUG)
			xil_printf("DEBUG: INSIDE AppTaskFirst while\n\r");
		//BSP_LEDToggle(led + 1); // S3A400 - Light selected LED, all others off
		
        OSTimeDlyHMSM(0,0,5,0); // Release the CPU (every 5 second)

		//led = (led + 1) % LEDS;				// S3A400 - Select next LED
    }
}
Exemple #6
0
static void appTaskConnect(void *pdata) {
  
  while (true) {
    OSTimeDlyHMSM(0,0,0,500);
    ledToggle(USB_CONNECT_LED);
  } 
}
Exemple #7
0
void LedFont_ScrollText(char *text, bool scrollOnce, bool waitForFinish) {
  INT8U err;
  
  UTIL1_strcpy((uint8_t*)LedFont_Text, sizeof(LedFont_Text), (const unsigned char*)text);
  LedFont_ScrollOnce = scrollOnce;
  while (!(OSFlagQuery(LedFont_Flags, &err)&LEDFONT_FLAG_READY)) {
    (void)OSTimeDlyHMSM(0,0,0,100); /* wait task to be ready */
  }
  OSTaskResume(TASK_PRIO_SCROLLER);
  if (scrollOnce && waitForFinish) {
    while (!(OSFlagQuery(LedFont_Flags, &err)&LEDFONT_FLAG_FINISHED_SCROLLING)) {
      (void)OSTimeDlyHMSM(0,0,0,100); /* wait for scrolling to be finished */
    }
    OSFlagPost(LedFont_Flags, LEDFONT_FLAG_FINISHED_SCROLLING, OS_FLAG_CLR, &err); /* clear flag */
  }
}
static  void  ProbeDemoIntro_TaskLED (void *p_arg)
{
    CPU_INT32U  ms_ctr;


    ms_ctr              = 0;
    ProbeDemoIntro_LED1 = DEF_OFF;
    ProbeDemoIntro_LED2 = DEF_OFF;
    ProbeDemoIntro_LED3 = DEF_OFF;

    while(DEF_TRUE) {
        if(ProbeDemoIntro_LED_Sel == DEF_OFF) {
            ProbeDemoIntro_LED1 = DEF_OFF;
            ProbeDemoIntro_LED2 = DEF_ON;
        } else {
            ProbeDemoIntro_LED1 = DEF_ON;
            ProbeDemoIntro_LED2 = DEF_OFF;
        }

        if (ms_ctr > (DEF_TIME_NBR_mS_PER_SEC / PROBE_DEMO_INTRO_LED_SEL_POLL_RATE_mS)) {
            if (ProbeDemoIntro_LED3 == DEF_OFF) {
               ProbeDemoIntro_LED3 = DEF_ON;
            } else {
               ProbeDemoIntro_LED3 = DEF_OFF;
            }
            ms_ctr = 0;
        } else {
            ms_ctr++;
        }

        OSTimeDlyHMSM(0, 0, 0, PROBE_DEMO_INTRO_LED_SEL_POLL_RATE_mS);
    }
}
//in t->func(t->data), don't restart tasklet_schedule,oterwise tasklet_kill will not exit.
void tasklet_kill(struct tasklet_struct *t)
{
    OS_ERR err;
    CPU_SR cpu_sr;
    
	if (in_interrupt())
		USBH_DBG("tasklet_kill Attempt to kill tasklet from interrupt\r\n");

    CPU_CRITICAL_ENTER();   
	while (t->state == TASKLET_STATE_SCHED){
        t->state = TASKLET_STATE_SCHED; 
		do {
            CPU_CRITICAL_EXIT();
			OSTimeDlyHMSM(0,0,0,5, OS_OPT_TIME_DLY,&err);
            CPU_CRITICAL_ENTER();  
		} while (t->state == TASKLET_STATE_SCHED);
	}
    CPU_CRITICAL_EXIT();
    
    
//	while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
//		do {
//			yield();
//		} while (test_bit(TASKLET_STATE_SCHED, &t->state));
//	}
//	tasklet_unlock_wait(t);
//	clear_bit(TASKLET_STATE_SCHED, &t->state);
}
Exemple #10
0
/* 
 * 函数名:Task_Tmr
 * 描述  : 定时器应用任务
 *			   优先级为OS_CFG_PRIO_MAX-5u
 * 输入  :无
 * 输出  : 无
 */
void Task_Tmr(void *p_arg)
{
  OS_ERR err;
 
  //定时器变量
  OS_TMR             MyTmr;
  (void)p_arg;      
  
  //创建定时器
  OSTmrCreate ((OS_TMR              *)&MyTmr,
               (CPU_CHAR            *)"MyTimer",          
               (OS_TICK              )100,                //第一次延时设置为100,结合定时器的频率是100Hz,正好1s
               (OS_TICK              )100,                //重复延时的时候100个TmrTick,结合定时器的频率是100Hz,正好1s
               (OS_OPT               )OS_OPT_TMR_PERIODIC,//模式设置为重复模式
               (OS_TMR_CALLBACK_PTR  )_cbOfTmr1,          //回调函数
               (void                *)0,                  //参数设置为0
               (OS_ERR              *)err);
  
  //启动定时器
  OSTmrStart ((OS_TMR   *)&MyTmr,
              (OS_ERR   *)err);
  
  //保存定时器开始的时候的时间戳
  ts_start = OS_TS_GET();
  
  while (1)
  {
    //不断阻塞
    OSTimeDlyHMSM(0, 0,1,0,OS_OPT_TIME_HMSM_STRICT,&err);	 
    
  }
}
Exemple #11
0
void* My_Task2()
{
	static INT32U mytask2 = GPIO_LED_PIN3;
	SysTest2 = 1;

	printf("My_Task2 Starting...9...\n");
	printf("My_Task2 Starting...8...\n");
	printf("My_Task2 Starting...7...\n");
	printf("My_Task2 Starting...6...\n");
	printf("My_Task2 Starting...5...\n");
	printf("My_Task2 Starting...4...\n");
	printf("My_Task2 Starting...3...\n");
	printf("My_Task2 Starting...2...\n");
	printf("My_Task2 Starting...1...\n");

	OSTimeDly(5);
	while(1)
	{
		SysTest2++;
		mytask2 = ~mytask2;
		GPIOPinWrite(GPIO_TEST_OUT_BASE, GPIO_TEST2_OUTPUT,SysTest2<<2);
		GPIOPinWrite(GPIO_LED_PORT_BASE, GPIO_LED_PIN3,mytask2);		
		printf("My_Task2 Running...%d,%#x...\n",&mytask2,mytask2);
		OSTimeDlyHMSM(0,0,2,0);
	}
}
Exemple #12
0
static  void  AppTask_2 (void *p_arg)
{
	INT8U  err;
	
   	(void)p_arg;

    APP_TRACE_INFO(("AppTask_2\n\r"));

	pSecureEventFlagGrp = OSFlagCreate(0x0, &err);

    /* Enable Crypto clock */        
    CLK->AHBCLK |= CLK_AHBCLK_CRPTCKEN_Msk;

	BSP_IntVectSet(BSP_INT_ID_CRYPTO, CRYPTO_IRQHandler);
	BSP_IntEn(BSP_INT_ID_CRYPTO);
	PRNG_ENABLE_INT();

	while (1)
	{
		PRNG_Open(PRNG_KEY_SIZE_256, 0, 0);
		bsp_printf("Start PRNG...\n");
		PRNG_Start();
		OSFlagPend(pSecureEventFlagGrp, 0x1, OS_FLAG_WAIT_SET_ANY, 0, &err);
		dump_PRNG();
        OSTimeDlyHMSM(0, 0, 0, 100);
    }
}
Exemple #13
0
void  Task5 (void *pdata)
{
    pdata = pdata;
    for (;;) {
        OSTimeDlyHMSM(0, 0, 0, 100);            //task 5 does nothing except delaying itself for 100ms
    }
}
Exemple #14
0
/*
 ***************************************************************
 * 名称: beep_task 
 * 功能: 蜂鸣器任务
 * 输入: 1. *pdata:任务参数
 * 输出: NULL 
 * 返回: NULL 
 * 描述: 无 
 ***************************************************************
 */
static void beep_task(void *pdata)
{		
	u8 flag = 0;
	
	Beep_On(100);
	Wt588d16_Play(0);	

	Show_StrInLine(1, 0, "江苏晶浩有限");
	Show_StrInLine(2, 0, "申通快递详情单");
	Show_StrInLine(3, 0, "延中盐汽水");
	Show_StrInLine(4, 0, "liuchao");
	
	oled_Show_StrInLine(1, 0, "江苏晶浩有限");
	oled_Show_StrInLine(2, 0, "申通快递详情单");
	oled_Show_StrInLine(3, 0, "延中盐汽水");
	oled_Show_StrInLine(4, 0, "liuchao:刘超");
	
	if (flag == 1)
		WriteCharToFlash();
	
	if (flag == 1)
		RTC_Set(2015, 5, 13, 16, 50, 00);
		
	while (1)
	{
		userCardCheck();
		
		sprintf(dateshow, "%4d-%2d-%2d", calendar.w_year, calendar.w_month, calendar.w_date);
		sprintf(timeshow, "%2d:%2d:%2d", calendar.hour, calendar.min, calendar.sec);
		Show_StrInLine(3, 0, dateshow);
		Show_StrInLine(4, 0, timeshow);		

		OSTimeDlyHMSM(0, 0, 0, 300);
	}									 
}
Exemple #15
0
bool App_testEndstops(void )
{
    OS_ERR       err;

    Debug_printf(Debug_Level_1, "Test all endstops\n");

    applicationState = ApplicationState_Test;

    endschalterXPlusTest  = FALSE;
    endschalterXMinusTest = FALSE;
    endschalterYPlusTest  = FALSE;
    endschalterYMinusTest = FALSE;
    endschalterZPlusTest  = FALSE;
    endschalterZMinusTest = FALSE;

    while(!(endschalterXPlusTest && endschalterXMinusTest
            && endschalterYPlusTest && endschalterYMinusTest
            && endschalterZPlusTest && endschalterZMinusTest
            && (applicationState == ApplicationState_Test)
           ))
        OSTimeDlyHMSM(0u, 0u, 0u, 100u, OS_OPT_TIME_HMSM_STRICT, &err);

    applicationState = ApplicationState_Idle;

    Debug_printf(Debug_Level_1, "All endstops successfully tested\n");

    return TRUE;
}
void  Clk_OS_Wait (CLK_ERR  *p_err)
{
    OS_ERR  os_err;


#if (CLK_CFG_SIGNAL_EN == DEF_ENABLED)
    OSSemPend((OS_SEM *)&Clk_OS_SignalObj,                      /* Wait for one-sec signal ...                          */
              (OS_TICK ) 0u,                                    /* ... without timeout.                                 */
              (OS_OPT  ) OS_OPT_PEND_BLOCKING,
              (CPU_TS *) 0,
              (OS_ERR *)&os_err);
#else
    OSTimeDlyHMSM(0u,
                  0u,
                  1u,                                           /* Dly for one sec (see Note #1).                       */
                  0u,
                  OS_OPT_TIME_PERIODIC,
                 &os_err);
#endif

    if (os_err != OS_ERR_NONE) {
       *p_err   = CLK_OS_ERR_WAIT;
        return;
    }

   *p_err = CLK_OS_ERR_NONE;
}
Exemple #17
0
void task2(void* pdata) {
	LCD lcd = LCD();
	while (1) {
		if (*((char*) SWITCHES_BASE) & 1 << 1) {
			// Clearing database
			{
				Database db;
				db.clearAll();
			}
			printf("Database has been cleared\n");
			LCD::writeToLCD("Database cleared", "");
			if (*((char*) SWITCHES_BASE) & 1 << 2) {
				// Populate database
				Database db;
				db.testPopulate();
				printf("Database has been populated\n");
				LCD::writeToLCD("Database","populated");
			}
		}
		if (*((char*) SWITCHES_BASE) & 1 << 3){
			Solenoid::unlock();
			LCD::writeToLCD("Unlocking", "");
		}
		//TODO: Switches for rest api calls
		/*if (*((char*) SWITCHES_BASE) & 1 << 4){

		}*/

		OSTimeDlyHMSM(0, 0, 1, 0);
	}
}
Exemple #18
0
static  void  App_Task_LCD (void *p_arg)
{
     OS_ERR      os_err;


    (void)p_arg;                                                /* See Note #1                                              */

    App_LCD_Dig1 =  0u;
    App_LCD_Dig2 =  0u;
    App_LCD_Dig3 =  0u;
    App_LCD_Dig4 =  0u;
    //BSP_LCD_OPT_COL = 1u;

    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.           */

        BSP_LCD_Write(App_LCD_Dig1,
                      App_LCD_Dig2,
                      App_LCD_Dig3,
                      App_LCD_Dig4,
                      BSP_LCD_OPT_COL);
			
			  App_LCD_Dig1++;
			  
			  if (App_LCD_Dig1 == 10) {
					  App_LCD_Dig1 = 0;
				}

        OSTimeDlyHMSM(0, 0, 1, 0,
                      OS_OPT_TIME_HMSM_STRICT, &os_err);        /* Suspend the task execution for 400 milliseconds.         */
    }
}
Exemple #19
0
//--------------------------------------------------------------------------
//  Description:
//     Delay for at least 'len' ms
//
void msDelay(int len)
{
#if SOCKIT_OWM_HW_DLY
   int i;

   // lock transfer
   ALT_SEM_PEND (sockit_owm.trn, 0);

   for (i=0; i<len; i++) {
      // create a 960us pause
      IOWR_SOCKIT_OWM (sockit_owm.base, ( sockit_owm.pwr        << SOCKIT_OWM_POWER_OFST)
                                      | ( sockit_owm.ena        << SOCKIT_OWM_ETX_OFST)
                                      | ((sockit_owm.pwr & 0x1) << SOCKIT_OWM_PWR_OFST)
                                      |                            SOCKIT_OWM_DLY_MSK);

     // wait for irq to set the transfer end flag
     ALT_FLAG_PEND (sockit_owm.irq, 0x1, OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME, 0);
     // wait for STX (end of transfer cycle)
     while (IORD_SOCKIT_OWM (sockit_owm.base) & SOCKIT_OWM_TRN_MSK);

     // release transfer lock
     ALT_SEM_POST (sockit_owm.trn);
   }
#else
#ifdef UCOS_II
   // uCOS-II timed delay
   OSTimeDlyHMSM(0,0,0,len);
#else
   // Altera HAL us delay
   usleep (1000*len);
#endif
#endif
}
Exemple #20
0
/*
*********************************************************************************************************
*                                          App_Task_LED()
*
* Description : This is an example of an application task.
*
* Argument(s) : p_arg   is the argument passed to 'App_Task_KEY()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Caller(s)   : This is a task.
*
* Notes       : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                   used.  The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static  void App_Task_LED (void *p_arg)
{
    OS_ERR       os_err;
	
    void         *p_msg;
    OS_MSG_SIZE  msg_size;
	
    CPU_TS       ts;
    CPU_TS       ts_delta;
	
    (void)       p_arg;
	
    p_arg = p_arg;
    while (DEF_TRUE) {
		
        p_msg = OSQPend((OS_Q        *)&AppQ,                  /* starts by waiting for messages to be sent through the message queue AppQ. */
                        (OS_TICK      )0,
                        (OS_OPT       )OS_OPT_PEND_BLOCKING,
                        (OS_MSG_SIZE *)&msg_size,              /* The size of the message.                                                  */
                        (CPU_TS      *)&ts,                    /* contain the timestamp of when the message was sent.                       */
                        (OS_ERR      *)&os_err);
		
        ts_delta = OS_TS_GET() - ts;
		
        BSP_LED_Toggle(BSP_LED_GREEN);

        OSTimeDlyHMSM(0, 0, 1, 0,
                      OS_OPT_TIME_HMSM_STRICT, &os_err);
    }
}
Exemple #21
0
void LedFont_Scroller(void *pdata) {
  INT8U err;
  char *p;
  short x, xStart;

  (void)pdata; /* avoid compiler warning */
  OSFlagPost(LedFont_Flags, LEDFONT_FLAG_READY, OS_FLAG_SET, &err); /* announce that we are ready */
  for(;;) { /* forever */
    while (LedFont_Text[0] == '\0') { /* no text */
      LedFont_Stop();
    }
    for(xStart=GDisp1_GetWidth()-1;;xStart--) {
      GDisp1_Clear();
      p = &LedFont_Text[0]; /* get character */
      x = xStart;
      while(*p != '\0') { /* go through the text */
        x += LedFont_PutChar(*p, x);
        p++; /* next character */
        x++; /* add a space between characters */
      }
      GDisp1_UpdateFull();
      if (x <= 0) { /* reached end of text to scroll: start over again */
        LedFont_Stop();
        break; /* start again */
      }
      (void)OSTimeDlyHMSM(0,0,0,60); /* delay specifies the scrolling speed */
      if (OSFlagQuery(LedFont_Flags, &err)&LEDFONT_FLAG_QUIT) { /* E8 pressed: quit */
        OSFlagPost(LedFont_Flags, LEDFONT_FLAG_QUIT, OS_FLAG_CLR, &err); /* clear flag */
        LedFont_Stop();
        break; /* start again */
      }
    } /* for */
  }
}
Exemple #22
0
/* Monitor Sensor Two Task
 * This task handles the monitoring of sensor two, the start sensor
 * and sends a message to the inpiut robot when the conveyor is 
 * occupied or free to deposit. 
 */
static void appTaskMonitorSens2(void *pdata) {
  /* 
   * Now execute the main task loop for this task
   */
  while (true) {
    if (conveyorItemPresent(CONVEYOR_SENSOR_2)){
      canSend(CONVEYOR_OCCUPIED);
    }
    if (!conveyorItemPresent(CONVEYOR_SENSOR_2)){
      canSend(CONVEYOR_FREE);
    }
    if (conveyorItemPresent(CONVEYOR_SENSOR_2) && checkForInputBlock) {
        OSTimeDlyHMSM(0,0,2,0);
        if (conveyorItemPresent(CONVEYOR_SENSOR_2)){
          checkForInputBlock = false;
          stopConveyorForLoad = false;
          noBlocks += 1;
          if (!conveyorItemPresent(CONVEYOR_SENSOR_1)){
            conveyorSetState(CONVEYOR_REVERSE);
          }
        }
    }
    if (stopConveyorForLoad){
      conveyorSetState(CONVEYOR_OFF);
    }
    OSTimeDly(20);
  }
}
Exemple #23
0
void   BSP_OS_TimeDlyMs (CPU_INT32U  dly_ms)
{
    CPU_INT16U  ms;
    CPU_INT16U  sec;
    OS_ERR      err;


    if (dly_ms > 10000u) {                                       /* Limit delays to 10 seconds.                        */
        dly_ms = 10000u;
    }

    if (dly_ms >= 1000u) {
        ms  = dly_ms / 1000u;
        sec = dly_ms % 1000u;
    } else {
        ms  = dly_ms;
        sec = 0u;
    }


    OSTimeDlyHMSM((CPU_INT16U) 0u,
                  (CPU_INT16U) 0u,
                  (CPU_INT16U) sec,
                  (CPU_INT32U) ms,
                  (OS_OPT    ) OS_OPT_TIME_HMSM_STRICT,
                  (OS_ERR   *)&err);
}
/* Notes      :(1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                   used.  The compiler should not generate any code for this statement.
*
*
*********************************************************************************************************
*/
void APP_TaskOne(void *p_arg)
{
  OS_ERR err = OS_ERR_NONE;
  static CPU_INT32U ledPos = 0U; /* LED position variable  */


  (void)p_arg; /* Note(1) */

  while (1U)
  { /* Task body, always written as an infinite loop  */

    /* Delay with 100msec                             */
    OSTimeDlyHMSM(0U, 0U, 0U, 100U, (OS_OPT_TIME_DLY | OS_OPT_TIME_HMSM_STRICT), &err);

    /* Animate LEDs */
    BSP_LedToggle(ledPos);

    /* Modify LED position variable                   */
    if (4u == ++ledPos)
    {
      ledPos = 0; /* 3bit overflow */
    }

    /* Delay task for 1 system tick (uC/OS-III suspends this task and executes
     * the next most important task) */
    OSTimeDly(1U, OS_OPT_TIME_DLY, &err);
  }
}
Exemple #25
0
void dine(philosopher *thePhilosopher)
{
	INT8U return_code;
	// Try to get lock with really short timeout
	OSSemPend(thePhilosopher->left, 1, &return_code);
	if (return_code != OS_TIMEOUT) {
		// We got the fork!!
		OSSemPend(thePhilosopher->right, 1, &return_code);
		if (return_code != OS_TIMEOUT) { // Success
			thePhilosopher->count++;
			printf("%c I'm eating. I've eaten %d times.\n", thePhilosopher->name, thePhilosopher->count);
			OSTimeDlyHMSM(0,0,5,0); // Sleep 5s
			printf("%c I'm done eating.\n", thePhilosopher->name);
			OSSemPost(thePhilosopher->right);
			OSSemPost(thePhilosopher->left);
		} else { // Failure
			OSSemPost(thePhilosopher->left);
			printf("%c Couldn't get second fork, swapping forks.\n", thePhilosopher->name);
			OS_EVENT *temp;
			temp = thePhilosopher->left;
			thePhilosopher->left = thePhilosopher->right;
			thePhilosopher->right = temp;
		}
	}
}
Exemple #26
0
/*************************************************************************
*                             野火嵌入式开发工作室
*
*  函数名称:Task_Start
*  功能说明:启动任务,初始化滴答时钟
*  参数说明:p_arg       没用
*  函数返回:无
*  修改时间:2012-2-10
*  备    注:
*************************************************************************/
void Task_Start(void *p_arg)
{
  /**************** 初始化 系统滴答时钟 :用于定时任务调度****************/
  u32  cnts;
  cnts = core_clk_mhz * ( (u32)1000000u / (u32)OS_TICKS_PER_SEC );       /* Determine nbr SysTick increments.                    */
  OS_CPU_SysTickInit(cnts);                                                     /* Init uC/OS periodic time src (SysTick).              */


#if (OS_TASK_STAT_EN > 0)
  /*       开启统计任务           */
  OSStatInit();
#endif


  (void)p_arg;    // 'p_arg' 并没有用到,防止编译器提示警告
  

  /******************* 用户任务区 ************************/
  u32 i = 0;
  
  OLED_Init(); 
  OLED_P6x8Str(0,0,"This is a test",0);
  
  while(1)
  {
    sprintf(mystr,"count:%d",i++); 
    OLED_P6x8Str(0,3,mystr,0);
    OSTimeDlyHMSM(0, 0, 0, 10);
  }
}
void  AppTask2 (void *p_arg)
{
    while (1) {
        AppFormatDec(&AppLCDTxt7[0], OSCtxSwCtr, LCD_LINE_BUF);         /* Update the value to be displayed                         */
        OSTimeDlyHMSM(0, 0, 0, 50);
    }
}
Exemple #28
0
bool App_testButtons(void )
{
    OS_ERR       err;

    Debug_printf(Debug_Level_1, "Press all buttons\n");

    applicationState = ApplicationState_Test;

    buttonXPlusTest  = FALSE;
    buttonXMinusTest = FALSE;
    buttonYPlusTest  = FALSE;
    buttonYMinusTest = FALSE;
    buttonZPlusTest  = FALSE;
    buttonZMinusTest = FALSE;
    buttonOkTest     = FALSE;

    while(!(buttonXPlusTest && buttonXMinusTest
            && buttonYPlusTest && buttonYMinusTest
            && buttonZPlusTest && buttonZMinusTest
            && buttonOkTest && (applicationState == ApplicationState_Test)
           ))
        OSTimeDlyHMSM(0u, 0u, 0u, 100u, OS_OPT_TIME_HMSM_STRICT, &err);

    applicationState = ApplicationState_Idle;

    Debug_printf(Debug_Level_1, "All buttons successfully tested\n");

    return TRUE;
}
Exemple #29
0
//浮点测试任务
void float_task(void *p_arg)
{
	OS_ERR err;
	//CPU_SR_ALLOC();
	while(1)
	{
		OSTimeDlyHMSM(0,0,0,400,OS_OPT_TIME_HMSM_STRICT,&err); //延时400ms	
		printf("float task wait Mutex Sem . \n\r");
		// 请求信号量
		OSMutexPend(&Mutex_Sem,0,OS_OPT_PEND_BLOCKING,0,&err);
		//OSSemPend(&SYNC_SEM,0,OS_OPT_PEND_BLOCKING,0,&err); //请求信号量
		printf("float task get Mutex Sem \n\r");
		OSMutexPost(&Mutex_Sem,OS_OPT_POST_NO_SCHED,&err);
		OSTimeDlyHMSM(0,0,0,100,OS_OPT_TIME_HMSM_STRICT,&err); //延时100ms	
	}
}
/*******************************************************************************
* Function Name  : TaskStart
* Description    : UCOS-II.
* Input          : *pdata.
* Output         : None
* Return         : None
*******************************************************************************/
void TaskStart(void *pdata)
{
    //u16 tp_xvalue = 0, tp_yvalue = 0;
    //INT8U  err = 0;

    pdata = pdata;                   // 防止编译器告警
    SysTick_Configuration();         // 初始化系统节拍(1ms)
    OSStatInit();                    // 初始化统计任务
    TaskStartCreateTasks();          // 建立其他任务

    /* 初始化TFT, 设置TFT背光 */
    TFT_Init();
    TFT_SetBlackLight(TFT_BL_PERCENT_90);

    TFT_Clear(Blue);

    TFT_DisplayD36x48(10,  150, '2', White, Blue);
    TFT_DisplayD36x48(46,  150, '1', White, Blue);
    TFT_DisplayD36x48(82,  150, ':', White, Blue);
    TFT_DisplayD36x48(118, 150, '5', White, Blue);
    TFT_DisplayD36x48(154, 150, '8', White, Blue);
    TFT_DisplayString(200, 182, "2011", White, Blue);

    TFT_DisplayString(30, 218, "Wendnesday, Septermber 23", White, Blue);
    TFT_DrawHLine(30, 236, 230, Blue);

    while(1)
    {
        //printf("Start task is running!\r\n");
        /* 任务延时500ms */
        OSTimeDlyHMSM(0, 0, 20, 0);
    }
}