__task void init(void) { t_LedTask1=os_tsk_create_user(LedTask1,1,LedTask1Stack,sizeof(LedTask1Stack)); t_LedTask1=os_tsk_create_user(LedTask2,2,LedTask2Stack,sizeof(LedTask2Stack)); t_UsartTask=os_tsk_create_user(UsartTask,3,UsartTaskStack,sizeof(UsartTaskStack)); os_tsk_delete_self(); }
/*********** Invoke Forground Command *********************/ static void command_invoke(void *args) { void (*func)(void * ) ; int i,iteration ; func = (void(*)(void *))((func_args *)args)->argv[0] ; #ifdef HAVE_KEIL_RTX LockMutex((CyaSSL_Mutex *)&command_mutex) ; #endif iteration = for_iteration ; for(i=0; i< iteration; i++) { if(iteration > 1) printf("--- Start for %d ---->\n", i) ; #if defined(HAVE_KEIL_RTX) stack_fill(command_stack, COMMAND_STACK_SIZE) ; #endif func(args) ; /* invoke command */ #if defined(HAVE_KEIL_RTX) stack_check(command_stack, COMMAND_STACK_SIZE) ; #endif } if(iteration > 1) for_iteration = 1 ; #ifdef HAVE_KEIL_RTX UnLockMutex((CyaSSL_Mutex *)&command_mutex) ; os_tsk_delete_self() ; #endif }
TASK void check_working(void* pc) { ProtectAssistCell* pac = reinterpret_cast<ProtectAssistCell*>(pc); if( pac == 0 ) { #ifdef EZ_DEBUG printf("\n!!!task check_working error!!!\n"); #endif os_tsk_delete_self(); } static int count = 0; while( 1 ) { os_dly_wait(100); if( pac->protectPause ) { continue; } Working_STATE_E currentState = pac->getOMUWorkingStateByHardware(); if( pac->getOMUCurrentWorkingState() != currentState ) { if( ++count > 3 ) { count = 0; pac->switchTo(currentState); } } else { count = 0; //保证必须连续三次采集到不同才会切换 } } }
/*********** Invoke Forground Command *********************/ static void command_invoke(void const *args) { void (*func)(void const * ) ; int i,iteration ; func = (void(*)(void const *))((func_args *)args)->argv[0] ; #if defined(HAVE_KEIL_RTX) wc_LockMutex((wolfSSL_Mutex *)&command_mutex) ; #endif iteration = for_iteration ; for(i=0; i< iteration; i++) { if(iteration > 1) printf("--- Start for %d ---->\n", i) ; #if defined(HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS) stack_fill(command_stack, COMMAND_STACK_SIZE) ; #endif func(args) ; /* invoke command */ #if defined(HAVE_KEIL_RTX)&& !defined(WOLFSSL_CMSIS_RTOS) stack_check(command_stack, COMMAND_STACK_SIZE) ; #endif } if(iteration > 1) for_iteration = 1 ; osDelay(20000) ; #ifdef HAVE_KEIL_RTX wc_UnLockMutex((wolfSSL_Mutex *)&command_mutex) ; #ifdef WOLFSSL_CMSIS_RTOS osThreadTerminate(osThreadGetId()) ; #else os_tsk_delete_self() ; #endif #endif }
// //=============================================================== // 操作系统启动初始化 // os_idle_demon 高一级别任务 //=============================================================== __task void init_task(void) { // //-------------------------------------- // 测试引脚 gpio.pinMode(testPin, OUTPUT); // dac.init (testDac); // //-------------------------------------- // usb 标准任务,起动 setSem serialCommu.setSem(); serialCommu.begin(); // //-------------------------------------- //== sd 卡初始化起动 sdReader.init(); // //-------------------------------------- //== ADC 初始化 adc.initCh(PIN_AI1, ADC_FACTOR_32); adc.initCh(PIN_AI2, ADC_FACTOR_32); adc.initCh(PIN_AI3, ADC_FACTOR_32); adc.initCh(AUTO_LEAVER_PIN, ADC_FACTOR_4); adc.start (); // //------------------------------------ // 建立任务 越前面优先级越低 os_tsk_create_user(lcdTask, 2, lcdStk, sizeof(lcdStk) ); os_tsk_create_user(mainLoopTask, 3, main_loop_stk, sizeof(main_loop_stk) ); os_tsk_create_user(sdReaderTask, 4, sdReaderStk, sizeof(sdReaderStk) ); os_tsk_create_user(commuTsk, 5, commuStk, sizeof(commuStk) ); os_tsk_create_user(gcodeTsk, 6, gcodeStk, sizeof(gcodeStk) ); os_tsk_delete_self(); }
/*** This is the parent task entry ***/ void main_task (void) { #ifdef CYASSL_KEIL_TCP_NET init_TcpNet (); os_tsk_create (tcp_tick, 2); os_tsk_create (tcp_poll, 1); #endif #ifdef CYASSL_MDK_SHELL #ifdef HAVE_KEIL_RTX os_tsk_create_user(shell_main, 1, Shell_stack, SHELL_STACKSIZE) ; #else shell_main() ; #endif #else /************************************/ /*** USER APPLICATION HERE ***/ /************************************/ printf("USER LOGIC STARTED\n") ; #endif #ifdef HAVE_KEIL_RTX CYASSL_MSG("Terminating tcp_main\n") ; os_tsk_delete_self (); #endif }
__task void task_init (void) { task1 = os_tsk_create_user( Monitor, 1, &StackMonitor, sizeof(StackMonitor)); task2 = os_tsk_create_user( KEYHandler, 2, &StackKey, sizeof(StackKey)); task3 = os_tsk_create_user( CMDHandler, 3, &StackCmd, sizeof(StackCmd)); os_tsk_delete_self (); }
/*---------------------------------------------------------------------------- * Task 5: Credit *---------------------------------------------------------------------------*/ __task void taskCredit (void) { GPU_Image credit; GPU_ConfigureLayer(&Layer_1,LAYER1_START_ADDRESS,320,240); Display_conf.Enable =1; Display_conf.Alpha_On =1; Display_conf.Plan_Enable = 0x1; Display_conf.Test_On=0; GPU_UpdateDisplayConfig(); GPU_HScroll (&Layer_1, 0,1); GPU_VScroll (&Layer_1, 0,1); // Load the image from the SD card to the graphic card GPU_NewImage(&credit, 320, 240,"credit", 0x0500000); SD_LoadImage(&credit, 320, 240, &fil); GPU_BitBlitI2L(&credit, 0, 0, 320, 240,&Layer_1, 0,0); // Waiting the user to press the user button while(is_button_pressed(USER)); // fin de la demo, pour relancer le menu os_tsk_create(taskMenu,15); os_tsk_delete_self (); while (1){}; }
__task void initTask(void){ //sem init os_sem_init(&semIncMin, 0); os_sem_init(&semKeyPress, 0); os_sem_init(&semIncHour, 0); os_sem_init(&semIncSec, 0); initTexts(); //mutex init os_mut_init(&mutTime); os_mut_init(&mut_msg_ptr); os_mut_init(&mut_msg_offset); //task init os_tsk_create(taskSerial, 0x82); os_tsk_create(clock_task, 0x90); os_tsk_create(taskIncHour, 0x7F); os_tsk_create(taskIncMin, 0x80); os_tsk_create(taskIncSec, 0x81); disTaskId = os_tsk_create(updateDisplay, 0x10); keyTaskId = os_tsk_create(key_task, 0x7E); joyTaskId = os_tsk_create(joy_task, 0x7D); //display stuff... os_evt_set(DIS_EVT_MSG_PTR, disTaskId); //end os_tsk_delete_self(); }
void exit_command(void) { printf("Command Aborted\n") ; #ifdef WOLFSSL_CMSIS_RTOS osThreadTerminate(osThreadGetId()) ; #else os_tsk_delete_self() ; #endif }
__task void timer_1s_task(void){ for(;;){ //PTB->PTOR = PIN_18_MASK; if( os_tmr_create(1000, st_diag_id) == NULL ) // 0x03e8 = 1000 = 1 секунда os_tsk_delete_self(); else os_evt_wait_or(st_diag_id, 0xffff); } }
__task void taskDemo (void) { demo(); // fin de la demo, pour relancer le menu os_tsk_create(taskMenu,15); os_tsk_delete_self (); while (1){}; }
/*---------------------------------------------------------------------------- * Task 7 'init': Initialize *---------------------------------------------------------------------------*/ __task void init (void) { os_mut_init(mut_GLCD); t_phaseA = os_tsk_create (phaseA, 0); /* start task phaseA */ t_phaseB = os_tsk_create (phaseB, 0); /* start task phaseB */ t_phaseC = os_tsk_create (phaseC, 0); /* start task phaseC */ t_phaseD = os_tsk_create (phaseD, 0); /* start task phaseD */ t_clock = os_tsk_create (clock, 0); /* start task clock */ t_lcd = os_tsk_create (lcd, 0); /* start task lcd */ os_evt_set (0x0001, t_phaseA); /* send signal event to task phaseA */ os_tsk_delete_self (); }
__task void init(void) // Task #1 { os_tsk_create(task1, 1); //task1 at priority 1 os_tsk_create(task2, 1); //task2 at priority 1 os_tsk_create(task3, 1); //task3 at priority 1 os_tsk_create(task4, 1); //task4 at priority 1 os_tsk_create(getActiveTasks, 1); os_tsk_delete_self(); //must delete itself before exiting }
/******* Invoke Background Job *******************************/ static void bg_job_invoke(void *args) { void (*func)(void * ) ; BackGround = 1 ; stack_fill(bg_job_stack, BG_JOB_STACK_SIZE) ; func = (void(*)(void *))((func_args *)args)->argv[0] ; func(args) ; /* invoke command */ stack_check(bg_job_stack, BG_JOB_STACK_SIZE) ; #ifdef CYASSL_KEIL_NET init_TcpNet (); #endif BackGround = 0 ; os_tsk_delete_self() ; ; }
__task void init (void) { /* Add System initialisation code here */ init_io (); init_display (); init_TcpNet (); /* Initialize Tasks */ os_tsk_prio_self (100); os_tsk_create (blink_led, 20); os_tsk_create (timer_task, 30); os_tsk_create_user (tcp_task, 0, &tcp_stack, sizeof(tcp_stack)); os_tsk_delete_self(); }
/*RTX系统初始化*/ __task void Init_task(void) { os_tsk_prio_self (100); //提升自身优先级 os_tsk_create (led_test_task,3); os_tsk_create (send_result,4); // os_tsk_create (upload_refresh_data,5); os_tsk_create(single_jb,6); os_tsk_create(u1recive,3); os_tsk_create (io_keep_time,8); os_tsk_create (get_adc_value,8); os_tsk_delete_self(); }
/*---------------------------------------------------------------------*/ __task void task3(void){ void *pointer; pointer = os_mem_alloc(box_mem); if (pointer == NULL) printf("Not enough memory\n"); else printf("malloc'd(): %d \n", pointer); os_dly_wait(50); if(os_mem_free(box_mem, pointer) == OS_R_OK){ printf("dealloc'd(): OS_R_OK \n"); }else{ printf("dealloc'd(): OS_R_NOK \n"); } os_dly_wait(50); os_tsk_delete_self(); }
__task void KEY_Sound (void) { //unsigned int keycount =0; //unsigned short BlankLED =0; // if(BackLED!=NULL) os_tmr_kill (BackLED); // BlankLED = BKP_ReadBackupRegister(BKP_DR34); // BackLED = os_tmr_create((unsigned int)(BlankLED*100*1.8),1); if( HAL_RTCEx_BKUPRead(&RtcHandle, RTC_BKP_DR3)==0) { HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_SET); os_dly_wait (20); HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_RESET); } os_tsk_delete_self (); }
__task void init(void) { os_mut_init(&g_mut_uart); os_mut_init(&procon); for( task_creator_ctr = 0; task_creator_ctr < P; task_creator_ctr++ ) { os_tsk_create(producer_task, 0); } task_creator_ctr = 0; for( task_creator_ctr = 0; task_creator_ctr < C; task_creator_ctr++ ) { os_tsk_create(consumer_task, 0); } // os_tsk_create(updater_task, 10); os_tsk_delete_self(); }
/*---------------------------------------------------------------------------- * Task 2: RTX Kernel starts this task with os_tsk_create (consumer_task, 0) *---------------------------------------------------------------------------*/ __task void consumer_task (void) { OS_TID consumer_tskid; /* assigned identification for consumer */ consumer_tskid = os_tsk_self(); /* get it's own task ID */ T_NUM *random_num_rx; while( msg_counter_rec < N ) { os_mbx_wait (MsgBox, (void **)&random_num_rx, 0xffff); /* wait for the message */ os_mut_wait(g_mut_uart, 0xFFFF); printf("[consumer_task [pid:(%d)] ]: Received %u\n", consumer_tskid, random_num_rx->number); msg_counter_rec += 1; os_mut_release(g_mut_uart); if( _free_box (mpool, random_num_rx) ) /* free memory allocated for message */ { os_mut_wait(g_mut_uart, 0xFFFF); printf("_free_box failed because memory couldn't be freed\n"); os_mut_release(g_mut_uart); exit(1); } } //Get Time C time_c = os_time_get(); os_mut_wait(g_mut_uart, 0xFFFF); printf("Time to initialize system: %0.6f\n", (float)(((float)time_b - time_a)/1000000) ); printf("Time to transmit data: %0.6f\n", (float)(((float)time_c - time_b)/1000000) ); os_mut_release(g_mut_uart); // os_dly_wait(10); os_tsk_delete_self (); /* We are done here, delete this task */ }
__task void Init_System(void){ //---------------------------------------------------------------- // Peripgherals INIT Section //---------------------------------------------------------------- os_dly_wait(1); //---------------------------------------------------------------- put_log("[MAIN]: Starting System PERIPHERALS Initialisation...\r\n"); //---------------------------------------------------------------- LED_Init(); //---------------------------------------------------------------- // System Tasks INIT Section //---------------------------------------------------------------- put_log("[MAIN]: Starting System TASKS...\r\n"); //---------------------------------------------------------------- create_LED_Control_Task(); create_Acc_Update_task(); //---------------------------------------------------------------- put_log("[MAIN]: TASKS and PERIPHERALS Init Complete.\r\n"); //---------------------------------------------------------------- os_tsk_delete_self(); //---------------------------------------------------------------- }
/*---------------------------------------------------------------------*/ __task void init(void) { //Initialize the memory pool _init_box(box_mem, sizeof(box_mem), 4); os_mut_init(&g_mut_uart); os_mut_wait(g_mut_uart, 0xFFFF); printf("init: TID = %d\n", os_tsk_self()); os_mut_release(g_mut_uart); g_tid = os_tsk_create(task1, 1); /* task 1 at priority 1 */ os_mut_wait(g_mut_uart, 0xFFFF); printf("init: created task1 with TID %d\n", g_tid); os_mut_release(g_mut_uart); g_tid = os_tsk_create(task2, 4); /* task 2 at priority 2 */ os_mut_wait(g_mut_uart, 0xFFFF); printf("init: created task2 with TID %d\n", g_tid); os_mut_release(g_mut_uart); g_tid = os_tsk_create(task3, 3); /* task 3 at priority 3 */ os_mut_wait(g_mut_uart, 0xFFFF); printf("init: created task3 with TID %d\n", g_tid); os_mut_release(g_mut_uart); g_tid = os_tsk_create(task4, 4); /* task 4 at priority 4 */ os_mut_wait(g_mut_uart, 0xFFFF); printf("init: created task4 with TID %d\n", g_tid); os_mut_release(g_mut_uart); g_tid = os_tsk_create(task5, 1); /* task 5 at priority 1 */ os_mut_wait(g_mut_uart, 0xFFFF); printf("init: created task5 with TID %d\n", g_tid); os_mut_release(g_mut_uart); os_tsk_delete_self(); /* task MUST delete itself before exiting */ }
/******* Invoke Background Job *******************************/ static void bg_job_invoke(void const *args) { void (*func)(void const * ) ; BackGround = 1 ; #if defined(HAVE_KEIL_RTX)&& !defined(WOLFSSL_CMSIS_RTOS) stack_fill(bg_job_stack, BG_JOB_STACK_SIZE) ; #endif func = (void(*)(void const *))((func_args *)args)->argv[0] ; func(args) ; /* invoke command */ #if defined(HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS) stack_check(bg_job_stack, BG_JOB_STACK_SIZE) ; #endif osDelay(20000) ; BackGround = 0 ; #ifdef WOLFSSL_CMSIS_RTOS osThreadTerminate(osThreadGetId()) ; #else os_tsk_delete_self() ; ; #endif }
/*---------------------------------------------------------------------*/ __task void task2(void) { U8 i=1; RL_TASK_INFO task_info; os_mut_wait(g_mut_uart, 0xFFFF); printf("TID\tNAME\t\tPRIO\tSTATE \t%%STACK\n"); os_mut_release(g_mut_uart); for(i = 0; i <7; i++) { // this is a lazy way of doing loop. if (os_tsk_get(i+1, &task_info) == OS_R_OK) { os_mut_wait(g_mut_uart, 0xFFFF); printf("%d\t%s\t\t%d\t%s\t%d%%\n", \ task_info.task_id, \ fp2name(task_info.ptask, g_tsk_name), \ task_info.prio, \ state2str(task_info.state, g_str), \ task_info.stack_usage); os_mut_release(g_mut_uart); } } if (os_tsk_get(0xFF, &task_info) == OS_R_OK) { os_mut_wait(g_mut_uart, 0xFFFF); printf("%d\t%s\t%d\t%s\t%d%%\n", \ task_info.task_id, \ fp2name(task_info.ptask, g_tsk_name), \ task_info.prio, \ state2str(task_info.state, g_str), \ task_info.stack_usage); os_mut_release(g_mut_uart); } os_dly_wait(20); os_tsk_delete_self(); }
__task void init (void) { os_mut_init(mut_GLCD); os_mut_init(mut_Gclock); GUI_UC_SetEncodeUTF8(); if(HAL_RTCEx_BKUPRead(&RtcHandle, RTC_BKP_DR6) !=1) { zhuantskid = os_tsk_create (zhuan1, 0); maintskid = os_tsk_create (Main_Task, 0); keytskid = os_tsk_create (phase_KEY, 0); servertskid = os_tsk_create (Server_Task, 0); }else { Time3Disable(); HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOE,GPIO_PIN_2,GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOG,GPIO_PIN_3,GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOG,GPIO_PIN_2,GPIO_PIN_SET); } os_tsk_create (power, 0); // os_tmr_create(500,2); os_tsk_delete_self (); }
/*---------------------------------------------------------------------------- * Task 1: RTX Kernel starts this task with os_sys_init (taskMenu) *---------------------------------------------------------------------------*/ __task void taskMenu (void) { // Variable declaration GPU_Image background; GPU_Color aColor; GPU_Color clearColor; int stateArrow = 0; uint8_t arrowX = 0; uint8_t arrowY = 0; uint32_t joystick; int stateOutput = 1; // Set the task priority id1 = os_tsk_self (); os_tsk_prio_self (1); // Configure the layer for the console menu GPU_ConfigureLayer(&Layer_1,LAYER1_START_ADDRESS,320,240); GPU_ConfigureLayer(&Layer_2,LAYER2_START_ADDRESS,320,240); GPU_ConfigureLayer(&Layer_3,LAYER3_START_ADDRESS,320,240); GPU_ConfigureLayer(&Layer_4,LAYER4_START_ADDRESS,320,240); Display_conf.Enable =1; Display_conf.Alpha_On =1; Display_conf.Plan_Enable = 0xF; Display_conf.Test_On=0; GPU_UpdateDisplayConfig(); GPU_HScroll (&Layer_1, 0,1); GPU_VScroll (&Layer_1, 0,1); GPU_HScroll (&Layer_2, 0,1); GPU_VScroll (&Layer_2, 0,1); GPU_HScroll (&Layer_3, 0,1); GPU_VScroll (&Layer_3, 0,1); GPU_HScroll (&Layer_4, 0,1); GPU_VScroll (&Layer_4, 0,1); GPU_ConfigureOutput(MODE_VGA); GPU_ClearScreen(&Layer_1); GPU_ClearScreen(&Layer_2); clearColor.R = 0; clearColor.G = 0; clearColor.B = 0; clearColor.A = 0; GPU_FillRect (&Layer_2,0,0,320,240, clearColor); GPU_ClearScreen(&Layer_3); GPU_FillRect (&Layer_4,0,0,320,240, clearColor); GPU_ClearScreen(&Layer_4); // Load the image from the SD card to the graphic card GPU_NewImage(&background, 320, 240,"menu", 0x0500000); SD_LoadImage(&background, 320, 240, &fil); GPU_BitBlitI2L(&background, 0, 0, 320, 240,&Layer_1, 0,0); // Display the two optionnal menu aColor.R = 255; aColor.G = 255; aColor.B = 255; aColor.A = 255; GPU_WriteText(&Layer_3, 76, 188, "-> Demo", aColor); GPU_WriteText(&Layer_3, 40, 220, "Credits", aColor); GPU_WriteText(&Layer_3, 220, 220, "Output :", aColor); // Display the selector to the first programm aColor.R = 7; aColor.G = 1; aColor.B = 15; aColor.A = 15; GPU_FillRect (&Layer_2,60,108,10,10, aColor); if ( stateOutput == 1) { GPU_WriteText(&Layer_4, 270, 220, "VGA", aColor); } else { GPU_WriteText(&Layer_4, 270, 220, "LCD", aColor); } while((is_button_pressed(USER) && joystick != JOY_RIGHT) || stateArrow == 5 ) { joystick = JOY_GetKeys(); if (joystick == JOY_UP) { if (stateArrow == 0) { stateArrow = 5; } else { stateArrow--; } } if (joystick == JOY_DOWN) { stateArrow++; stateArrow = stateArrow % 6; } if (stateArrow == 4) { arrowX = 20; arrowY = 215; } else if (stateArrow == 5) { arrowX = 200; arrowY = 215; } else { arrowX = 60; arrowY = 108 + 26*stateArrow; } // Update the position of the selector GPU_ClearScreen(&Layer_2); GPU_FillRect (&Layer_2,arrowX ,arrowY,10,10, aColor); switch (stateArrow) { case 0: { Turn_Led(LED2,ON); Turn_Led(LED3,OFF); Turn_Led(LED4,OFF); Turn_Led(LED5,OFF); Turn_Led(LED6,OFF); Turn_Led(LED7,OFF); break; } case 1: { Turn_Led(LED2,OFF); Turn_Led(LED3,ON); Turn_Led(LED4,OFF); Turn_Led(LED5,OFF); Turn_Led(LED6,OFF); Turn_Led(LED7,OFF); break; } case 2: { Turn_Led(LED2,OFF); Turn_Led(LED3,OFF); Turn_Led(LED4,ON); Turn_Led(LED5,OFF); Turn_Led(LED6,OFF); Turn_Led(LED7,OFF); break; } case 3: { Turn_Led(LED2,OFF); Turn_Led(LED3,OFF); Turn_Led(LED4,OFF); Turn_Led(LED5,ON); Turn_Led(LED6,OFF); Turn_Led(LED7,OFF); break; } case 4: { Turn_Led(LED2,OFF); Turn_Led(LED3,OFF); Turn_Led(LED4,OFF); Turn_Led(LED5,OFF); Turn_Led(LED6,ON); Turn_Led(LED7,OFF); break; } case 5: { Turn_Led(LED2,OFF); Turn_Led(LED3,OFF); Turn_Led(LED4,OFF); Turn_Led(LED5,OFF); Turn_Led(LED6,OFF); Turn_Led(LED7,ON); break; } } if (stateArrow == 5 && !is_button_pressed(USER)) { GPU_ClearScreen(&Layer_4); GPU_FillRect (&Layer_4,0,0,320,240, clearColor); if ( stateOutput == 1) { stateOutput = 0; GPU_WriteText(&Layer_4, 270, 220, "VGA", aColor); GPU_ConfigureOutput(MODE_VGA); } else { stateOutput = 1; GPU_WriteText(&Layer_4, 270, 220, "LCD", aColor); GPU_ConfigureOutput(MODE_LCD); } while(!is_button_pressed(USER)); } os_dly_wait(30); } // Start the task selected switch (stateArrow) { case 0: { os_tsk_create (taskUnicorn, 10); break; } case 1: { os_tsk_create (taskSOR, 10); break; } case 2: { os_tsk_create (taskZelda, 10); break; } case 3: { os_tsk_create (taskDemo, 10); break; } case 4: { os_tsk_create (taskCredit, 10); break; } } // Destroy the task os_tsk_delete_self (); while (1){}; }
__task void quick_sort_task( void* void_ptr){ // Make all declarations at head of fcn array_type *aptr, pivot, tmp; size_t pivotIndex, a, c, lo, hi, length; array_interval_t int_right, int_left; qsort_task_parameters_t *param, left_param, right_param; // End declarations param = (qsort_task_parameters_t *) void_ptr; aptr = param->interval.array.array; a = param->interval.a; c = param->interval.c; length = c - a + 1; if (length <= USE_INSERTION_SORT) { insertion_sort(param->interval); os_tsk_delete_self(); } pivotIndex = (size_t) (a + (c - a + 1)*(1.0*rand()/RAND_MAX)); pivot = aptr[pivotIndex]; lo = a; hi = c; while(lo <= hi) { while(aptr[lo] < pivot) lo += 1; while(aptr[hi] > pivot) hi -= 1; if (lo <= hi) { tmp = aptr[lo]; aptr[lo] = aptr[hi]; aptr[hi] = tmp; lo += 1; hi -= 1; } } int_left.array = param->interval.array; int_right.array = param->interval.array; left_param.priority = param->priority + 1; right_param.priority = param->priority + 1; int_left.a = a; int_left.c = hi; int_right.a = lo; int_right.c = c; left_param.interval = int_left; right_param.interval = int_right; os_tsk_create_ex( quick_sort_task, left_param.priority, &left_param ); os_tsk_create_ex( quick_sort_task, right_param.priority, &right_param ); os_tsk_delete_self(); }
__task void task5(void) { os_dly_wait(100); os_tsk_delete_self(); }
/*---------------------------------------------------------------------------- * Task Producer: RTX Kernel starts this task with os_sys_init (producer_task) *---------------------------------------------------------------------------*/ __task void producer_task (void) { OS_TID producer_tskid; /* assigned identification for producer */ T_NUM *random_num_tx; //Get Time A //time_a = os_time_get(); //Get current task ID producer_tskid = os_tsk_self (); // fork the child process os_tsk_create (consumer_task, 0); /* start task 2 */ os_mut_wait(procon, 0xFFFF); if(cur_producer == 0) { os_mbx_init (MsgBox, sizeof(MsgBox));/* initialize the mailbox */ os_mut_wait(g_mut_uart, 0xFFFF); printf("[producer_task [pid:(%d)] ]: Mailbox Created\n", producer_tskid); os_mut_release(g_mut_uart); cur_producer = 1; } os_mut_release(procon); //Get Time B //time_b = os_time_get() ; // Check if the number is the required one // .. And also make sure that we still have to send numbers. while (msg_counter_send < N && ( (msg_counter_send % P) == producer_tskid ) ) { random_num_tx = _alloc_box(mpool); /* Allocate a memory for the message */ if( random_num_tx == NULL ) { os_mut_wait(g_mut_uart, 0xFFFF); printf("_alloc_box failed because of no mem available!\n"); os_mut_release(g_mut_uart); exit(1); } random_num_tx->number = (U32) ( msg_counter_send ); os_mbx_send (MsgBox, random_num_tx, 0xffff); /* Send the message to the mailbox */ os_mut_wait(g_mut_uart, 0xFFFF); printf("[producer_task [pid:(%d)] ]: Sent %u\n", producer_tskid, random_num_tx->number); msg_counter_send++; os_mut_release(g_mut_uart); // os_dly_wait (100); } //msg_counter_send = 0; os_tsk_delete_self (); /* We are done here, delete this task */ }