void app_main() { #if sem_test sem_init(&sem, (U8 *)"sem1", 1); #endif #if mutex_test mutex_init(&mutex, (U8 *)"mutex1"); #endif #if msg_queue_test msg_queue_create(&my_queue, 100, (U8 *)"my_queue"); msg_queue_create(&my_queue1, 100, (U8 *)"my_queue1"); msg_queue_create(&my_queue2, 100, (U8 *)"my_queue2"); msg1.buff = (U8 *)"1aaa"; msg2.buff = (U8 *)"2bbb"; msg3.buff = (U8 *)"3ccc"; msg4.buff = (U8 *)"4aaa"; msg5.buff = (U8 *)"5bbb"; msg6.buff = (U8 *)"6ccc"; msg7.buff = (U8 *)"7aaa"; msg8.buff = (U8 *)"8bbb"; msg9.buff = (U8 *)"9ccc"; #endif task_create(&tcb1, (U8 *)"task1", task1, NULL, stack1, STACK_SIZE, 3, 1); task_create(&tcb2, (U8 *)"task2", task2, NULL, stack2, STACK_SIZE, 4, 1); //task_create(&tcb3, (U8 *)"task3", task3, NULL, stack3, STACK_SIZE, 3, 1); //task_create(&tcb4, (U8 *)"task4", task4, NULL, stack4, STACK_SIZE, 1, 1); }
int init_timer_mgr (void) { int i = TIMER_WHEEL; tmtaskid_t btmhlftask_id = 0; tmtaskid_t task_id = 0; timer_rq_init (); EventInit (&timer_event); #ifdef TIMER_BTM_HALF if (task_create ("TMRBHF", 99, TSK_SCHED_RR, 32000, tick_service, NULL, NULL, &btmhlftask_id) == TSK_FAILURE) { return FAILURE; } #endif if (task_create ("TMRTHF", 99, TSK_SCHED_RR, 32000, tick_clock, NULL, NULL, &task_id) == TSK_FAILURE) { return FAILURE; } while (--i >= 0) { create_sync_lock (&tmrrq.root[i].lock); sync_unlock (&tmrrq.root[i].lock); } timer_lock_create (); #ifdef TIMER_BTM_HALF bh_timer_lock_create (); #endif return SUCCESS; }
int main (int argc, char *argv[]) { printf ("Main INICIO\n") ; task_init () ; sem_create (&s1, 1) ; sem_create (&s2, 0) ; task_create (&a1, TaskA, "A1") ; task_create (&a2, TaskA, " A2") ; task_create (&b1, TaskB, " B1") ; task_create (&b2, TaskB, " B2") ; task_join (&a1) ; sem_destroy (&s1) ; sem_destroy (&s2) ; task_join (&a2) ; task_join (&b1) ; task_join (&b2) ; printf ("Main FIM\n") ; task_exit (0) ; exit (0) ; }
static void test_readwrite_start(int n) { rw_task_finished = 0; sem_initialize(&sem_rw, 1); mtx_initialize(&mtx_rw); taskrw[0] = task_create("tRA", task_reader, &n, NULL, 0x1000, 220, 10, 0); task_resume_noschedule(taskrw[0]); taskrw[1] = task_create("tRB", task_reader, &n, NULL, 0x1000, 220, 10, 0); task_resume_noschedule(taskrw[1]); taskrw[2] = task_create("tRC", task_reader, &n, NULL, 0x1000, 220, 10, 0); task_resume_noschedule(taskrw[2]); taskrw[3] = task_create("tWA", task_writer, &n, NULL, 0x1000, 220, 10, 0); task_resume_noschedule(taskrw[3]); /* wait test task to exit */ printf("Reader/Writer started\n"); while(rw_task_finished < 4) task_delay(50); printf("Reader/Writer finished\n"); }
void pingpong_init() { #ifdef DEBUG puts("Ping Pong OS inicializado!\n"); #endif /* desativa o buffer de saída padrão (stdout), usado pela função printf */ setvbuf(stdout, 0, _IONBF, 0); // Cria a tarefa main task_create(&mainTask, NULL, NULL); // Ajusta a tarefa atual como a tarefa main currentTask = &mainTask; // Retira a tarefa main da fila de prontas exec = (taskqueue_t*) queue_remove((queue_t**) &ready, (queue_t*) ready); free(exec); // Cria a tarefa dispatcher task_create(&dispatcher, dispatcher_body, NULL); // Retira a tarefa dispathcer da fila de prontas exec = (taskqueue_t*) queue_remove((queue_t**) &ready, (queue_t*) ready); free(exec); }
static void test_multitasks_start() { task_t taskA, taskB; kprintf("create taskA with pri=200\n"); taskA = task_create("ttaskA", task_multitasks_taskA, NULL, NULL, 0x1000, 200, 0, 0); task_resume_noschedule(taskA); kprintf("create taskB with pri=210\n"); taskB = task_create("ttaskB", task_multitasks_taskB, NULL, NULL, 0x1000, 210, 0, 0); task_resume_noschedule(taskB); task_set_schedule_hook(sched_hook); kprintf("cmd task Delay 500 ticks\n"); task_delay(500); kprintf("destroy taskA\n"); task_destroy(taskA); kprintf("destroy taskB\n"); task_destroy(taskB); task_set_schedule_hook(NULL); kprintf("testcase multitasks end\n"); }
int ostest_main(int argc, char *argv[]) { int result; /* Verify that stdio works first */ stdio_test(); #ifdef SDCC /* I am not yet certain why SDCC does not like the following initilizers. * It involves some issues with 2- vs 3-byte pointer types. */ g_argv[0] = arg1; g_argv[1] = arg2; g_argv[2] = arg3; g_argv[3] = arg4; g_argv[4] = NULL; #endif /* Set up some environment variables */ #ifndef CONFIG_DISABLE_ENVIRON printf("ostest_main: putenv(%s)\n", g_putenv_value); putenv(g_putenv_value); /* Varaible1=BadValue3 */ printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var1_name, g_var1_value); setenv(g_var1_name, g_var1_value, TRUE); /* Variable1=GoodValue1 */ printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var2_name, g_bad_value1); setenv(g_var2_name, g_bad_value1, FALSE); /* Variable2=BadValue1 */ printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var2_name, g_var2_value); setenv(g_var2_name, g_var2_value, TRUE); /* Variable2=GoodValue2 */ printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); setenv(g_var3_name, g_var3_value, FALSE); /* Variable3=GoodValue3 */ printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); setenv(g_var3_name, g_bad_value2, FALSE); /* Variable3=GoodValue3 */ show_environment(true, true, true); #endif /* Verify that we can spawn a new task */ #ifndef CONFIG_CUSTOM_STACK result = task_create("ostest", PRIORITY, STACKSIZE, user_main, g_argv); #else result = task_create("ostest", PRIORITY, user_main, g_argv); #endif if (result == ERROR) { printf("ostest_main: ERROR Failed to start user_main\n"); } else { printf("ostest_main: Started user_main at PID=%d\n", result); } printf("ostest_main: Exitting\n"); return 0; }
void kernel_main() { int i = 0; //init_sys_mmu(); //start_mmu(); /* 开启MMU */ unsigned int end = (unsigned int)(&__end+PGDR_MASK)&0xffffc000; unsigned int physfree = init_paging(end-0xC0000000); init_ram(physfree); /* 重定位内核*/ asm volatile( "add sp, sp, #0xC0000000\n\t" ); /*清空恒等隐射*/ for(i = 1; i < NR_KERN_PAGETABLE; i++) PTD[i] = 0; uart_init(); char *_temp = "0000000000\r\n"; unsigned int temp; HexToString((unsigned int)&temp, _temp); uart_puts(_temp); task_init(); unsigned char rank = MAX_rank ; unsigned int task_func = (unsigned int)task_idle0; unsigned char TID = task_create( rank , task_func); task_run(TID); task_func = (unsigned int)task_idle1; TID = task_create( rank , task_func); task_run(TID); task_func = (unsigned int)task_idle2; TID = task_create( rank , task_func); task_run(TID); task_func = (unsigned int)task_idle3; TID = task_create( rank , task_func); task_run(TID); init_arm_timer(Kernel_1Hz); _enable_interrupts(); while(1) { char *_ch = "0000000000\r\n"; for(i = 0; i < 20; i++) { HexToString(PTD[i], _ch); uart_puts(_ch); } for(i = 0; i < 20; i++) { HexToString(PTD[i+0xC00], _ch); uart_puts(_ch); } sleep(500); } }
void eos_start( void ) { DDRB = 0xff; PORTB = 0xff; task_create( led_task, (task_data_t)0x1, &stk[0][99], 0 ); task_create( led_task, ( task_data_t )0x2, &stk[1][99], 0 ); task_create( led_task, ( task_data_t )0x4, &stk[2][99], 0 ); }
void User() { task_create(Motor); task_create(Water); task_create(Console); task_create(Fnd); task_create(Counter); }
static void test_setopt_start() { task_t taskA; taskA = task_create("ttaskA", task_setopt_taskA, NULL, NULL, 0x1000, 150, 0, 0); task_resume_noschedule(taskA); taskSetoptB = task_create("ttaskB", task_setopt_taskB, NULL, NULL, 0x1000, 90, 0, 0); task_resume_noschedule(taskSetoptB); }
/** * Kernel state reset before syscall tests. */ void reset() { initialize_memory(); initialize_tasks(); initialize_scheduling(); initialize_messaging(); t0 = task_create(0, 0, MEDIUM); t1 = task_create(0, 0, MEDIUM); t2 = task_create(0, 1, MEDIUM); }
void uos_init (void) { /* Стираем экран. */ debug_puts ("\33[H\33[2J"); /* Запускаем задачу выдачи статистики на консоль. */ task_create (console, 0, "console", 1, task_console, sizeof (task_console)); /* Запускаем задачу приёма сообщений. */ task_create (receiver, 0, "rcv", 2, task_receiver, sizeof (task_receiver)); }
result_t can_aerospace_init(const neutron_parameters_t *params, bool init_mode) { handle_t task_id; result_t result; hardware_revision = params->hardware_revision; software_revision = params->software_revision; node_id = params->node_id; if (failed(result = deque_create(sizeof(canmsg_t), params->tx_length == 0 ? DEFAULT_TX_QUEUE_SIZE : params->tx_length, &can_tx_queue))) { trace_error("Cannot create can_txt_queue"); return result; } if (failed(result = deque_create(sizeof(canmsg_t), params->rx_length == 0 ? DEFAULT_RX_QUEUE_SIZE : params->rx_length, &can_rx_queue))) { trace_error("Cannot create can_rx_queue"); return result; } if (failed(result = task_create("CAN_TX", params->tx_stack_length, can_tx_task, 0, NORMAL_PRIORITY, &task_id))) { trace_error("Cannot create the can_tx task"); return result; } if (failed(result = task_create("CAN_RX", params->rx_stack_length, can_rx_task, 0, NORMAL_PRIORITY + 1, &task_id))) { trace_error("Cannot create the can_rx task"); return result; } if(failed(result = neutron_init(params, init_mode))) return result; // start the can driver running. return bsp_can_init(can_rx_queue); }
static void test_tasklock_start() { task_t taskA, taskB; taskA = task_create("ttaskA", task_lock_taskA, NULL, NULL, 0x1000, 210, 0, 0); task_resume_noschedule(taskA); taskB = task_create("ttaskB", task_lock_taskB, NULL, NULL, 0x1000, 90, 0, 0); task_resume_noschedule(taskB); task_delay(500); task_destroy(taskA); task_destroy(taskB); }
void uos_init (void) { extern gpanel_font_t font_fixed6x8; /* Стираем экран. */ gpanel_init (&display, &font_fixed6x8); gpanel_clear (&display, 0); /* Запускаем задачу выдачи статистики на консоль. */ task_create (console, 0, "console", 1, task_console, sizeof (task_console)); /* Запускаем задачу приёма сообщений. */ task_create (receiver, 0, "rcv", 2, task_receiver, sizeof (task_receiver)); }
void uos_init (void) { /* Baud 38400. */ outb (((int) (KHZ * 1000L / 38400) + 8) / 16 - 1, UBRR); /* Установлена микросхема 62256 - имеем 32 килобайта памяти. */ /* Разрешаем внешнюю память: порты A - адрес/данные, C - адрес. */ setb (SRE, MCUCR); mem_init (&pool, RAM_START, RAM_END); timer_init (&timer, KHZ, 10); task_create (main_task, 0, "main", 5, task, sizeof (task)); task_create (main_poll, 0, "poll", 1, stack_poll, sizeof (stack_poll)); }
static void test_signal_start() { static task_t tsig1, tsig2; tsig1 = task_create("tsig1", task_signal_taskA, NULL, NULL, 0x1000, 220, 0, 0); task_resume_noschedule(tsig1); tsig2 = task_create("tsig2", task_signal_taskB, NULL, NULL, 0x1000, 210, 0, 0); task_resume_noschedule(tsig2); task_delay(470); sig_task(tsig1, 1); sig_task(tsig2, 7); }
void init() { init_audio(); init_input(); sysclock_start(); sei(); task_create(handle_input, 10, true); }
void uos_init (void) { set_mem(cscon); uart_init (&uart, 0, 90, KHZ, 115200); #if 0 /* Стираем экран. */ printf (&uart, "\33[H\33[2J"); printf (&uart, "\nTesting memory on LDE-Vega board\n"); printf (&uart, "Generator %d.%d MHz, CPU clock %d.%d MHz, bus clock %d.%d MHz\n", ELVEES_CLKIN/1000, ELVEES_CLKIN/100%10, KHZ/1000, KHZ/100%10, MPORT_KHZ/1000, MPORT_KHZ/100%10); #ifdef ENABLE_ICACHE puts (&uart, "Instruction cache enabled\n"); #else puts (&uart, "Instruction cache disabled\n"); #endif #ifdef ENABLE_DCACHE puts (&uart, "Data cache enabled\n"); #else puts (&uart, "Data cache disabled\n"); #endif printf (&uart, " CRPLL = %08X\n", MC_CRPLL); printf (&uart, " CSCON0 = %08X\n", MC_CSCON0); printf (&uart, " CSCON3 = %08X\n", MC_CSCON3); printf (&uart, " SDRCON = %08X\n", MC_SDRCON); printf (&uart, " SDRTMR = %08X\n", MC_SDRTMR); printf (&uart, " SDRTMR = %08X\n", MC_SDRTMR); #endif task_create (main_console, 0, "console", 1, stack_console, sizeof (stack_console)); }
int stm32_usbhost_initialize(void) { int pid; int ret; /* First, register all of the class drivers needed to support the drivers * that we care about: */ uvdbg("Register class drivers\n"); ret = usbhost_storageinit(); if (ret != OK) { udbg("Failed to register the mass storage class\n"); } /* Then get an instance of the USB host interface */ uvdbg("Initialize USB host\n"); g_usbconn = stm32_otgfshost_initialize(0); if (g_usbconn) { /* Start a thread to handle device connection. */ uvdbg("Start usbhost_waiter\n"); pid = task_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); return pid < 0 ? -ENOEXEC : OK; } return -ENODEV; }
int leds_main(int argc, FAR char *argv[]) #endif { FAR char *ledargv[2]; int ret; printf("leds_main: Starting the led_daemon\n"); if (g_led_daemon_started) { printf("leds_main: led_daemon already running\n"); return EXIT_SUCCESS; } ledargv[0] = "led_daemon"; ledargv[1] = NULL; ret = task_create("led_daemon", CONFIG_EXAMPLES_LEDS_PRIORITY, CONFIG_EXAMPLES_LEDS_STACKSIZE, led_daemon, (FAR char * const *)ledargv); if (ret < 0) { int errcode = errno; printf("leds_main: ERROR: Failed to start led_daemon: %d\n", errcode); return EXIT_FAILURE; } printf("leds_main: led_daemon started\n"); return EXIT_SUCCESS; }
void swi_handler_c(uint32_t swi_num, int *r) { switch (swi_num) { case READ_SWI: read(r[0], (void*) r[1], (size_t) r[2]); break; case WRITE_SWI: write(r[0], (void*) r[1], (size_t) r[2]); break; case TIME_SWI: time(); break; case SLEEP_SWI: sleep((unsigned long) r[0]); break; case CREATE_SWI: task_create((task_t*) r[0], (size_t) r[1]); break; case MUTEX_CREATE: mutex_create(); break; case MUTEX_LOCK: mutex_lock(r[0]); break; case MUTEX_UNLOCK: mutex_unlock(r[0]); break; case EVENT_WAIT: event_wait(r[0]); break; default: printf("Illegal SWI number: %x\n", swi_num); disable_interrupts(); while(1); } }
task_t *new_thread(team_t *team, uint32 ip, int kernelspace) { task_t *t; int stack; void *addr; int i; /* xxx this should be cleaner -- have a flag to area_create perhaps */ for(i=1023;i>0;i--){ if(!team->aspace->ptab[i]) break; } stack = area_create(team->aspace, 4096, i*4096, &addr, 0); if(!stack) panic("cannot create a stack area. eek"); t = task_create(team, ip, i*4096+4092, kernelspace); t->ustack = (void *) (i << 12); t->stack_area = rsrc_find(RSRC_AREA,stack); rsrc_bind(&t->rsrc, RSRC_TASK, team); t->flags = tREADY; if(!kernelspace) { rsrc_enqueue(run_queue, t); live_tasks++; } return t; }
task_id_t register_task(struct module *m, void *arg) { task_id_t id; struct task *t; /* Module class must define run_task() to register a task */ if (!m->mclass->run_task) return INVALID_TASK_ID; for (id = 0; id <= MAX_TASKS_PER_MODULE; id++) if (m->tasks[id] == NULL) goto found; /* cannot find an empty slot */ return INVALID_TASK_ID; found: t = task_create(m, arg); if (!t) return INVALID_TASK_ID; m->tasks[id] = t; return id; }
int main(int argc, char **argv) { pid_t parent_pid = getpid(); char *child_argv[2]; pid_t child_pid; printf("Parent: Started, pid=%d\n", parent_pid); sem_init(&g_sem, 0, 0); printf("Parent: Calling task_create()\n"); child_argv[0] = child_arg; child_argv[1] = 0; child_pid = task_create(child_name, 50, 512, child_task, (FAR char * const *)child_argv); if (child_pid < 0) { printf("Parent: task_create failed: %d\n", errno); } printf("Parent: Waiting for child (pid=%d)\n", child_pid); sem_wait(&g_sem); printf("Parent: Exit-ing\n"); sem_destroy(&g_sem); return 0; }
int main(int argc, char** argv) { task_t tasks[3]; tasks[0].lambda = fun1; tasks[0].data = (void*)'s'; tasks[0].stack_pos = (void*)0xa2000000; tasks[0].C = 1; tasks[0].T = PERIOD_DEV0; tasks[1].lambda = fun2; tasks[1].data = (void*)'u'; tasks[1].stack_pos = (void*)0xa1000000; tasks[1].C = 1; tasks[1].T = PERIOD_DEV1; tasks[2].lambda = fun3; tasks[2].data = (void*)'c'; tasks[2].stack_pos = (void*)0xa1200000; tasks[2].C = 1; tasks[2].T = PERIOD_DEV2; task_create(tasks, 3); // just to get rid of compiler... argc = argc; argv = argv; puts("WTF!\n"); return 0; }
void mldr_usbdev_init (usbdev_t *owner, int io_prio, mem_pool_t *pool, mutex_t *m) { usbdev = owner; mem = pool; io_lock = m; usbdevhal_bind (usbdev, &hal, m); //power on the module ARM_RSTCLK->PER_CLOCK |= ARM_PER_CLOCK_USB; ARM_RSTCLK->USB_CLOCK = ARM_USB_C1_SEL(ARM_USB_HSE_DIV2) | ARM_USB_C2_SEL(ARM_USB_PLLUSBo) | ARM_USB_C3_SEL(ARM_USB_C2) | ARM_USB_CLK_EN; ARM_RSTCLK->PLL_CONTROL |= ARM_PLL_CONTROL_USB_ON | ARM_PLL_CONTROL_USB_MUL(48000/KHZ_CLKIN*2); while (! (ARM_RSTCLK->CLOCK_STATUS & ARM_CLOCK_STATUS_PLL_USB_RDY)); ARM_USB->HSCR |= ARM_USB_RESET_CORE; volatile unsigned cnt; for (cnt = 0; cnt < 1000; cnt++); #ifdef MILANDR_USB_LOW_SPEED ARM_USB->HSCR = ARM_USB_D_MINUS_PULLUP; #else ARM_USB->HSCR = ARM_USB_D_PLUS_PULLUP; #endif mldr_usb_reset (); task_create (usb_interrupt, 0, "usb_intr", io_prio, io_stack, sizeof (io_stack)); }
static int create_workqueue_thread(struct workqueue_struct *wq, const char *name) { task_t *task_wq; startup_t startup; int ret; sema_init(&wq->lock, 1); wq->task = NULL; wq->insert_sequence = 0; wq->remove_sequence = 0; INIT_LIST_HEAD(&wq->worklist); init_waitqueue_head(&wq->more_work); init_waitqueue_head(&wq->work_done); init_completion(&wq->exit); init_completion(&startup.done); startup.wq = wq; startup.name = name; task_wq = task_alloc("workqueue", WQ_STACK_SIZE, 1); if (NULL == task_wq) { return -1; } ret = task_create(task_wq, worker_thread, &startup); if (0 == ret) { wait_for_completion(&startup.done); } return ret; }
void uos_init (void) { mil_std_1553_init_pins(MY_MIL_STD_PORT); mil_std_1553_rt_init(&mil_rt, MY_MIL_STD_PORT, MIL_STD_SELF, mil_std_rx_buffer, mil_std_tx_buffer, -1, (void*)0); task_create(test_milstd_rt_main, 0, "test_milstd_rt_main", 1, test_milstd_rt_stack, sizeof(test_milstd_rt_stack)); }