void rf_set_rx(RF_RX_INFO *pRRI, uint8_t channel) { rf_flush_rx_fifo(); rf_set_channel(channel); rfSettings.pRxInfo = pRRI; MRF_FSM_RESET(); }
// Setup working channel static void setup_channel(void) { int r; set_state(st_setup); // Select control channel rf_set_channel(CTL_CHANNEL); // Wait setup message r = rfb_receive_msg(&g_rf, pkt_setup); if (r) { // Show error message rfb_err_msg(r); // Reset itself wc_delay(&g_wc, SHORT_DELAY_TICKS); reset(); } else { // Show channel number display_msg("Ch"); display_set_dp(1); display_hex_(g_rf.rx.p.setup.chan, 2, 2); } beep_on(); // Set working channel rf_set_channel(g_rf.rx.p.setup.chan); // Delay to allow sender to switch to RX wc_delay(&g_wc, SETUP_RESP_DELAY); // Send test message g_rf.tx.setup_resp.li = g_rf.rx.li; rfb_send_msg(&g_rf, pkt_setup_resp); beep_off(); // Reset itself on error or in test mode if (r || (g_rf.rx.p.setup.flags & SETUP_F_TEST)) reset(); }
// Configures RF parameters before Enhanced Shockburst can be used. static void configureRF() { packet_received = false; // Enable the radio clock rf_clock_enable(); // Set pipe address rf_set_tx_address(default_pipe_address,5); //also set addr width and pipe 0 addr // Set initial channelC rf_set_channel(default_channels[1]); // Enable shockburst rf_enable_shockburst(dr2m,n0dbm,5,false,true); //data rate 2m, pa=0dbm, retransmit 5 times, ptx mode, powerup //rf_power_up(); }
void rf_init(RF_RX_INFO *pRRI, uint8_t channel, uint16_t panId, uint16_t myAddr) { mrf_init(); rf_set_channel(channel); mrf_set_addr(myAddr); mrf_set_panid(panId); rfSettings.myAddr = myAddr; rfSettings.panId = panId; rfSettings.txSeqNumber = 1; rfSettings.pRxInfo = pRRI; rf_auto_ack_enable(); auto_ack_enable = 1; security_enable = 0; NVIC_EnableIRQ(EINT3_IRQn); // Enable the EXT3 interrupt // TODO: Paul Gurniak, check that our init settings match expected }
int main(int argc, char *argv[]) { node_id_restore(); /* init system: clocks, board etc */ system_init(); sio2host_init(); leds_init(); leds_on(LEDS_ALL); system_interrupt_enable_global(); flash_init(); delay_init(); /* Initialize Contiki and our processes. */ #ifdef LOW_POWER_MODE configure_tc3(); #else clock_init(); #endif process_init(); ctimer_init(); rtimer_init(); process_start(&etimer_process, NULL); /* Set MAC address and node ID */ #ifdef NODEID node_id = NODEID; #ifdef BURN_NODEID node_id_burn(node_id); #endif /* BURN_NODEID */ #else/* NODE_ID */ #endif /* NODE_ID */ printf("\r\n\n\n\n Starting the SmartConnect-6LoWPAN \r\n Platform : Atmel IoT device \r\n"); print_reset_causes(); netstack_init(); #if BOARD == SAMR21_XPLAINED_PRO eui64 = edbg_eui_read_eui64(); SetIEEEAddr(eui64); #else SetIEEEAddr(node_mac); #endif set_link_addr(); rf_set_channel(RF_CHANNEL); printf("\r\n Configured RF channel: %d\r\n", rf_get_channel()); leds_off(LEDS_ALL); process_start(&sensors_process, NULL); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); if(node_id > 0) { printf(" Node id %u.\r\n", node_id); } else { printf(" Node id not set.\r\n"); } /* Setup nullmac-like MAC for 802.15.4 */ #if SAMD memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr)); #else memcpy(&uip_lladdr.addr, eui64, sizeof(uip_lladdr.addr)); #endif queuebuf_init(); printf(" %s %lu %d\r\n", NETSTACK_RDC.name, (uint32_t) (CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval())), RF_CHANNEL); process_start(&tcpip_process, NULL); printf(" IPv6 Address: "); { uip_ds6_addr_t *lladdr; int i; lladdr = uip_ds6_get_link_local(-1); for(i = 0; i < 7; ++i) { printf("%02x%02x:", lladdr->ipaddr.u8[i * 2], lladdr->ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\r\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, 0xfc00, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); printf("Tentative global IPv6 address "); for(i = 0; i < 7; ++i) { printf("%02x%02x:", ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\r\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } print_processes(autostart_processes); /* set up AES key */ #if ((THSQ_CONF_NETSTACK) & THSQ_CONF_AES) #ifndef NETSTACK_AES_KEY #error Please define NETSTACK_AES_KEY! #endif /* NETSTACK_AES_KEY */ { const uint8_t key[] = NETSTACK_AES_KEY; netstack_aes_set_key(key); } printf("AES encryption is enabled\n"); #else /* ((THSQ_CONF_NETSTACK) & THSQ_CONF_AES) */ printf("\r\n Warning: AES encryption is disabled\n"); #endif /* ((THSQ_CONF_NETSTACK) & THSQ_CONF_AES) */ #ifdef ENABLE_LEDCTRL ledctrl_init(); #endif autostart_start(autostart_processes); while(1){ int r = 0; serial_data_handler(); do { r = process_run(); } while(r > 0); } }
/** * isa_set_channel() * * This function set channel and is used for channel hopping. * */ void isa_set_channel (uint8_t chan) { isa_param.channel = chan; rf_set_channel (chan); }
/* Ma-ma-ma-main function! */ void main() { command_t cmd = CMD_NO_CMD; uint16_t channel_timer = 0, bootloader_timer = 0, connection_timer = 0; uint8_t ch_i = 0; bool running; // Disable global interrupt cli(); // Set up parameters for RF communication. configureRF(); #ifdef DEBUG_LED_ P0DIR = 0; P0 = 0x55; #endif running = true; // Boot loader loop. // Will terminate after a couple of seconds if firmware has been successfully // installed. send(CMD_PING,1); while(running) { if(send_success){ if (packet_received) { connection_timer = 0; cmd = MSG_CMD; switch (cmd) { // Host initiates contact with the device. case CMD_INIT: // Send ACK to host, go to CONNECTED state if successful. sendInitAck(); // Reset timers channel_timer = bootloader_timer = 0; break; // Host starts a firmware update. case CMD_UPDATE_START: if (state == CONNECTED) { // Initiate firmware updates, go to RECEIVING_FIRMWARE state // if successful. startFirmwareUpdate(); } #ifdef DEBUG_LED_ P0 = state; #endif break; // Write message containing one hex record. case CMD_WRITE: if (state == RECEIVING_FIRMWARE) { writeHexRecord( ); } #ifdef DEBUG_LED_ P0 = 0x40; #endif break; // Firmware update has been completed. case CMD_UPDATE_COMPLETE: // Check that every byte is received. if (bytes_received == bytes_total) { // Mark firmware as successfully installed. flash_write_byte(FW_NUMBER, firmware_number); state = CONNECTED; send(CMD_ACK,1); } else { send(CMD_NACK,1); } if (!send_success) { state = ERROR; } #ifdef DEBUG_LED_ P0 = 0x10; #endif break; // Host request data from flash at specified address. case CMD_READ: readHexRecord(); #ifdef DEBUG_LED_ P0 = 0x20; #endif break; // Host sends pong to keep connections with device. case CMD_PONG: send(CMD_PING,1); #ifdef DEBUG_LED_ P0 = 0x80; #endif break; // Host sends disconnect case CMD_EXIT: send(CMD_ACK,1); if(send_success)running=false; state = PINGING; break; // These commands should no be received. case CMD_NO_CMD: default: state = ERROR; break; } // Clear command cmd = CMD_NO_CMD; }else{ //Host app do not reply, reping send(CMD_PING,1); } }else{ //host unreached if (state == PINGING) { // Will ping to one channel for 'a while' before changing. if (++channel_timer > CHANNEL_TIMEOUT) { channel_timer = 0; // Go to next channel ch_i = (ch_i+1)%CHANNEL_SIZE; rf_set_channel(default_channels[ch_i]); #ifdef DEBUG_LED_ P0 = ch_i; #endif // After changing channels and being in the PINGING state // for 'a while', boot loader loop will check if there is firmware // installed, and if so end the while(running) loop. if (++bootloader_timer > BOOTLOADER_TIMEOUT) { bootloader_timer = 0; running = (flash_read_byte(FW_NUMBER) != 0xFF) ? false : true; }else send(CMD_PING,1); } }else { if (++connection_timer > CONNECTION_TIMEOUT) state = PINGING; send(CMD_PING,1); } } } resetRF(); #ifdef DEBUG_LED_ // Default value for P0DIR P0 = 0x00; P0DIR = 0xFF; #endif // Reads address of firmware's reset vector. temp_data[0] = flash_read_byte(FW_RESET_ADDR_H); temp_data[1] = flash_read_byte(FW_RESET_ADDR_L); // sti(); //Should we enable irqs? or should the firmware enable it later? // Jump to firmware. Goodbye! ((firmware_start)(((uint16_t)temp_data[0]<<8) | (temp_data[1])))(); }
void ota_mgr_set_channel(uint8_t channel) { rf_set_channel(channel); }