Esempio n. 1
0
/**
 * -----------------------------------------------------------------------------
 * @brief       mutex1_execute	 
 * @param[in]   None	
 * @param[out]  None
 * @retval      None	 
 * @par Description
 * @details     The code of mutex test example 1. 
 * -----------------------------------------------------------------------------
 */
static void mutex1_execute (void)
{
  unsigned char i;
  Cnt = 0;
  Del_Flag  = 0;
  Exit_Flag = 0;

  CoTickDelay (1);

  for (i=0; i<MUTEX_NUM; i++) {
      Mutex_Id[i] = CoCreateMutex ();
	  if (Mutex_Id[i] == E_CREATE_FAIL) {
	       printf ("\r Create the %d mutex fail. \n",i+1);
	  }
  }

  for (i=0; i< MAX_SLAVE_TEST_TASKS; i++) {
      Task_Id [i] = CoCreateTask (mutexTask01,(void*)i,MAINTEST_PRIMARY_PRIORITY-(i+1),&Task_Stack[i][SLAVE_TASK_STK_SIZE-1],SLAVE_TASK_STK_SIZE);
	  testAssert((Task_Id[i] != E_CREATE_FAIL)," Create task fail #3 ");
  }

    while (Exit_Flag == 0) ;
	Del_Flag  = 0;
	Exit_Flag = 0;

	for (i=0; i<MAX_SLAVE_TEST_TASKS; i++) {
	    testAssert((Flag[i] == Sequence[i])," Mutex #1 ");
	} 
}
Esempio n. 2
0
int main(void)
{
    cpuInit();
    uartInit(BAUDRATE);
    i2cInit();

    TASKHANDLES System;
    System.flight_control.armed=0;
    System.flight_control.error=0;    
    System.lock.i2c = CoCreateMutex ( );
    
    CoInitOS();

    CoCreateTask( ledTask,
            &System,
            PRIORITY_LED_TASK,
            &stkLED[SIZE_LED_TASK-1],
            SIZE_LED_TASK );

    CoCreateTask( radioTask,
            &System,
            PRIORITY_RADIO_TASK,
            &stkRADIO[SIZE_RADIO_TASK-1],
            SIZE_RADIO_TASK );

    CoCreateTask( flightTask,
            &System,
            PRIORITY_FLIGHT_TASK,
            &stkFLIGHT[SIZE_FLIGHT_TASK-1],
            SIZE_FLIGHT_TASK );    


    printf("Starting OS!!\n");

    CoStartOS();
    printf("ERROR");
    while(1);
}
Esempio n. 3
0
void menusTask(void * pdata)
{
  opentxInit();

#if defined(PCBTARANIS) && defined(REV9E)
  while (1) {
    uint32_t pwr_check = pwrCheck();
    if (pwr_check == e_power_off) {
      break;
    }
    else if (pwr_check == e_power_press) {
      continue;
    }
#else
  while (pwrCheck() != e_power_off) {
#endif
    U64 start = CoGetOSTime();
    perMain();
    // TODO remove completely massstorage from sky9x firmware
    U32 runtime = (U32)(CoGetOSTime() - start);
    // deduct the thread run-time from the wait, if run-time was more than 
    // desired period, then skip the wait all together
    if (runtime < MENU_TASK_PERIOD_TICKS) {
      CoTickDelay(MENU_TASK_PERIOD_TICKS - runtime);
    }
  }

#if defined(REV9E)
  topLcdOff();
#endif

  BACKLIGHT_OFF();

#if defined(PCBTARANIS)
  displaySleepBitmap();
#else
  lcd_clear();
  displayPopup(STR_SHUTDOWN);
#endif

  opentxClose();
  boardOff(); // Only turn power off if necessary
}

extern void audioTask(void* pdata);

void tasksStart()
{
  CoInitOS();

#if defined(CLI)
  cliStart();
#endif

#if defined(BLUETOOTH)
  btTaskId = CoCreateTask(btTask, NULL, 15, &btStack[BT_STACK_SIZE-1], BT_STACK_SIZE);
#endif

  mixerTaskId = CoCreateTask(mixerTask, NULL, 5, &mixerStack[MIXER_STACK_SIZE-1], MIXER_STACK_SIZE);
  menusTaskId = CoCreateTask(menusTask, NULL, 10, &menusStack[MENUS_STACK_SIZE-1], MENUS_STACK_SIZE);
  audioTaskId = CoCreateTask(audioTask, NULL, 7, &audioStack[AUDIO_STACK_SIZE-1], AUDIO_STACK_SIZE);

#if !defined(SIMU)
  audioMutex = CoCreateMutex();
  mixerMutex = CoCreateMutex();
#endif

  CoStartOS();
}
Esempio n. 4
0
/**
 *******************************************************************************
 * @brief		Initialization task	  
 * @param[in] 	pdata	A pointer to parameter passed to task.	 
 * @param[out] 	None  
 * @retval		None
 *		 
 * @details	    This task is called to initial hardware and created tasks.
 *******************************************************************************
 */
void task_init(void *pdata)
{
	uart_printf (" [OK]. \n\r\n\r");
	uart_printf ("\r \"task_init\" task enter.		\n\r\n\r ");
	pdata = pdata; 
	 
    /* Initiate Time buffer for LCD display */
	chart[0] = time[2]/10 + '0';
	chart[1] = time[2]%10 + '0';
		
	chart[3] = time[1]/10 + '0';
	chart[4] = time[1]%10 + '0';

	chart[6] = time[0]/10 + '0';
	chart[7] = time[0]%10 + '0';	


	uart_printf ("\r Create the \"mut_uart\" mutex...      ");
	mut_uart = CoCreateMutex();
	if(mut_uart != E_CREATE_FAIL)
		uart_printf (" [OK]. \n");		
	else
		uart_printf (" [Fail]. \n");	


	uart_printf ("\r Create the \"mut_lcd\" mutex...       ");
	mut_lcd  = CoCreateMutex(); 
	if(mut_lcd != E_CREATE_FAIL)
		uart_printf (" [OK]. \n");		
	else
		uart_printf (" [Fail]. \n");	


	uart_printf ("\r Create the \"button_sel_flg\" flag... ");

	/*!< Manual reset flag,initial state:0 */
	button_sel_flg	= CoCreateFlag(Co_FALSE,0); 
	if(button_sel_flg != E_CREATE_FAIL)
		uart_printf (" [OK]. \n");		
	else
		uart_printf (" [Fail]. \n");	


	uart_printf ("\r Create the \"button_add_flag\" flag...");

	/*!< Manual reset flag,initial state:0	*/
	button_add_flg = CoCreateFlag(Co_FALSE,0);	
	if(button_add_flg != E_CREATE_FAIL)
		uart_printf (" [OK]. \n\n");		
	else
		uart_printf (" [Fail]. \n\n");	

	uart_printf ("\r Create the \"lcd_blink_flg\" flag...  ");
	lcd_blink_flg = CoCreateFlag(Co_FALSE,0); 	/*!< Manual reset flag,initial state:0	*/ 
	if(lcd_blink_flg != E_CREATE_FAIL)
		uart_printf (" [OK]. \n");		
	else
		uart_printf (" [Fail]. \n");
								  
	uart_printf ("\r Create the \"time_display_flg\" flag...");

	/*!< Manual reset flag,initial state:0	*/ 
	time_display_flg = CoCreateFlag(Co_FALSE,0); 
	if(time_display_flg != E_CREATE_FAIL)
		uart_printf (" [OK]. \n");		
	else
		uart_printf (" [Fail]. \n");

	/*!< Set flag to allow "time_display_flg" task run.	*/
	CoSetFlag(time_display_flg);
		

	uart_printf ("\r Create the first mailbox...         ");
	mbox0 = CoCreateMbox(EVENT_SORT_TYPE_FIFO);
 	if(mbox0 == E_CREATE_FAIL)
		uart_printf (" [Fail]. \n\n");		
	else
	    uart_printf (" [OK]. \n\n");
			



	/* Configure Peripheral */
	uart_printf ("\r Initial hardware in Board :     \n\r");

	uart_printf ("\r ADC initial...                      ");
	ADC_Configuration  ();
	uart_printf (" [OK]. \n");

	uart_printf ("\r RTC initial...                      ");
	RTC_Configuration  ();
	uart_printf (" [OK]. \n");

	uart_printf ("\r GPIO initial...                     ");
	GPIO_Configuration ();	
	uart_printf (" [OK]. \n");

	uart_printf ("\r External interrupt initial...       ");
	EXIT_Configuration ();
	uart_printf (" [OK]. \n");	

	uart_printf ("\r LCD initial...                      ");
	LCD_Configuration  ();		
	uart_printf (" [OK]. \n\n");
	

	/* Create Tasks */
	CoCreateTask(                       lcd_display_adc, 
	                                         (void *)0 , 
					                    LCD_DISPLAY_PRI ,
			     &lcd_display_adc_Stk[TASK_STK_SIZE-1] , 
					                     TASK_STK_SIZE
				 );

    CoCreateTask(    	              uart_print , 
	                                   (void *)0 , 
				                  UART_PRINT_PRI ,   
				 &uart_print_Stk[TASK_STK_SIZE-1],
					                TASK_STK_SIZE 
		        );
	CoCreateTask(                       led_blink , 
	                                    (void *)0 ,
	                                LCD_BLINK_PRI ,    
	             &led_display_Stk[TASK_STK_SIZE-1],
	                                 TASK_STK_SIZE 
	             );

	time_display_id = CoCreateTask(                         time_display, 
	                                                           (void *)0, 
								                       TIME_DISRPLAY_PRI,  
								    &time_display_Stk[TASK_STK_SIZE - 1], 
									                       TASK_STK_SIZE 
								  );

	CoCreateTask(                   time_set ,
			                       (void *)0 , 
			                    TIME_SET_PRI ,      
			   &time_set_Stk[TASK_STK_SIZE-1], 
			                    TASK_STK_SIZE 
			   );


	CoExitTask();	 /*!< Delete 'task_init' task. 	*/	
}