znp_soc.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**************************************************************************************************
  2. Filename: znp_soc.c
  3. Revised: $Date: 2010-11-22 08:13:43 -0800 (Mon, 22 Nov 2010) $
  4. Revision: $Revision: 24480 $
  5. Description:
  6. This file is the HAL-specific Application implementation for the ZNP by 8051 SOC.
  7. Copyright 2010 Texas Instruments Incorporated. All rights reserved.
  8. IMPORTANT: Your use of this Software is limited to those specific rights
  9. granted under the terms of a software license agreement between the user
  10. who downloaded the software, his/her employer (which must be your employer)
  11. and Texas Instruments Incorporated (the "License"). You may not use this
  12. Software unless you agree to abide by the terms of the License. The License
  13. limits your use, and you acknowledge, that the Software may not be modified,
  14. copied or distributed unless embedded on a Texas Instruments microcontroller
  15. or used solely and exclusively in conjunction with a Texas Instruments radio
  16. frequency transceiver, which is integrated into your product. Other than for
  17. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  18. works of, modify, distribute, perform, display or sell this Software and/or
  19. its documentation for any purpose.
  20. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  21. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  22. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  23. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  24. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  25. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  26. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  27. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  28. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  29. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  30. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  31. Should you have any questions regarding your right to use this Software,
  32. contact Texas Instruments Incorporated at www.TI.com.
  33. **************************************************************************************************/
  34. /* ------------------------------------------------------------------------------------------------
  35. * Includes
  36. * ------------------------------------------------------------------------------------------------
  37. */
  38. #include "comdef.h"
  39. #include "hal_board_cfg.h"
  40. #include "mac_radio_defs.h"
  41. #include "MT.h"
  42. #include "OSAL.h"
  43. #include "OSAL_Nv.h"
  44. #include "znp_app.h"
  45. /* ------------------------------------------------------------------------------------------------
  46. * Macros
  47. * ------------------------------------------------------------------------------------------------
  48. */
  49. #define MAC_RADIO_TX_ON() st( RFST = ISTXON; )
  50. #define MOD_IF 4 // ~Modulation bit of MDMTEST1 register.
  51. #define TX_PWR_MOD__SET(MOD_) st ( \
  52. if ((MOD_)) \
  53. { \
  54. MDMTEST1 |= BV(MOD_IF); \
  55. } \
  56. else \
  57. { \
  58. MDMTEST1 &= ~BV(MOD_IF); \
  59. } \
  60. );
  61. #define TX_PWR_TONE_SET(TONE) st ( \
  62. MDMTEST0 &= ~0xF0; \
  63. MDMTEST0 |= (TONE << 4); \
  64. )
  65. /**************************************************************************************************
  66. * @fn znpTestRF
  67. *
  68. * @brief This function initializes and checks the ZNP RF Test Mode NV items. It is designed
  69. * to be invoked before/instead of MAC radio initialization.
  70. *
  71. * input parameters
  72. *
  73. * None.
  74. *
  75. * output parameters
  76. *
  77. * None.
  78. *
  79. * @return None.
  80. */
  81. void znpTestRF(void)
  82. {
  83. uint8 rfTestParms[4] = { 0, 0, 0, 0 };
  84. if ((SUCCESS != osal_nv_item_init(ZNP_NV_RF_TEST_PARMS, 4, rfTestParms)) ||
  85. (SUCCESS != osal_nv_read(ZNP_NV_RF_TEST_PARMS, 0, 4, rfTestParms)) ||
  86. (rfTestParms[0] == 0))
  87. {
  88. return;
  89. }
  90. // Settings from SmartRF Studio
  91. MDMCTRL0 = 0x85;
  92. RXCTRL = 0x3F;
  93. FSCTRL = 0x5A;
  94. FSCAL1 = 0x2B;
  95. AGCCTRL1 = 0x11;
  96. ADCTEST0 = 0x10;
  97. ADCTEST1 = 0x0E;
  98. ADCTEST2 = 0x03;
  99. FRMCTRL0 = 0x43;
  100. FRMCTRL1 = 0x00;
  101. MAC_RADIO_RXTX_OFF();
  102. MAC_RADIO_SET_CHANNEL(rfTestParms[1]);
  103. MAC_RADIO_SET_TX_POWER(rfTestParms[2]);
  104. TX_PWR_TONE_SET(rfTestParms[3]);
  105. switch (rfTestParms[0])
  106. {
  107. case 1: // Rx promiscuous mode.
  108. MAC_RADIO_RX_ON();
  109. break;
  110. case 2: // Un-modulated Tx.
  111. TX_PWR_MOD__SET(1);
  112. // no break;
  113. case 3: // Modulated Tx.
  114. // Modulated is default register setting, so no special action.
  115. // Now turn on Tx power for either mod or un-modulated Tx test.
  116. MAC_RADIO_TX_ON();
  117. break;
  118. default: // Not expected.
  119. break;
  120. }
  121. // Clear the RF test mode.
  122. (void)osal_memset(rfTestParms, 0, 4);
  123. (void)osal_nv_write(ZNP_NV_RF_TEST_PARMS, 0, 4, rfTestParms);
  124. while (1); // Spin in RF test mode until a hard reset.
  125. }
  126. /**************************************************************************************************
  127. */