/*------------------------------------------------------------------------------ * * FUNCTION DESCRIPTION: * This function contains the loop which consists of three procedures, * tx setup, tx loop and tx shutdown in the application. * During waiting for repeat transmission, check button state. * Once any new push button is detected, then transmit the new packet * instead of the current packet. * *------------------------------------------------------------------------------ */ void vRepeatTxLoop (void) { vFCast_Tune( fDesiredFreq ); if (rOdsSetup.bModulationType == bModFSK_c) { vFCast_FskAdj( bFskDev ); } // Wait until there is a temperature sample available while ( 0 == bDmdTs_GetSamplesTaken() ) { //wait } // Tune the PA with the temperature as an argument vPa_Tune( iDmdTs_GetLatestTemp()); vPacketAssemble(); //Convert whole frame before transmission vConvertPacket(rOdsSetup.bModulationType); vStl_PreLoop(); do { // get current timestamp lTimestamp = lSys_GetMasterTime(); //if part is burned to user or run mode if ((PROT0_CTRL & M_NVM_BLOWN) > 1) { //turn LED on GPIO_LED = 1; } while ( (lSys_GetMasterTime() - lTimestamp) < lLEDOnTime ) { //wait for LED ON time to expire } GPIO_LED = 0; //turn LED off //Transmit packet vStl_SingleTxLoop(pbFrameHead,bFrameSize); // Wait repeat interval. while ( (lSys_GetMasterTime() - lTimestamp) < wRepeatInterval_c ); }while(--bRepeatCount); vStl_PostLoop(); // Clear time value for next button push detecting. vSys_SetMasterTime(0); return; }
/*------------------------------------------------------------------------------ * * FUNCTION DESCRIPTION: * This function tunes the si4010 for transmission and transmits frames. * It consists of two fundamental phases, setup and the transmission loop. * * Setup Phase: * The Setup Phase calls all setup function for the need API modules. * These functions are to be called once per boot of the chip. * vSys_Setup * vPa_Setup * vOds_Setup * vStl_EncodeSetup * vFCast_Setup * * Transmission Loop Phase: * The Transmission Loop Phase is a loop which transmits the proper frame * once a button is pushed. Frequency casting, FSK adjustment * and PA tuning are all performed between each transmission. * *------------------------------------------------------------------------------ */ void main(void) { /*------------------------------------------------------------------------------ * SETUP PHASE *------------------------------------------------------------------------------ */ //Set DMD interrupt to high priority, // any other interrupts have to stay low priority PDMD=1; // Parameters Initialization. vAppInitial(); // Call the system setup. This just for initialization. // Argument of 1 just configures the SYS module such that the // bandgap can be turned off if needed. vSys_Setup( 1 ); // Setup the bandgap for working with the temperature sensor here vSys_BandGapLdo( 1 ); // Setup the BSR vBsr_Setup( &rBsrSetup ); // Setup the RTC to tick every 5ms and clear it. Keep it disabled. RTC_CTRL = (0x07 << B_RTC_DIV) | M_RTC_CLR; // Enable the RTC RTC_CTRL |= M_RTC_ENA; // Enable the RTC interrupt and global interrupt enable ERTC = 1; EA = 1; // Setup the PA vPa_Setup( &rPaSetup ); // ODS setup vOds_Setup( &rOdsSetup ); // Setup the STL encoding to NoneNrz code. we // leave the pointer at NULL. // vStl_EncodeSetup( bEnc_Manchester_c, NULL ); vStl_EncodeSetup( bEnc_NoneNrz_c, NULL ); // Setup frequency casting .. needed to be called once per boot vFCast_Setup(); /*------------------------------------------------------------------------------ * TRANSMISSION LOOP PHASE *------------------------------------------------------------------------------ */ // Application loop, including push button state analyzation and transmission. while(1) { // Buttons analyzation and update task flag. vButtonCheck(); if (bAp_ButtonState) { // Set frame size and frame header pointer vPacketAssemble(); if (lPayLoad) { // Start to transmit vRtl_RepeatTxLoop(); } } else if( (lSys_GetMasterTime() >> 5) > bMaxWaitForPush_c ) { // Shutdown if timeout, currently after about 1.6s, // For debugging with IDE, comment it out since it does not support boot. vSys_Shutdown(); } } }