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 () { 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 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; }
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; }
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; }
int8_t slip_init (FILE * device_in, FILE * device_out, bool echo, uint8_t delay) { g_dv_in = device_in; g_dv_out = device_out; g_echo = echo; g_delay = delay; #ifndef UART_PCP_CEILING #define UART_PCP_CEILING 255 #endif slip_tx_sem = nrk_sem_create (1, UART_PCP_CEILING); if (slip_tx_sem == NRK_ERROR) nrk_kernel_error_add (NRK_SEMAPHORE_CREATE_ERROR, nrk_get_pid ()); _slip_started = NRK_OK; return NRK_OK; }
int main () { nrk_setup_ports(); nrk_setup_uart(UART_BAUDRATE_115K2); printf( "Starting up...\r\n" ); nrk_init(); nrk_time_set(0,0); //Initialize tasks INITIALIZE_TASK(1); INITIALIZE_TASK(2); INITIALIZE_TASK(3); //instead of passing the ceiling priority, the task with the shortest period that accesses the semaphore is given //in this case, task1 which has a period 350*NANOS_PER_MS my_semaphore = nrk_sem_create(1,350*NANOS_PER_MS); if(my_semaphore==NULL) nrk_kprintf( PSTR("Error creating sem\r\n" )); nrk_start(); return 0; }
void initialise_buffer_manager() { int8_t i; // loop index // initialise the receive buffers for(i = 0; i < MAX_RX_QUEUE_SIZE; i++) { rx_buf_udp[i].status = UNALLOCATED; // initially all rx buffers are unallocated rx_buf_udp[i].next = NULL; // no links formed as of yet } num_bufs_free = MAX_RX_QUEUE_SIZE; // initially all rx buffers are unallocated // initialise the receive buffer managers for(i = 0; i < NUM_PORTS; i++) { rx_buf_mgr[i].pid = INVALID_PID; // pid of task associated with the port rx_buf_mgr[i].pindex = -1; // indicates absence of rbm/port mapping rx_buf_mgr[i].head_fq = NULL; rx_buf_mgr[i].tail_fq = NULL; rx_buf_mgr[i].head_pq = NULL; rx_buf_mgr[i].tail_pq = NULL; rx_buf_mgr[i].countTotal = 0; rx_buf_mgr[i].countFree = 0; } // initialise the transmit buffer manager tx_buf_mgr.head_fq = NULL; tx_buf_mgr.tail_fq = NULL; tx_buf_mgr.head_aq = NULL; tx_buf_mgr.tail_aq = NULL; tx_buf_mgr.count_fq = 0; tx_buf_mgr.count_aq = 0; // initialise the transmit buffers for(i = 0; i < MAX_TX_QUEUE_SIZE; i++) { tx_buf[i].status = EMPTY; tx_buf[i].next = NULL; initialise_nw_packet( &(tx_buf[i].pkt) ); insert_tx_fq( &(tx_buf[i]) ); } // initialise the excess policy settings excessPolicySettings = 0; // by default, its OVERWRITE for all priority levels bm_sem = nrk_sem_create(1,MAX_TASK_PRIORITY); // create the mutex if(bm_sem == NULL) { nrk_int_disable(); nrk_led_set(RED_LED); while(1) nrk_kprintf(PSTR("initialise_buffer_manager(): Error creating the semaphore\r\n")); } if(DEBUG_BM == 2) { nrk_kprintf(PSTR("Initial tx buffer\r\n")); print_tx_buffer(); } return; }
//------------------------------------------------------------------------------------------------------- // void rf_init(RF_RX_INFO *pRRI, uint8_t channel, WORD panId, WORD myAddr) // // DESCRIPTION: // Initializes CC2420 for radio communication via the basic RF library functions. Turns on the // voltage regulator, resets the CC2420, turns on the crystal oscillator, writes all necessary // registers and protocol addresses (for automatic address recognition). Note that the crystal // oscillator will remain on (forever). // // ARGUMENTS: // RF_RX_INFO *pRRI // A pointer the RF_RX_INFO data structure to be used during the first packet reception. // The structure can be switched upon packet reception. // uint8_t channel // The RF channel to be used (11 = 2405 MHz to 26 = 2480 MHz) // WORD panId // The personal area network identification number // WORD myAddr // The 16-bit short address which is used by this node. Must together with the PAN ID form a // unique 32-bit identifier to avoid addressing conflicts. Normally, in a 802.15.4 network, the // short address will be given to associated nodes by the PAN coordinator. //------------------------------------------------------------------------------------------------------- void rf_init(RF_RX_INFO *pRRI, uint8_t channel, uint16_t panId, uint16_t myAddr) { uint8_t n; #ifdef RADIO_PRIORITY_CEILING int8_t v; radio_sem = nrk_sem_create(1,RADIO_PRIORITY_CEILING); if (radio_sem == NULL) nrk_kernel_error_add (NRK_SEMAPHORE_CREATE_ERROR, nrk_get_pid ()); v = nrk_sem_pend (radio_sem); if (v == NRK_ERROR) { nrk_kprintf (PSTR ("CC2420 ERROR: Access to semaphore failed\r\n")); } #endif // Make sure that the voltage regulator is on, and that the reset pin is inactive SET_VREG_ACTIVE(); halWait(1000); SET_RESET_ACTIVE(); halWait(1); SET_RESET_INACTIVE(); halWait(100); // Initialize the FIFOP external interrupt //FIFOP_INT_INIT(); //ENABLE_FIFOP_INT(); // Turn off all interrupts while we're accessing the CC2420 registers DISABLE_GLOBAL_INT(); FASTSPI_STROBE(CC2420_SXOSCON); mdmctrl0=0x02E2; FASTSPI_SETREG(CC2420_MDMCTRL0, mdmctrl0); // Std Preamble, CRC, no auto ack, no hw addr decoding //FASTSPI_SETREG(CC2420_MDMCTRL0, 0x0AF2); // Turn on automatic packet acknowledgment // Turn on hw addre decoding FASTSPI_SETREG(CC2420_MDMCTRL1, 0x0500); // Set the correlation threshold = 20 FASTSPI_SETREG(CC2420_IOCFG0, 0x007F); // Set the FIFOP threshold to maximum FASTSPI_SETREG(CC2420_SECCTRL0, 0x01C4); // Turn off "Security" FASTSPI_SETREG(CC2420_RXCTRL1, 0x1A56); // All default except // reference bias current to RX // bandpass filter is set to 3uA /* // FIXME: remove later for auto ack myAddr=MY_MAC; panId=0x02; FASTSPI_SETREG(CC2420_MDMCTRL0, 0x0AF2); // Turn on automatic packet acknowledgment // FASTSPI_SETREG(CC2420_MDMCTRL0, 0x0AE2); // Turn on automatic packet acknowledgment nrk_spin_wait_us(500); nrk_spin_wait_us(500); FASTSPI_WRITE_RAM_LE(&myAddr, CC2420RAM_SHORTADDR, 2, n); nrk_spin_wait_us(500); FASTSPI_WRITE_RAM_LE(&panId, CC2420RAM_PANID, 2, n); nrk_spin_wait_us(500); printf( "myAddr=%d\r\n",myAddr ); */ nrk_spin_wait_us(500); FASTSPI_WRITE_RAM_LE(&panId, CC2420RAM_PANID, 2, n); nrk_spin_wait_us(500); ENABLE_GLOBAL_INT(); // Set the RF channel halRfSetChannel(channel); // Turn interrupts back on ENABLE_GLOBAL_INT(); // Set the protocol configuration rfSettings.pRxInfo = pRRI; rfSettings.panId = panId; rfSettings.myAddr = myAddr; rfSettings.txSeqNumber = 0; rfSettings.receiveOn = FALSE; // Wait for the crystal oscillator to become stable halRfWaitForCrystalOscillator(); // Write the short address and the PAN ID to the CC2420 RAM (requires that the XOSC is on and stable) // DISABLE_GLOBAL_INT(); // FASTSPI_WRITE_RAM_LE(&myAddr, CC2420RAM_SHORTADDR, 2, n); // FASTSPI_WRITE_RAM_LE(&panId, CC2420RAM_PANID, 2, n); // ENABLE_GLOBAL_INT(); #ifdef RADIO_PRIORITY_CEILING v = nrk_sem_post (radio_sem); if (v == NRK_ERROR) { nrk_kprintf (PSTR ("CC2420 ERROR: Release of semaphore failed\r\n")); _nrk_errno_set (2); } #endif auto_ack_enable=0; security_enable=0; last_pkt_encrypted=0; } // rf_init()
int main() { packet act_packet; // setup ports/uart nrk_setup_ports(); nrk_setup_uart(UART_BAUDRATE_115K2); SPI_Init(); pwr_init(); nrk_init (); nrk_time_set (0, 0); // clear all LEDs nrk_led_clr(0); nrk_led_clr(1); nrk_led_clr(2); nrk_led_clr(3); // flags g_verbose = FALSE; g_network_joined = FALSE; g_global_outlet_state = OFF; g_button_pressed = FALSE; // mutexs g_net_tx_buf_mux = nrk_sem_create(1, 8); g_act_queue_mux = nrk_sem_create(1, 8); g_cmd_tx_queue_mux = nrk_sem_create(1, 8); g_data_tx_queue_mux = nrk_sem_create(1, 8); g_seq_num_mux = nrk_sem_create(1, 8); g_network_joined_mux = nrk_sem_create(1, 8); g_global_outlet_state_mux = nrk_sem_create(1, 8); g_button_pressed_mux = nrk_sem_create(1, 8); g_net_watchdog_mux = nrk_sem_create(1, 8); // sensor periods (in seconds / 2) g_pwr_period = 2; g_temp_period = 3; g_light_period = 4; // packet queues packet_queue_init(&g_act_queue); packet_queue_init(&g_cmd_tx_queue); packet_queue_init(&g_data_tx_queue); // ensure node is initially set to "OFF" act_packet.source_id = MAC_ADDR; act_packet.type = MSG_CMD; act_packet.seq_num = 0; act_packet.num_hops = 0; act_packet.payload[CMD_CMDID_INDEX] = (uint16_t)0; act_packet.payload[CMD_NODE_ID_INDEX] = MAC_ADDR; act_packet.payload[CMD_ACT_INDEX] = OFF; atomic_push(&g_act_queue, &act_packet, g_act_queue_mux); // initialize bmac bmac_task_config (); bmac_init(13); nrk_register_drivers(); nrk_set_gpio(); nrk_create_taskset(); nrk_start (); return 0; }