/*---------------------------------------------------------------------------*/ static int stm32w_radio_init(void) { // A channel needs also to be setted. ST_RadioSetChannel(RF_CHANNEL); // Initialize radio (analog section, digital baseband and MAC). // Leave radio powered up in non-promiscuous rx mode. ST_RadioInit(ST_RADIO_POWER_MODE_OFF); onoroff = OFF; ST_RadioSetPanId(IEEE802154_PANID); CLEAN_RXBUFS(); CLEAN_TXBUF(); #if ST_RADIO_AUTOACK && !(UIP_CONF_LL_802154 && RIMEADDR_CONF_SIZE==8) #error "Autoack and address filtering can only be used with EUI 64" #endif ST_RadioEnableAutoAck(ST_RADIO_AUTOACK); ST_RadioEnableAddressFiltering(ST_RADIO_AUTOACK); locked = 0; process_start(&stm32w_radio_process, NULL); return 0; }
/*--------------------------------------------------------------------------*/ static radio_result_t set_value(radio_param_t param, radio_value_t value) { switch(param) { case RADIO_PARAM_POWER_MODE: if(value == RADIO_POWER_MODE_ON) { stm32w_radio_on(); return RADIO_RESULT_OK; } if(value == RADIO_POWER_MODE_OFF) { stm32w_radio_off(); return RADIO_RESULT_OK; } return RADIO_RESULT_INVALID_VALUE; case RADIO_PARAM_CHANNEL: if(value < ST_MIN_802_15_4_CHANNEL_NUMBER || value > ST_MAX_802_15_4_CHANNEL_NUMBER) { return RADIO_RESULT_INVALID_VALUE; } if(ST_RadioSetChannel(value) != ST_SUCCESS) { return RADIO_RESULT_ERROR; } return RADIO_RESULT_OK; case RADIO_PARAM_PAN_ID: ST_RadioSetPanId(value & 0xffff); return RADIO_RESULT_OK; case RADIO_PARAM_16BIT_ADDR: ST_RadioSetNodeId(value & 0xffff); return RADIO_RESULT_OK; case RADIO_PARAM_RX_MODE: if(value & ~(RADIO_RX_MODE_ADDRESS_FILTER | RADIO_RX_MODE_AUTOACK)) { return RADIO_RESULT_INVALID_VALUE; } ST_RadioEnableAddressFiltering((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0); ST_RadioEnableAutoAck((value & RADIO_RX_MODE_AUTOACK) != 0); return RADIO_RESULT_OK; case RADIO_PARAM_TXPOWER: if(value < MIN_RADIO_POWER || value > MAX_RADIO_POWER) { return RADIO_RESULT_INVALID_VALUE; } if(ST_RadioSetPower((int8_t)value) != ST_SUCCESS) { return RADIO_RESULT_INVALID_VALUE; } return RADIO_RESULT_OK; case RADIO_PARAM_CCA_THRESHOLD: ST_RadioSetEdCcaThreshold((int8_t)value); return RADIO_RESULT_OK; default: return RADIO_RESULT_NOT_SUPPORTED; } }
/******************************************************************************* * Function Name : main. * Description : talk main routine. * Input : None * Output : None * Return : None *******************************************************************************/ void main(void) { u8 i; u32 seed; StStatus status = ST_SUCCESS; /* Initialization */ halInit(); ST_RadioGetRandomNumbers((u16 *)&seed, 2); halCommonSeedRandom(seed); uartInit(115200, 8, PARITY_NONE, 1); INTERRUPTS_ON(); /* init leds */ halInitLed(); /* Initialize radio (analog section, digital baseband and MAC). Leave radio powered up in non-promiscuous rx mode */ status = ST_RadioInit(ST_RADIO_POWER_MODE_RX_ON); assert(status==ST_SUCCESS); /* Setup some node and pan ids. The packet above is also sent to a device with the same node and pan id so that two nodes running this same image will talk to each other, even though its not right to have two nodes with the same node id */ ST_RadioSetNodeId(0x1604); ST_RadioSetPanId(0x1604); printf("\r\nSimpleMAC (%s) Talk Application\r\n",SIMPLEMAC_VERSION_STRING); while(1) { processSerialInput(); /* print out any packets that were received */ if(packetReceived == TRUE) { for (i = 8; i <= rxPacket[0]; i++) putchar(rxPacket[i]); /* The packet has been processed, so free the single entry queue up */ packetReceived = FALSE; } ledTime++; if (ledTime > 20000) { halToggleLed(LED_D1); ledTime = 0; } } }/* end main ()*/
void radio_init() { #ifdef EUI64_TRUNK_ID { uint8_t *eui = ST_RadioGetEui64(); my_addr8_ = eui[0]; my_addr16_ = my_addr8_; } #else { my_addr8_ = MY_ADDR; my_addr16_ = MY_ADDR; } #endif result_1 = ST_RadioSetPowerMode(0x00); #ifdef _STM32W_HIGH_POWER_ // For High Power Module use this uint16_t txPowerMode = 0x0001; //USER_TX_POWER_MODE; // Boost and alternate Tx/RX result_1 = ST_RadioSetPowerMode(txPowerMode); GPIO_PCCFGH = GPIO_PCCFGH & 0xFFFFFF0F; // PC5 GPIO_PCCFGH = GPIO_PCCFGH | 0x00000090; // PC5 = 0x9 - Special function (TX select) // Prepare PB5, PB6, PB7 for controlling the external amplifier GPIO_PBCFGH = GPIO_PBCFGH & 0xFFFF000F; GPIO_PBCFGH = GPIO_PBCFGH | 0x00001110; GPIO_PBCLR = 0x000000E0; GPIO_PBSET = 0x000000C0; // 0xC - enable LNA and activate chip, 0x4 - enable chip (exit sleep) #endif //_STM32W_HIGH_POWER_ my_rf_channel_ = DEFAULT_RF_CHANNEL; my_tx_power_ = DEFAULT_TX_POWER; // configured power level (default for orodinary communication stradio_retransmit_req_ = 0; ST_RadioSetNodeId(MY_ADDR); ST_RadioSetPanId(MY_PAN_ID); result_1 = ST_RadioSetChannel(my_rf_channel_); phy_set_power_level ( my_tx_power_ ); stradio_pending_len_ = 0; stradio_pending_data_ = NULL; stradio_pending_dst_ = 0; sch_add_loop((sch_loop_func_t)radio_loop); // GPIO_PBOUT = }
int main (void) { u8 returnValue; u32 seed; interactive = 1; halInit(); ST_RadioGetRandomNumbers((u16 *)&seed, 2); halCommonSeedRandom(seed); uartInit(115200, 8, PARITY_NONE, 1); INTERRUPTS_ON(); /* Initialize radio (analog section, digital baseband and MAC). Leave radio powered up in non-promiscuous rx mode */ returnValue = ST_RadioInit(ST_RADIO_POWER_MODE_RX_ON); assert(returnValue==ST_SUCCESS); TIMER_Init(); printf("Bootloader demo application\r\n"); responsePrintf("{&N API call... &t2x}\r\n", "halGetResetInfo", "resetInfo", 0); txBufferInit(FALSE); rxBufferInit(); blInit(NULL, transmitByte, receiveByte); ST_RadioSetPanId(IAP_BOOTLOADER_PAN_ID); ST_RadioSetChannel(IAP_BOOTLOADER_DEFAULT_CHANNEL); commandReaderInit(); while(1) { // Process input and print prompt if it returns TRUE. if (processCmdInput(interactive)) { if (interactive) { printf(">"); } TIMER_Tick(); } } }
/*---------------------------------------------------------------------------*/ static int stm32w_radio_init(void) { // A channel needs also to be setted. ST_RadioSetChannel(RF_CHANNEL); // Initialize radio (analog section, digital baseband and MAC). // Leave radio powered up in non-promiscuous rx mode. ST_RadioInit(ST_RADIO_POWER_MODE_OFF); onoroff = OFF; ST_RadioSetNodeId(STM32W_NODE_ID); // To be deleted. ST_RadioSetPanId(IEEE802154_PANID); CLEAN_RXBUFS(); CLEAN_TXBUF(); process_start(&stm32w_radio_process, NULL); return 0; }