Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 18.79 KB | None | 0 0
  1. #include "LED.h"
  2. #include "ledcontrol.h"
  3.  
  4. #include "MemManager.h"
  5. #include "Messaging.h"
  6. #include "TimersManager.h"
  7. #include "SecLib.h"
  8. #include "Panic.h"
  9. #include "fsl_xcvr.h"
  10. #include "fsl_os_abstraction.h"
  11. #include "SerialManager.h"
  12.  
  13. #include "board.h"
  14.  
  15. #include "FreeRTOSConfig.h"
  16.  
  17.  
  18. #define App_NotifySelf() OSA_EventSet(mAppThreadEvt, gCtEvtSelfEvent_c)
  19.  
  20. /*Application main*/
  21. static void App_Thread (uint32_t param);
  22. /*Application event handler*/
  23. static void App_HandleEvents(osaEventFlags_t flags);
  24. /*Function that reads latest byte from Serial Manager*/
  25. static void App_UpdateUartData(uint8_t* pData);
  26.  
  27.  
  28. /*Generic FSK RX callback*/
  29. static void App_GenFskReceiveCallback(uint8_t *pBuffer,
  30.                                       uint16_t bufferLength,
  31.                                       uint64_t timestamp,
  32.                                       uint8_t rssi,
  33.                                       uint8_t crcValid);
  34. /*Generic FSK Notification callback*/
  35. static void App_GenFskEventNotificationCallback(genfskEvent_t event,
  36.                                                 genfskEventStatus_t eventStatus);
  37. /*Serial Manager UART RX callback*/
  38. static void App_SerialCallback(void* param);
  39.  
  40. /*Timer manager callback function*/
  41. static void App_TimerCallback(void* param);
  42.  
  43.  
  44. //application specific genfsk init
  45. static void gFsk_Init();
  46.  
  47.  
  48. /************************************************************************************
  49. *************************************************************************************
  50. * Private memory declarations
  51. *************************************************************************************
  52. ************************************************************************************/
  53. static uint8_t platformInitialized = 0;
  54.  
  55. /*event used by the application thread*/
  56. static osaEventId_t mAppThreadEvt;
  57.  
  58. #ifdef LEDCONTROL_MASTER
  59. /*variable to store key pressed by user*/
  60. static uint8_t mAppUartData = 0;
  61. #endif
  62.  
  63.  
  64.  
  65. #ifdef LEDCONTROL_MASTER
  66. static connectivity_states_t conState = gAppSlave1Check;
  67. #endif
  68.  
  69. /*structure to store information regarding latest received packet*/
  70. static ct_rx_indication_t mAppRxLatestPacket;
  71.  
  72. /*latest generic fsk event status*/
  73. static genfskEventStatus_t mAppGenfskStatus;
  74.  
  75. // transmission buffer and packet
  76. static uint8_t* gTxBuffer;
  77. static GENFSK_packet_t gTxPacket;
  78.  
  79. //receive buffer/packet
  80. static uint8_t* gRxBuffer;
  81. static GENFSK_packet_t gRxPacket;
  82.  
  83. //length of genfsk buffer
  84. uint16_t buffLen;
  85.  
  86. /*extern MCU reset api*/
  87. extern void ResetMCU(void);
  88.  
  89.  
  90. /*! *********************************************************************************
  91. * \brief  This is the first task created by the OS. This task will initialize
  92. *         the system
  93. *
  94. * \param[in]  param
  95. *
  96. ********************************************************************************** */
  97. void main_task(uint32_t param)
  98. {  
  99.     if (!platformInitialized)
  100.     {
  101.         platformInitialized = 1;
  102.        
  103.         hardware_init();
  104.        
  105.         /* Framework init */
  106.         MEM_Init();
  107.  
  108.         //initialize Serial Manager
  109.         SerialManager_Init();
  110.         LED_Init();
  111.         SecLib_Init();
  112. #ifdef LEDCONTROL_MASTER
  113.         TMR_Init();
  114.         mAppTmrId = TMR_AllocateTimer();
  115.  
  116. #endif
  117.  
  118.         GENFSK_Init();
  119.        
  120.  
  121.  
  122.        
  123.         /*create app thread event*/
  124.         mAppThreadEvt = OSA_EventCreate(TRUE);
  125.        
  126.  
  127.         /*initialize the application interface id*/
  128.         Serial_InitInterface(&mAppSerId,
  129.                              APP_SERIAL_INTERFACE_TYPE,
  130.                              APP_SERIAL_INTERFACE_INSTANCE);
  131.         /*set baudrate to 115200*/
  132.         Serial_SetBaudRate(mAppSerId,
  133.                            APP_SERIAL_INTERFACE_SPEED);
  134.         /*set Serial Manager receive callback*/
  135.         Serial_SetRxCallBack(mAppSerId, App_SerialCallback, NULL);
  136.        
  137.  
  138.  
  139.  
  140.         /* GENFSK LL Init with default register config */
  141.         if(gGenfskSuccess_c != GENFSK_AllocInstance(&mAppGenfskId, NULL, NULL, NULL))
  142.         {
  143.             Serial_Print(mAppGenfskId,"Allocation failed...\r\n",gAllowToBlock_d);
  144.         }
  145.  
  146.     }
  147.    
  148.     /* Call application task */
  149.     App_Thread( param );
  150. }
  151.  
  152. /*! *********************************************************************************
  153. * \brief  This function represents the Application task.
  154. *         This task reuses the stack alocated for the MainThread.
  155. *         This function is called to process all events for the task. Events
  156. *         include timers, messages and any other user defined events.
  157. * \param[in]  argument
  158. *
  159. ********************************************************************************** */
  160. void App_Thread (uint32_t param)
  161. {
  162.     osaEventFlags_t mAppThreadEvtFlags = 0;
  163.    
  164.     gFsk_Init();
  165. #ifdef LEDCONTROL_MASTER
  166.     TMR_EnableTimer(mAppTmrId);
  167.     TMR_StartIntervalTimer(mAppTmrId,LEDCONTROL_CONNECTIONCHECK_TIMEOUT_MILLISECONDS, App_TimerCallback, NULL);
  168. #endif
  169.     GENFSK_StartRx(mAppGenfskId, gRxBuffer, gGenFskDefaultMaxBufferSize_c+crcConfig.crcSize, 0, 0);
  170.     while(1)
  171.     {
  172.         (void)OSA_EventWait(mAppThreadEvt, gCtEvtEventsAll_c, FALSE, osaWaitForever_c ,&mAppThreadEvtFlags);
  173.         if(mAppThreadEvtFlags)
  174.         {
  175.             App_HandleEvents(mAppThreadEvtFlags);/*handle app events*/
  176.         }
  177.     }
  178. }
  179.  
  180.  
  181.  
  182. /*! *********************************************************************************
  183. * \brief  The application event handler
  184. *         This function is called each time there is an OS event for the AppThread
  185. * \param[in]  flags The OS event flags specific to the Connectivity Test App.
  186. *
  187. ********************************************************************************** */
  188. void App_HandleEvents(osaEventFlags_t flags)
  189. {
  190.     if(flags & gCtEvtUart_c)
  191.     {
  192. #ifdef LEDCONTROL_MASTER //slave boards should never fire a uart event
  193.         App_UpdateUartData(&mAppUartData);
  194.  
  195.         if(
  196.                   (mAppUartData != '1')
  197.                 &&(mAppUartData != '2')
  198.                 &&(mAppUartData != '3')
  199.                 &&(mAppUartData != '4')
  200.                 &&(mAppUartData != '5')
  201.                 &&(mAppUartData != '6')
  202.                 &&(mAppUartData != '7')
  203.                 &&(mAppUartData != '8')
  204.                 &&(mAppUartData != '9')
  205.           )
  206.         {
  207.             GENFSK_AbortAll();
  208.             GENFSK_StartRx(mAppGenfskId, gRxBuffer, gGenFskDefaultMaxBufferSize_c+crcConfig.crcSize, 0, 0);
  209.         }
  210.         else
  211.         {
  212.             int command = (mAppUartData - '0')-1;//convert to int
  213.             gTxPacket.header.lengthField = gGenFskMinPayloadLen_c;
  214.             switch(command)
  215.             {
  216.             case 0:
  217.                 //Device ID 0, red LED
  218.                 gTxPacket.payload[0] = LEDCONTROL_DEVICE_ID_ZERO;
  219.                 gTxPacket.payload[1] = 'r';
  220.                 break;
  221.             case 1:
  222.                 //Device ID 0, green LED
  223.                 gTxPacket.payload[0] = LEDCONTROL_DEVICE_ID_ZERO;
  224.                 gTxPacket.payload[1] = 'g';
  225.                 break;
  226.             case 2:
  227.                 //Device ID 0, blue LED
  228.                 gTxPacket.payload[0] = LEDCONTROL_DEVICE_ID_ZERO;
  229.                 gTxPacket.payload[1] = 'b';
  230.                 break;
  231.             case 3:
  232.                 //Device ID 1, red LED
  233.                 gTxPacket.payload[0] = LEDCONTROL_DEVICE_ID_ONE;
  234.                 gTxPacket.payload[1] = 'r';
  235.                 break;
  236.             case 4:
  237.                 //Device ID 1, green LED
  238.                 gTxPacket.payload[0] = LEDCONTROL_DEVICE_ID_ONE;
  239.                 gTxPacket.payload[1] = 'g';
  240.                 break;
  241.             case 5:
  242.                 //Device ID 1, blue LED
  243.                 gTxPacket.payload[0] = LEDCONTROL_DEVICE_ID_ONE;
  244.                 gTxPacket.payload[1] = 'b';
  245.                 break;
  246.             case 6:
  247.                 //Device ID 2, red LED
  248.                 gTxPacket.payload[0] = LEDCONTROL_DEVICE_ID_TWO;
  249.                 gTxPacket.payload[1] = 'r';
  250.                 break;
  251.             case 7:
  252.                 //Device ID 2, green LED
  253.                 gTxPacket.payload[0] = LEDCONTROL_DEVICE_ID_TWO;
  254.                 gTxPacket.payload[1] = 'g';
  255.                 break;
  256.             case 8:
  257.                 //Device ID 2, blue LED
  258.                 gTxPacket.payload[0] = LEDCONTROL_DEVICE_ID_TWO;
  259.                 gTxPacket.payload[1] = 'b';
  260.                 break;
  261.             default:
  262.                 break;
  263.  
  264.                 buffLen = gTxPacket.header.lengthField+(gGenFskDefaultHeaderSizeBytes_c)+(gGenFskDefaultSyncAddrSize_c + 1);
  265.                 GENFSK_PacketToByteArray(mAppGenfskId, &gTxPacket, gTxBuffer);
  266.                 GENFSK_AbortAll();
  267.                 GENFSK_StartTx(mAppGenfskId, gTxBuffer, buffLen, 0);
  268.             }
  269.         }
  270. #endif
  271.     }
  272.     else if(flags & gCtEvtRxDone_c) //received comms
  273.     {
  274.         GENFSK_ByteArrayToPacket(mAppGenfskId, mAppRxLatestPacket.pBuffer, &gRxPacket);
  275.         uint8_t devID = gRxPacket.payload[0];
  276.         uint8_t data = gRxPacket.payload[1];
  277. #ifdef LEDCONTROL_MASTER
  278.  
  279.         if(data == 'v')
  280.         {
  281.             if((conState == gAppSlave1Check) && (devID = LEDCONTROL_DEVICE_ID_ZERO))
  282.             {
  283.                 slave1connected = true;
  284.             }
  285.             else if((conState == gAppSlave2Check) && (devID = LEDCONTROL_DEVICE_ID_ONE))
  286.             {
  287.                 slave2connected = true;
  288.             }
  289.             else if((conState == gAppSlave3Check) && (devID = LEDCONTROL_DEVICE_ID_TWO))
  290.             {
  291.                 slave3connected = true;
  292.             }
  293.             else
  294.             {
  295.                 //bad packet, ignore
  296.             }
  297.         }
  298.         else
  299.         {
  300.             //TODO: Print suitable data back to indicate successful slave reception of data
  301.             if(devID == 0)
  302.             {
  303.                 if(data == 'r')
  304.                 {
  305.                     Serial_Print(mAppSerId,"1",gAllowToBlock_d);
  306.                 }
  307.                 else if(data == 'g')
  308.                 {
  309.                     Serial_Print(mAppSerId,"2",gAllowToBlock_d);
  310.                 }
  311.                 else if(data == 'b')
  312.                 {
  313.                     Serial_Print(mAppSerId,"3",gAllowToBlock_d);
  314.                 }
  315.                 else
  316.                 {
  317.                     //bad data
  318.                 }
  319.             }
  320.             else if(devID == 1)
  321.             {
  322.                 if(data == 'r')
  323.                 {
  324.                     Serial_Print(mAppSerId,"4",gAllowToBlock_d);
  325.                 }
  326.                 else if(data == 'g')
  327.                 {
  328.                     Serial_Print(mAppSerId,"5",gAllowToBlock_d);
  329.                 }
  330.                 else if(data == 'b')
  331.                 {
  332.                     Serial_Print(mAppSerId,"6",gAllowToBlock_d);
  333.                 }
  334.                 else
  335.                 {
  336.                     //bad data
  337.                 }
  338.             }
  339.             else if(devID == 2)
  340.             {
  341.                 if(data == 'r')
  342.                 {
  343.                     Serial_Print(mAppSerId,"7",gAllowToBlock_d);
  344.                 }
  345.                 else if(data == 'g')
  346.                 {
  347.                     Serial_Print(mAppSerId,"8",gAllowToBlock_d);
  348.                 }
  349.                 else if(data == 'b')
  350.                 {
  351.                     Serial_Print(mAppSerId,"9",gAllowToBlock_d);
  352.                 }
  353.                 else
  354.                 {
  355.                     //bad data
  356.                 }
  357.             }
  358.             else
  359.             {
  360.                 //bad data
  361.             }
  362.             GENFSK_AbortAll();
  363.             GENFSK_StartRx(mAppGenfskId, gRxBuffer, gGenFskDefaultMaxBufferSize_c+crcConfig.crcSize, 0, 0);
  364.  
  365.         }
  366.  
  367.  
  368. #else
  369.         if(devID == LEDCONTROL_DEVICE_ID)
  370.         {
  371.             gTxPacket.payload[0] = LEDCONTROL_DEVICE_ID;
  372.  
  373.             if(data == 'r')
  374.             {
  375.                 Led2Toggle();
  376.                 gTxPacket.payload[1] = 'r';
  377.                 buffLen = gTxPacket.header.lengthField+(gGenFskDefaultHeaderSizeBytes_c)+(gGenFskDefaultSyncAddrSize_c + 1);
  378.                 GENFSK_PacketToByteArray(mAppGenfskId, &gTxPacket, gTxBuffer);
  379.                 GENFSK_AbortAll();
  380.                 GENFSK_StartTx(mAppGenfskId, gTxBuffer, buffLen, 0);
  381.             }
  382.             else if(data == 'g')
  383.             {
  384.                 Led3Toggle();
  385.                 gTxPacket.payload[1] = 'g';
  386.                 buffLen = gTxPacket.header.lengthField+(gGenFskDefaultHeaderSizeBytes_c)+(gGenFskDefaultSyncAddrSize_c + 1);
  387.                 GENFSK_PacketToByteArray(mAppGenfskId, &gTxPacket, gTxBuffer);
  388.                 GENFSK_AbortAll();
  389.                 GENFSK_StartTx(mAppGenfskId, gTxBuffer, buffLen, 0);
  390.             }
  391.             else if(data == 'b')
  392.             {
  393.                 Led4Toggle();
  394.                 gTxPacket.payload[1] = 'b';
  395.                 buffLen = gTxPacket.header.lengthField+(gGenFskDefaultHeaderSizeBytes_c)+(gGenFskDefaultSyncAddrSize_c + 1);
  396.                 GENFSK_PacketToByteArray(mAppGenfskId, &gTxPacket, gTxBuffer);
  397.                 GENFSK_AbortAll();
  398.                 GENFSK_StartTx(mAppGenfskId, gTxBuffer, buffLen, 0);
  399.             }
  400.             else if(data == 'v')
  401.             {
  402.                 //this packet is so the master can check slave is still connected, send response back
  403.                 Serial_Print(mAppSerId,"Right place\r\n",gAllowToBlock_d);
  404.                 gTxPacket.payload[1] = 'v';
  405.                 buffLen = gTxPacket.header.lengthField+(gGenFskDefaultHeaderSizeBytes_c)+(gGenFskDefaultSyncAddrSize_c + 1);
  406.                 GENFSK_PacketToByteArray(mAppGenfskId, &gTxPacket, gTxBuffer);
  407.                 GENFSK_AbortAll();
  408.                 GENFSK_StartTx(mAppGenfskId, gTxBuffer, buffLen, 0);
  409.             }
  410.             else
  411.             {
  412.                 //bad data
  413.                 Serial_Print(mAppSerId,"Bad data\r\n",gAllowToBlock_d);
  414.                 GENFSK_AbortAll();
  415.                 GENFSK_StartRx(mAppGenfskId, gRxBuffer, gGenFskDefaultMaxBufferSize_c+crcConfig.crcSize, 0, 0);
  416.             }
  417.  
  418.         }
  419.         else
  420.         {
  421.             //bad id
  422.             Serial_Print(mAppSerId,"Bad ID\r\n",gAllowToBlock_d);
  423.             GENFSK_AbortAll();
  424.             GENFSK_StartRx(mAppGenfskId, gRxBuffer, gGenFskDefaultMaxBufferSize_c+crcConfig.crcSize, 0, 0);
  425.         }
  426. #endif
  427.     }
  428.     else if(flags & gCtEvtTxDone_c)
  429.     {
  430.         Serial_Print(mAppSerId,"Finished transmission\r\n",gAllowToBlock_d);
  431.         GENFSK_AbortAll();
  432.         GENFSK_StartRx(mAppGenfskId, gRxBuffer, gGenFskDefaultMaxBufferSize_c+crcConfig.crcSize, 0, 0);
  433.     }
  434.     else if(flags & gCtEvtTimerExpired_c)
  435.     {
  436. #ifdef LEDCONTROL_MASTER
  437.         if(conState == gAppSlave1Check)
  438.         {
  439.             if(!slave1connected)
  440.             {
  441.                 Serial_Print(mAppSerId,"Slave 1 disconnected\r\n",gAllowToBlock_d);
  442.             }
  443.             else
  444.             {
  445.                 Serial_Print(mAppSerId,"Slave 1 connected\r\n",gAllowToBlock_d);
  446.             }
  447.             conState = gAppSlave2Check;
  448.             slave2connected = false;
  449.             gTxPacket.payload[0] = LEDCONTROL_DEVICE_ID_ONE;
  450.         }
  451.         else if(conState == gAppSlave2Check)
  452.         {
  453.             if(!slave2connected)
  454.             {
  455.                 Serial_Print(mAppSerId,"Slave 2 disconnected\r\n",gAllowToBlock_d);
  456.             }
  457.             else
  458.             {
  459.                 Serial_Print(mAppSerId,"Slave 2 connected\r\n",gAllowToBlock_d);
  460.             }
  461.             conState = gAppSlave3Check;
  462.             slave3connected = false;
  463.             gTxPacket.payload[0] = LEDCONTROL_DEVICE_ID_TWO;
  464.         }
  465.         else if(conState == gAppSlave3Check)
  466.         {
  467.             if(!slave3connected)
  468.             {
  469.                 Serial_Print(mAppSerId,"Slave 3 disconnected\r\n",gAllowToBlock_d);
  470.             }
  471.             else
  472.             {
  473.                 Serial_Print(mAppSerId,"Slave 3 connected\r\n",gAllowToBlock_d);
  474.             }
  475.             conState = gAppSlave1Check;
  476.             slave1connected = false;
  477.             gTxPacket.payload[0] = LEDCONTROL_DEVICE_ID_ZERO;
  478.         }
  479.         else
  480.         {
  481.             //unreachable
  482.         }
  483.         gTxPacket.payload[1] = 'v';
  484.         buffLen = gTxPacket.header.lengthField+(gGenFskDefaultHeaderSizeBytes_c)+(gGenFskDefaultSyncAddrSize_c + 1);
  485.         GENFSK_PacketToByteArray(mAppGenfskId, &gTxPacket, gTxBuffer);
  486.         GENFSK_AbortAll();
  487.         GENFSK_StartTx(mAppGenfskId, gTxBuffer, buffLen, 0);
  488. #endif
  489.  
  490.     }
  491.  
  492. }
  493.  
  494. /*! *********************************************************************************
  495. * \brief  This function is called each time SerialManager notifies the application
  496. *         task that a byte was received.
  497. *         The function checks if there are additional bytes in the SerialMgr  
  498. *         queue and simulates a new SM event if there is more data.
  499. * \param[in]  pData Pointer to where to store byte read.
  500. *
  501. ********************************************************************************** */
  502. static void App_UpdateUartData(uint8_t* pData)
  503. {
  504.     uint16_t u16SerBytesCount = 0;
  505.     if(gSerial_Success_c == Serial_GetByteFromRxBuffer(mAppSerId, pData, &u16SerBytesCount))
  506.     {
  507.         Serial_RxBufferByteCount(mAppSerId, &u16SerBytesCount);
  508.         if(u16SerBytesCount)
  509.         {
  510.             (void)OSA_EventSet(mAppThreadEvt, gCtEvtUart_c);
  511.         }
  512.     }
  513. }
  514.  
  515.  
  516.  
  517. /*! *********************************************************************************
  518. * \brief  This function represents the Generic FSK receive callback.
  519. *         This function is called each time the Generic FSK Link Layer receives a
  520. *         valid packet
  521. * \param[in]  pBuffer Pointer to receive buffer as byte array
  522. * \param[in]  timestamp Generic FSK timestamp for received packet
  523. * \param[in]  rssi The RSSI measured during the reception of the packet
  524. *
  525. ********************************************************************************** */
  526. static void App_GenFskReceiveCallback(uint8_t *pBuffer,
  527.                                       uint16_t bufferLength,
  528.                                       uint64_t timestamp,
  529.                                       uint8_t rssi,
  530.                                       uint8_t crcValid)
  531. {
  532.    mAppRxLatestPacket.pBuffer      = pBuffer;
  533.    mAppRxLatestPacket.bufferLength = bufferLength;
  534.    mAppRxLatestPacket.timestamp    = timestamp;
  535.    mAppRxLatestPacket.rssi         = rssi;
  536.    mAppRxLatestPacket.crcValid     = crcValid;
  537.    
  538.    /*send event to app thread*/
  539.    OSA_EventSet(mAppThreadEvt, gCtEvtRxDone_c);
  540. }
  541.  
  542. /*! *********************************************************************************
  543. * \brief  This function represents the Generic FSK event notification callback.
  544. *         This function is called each time the Generic FSK Link Layer has
  545. *         a notification for the upper layer
  546. * \param[in]  event The event that generated the notification
  547. * \param[in]  eventStatus status of the event
  548. *
  549. ********************************************************************************** */
  550. static void App_GenFskEventNotificationCallback(genfskEvent_t event,
  551.                                                 genfskEventStatus_t eventStatus)
  552. {
  553.    if(event & gGenfskTxEvent)
  554.    {
  555.        mAppGenfskStatus = eventStatus;
  556.        /*send event done*/
  557.        OSA_EventSet(mAppThreadEvt, gCtEvtTxDone_c);
  558.    }
  559.    if(event & gGenfskRxEvent)
  560.    {
  561.        if(eventStatus == gGenfskTimeout)
  562.        {
  563.            OSA_EventSet(mAppThreadEvt, gCtEvtSeqTimeout_c);
  564.        }
  565.        else
  566.        {
  567.            OSA_EventSet(mAppThreadEvt, gCtEvtRxFailed_c);
  568.        }
  569.    }
  570. }
  571.  
  572. static void App_SerialCallback(void* param)
  573. {
  574.     OSA_EventSet(mAppThreadEvt, gCtEvtUart_c);
  575. }
  576.  
  577.  
  578. static void gFsk_Init()
  579. {
  580.     GENFSK_RegisterCallbacks(mAppGenfskId, App_GenFskReceiveCallback, App_GenFskEventNotificationCallback);
  581.     gRxBuffer  = MEM_BufferAlloc(gGenFskDefaultMaxBufferSize_c +
  582.                                  crcConfig.crcSize);
  583.     gTxBuffer  = MEM_BufferAlloc(gGenFskDefaultMaxBufferSize_c);
  584.  
  585.     gRxPacket.payload = (uint8_t*)MEM_BufferAlloc(gGenFskMaxPayloadLen_c  +
  586.                                                        crcConfig.crcSize);
  587.     gTxPacket.payload = (uint8_t*)MEM_BufferAlloc(gGenFskMaxPayloadLen_c);
  588.  
  589.     /*prepare the part of the tx packet that is common for all tests*/
  590.     gTxPacket.addr = gGenFskDefaultSyncAddress_c;
  591.     gTxPacket.header.h0Field = gGenFskDefaultH0Value_c;
  592.     gTxPacket.header.h1Field = gGenFskDefaultH1Value_c;
  593.     gTxPacket.header.lengthField = gGenFskMinPayloadLen_c;
  594.     /*set bitrate*/
  595.     GENFSK_RadioConfig(mAppGenfskId, &radioConfig);
  596.     /*set packet config*/
  597.     GENFSK_SetPacketConfig(mAppGenfskId, &pktConfig);
  598.     /*set whitener config*/
  599.     GENFSK_SetWhitenerConfig(mAppGenfskId, &whitenConfig);
  600.     /*set crc config*/
  601.     GENFSK_SetCrcConfig(mAppGenfskId, &crcConfig);
  602.  
  603.     /*set network address at location 0 and enable it*/
  604.     GENFSK_SetNetworkAddress(mAppGenfskId, 0, &ntwkAddr);
  605.     GENFSK_EnableNetworkAddress(mAppGenfskId, 0);
  606.  
  607.     /*set tx power level*/
  608.     GENFSK_SetTxPowerLevel(mAppGenfskId, gGenFskDefaultTxPowerLevel_c);
  609.     /*set channel: Freq = 2360MHz + ChannNumber*1MHz*/
  610.     GENFSK_SetChannelNumber(mAppGenfskId, gGenFskDefaultChannel_c);
  611. }
  612.  
  613. static void App_TimerCallback(void* param)
  614. {
  615.     OSA_EventSet(mAppThreadEvt, gCtEvtTimerExpired_c);
  616. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement