void context_switch_test(void) { event_init(&context_switch_event, false, 0); event_init(&context_switch_done_event, false, 0); thread_detach_and_resume(thread_create("context switch idle", &context_switch_tester, (void *)1, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_sleep(100); event_signal(&context_switch_event, true); event_wait(&context_switch_done_event); thread_sleep(100); event_unsignal(&context_switch_event); event_unsignal(&context_switch_done_event); thread_detach_and_resume(thread_create("context switch 2a", &context_switch_tester, (void *)2, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_detach_and_resume(thread_create("context switch 2b", &context_switch_tester, (void *)2, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_sleep(100); event_signal(&context_switch_event, true); event_wait(&context_switch_done_event); thread_sleep(100); event_unsignal(&context_switch_event); event_unsignal(&context_switch_done_event); thread_detach_and_resume(thread_create("context switch 4a", &context_switch_tester, (void *)4, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_detach_and_resume(thread_create("context switch 4b", &context_switch_tester, (void *)4, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_detach_and_resume(thread_create("context switch 4c", &context_switch_tester, (void *)4, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_detach_and_resume(thread_create("context switch 4d", &context_switch_tester, (void *)4, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_sleep(100); event_signal(&context_switch_event, true); event_wait(&context_switch_done_event); thread_sleep(100); }
//dev3 void fun1(void* str) { int cur_mutex=1; str = str; while(cur_mutex<MUTEX_NUM){ putchar((int)str); printf(">>mutex %d\n",cur_mutex); if(mutex_lock(cur_mutex)) panic("Failed to acquire mutex"); mutex_val[cur_mutex]=mutex_val[cur_mutex]+fun1_opval; if(mutex_unlock(cur_mutex)) { if(errno==EINVAL) puts("EINVAL"); if(errno==EPERM) puts("EPERM"); panic("Failed to release mutex"); } cur_mutex++; if (event_wait(3) < 0) panic("Dev 3 failed"); } while(1) if (event_wait(3) < 0) panic("Dev 3 failed"); }
//dev2 void fun4(void* str) { int cur_mutex=1,i=0,m_val; str = str; while(cur_mutex<MUTEX_NUM){ putchar((int)str); printf(">>mutex %d\n",cur_mutex); if(mutex_lock(cur_mutex)) panic("Failed to acquire mutex"); mutex_val[cur_mutex]=mutex_val[cur_mutex]*fun4_opval; if(mutex_unlock(cur_mutex)) panic("Failed to release mutex"); cur_mutex++; if (event_wait(2) < 0) panic("Dev 2 failed"); } for(;i<MUTEX_NUM;i++) { m_val=mutex_val[i]; printf("Final mutex%d value %d == result value %d\n",i,m_val,result_val); if(m_val==result_val) puts(YES_STR); else puts(NO_STR); } puts(TEST_DONE); while(1) if (event_wait(2) < 0) panic("Dev 2 failed"); }
static int display_server_thread(void *args) { for (;;) { // wait for start event dprintf(INFO, "%s: IDLE\n", __func__); if (event_wait(&e_start_server) < 0) { dprintf(INFO, "%p: event_wait() returned error\n", get_current_thread()); return -1; } // main worker loop dprintf(INFO, "%s: START\n", __func__); is_running = 1; // ignore first key to prevent unwanted interactions getkey(); int keycode = 0; for(;;) { // render frame if(renderer) renderer(keycode); // signal refresh event_signal(&e_frame_finished, true); // poll key lk_time_t last_refresh = current_time(); while(!(keycode=getkey()) && !request_stop && !request_refresh) { // refresh every 59s if((current_time()-last_refresh)>=59000) break; thread_yield(); } // stop request if(request_stop) { request_stop = 0; break; } // refresh request if(request_refresh) { request_refresh = 0; } event_wait(&e_continue); } dprintf(INFO, "%s: EXIT\n", __func__); is_running = 0; } return 0; }
void button_task(void) { task_open(); // init the Interrupt P3IES = 0xF8; P3OUT = 0xF8; P3REN = 0xF8; P3IFG = 0; P3IE = 0xF8; while(1) { event_wait(buttonEvent); // wait till button pressed buttonHoldDuration = 0; while(buttonMask != 0xF8) { // count the number of ticks that have elapsed. task_wait(10); buttonHoldDuration++; buttonMask = (P3IN & 0xF8); } //buttonMask = 0; } task_close(); }
void event_Recv(event_queue_t queue, void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status){ MPI_Request request; int res = MPI_Irecv(buf,count,datatype,source,tag,comm,&request); if (res != MPI_SUCCESS) Abort("MPI_Irecv"); event_wait(queue,&request,status); }
size_t cbuf_read_char(cbuf_t *cbuf, char *c, bool block) { DEBUG_ASSERT(cbuf); DEBUG_ASSERT(c); enter_critical_section(); if (block) event_wait(&cbuf->event); // see if there's data available size_t ret = 0; if (cbuf->tail != cbuf->head) { *c = cbuf->buf[cbuf->tail]; cbuf->tail = INC_POINTER(cbuf, cbuf->tail, 1); if (cbuf->tail == cbuf->head) { // we've emptied the buffer, unsignal the event event_unsignal(&cbuf->event); } ret = 1; } exit_critical_section(); return ret; }
void fun1(void* str) { int ret2,i,ind; str = str; for(i=0 ;i<MAX_MUTEX;i++) { ind = mutex_create(); } ret2 = mutex_create(); check_return(errno,ENOMEM,"3. Mutex Create returns ENOMEM"); ret2 = mutex_unlock(165); check_return(errno,EINVAL,"4. Mutex Unlock return EINVAL"); ret2 = mutex_unlock(23); check_return(errno,EPERM,"5. Mutex Unlock return EPERM"); ret2 = mutex_lock(124); check_return(errno,EINVAL,"6. Mutex Lock return EINVAL"); ret2 = mutex_lock(4); check_return(ret2,0,"7. Mutex Lock return success"); ret2 = mutex_lock(4); check_return(errno,EDEADLOCK,"8. Mutex Lock return EDEADLOCK"); ret2 = mutex_unlock(4); check_return(ret2,0,"9. Mutex Unlock return success"); ret2 = event_wait(10000); check_return(errno,EINVAL,"10. Event Wait return EINVAL"); puts("TEST END!\n"); while(1) { spin++; } }
void ssbi_keypad_init(struct qwerty_keypad_info *qwerty_kp) { unsigned int mach_id; int len; len = sizeof(struct gpio_qwerty_kp); qwerty_keypad = malloc(len); ASSERT(qwerty_keypad); memset(qwerty_keypad, 0, len); qwerty_keypad->keypad_info = qwerty_kp; event_init(&qwerty_keypad->full_scan, false, EVENT_FLAG_AUTOUNSIGNAL); timer_initialize(&qwerty_keypad->timer); mach_id = board_machtype(); ssbi_gpio_init(mach_id); if(mach_id == LINUX_MACHTYPE_8660_QT) { mdelay((qwerty_keypad->keypad_info)->settle_time); #ifdef QT_8660_KEYPAD_HW_BUG timer_set_oneshot(&qwerty_keypad->timer, 0, scan_qt_keypad, NULL); #endif } else timer_set_oneshot(&qwerty_keypad->timer, 0, scan_qwerty_keypad, NULL); /* wait for the keypad to complete one full scan */ event_wait(&qwerty_keypad->full_scan); }
size_t cbuf_read_char(cbuf_t* cbuf, char* c, bool block) { DEBUG_ASSERT(cbuf); DEBUG_ASSERT(c); retry: if (block) { event_wait(&cbuf->event); } size_t ret = 0; { AutoSpinLock guard(&cbuf->lock); // see if there's data available if (cbuf->tail != cbuf->head) { *c = cbuf->buf[cbuf->tail]; cbuf->tail = inc_pointer(cbuf, cbuf->tail, 1); if (cbuf->tail == cbuf->head) { // we've emptied the buffer, unsignal the event event_unsignal(&cbuf->event); } ret = 1; } } if (block && ret == 0) { goto retry; } return ret; }
static int virtio_gpu_flush_thread(void *arg) { struct virtio_gpu_dev *gdev = (struct virtio_gpu_dev *)arg; status_t err; for (;;) { event_wait(&gdev->flush_event); /* transfer to host 2d */ err = transfer_to_host_2d(gdev, gdev->display_resource_id, gdev->pmode.r.width, gdev->pmode.r.height); if (err < 0) { LTRACEF("failed to flush resource\n"); continue; } /* resource flush */ err = flush_resource(gdev, gdev->display_resource_id, gdev->pmode.r.width, gdev->pmode.r.height); if (err < 0) { LTRACEF("failed to flush resource\n"); continue; } } return 0; }
void fun2(void* str) { int i; while(1) { if(once < NUM_ITER) { once++; puts("One more time"); } else { // check RMA for(i=0;i<(NUM_TASK-2);i++) { if(score[i] < score[i+1]) { printf("RMA check failed on %d\n",i); puts("xxxxxxxxxx Test FAIL xxxxxxxx"); } if(score[i] == 0) { printf("Task %d never executed?\n",i); puts("xxxxxxxxxx Test FAIL xxxxxxxxx"); } } puts("*********** Test PASEED *******************"); flag = 1; } if (event_wait((int)str) < 0) panic("Dev 0 failed"); } }
// task desc: sit and wait for buzzer request.. // when req recv. timeout and stop buzzer void buzzer_task(void) { task_open(); // some initial init P2SEL0 |= BUZZER; //assign TB2.0 to BUZZER P2DIR |= BUZZER; while(1){ // sit and wait event_wait(buzzerEvent); // configure timer B2 TB2CCR0 = 650; TB2CTL = TASSEL_2 + MC_3 + TACLR; TB2CCTL0 = OUTMOD_4; // timeout? task_wait(20); // clean up, disabling timer will save power // ensure NPN is off to reduce current through buzzer. TB2CCTL0 = 0; // this will clear OUT, setting BUZZER LOW TB2CTL = 0; // disable timer } // never ends task_close(); }
void home_task(void) { task_open(); current_menu_item = 1; current_tid = 0; while(1) { if( current_tid == 0) { clearBuff(); setxy(2,4); xprint("%s\n0x%04X",mainMenu[current_menu_item].name,mainMenu[current_menu_item].task ); lcd_xmit(); } event_wait( buttonEvent ); char button_state = button_get_pressed(); if(current_tid == 0) { if(( button_state & BUTTON_DOWN )&&( current_menu_item > 0 )) { current_menu_item--; // antmation? } else if(( button_state & BUTTON_UP )&&( current_menu_item < N_MENU -1 )) { current_menu_item++; } else if(( button_state & BUTTON_SELECT )) // no task running { // call up a new task task_create( mainMenu[current_menu_item].task, 10, 0, 0, 0 ); // should be a lower priority than this task // store tid current_tid = 1;//task_id_get( mainMenu[current_menu_item].task ); } } else { if(( button_state & BUTTON_MENU )) { task_kill( mainMenu[current_menu_item].task ); current_tid = 0; } } task_wait(10); //P2OUT ^= BIT3; } task_close(); }
rstatus_t core_loop(struct context *ctx) { int nsd, delta; int64_t now; now = nc_msec_now(); while (now >= ctx->next_tick) { core_tick(ctx); ctx->next_tick += NC_TICK_INTERVAL; } delta = (int)(ctx->next_tick - now); ASSERT(delta > 0); ctx->timeout = MIN(delta, ctx->timeout); nsd = event_wait(ctx->evb, ctx->timeout); if (nsd < 0) { return nsd; } core_timeout(ctx); stats_swap(ctx->stats); return NC_OK; }
static void imx_dputs(const char* str, size_t len, bool block, bool map_NL) { spin_lock_saved_state_t state; bool copied_CR = false; if (!uart_base) { return; } if (!uart_tx_irq_enabled) { block = false; } spin_lock_irqsave(&uart_spinlock, state); while (len > 0) { // is FIFO full? while ((UARTREG(MX8_UTS) & UTS_TXFULL)) { spin_unlock_irqrestore(&uart_spinlock, state); if (block) { event_wait(&uart_dputc_event); } else { arch_spinloop_pause(); } spin_lock_irqsave(&uart_spinlock, state); } if (*str == '\n' && map_NL && !copied_CR) { copied_CR = true; imx_uart_pputc('\r'); } else { copied_CR = false; imx_uart_pputc(*str++); len--; } } spin_unlock_irqrestore(&uart_spinlock, state); }
static inline int multi_tcp_wait(const struct context *c, struct multi_tcp *mtcp) { int status; socket_set_listen_persistent(c->c2.link_socket, mtcp->es, MTCP_SOCKET); tun_set(c->c1.tuntap, mtcp->es, EVENT_READ, MTCP_TUN, &mtcp->tun_rwflags); #ifdef ENABLE_MANAGEMENT if (management) { management_socket_set(management, mtcp->es, MTCP_MANAGEMENT, &mtcp->management_persist_flags); } #endif #ifdef ENABLE_ASYNC_PUSH /* arm inotify watcher */ event_ctl(mtcp->es, c->c2.inotify_fd, EVENT_READ, MTCP_FILE_CLOSE_WRITE); #endif status = event_wait(mtcp->es, &c->c2.timeval, mtcp->esr, mtcp->maxevents); update_time(); mtcp->n_esr = 0; if (status > 0) { mtcp->n_esr = status; } return status; }
void c_main(void) { address_t address = system_load_sram(); if (!data_system(region_start(1, address)) || !data_get_output_keys(region_start(2, address)) || !input_filter_get_filters(&g_input, region_start(3, address)) || !input_filter_get_filter_routes(&g_input, region_start(4, address)) || !data_get_transform(region_start(5, address)) ) { io_printf(IO_BUF, "[Filter] Failed to initialise.\n"); return; } // Setup timer tick, start spin1_set_timer_tick(g_filter.machine_timestep); spin1_callback_on(MCPL_PACKET_RECEIVED, mcpl_callback, -1); spin1_callback_on(TIMER_TICK, filter_update, 2); while (true) { // Wait for data loading, etc. event_wait(); // Determine how long to simulate for config_get_n_ticks(); // Perform the simulation spin1_start(SYNC_WAIT); } }
void c_main(void) { // Load in all data address_t address = system_load_sram(); if (!get_packets(region_start(2, address), &start_packets) || !get_packets(region_start(4, address), &end_packets) ) { return; } spin1_set_timer_tick(1000); spin1_callback_on(TIMER_TICK, tick, 2); while(true) { // Wait for data loading, etc. event_wait(); // Determine how long to simulate for config_get_n_ticks(); // Transmit all packets assigned to be sent prior to the start of the // simulation transmit_packet_region(start_packets); // Synchronise with the simulation spin1_start(SYNC_WAIT); } }
static void usbtest_entry(const struct app_descriptor *app, void *args) { LTRACE_ENTRY; TRACEF("starting usb stack\n"); usb_start(); // XXX get callback from stack thread_sleep(2000); TRACEF("queuing transfers\n"); queue_rx_transfer(); queue_tx_transfer(); while (event_wait(&testevent) == NO_ERROR) { if (!rxqueued) { /* dump the state of the transfer */ LTRACEF("rx transfer completed\n"); usbc_dump_transfer(&rx); hexdump8(rx.buf, MIN(128, rx.bufpos)); queue_rx_transfer(); } if (!txqueued) { /* dump the state of the transfer */ LTRACEF("tx transfer completed\n"); usbc_dump_transfer(&tx); queue_tx_transfer(); } } LTRACE_EXIT; }
void fun1(void* str) { // On first pass, create the shared mutex mid = mutex_create(); while(1) { if(even_t1) { // first and last s putchar((int)str); // terminating if(once >0) { putchar((int)'!'); while(1) mid++; } once = 1; even_t1 = 0; } else { // should not succeed right away mutex_lock(mid); // prints e putchar((int)'e'); even_t1 = 1; mutex_unlock(mid); } if (event_wait(0) < 0) { panic("Dev 0 failed"); } } }
bool video_output_wait(video_t video) { if (!video) return false; event_wait(video->update_event); return event_try(video->stop_event) == EAGAIN; }
int usb_write(void *buf, unsigned len) { int r; if (fastboot_state == STATE_ERROR) goto oops; req->buf = buf; req->length = len; req->complete = req_complete; r = udc_request_queue(in, req); if (r < 0) { dprintf(INFO, "usb_write() queue failed\n"); goto oops; } event_wait(&txn_done); if (txn_status < 0) { dprintf(INFO, "usb_write() transaction failed\n"); goto oops; } return req->length; oops: fastboot_state = STATE_ERROR; return -1; }
void cos_init(void *arg) { static volatile int first = 1, second = 1; if (first) { first = 0; union sched_param sp; sp.c.type = SCHEDP_PRIO; sp.c.value = 10; if (sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG(); return; } else if (second) { // high prio thd union sched_param sp; second = 0; init(); sp.c.type = SCHEDP_PRIO; sp.c.value = 20; if (sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG(); event_wait(); } else { // low prio thd. keep writing tsc while (1) rdtscll(t_0); } }
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); } }
int download_ex(u32 data_length)//Big image and parallel transfer. { thread_t *thr; init_engine_context(&ctx); init_sto_info(&sto_info, FALSE); //no checksum enabled. sto_info.to_write_data_len = data_length; thr = thread_create("fastboot", write_storage_proc, 0, DEFAULT_PRIORITY, 16*1024); if (!thr) { return -1; } thread_resume(thr); TIME_START; read_usb_proc(&data_length); //wait for write thread end. event_wait(&ctx.thr_end_ev); destroy_engine(&ctx); if(ctx.b_error) { fastboot_fail_wrapper("\n@DOWNLOAD ERROR@\nPlease re-plug your USB cable\n"); fastboot_state = STATE_ERROR; }else { fastboot_okay(""); } return 0; }
static int fastboot_handler(void *arg) { for (;;) { event_wait(&usb_online); fastboot_command_loop(); } return 0; }
void event_Ssend(event_queue_t queue,void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm){ MPI_Request request; MPI_Status status; int res = MPI_Issend(buf,count,datatype,dest,tag,comm,&request); if (res != MPI_SUCCESS) Abort("MPI_Issend"); event_wait(queue,&request,&status); }
static void sam3x_dac_start(struct Dac *dac, void *_buf, size_t len, size_t slice_len) { ASSERT(dac); ASSERT(len >= slice_len); /* Reset the previous status. */ dac->hw->end = false; sample_buff = (uint16_t *)_buf; next_idx = 0; chunk_size = slice_len; remaing_size = len; /* Program the dma with the first and second chunk of samples and update counter */ dac->ctx.callback(dac, &sample_buff[0], chunk_size); DACC_TPR = (uint32_t)&sample_buff[0]; DACC_TCR = chunk_size; remaing_size -= chunk_size; next_idx += chunk_size; if (chunk_size <= remaing_size) { dac->ctx.callback(dac, &sample_buff[next_idx], chunk_size); DACC_TNPR = (uint32_t)&sample_buff[next_idx]; DACC_TNCR = chunk_size; remaing_size -= chunk_size; next_idx += chunk_size; } DACC_PTCR |= BV(DACC_PTCR_TXTEN); DACC_IER = BV(DACC_ENDTX); /* Set up timer and trig the conversions */ tc_setup(dac->hw->rate, len); tc_start(); while (1) { event_wait(&buff_emtpy); if (dac->hw->end) break; remaing_size -= chunk_size; next_idx += chunk_size; if (remaing_size <= 0) { remaing_size = len; next_idx = 0; } dac->ctx.callback(dac, &sample_buff[next_idx], chunk_size); } }
void smd_uninit(smd_channel_info_t *ch) { event_init(&smd_closed, false, EVENT_FLAG_AUTOUNSIGNAL); smd_set_state(ch, SMD_SS_CLOSING, 1); smd_notify_rpm(); /* Wait for the SMD-RPM channel to be closed */ event_wait(&smd_closed); }