PROCESS_THREAD(node_timeout_process, ev, data) { PROCESS_BEGIN(); while (1) { static struct etimer timeout; int16_t sensor_value = 0; static char message[3]; etimer_set(&timeout, CLOCK_SECOND * SLEEP_TIMEOUT); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timeout)); etimer_set(&timeout, CLOCK_SECOND/16); leds_on(LEDS_ALL); sensor_init(); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timeout)); sensor_value = sensor_read() - my_noise; sensor_uinit(); itoa(sensor_value, message, 10); strcat(message, "!\0"); transmit_runicast(message, SINK_NODE); leds_off(LEDS_ALL); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ static int detect_ack(void) { #define INTER_PACKET_INTERVAL RTIMER_ARCH_SECOND / 5000 #define ACK_LEN 3 #define AFTER_ACK_DETECTECT_WAIT_TIME RTIMER_ARCH_SECOND / 1000 rtimer_clock_t wt; uint8_t ack_received = 0; wt = RTIMER_NOW(); leds_on(LEDS_GREEN); while(RTIMER_CLOCK_LT(RTIMER_NOW(), wt + INTER_PACKET_INTERVAL)) { } leds_off(LEDS_GREEN); /* Check for incoming ACK. */ if((NETSTACK_RADIO.receiving_packet() || NETSTACK_RADIO.pending_packet() || NETSTACK_RADIO.channel_clear() == 0)) { int len; uint8_t ackbuf[ACK_LEN + 2]; wt = RTIMER_NOW(); while(RTIMER_CLOCK_LT(RTIMER_NOW(), wt + AFTER_ACK_DETECTECT_WAIT_TIME)) { } len = NETSTACK_RADIO.read(ackbuf, ACK_LEN); if(len == ACK_LEN) { ack_received = 1; } } if(ack_received) { leds_toggle(LEDS_RED); } return ack_received; }
int main() { // Initialize the platform platform_init(); //fiteco_lib_gwt_opennode_power_select(FITECO_GWT_OPENNODE_POWER__OFF); /* compatibility with HiKoB */ if (uart_external == NULL) uart_external = uart_print; else uart_enable(uart_external, 500000); // Start the soft timer soft_timer_init(); //set the open node power to off and charge the battery //fiteco_lib_gwt_opennode_power_select(FITECO_GWT_OPENNODE_POWER__MAIN); fiteco_lib_gwt_opennode_power_select(FITECO_GWT_OPENNODE_POWER__OFF); fiteco_lib_gwt_battery_charge_enable(); fiteco_lib_gwt_opennode_power_select(FITECO_GWT_OPENNODE_POWER__MAIN); cn_i2c_start(); //initialize the led, red off, green on leds_off(LEDS_MASK); leds_on(GREEN_LED); uart_set_rx_handler(uart_print, char_rx, NULL); // Run platform_run(); return 0; }
static void k2_test(void) { if (GPH2DAT & (1<<1)) leds_off(2); else leds_on(2); }
static void cs8900_service(struct netif *netif) { u8_t events2service = CS8900_EVTS2SRV; #if (CS8900_STATS > 0) u16_t miss_count = 0, coll_count = 0; #endif // NOTES: // static, so only initialized to zero at program start. // irq_status will always hold the last ISQ event register that // still needs service. As such, we may leave this function if // we encounter an event we cannot service yet, and return later // to try to service it. static u16_t irq_status = 0x0000U; // The "cs8900_needs_service" flag indicates whether any events // still need to be serviced. // clear flag here. // a receive interrupt can, *concurrently with this function*, // set this flag on new ISQ event occurences. // we will re-evaluate the correct setting of this flag at // function exit (below). ((struct cs8900if *)netif->state)->needs_service = 0; #ifdef LED_NEED_SERVICE leds_off(LED_NEED_SERVICE); #endif /* no unhandled irq_status left? */ if (irq_status == 0x0000U) { /* read ISQ register */ irq_status = ISQ; } /* ISQ interrupt event, and allowed to service in this loop? */ while ((irq_status != 0x0000U) && (events2service-- > 0)) { /* investigate event */ if ((irq_status & 0x003fU) == 0x0004U/*Receiver Event*/) { /* correctly received frame, either broadcast or individual address */ /* TODO: think where these checks should appear: here or in cs8900_input() */ if ((irq_status & 0x0100U/*RxOK*/) && (irq_status & 0x0c00U/*Broadcast | Individual*/)) { /* read the frame from the cs8900a */ cs8900if_input(netif); } else { /* skip this frame */ PACKETPP = CS_PP_RXCFG; PPDATA |= 0x0040U/*Skip_1*/; #if (CS8900_STATS > 0) ((struct cs8900if *)netif->state)->dropped++; #endif } } #if (CS8900_STATS > 0) else if ((irq_status & 0x003fU) == 0x0010U/*RxMISS Event*/) { miss_count += (irq_status >> 6); } else if ((irq_status & 0x003fU) == 0x0012U/*TxCOL Event*/)
static void k1_test(void) { if (GPH2DAT & (1<<0)) leds_off(1); else leds_on(1); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_change_detect_process, ev, data) { static struct etimer etimer; PROCESS_BEGIN(); leds_init(); while(1) { sensor_init(); etimer_set(&etimer, CLOCK_SECOND / 4); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); sample = sensor_read(); sensor_uinit(); printf("sample = %d\n",sample); if(abs_sub(sample, sample_mean) > (sample_std_dev * NUM_DEVS)) { // Change detected, turn on LED(s)? leds_on(LEDS_RED); } else { // Turn off LED(s). leds_off(LEDS_RED); } } PROCESS_END(); }
PROCESS_THREAD(node_read_process, ev, data) { PROCESS_BEGIN(); static struct etimer etimer; static int16_t sensor_value = 0; static char message[3]; etimer_set(&etimer, CLOCK_SECOND * sleep_time); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etimer)); etimer_set(&etimer, CLOCK_SECOND/16); leds_on(LEDS_ALL); sensor_init(); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etimer)); sensor_value = sensor_read() - my_noise; sensor_uinit(); itoa(sensor_value, message, 10); strcat(message, "!\0"); transmit_runicast(message, SINK_NODE); leds_off(LEDS_ALL); // process_start(&node_timeout_process, NULL); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ static int write_state(lwm2m_context_t *ctx, const uint8_t *inbuf, size_t insize, uint8_t *outbuf, size_t outsize) { int value; size_t len; uint8_t idx = ctx->object_instance_index; if(idx >= LEDS_CONTROL_NUMBER) { return 0; } len = ctx->reader->read_boolean(ctx, inbuf, insize, &value); if(len > 0) { if(value) { if(!states[idx].is_on) { states[idx].is_on = 1; states[idx].last_on_time = clock_seconds(); #if PLATFORM_HAS_LEDS leds_on(1 << idx); #endif /* PLATFORM_HAS_LEDS */ } } else if(states[idx].is_on) { states[idx].total_on_time += clock_seconds() - states[idx].last_on_time; states[idx].is_on = 0; #if PLATFORM_HAS_LEDS leds_off(1 << idx); #endif /* PLATFORM_HAS_LEDS */ } } else { PRINTF("IPSO leds control - ignored illegal write to on/off\n"); } return len; }
/*---------------------------------------------------------------------------*/ static void timeout_handler(void) { static int seq_id; struct uip_udp_conn *this_conn; leds_on(LEDS_RED); memset(buf, 0, MAX_PAYLOAD_LEN); seq_id++; /* evens / odds */ if(seq_id & 0x01) { this_conn = l_conn; } else { this_conn = g_conn; if(uip_ds6_get_global(ADDR_PREFERRED) == NULL) { return; } } PRINTF("Client to: "); PRINT6ADDR(&this_conn->ripaddr); memcpy(buf, &seq_id, sizeof(seq_id)); PRINTF(" Remote Port %u,", UIP_HTONS(this_conn->rport)); PRINTF(" (msg=0x%04x), %u bytes\n", *(uint16_t *) buf, sizeof(seq_id)); uip_udp_packet_send(this_conn, buf, sizeof(seq_id)); leds_off(LEDS_RED); }
void keypad_set_leds( uint16_t mask ) { leds = mask; leds_off( ); keypad_write_cols( ~leds ); leds_on( ); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_server_process, ev, data) { // uint16_t ipaddr=(uint16_t) IP_TRANS128; //#if UIP_CONF_ROUTER uip_ipaddr_t ipaddr;//=IP_TRANS128; uip_ip6addr(&ipaddr,0xfe80,0,0,0,0x2001,0x22ff,0xfe33,0x4455); //#endif /* UIP_CONF_ROUTER */ PROCESS_BEGIN(); SENSORS_ACTIVATE(button_sensor);//activate button leds_init(); leds_off(LEDS_ALL); simple_udp_register(&udp_connection, UDP_PORT, NULL, UDP_PORT, receiver); while(1) { // printf("bla1"); PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor); // PROCESS_YIELD(); send_data(&ipaddr); } PROCESS_END(); }
void hw_init() { #if defined (PLATFORM_HAS_LEDS) leds_off(LEDS_RED); #endif }
int main() { // Initialize the platform platform_init(); printf("SysTick test program\n"); // Set initial values leds_on(LED_0); leds_off(LED_1); // Enable the SysTick, 100Hz nvic_enable_systick(100, alarm, 0); while (1) { int i; for (i = 0; i < 0x80000; i++) { __asm__("nop"); } leds_toggle(LED_1); } return 0; }
void hw_init() { #if PLATFORM_HAS_LEDS leds_off(LEDS_RED); #endif }
/*---------------------------------------------------------------------------*/ static void pub_handler(const char *topic, uint16_t topic_len, const uint8_t *chunk, uint16_t chunk_len) { DBG("Pub Handler: topic='%s' (len=%u), chunk_len=%u\n", topic, topic_len, chunk_len); /* If we don't like the length, ignore */ if(topic_len != 23 || chunk_len != 1) { printf("Incorrect topic or chunk len. Ignored\n"); return; } /* If the format != json, ignore */ if(strncmp(&topic[topic_len - 4], "json", 4) != 0) { printf("Incorrect format\n"); } if(strncmp(&topic[10], "leds", 4) == 0) { if(chunk[0] == '1') { leds_on(LEDS_RED); } else if(chunk[0] == '0') { leds_off(LEDS_RED); } return; } }
/*--- codigo de funciones ---*/ void Main(void) { /* Inicializa controladores */ sys_init(); // Inicializacion de la placa, interrupciones y puertos timer_init(); // Inicializacion del temporizador mybutton_init(); // inicializamos los pulsadores. Cada vez que se pulse se verá reflejado en el 8led D8Led_init(); // inicializamos el 8led /* Valor inicial de los leds */ leds_off(); led1_on(); while (1) { /* Cambia los leds con cada interrupcion del temporizador */ if (switch_leds == 1) { leds_switch(); switch_leds = 0; } comprobar_boton(); } }
static void k3_test(void) { if (GPH2DAT & (1<<2)) leds_off(3); else leds_on(3); }
void hw_init() { leds_off(LEDS_RED); statusledinit(); key_init(); }
static void k4_test(void) { if (GPH2DAT & (1<<3)) leds_off(4); else leds_on(4); }
void led1_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { size_t len = 0; const char *mode = NULL; uint8_t led = 0; int success = 1; led = LEDS_RED; if (success && (len=REST.get_post_variable(request, "mode", &mode))) { PRINTF("mode %s\n", mode); if (strncmp(mode, "on", len)==0) { leds_on(led); } else if (strncmp(mode, "off", len)==0) { leds_off(led); } else { success = 0; } } else { success = 0; } if (!success) { REST.set_response_status(response, REST.status.BAD_REQUEST); } }
//------------------------------------------------------------------------ int notmain ( void ) { unsigned int ra; unsigned int rb; leds_off(); uart_init(); hexstring(0x12345678); hexstring(GETPC()); hexstring(GETCPSR()); hexstring(GETSCTLR()); hexstring(GETMPIDR()); hexstring(GET32(0x1000)); hexstring(GET32(0x1004)); hexstring(GET32(0x1008)); if(1) { for(ra=0x000; ra<0x1000; ra+=4) { rb=GET32(ra); if(rb) { hexstrings(ra); hexstring(rb); } } } return(0); }
/*---------------------------------------------------------------------------*/ void cc26xx_web_demo_restore_defaults(void) { cc26xx_web_demo_sensor_reading_t *reading = NULL; leds_on(LEDS_ALL); for(reading = list_head(sensor_list); reading != NULL; reading = list_item_next(reading)) { reading->publish = 1; } #if CC26XX_WEB_DEMO_MQTT_CLIENT process_post_synch(&mqtt_client_process, cc26xx_web_demo_load_config_defaults, NULL); #endif #if CC26XX_WEB_DEMO_NET_UART process_post_synch(&net_uart_process, cc26xx_web_demo_load_config_defaults, NULL); #endif save_config(); leds_off(LEDS_ALL); }
/*--- codigo de la funcion ---*/ int Main(void){ char *pt_str = str; leds_off(); sys_init(); // inicializacion de la placa, interrupciones, puertos Eint4567_init(); keyboard_init(); Uart_Init(115200); // inicializacion de la Uart Uart_Config(); // configuración de interrupciones y buffers while(1){ *pt_str = Uart_Getch1(); // leer caracter if(pt_str[0] == 'L'){ led1_on(); led2_off(); } else if (pt_str[0] == 'R'){ led2_on(); led1_off(); } else { D8Led_symbol(pt_str[0]-'0'); } } }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(hello_world_process, ev, data) { PROCESS_BEGIN(); //* init leds_init(); printf("Start Main Process\n"); leds_on(4); static struct etimer timer; static uint8_t leds_state = 0; while (1) { // we set the timer from here every time etimer_set(&timer, CLOCK_CONF_SECOND / 4); // and wait until the vent we receive is the one we're waiting for PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); // update the LEDs leds_off(0xFF); leds_on(leds_state%2); leds_state += 1; } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ static void write_chunk(struct rudolph2_conn *c, int offset, int flag, uint8_t *data, int datalen) { int fd; #if CONTIKI_TARGET_NETSIM { char buf[100]; sprintf(buf, "%d%%", (100 * (offset + datalen)) / FILESIZE); ether_set_text(buf); } #endif /* CONTIKI_TARGET_NETSIM */ if(flag == RUDOLPH2_FLAG_NEWFILE) { printf("+++ rudolph2 new file incoming at %lu\n", clock_time()); leds_on(LEDS_RED); fd = cfs_open("codeprop.out", CFS_WRITE); } else { fd = cfs_open("codeprop.out", CFS_WRITE + CFS_APPEND); } if(datalen > 0) { cfs_seek(fd, offset, CFS_SEEK_SET); cfs_write(fd, data, datalen); printf("+++ rudolph2 offset %d, length %d\n", offset, datalen); } cfs_close(fd); if(flag == RUDOLPH2_FLAG_LASTCHUNK) { int i; printf("+++ rudolph2 entire file received at %d, %d\n", linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]); leds_off(LEDS_RED); leds_on(LEDS_YELLOW); fd = cfs_open("hej", CFS_READ); for(i = 0; i < FILESIZE; ++i) { unsigned char buf; int r = cfs_read(fd, &buf, 1); if (r != 1) { printf("%d.%d: error: read failed at %d\n", linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1], i); break; } else if(buf != (unsigned char)i) { printf("%d.%d: error: diff at %d, %d != %d\n", linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1], i, (unsigned char)i, buf); break; } } #if CONTIKI_TARGET_NETSIM ether_send_done(); #endif cfs_close(fd); } }
/*---------------------------------------------------------------------------*/ static void recv_uc(struct unicast_conn *c, const linkaddr_t *from) { leds_on(LEDS_BLUE); printf("unicast message received from %d.%d: %s\n", from->u8[0], from->u8[1], (char*)packetbuf_dataptr()); leds_off(LEDS_BLUE); }
static int led_g_set(uint32_t value, uint32_t len) { if (value) { leds_on(LEDS_GREEN); } else { leds_off(LEDS_GREEN); } return 1; }
/*---------------------------------------------------------------------------*/ void hand_off_backoff(void) { leds_off(LEDS_RED); leds_on(LEDS_GREEN); hand_off_backoff_flag = 0; NO_DATA = 0; }
static int led_b_set(uint32_t value, uint32_t len) { if (value) { leds_on(LEDS_BLUE); } else { leds_off(LEDS_BLUE); } return 1; }