static void handler_KeyTimer(s32 data) { static u16 i1; if(front_timer) { if(front_timer == 1) { static event_t e; e.type = kEventSaveFlash; event_post(&e); preset_mode = 0; front_timer--; } else front_timer--; } for(i1=0;i1<key_count;i1++) { if(key_times[held_keys[i1]]) if(--key_times[held_keys[i1]]==0) { if(preset_mode == 1) { if(held_keys[i1] % 16 == 0) { preset_select = held_keys[i1] / 16; // flash_write(); static event_t e; e.type = kEventSaveFlash; event_post(&e); preset_mode = 0; } } // print_dbg("\rlong press: "); // print_dbg_ulong(held_keys[i1]); } } }
static void irq_port1_line1(void) { // print_dbg("\r\ninterrupt on PB08-PB15."); // clock norm // if(gpio_get_pin_interrupt_flag(B10)) { // static event_t e; // e.type = kEventTrNormal; // e.data = !gpio_get_pin_value(B10); // event_post(&e); // gpio_clear_pin_interrupt_flag(B10); // } // clock in if(gpio_get_pin_interrupt_flag(B08)) { static event_t e; e.type = kEventTr; e.data = gpio_get_pin_value(B08); event_post(&e); gpio_clear_pin_interrupt_flag(B08); } // tr in if(gpio_get_pin_interrupt_flag(B09)) { static event_t e; e.type = kEventTr; e.data = gpio_get_pin_value(B09) + 2; event_post(&e); gpio_clear_pin_interrupt_flag(B09); } }
// perform conversion, check for changes, and post events void adc_poll(void) { #if 1 #else static u16 adcVal[4] = {0, 0, 0, 0}; static event_t e; u8 i; adc_convert(&adcVal); #if 0 for(i=0; i<4; i++) { // TODO: /// probably want more filtering before posting events?? i dunno // if(adcVal[i] != adcOldVal[i]) { /// this is a dirty way! but the two lower bits are pretty noisy. valMask = adcVal[i] & 0xff8; if( valMask != adcOldVal[i] ) { adcOldVal[i] = valMask; e.type = adctypes[i]; // use the data without the mask e.data = (S16)(adcVal[i]); event_post(&e); } } #else /// test with no filtering.. maybe this is fine for(i=0; i<4; i++) { e.type = adctypes[i]; e.data = (S16)(adcVal[i]); event_post(&e); } #endif #endif }
static void irq_port1_line1(void) { // print_dbg("\r\ninterrupt on PB08-PB15."); // static event_t e; // e.type = kSwitchEvents[swIdx]; // e.data = gpio_get_pin_value(kSwitchPins[swIdx]); // event_post(&e); // clock norm if(gpio_get_pin_interrupt_flag(B09)) { static event_t e; e.type = kEventClockNormal; e.data = !gpio_get_pin_value(B09); event_post(&e); gpio_clear_pin_interrupt_flag(B09); } // clock in if(gpio_get_pin_interrupt_flag(B08)) { // CLOCK BOUNCY WITHOUT THESE PRINTS // print_dbg("\rclk: "); // print_dbg_ulong(gpio_get_pin_value(B08)); // (*clock_pulse)(gpio_get_pin_value(B08)); static event_t e; e.type = kEventClockExt; e.data = gpio_get_pin_value(B08); event_post(&e); gpio_clear_pin_interrupt_flag(B08); } }
int main(void) { puts("[START] event test application.\n"); event_queue_t queue = { .waiter = (thread_t *)sched_active_thread }; printf("posting 0x%08x\n", (unsigned)&event); event_post(&queue, &event); printf("posting 0x%08x\n", (unsigned)&event2); event_post(&queue, &event2); printf("canceling 0x%08x\n", (unsigned)&event2); event_cancel(&queue, &event2); printf("posting custom event\n"); event_post(&queue, (event_t *)&custom_event); event_timeout_t event_timeout; printf("posting timed callback with timeout 1sec\n"); event_timeout_init(&event_timeout, &queue, (event_t *)&event_callback); before = xtimer_now_usec(); event_timeout_set(&event_timeout, 100000LU); printf("launching event queue\n"); event_loop(&queue); return 0; }
static void alarm(handler_arg_t arg) { if (leds_active) leds_toggle(LED_0 | LED_1 | LED_2); /* Print help before getting first real \n */ if (print_help) { event_post(EVENT_QUEUE_APPLI, handle_cmd, (handler_arg_t) 'h'); event_post(EVENT_QUEUE_APPLI, handle_cmd, (handler_arg_t) '\n'); } }
static void rx_done(phy_status_t status) { switch (status) { case PHY_SUCCESS: event_post(EVENT_QUEUE_APPLI, process_rx_packet, NULL); break; default: // Bad packet event_post(EVENT_QUEUE_APPLI, enter_rx, NULL); break; } }
void event_wait(event_queue_t queue,MPI_Request *request,MPI_Status *status){ struct event_status e_stat; e_stat.pending=1; e_stat.status=status; event_post(queue,request,copy_status,&e_stat); event_while(queue,&e_stat.pending); }
static void test_task(void *param) { static unsigned int stack1, stack2, stack3; static int a; static char str[128]; static float pi; stack = uxTaskGetStackHighWaterMark( NULL ); sscanf("", ""); stack1 = uxTaskGetStackHighWaterMark( NULL ); sscanf("1", "%d", &a); stack2 = uxTaskGetStackHighWaterMark( NULL ); sscanf("1 string 3.14", "%d", &a, str, &pi); stack3 = uxTaskGetStackHighWaterMark( NULL ); printf("\n"); printf("Base stack %u\n", stack); printf("Post empty scanf %u diff %u\n", stack1, stack - stack1); printf("Post simple scanf %u diff %u\n", stack2, stack - stack2); printf("Post complex scanf %u diff %u\n", stack3, stack - stack3); printf("\n"); event_post(EVENT_QUEUE_APPLI, print_queue_stack, NULL); while (1) asm("wfi"); }
// monome refresh callback static void monome_refresh_timer_callback(void* obj) { if(monomeFrameDirty > 0) { static event_t e; e.type = kEventMonomeRefresh; event_post(&e); } }
static void irq_port0_line1(void) { if(gpio_get_pin_interrupt_flag(NMI)) { // print_dbg("\r\n ### NMI ### "); event_t e = { .type = kEventFront, .data = gpio_get_pin_value(NMI) }; event_post(&e); gpio_clear_pin_interrupt_flag(NMI); } }
// generate events from switch interrupts void process_sw( const U8 swIdx ) { static event_t e; e.type = kSwitchEvents[swIdx]; e.data = gpio_get_pin_value(kSwitchPins[swIdx]); event_post(&e); // print_dbg("\r\n posted switch event "); // print_dbg_ulong(swIdx); }
static int net_connect_req_handler(struct net_handle_cxt* cxt, struct net_req* req) { PLOGD("Entering CONNECT handler!"); struct strbuf* buf = &req->data->buf; PLOGD("HTTP/%d.%d", req->ver_major, req->ver_minor); req->host = req->path; PLOGD("Host: %s", buf->p + req->host); PLOGD("Port: %d", req->port); struct conn* client = cxt->client; PLOGD("From client: %s", ep_tostring(&client->ep)); struct conn* server = net_connect_to_server(cxt, buf->p + req->host, htons(req->port)); if (server == NULL) { // No server available net_bad_gateway(client); return -1; } struct net_handle_list* p = mem_alloc(sizeof(struct net_handle_list)); p->server = server; mem_incref(server); p->next = NULL; p->req = req; mem_incref(req); if (cxt->head == NULL) cxt->head = cxt->tail = p; else { cxt->tail->next = p; cxt->tail = p; } event_post(cxt->ev_notice_rsp, (void*)1); static char msg[] = "HTTP/1.1 200 OK\r\n\r\n"; int ret = conn_write(client, msg, strlen(msg)); if (ret) { net_bad_gateway(client); mem_decref(server, conn_done); return -1; } while (1) { ret = conn_copy(server, client, 64*1024); if (ret) break; } PLOGI("%s CONNECT %s %d", ep_tostring(client), buf->p + req->host, client->tx); mem_decref(server, conn_done); return ret; }
static void irq_port0_line0(void) { for(int i=0;i<8;i++) { if(gpio_get_pin_interrupt_flag(i)) { // print_dbg("\r\n # A00"); event_t e = { .type = kEventTrigger, .data = i }; event_post(&e); gpio_clear_pin_interrupt_flag(i); } } }
// HID device was plugged or unplugged extern void hid_change(uhc_device_t* dev, u8 plug) { event_t e; if(plug) { e.type = kEventHidConnect; } else { e.type = kEventHidDisconnect; } // posting an event so the main loop can respond event_post(&e); }
// MIDI device was plugged or unplugged extern void midi_change(uhc_device_t* dev, u8 plug) { event_t e; if(plug) { e.type = kEventMidiConnect; } else { e.type = kEventMidiDisconnect; } // posting an event so the main loop can respond event_post(&e); // midiConnect = plug; }
// handler to detect front panel button long press static void handler_KeyTimer(s32 data) { if(front_timer) { if(front_timer == 1) { static event_t e; // long press happened - here it fires up the event for SaveFlash e.type = kEventSaveFlash; event_post(&e); front_timer--; } else front_timer--; } }
extern void KeyScanProc(void) { if(KEY_FEED()) // FEED key up { if((keyStatus & KEY_FEED_DB_SHIFT) == 0) // status no changed { if(keyStatus & KEY_FEED_SHIFT) // previous mode key up { event_post(evtKeyUpFeed); // mode key up keyStatus &= ~KEY_FEED_SHIFT; } } else { keyStatus &= ~KEY_FEED_DB_SHIFT;//keyStatus = xxx0 } } else { if(keyStatus & KEY_FEED_DB_SHIFT) // status no changed { if((keyStatus & KEY_FEED_SHIFT) == 0) // previous mode key down { event_post(evtKeyDownFeed); // mode key down keyStatus |= KEY_FEED_SHIFT;// } } else { keyStatus |= KEY_FEED_DB_SHIFT;//keyStatus =xxx1 } } //for burning test,auto post key event if (IsPrinterFree()) { event_post(evtKeyDownFeed); } }
int RT::System::setPeriod(long long period) { ::Event::Object event_pre(::Event::RT_PREPERIOD_EVENT); event_pre.setParam("period",&period); ::Event::Manager::getInstance()->postEvent(&event_pre); SetPeriodEvent event(period); int retval = postEvent(&event); ::Event::Object event_post(::Event::RT_POSTPERIOD_EVENT); event_post.setParam("period",&period); ::Event::Manager::getInstance()->postEvent(&event_post); return retval; }
// encoder accumulator polling callback // the encoder class is defined in avr32_lib. // each encoder object has an accumulator static void enc_timer_callback(void* obj) { static s16 val, valAbs; u8 i; for(i=0; i<NUM_ENC; i++) { val = enc[i].val; valAbs = (val & 0x8000 ? (val ^ 0xffff) + 1 : val); if(valAbs > enc[i].thresh) { e.type = enc[i].event; e.data = val; enc[i].val = 0; event_post(&e); } } }
/* ************************************************************************************************************************ * Post an event (LIFO) to idle task * * Description: This function is called to post an event to idle task, it might be called in interrupt. * * Arguments :me is the address of ACTIVE_EVENT_STRUCT * ----- * sig is the signal which want to be posted to idle task * ----- * para is the parameter which want to be posted to idle task. * * Returns RAW_SUCCESS: raw os return success * RAW_IDLE_EVENT_EXHAUSTED: No more msg to me. * * Note(s) * * ************************************************************************************************************************ */ RAW_OS_ERROR idle_event_front_post(ACTIVE_EVENT_STRUCT *me, RAW_U16 sig, void *para) { #if (CONFIG_RAW_ZERO_INTERRUPT > 0) if (raw_int_nesting && raw_sched_lock) { return int_msg_post(RAW_TYPE_IDLE_FRONT_EVENT_POST, me, para, sig, 0, 0); } #endif return event_post(me, sig, para, SEND_TO_FRONT); }
static void handle_event(handler_arg_t ignored) { int16_t a[3] = { 0, 0 ,0 }; while (lsm303dlhc_acc_get_drdy_int1_pin_value()) lsm303dlhc_read_acc(a); uint32_t accel = a[0]*a[0] + a[1]*a[1] + a[2]*a[2]; if (accel > 800000) return; event_post( EVENT_QUEUE_APPLI, (handler_t)event_handler, (handler_arg_t)accel); }
int main() { // Initialize the platform platform_init(); event_init(); soft_timer_init(); // Begin with RX event_post(EVENT_QUEUE_APPLI, enter_rx, NULL); // Create a periodic packet sending soft_timer_set_handler(&tx_timer, send_packet, NULL); soft_timer_start(&tx_timer, TX_PERIOD, 1); // Run platform_run(); return 0; }
static void sniff_rx(phy_status_t status) { // Switch packets phy_packet_t *rx_packet = radio.sniff.pkt_buf + radio.sniff.pkt_index; radio.sniff.pkt_index = (radio.sniff.pkt_index + 1) % 2; // Enter RX again phy_status_t ret = phy_rx(platform_phy, 0, soft_timer_time() + soft_timer_ms_to_ticks(500), radio.sniff.pkt_buf + radio.sniff.pkt_index, sniff_rx); if (ret != PHY_SUCCESS) { log_error("PHY RX Failed"); } if (status == PHY_SUCCESS) { // Send packet to serial packet_t *serial_pkt = packet_alloc(IOTLAB_SERIAL_PACKET_OFFSET); if (serial_pkt == NULL) { log_error("Failed to get a packet for sniffed RX"); return; } uint8_t *data = serial_pkt->data; // Place timestamp, channel, RSSI, LQI, captured length, as header data = packer_uint32_pack(data, packer_uint32_hton( iotlab_control_convert_time(rx_packet->timestamp))); *data++ = radio.current_channel; *data++ = rx_packet->rssi; *data++ = rx_packet->lqi; *data++ = rx_packet->length; memcpy(data, rx_packet->data, rx_packet->length); data += rx_packet->length; serial_pkt->length = data - serial_pkt->data; event_post(EVENT_QUEUE_APPLI, sniff_send_to_serial, serial_pkt); } }
// parse frame and spawn events void hid_parse_frame(u8* data, u8 size) { u8 i; // one event per frame changed. // event data is bitfield indicating bytes changed. for(i=0; i<size; i++) { hid_set_byte_flag( (u32*)&(ev.data), i, data[i] != frame[i] ); } event_post(&ev); /* // one event per byte changed. */ /* for(i=0; i<size; i++) { */ /* if(data[i] != frame[i]) { */ /* frame[i] = data[i]; */ /* ev.type = kEventHidPacket; */ /* /\* ev.data = frame[i]; *\/ */ /* /\* ev.data |= (i << 8); *\/ */ /* event_post(&ev); */ /* } */ /* } */ }
static void* producer_thread( object_t thread, void* arg ) { uint8_t buffer[256] = {0}; producer_thread_arg_t* args = arg; unsigned int produced = 0; tick_t timestamp = 0; do { if( args->sleep_time ) thread_sleep( (int)args->sleep_time ); else thread_yield(); timestamp = args->max_delay ? time_current() + random64_range( 0, args->max_delay ) : 0; memcpy( buffer, ×tamp, sizeof( tick_t ) ); event_post( args->stream, random32_range( 1, 65535 ), random32_range( timestamp ? 8 : 0, 256 ), args->id, buffer, timestamp ); ++produced; } while( !thread_should_terminate( thread ) && ( time_current() < args->end_time ) ); return (void*)((uintptr_t)produced); }
int main (int argc, char *argv[]) { DWORD sp1, sp2; struct ll_initparms parms; void *mbi; struct timespec time1, time2, time3, time4, time5; struct timespec time6, time7, time8, time9; int par[10]; int i, secs; DWORD oldt, t; sp1 = get_sp(); cli(); #ifdef PERIODIC parms.mode = LL_PERIODIC; parms.tick = T; #else parms.mode = LL_ONESHOT; #endif mbi = ll_init(); event_init(&parms); if (mbi == NULL) { message("Error in LowLevel initialization code...\n"); sti(); l1_exit(-1); } sti(); message("LowLevel started...\n"); /* cli(); */ NULL_TIMESPEC(&time1); NULL_TIMESPEC(&time2); NULL_TIMESPEC(&time3); NULL_TIMESPEC(&time4); NULL_TIMESPEC(&time5); NULL_TIMESPEC(&time6); NULL_TIMESPEC(&time7); NULL_TIMESPEC(&time8); NULL_TIMESPEC(&time9); ADDNANO2TIMESPEC(1000000, &time1); /* Time1: 1 ms */ ADDNANO2TIMESPEC(5000000, &time2); /* Time2: 5 ms */ ADDNANO2TIMESPEC(10000000, &time3); /* Time 3: 10 ms */ ADDNANO2TIMESPEC(3000000, &time4); /* Time 4: 3 ms */ ADDNANO2TIMESPEC(7500000, &time5); /* Time 5: 7.5 ms */ ADDNANO2TIMESPEC(7000000, &time6); /* Time 6: 7 ms */ ADDNANO2TIMESPEC(500000000, &time7); ADDNANO2TIMESPEC(500000000, &time7); ADDNANO2TIMESPEC(500000000, &time7); ADDNANO2TIMESPEC(500000000, &time7); ADDNANO2TIMESPEC(500000000, &time7); ADDNANO2TIMESPEC(500000000, &time7); /* Time 7: 6*500 ms = 3 Sec*/ ADDNANO2TIMESPEC(51700000, &time8); /* Time 8: 51.7 ms */ ADDNANO2TIMESPEC(51500000, &time9); /* Time 9: 51.5 ms */ cli(); t = ll_gettime(TIME_NEW, NULL); sti(); for (i = 0; i < 10; i++) { par[i] = i + 1; } canEnd = 0; cli(); event_post(time1, evtHandler, &(par[0])); event_post(time2, evtHandler, &(par[1])); event_post(time3, evtHandler, &(par[2])); event_post(time4, evtHandler, &(par[3])); event_post(time5, evtHandler, &(par[4])); i = event_post(time6, evtHandler, &(par[5])); event_post(time7, evtHandler, &(par[6])); event_post(time8, evtHandler, &(par[7])); event_post(time9, evtHandler, &(par[8])); event_delete(i); event_post(time5, evtHandler, &(par[5])); message("Now time is %lu\n", t); secs = 0; oldt = 0; canEnd = 0; while((canEnd == 0) && (secs < 6)) { cli(); t = ll_gettime(TIME_NEW, NULL); sti(); if (t < oldt) { error("Time goes back???\n"); message("ARGGGGG! %lu %lu\n", t, oldt); ll_abort(100); } oldt = t; if ((t / 1000000) > secs) { secs++; message(" %d %lu\n", secs, t); } } cli(); message("Can End detected\n"); ll_end(); sp2 = get_sp(); for (i = 1; i < 10; i++) { message("Event %d called at time %lu == %lu\n", id[i], t1[i], t2[i]); } message("End reached!\n"); message("Actual stack : %lx - ", sp2); message("Begin stack : %lx\n", sp1); message("Check if same : %s\n",sp1 == sp2 ? "Ok :-)" : "No :-("); return 1; }
static void adcTimer_callback(void* o) { static event_t e; e.type = kEventPollADC; e.data = 0; event_post(&e); }
void system_post_event( foundation_event_id event ) { event_post( _system_event_stream, event, 0, 0, 0, 0 ); }
void system_post_event( foundation_event_id event ) { event_post( _system_event_stream, SYSTEM_FOUNDATION, event, 0, 0, 0, 0 ); }