mac_mcu.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /**************************************************************************************************
  2. Filename: mac_mcu.h
  3. Revised: $Date: 2012-03-07 11:55:12 -0800 (Wed, 07 Mar 2012) $
  4. Revision: $Revision: 29664 $
  5. Description: Describe the purpose and contents of the file.
  6. Copyright 2006-2011 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. #ifndef MAC_MCU_H
  34. #define MAC_MCU_H
  35. /* ------------------------------------------------------------------------------------------------
  36. * Compiler Includes
  37. * ------------------------------------------------------------------------------------------------
  38. */
  39. #include "hal_mcu.h"
  40. #include "hal_types.h"
  41. #include "hal_defs.h"
  42. #include "hal_board.h"
  43. #include "mac_high_level.h"
  44. /* ------------------------------------------------------------------------------------------------
  45. * Target Specific Defines
  46. * ------------------------------------------------------------------------------------------------
  47. */
  48. /* IP0, IP1 */
  49. #define IPX_0 BV(0)
  50. #define IPX_1 BV(1)
  51. #define IPX_2 BV(2)
  52. #define IP_RFERR_RF_DMA_BV IPX_0
  53. #define IP_RXTX0_T2_BV IPX_2
  54. /* T2CTRL */
  55. #define LATCH_MODE BV(3)
  56. #define TIMER2_STATE BV(2)
  57. #define TIMER2_SYNC BV(1)
  58. #define TIMER2_RUN BV(0)
  59. /* T2IRQF */
  60. #define TIMER2_OVF_COMPARE2F BV(5)
  61. #define TIMER2_OVF_COMPARE1F BV(4)
  62. #define TIMER2_OVF_PERF BV(3)
  63. #define TIMER2_COMPARE2F BV(2)
  64. #define TIMER2_COMPARE1F BV(1)
  65. #define TIMER2_PERF BV(0)
  66. /* T2IRQM */
  67. #define TIMER2_OVF_COMPARE2M BV(5)
  68. #define TIMER2_OVF_COMPARE1M BV(4)
  69. #define TIMER2_OVF_PERM BV(3)
  70. #define TIMER2_COMPARE2M BV(2)
  71. #define TIMER2_COMPARE1M BV(1)
  72. #define TIMER2_PERM BV(0)
  73. /* T2PEROF2 */
  74. #define CMPIM BV(7)
  75. #define PERIM BV(6)
  76. #define OFCMPIM BV(5)
  77. #define PEROF2_BITS (BV(3) | BV(2) | BV(1) | BV(0))
  78. /* RFIRQF0 */
  79. #define IRQ_SFD BV(1)
  80. #define IRQ_FIFOP BV(2)
  81. /* RFIRQF1 */
  82. #define IRQ_TXACKDONE BV(0)
  83. #define IRQ_TXDONE BV(1)
  84. #define IRQ_CSP_MANINT BV(3)
  85. #define IRQ_CSP_STOP BV(4)
  86. /* RFIRQM0 */
  87. #define IM_SFD BV(1)
  88. #define IM_FIFOP BV(2)
  89. /* RFIRQM1 */
  90. #define IM_TXACKDONE BV(0)
  91. #define IM_TXDONE BV(1)
  92. #define IM_CSP_MANINT BV(3)
  93. #define IM_CSP_STOP BV(4)
  94. /* IRQSRC */
  95. #define TXACK BV(0)
  96. /* RFERRM and RFERRF */
  97. #define RFERR_RXOVERF BV(2)
  98. /* ------------------------------------------------------------------------------------------------
  99. * Interrupt Macros
  100. * ------------------------------------------------------------------------------------------------
  101. */
  102. #define MAC_MCU_WRITE_RFIRQF0(x) HAL_CRITICAL_STATEMENT( S1CON = 0x00; RFIRQF0 = x; )
  103. #define MAC_MCU_WRITE_RFIRQF1(x) HAL_CRITICAL_STATEMENT( S1CON = 0x00; RFIRQF1 = x; )
  104. #define MAC_MCU_OR_RFIRQM0(x) st( RFIRQM0 |= x; ) /* compiler must use atomic ORL instruction */
  105. #define MAC_MCU_AND_RFIRQM0(x) st( RFIRQM0 &= x; ) /* compiler must use atomic ANL instruction */
  106. #define MAC_MCU_OR_RFIRQM1(x) st( RFIRQM1 |= x; ) /* compiler must use atomic ORL instruction */
  107. #define MAC_MCU_AND_RFIRQM1(x) st( RFIRQM1 &= x; ) /* compiler must use atomic ANL instruction */
  108. #define MAC_MCU_FIFOP_ENABLE_INTERRUPT() MAC_MCU_OR_RFIRQM0(IM_FIFOP)
  109. #define MAC_MCU_FIFOP_DISABLE_INTERRUPT() MAC_MCU_AND_RFIRQM0(~IM_FIFOP)
  110. #define MAC_MCU_FIFOP_CLEAR_INTERRUPT() MAC_MCU_WRITE_RFIRQF0(~IRQ_FIFOP)
  111. #define MAC_MCU_TXACKDONE_ENABLE_INTERRUPT() MAC_MCU_OR_RFIRQM1(IM_TXACKDONE)
  112. #define MAC_MCU_TXACKDONE_DISABLE_INTERRUPT() MAC_MCU_AND_RFIRQM1(~IM_TXACKDONE)
  113. #define MAC_MCU_TXACKDONE_CLEAR_INTERRUPT() MAC_MCU_WRITE_RFIRQF1(~IRQ_TXACKDONE)
  114. #define MAC_MCU_CSP_STOP_ENABLE_INTERRUPT() MAC_MCU_OR_RFIRQM1(IM_CSP_STOP)
  115. #define MAC_MCU_CSP_STOP_DISABLE_INTERRUPT() MAC_MCU_AND_RFIRQM1(~IM_CSP_STOP)
  116. #define MAC_MCU_CSP_STOP_CLEAR_INTERRUPT() MAC_MCU_WRITE_RFIRQF1(~IRQ_CSP_STOP)
  117. #define MAC_MCU_CSP_STOP_INTERRUPT_IS_ENABLED() (RFIRQM1 & IM_CSP_STOP)
  118. #define MAC_MCU_CSP_INT_ENABLE_INTERRUPT() MAC_MCU_OR_RFIRQM1(IM_CSP_MANINT)
  119. #define MAC_MCU_CSP_INT_DISABLE_INTERRUPT() MAC_MCU_AND_RFIRQM1(~IM_CSP_MANINT)
  120. #define MAC_MCU_CSP_INT_CLEAR_INTERRUPT() MAC_MCU_WRITE_RFIRQF1(~IRQ_CSP_MANINT)
  121. #define MAC_MCU_CSP_INT_INTERRUPT_IS_ENABLED() (RFIRQM1 & IM_CSP_MANINT)
  122. #define MAC_MCU_RFERR_ENABLE_INTERRUPT() st( RFERRM |= RFERR_RXOVERF; )
  123. #define MAC_MCU_RFERR_DISABLE_INTERRUPT() st( RFERRM &= ~RFERR_RXOVERF; )
  124. /* ------------------------------------------------------------------------------------------------
  125. * MAC Timer Macros
  126. * ------------------------------------------------------------------------------------------------
  127. */
  128. #define T2M_OVF_BITS (BV(6) | BV(5) | BV(4))
  129. #define T2M_BITS (BV(2) | BV(1) | BV(0))
  130. #define T2M_OVFSEL(x) ((x) << 4)
  131. #define T2M_SEL(x) (x)
  132. #define T2M_T2OVF T2M_OVFSEL(0)
  133. #define T2M_T2OVF_CAP T2M_OVFSEL(1)
  134. #define T2M_T2OVF_PER T2M_OVFSEL(2)
  135. #define T2M_T2OVF_CMP1 T2M_OVFSEL(3)
  136. #define T2M_T2OVF_CMP2 T2M_OVFSEL(4)
  137. #define T2M_T2TIM T2M_SEL(0)
  138. #define T2M_T2_CAP T2M_SEL(1)
  139. #define T2M_T2_PER T2M_SEL(2)
  140. #define T2M_T2_CMP1 T2M_SEL(3)
  141. #define T2M_T2_CMP2 T2M_SEL(4)
  142. #define MAC_MCU_T2_ACCESS_OVF_COUNT_VALUE() st( T2MSEL = T2M_T2OVF; )
  143. #define MAC_MCU_T2_ACCESS_OVF_CAPTURE_VALUE() st( T2MSEL = T2M_T2OVF_CAP; )
  144. #define MAC_MCU_T2_ACCESS_OVF_PERIOD_VALUE() st( T2MSEL = T2M_T2OVF_PER; )
  145. #define MAC_MCU_T2_ACCESS_OVF_CMP1_VALUE() st( T2MSEL = T2M_T2OVF_CMP1; )
  146. #define MAC_MCU_T2_ACCESS_OVF_CMP2_VALUE() st( T2MSEL = T2M_T2OVF_CMP2; )
  147. #define MAC_MCU_T2_ACCESS_COUNT_VALUE() st( T2MSEL = T2M_T2TIM; )
  148. #define MAC_MCU_T2_ACCESS_CAPTURE_VALUE() st( T2MSEL = T2M_T2_CAP; )
  149. #define MAC_MCU_T2_ACCESS_PERIOD_VALUE() st( T2MSEL = T2M_T2_PER; )
  150. #define MAC_MCU_T2_ACCESS_CMP1_VALUE() st( T2MSEL = T2M_T2_CMP1; )
  151. #define MAC_MCU_T2_ACCESS_CMP2_VALUE() st( T2MSEL = T2M_T2_CMP2; )
  152. #define MAC_MCU_CONFIG_CSP_EVENT1() st( T2CSPCFG = 1; )
  153. /* ------------------------------------------------------------------------------------------------
  154. * Global Variable Externs
  155. * ------------------------------------------------------------------------------------------------
  156. */
  157. extern uint8 macChipVersion;
  158. /* ------------------------------------------------------------------------------------------------
  159. * Prototypes
  160. * ------------------------------------------------------------------------------------------------
  161. */
  162. MAC_INTERNAL_API void macMcuInit(void);
  163. MAC_INTERNAL_API uint8 macMcuRandomByte(void);
  164. MAC_INTERNAL_API uint16 macMcuRandomWord(void);
  165. MAC_INTERNAL_API void macMcuTimerForceDelay(uint16 count);
  166. MAC_INTERNAL_API uint16 macMcuTimerCapture(void);
  167. MAC_INTERNAL_API uint32 macMcuOverflowCount(void);
  168. MAC_INTERNAL_API uint32 macMcuOverflowCapture(void);
  169. MAC_INTERNAL_API void macMcuOverflowSetCount(uint32 count);
  170. MAC_INTERNAL_API void macMcuOverflowSetCompare(uint32 count);
  171. MAC_INTERNAL_API void macMcuOverflowSetPeriod(uint32 count);
  172. MAC_INTERNAL_API void macMcuRecordMaxRssiStart(void);
  173. MAC_INTERNAL_API int8 macMcuRecordMaxRssiStop(void);
  174. MAC_INTERNAL_API void macMcuRecordMaxRssiIsr(void);
  175. MAC_INTERNAL_API void macMcuAccumulatedOverFlow(void);
  176. uint32 macMcuPrecisionCount(void);
  177. void macMcuTimer2OverflowWorkaround(void);
  178. /**************************************************************************************************
  179. */
  180. #endif