/****************************************************************************** * @fn halTimer32kMcuSleepTicks * * @brief This function uses Timer B to sleep for a specfied number of * ACLK ticks, that is less than 2^15 tics(1s). * Assumes that the only interrupt source is * generated by Timer B. * * NOTE: When called, this function will assign NO ISR to the * TIMERB0_VECTOR interrupt(NULL pointer). When interrupt triggers * it will just wake up the MCU. Conflicts are possible if not * used carefully since other parts of a program might use the * TIMER B. * * input parameters * * @param ticks - Number of ACLK(32768Hz) ticks that the MCU will sleep * * output parameters * * @return void */ void halTimer32kMcuSleepTicks(uint16 ticks) { halTimer32kIntConnect(NULL); halTimer32kInit(ticks); halTimer32kIntEnable(); __low_power_mode_3(); halTimer32kAbort(); }
/*********************************************************************************** * @fn appConfigTimer * * @brief Configure timer interrupts for application. Uses 32 KHz timer * * @param uint16 period - Frequency of timer interrupt. This value must be * between 1 and 32768 Hz * * @return none */ static void appConfigTimer(uint16 rate) { halTimer32kInit(TIMER_32K_CLK_FREQ/rate); halTimer32kIntConnect(&appTimerISR); }
int main(void) { #error "Hi, Currently not working, still to be tested! - I didn't find time to debug it! " //halIntOn(); unsigned long pktsSent = 0; perConfig.mode = PER_MODE_TX; perConfig.state = PER_IDLE; perConfig.channel = 26; perConfig.txPower = 0; // Index 0. Max output perConfig.burstSize = 1000000; // Max value perConfig.pktRate = 20; // 20 pkts per second perConfig.gainMode = PER_GAIN_MODE_NONE; // No PA/LNA // // Config basicRF // basicRfConfig.panId = PAN_ID; basicRfConfig.ackRequest = false; if(basicRfInit(&basicRfConfig) == FAILED) { while(1); } basicRfReceiveOff(); halRfSetTxPower(0); // appTimerConfig(20); halTimer32kInit(32768/20); halTimer32kIntConnect(&appTimerIsr); // Connect ISR halTimer32kIntEnable(); // Enable interrupts while(1) { if(perConfig.state == PER_TRANSMIT) { if(pktsSent < perConfig.burstSize) { // // Make sure sequence number has network byte order // UINT32_HTON(tTxPacket.seqNumber); basicRfSendPacket(RX_ADDR, (unsigned char*)&tTxPacket, PACKET_SIZE); // // Change byte order back to host order before increment // UINT32_NTOH(tTxPacket.seqNumber); // // Update variables // tTxPacket.seqNumber++; pktsSent++; perConfig.state = PER_PACKET_RECEIVED; // // Update LED // // bspLedToggle(BSP_LED_1); } else { // // Done sending packets, exit TX loop // break; } } } }
/*********************************************************************************** * @fn halTimer32kSetIntFrequency * * @brief Configure timer interrupts for application. Uses 32KHz timer * * input parameters * * @param rate - Frequency of timer interrupt. This value must be * between 1 and 32768 Hz * * output parameters * * @return none */ void halTimer32kSetIntFrequency(uint16 rate) { halTimer32kInit(TIMER_32K_CLK_FREQ/rate); }