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); } }
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 (); } }
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 /* */ }
void Task1() { uint16_t cnt; int8_t fd,val,chan; uint16_t sample; printf( "Task1 PID=%d\r\n",nrk_get_pid()); nrk_gpio_direction(NRK_BUTTON, NRK_PIN_INPUT); nrk_gpio_direction(NRK_DEBUG_0, NRK_PIN_OUTPUT); nrk_led_set(RED_LED); do{} while(nrk_gpio_get(NRK_BUTTON)==1); nrk_led_clr(RED_LED); nrk_led_set(GREEN_LED); // Initialize values here ADC_INIT (); ADC_ENABLE (); ADC_SET_CHANNEL (2); while(1) { ADC_SAMPLE_SINGLE(); ADC_GET_SAMPLE_10(sample); // Send sync byte putchar(0x55); putchar(sample>>8); putchar(sample&0xff); } }
//------------------------------------------------------------------------------ // 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); } }
// 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 () { uint8_t i, len, rssi; int8_t val; //char *local_rx_buf; nrk_time_t check_period; printf ("rx_task PID=%d\r\n", nrk_get_pid ()); // init bmac on channel 24 bmac_init (24); // Enable AES 128 bit encryption // When encryption is active, messages from plaintext // source will still be received. // Commented out by MB //bmac_encryption_set_key(aes_key,16); //bmac_encryption_enable(); // bmac_encryption_disable(); // By default the RX check rate is 200ms // below shows how to change that //check_period.secs=0; //check_period.nano_secs=200*NANOS_PER_MS; //val=bmac_set_rx_check_rate(check_period); // The default Clear Channel Assement RSSI threshold. // Setting this value higher means that you will only trigger // receive with a very strong signal. Setting this lower means // bmac will try to receive fainter packets. If the value is set // too high or too low performance will suffer greatly. bmac_set_cca_thresh(DEFAULT_BMAC_CCA); // This sets the next RX buffer. // This can be called at anytime before releaseing the packet // if you wish to do a zero-copy buffer switch bmac_rx_pkt_set_buffer (rx_buf, RF_MAX_PAYLOAD_SIZE); while (1) { // Wait until an RX packet is received //val = bmac_wait_until_rx_pkt (); //printf("Hi..\n"); // Get the RX packet nrk_led_set (ORANGE_LED); length1=len; nrk_led_clr (ORANGE_LED); // Release the RX buffer so future packets can arrive bmac_rx_pkt_release (); // this is necessary nrk_wait_until_next_period (); } }
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 Task1() { uint16_t i,j; uint32_t it; nrk_time_t time, time2, time3; while(1) { nrk_led_set(RED_LED); nrk_gpio_toggle(NRK_DEBUG_0); nrk_kprintf("Task 1\r\n"); //for (i = 0; i < 10; i++) { // nrk_time_get(&time); // nrk_time_get(&time2); // nrk_time_sub(&time3, time2, time); // printf("%lu.%09lu\r\n", time3.secs, time3.nano_secs); nrk_time_get(&time); printf("%lu.%09lu\r\n", time.secs, time.nano_secs); for(it=0;it<115200;it++); nrk_time_get(&time); printf("%lu.%09lu\r\n", time.secs, time.nano_secs); // nrk_time_get(&time2); // nrk_time_sub(&time3, time2, time); // printf("%lu.%09lu\r\n", time3.secs, time3.nano_secs); //} // nrk_time_get(&time); // for(i=0;i<256;i++) for(j=0;j<65000;j++); // wait 1 second // nrk_time_get(&time2); // nrk_time_sub(&time3, time2, time); // printf("%lu.%lu\r\n", time3.secs, time3.nano_secs); nrk_kprintf("Task 1 done\r\n"); nrk_wait_until_next_period(); } }
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; }
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: ") ); } }
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 (); } }
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; }
void blink_dot() { nrk_led_set(GREEN_LED); pause(); nrk_led_clr(GREEN_LED); pause(); }
void initialise_network_layer() { int8_t i; // loop index /* initialise the data structures required for the network layer */ nl.count = 0; // no neighbors recorded yet nl.my_addr = NODE_ADDR; // assign my network layer address for(i = 0; i < MAX_NGBS; i++) // an addr = BCAST_ADDR indicates an invalid entry nl.ngbs[i].addr = BCAST_ADDR; DEFAULT_GATEWAY = BCAST_ADDR; // initially the default gateway is unknown ROUTING_ALGORITHM = DEFAULT_ROUTING_ALGORITHM; // set the routing algorithm FLOODING_TYPE = DEFAULT_FLOODING_TYPE; // set the flooding type to be ttl-based P_DISTRIBUTION = DEFAULT_PDISTRIBUTION; // set the probability distribution initialise_routing_table(); nl_sem = nrk_sem_create(1,MAX_TASK_PRIORITY); // create the mutex if(nl_sem == NULL) { nrk_int_disable(); nrk_led_set(RED_LED); while(1) nrk_kprintf(PSTR("NL: Error creating semaphore in initialise_network_layer()\r\n")); } create_network_layer_tasks(); // create the two tasks return; }
void wakeup_func() { if(snoozing==1) { nrk_led_set(RED_LED); snoozing=0; } }
/****************************** FUNCTION DEFINITIONS ****************************************/ void go_into_panic(char *str) // This function is for signalling error conditions { nrk_int_disable(); nrk_led_set(RED_LED); while(1) printf("PANIC: %s. This should never happen\n", str); return; }
void rx_task () { uint8_t i, len; int8_t rssi, val; uint8_t *local_rx_buf; nrk_time_t check_period; printf ("rx_task PID=%d\r\n", nrk_get_pid ()); // init bmac on channel 25 bmac_init (15); // Enable AES 128 bit encryption // When encryption is active, messages from plaintext // source will still be received. bmac_encryption_set_key(aes_key,16); bmac_encryption_enable(); // bmac_encryption_disable(); // By default the RX check rate is 100ms // below shows how to change that check_period.secs=0; check_period.nano_secs=25*NANOS_PER_MS; val=bmac_set_rx_check_rate(check_period); // The default Clear Channel Assement RSSI threshold is -45 // Setting this value higher means that you will only trigger // receive with a very strong signal. Setting this lower means // bmac will try to receive fainter packets. If the value is set // too high or too low performance will suffer greatly. // bmac_set_cca_thresh(-45); //if(val==NRK_ERROR) nrk_kprintf( PSTR("ERROR setting bmac rate\r\n" )); // This sets the next RX buffer. // This can be called at anytime before releaseing the packet // if you wish to do a zero-copy buffer switch bmac_rx_pkt_set_buffer (rx_buf, RF_MAX_PAYLOAD_SIZE); while (1) { // Wait until an RX packet is received val = bmac_wait_until_rx_pkt (); // Get the RX packet nrk_led_set (ORANGE_LED); local_rx_buf = bmac_rx_pkt_get (&len, &rssi); if( bmac_rx_pkt_is_encrypted()==1 ) nrk_kprintf( PSTR( "Packet Encrypted\r\n" )); printf ("Got RX packet len=%d RSSI=%d [", len, rssi); for (i = 0; i < len; i++) printf ("%c", local_rx_buf[i]); printf ("]\r\n"); nrk_led_clr (ORANGE_LED); // Release the RX buffer so future packets can arrive bmac_rx_pkt_release (); } }
void rx_task () { uint8_t i, len, rssi; int8_t val; //char *local_rx_buf; nrk_time_t check_period; printf ("rx_task PID=%d\r\n", nrk_get_pid ()); // init bmac on channel 24 bmac_init (5); bmac_set_cca_thresh(DEFAULT_BMAC_CCA); bmac_rx_pkt_set_buffer (rx_buf, RF_MAX_PAYLOAD_SIZE); while (1) { // Wait until an RX packet is received val = bmac_wait_until_rx_pkt (); //printf("Hi..\n"); // Get the RX packet nrk_led_set (ORANGE_LED); local_rx_buf = bmac_rx_pkt_get (&len, &rssi); inter_flag=0; if(rssi<5){ dst_addr=0x0003; //inter_tx_buf=local_rx_buf; } else { dst_addr=0x0001; } if(local_rx_buf[0]=='n'){ dst_addr=0x0001; inter_tx_buf=local_rx_buf; inter_flag=1; } printf("inter_flag: %d",inter_flag); printf("\r\n"); printf("rx_buf:"); for(i=0;i<len;i++){ printf("%c",local_rx_buf[i]); } nrk_led_clr (ORANGE_LED); // Release the RX buffer so future packets can arrive bmac_rx_pkt_release (); // this is necessary nrk_wait_until_next_period (); } }
void Task3() { uint8_t i, len,cnt; int8_t rssi, val; uint8_t *local_rx_buf; nrk_sig_mask_t ret; nrk_time_t check_period; printf( "Task3 PID=%u\r\n",nrk_get_pid()); // init bmac on channel 25 bmac_init (25); bmac_rx_pkt_set_buffer (rx_buf, RF_MAX_PAYLOAD_SIZE); while (!bmac_started ()) nrk_wait_until_next_period (); /* while (1) { // Wait until an RX packet is received nrk_kprintf( PSTR( "Waiting for packet\r\n" )); val = bmac_wait_until_rx_pkt (); // Get the RX packet nrk_led_set (ORANGE_LED); local_rx_buf = bmac_rx_pkt_get (&len, &rssi); printf ("Got RX packet len=%d RSSI=%d [", len, rssi); for (i = 0; i < len; i++) printf ("%c", rx_buf[i]); printf ("]\r\n"); nrk_led_clr (ORANGE_LED); // Release the RX buffer so future packets can arrive bmac_rx_pkt_release (); } */ while (1) { // Build a TX packet sprintf (tx_buf, "This is a test %d", cnt); cnt++; nrk_led_set (RED_LED); // For blocking transmits, use the following function call. // For this there is no need to register val=bmac_tx_pkt(tx_buf, strlen(tx_buf)+1); // Task gets control again after TX complete nrk_kprintf (PSTR ("Tx task sent data!\r\n")); nrk_led_clr (RED_LED); nrk_wait_until_next_period (); } }
// tx_data_task() - send standard messages out to the network (i.e. handshake messages, etc.) void tx_data() { // local variable initialization packet tx_packet; volatile int8_t val = 0; volatile uint8_t sent_heart = FALSE; volatile uint8_t to_send; volatile uint8_t tx_length = 0; volatile uint8_t local_tx_data_queue_size; volatile msg_type tx_type; // atomically get the queue size local_tx_data_queue_size = atomic_size(&g_data_tx_queue, g_data_tx_queue_mux); // print out task header if((TRUE == g_verbose) && (0 < local_tx_data_queue_size)){ nrk_kprintf(PSTR("tx_data...\r\n")); } // loop on queue size received above, and no more. for(uint8_t i = 0; i < local_tx_data_queue_size; i++) { nrk_led_set(ORANGE_LED); // get a packet out of the queue. atomic_pop(&g_data_tx_queue, &tx_packet, g_data_tx_queue_mux); // get packet parameters tx_type = tx_packet.type; // only hop one heartbeat per iteration. if(((MSG_HEARTBEAT == tx_type) || (MSG_RESET == tx_type)) && (TRUE == sent_heart)) { to_send = FALSE; } else { to_send = TRUE; } if (TRUE == to_send) { // assembe and send packet 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" )); } // set flag if(MSG_HEARTBEAT == tx_type){ sent_heart = TRUE; } } nrk_led_clr(ORANGE_LED); } return; }
void rx_task () { uint8_t i, len; int8_t rssi, val; uint8_t *local_rx_buf; nrk_time_t check_period; // init bmac on channel 25 bmac_init (25); rx_data_ok=0; // This sets the next RX buffer. // This can be called at anytime before releaseing the packet // if you wish to do a zero-copy buffer switch bmac_rx_pkt_set_buffer (rx_buf, RF_MAX_PAYLOAD_SIZE); while (1) { // Wait until an RX packet is received val = bmac_wait_until_rx_pkt (); // Get the RX packet nrk_led_set(0); nrk_led_set(1); nrk_led_set(2); nrk_led_set(3); local_rx_buf = bmac_rx_pkt_get (&len, &rssi); printf("RX received: RSSI = %d\r\n", rssi); nrk_spin_wait_us(50000); // Release the RX buffer so future packets can arrive bmac_rx_pkt_release (); nrk_led_clr(0); nrk_led_clr(1); nrk_led_clr(2); nrk_led_clr(3); } }
void Task2 () { uint8_t cnt; printf ("Task2 PID=%d\r\n", nrk_get_pid ()); cnt = 0; while (1) { nrk_led_set (BLUE_LED); printf ("Task2 cnt=%d\r\n", cnt); nrk_wait_until_next_period (); nrk_led_clr (BLUE_LED); nrk_wait_until_next_period (); cnt++; } }
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; }
// This function gets called in a loop if sync is lost. // It is passed a counter indicating how long it has gone since the last synchronization. int8_t tdma_error(uint16_t cons_err_cnt) { if(tdma_sync_ok()==0) nrk_led_set(1); else nrk_led_clr(1); // If there has been enough cycles without sync then snooze if(cons_err_cnt>400) { //nrk_kprintf(PSTR("Entering TDMA snooze...\r\n" )); nrk_wait_until_next_period(); tdma_snooze(); return NRK_OK; } return NRK_ERROR; }
void Task2() { uint8_t cnt; printf( "Task2 PID=%d\r\n",nrk_get_pid()); cnt=0; while(1) { nrk_led_set(BLUE_LED); printf( "Task2 cnt=%d\r\n",cnt ); cnt++; //if(cnt>=10) while(1); // This will test the reservation //if(cnt>=10) kill_stack(100); nrk_wait_until_next_period(); nrk_led_clr(BLUE_LED); nrk_wait_until_next_period(); } }
void tx_task () { uint8_t j, i, val, cnt; int8_t len; int8_t v,fd; uint8_t buf[2]; nrk_sig_t tx_done_signal; nrk_sig_mask_t ret; nrk_time_t r_period; printf ("tx_task PID=%d\r\n", nrk_get_pid ()); // Wait until the tx_task starts up bmac // This should be called by all tasks using bmac that while (!tdma_started ()) nrk_wait_until_next_period (); while (1) { tx_pkt.payload[0] = 1; // ELEMENTS tx_pkt.payload[1] = 5; // Key tx_pkt.payload[2]=Gain; tx_pkt.payload_len=3; if(gpio_pin) nrk_led_set(BLUE_LED); else nrk_led_clr(BLUE_LED); tx_pkt.src_mac=mac_address; tx_pkt.dst_mac=0; tx_pkt.type=APP; len=pkt_to_buf(&tx_pkt,&tx_buf ); if(len>0) { v = tdma_send (&tx_tdma_fd, &tx_buf, len, TDMA_BLOCKING); if (v == NRK_OK) { //nrk_kprintf (PSTR ("App Packet Sent\n")); } } else nrk_wait_until_next_period(); } }
void Task4() { uint16_t cnt; nrk_time_t my_time; printf( "Task4 PID=%d\r\n",nrk_get_pid()); cnt=0; while(1) { nrk_led_set(RED_LED); nrk_time_get(&my_time); printf( "Task4 cnt=%d\r\n",cnt ); nrk_wait_until_next_period(); nrk_led_clr(RED_LED); cnt++; nrk_wait_until_next_period(); } }