int main () { nrk_setup_ports(); nrk_setup_uart(UART_BAUDRATE_115K2); TWI_Master_Initialise(); sei(); nrk_led_set(RED_LED); /* initialize the adxl345 */ init_adxl345(); init_itg3200(); init_hmc5843(); nrk_init(); nrk_led_clr(ORANGE_LED); nrk_led_clr(BLUE_LED); nrk_led_clr(GREEN_LED); nrk_led_clr(RED_LED); nrk_time_set(0,0); nrk_create_taskset (); nrk_start(); return 0; }
int main() { // initialise the UART nrk_setup_ports(); nrk_setup_uart(UART_BAUDRATE_115K2); // initialise the OS nrk_init(); // clear all LEDs nrk_led_clr(ORANGE_LED); nrk_led_clr(BLUE_LED); // will toggle whenever a packet is sent nrk_led_clr(GREEN_LED); // will toggle whenever a packet is received nrk_led_clr(RED_LED); // will light up on error // start the clock nrk_time_set(0,0); // initialise the network stack nrk_init_nw_stack(); if(DEBUG_APP == 1) nrk_kprintf(PSTR("Network stack initialised\r\n")); nrk_create_taskset(); // create the set of tasks nrk_start(); // start this node return 0; }
int main () { nrk_setup_ports(); nrk_setup_uart(UART_BAUDRATE_115K2); nrk_init_hardware(); nrk_init(); nrk_led_clr(BLUE_LED); nrk_led_clr(GREEN_LED); nrk_led_clr(RED_LED); nrk_time_set(0,0); nrk_create_taskset (); for (uint16_t task_ID = 1; task_ID <= 3; task_ID++) { nrk_kprintf("InitT"); nrk_printnum((uint32_t)task_ID); nrk_kprintf(":NP:"); nrk_printnum((uint32_t)nrk_task_TCB[task_ID].next_period); nrk_kprintf("\r\n"); } nrk_start(); return 0; }
int main () { nrk_setup_ports (); nrk_setup_uart (UART_BAUDRATE_115K2); nrk_init (); nrk_led_clr (0); nrk_led_clr (1); nrk_led_clr (2); nrk_led_clr (3); nrk_time_set (0, 0); tdma_mode_set(TDMA_MASTER); // use tdma's tree scheduler tdma_schedule_method_set(TDMA_SCHED_TREE); tdma_task_config (); nrk_create_taskset (); nrk_start (); return 0; }
int main () { uint8_t t; nrk_setup_ports(); nrk_setup_uart(UART_BAUDRATE_115K2); oled_setup(); nrk_init(); nrk_gpio_direction(NRK_DEBUG_0, NRK_PIN_INPUT); nrk_gpio_direction(NRK_DEBUG_1, NRK_PIN_OUTPUT); oled_off(); nrk_gpio_direction(NRK_DEBUG_2, NRK_PIN_INPUT); nrk_gpio_direction(NRK_DEBUG_3, NRK_PIN_INPUT); nrk_led_clr(ORANGE_LED); nrk_led_clr(BLUE_LED); nrk_led_clr(GREEN_LED); nrk_led_clr(RED_LED); nrk_time_set(0,0); bmac_task_config (); nrk_create_taskset (); nrk_start(); return 0; }
int main() { nrk_setup_ports(); nrk_setup_uart(UART_BAUDRATE_115K2); nrk_init(); nrk_led_clr(ORANGE_LED); nrk_led_clr(BLUE_LED); nrk_led_clr(GREEN_LED); nrk_led_clr(RED_LED); nrk_time_set(0, 0); nrk_create_taskset(); // sem1 = nrk_sem_create(1, 10); nrk_sem_list[0].value = 1; nrk_sem_list[0].count = 1; nrk_sem_list[0].resource_ceiling = 5; sem1 = nrk_sem_list; if (sem1 == NULL) printf("Creating sem error\n"); nrk_start(); return 0; }
int main () { uint8_t t; nrk_setup_ports(); nrk_setup_uart(UART_BAUDRATE_115K2); printf( "Starting up...\r\n" ); nrk_init(); nrk_led_clr(ORANGE_LED); nrk_led_clr(BLUE_LED); nrk_led_set(GREEN_LED); nrk_led_clr(RED_LED); nrk_time_set(0,0); nrk_create_taskset (); my_semaphore = nrk_sem_create(1,4); if(my_semaphore==NULL) nrk_kprintf( PSTR("Error creating sem\r\n" )); nrk_start(); return 0; }
void nrk_kernel_error_add (uint8_t n, uint8_t task) { error_num = n; error_task = task; #ifdef NRK_LOG_ERRORS _nrk_log_error(error_num, error_task); #endif #ifdef NRK_REPORT_ERRORS nrk_error_print (); #endif /* */ #ifdef NRK_SOFT_REBOOT_ON_ERROR #ifdef NRK_WATCHDOG nrk_watchdog_disable(); #endif asm volatile("jmp 0x0000\n\t" ::); #endif #ifdef NRK_REBOOT_ON_ERROR // wait for watchdog to kick in if(n!=NRK_WATCHDOG_ERROR && n!=NRK_BOD_ERROR && n!=NRK_EXT_RST_ERROR) { nrk_watchdog_enable(); nrk_int_disable(); while(1); } #endif #ifdef NRK_HALT_ON_ERROR uint8_t t; uint8_t i; while (1) { for(i=0; i<20; i++ ) { nrk_led_set (2); nrk_led_clr (3); for (t = 0; t < 100; t++) nrk_spin_wait_us (1000); nrk_led_set (3); nrk_led_clr (2); for (t = 0; t < 100; t++) nrk_spin_wait_us (1000); } nrk_led_clr (3); nrk_led_clr (2); blink_morse_code_error( task ); blink_morse_code_error( n ); } #endif /* */ }
int main () { nrk_setup_ports (); nrk_setup_uart (UART_BAUDRATE_115K2); nrk_init (); nrk_led_clr(ORANGE_LED); nrk_led_clr(GREEN_LED); nrk_led_clr(RED_LED); nrk_led_clr(BLUE_LED); nrk_time_set(0,0); bmac_task_config(); nrk_create_taskset(); lock = nrk_sem_create(1,2); if( lock==NULL ) { nrk_kprintf( PSTR("Error creating sem\r\n" )); } nrk_start(); return 0; }
int main () { nrk_setup_ports(); nrk_setup_uart(UART_BAUDRATE_115K2); DDRF=0xff; while(1) { PORTF=0xff; nrk_spin_wait_us(500); PORTF=0x00; nrk_spin_wait_us(500); } nrk_init(); nrk_led_clr(ORANGE_LED); nrk_led_clr(BLUE_LED); nrk_led_clr(GREEN_LED); nrk_led_clr(RED_LED); nrk_time_set(0,0); nrk_create_taskset (); nrk_start(); return 0; }
int main () { nrk_setup_ports(); nrk_setup_uart(UART_BAUDRATE_115K2); nrk_init(); nrk_led_clr(ORANGE_LED); nrk_led_clr(BLUE_LED); nrk_led_clr(GREEN_LED); nrk_led_clr(RED_LED); nrk_time_set(0,0); nrk_create_taskset(); // Semaphore initialization semaphore1 = nrk_sem_create(1,3); semaphore2 = nrk_sem_create(1,5); semaphore3 = nrk_sem_create(1,1); nrk_start(); return 0; }
int main () { uint16_t div; nrk_setup_ports(); nrk_setup_uart(UART_BAUDRATE_115K2); printf( "Starting up...\r\n" ); nrk_init(); nrk_led_clr(0); nrk_led_clr(1); nrk_led_clr(2); nrk_led_clr(3); nrk_time_set(0,0); rtl_task_config(); nrk_create_taskset (); nrk_start(); return 0; }
int main () { nrk_setup_ports (); nrk_setup_uart (UART_BAUDRATE_115K2); // nrk_setup_uart (UART_BAUDRATE_230K4); nrk_setup_uart_gps(UART_BAUDRATE_115K2); TWI_Master_Initialise(); grideye_addr = 0x68; printf ("Starting up...\r\n"); nrk_init (); nrk_led_clr (ORANGE_LED); nrk_led_clr (BLUE_LED); nrk_led_clr (GREEN_LED); nrk_led_clr (RED_LED); nrk_time_set (0, 0); nrk_create_taskset (); nrk_start (); return 0; }
int main () { uint8_t ds; nrk_setup_ports (); nrk_setup_uart (UART_BAUDRATE_115K2); ds=nrk_eeprom_read_byte(EEPROM_SLEEP_STATE_ADDR); if(ds==1) deep_sleep_button(); nrk_init (); nrk_led_clr (0); nrk_led_clr (1); nrk_led_clr (2); nrk_led_clr (3); nrk_time_set (0, 0); tdma_set_error_callback(&tdma_error); tdma_task_config(); nrk_register_drivers(); nrk_create_taskset (); nrk_start (); return 0; }
int main () { uint16_t div; nrk_setup_ports (); nrk_setup_uart (UART_BAUDRATE_115K2); begin();//start I2C nrk_init (); nrk_led_clr (0); nrk_led_clr (1); nrk_led_clr (2); nrk_led_clr (3); nrk_time_set (0, 0); tdma_set_error_callback(&tdma_error); tdma_task_config(); //nrk_register_drivers(); nrk_create_taskset (); nrk_start (); return 0; }
void rx_task() { uint8_t i, len, rssi, *local_rx_buf; bmac_set_cca_thresh(DEFAULT_BMAC_CCA); bmac_rx_pkt_set_buffer ((char*)rx_buf, RF_MAX_PAYLOAD_SIZE); while (1) { if(cache[0]==MyOwnAddress) { nrk_led_set(RED_LED); } else { nrk_led_clr(RED_LED); } bmac_wait_until_rx_pkt(); nrk_led_set(ORANGE_LED); (char*)local_rx_buf = bmac_rx_pkt_get (&len, &rssi); for(i=0; i<len; i++) { putchar(local_rx_buf[i]); } RxPacketProcess(local_rx_buf,len); nrk_led_clr (ORANGE_LED); bmac_rx_pkt_release(); nrk_wait_until_next_period (); } }
int main () { nrk_setup_ports(); nrk_register_drivers(); //nrk_setup_uart(UART_BAUDRATE_115K2); nrk_kprintf( PSTR("Starting up...\r\n") ); nrk_init(); nrk_led_clr(0); nrk_led_clr(1); nrk_led_clr(2); nrk_led_clr(3); nrk_time_set(0,0); rtl_task_config(); nrk_create_taskset (); nrk_start(); return 0; }
int main () { // init phoenix phoenix_init(); nrk_setup_ports (); nrk_setup_uart (UART_BAUDRATE_115K2); nrk_init (); nrk_led_clr (0); nrk_led_clr (1); nrk_led_clr (2); nrk_led_clr (3); nrk_time_set (0, 0); bmac_task_config (); nrk_create_taskset (); nrk_start (); return 0; }
int main () { nrk_setup_ports (); nrk_setup_uart (UART_BAUDRATE_115K2); nrk_init (); nrk_led_clr (0); nrk_led_clr (1); nrk_led_clr (2); nrk_led_clr (3); nrk_time_set (0, 0); tdma_mode_set(TDMA_SLAVE); // do the scheduling by yourself tdma_schedule_method_set(TDMA_SCHED_MANUAL); // rcv sync packet from master tdma_schedule_add(0, TDMA_RX, -1); // SCHEDULE A // add a TX slot for every tenth slot for (tdma_slot_t i = 10; i < TDMA_SLOTS_PER_CYCLE; i+=10) { tdma_schedule_add(i, TDMA_TX_PARENT, 0); } // SCHEDULE B // just do one slot //tdma_schedule_add(10, TDMA_TX_PARENT, 0); // SCHEDULE C // for node 2 // tdma_schedule_add(0, TDMA_RX, 0); // tdma_schedule_add(10, TDMA_TX_PARENT, 0); // tdma_schedule_add(100, TDMA_TX_CHILD, 0); // for node 3 //tdma_schedule_add(20, TDMA_TX_PARENT, 0); //tdma_schedule_add(100, TDMA_RX, 0); tdma_task_config (); nrk_create_taskset (); nrk_start (); return 0; }
//------------------------------------------------------------------------------ // void main (void) // // DESCRIPTION: // Startup routine and main loop //------------------------------------------------------------------------------ int main (void) { uint8_t i,length; uint32_t cnt; nrk_setup_ports(); nrk_setup_uart (UART_BAUDRATE_115K2); printf( "Basic TX...\r\n" ); nrk_led_set(0); nrk_led_set(1); nrk_led_clr(2); nrk_led_clr(3); /* while(1) { for(i=0; i<40; i++ ) halWait(10000); nrk_led_toggle(1); } */ rfRxInfo.pPayload = rx_buf; rfRxInfo.max_length = RF_MAX_PAYLOAD_SIZE; nrk_int_enable(); rf_init (&rfRxInfo, 26, 0x2420, 0x1214); cnt=0; while(1){ DPDS1 |= 0x3; DDRG |= 0x1; PORTG |= 0x1; DDRE|=0xE0; PORTE|=0xE0; rfTxInfo.pPayload=tx_buf; sprintf( tx_buf, "%lu", cnt); rfTxInfo.length= strlen(tx_buf) + 1; rfTxInfo.destAddr = 0x1215; rfTxInfo.cca = 0; rfTxInfo.ackRequest = 0; printf( "Sending\r\n" ); // nrk_gpio_set(NRK_DEBUG_0); if(rf_tx_packet(&rfTxInfo) != 1) printf("--- RF_TX ERROR ---\r\n"); // nrk_gpio_clr(NRK_DEBUG_0); cnt++; for(i=0; i<10; i++ ) halWait(10000); nrk_led_toggle(RED_LED); } }
//------------------------------------------------------------------------------ // void main (void) // // DESCRIPTION: // Startup routine and main loop //------------------------------------------------------------------------------ int main (void) { uint8_t cnt,i,length; nrk_setup_ports(); nrk_setup_uart (UART_BAUDRATE_115K2); printf( "Basic TX...\r\n" ); nrk_led_set(0); nrk_led_set(1); nrk_led_clr(2); nrk_led_clr(3); /* while(1) { for(i=0; i<40; i++ ) halWait(10000); nrk_led_toggle(1); } */ rfRxInfo.pPayload = rx_buf; rfRxInfo.max_length = RF_MAX_PAYLOAD_SIZE; nrk_int_enable(); rf_init (&rfRxInfo, 13, 0x2420, 0x1214); cnt=0; while(1){ nrk_led_set(GREEN_LED); rfTxInfo.pPayload=tx_buf; sprintf( tx_buf, "This is my string counter %d", cnt); rfTxInfo.length= strlen(tx_buf) + 1; rfTxInfo.destAddr = 0x1215; rfTxInfo.cca = 0; rfTxInfo.ackRequest = 0; printf( "Sending\r\n" ); nrk_gpio_set(NRK_DEBUG_0); if(rf_tx_packet(&rfTxInfo) != 1) printf("--- RF_TX ERROR ---\r\n"); nrk_gpio_clr(NRK_DEBUG_0); cnt++; for(i=0; i<80; i++ ) halWait(10000); nrk_led_clr(GREEN_LED); for(i=0; i<20; i++ ) halWait(10000); } }
// This function will put the node into a low-duty checking mode to save power void tdma_snooze() { int8_t v; uint8_t i; // stop the software watchdog timer so it doesn't interrupt nrk_sw_wdt_stop(0); // This flag is cleared only by the button interrupt snoozing=1; // Setup the button interrupt nrk_ext_int_configure( NRK_EXT_INT_1,NRK_LEVEL_TRIGGER, &wakeup_func); // Clear it so it doesn't fire instantly EIFR=0xff; nrk_ext_int_enable( NRK_EXT_INT_1); // Now loop and periodically check for packets while(1) { nrk_led_clr(RED_LED); nrk_led_clr(GREEN_LED); rf_power_up(); rf_rx_on (); // check return from button interrupt on next cycle if(snoozing==0 ) return; tmp_time.secs=0; tmp_time.nano_secs=10*NANOS_PER_MS; nrk_led_set(RED_LED); // Leave radio on for two loops of 10ms for a total of 20ms every 10 seconds for(i=0; i<2; i++ ) { v = _tdma_rx (); if(v==NRK_OK) { nrk_led_set(RED_LED); nrk_ext_int_disable( NRK_EXT_INT_1); nrk_sw_wdt_update(0); nrk_sw_wdt_start(0); return NRK_OK; } nrk_wait(tmp_time); } nrk_led_clr(RED_LED); rf_power_down(); tmp_time.secs=10; tmp_time.nano_secs=0; nrk_sw_wdt_stop(0); nrk_wait(tmp_time); } }
int main () { nrk_setup_ports (); nrk_setup_uart (UART_BAUDRATE_115K2); nrk_init (); nrk_led_clr (0); nrk_led_clr (1); nrk_led_clr (2); nrk_led_clr (3); nrk_time_set (0, 0); tdma_mode_set(TDMA_MASTER); // do the scheduling by yourself tdma_schedule_method_set(TDMA_SCHED_MANUAL); // send sync to child tdma_schedule_add(0, TDMA_TX_CHILD, 0); // SCHEDULE A // add a RX from child every tenth slot for (tdma_slot_t i = 10; i < TDMA_SLOTS_PER_CYCLE; i+=10) { tdma_schedule_add(i, TDMA_RX, 0); } // SCHEDULE B // rcv data from child. priority is ignored //tdma_schedule_add(10, TDMA_RX, -1); // SCHEDULE C: Sync Test // Add 2 RX slots from children from level 1 and 2 //tdma_schedule_add(0, TDMA_TX_CHILD, 0); //tdma_schedule_add(10, TDMA_RX, 0); //tdma_schedule_add(20, TDMA_RX, 0); tdma_task_config (); nrk_create_taskset (); nrk_start (); return 0; }
int main () { nrk_setup_ports(); nrk_setup_uart(UART_BAUDRATE_115K2); log_g = 1; if(log_g)printf("log:Starting up...\r\n" ); nrk_init(); uint8_t i; request_flag_g=0; retransmit_count_g=0; //added this 1 for(i=0;i<5;i++) { version_g[i] = 0; } //added version_g[MAC_ADDR] = -1; data_index_g = -1; nrk_led_clr(ORANGE_LED); nrk_led_clr(BLUE_LED); nrk_led_set(GREEN_LED); nrk_led_clr(RED_LED); tx_sem = nrk_sem_create(1,4); if(tx_sem==NULL) nrk_kprintf( PSTR("log:Error creating sem\r\n" )); conn_sem = nrk_sem_create(1,4); if(conn_sem==NULL) nrk_kprintf( PSTR("log:Error creating sem\n" )); uart_sem = nrk_sem_create(1,4); if(conn_sem==NULL) nrk_kprintf( PSTR("log:Error creating sem\n" )); ack_sem = nrk_sem_create(1,4); if(conn_sem==NULL) nrk_kprintf( PSTR("log:Error creating sem\n" )); nrk_time_set(0,0); nrk_register_drivers(); bmac_task_config (); nrk_create_taskset (); nrk_start(); return 0; }
void inter_tx_task () { uint8_t i; nrk_sig_t tx_done_signal; while (!bmac_started ()) nrk_wait_until_next_period (); tx_done_signal = bmac_get_tx_done_signal (); nrk_signal_register (tx_done_signal); bmac_addr_decode_enable(); bmac_addr_decode_set_my_mac(MyOwnAddress); while (1) { if(ipQue>0) { if(itxPtr>queMax-1) { itxPtr=0; } bmac_addr_decode_enable(); bmac_addr_decode_set_my_mac(MyOwnAddress); nrk_led_set(BLUE_LED); bmac_auto_ack_disable(); for(i=0; i<ipLen[itxPtr]; i++) { itx_buf[i]=ipDat[itxPtr][i]; } if(ipDes[itxPtr]==0xFF) { bmac_addr_decode_dest_mac(0xFFFF); } else { bmac_addr_decode_dest_mac(ipDes[itxPtr]); } bmac_tx_pkt((char*)itx_buf,ipLen[itxPtr]); ipQue--; itxPtr++; nrk_led_clr(BLUE_LED); } nrk_wait_until_next_period (); } }
// tx_cmds() - send all commands out to the network. void tx_cmds() { // local variable instantiation packet tx_packet; volatile uint8_t local_tx_cmd_queue_size; volatile uint8_t tx_length = 0; volatile int8_t val = 0; // atomically get the queue size local_tx_cmd_queue_size = atomic_size(&g_cmd_tx_queue, g_cmd_tx_queue_mux); // print out task header if((TRUE == g_verbose) && (0 < local_tx_cmd_queue_size)) { nrk_kprintf(PSTR("tx_cmds...\r\n")); } // loop on queue size received above, and no more. for(uint8_t i = 0; i < local_tx_cmd_queue_size; i++) { nrk_led_set(ORANGE_LED); // get a packet out of the queue. atomic_pop(&g_cmd_tx_queue, &tx_packet, g_cmd_tx_queue_mux); // assemble the packet and senx tx_length = assemble_packet((uint8_t *)&g_net_tx_buf, &tx_packet); val = bmac_tx_pkt(g_net_tx_buf, tx_length); if(NRK_OK != val){ nrk_kprintf( PSTR( "NO ack or Reserve Violated!\r\n" )); } nrk_led_clr(ORANGE_LED); } return; }
void rx_task() { char c; nrk_sig_t uart_rx_signal; nrk_sig_mask_t sm; printf( "My node's address is %d\r\n",NODE_ADDR ); printf( "rx_task PID=%d\r\n",nrk_get_pid()); // Get the signal for UART RX uart_rx_signal=nrk_uart_rx_signal_get(); // Register your task to wakeup on RX Data if(uart_rx_signal==NRK_ERROR) nrk_kprintf( PSTR("Get Signal ERROR!\r\n") ); nrk_signal_register(uart_rx_signal); while(1) { // Wait for UART signal while(nrk_uart_data_ready(NRK_DEFAULT_UART)!=0) { // Read Character c=getchar(); printf( "%c",c); if(c=='x') nrk_led_set(GREEN_LED); else nrk_led_clr(GREEN_LED); } sm=nrk_event_wait(SIG(uart_rx_signal)); if(sm != SIG(uart_rx_signal)) nrk_kprintf( PSTR("RX signal error") ); nrk_kprintf( PSTR("\r\ngot uart data: ") ); } }
static int8_t proc_ping(node_id_t requester, uint8_t *req_buf, uint8_t req_len, uint8_t *reply_buf, uint8_t reply_size, uint8_t *reply_len) { uint8_t token; if (req_len != RPC_PING_REQ_LEN) { LOG("WARN: req of unexpected length: "); LOGP("%u/%u\r\n", req_len, RPC_PING_REQ_LEN); return NRK_ERROR; } if (reply_size < RPC_PING_REPLY_LEN) { LOG("WARN: reply buf too small: "); LOGP("%u/%u\r\n", reply_size, RPC_PING_REPLY_LEN); return NRK_ERROR; } nrk_led_set(led_proc_ping); nrk_wait(pong_delay); nrk_led_clr(led_proc_ping); token = req_buf[RPC_PING_REQ_TOKEN_OFFSET]; reply_buf[RPC_PING_REPLY_TOKEN_OFFSET] = token; *reply_len = RPC_PING_REPLY_LEN; return NRK_OK; }
int main() { uint8_t led = 0; nrk_setup_ports(); nrk_led_clr(ORANGE_LED); nrk_led_clr(BLUE_LED); nrk_led_clr(GREEN_LED); nrk_led_clr(RED_LED); while (1) { nrk_led_toggle(ORANGE_LED); nrk_spin_wait_us(PERIOD); } return 0; }
void tx_task() { uint8_t cnt = 0; uint8_t val; int8_t v; // printf( "tx_task: PID=%d\r\n",nrk_get_pid()); bmac_init(25); while(!bmac_started()) nrk_wait_until_next_period(); while(1) { if (cnt > 25) { nrk_led_set(BLUE_LED); nrk_terminate_task(); } nrk_led_set(RED_LED); sprintf( tx_buf, "%d", cnt ); val = bmac_tx_pkt(tx_buf, strlen(tx_buf)); nrk_led_clr(RED_LED); // nrk_kprintf( PSTR("TX task sent data!\r\n") ); nrk_wait_until_next_period(); v = nrk_sem_pend(lock); if ( startCnt ) cnt++; v = nrk_sem_post(lock); } }