/*! * Power up the Radio. * * @note * */ void vRadio_PowerUp(void) { SEGMENT_VARIABLE(wDelay, U16, SEG_XDATA) = 0u; SEGMENT_VARIABLE(lBootOpt, U8, SEG_XDATA) = 0u; /* Hardware reset the chip */ si446x_reset(); /* Wait until reset timeout or Reset IT signal */ for (; wDelay < pRadioConfiguration->Radio_Delay_Cnt_After_Reset; wDelay++); }
/*! * This function is used to load all properties and commands with a list of NULL terminated commands. * Before this function @si446x_reset should be called. */ U8 si446x_configuration_init(const U8* pSetPropCmd) { SEGMENT_VARIABLE(col, U8, SEG_DATA); SEGMENT_VARIABLE(numOfBytes, U8, SEG_DATA); /* While cycle as far as the pointer points to a command */ while (*pSetPropCmd != 0x00) { /* Commands structure in the array: * -------------------------------- * LEN | <LEN length of data> */ numOfBytes = *pSetPropCmd++; if (numOfBytes > 16u) { /* Number of command bytes exceeds maximal allowable length */ return SI446X_COMMAND_ERROR; } for (col = 0u; col < numOfBytes; col++) { Pro2Cmd[col] = *pSetPropCmd; pSetPropCmd++; } if (radio_comm_SendCmdGetResp(numOfBytes, Pro2Cmd, 0, 0) != 0xFF) { /* Timeout occured */ return SI446X_CTS_TIMEOUT; } if (radio_hal_NirqLevel() == 0) { /* Get and clear all interrupts. An error has occured... */ si446x_get_int_status(0, 0, 0); if (Si446xCmd.GET_INT_STATUS.CHIP_PEND & SI446X_CMD_GET_CHIP_STATUS_REP_CMD_ERROR_PEND_MASK) { return SI446X_COMMAND_ERROR; } } } return SI446X_SUCCESS; }
/*! * This function is used to get menu state transition caused by buttons. * * @param[in] biMenuState Actual menu state. * @param[in] biInput Stimuli of state transition. * * @return Next menu state after the transition or same if no such transition. */ U8 bMnu_MenuButtonStep(U8 biMenuState, U8 biInput) { SEGMENT_VARIABLE(bNextState, U8, SEG_DATA) = biMenuState; /**< Default stay in same state */ SEGMENT_VARIABLE(bMnuCnt, U8, SEG_DATA); // Step through the next state array (note: last element is NULL) for (bMnuCnt = 0; parMnu_AppMenuNextState[bMnuCnt].bMenuState; bMnuCnt++) { if ((parMnu_AppMenuNextState[bMnuCnt].bMenuState == biMenuState) && (parMnu_AppMenuNextState[bMnuCnt].bInput == biInput)) { // This is the one! bNextState = parMnu_AppMenuNextState[bMnuCnt].bMenuNextState; break; } } return bNextState; }
U8 radio_comm_GetResp(U8 byteCount, U8* pData) { SEGMENT_VARIABLE(ctsVal = 0u, U8); SEGMENT_VARIABLE(errCnt = RADIO_CTS_TIMEOUT, U16); while (errCnt != 0) //wait until radio IC is ready with the data { radio_hal_ClearNsel(); radio_hal_SpiWriteByte(0x44); //read CMD buffer ctsVal = radio_hal_SpiReadByte(); if (ctsVal == 0xFF) { if (byteCount) { radio_hal_SpiReadData(byteCount, pData); } radio_hal_SetNsel(); break; } radio_hal_SetNsel(); errCnt--; } if (errCnt == 0) { while(1) { /* ERROR!!!! CTS should never take this long. */ #ifdef RADIO_COMM_ERROR_CALLBACK RADIO_COMM_ERROR_CALLBACK(); #endif } } if (ctsVal == 0xFF) { ctsWentHigh = 1; } return ctsVal; }
/*! * Power up the Radio, set GPIOs to HiZ state, get Part Info * then set Sleep mode. * * @note * */ void vRadio_PowerUp(void) { SEGMENT_VARIABLE(wDelay, U16, SEG_XDATA) = 0u; si4455_reset(); for (; wDelay < pRadioConfiguration->Radio_Delay_Cnt_After_Reset; wDelay++); si4455_power_up(pRadioConfiguration->Radio_BOOT_OPTIONS, pRadioConfiguration->Radio_XTAL_OPTIONS, pRadioConfiguration->Radio_XO_FREQ); radio_comm_PollCTS(); }
/*! * This function is used to change the menu state. * * @param[in] biNewMenuState New menu state. * * @return None. */ void vMnu_MenuChangeState(U8 biNewMenuState) { SEGMENT_VARIABLE(bMnuCnt, U8, SEG_DATA); rMnu_MenuStateInfo.bMenuState = biNewMenuState; for (bMnuCnt = 0; parMnu_AppMenuState[bMnuCnt].bMenuState; bMnuCnt++) { if (parMnu_AppMenuState[bMnuCnt].bMenuState == rMnu_MenuStateInfo.bMenuState) { rMnu_MenuStateInfo.pbStateFunction = parMnu_AppMenuState[bMnuCnt].pStateFunction; break; } } }
/*! * This function is used to apply a firmware patch to the si446x radio. This * patch is stored in code using the si446x_patch.h file. * * @return SI446X_CTS_TIMEOUT If a CTS error occurs. * SI446X_PATCH_FAIL If the patch fails. * SI446X_SUCCESS If the patch is successful. * SI446X_NO_PATCH If there is no patch in the Flash to load. */ U8 si446x_apply_patch(void) { #ifdef SI446X_PATCH_CMDS SEGMENT_VARIABLE(line, U16, SEG_DATA); SEGMENT_VARIABLE(row, U8, SEG_DATA); /* Check if patch is needed. */ si446x_part_info(); if ((Si446xCmd.PART_INFO.ROMID == SI446X_PATCH_ROMID) && (Si446xCmd.PART_INFO.ID.U8[MSB] < SI446X_PATCH_ID)) { for (line = 0; line < (sizeof(Si446xPatchCommands) / 8u); line++) { for (row=0; row<8; row++) { Pro2Cmd[row] = Si446xPatchCommands[line][row]; } if (radio_comm_SendCmdGetResp(8, Pro2Cmd, 0, 0) != 0xFF) { // Timeout occured return SI446X_CTS_TIMEOUT; } if (radio_hal_NirqLevel() == 0) { /* Get and clear all interrupts. An error has occured... */ si446x_get_int_status(0, 0, 0); return SI446X_PATCH_FAIL; } } } return SI446X_SUCCESS; #else return SI446X_NO_PATCH; #endif }
/*! * This function is used to start Timer 3 in the specified mode. * * @param[in] biPrescaler Prescaler value of timer (use predefined constants: bTmr_Tmr3One_c, bTmr_Tmr3Both_c) * @param[in] wiPeriod The duration of the timing * @param[in] biItEnable Enables timer IT if TRUE, disables it if FALSE * @param[in] biExtClkSel External clock select (use predefined constants: bTmr_TxXCLK_00_c etc.) * * @return None. */ void vTmr_StartTmr3(U8 biPrescaler, U16 wiPeriod, U8 biItEnable, U8 biExtClkSel) { #ifdef SILABS_MCU_F960 SEGMENT_VARIABLE(bRestoreSfrPage, U8, SEG_DATA); bRestoreSfrPage = SFRPAGE; SFRPAGE = LEGACY_PAGE; #endif //#ifdef SILABS_MCU_F960 /* Configure the timer3 operation */ vTmr_StartTmr3_phaseConfigure(biPrescaler, wiPeriod, biItEnable, biExtClkSel, FALSE ); vTmr_StartTmr3_phaseStart(wiPeriod); #ifdef SILABS_MCU_F960 // Restore SFR page after SPI transfer SFRPAGE = bRestoreSfrPage; #endif //#ifdef SILABS_MCU_F960 }
BIT gTmr_Tmr3Expired(void) { #ifdef SILABS_MCU_F960 SEGMENT_VARIABLE(bRestoreSfrPage, U8, SEG_DATA); bRestoreSfrPage = SFRPAGE; SFRPAGE = LEGACY_PAGE; #endif //#ifdef SILABS_MCU_F960 if( (TMR3CN & M_TF3H) == 0) { return 0; } else { mTmr_StopTmr3(); return 1; } #ifdef SILABS_MCU_F960 // Restore SFR page after SPI transfer SFRPAGE = bRestoreSfrPage; #endif //#ifdef SILABS_MCU_F960 }
/** * Sample Code Demo application poll handler. * * * @note Must be called periodically. * *****************************************************************************/ void SampleCode_Demo_Pollhandler() { SEGMENT_VARIABLE(boPbPushTrack, U8, SEG_DATA); SEGMENT_VARIABLE(woPbPushTime, U16, SEG_DATA); /* Transmitter Demo state machine */ switch (SampleCode_Demo_InternalData.SampleCode_Demo_State) { case SM_START: /* Check RF picoboard EBID*/ /* Shutdown the Si4012 */ Si4012_Shutdown(); /* Check RF Pico board EBID */ if (EBID_CheckAvailability() == TRUE) { if (EBID_SearchRadioRecord() != FALSE) { /* EBIDInfo filled */ if ( (EBIDInfo.EBID_Freqband & (1u << 9u)) || (EBIDInfo.EBID_Freqband & (1u << 4u)) ) { /* Use the default settings */ pSi4012_Config_Array = pSi4012_Config_Array_Default; } else { /* Waiting for Reset */ ERROR_HOOK; } SampleCode_Demo_InternalData.SampleCode_Demo_State = SM_STEP1; break; } } /* Waiting for Reset */ ERROR_HOOK; break; case SM_STEP1: /* RF Pico Board detected */ if(TRUE == Si4012_Configure()); { /* LED4 always on */ vHmi_ChangeLedState(eHmi_Led4_c, eHmi_LedOn_c); SampleCode_Demo_InternalData.SampleCode_Demo_State = SM_STEP2; break; } /* Waiting for Reset */ ERROR_HOOK; break; case SM_STEP2: /* Check which button pushed*/ gHmi_PbIsPushed(&boPbPushTrack, &woPbPushTime); /* If Button1 pushed */ if(boPbPushTrack & eHmi_Pb1_c) { /* LED1 turned on*/ vHmi_ChangeLedState(eHmi_Led1_c, eHmi_LedBlinkOnce_c); /* Send packet 3 times */ Si4012_SendPacket(eHmi_Pb1_c); Si4012_SendPacket(eHmi_Pb1_c); Si4012_SendPacket(eHmi_Pb1_c); } /* If Button2 pushed */ if(boPbPushTrack & eHmi_Pb2_c) { /* LED2 turned on*/ vHmi_ChangeLedState(eHmi_Led2_c, eHmi_LedBlinkOnce_c); /* Send packet 3 times */ Si4012_SendPacket(eHmi_Pb2_c); Si4012_SendPacket(eHmi_Pb2_c); Si4012_SendPacket(eHmi_Pb2_c); } /* If Button3 pushed */ if(boPbPushTrack & eHmi_Pb3_c) { /* LED3 turned on */ vHmi_ChangeLedState(eHmi_Led3_c, eHmi_LedBlinkOnce_c); /* Send packet 3 times */ Si4012_SendPacket(eHmi_Pb3_c); Si4012_SendPacket(eHmi_Pb3_c); Si4012_SendPacket(eHmi_Pb3_c); } SampleCode_Demo_InternalData.SampleCode_Demo_State = SM_STEP2; break; } }