hal_mcu.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /**************************************************************************************************
  2. Filename: hal_mcu.h
  3. Revised: $Date: 2012-03-29 12:09:02 -0700 (Thu, 29 Mar 2012) $
  4. Revision: $Revision: 29943 $
  5. Description: Describe the purpose and contents of the file.
  6. Copyright 2006-2010 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 _HAL_MCU_H
  34. #define _HAL_MCU_H
  35. /*
  36. * Target : Texas Instruments CC2530 (8051 core)
  37. *
  38. */
  39. /* ------------------------------------------------------------------------------------------------
  40. * Includes
  41. * ------------------------------------------------------------------------------------------------
  42. */
  43. #include "hal_defs.h"
  44. #include "hal_types.h"
  45. /* ------------------------------------------------------------------------------------------------
  46. * Target Defines
  47. * ------------------------------------------------------------------------------------------------
  48. */
  49. #define HAL_MCU_CC2530
  50. /* ------------------------------------------------------------------------------------------------
  51. * Compiler Abstraction
  52. * ------------------------------------------------------------------------------------------------
  53. */
  54. /* ---------------------- IAR Compiler ---------------------- */
  55. #ifdef __IAR_SYSTEMS_ICC__
  56. #include <ioCC2530.h>
  57. #define HAL_COMPILER_IAR
  58. #define HAL_MCU_LITTLE_ENDIAN() __LITTLE_ENDIAN__
  59. #define _PRAGMA(x) _Pragma(#x)
  60. #define HAL_ISR_FUNC_DECLARATION(f,v) _PRAGMA(vector=v) __near_func __interrupt void f(void)
  61. #define HAL_ISR_FUNC_PROTOTYPE(f,v) _PRAGMA(vector=v) __near_func __interrupt void f(void)
  62. #define HAL_ISR_FUNCTION(f,v) HAL_ISR_FUNC_PROTOTYPE(f,v); HAL_ISR_FUNC_DECLARATION(f,v)
  63. /* ---------------------- Keil Compiler ---------------------- */
  64. #elif defined __KEIL__
  65. #include <CC2530.h>
  66. #define HAL_COMPILER_KEIL
  67. #define HAL_MCU_LITTLE_ENDIAN() 0
  68. #define HAL_ISR_FUNC_DECLARATION(f,v) void f(void) interrupt v
  69. #define HAL_ISR_FUNC_PROTOTYPE(f,v) void f(void)
  70. #define HAL_ISR_FUNCTION(f,v) HAL_ISR_FUNC_PROTOTYPE(f,v); HAL_ISR_FUNC_DECLARATION(f,v)
  71. /* ------------------ Unrecognized Compiler ------------------ */
  72. #else
  73. #error "ERROR: Unknown compiler."
  74. #endif
  75. /* ------------------------------------------------------------------------------------------------
  76. * Interrupt Macros
  77. * ------------------------------------------------------------------------------------------------
  78. */
  79. #define HAL_ENABLE_INTERRUPTS() st( EA = 1; )
  80. #define HAL_DISABLE_INTERRUPTS() st( EA = 0; )
  81. #define HAL_INTERRUPTS_ARE_ENABLED() (EA)
  82. typedef unsigned char halIntState_t;
  83. #define HAL_ENTER_CRITICAL_SECTION(x) st( x = EA; HAL_DISABLE_INTERRUPTS(); )
  84. #define HAL_EXIT_CRITICAL_SECTION(x) st( EA = x; )
  85. #define HAL_CRITICAL_STATEMENT(x) st( halIntState_t _s; HAL_ENTER_CRITICAL_SECTION(_s); x; HAL_EXIT_CRITICAL_SECTION(_s); )
  86. #ifdef __IAR_SYSTEMS_ICC__
  87. /* IAR library uses XCH instruction with EA. It may cause the higher priority interrupt to be
  88. * locked out, therefore, may increase interrupt latency. It may also create a lockup condition.
  89. * This workaround should only be used with 8051 using IAR compiler. When IAR fixes this by
  90. * removing XCH usage in its library, compile the following macros to null to disable them.
  91. */
  92. #define HAL_ENTER_ISR() { halIntState_t _isrIntState = EA; HAL_ENABLE_INTERRUPTS();
  93. #define HAL_EXIT_ISR() EA = _isrIntState; }
  94. #else
  95. #define HAL_ENTER_ISR()
  96. #define HAL_EXIT_ISR()
  97. #endif /* __IAR_SYSTEMS_ICC__ */
  98. /* ------------------------------------------------------------------------------------------------
  99. * Reset Macro
  100. * ------------------------------------------------------------------------------------------------
  101. */
  102. #define WD_EN BV(3)
  103. #define WD_MODE BV(2)
  104. #define WD_INT_1900_USEC (BV(0) | BV(1))
  105. #define WD_RESET1 (0xA0 | WD_EN | WD_INT_1900_USEC)
  106. #define WD_RESET2 (0x50 | WD_EN | WD_INT_1900_USEC)
  107. #define WD_KICK() st( WDCTL = (0xA0 | WDCTL & 0x0F); WDCTL = (0x50 | WDCTL & 0x0F); )
  108. /* disable interrupts, set watchdog timer, wait for reset */
  109. #define HAL_SYSTEM_RESET() st( HAL_DISABLE_INTERRUPTS(); WDCTL = WD_RESET1; WDCTL = WD_RESET2; for(;;); )
  110. /* ------------------------------------------------------------------------------------------------
  111. * CC2530 rev numbers
  112. * ------------------------------------------------------------------------------------------------
  113. */
  114. #define REV_A 0x00 /* workaround turned off */
  115. #define REV_B 0x11 /* PG1.1 */
  116. #define REV_C 0x20 /* PG2.0 */
  117. #define REV_D 0x21 /* PG2.1 */
  118. /* ------------------------------------------------------------------------------------------------
  119. * CC2530 sleep common code
  120. * ------------------------------------------------------------------------------------------------
  121. */
  122. /* PCON bit definitions */
  123. #define PCON_IDLE BV(0) /* Writing 1 to force CC2530 to enter sleep mode */
  124. /* SLEEPCMD bit definitions */
  125. #define OSC_PD BV(2) /* Idle Osc: powered down=1 */
  126. #define PMODE (BV(1) | BV(0)) /* Power mode bits */
  127. /* SLEEPSTA bit definitions */
  128. #define XOSC_STB BV(6) /* XOSC: powered, stable=1 */
  129. #define HFRC_STB BV(5) /* HFRCOSC: powered, stable=1 */
  130. /* SLEEPCMD and SLEEPSTA bit definitions */
  131. #define OSC_PD BV(2) /* 0: Both oscillators powered up and stable
  132. * 1: oscillators not stable */
  133. /* CLKCONCMD bit definitions */
  134. #define OSC BV(6)
  135. #define TICKSPD(x) (x << 3)
  136. #define CLKSPD(x) (x << 0)
  137. #define CLKCONCMD_32MHZ (0)
  138. #define CLKCONCMD_16MHZ (CLKSPD(1) | TICKSPD(1) | OSC)
  139. /* STLOAD */
  140. #define LDRDY BV(0) /* Load Ready. This bit is 0 while the sleep timer
  141. * loads the 24-bit compare value and 1 when the sleep
  142. * timer is ready to start loading a newcompare value. */
  143. #ifdef POWER_SAVING
  144. extern volatile __data uint8 halSleepPconValue;
  145. /* Any ISR that is used to wake up the chip shall call this macro. This prevents the race condition
  146. * when the PCON IDLE bit is set after such a critical ISR fires during the prep for sleep.
  147. */
  148. #define CLEAR_SLEEP_MODE() st( halSleepPconValue = 0; )
  149. #define ALLOW_SLEEP_MODE() st( halSleepPconValue = PCON_IDLE; )
  150. #else
  151. #define CLEAR_SLEEP_MODE()
  152. #define ALLOW_SLEEP_MODE()
  153. #endif
  154. /**************************************************************************************************
  155. */
  156. #endif