void Task1() { nrk_time_t t; uint16_t cnt; cnt=0; nrk_kprintf( PSTR("Nano-RK Version ") ); printf( "%d\r\n",NRK_VERSION ); printf( "My node's address is %u\r\n",NODE_ADDR ); printf( "Task1 PID=%u\r\n",nrk_get_pid()); while(1) { nrk_led_toggle(ORANGE_LED); //nrk_gpio_toggle(NRK_DEBUG_0); printf( "Task1 cnt=%u\r\n",cnt ); nrk_wait_until_next_period(); // Uncomment this line to cause a stack overflow // if(cnt>20) kill_stack(10); // At time 50, the OS will halt and print statistics // This requires the NRK_STATS_TRACKER #define in nrk_cfg.h if(cnt==50) { nrk_stats_display_all(); // This will induce a kernel panic on purpose nrk_halt(); } // This is an example of how to access the task execution data if( cnt==10 ) { nrk_stats_get(nrk_get_pid(), &my_stats); nrk_kprintf( PSTR( "\r\n Total CPU: ")); t=_nrk_ticks_to_time(my_stats.total_ticks); printf( "%lu secs %lu ms", t.secs, t.nano_secs/NANOS_PER_MS ); nrk_kprintf( PSTR( "\r\n Time [Min,Last,Max]: ")); t=_nrk_ticks_to_time(my_stats.min_exec_ticks); printf( "%lu secs %lu ms, ", t.secs, t.nano_secs/NANOS_PER_MS ); t=_nrk_ticks_to_time(my_stats.last_exec_ticks); printf( "%lu secs %lu ms, ", t.secs, t.nano_secs/NANOS_PER_MS ); t=_nrk_ticks_to_time(my_stats.max_exec_ticks); printf( "%lu secs %lu ms", t.secs, t.nano_secs/NANOS_PER_MS ); nrk_kprintf( PSTR( "\r\n Swap-ins: ")); printf( "%lu",my_stats.swapped_in ); nrk_kprintf( PSTR( "\r\n Preemptions: ")); printf( "%lu",my_stats.preempted); nrk_kprintf( PSTR( "\r\n Kernel Violations: ")); printf( "%u",my_stats.violations); nrk_kprintf( PSTR( "\r\n Overflow Error Status: ")); printf( "%u",my_stats.overflow); nrk_kprintf( PSTR("\r\n") ); } cnt++; } }
// creates Task2 void Task2() { int16_t counter; printf( "Task2 PID=%u\r\n",nrk_get_pid()); counter=0; while(1) { nrk_led_toggle(BLUE_LED); printf( "Task2 signed counter=%d\r\n",counter ); nrk_stats_display_pid(nrk_get_pid()); nrk_wait_until_next_period(); counter--; } }
void Task3 () { int8_t v; int8_t i; printf ("Task3 PID=%d\r\n", nrk_get_pid ()); while (slip_started () != 1) nrk_wait_until_next_period (); while (1) { nrk_led_toggle (GREEN_LED); printf ("Task3\r\n"); v = slip_rx (slip_rx_buf, MAX_SLIP_BUF); if (v > 0) { nrk_kprintf (PSTR ("Task3 got data: ")); for (i = 0; i < v; i++) printf ("%c", slip_rx_buf[i]); printf ("\r\n"); } else nrk_kprintf (PSTR ("Task3 data failed\r\n")); nrk_wait_until_next_period (); } }
void Task3 () { int8_t v; int8_t i; printf ("Task3 PID=%d\r\n", nrk_get_pid ()); slip_init (stdin, stdout, 0, 0); while (slip_started () != 1) nrk_wait_until_next_period (); while (1) { nrk_led_toggle (RED_LED); v = slip_rx (slip_rx_buf, MAX_SLIP_BUF); printf ("%d\r\n", slip_rx_buf[0]); /* if (v > 0) { nrk_kprintf (PSTR ("Task3 got data ")); printf( "%d bytes: ",v ); for (i = 0; i < v; i++) printf ("%d ", slip_rx_buf[i]); printf ("\r\n"); } else nrk_kprintf (PSTR ("Task3 data failed\r\n")); */ //nrk_wait_until_next_period (); } }
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); } }
// net_tx_task - send network messages void tx_net_task() { volatile uint8_t counter = 0; volatile uint8_t tx_data_flag; // print task pid printf("tx_net PID: %d.\r\n", nrk_get_pid()); // Wait until bmac has started. This should be called by all tasks // using bmac that do not call bmac_init(). while(!bmac_started ()) { nrk_wait_until_next_period (); } // loop forever while(1) { // increment counter and set flags counter++; tx_data_flag = counter % NODE_TX_DATA_FLAG; // if data shoudl be transmitted, then call the tx_data() helper if (TRANSMIT == tx_data_flag) { tx_data(); counter = 0; } else { tx_cmds(); } // nrk_kprintf(PSTR("OUT\r\n")); nrk_wait_until_next_period(); } nrk_kprintf(PSTR("Fallthrough: tx_net_task\r\n")); }
void Task4() { int8_t v; uint8_t cnt; nrk_sig_mask_t my_sigs; cnt =0; printf("Node's addre is %d\r\n",NODE_ADDR); printf("Task4 PID=%d\r\n",nrk_get_pid()); while(1) { // nrk_led_toggle(ORANGE_LED); V_5Sec_U8R++; if(V_5Sec_U8R==5) { V_5Sec_U8R=0; // v = nrk_event_signal(signal_one); // if(v==NRK_ERROR) // nrk_kprintf( PSTR("T1 nrk_event_signal failed\r\n")); cnt++; } else { } nrk_wait_until_next_period(); } }
void Task1() { uint16_t cnt; uint8_t val; printf( "My node's address is %d\r\n",NODE_ADDR ); printf( "Task1 PID=%d\r\n",nrk_get_pid()); cnt=0; // Setup application timer with: // Prescaler = 5 // Compare Match = 25000 // Sys Clock = 7.3728 MHz // Prescaler 5 means divide sys clock by 1024 // 7372800 / 1024 = 7200 Hz clock // 1 / 7200 = 0.138 ms per tick // 0.138 ms * 25000 = ~3472 ms / per interrupt callback val=nrk_timer_int_configure(NRK_APP_TIMER_0, 5, 25000, &my_timer_callback ); if(val==NRK_OK) nrk_kprintf( PSTR("Callback timer setup\r\n")); else nrk_kprintf( PSTR("Error setting up timer callback\r\n")); // Zero the timer... nrk_timer_int_reset(NRK_APP_TIMER_0); // Start the timer... nrk_timer_int_start(NRK_APP_TIMER_0); while(1) { cnt=nrk_timer_int_read(NRK_APP_TIMER_0); printf( "Task1 timer=%u\r\n",cnt ); nrk_wait_until_next_period(); } }
void discover_task() { uint8_t len; uint8_t connection_l; while (!bmac_started ()) nrk_wait_until_next_period (); if(log_g) printf("log:discover_task PID=%d\r\n",nrk_get_pid()); while(1) { nrk_sem_pend(conn_sem); connection_l = connection_g; nrk_sem_post(conn_sem); if(connection_l == 0 && vertsk_active_g == 0 && version_g[MAC_ADDR] > 0) { nrk_led_toggle(BLUE_LED); if(log_g) printf("log:Sending discover pkt\r\n"); nrk_sem_pend(tx_sem); sprintf(tx_buf,"0:%d:S:%d",MAC_ADDR,version_g[MAC_ADDR]); bmac_tx_pkt(tx_buf, strlen(tx_buf)); nrk_sem_post(tx_sem); memset(tx_buf,0,strlen(tx_buf)); } nrk_wait_until_next_period (); } }
void Task1() { uint16_t cnt; int8_t v; printf( "My node's address is %d\r\n",NODE_ADDR ); printf( "Task1 PID=%d\r\n",nrk_get_pid()); cnt=0; while(1) { nrk_led_toggle(ORANGE_LED); printf( "Task1 cnt=%d\r\n",cnt ); nrk_kprintf( PSTR("Task1 accessing semaphore\r\n")); v = nrk_sem_pend(my_semaphore); if(v==NRK_ERROR) nrk_kprintf( PSTR("T1 error pend\r\n")); nrk_kprintf( PSTR("Task1 holding semaphore\r\n")); // wait some time inside semaphore to show the effect nrk_wait_until_next_period(); v = nrk_sem_post(my_semaphore); if(v==NRK_ERROR) nrk_kprintf( PSTR("T1 error post\r\n")); nrk_kprintf( PSTR("Task1 released semaphore\r\n")); nrk_wait_until_next_period(); cnt++; } }
void TaskGPS () { uint8_t i,n,checksum,index=0; char c; uint8_t line_cnt=0; printf( "Task2 PID=%d\r\n",nrk_get_pid()); while(1) { if(nrk_uart_data_ready_gps(1)) { c = getc_gps(); gps_print_buf[index++]=c; if(c=='\n') { gps_print_buf[index]='\0'; while(uart_tx_busy==1) nrk_wait_until_next_period(); uart_tx_busy=1; printf("%s\n", gps_print_buf); uart_tx_busy=0; index=0; } if(index>=GPS_PRINT_BUF_LEN) index=0; } else{ nrk_wait_until_next_period(); } } }
// creates Task4 and uses semaphore1 void Task4() { uint8_t counter; uint8_t waitCount=3; printf( "Task4 PID=%d\r\n",nrk_get_pid()); counter=0; while(1) { nrk_led_toggle(GREEN_LED); printf( "Task4 counter=%d\r\n",counter ); if(0==waitCount) { nrk_kprintf( PSTR("Task4 accessing semaphore1\r\n")); nrk_sem_pend(semaphore1); nrk_kprintf( PSTR("Task4 holding semaphore1\r\n")); } waitCount++; if(3==waitCount) { nrk_sem_post(semaphore1); nrk_kprintf( PSTR("Task4 released semaphore1\r\n")); waitCount=0; } nrk_wait_until_next_period(); counter++; } }
void tx_task() { int8_t v,i; uint8_t len,cnt; printf( "Gateway Tx Task PID=%u\r\n",nrk_get_pid()); cnt=0; while(1) { // This is simply a place holder in case you want to add Host -> Client Communication v = slip_rx ( slip_rx_buf, TDMA_MAX_PKT_SIZE); if (v > 0) { nrk_kprintf (PSTR ("Sending data: ")); for (i = 0; i < v; i++) printf ("%d ", slip_rx_buf[i]); printf ("\r\n"); v=tdma_send(&tx_tdma_fd, &slip_rx_buf, v, TDMA_BLOCKING ); } nrk_led_toggle(BLUE_LED); } }
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 (); } }
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 tx_task () { int8_t v,state,outlet_state,dst_mac, outlet; uint8_t len, cnt; nrk_sig_t uart_rx_signal; char c; printf ("Gateway Tx Task PID=%u\r\n", nrk_get_pid ()); while (!tdma_started ()) nrk_wait_until_next_period (); uart_rx_signal=nrk_uart_rx_signal_get(); nrk_signal_register(uart_rx_signal); cnt = 0; state=0; while (1) { if(nrk_uart_data_ready(NRK_DEFAULT_UART)) { c=getchar(); if(state==1) { dst_mac=c; state=2; } else if(state==2) { outlet=c; state=3; } else if(state==3) { outlet_state=c; state=4; } if(c=='S') state=1; if(c=='E') { if(state==4) { printf( "TX: %d %d %d\r\n",dst_mac, outlet, outlet_state ); tx_buf[0]=dst_mac; tx_buf[1]=outlet; tx_buf[2]=outlet_state; len=3; // Only transmit data if you want to do so // Messages from the host are always broadcasts v = tdma_send (&tx_tdma_fd, &tx_buf, len, TDMA_BLOCKING); if (v == NRK_OK) { nrk_kprintf (PSTR ("Host Packet Sent\n")); } } state=0; } } else nrk_event_wait(SIG(uart_rx_signal)); } }
void Task2() { int16_t cnt; int8_t val; uint32_t sector = 0; nrk_sem_t *radio_sem; while(1) nrk_wait_until_next_period(); radio_sem= rf_get_sem(); if(radio_sem==NULL) nrk_kprintf( PSTR("radio sem failed!\r\n" )); printf( "Task2 PID=%u\r\n",nrk_get_pid()); cnt=0; val=mmc_init(); if(val!=0 ) { printf( "val=%d\r\n",val ); nrk_kprintf( PSTR("card init failed\r\n") ); while(1); } while(1) { nrk_sem_pend (radio_sem); printf("\nsector %lu\n\r",sector); // show sector number val=mmc_readsector(sector,sectorbuffer); // read a data sector printf( "readsector returned %d\n",val ); for(cnt=0; cnt<32; cnt++ ) printf( "%d ",sectorbuffer[cnt] ); printf( "\n\r" ); val=sectorbuffer[0]; val++; for(cnt=0; cnt<512; cnt++ ) { sectorbuffer[cnt]=val; } nrk_kprintf( PSTR("Writting\r\n") ); val=mmc_writesector(sector,sectorbuffer); // read a data sector printf( "writesector returned %d\n",val ); printf( "After write:\r\n" ); val=mmc_readsector(sector,sectorbuffer); // read a data sector nrk_sem_post(radio_sem); printf( "readsector returned %d\n",val ); if(val==0) { for(cnt=0; cnt<32; cnt++ ) printf( "%d ",sectorbuffer[cnt] ); nrk_kprintf( PSTR("\n\r") ); } sector++; // nrk_led_toggle(RED_LED); // printf( "Task2 signed cnt=%d\r\n",cnt ); nrk_wait_until_next_period(); cnt--; } }
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 serial_task() { int8_t ret; if(DEBUG_SR == 0) { nrk_kprintf(PSTR("Inside serial_task. Task PID = ")); printf("%d\r\n", nrk_get_pid()); } // initialise the SLIP module slip_init (stdin, stdout, 0, 0); while(1) { // wait for the gateway to send you a message if(DEBUG_SR == 0) { nrk_kprintf(PSTR("SL: Waiting for a packet from the gateway\r\n")); } ret = slip_rx (rx_buf, SIZE_GATEWAYTONODESERIAL_PACKET); if (ret > 0) // message received successfully { if(DEBUG_SR == 0) { nrk_kprintf(PSTR("Received a message from the gateway\r\n")); } unpack_GatewayToNodeSerial_Packet_header(>n_pkt, rx_buf); switch(serial_pkt_type(>n_pkt)) { case SERIAL_APPLICATION: process_serial_app_pkt(>n_pkt); break; case SERIAL_NW_CONTROL: process_serial_nw_ctrl_pkt(>n_pkt); break; case INVALID: // drop the packet and go receive another one //printf("serial_task(): Invalid packet type received = %d\n", gtn_pkt.type); break; } // end switch } // end if else // message was corrupted { nrk_kprintf(PSTR("Failed to receive a SLIP message from gateway\r\n")); //nrk_wait_until_next_period (); } } // end while return; }
void Task3() { uint16_t cnt; uint16_t i; printf( "Task3 PID=%d\r\n",nrk_get_pid()); cnt=0; while(1) { printf( "Task3 cnt=%d\r\n",cnt ); nrk_wait_until_next_period(); cnt++; } }
void Task3() { uint16_t cnt; printf("Task3 PID=%u\r\n", nrk_get_pid()); cnt = 0; while (1) { nrk_led_toggle(BLUE_LED); nrk_gpio_toggle(NRK_DEBUG_2); printf("Task3 cnt=%u\r\n", cnt); nrk_wait_until_next_period(); cnt++; } }
void tx_task() { uint8_t cnt; printf( "tx_task PID=%d\r\n",nrk_get_pid()); cnt=0; while(1) { nrk_led_toggle(BLUE_LED); // printf( "Task2 cnt=%d\r\n",cnt ); nrk_wait_until_next_period(); cnt++; } }
void tx_task() { int8_t v,fd; uint8_t len,cnt,chan; printf( "Tx Task PID=%u\r\n",nrk_get_pid()); while(!tdma_started()) nrk_wait_until_next_period(); v=tdma_tx_slot_add(mac_address); cnt=0; while(1) { // Open ADC device as read fd = nrk_open (FIREFLY_SENSOR_BASIC, READ); nrk_wait_until_next_period(); // allow sensor to warm up if (fd == NRK_ERROR) nrk_kprintf (PSTR ("Failed to open sensor driver\r\n")); v = nrk_set_status (fd, SENSOR_SELECT, BAT); v = nrk_read (fd, &bat, 2); v = nrk_set_status (fd, SENSOR_SELECT, LIGHT); v = nrk_read (fd, &light, 2); v = nrk_set_status (fd, SENSOR_SELECT, TEMP); v = nrk_read (fd, &temp, 2); v = nrk_set_status (fd, SENSOR_SELECT, ACC_X); v = nrk_read (fd, &adxl_x, 2); v = nrk_set_status (fd, SENSOR_SELECT, ACC_Y); v = nrk_read (fd, &adxl_y, 2); v = nrk_set_status (fd, SENSOR_SELECT, ACC_Z); v = nrk_read (fd, &adxl_z, 2); v = nrk_set_status (fd, SENSOR_SELECT, AUDIO_P2P); v = nrk_read (fd, &mic, 2); nrk_close(fd); // Build a sensor packet sprintf (tx_buf, "S MAC: %u bat: %u light: %u temp: %u audio: %u adxl: %u %u %u\r\n", (uint16_t) (mac_address & 0xffff), bat, light, temp, mic, adxl_x, adxl_y, adxl_z); len=strlen(tx_buf); v=tdma_send(&tx_tdma_fd, &tx_buf, len, TDMA_BLOCKING ); if(v==NRK_OK) { printf ("%s", tx_buf); } } }
void Task4() { uint16_t cnt; uint8_t v; uint8_t row; printf( "Task4 PID=%u\r\n",nrk_get_pid()); oled_on(); cnt=0; row=0; while(1) { v=hrm_get_value(); sprintf(txt_str,"%d%d%d cnt=%d hrm=%d",nrk_gpio_get(NRK_MMC_9), nrk_gpio_get(NRK_MMC_10), nrk_gpio_get(NRK_MMC_11), cnt,v); oled_write_str( 2, row, 0, 0xFFFF, txt_str ); /* oled_clear_screen(); nrk_wait_until_ticks(50); sprintf(txt_str,"Neighbor List:"); oled_write_str( 2, 3, 0, 0xFFFF, txt_str ); nrk_wait_until_ticks(50); sprintf(txt_str," 0x100002a -27 4"); oled_write_str( 2, 4, 0, 0xFFFF, txt_str ); nrk_wait_until_ticks(50); sprintf(txt_str," 0x1000012: -30 2"); oled_write_str( 2, 5, 0, 0xFFFF, txt_str ); nrk_wait_until_ticks(50); sprintf(txt_str," 0x100000a: -5 3"); oled_write_str( 2, 6, 0, 0xFFFF, txt_str ); nrk_wait_until_ticks(50); sprintf(txt_str,"Round Trip Pkt: 93%%"); oled_write_str( 2, 9, 0, 0xFFFF, txt_str ); nrk_wait_until_ticks(50); //putc0(0x70); //putc0(0x01); //nrk_wait_until_ticks(50); oled_draw_square( 8, 83, 150, 92, 0x001F ); nrk_wait_until_ticks(50); //putc0(0x70); //putc0(0x00); //nrk_wait_until_ticks(50); oled_draw_square( 10, 85, 100, 90, 0x07e0 ); nrk_wait_until_ticks(50); */ cnt++; row++; if(row==15) { oled_clear_screen(); row=0; } nrk_wait_until_next_period(); } }
void Task2() { int16_t cnt; printf("Task2 PID=%u\r\n", nrk_get_pid()); cnt = 0; while (1) { nrk_led_toggle(GREEN_LED); nrk_gpio_toggle(NRK_DEBUG_1); printf("Running: Task2 , signed cnt=%d\r\n", cnt); nrk_wait_until_next_period(); //nrk_stats_display_pid(nrk_get_pid()); cnt--; } }
void Task4() { uint16_t cnt; printf( "Task4 PID=%u\r\n",nrk_get_pid()); cnt=0; while(1) { nrk_led_toggle(RED_LED); printf( "Task4 cnt=%u\r\n",cnt ); nrk_wait_until_next_period(); cnt++; } }
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 (); } }
void Task3 () { int8_t v; uint8_t pckts=0; printf ("radio stuff Task3 PID=%d\r\n", nrk_get_pid ()); while (slip_started () != 1) nrk_wait_until_next_period (); while (1) { v = slip_rx (slip_rx_buf, MAX_SLIP_BUF); printf("nanork@ bytesread %d\n",v); //for (i=0;i<v;i++) printf("<%d>",slip_rx_buf[i]); //printf("\n"); if (v > HDR_SIZE) { ack_buf[0] = 'Z'; ack_buf[1] = slip_rx_buf[1]; ack_buf[2] = slip_rx_buf[2]; while(uart_tx_busy==1) nrk_wait_until_next_period(); uart_tx_busy=1; slip_tx (ack_buf, 3); uart_tx_busy=0; rfTxInfo.pPayload = slip_rx_buf; rfTxInfo.length= v; rfTxInfo.destAddr = 0xFFFF; rfTxInfo.cca = 0; rfTxInfo.ackRequest = 0; nrk_led_toggle (RED_LED); pckts++; PORTG=0x1; if(rf_tx_packet(&rfTxInfo) != 1) { printf("--- RF_TX ERROR ---\r\n"); nrk_spin_wait_us(10000); } } } }
void retrans_task() { if(log_g) printf ("log:retrans_task PID=%d\r\n", nrk_get_pid ()); uint8_t cnt = 0; uint8_t connection_l; uint8_t data_cnt; uint8_t prev_data_seq = 0; // while (!bmac_started ()) nrk_wait_until_next_period (); while(1) { nrk_sem_pend(conn_sem); connection_l = connection_g; nrk_sem_post(conn_sem); if(pending_retransmit_g == 1) { if(log_g) printf("log:Re-transmitting packet\r\n"); bmac_tx_pkt(uart_rx_buf, strlen(uart_rx_buf)); retransmit_count_g++; if(retransmit_count_g==5) terminate_connection(); } else { // this checks if there is a connection and one is receivng data then // if the sender shuts down then the connection is terminated after a while if(connection_l == 1 && data_index_g < 0) { if(recv_data_seq_g == prev_data_seq) data_cnt++; if(recv_data_seq_g > prev_data_seq) { data_cnt = 0; prev_data_seq = recv_data_seq_g; } if(data_cnt > 5) { if(log_g)nrk_kprintf(PSTR("log:Recv cn term\n")); terminate_connection(); data_cnt = 0; } } cnt++; //if(log_g) printf("log:ver activ con:%d cnt:%d\n",connection_l,cnt); if(cnt>0 && connection_l == 0) { cnt = 0; vertsk_active_g = 1; } } nrk_wait_until_next_period(); } }