Example #1
0
void Platform_Init(void)
{
  Asp_TrimReq( gHardwareParameters.gXtalFTune_c, gHardwareParameters.gXtalCTune_c );

  PlatformInitGpio();
  AppInterruptsInit();  // Initializes interrupts and Itc peripheral
}
/*
  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;
}