/************************************************************************************ * Initialize platform and stack. * * This function is the main initialization procedure, which will be called from the * startup code of the project. * If the code is build as a stand-alone application, this function is * called from main() below. * * Interface assumptions: * * Return value: * NONE * * ************************************************************************************/ void Init_802_15_4(bool_t mUseTS) { gbTaskMode = mUseTS; MacPhyInit_Initialize(); // Init 802.15.4 MAC/PHY stack MacPhyInit_WriteExtAddress((uint8_t*)(&(gHardwareParameters.MAC_Address[0]))); Asp_SetPowerLevel(gHardwareParameters.defaultPowerLevel); { uint32_t reg_value = *((volatile uint32_t*)0x80009460); reg_value &= (uint32_t)0xFF00FFFF; /* clear the cca threshold */ reg_value |= (uint32_t) gHardwareParameters.ccaThreshold << 16; /* set the cca threshold */ *((volatile uint32_t*)0x80009460) = reg_value; } }
/* Synchronous calls to the ASP handler. */ uint8_t APP_ASP_SapHandler(AppToAspMessage_t *pMsg) { uint8_t msgStatus = gZbSuccess_c; uint32_t auxAddrAlign; #if gSCIInterface_d uint8_t byte; #endif switch(pMsg->msgType) { case aspMsgTypeGetTimeReq_c: Asp_GetTimeReq(&auxAddrAlign); pMsg->msgData.req.aspGetTimeReq.time= auxAddrAlign; break; case aspMsgTypeWakeReq_c: Asp_WakeReq(); break; case aspMsgTypeGetMacStateReq_c: msgStatus = Asp_GetMacStateReq(); break; #if gAspPowerSaveCapability_d case aspMsgTypeDozeReq_c: msgStatus = Asp_DozeReq(&pMsg->msgData.req.aspDozeReq.dozeDuration,pMsg->msgData.req.aspDozeReq.clko_en); break; case aspMsgTypeAutoDozeReq_c: Asp_AutoDozeReq(pMsg->msgData.req.aspAutoDozeReq.autoEnable, pMsg->msgData.req.aspAutoDozeReq.enableWakeIndication, &pMsg->msgData.req.aspAutoDozeReq.autoDozeInterval, pMsg->msgData.req.aspAutoDozeReq.clko_en); break; case aspMsgTypeSetMinDozeTimeReq_c: Asp_SetMinDozeTimeReq(&pMsg->msgData.req.aspSetMinDozeTimeReq.minDozeTime); break; case aspMsgTypeAcomaReq_c: msgStatus = Asp_AcomaReq(pMsg->msgData.req.aspAcomaReq.clko_en); break; case aspMsgTypeHibernateReq_c: msgStatus = Asp_HibernateReq(); break; #endif #if gAspHwCapability_d case aspMsgTypeClkoReq_c: msgStatus = Asp_ClkoReq(pMsg->msgData.req.aspClkoReq.clkoEnable, pMsg->msgData.req.aspClkoReq.clkoRate); break; case aspMsgTypeTrimReq_c: Asp_TrimReq(pMsg->msgData.req.aspTrimReq.fineTune, pMsg->msgData.req.aspTrimReq.coarseTune); break; case aspMsgTypeDdrReq_c: Asp_DdrReq(pMsg->msgData.req.aspDdrReq.directionMask); break; case aspMsgTypePortReq_c: Asp_PortReq(pMsg->msgData.req.aspPortReq.portWrite, &pMsg->msgData.req.aspPortReq.portValue); break; #endif #if gAspEventCapability_d case aspMsgTypeEventReq_c: msgStatus = Asp_EventReq(&pMsg->msgData.req.aspEventReq.eventTime); break; #endif #if gBeaconedCapability_d case aspMsgTypeGetInactiveTimeReq_c: msgStatus = Asp_GetInactiveTimeReq(&pMsg->msgData.req.aspGetInactiveTimeReq.time); break; case aspMsgTypeSetNotifyReq_c: msgStatus = Asp_SetNotifyReq(pMsg->msgData.req.aspSetNotifyReq.notifications); break; #endif #if gAspPowerLevelCapability_d case aspMsgTypeSetPowerLevel_c: msgStatus = Asp_SetPowerLevel(pMsg->msgData.req.aspSetPowerLevelReq.powerLevel); break; case aspMsgTypeGetPowerLevel_c: msgStatus = Asp_GetPowerLevel(); break; #endif case aspMsgTypeTelecTest_c: ASP_TelecTest(pMsg->msgData.req.aspTelecTest.mode); #if gSCIInterface_d if(gTestPulseTxPrbs9_c == pMsg->msgData.req.aspTelecTest.mode) { while(FALSE == UartX_GetByteFromRxBuffer(&byte)) { ASP_TelecTest(pMsg->msgData.req.aspTelecTest.mode); } UartX_UngetByte(byte); } #endif break; case aspMsgTypeTelecSetFreq_c: ASP_TelecSetFreq(pMsg->msgData.req.aspTelecsetFreq.channel); break; case aspMsgTypeTelecSendRawData_c: if((pMsg->msgData.req.aspTelecSendRawData.length >= 3) && (pMsg->msgData.req.aspTelecSendRawData.length <= 125)) { ASP_TelecSendRawData(pMsg->msgData.req.aspTelecSendRawData.length, (uint8_t*)&pMsg->msgData.req.aspTelecSendRawData.dataPtr); } else { msgStatus = gZbInvalidRequest_c; } break; default: msgStatus = gZbInvalidRequest_c; break; } /* monitoring this task */ ZTC_TaskEventMonitor(gNwkASP_SAPHandlerId_c, (uint8_t *)pMsg, msgStatus); return msgStatus; }