void cmd_chibi_addr(uint8_t argc, char **argv) { if (argc > 0) { // Try to convert supplied value to an integer int32_t addr; getNumber (argv[0], &addr); // Check for invalid values (getNumber may complain about this as well) if (addr <= 0 || addr > 0xFFFF) { printf("Invalid Address: 1-65534 or 0x0001-0xFFFE required.%s", CFG_PRINTF_NEWLINE); return; } if (addr == 0xFFFF) { printf("Invalid Address: 0xFFFF reserved for broadcast.%s", CFG_PRINTF_NEWLINE); return; } // Write address to EEPROM and update peripheral control block chb_set_short_addr((uint16_t)addr); chb_pcb_t *pcb = chb_get_pcb(); printf("Address set to: 0x%04X%s", pcb->src_addr, CFG_PRINTF_NEWLINE); } else { // Display the current address chb_pcb_t *pcb = chb_get_pcb(); printf("0x%04X%s", pcb->src_addr, CFG_PRINTF_NEWLINE); } }
U8 chb_tx(U8 *hdr, U8 *data, U8 len) { U8 state = chb_get_state(); chb_pcb_t *pcb = chb_get_pcb(); if ((state == BUSY_TX) || (state == BUSY_TX_ARET)) { return RADIO_WRONG_STATE; } // TODO: check why we need to transition to the off state before we go to tx_aret_on chb_set_state(TRX_OFF); chb_set_state(TX_ARET_ON); // TODO: try and start the frame transmission by writing TX_START command instead of toggling // sleep pin...i just feel like it's kind of weird... // write frame to buffer. first write header into buffer (add 1 for len byte), then data. chb_frame_write(hdr, CHB_HDR_SZ + 1, data, len); //Do frame transmission chb_reg_read_mod_write(TRX_STATE, CMD_TX_START, 0x1F); // wait for the transmission to end, signalled by the TRX END flag while (!pcb->tx_end); pcb->tx_end = false; // check the status of the transmission return chb_get_status(); }
U8 chb_tx(U8 *hdr, U8 *data, U8 len) { U8 state = chb_get_state(); pcb_t *pcb = chb_get_pcb(); if ((state == BUSY_TX) || (state == BUSY_TX_ARET)) { return RADIO_WRONG_STATE; } // transition to the Transmit state chb_set_state(TX_ARET_ON); // write frame to buffer. first write header into buffer (add 1 for len byte), then data. chb_frame_write(hdr, CHB_HDR_SZ + 1, data, len); //Do frame transmission. pcb->tx_busy = true; chb_reg_read_mod_write(TRX_STATE, CMD_TX_START, 0x1F); // wait for the transmission to end, signalled by the TRX END flag while (!pcb->tx_end); pcb->tx_end = false; // check the status of the transmission return chb_get_status(); }
int main(void) { // Configure cpu and mandatory peripherals systemInit(); // Make sure that projectconfig.h is properly configured for this example #if !defined CFG_CHIBI #error "CFG_CHIBI must be enabled in projectconfig.h for this example" #endif #if CFG_CHIBI_PROMISCUOUS != 0 #error "CFG_CHIBI_PROMISCUOUS must be set to 0 in projectconfig.h for this example" #endif #ifdef CFG_CHIBI uint32_t counter = 0; chb_pcb_t *pcb = chb_get_pcb(); while(1) { // Enable LED gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); // Create and send the message char text[10]; counter++; itoa(counter, text, 10); chb_write(0xFFFF, text, strlen(text) + 1); // Disable LED gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); systickDelay(250); } #endif return 0; }
void chb_set_short_addr(U16 addr) { chb_pcb_t *pcb = chb_get_pcb(); chb_eeprom_write((U8*)CFG_EEPROM_CHIBI_NODEADDR, (U8*)&addr, 2); chb_reg_write16(SHORT_ADDR_0, addr); pcb->src_addr = addr; }
void chb_set_short_addr(U16 addr) { U8 *addr_ptr = (U8 *)&addr; chb_pcb_t *pcb = chb_get_pcb(); chb_eeprom_write(CFG_EEPROM_CHIBI_SHORTADDR, addr_ptr, 2); chb_reg_write16(SHORT_ADDR_0, addr); pcb->src_addr = addr; }
void chb_rcv_poll() { pcb_t *pcb = chb_get_pcb(); // if an interrupt occured, handle it if (rx_intp_flag) { chb_irq_handler(); } }
int main(void) { // Configure cpu and mandatory peripherals systemInit(); // Check if projectconfig.h is properly configured for this example #if !defined CFG_CHIBI #error "CFG_CHIBI must be enabled in projectconfig.h for this example" #endif #if CFG_CHIBI_PROMISCUOUS == 0 #error "CFG_CHIBI_PROMISCUOUS must set to 1 in projectconfig.h for this example" #endif #if !defined CFG_PRINTF_UART #error "CFG_PRINTF_UART must be enabled in projectconfig.h for this example" #endif #if defined CFG_INTERFACE #error "CFG_INTERFACE must be disabled in projectconfig.h for this example" #endif #if defined CFG_CHIBI && CFG_CHIBI_PROMISCUOUS != 0 // Get a reference to the Chibi peripheral control block chb_pcb_t *pcb = chb_get_pcb(); // Wait for incoming frames and transmit the raw data over uart while(1) { // Check for incoming messages while (pcb->data_rcv) { // get the length of the data rx_data.len = chb_read(&rx_data); // make sure the length is nonzero if (rx_data.len) { // Enable LED to indicate message reception gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); // Send raw data to UART for processing on // the PC (requires WSBridge - www.freaklabs.org) uint8_t i; for (i=0; i<rx_data.len; i++) { // Send output to UART uartSendByte(rx_data.data[i]); } // Disable LED gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); } } } #endif return 0; }
void cmd_sysinfo(uint8_t argc, char **argv) { IAP_return_t iap_return; printf("%-25s : %d.%d MHz %s", "System Clock", CFG_CPU_CCLK / 1000000, CFG_CPU_CCLK % 1000000, CFG_PRINTF_NEWLINE); printf("%-25s : v%d.%d.%d %s", "Firmware", CFG_FIRMWARE_VERSION_MAJOR, CFG_FIRMWARE_VERSION_MINOR, CFG_FIRMWARE_VERSION_REVISION, CFG_PRINTF_NEWLINE); // 128-bit MCU Serial Number iap_return = iapReadSerialNumber(); if(iap_return.ReturnCode == 0) { printf("%-25s : %08X %08X %08X %08X %s", "Serial Number", iap_return.Result[0],iap_return.Result[1],iap_return.Result[2],iap_return.Result[3], CFG_PRINTF_NEWLINE); } // CLI and buffer Settings #ifdef CFG_INTERFACE printf("%-25s : %d bytes %s", "Max CLI Command", CFG_INTERFACE_MAXMSGSIZE, CFG_PRINTF_NEWLINE); #endif #ifdef CFG_PRINTF_UART uart_pcb_t *pcb = uartGetPCB(); printf("%-25s : %d %s", "UART Baud Rate", pcb->baudrate, CFG_PRINTF_NEWLINE); #endif // TFT LCD Settings (if CFG_TFTLCD enabled) #ifdef CFG_TFTLCD printf("%-25s : %d %s", "LCD Width", (int)lcdGetWidth(), CFG_PRINTF_NEWLINE); printf("%-25s : %d %s", "LCD Height", (int)lcdGetHeight(), CFG_PRINTF_NEWLINE); #endif // Wireless Settings (if CFG_CHIBI enabled) #ifdef CFG_CHIBI chb_pcb_t *pcb = chb_get_pcb(); printf("%-25s : %s %s", "Wireless", "AT86RF212", CFG_PRINTF_NEWLINE); printf("%-25s : 0x%04X %s", "802.15.4 PAN ID", CFG_CHIBI_PANID, CFG_PRINTF_NEWLINE); printf("%-25s : 0x%04X %s", "802.15.4 Node Address", pcb->src_addr, CFG_PRINTF_NEWLINE); printf("%-25s : %d %s", "802.15.4 Channel", CFG_CHIBI_CHANNEL, CFG_PRINTF_NEWLINE); #endif // System Uptime (based on systick timer) printf("%-25s : %u s %s", "System Uptime", (unsigned int)systickGetSecondsActive(), CFG_PRINTF_NEWLINE); // System Temperature (if LM75B Present) #ifdef CFG_LM75B int32_t temp = 0; lm75bGetTemperature(&temp); temp *= 125; printf("%-25s : %d.%d C %s", "Temperature", temp / 1000, temp % 1000, CFG_PRINTF_NEWLINE); #endif #ifdef CFG_SDCARD printf("%-25s : %s %s", "SD Card Present", gpioGetValue(CFG_SDCARD_CDPORT, CFG_SDCARD_CDPIN) ? "True" : "False", CFG_PRINTF_NEWLINE); #endif }
static void chb_frame_read() { U8 i, len, data; CHB_ENTER_CRIT(); RadioCS(TRUE); /*Send frame read command and read the length.*/ SPID_write(CHB_SPI_CMD_FR); len = SPID_write(0); /*Check for correct frame length.*/ if ((len >= CHB_MIN_FRAME_LENGTH) && (len <= CHB_MAX_FRAME_LENGTH)) { // check to see if there is room to write the frame in the buffer. if not, then drop it if (len < (CHB_BUF_SZ - chb_buf_get_len())) { chb_buf_write(len); for (i=0; i<len; i++) { data = SPID_write(0); chb_buf_write(data); } //generate message received event here //EVSYS.STROBE = 0x04; //generate event on channel 3 //generate interrupt on port E by toggling pin 2 //PORTE.OUTSET = PIN2_bm; //PORTE.OUTCLR = PIN2_bm; } else { // we've overflowed the buffer. toss the data and do some housekeeping pcb_t *pcb = chb_get_pcb(); //char buf[50]; // read out the data and throw it away for (i=0; i<len; i++) { data = SPID_write(0); } // Increment the overflow stat pcb->overflow++; // grab the message from flash & print it out //strcpy_P(buf, chb_err_overflow); //printf(buf); } } RadioCS(FALSE); CHB_LEAVE_CRIT(); }
uint8_t chibiDataRcvd() { pcb_t *pcb = chb_get_pcb(); #if (CHB_RX_POLLING_MODE) // need to poll for received data if we're not retrieving the data // in the ISR chb_rcv_poll(); #endif return pcb->data_rcv; }
static void chb_frame_read() { U8 i, len, data; CHB_ENTER_CRIT(); CHB_SPI_ENABLE(); /*Send frame read command and read the length.*/ chb_xfer_byte(CHB_SPI_CMD_FR); len = chb_xfer_byte(0); // check the length of the frame to make sure its within the correct size limits if ((len >= CHB_MIN_FRAME_LENGTH) && (len <= CHB_MAX_FRAME_LENGTH)) { // check to see if there is room to write the frame in the buffer. if not, then drop it if (len < (CHB_BUF_SZ - chb_buf_get_len())) { chb_buf_write(len); for (i=0; i<len; i++) { data = chb_xfer_byte(0); chb_buf_write(data); } } else { // this frame will overflow the buffer. toss the data and do some housekeeping pcb_t *pcb = chb_get_pcb(); char buf[50]; // read out the data and throw it away for (i=0; i<len; i++) { data = chb_xfer_byte(0); } // Increment the overflow stat, and print a message. pcb->overflow++; // grab the message from flash & print it out strcpy_P(buf, chb_err_overflow); Serial.print(buf); } } CHB_SPI_DISABLE(); CHB_LEAVE_CRIT(); }
static void chb_frame_read() { U8 i, len, data; // CHB_ENTER_CRIT(); CHB_SPI_ENABLE(); /*Send frame read command and read the length.*/ chb_xfer_byte(CHB_SPI_CMD_FR); len = chb_xfer_byte(0); /*Check for correct frame length.*/ if ((len >= CHB_MIN_FRAME_LENGTH) && (len <= CHB_MAX_FRAME_LENGTH)) { // check to see if there is room to write the frame in the buffer. if not, then drop it if (len < (CFG_CHIBI_BUFFERSIZE - chb_buf_get_len())) { chb_buf_write(len); for (i=0; i<len; i++) { data = chb_xfer_byte(0); chb_buf_write(data); } } else { // we've overflowed the buffer. toss the data and do some housekeeping chb_pcb_t *pcb = chb_get_pcb(); // read out the data and throw it away for (i=0; i<len; i++) { data = chb_xfer_byte(0); } // Increment the overflow stat pcb->overflow++; // print the error message printf(chb_err_overflow); } } CHB_SPI_DISABLE(); CHB_LEAVE_CRIT(); }
U8 chb_tx(U8 *hdr, U8 *data, U8 len) { U8 state = chb_get_state(); pcb_t *pcb = chb_get_pcb(); if ((state == BUSY_TX) || (state == BUSY_TX_ARET)) { return RADIO_WRONG_STATE; } // TODO: check why we need to transition to the off state before we go to tx_aret_on chb_set_state(TRX_OFF); chb_set_state(TX_ARET_ON); // TODO: try and start the frame transmission by writing TX_START command instead of toggling // sleep pin...i just feel like it's kind of weird... // write frame to buffer. first write header into buffer (add 1 for len byte), then data. chb_frame_write(hdr, CHB_HDR_SZ + 1, data, len); // TEST - check data in buffer //{ // U8 i, len, tmp[30]; // // len = 1 + CHB_HDR_SZ + len; // chb_sram_read(0, len, tmp); // for (i=0; i<len; i++) // { // printf("%02X ", tmp[i]); // } // printf("\n"); // state = chb_get_state(); // printf("State = %02X.\n", state); //} //TEST //Do frame transmission. Toggle the SLP_TR pin to initiate the frame transmission. CHB_SLPTR_ENABLE(); CHB_SLPTR_DISABLE(); // wait for the transmission to end, signalled by the TRX END flag while (!pcb->tx_end); pcb->tx_end = false; // check the status of the transmission return chb_get_status(); }
int main(void) { // Configure cpu and mandatory peripherals systemInit(); // Make sure that projectconfig.h is properly configured for this example #if !defined CFG_CHIBI #error "CFG_CHIBI must be enabled in projectconfig.h for this example" #endif #if CFG_CHIBI_PROMISCUOUS != 0 #error "CFG_CHIBI_PROMISCUOUS must be set to 0 in projectconfig.h for this example" #endif // Get a reference to the Chibi peripheral control block chb_pcb_t *pcb = chb_get_pcb(); while(1) { // Check for incoming messages while (pcb->data_rcv) { // Enable LED to indicate message reception gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); // get the length of the data rx_data.len = chb_read(&rx_data); // make sure the length is nonzero if (rx_data.len) { int dbm = edToDBM(pcb->ed); printf("Message received from node %02X: %s, len=%d, dBm=%d.%s", rx_data.src_addr, rx_data.data, rx_data.len, dbm, CFG_PRINTF_NEWLINE); } // Disable LED gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); } } return 0; }
uint8_t chibiGetRSSI() { pcb_t *pcb = chb_get_pcb(); return pcb->ed; }
int main(void) { // Configure cpu and mandatory peripherals systemInit(); // Check if projectconfig.h is properly configured for this example #if !defined CFG_CHIBI #error "CFG_CHIBI must be enabled in projectconfig.h for this example" #endif #if CFG_CHIBI_PROMISCUOUS == 0 #error "CFG_CHIBI_PROMISCUOUS must set to 1 in projectconfig.h for this example" #endif #if defined CFG_INTERFACE #error "CFG_INTERFACE must be disabled in projectconfig.h for this example" #endif #if defined CFG_CHIBI && CFG_CHIBI_PROMISCUOUS != 0 // Get a reference to the Chibi peripheral control block chb_pcb_t *pcb = chb_get_pcb(); // Wait for incoming frames and transmit the raw data over uart while(1) { // Check for incoming messages while (pcb->data_rcv) { // get the length of the data rx_data.len = chb_read(&rx_data); // make sure the length is nonzero if (rx_data.len) { // Enable LED to indicate message reception gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); // Send raw data the to PC for processing using wsbridge uint8_t i; for (i=0; i<rx_data.len; i++) { #ifdef CFG_PRINTF_UART uartSendByte(rx_data.data[i]); #endif #ifdef CFG_PRINTF_USBCDC // ToDo: This really needs to be refactored! if (USB_Configuration) { cdcBufferWrite(rx_data.data[i]); // Check if we can flush the buffer now or if we need to wait unsigned int currentTick = systickGetTicks(); if (currentTick != lastTick) { uint8_t frame[64]; uint32_t bytesRead = 0; while (cdcBufferDataPending()) { // Read 64 byte chunks until end of data bytesRead = cdcBufferReadLen(frame, 64); // debug_printf("%d,", bytesRead); USB_WriteEP (CDC_DEP_IN, frame, bytesRead); systickDelay(1); } lastTick = currentTick; } } #endif } // Disable LED gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); } } } #endif return 0; }
void cmd_sysinfo(uint8_t argc, char **argv) { IAP_return_t iap_return; /* Note: Certain values are only reported if CFG_INTERFACE_LONGSYSINFO is set to 1 in projectconfig.h. These extra values are more useful for debugging than real-world use, so there's no point wasiting flash space storing the code for them */ printf("%-25s : %d.%d.%d %s", "Firmware", CFG_FIRMWARE_VERSION_MAJOR, CFG_FIRMWARE_VERSION_MINOR, CFG_FIRMWARE_VERSION_REVISION, CFG_PRINTF_NEWLINE); printf("%-25s : %d.%d MHz %s", "System Clock", CFG_CPU_CCLK / 1000000, CFG_CPU_CCLK % 1000000, CFG_PRINTF_NEWLINE); // System Uptime (based on systick timer) printf("%-25s : %u s %s", "System Uptime", (unsigned int)systickGetSecondsActive(), CFG_PRINTF_NEWLINE); // 128-bit MCU Serial Number iap_return = iapReadSerialNumber(); if(iap_return.ReturnCode == 0) { printf("%-25s : %08X %08X %08X %08X %s", "Serial Number", iap_return.Result[0],iap_return.Result[1],iap_return.Result[2],iap_return.Result[3], CFG_PRINTF_NEWLINE); } #if CFG_INTERFACE_LONGSYSINFO #ifdef CFG_USBCDC printf("%-25s : %d ms %s", "USB Init Timeout", CFG_USBCDC_INITTIMEOUT, CFG_PRINTF_NEWLINE); #endif #endif // CLI and buffer Settings #if CFG_INTERFACE_LONGSYSINFO printf("%-25s : %d bytes %s", "CLI Max Command Size", CFG_INTERFACE_MAXMSGSIZE, CFG_PRINTF_NEWLINE); printf("%-25s : %s %s", "CLI IRQ Enabled", CFG_INTERFACE_ENABLEIRQ ? "True" : "False", CFG_PRINTF_NEWLINE); #if CFG_INTERFACE_ENABLEIRQ printf("%-25s : %d.%d %s", "CLI IRQ Location", CFG_INTERFACE_IRQPORT, CFG_INTERFACE_IRQPIN, CFG_PRINTF_NEWLINE); #endif #endif #if CFG_INTERFACE_LONGSYSINFO #ifdef CFG_I2CEEPROM printf("%-25s : %d bytes %s", "EEPROM Size", CFG_I2CEEPROM_SIZE, CFG_PRINTF_NEWLINE); #endif #endif #ifdef CFG_SDCARD printf("%-25s : %s %s", "SD Card Present", gpioGetValue(CFG_SDCARD_CDPORT, CFG_SDCARD_CDPIN) ? "True" : "False", CFG_PRINTF_NEWLINE); #if CFG_INTERFACE_LONGSYSINFO printf("%-25s : %s %s", "FAT File System", CFG_SDCARD_READONLY ? "Read Only" : "Read/Write", CFG_PRINTF_NEWLINE); #endif #endif #ifdef CFG_PRINTF_UART uart_pcb_t *pcb = uartGetPCB(); printf("%-25s : %u %s", "UART Baud Rate", (unsigned int)(pcb->baudrate), CFG_PRINTF_NEWLINE); #endif // TFT LCD Settings (if CFG_TFTLCD enabled) #ifdef CFG_TFTLCD printf("%-25s : %d %s", "LCD Width", (int)lcdGetWidth(), CFG_PRINTF_NEWLINE); printf("%-25s : %d %s", "LCD Height", (int)lcdGetHeight(), CFG_PRINTF_NEWLINE); #if CFG_INTERFACE_LONGSYSINFO printf("%-25s : %04X %s", "LCD Controller ID", (unsigned short)lcdGetControllerID(), CFG_PRINTF_NEWLINE); printf("%-25s : %s %s", "LCD Small Fonts", CFG_TFTLCD_INCLUDESMALLFONTS == 1 ? "True" : "False", CFG_PRINTF_NEWLINE); printf("%-25s : %s %s", "LCD AA Fonts", CFG_TFTLCD_USEAAFONTS == 1 ? "True" : "False", CFG_PRINTF_NEWLINE); lcdProperties_t lcdprops = lcdGetProperties(); printf("%-25s : %s %s", "Touch Screen", lcdprops.touchscreen ? "True" : "False", CFG_PRINTF_NEWLINE); if (lcdprops.touchscreen) { printf("%-25s : %s %s", "Touch Screen Calibrated", eepromReadU8(CFG_EEPROM_TOUCHSCREEN_CALIBRATED) == 1 ? "True" : "False", CFG_PRINTF_NEWLINE); printf("%-25s : %d %s", "Touch Screen Threshold", CFG_TFTLCD_TS_DEFAULTTHRESHOLD, CFG_PRINTF_NEWLINE); } #endif #endif // Wireless Settings (if CFG_CHIBI enabled) #ifdef CFG_CHIBI chb_pcb_t *pcb = chb_get_pcb(); printf("%-25s : %s %s", "Wireless", "AT86RF212", CFG_PRINTF_NEWLINE); printf("%-25s : 0x%04X %s", "802.15.4 PAN ID", CFG_CHIBI_PANID, CFG_PRINTF_NEWLINE); printf("%-25s : 0x%04X %s", "802.15.4 Node Address", pcb->src_addr, CFG_PRINTF_NEWLINE); printf("%-25s : %d %s", "802.15.4 Channel", CFG_CHIBI_CHANNEL, CFG_PRINTF_NEWLINE); #endif // System Temperature (if LM75B Present) #ifdef CFG_LM75B int32_t temp = 0; lm75bGetTemperature(&temp); temp *= 125; printf("%-25s : %d.%d C %s", "Temperature", temp / 1000, temp % 1000, CFG_PRINTF_NEWLINE); #endif // ADC Averaging #if CFG_INTERFACE_LONGSYSINFO printf("%-25s : %s %s", "ADC Averaging", ADC_AVERAGING_ENABLE ? "True" : "False", CFG_PRINTF_NEWLINE); #if ADC_AVERAGING_ENABLE printf("%-25s : %d %s", "ADC Averaging Samples", ADC_AVERAGING_SAMPLES, CFG_PRINTF_NEWLINE); #endif #endif // Debug LED #if CFG_INTERFACE_LONGSYSINFO printf("%-25s : %d.%d %s", "LED Location", CFG_LED_PORT, CFG_LED_PIN, CFG_PRINTF_NEWLINE); #endif }
static void chb_irq_handler() { U8 dummy, state, pinval; pcb_t *pcb = chb_get_pcb(); // find out who issued the interrupt intp_src |= chb_reg_read(IRQ_STATUS); while (intp_src) { /*Handle the incomming interrupt. Prioritized.*/ if ((intp_src & CHB_IRQ_RX_START_MASK)) { intp_src &= ~CHB_IRQ_RX_START_MASK; } else if (intp_src & CHB_IRQ_TRX_END_MASK) { state = chb_get_state(); if ((state == RX_ON) || (state == RX_AACK_ON) || (state == BUSY_RX_AACK)) { // get the ed measurement pcb->ed = chb_reg_read(PHY_ED_LEVEL); // get the crc pcb->crc = (chb_reg_read(PHY_RSSI) & (1<<7)) ? 1 : 0; // if the crc is not valid, then do not read the frame and set the rx flag // CHECK COMMENTED OUT FOR PROMISCOUS MODE OPERATION //if (pcb->crc) //{ pcb->data_rcv = true; chb_frame_read(); // get the data pcb->rcvd_xfers++; //} } intp_src &= ~CHB_IRQ_TRX_END_MASK; // THIS IS CHANGED FOR PROMISCOUS MODE (to match above mode setting change): //while (chb_set_state(RX_AACK_ON) != RADIO_SUCCESS); while (chb_set_state(RX_ON) != RADIO_SUCCESS); } else if (intp_src & CHB_IRQ_TRX_UR_MASK) { intp_src &= ~CHB_IRQ_TRX_UR_MASK; pcb->underrun++; } else if (intp_src & CHB_IRQ_PLL_UNLOCK_MASK) { intp_src &= ~CHB_IRQ_PLL_UNLOCK_MASK; } else if (intp_src & CHB_IRQ_PLL_LOCK_MASK) { intp_src &= ~CHB_IRQ_PLL_LOCK_MASK; } else if (intp_src & CHB_IRQ_BAT_LOW_MASK) { intp_src &= ~CHB_IRQ_BAT_LOW_MASK; pcb->battlow++; } else { } } rx_intp_flag = false; CHB_IRQ_ENABLE(); }
void cmd_sysinfo(uint8_t argc, char **argv) { printf("%-25s : %d.%d MHz %s", "System Clock", CFG_CPU_CCLK / 1000000, CFG_CPU_CCLK % 1000000, CFG_PRINTF_NEWLINE); printf("%-25s : %d.%d.%d %s", "Firmware", CFG_FIRMWARE_VERSION_MAJOR, CFG_FIRMWARE_VERSION_MINOR, CFG_FIRMWARE_VERSION_REVISION, CFG_PRINTF_NEWLINE); // 128-bit MCU Serial Number IAP_return_t iap_return; iap_return = iapReadSerialNumber(); if(iap_return.ReturnCode == 0) { printf("%-25s : %08X %08X %08X %08X %s", "Serial Number", iap_return.Result[0],iap_return.Result[1],iap_return.Result[2],iap_return.Result[3], CFG_PRINTF_NEWLINE); } // Check the battery voltage #ifdef CFG_BAT uint32_t c; gpioSetDir(CFG_BAT_ENPORT, CFG_BAT_ENPIN, gpioDirection_Output ); gpioSetValue(CFG_BAT_ENPORT, CFG_BAT_ENPIN, 1 ); // Enable the voltage divider systickDelay(5); c = adcRead(CFG_BAT_ADC); // Pre-read ADC to warm it up systickDelay(10); c = adcRead(CFG_BAT_ADC); c = (c * CFG_VREG_VCC_MAIN) / 1000; // Value in millivolts relative to supply voltage c = (c * CFG_BAT_MULTIPLIER) / 1000; // Battery voltage in millivolts (depends on resistor values) gpioSetValue(CFG_BAT_ENPORT, CFG_BAT_ENPIN, 0 ); // Turn the voltage divider back off to save power printf("%-25s : %u.%u V %s", "Supply Voltage", (unsigned int)(c / 1000), (unsigned int)(c % 1000), CFG_PRINTF_NEWLINE); #endif // Wireless Settings (if CFG_CHIBI enabled) #ifdef CFG_CHIBI chb_pcb_t *pcb = chb_get_pcb(); printf("%-25s : %s %s", "RF Transceiver", "AT86RF212", CFG_PRINTF_NEWLINE); #if CFG_CHIBI_PROMISCUOUS == 1 printf("%-25s : %s %s", "RF Receive Mode", "Promiscuous", CFG_PRINTF_NEWLINE); #else printf("%-25s : %s %s", "RF Receive Mode", "Normal", CFG_PRINTF_NEWLINE); #endif printf("%-25s : 0x%04X (%d) %s", "802.15.4 PAN ID", CFG_CHIBI_PANID, CFG_CHIBI_PANID, CFG_PRINTF_NEWLINE); printf("%-25s : 0x%04X (%d) %s", "802.15.4 Node Address", pcb->src_addr, pcb->src_addr, CFG_PRINTF_NEWLINE); printf("%-25s : %d %s", "802.15.4 Channel", CFG_CHIBI_CHANNEL, CFG_PRINTF_NEWLINE); #endif // CLI and buffer Settings #ifdef CFG_INTERFACE printf("%-25s : %d bytes %s", "Max CLI Command", CFG_INTERFACE_MAXMSGSIZE, CFG_PRINTF_NEWLINE); #endif // System Uptime (based on systick timer) printf("%-25s : %u s %s", "System Uptime", (unsigned int)systickGetSecondsActive(), CFG_PRINTF_NEWLINE); // System Temperature (if LM75B Present) #ifdef CFG_LM75B int32_t temp = 0; lm75bGetTemperature(&temp); temp *= 125; printf("%-25s : %d.%d C %s", "Temperature", (int)(temp / 1000), (int)(temp % 1000), CFG_PRINTF_NEWLINE); #endif #ifdef CFG_SDCARD printf("%-25s : %s %s", "SD Card Present", gpioGetValue(CFG_SDCARD_CDPORT, CFG_SDCARD_CDPIN) ? "True" : "False", CFG_PRINTF_NEWLINE); #endif }
void chb_ISR_Handler (void) { U8 dummy, state, intp_src = 0; chb_pcb_t *pcb = chb_get_pcb(); CHB_ENTER_CRIT(); /*Read Interrupt source.*/ CHB_SPI_ENABLE(); /*Send Register address and read register content.*/ dummy = chb_xfer_byte(IRQ_STATUS | CHB_SPI_CMD_RR); intp_src = chb_xfer_byte(0); CHB_SPI_DISABLE(); while (intp_src) { /*Handle the incomming interrupt. Prioritized.*/ if ((intp_src & CHB_IRQ_RX_START_MASK)) { intp_src &= ~CHB_IRQ_RX_START_MASK; } else if (intp_src & CHB_IRQ_TRX_END_MASK) { state = chb_get_state(); if ((state == RX_ON) || (state == RX_AACK_ON) || (state == BUSY_RX_AACK)) { // get the ed measurement pcb->ed = chb_reg_read(PHY_ED_LEVEL); // get the crc pcb->crc = (chb_reg_read(PHY_RSSI) & (1<<7)) ? 1 : 0; // if the crc is not valid, then do not read the frame and set the rx flag if (pcb->crc) { // get the data chb_frame_read(); pcb->rcvd_xfers++; pcb->data_rcv = true; } } else { pcb->tx_end = true; } intp_src &= ~CHB_IRQ_TRX_END_MASK; while (chb_set_state(RX_STATE) != RADIO_SUCCESS); } else if (intp_src & CHB_IRQ_TRX_UR_MASK) { intp_src &= ~CHB_IRQ_TRX_UR_MASK; pcb->underrun++; } else if (intp_src & CHB_IRQ_PLL_UNLOCK_MASK) { intp_src &= ~CHB_IRQ_PLL_UNLOCK_MASK; } else if (intp_src & CHB_IRQ_PLL_LOCK_MASK) { intp_src &= ~CHB_IRQ_PLL_LOCK_MASK; } else if (intp_src & CHB_IRQ_BAT_LOW_MASK) { intp_src &= ~CHB_IRQ_BAT_LOW_MASK; pcb->battlow++; } else { } } CHB_LEAVE_CRIT(); }
int main(void) { // Configure cpu and mandatory peripherals systemInit(); // Check if projectconfig.h is properly configured for this example #if !defined CFG_CHIBI #error "CFG_CHIBI must be enabled in projectconfig.h for this example" #endif #if CFG_CHIBI_PROMISCUOUS == 0 #error "CFG_CHIBI_PROMISCUOUS must set to 1 in projectconfig.h for this example" #endif #if !defined CFG_SDCARD #error "CFG_SDCARD must be enabled in projectconfig.h for this example" #endif #if defined CFG_CHIBI && defined CFG_SDCARD && CFG_CHIBI_PROMISCUOUS != 0 // Get a reference to the Chibi peripheral control block chb_pcb_t *pcb = chb_get_pcb(); // Create a binary file to store captured data libpcap_error_t error; error = libpcapInit("/capture.cap"); if (error) { // Something happened trying to create the file or access the SD card switch (error) { case LIBPCAP_ERROR_FATFS_NODISK: printf("No Disk\r\n"); break; case LIBPCAP_ERROR_FATFS_INITFAILED: printf("Init Failed\r\n"); break; case LIBPCAP_ERROR_FATFS_FAILEDTOMOUNTDRIVE: printf("Failed to mount drive\r\n"); break; case LIBPCAP_ERROR_FATFS_UNABLETOCREATEFILE: printf("Unable to create file\r\n"); break; } // Quit the program return -1; } // Wait for incoming frames and log them to disk in libpcap format. while(1) { // Check for incoming messages while (pcb->data_rcv) { // get the length of the data rx_data.len = chb_read(&rx_data); // make sure the length is non-zero if (rx_data.len) { // Enable LED to indicate message reception gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); // Write frame content to disk libpcapWriteFrame(rx_data.data, rx_data.len); // Disable LED gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); } } } #endif return 0; }