hal_board_cfg.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /**************************************************************************************************
  2. Filename: hal_board_cfg.h
  3. Revised: $Date: 2012-03-29 12:17:34 -0700 (Thu, 29 Mar 2012) $
  4. Revision: $Revision: 29944 $
  5. Description: Declarations for the CC2530EM used as a ZNP replacement for the CC2520 on
  6. MSP platforms (and possibly others.)
  7. Copyright 2009-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. #ifndef HAL_BOARD_CFG_H
  35. #define HAL_BOARD_CFG_H
  36. /* ------------------------------------------------------------------------------------------------
  37. * Includes
  38. * ------------------------------------------------------------------------------------------------
  39. */
  40. #include "hal_mcu.h"
  41. #include "hal_defs.h"
  42. #include "hal_types.h"
  43. /* ------------------------------------------------------------------------------------------------
  44. * CC2590/CC2591 support
  45. *
  46. * Define HAL_PA_LNA_CC2590 if CC2530+CC2590EM is used
  47. * Define HAL_PA_LNA if CC2530+CC2591EM is used
  48. * Note that only one of them can be defined
  49. * ------------------------------------------------------------------------------------------------
  50. */
  51. #define xHAL_PA_LNA
  52. #define xHAL_PA_LNA_CC2590
  53. /* ------------------------------------------------------------------------------------------------
  54. * Board Indentifier
  55. *
  56. * Define the Board Identifier to HAL_BOARD_CC2530EB_REV13 for SmartRF05 EB 1.3 board
  57. * ------------------------------------------------------------------------------------------------
  58. */
  59. #if !defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_BOARD_CC2530EB_REV13)
  60. #define HAL_BOARD_CC2530EB_REV17
  61. #endif
  62. /* ------------------------------------------------------------------------------------------------
  63. * Clock Speed
  64. * ------------------------------------------------------------------------------------------------
  65. */
  66. #define HAL_CPU_CLOCK_MHZ 32
  67. /* This flag should be defined if the SoC uses the 32MHz crystal
  68. * as the main clock source (instead of DCO).
  69. */
  70. #define HAL_CLOCK_CRYSTAL
  71. // Values based on powerup h/w config as input with pull-up - not using dynamic cfg of transport.
  72. #define ZNP_CFG0_32K_XTAL 1 /* 32kHz crystal installed and used */
  73. #define ZNP_CFG0_32K_OSC 0 /* 32kHz crystal not installed; internal osc. used */
  74. #define ZNP_CFG1_SPI 1 /* use SPI transport */
  75. #define ZNP_CFG1_UART 0 /* use UART transport */
  76. extern unsigned char znpCfg1;
  77. extern unsigned char znpCfg0;
  78. /* ------------------------------------------------------------------------------------------------
  79. * LED Configuration
  80. * ------------------------------------------------------------------------------------------------
  81. */
  82. #if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) && !defined (HAL_PA_LNA_CC2590)
  83. #define HAL_NUM_LEDS 3
  84. #elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) || defined (HAL_PA_LNA_CC2590)
  85. #define HAL_NUM_LEDS 1
  86. #else
  87. #error Unknown Board Indentifier
  88. #endif
  89. #define HAL_LED_BLINK_DELAY() st( { volatile uint32 i; for (i=0; i<0x5800; i++) { }; } )
  90. /* 1 - Green */
  91. #define LED1_BV BV(0)
  92. #define LED1_SBIT P1_0
  93. #define LED1_DDR P1DIR
  94. #define LED1_POLARITY ACTIVE_HIGH
  95. #if defined (HAL_BOARD_CC2530EB_REV17)
  96. /* 2 - Red */
  97. #define LED2_BV BV(1)
  98. #define LED2_SBIT P1_1
  99. #define LED2_DDR P1DIR
  100. #define LED2_POLARITY ACTIVE_HIGH
  101. /* 3 - Yellow */
  102. #define LED3_BV BV(4)
  103. #define LED3_SBIT P1_4
  104. #define LED3_DDR P1DIR
  105. #define LED3_POLARITY ACTIVE_HIGH
  106. #endif
  107. /* ------------------------------------------------------------------------------------------------
  108. * GPIO Configuration
  109. * ------------------------------------------------------------------------------------------------
  110. */
  111. #ifndef HAL_GPIO
  112. #define HAL_GPIO TRUE
  113. #endif
  114. #if defined CC2530_MK
  115. #define GPIO_0_PORT 0
  116. #define GPIO_0_PIN 6
  117. #define GPIO_1_PORT 0
  118. #define GPIO_1_PIN 7
  119. #define GPIO_2_PORT 1
  120. #define GPIO_2_PIN 6
  121. #define GPIO_3_PORT 1
  122. #define GPIO_3_PIN 7
  123. #else
  124. #define GPIO_0_PORT 0
  125. #define GPIO_0_PIN 0
  126. #define GPIO_1_PORT 0
  127. #define GPIO_1_PIN 1
  128. #define GPIO_2_PORT 0
  129. #define GPIO_2_PIN 6
  130. #define GPIO_3_PORT 1
  131. #define GPIO_3_PIN 0
  132. #endif
  133. #define GPIO_DIR_IN(IDX) MCU_IO_DIR_INPUT(GPIO_##IDX##_PORT, GPIO_##IDX##_PIN)
  134. #define GPIO_DIR_OUT(IDX) MCU_IO_DIR_OUTPUT(GPIO_##IDX##_PORT, GPIO_##IDX##_PIN)
  135. #define GPIO_TRI(IDX) MCU_IO_INPUT(GPIO_##IDX##_PORT, GPIO_##IDX##_PIN, MCU_IO_TRISTATE)
  136. #define GPIO_PULL_UP(IDX) MCU_IO_INPUT(GPIO_##IDX##_PORT, GPIO_##IDX##_PIN, MCU_IO_PULLUP)
  137. #define GPIO_PULL_DN(IDX) MCU_IO_INPUT(GPIO_##IDX##_PORT, GPIO_##IDX##_PIN, MCU_IO_PULLDOWN)
  138. #define GPIO_SET(IDX) MCU_IO_SET_HIGH(GPIO_##IDX##_PORT, GPIO_##IDX##_PIN)
  139. #define GPIO_CLR(IDX) MCU_IO_SET_LOW(GPIO_##IDX##_PORT, GPIO_##IDX##_PIN)
  140. #define GPIO_TOG(IDX) MCU_IO_TGL(GPIO_##IDX##_PORT, GPIO_##IDX##_PIN)
  141. #define GPIO_GET(IDX) MCU_IO_GET(GPIO_##IDX##_PORT, GPIO_##IDX##_PIN)
  142. #define GPIO_HiD_SET() (PICTL |= BV(7)) /* PADSC */
  143. #define GPIO_HiD_CLR() (PICTL &= ~BV(7)) /* PADSC */
  144. // Used as "func" for the macros below
  145. #define MCU_IO_TRISTATE 1
  146. #define MCU_IO_PULLUP 2
  147. #define MCU_IO_PULLDOWN 3
  148. //-----------------------------------------------------------------------------
  149. // Macros for simple configuration of IO pins on TI LPW SoCs
  150. //-----------------------------------------------------------------------------
  151. #define MCU_IO_PERIPHERAL(port, pin) MCU_IO_PERIPHERAL_PREP(port, pin)
  152. #define MCU_IO_INPUT(port, pin, func) MCU_IO_INPUT_PREP(port, pin, func)
  153. #define MCU_IO_OUTPUT(port, pin, val) MCU_IO_OUTPUT_PREP(port, pin, val)
  154. #define MCU_IO_SET(port, pin, val) MCU_IO_SET_PREP(port, pin, val)
  155. #define MCU_IO_SET_HIGH(port, pin) MCU_IO_SET_HIGH_PREP(port, pin)
  156. #define MCU_IO_SET_LOW(port, pin) MCU_IO_SET_LOW_PREP(port, pin)
  157. #define MCU_IO_TGL(port, pin) MCU_IO_TGL_PREP(port, pin)
  158. #define MCU_IO_GET(port, pin) MCU_IO_GET_PREP(port, pin)
  159. #define MCU_IO_DIR_INPUT(port, pin) MCU_IO_DIR_INPUT_PREP(port, pin)
  160. #define MCU_IO_DIR_OUTPUT(port, pin) MCU_IO_DIR_OUTPUT_PREP(port, pin)
  161. //----------------------------------------------------------------------------------
  162. // Macros for internal use (the macros above need a new round in the preprocessor)
  163. //----------------------------------------------------------------------------------
  164. #define MCU_IO_PERIPHERAL_PREP(port, pin) st( P##port##SEL |= BV(pin); )
  165. #define MCU_IO_INPUT_PREP(port, pin, func) st( P##port##SEL &= ~BV(pin); \
  166. P##port##DIR &= ~BV(pin); \
  167. switch (func) { \
  168. case MCU_IO_PULLUP: \
  169. P##port##INP &= ~BV(pin); \
  170. P2INP &= ~BV(port + 5); \
  171. break; \
  172. case MCU_IO_PULLDOWN: \
  173. P##port##INP &= ~BV(pin); \
  174. P2INP |= BV(port + 5); \
  175. break; \
  176. default: \
  177. P##port##INP |= BV(pin); \
  178. break; } )
  179. #define MCU_IO_OUTPUT_PREP(port, pin, val) st( P##port##SEL &= ~BV(pin); \
  180. P##port##_##pin## = val; \
  181. P##port##DIR |= BV(pin); )
  182. #define MCU_IO_SET_HIGH_PREP(port, pin) st( P##port##_##pin## = 1; )
  183. #define MCU_IO_SET_LOW_PREP(port, pin) st( P##port##_##pin## = 0; )
  184. #define MCU_IO_SET_PREP(port, pin, val) st( P##port##_##pin## = val; )
  185. #define MCU_IO_TGL_PREP(port, pin) st( P##port##_##pin## ^= 1; )
  186. #define MCU_IO_GET_PREP(port, pin) (P##port## & BV(pin))
  187. #define MCU_IO_DIR_INPUT_PREP(port, pin) st( P##port##DIR &= ~BV(pin); )
  188. #define MCU_IO_DIR_OUTPUT_PREP(port, pin) st( P##port##DIR |= BV(pin); )
  189. /* ------------------------------------------------------------------------------------------------
  190. * Push Button Configuration
  191. * ------------------------------------------------------------------------------------------------
  192. */
  193. #define ACTIVE_LOW !
  194. #define ACTIVE_HIGH !! /* double negation forces result to be '1' */
  195. /* S1 */
  196. #define PUSH1_BV BV(1)
  197. #define PUSH1_SBIT P0_1
  198. #if defined (HAL_BOARD_CC2530EB_REV17)
  199. #define PUSH1_POLARITY ACTIVE_HIGH
  200. #elif defined (HAL_BOARD_CC2530EB_REV13)
  201. #define PUSH1_POLARITY ACTIVE_LOW
  202. #else
  203. #error Unknown Board Indentifier
  204. #endif
  205. /* Joystick Center Press */
  206. #define PUSH2_BV BV(0)
  207. #define PUSH2_SBIT P2_0
  208. #define PUSH2_POLARITY ACTIVE_HIGH
  209. /* ------------------------------------------------------------------------------------------------
  210. * OSAL NV implemented by internal flash pages.
  211. * ------------------------------------------------------------------------------------------------
  212. */
  213. // Flash is partitioned into 8 banks of 32 KB or 16 pages.
  214. #define HAL_FLASH_PAGE_PER_BANK 16
  215. // Flash is constructed of 128 pages of 2 KB.
  216. #define HAL_FLASH_PAGE_SIZE 2048
  217. #define HAL_FLASH_WORD_SIZE 4
  218. // CODE banks get mapped into the XDATA range 8000-FFFF.
  219. #define HAL_FLASH_PAGE_MAP 0x8000
  220. // The last 16 bytes of the last available page are reserved for flash lock bits.
  221. // NV page definitions must coincide with segment declaration in project *.xcl file.
  222. #if defined NON_BANKED
  223. #define HAL_FLASH_LOCK_BITS 16
  224. #define HAL_NV_PAGE_END 30
  225. #define HAL_NV_PAGE_CNT 2
  226. #else
  227. #define HAL_FLASH_LOCK_BITS 16
  228. #define HAL_NV_PAGE_END 126
  229. #define HAL_NV_PAGE_CNT 6
  230. #endif
  231. // Re-defining Z_EXTADDR_LEN here so as not to include a Z-Stack .h file.
  232. #define HAL_FLASH_IEEE_SIZE 8
  233. #define HAL_FLASH_IEEE_PAGE (HAL_NV_PAGE_END+1)
  234. #define HAL_FLASH_IEEE_OSET (HAL_FLASH_PAGE_SIZE - HAL_FLASH_LOCK_BITS - HAL_FLASH_IEEE_SIZE)
  235. #define HAL_INFOP_IEEE_OSET 0xC
  236. #define HAL_FLASH_DEV_PRIVATE_KEY_OSET 0x7D2
  237. #define HAL_FLASH_CA_PUBLIC_KEY_OSET 0x7BC
  238. #define HAL_FLASH_IMPLICIT_CERT_OSET 0x78C
  239. #define HAL_NV_PAGE_BEG (HAL_NV_PAGE_END-HAL_NV_PAGE_CNT+1)
  240. // Used by DMA macros to shift 1 to create a mask for DMA registers.
  241. #define HAL_NV_DMA_CH 0
  242. #define HAL_DMA_CH_RX 3
  243. #define HAL_DMA_CH_TX 4
  244. #define HAL_NV_DMA_GET_DESC() HAL_DMA_GET_DESC0()
  245. #define HAL_NV_DMA_SET_ADDR(a) HAL_DMA_SET_ADDR_DESC0((a))
  246. /* ------------------------------------------------------------------------------------------------
  247. * Serial Boot Loader: reserving the first 4 pages of flash and other memory in cc2530-sb.xcl.
  248. * ------------------------------------------------------------------------------------------------
  249. */
  250. #define HAL_SB_IMG_ADDR 0x2000
  251. #define HAL_SB_CRC_ADDR 0x2090
  252. // Size of internal flash less 4 pages for boot loader, 6 pages for NV, & 1 page for lock bits.
  253. #define HAL_SB_IMG_SIZE (0x40000 - 0x2000 - 0x3000 - 0x0800)
  254. /* ------------------------------------------------------------------------------------------------
  255. * Macros
  256. * ------------------------------------------------------------------------------------------------
  257. */
  258. /* ----------- RF-frontend Connection Initialization ---------- */
  259. #if defined HAL_PA_LNA || defined HAL_PA_LNA_CC2590
  260. extern void MAC_RfFrontendSetup(void);
  261. #define HAL_BOARD_RF_FRONTEND_SETUP() MAC_RfFrontendSetup()
  262. #else
  263. #define HAL_BOARD_RF_FRONTEND_SETUP()
  264. #endif
  265. /* ----------- Cache Prefetch control ---------- */
  266. #define PREFETCH_ENABLE() st( FCTL = 0x08; )
  267. #define PREFETCH_DISABLE() st( FCTL = 0x04; )
  268. /* Default powerup with P1_2 as input with pullup. P1_2 is read into znpCfg0 is in "init_board()".
  269. * 1->0x00 external 32 kHz xosc & 0->0x80 for internal.
  270. */
  271. #define HAL_CLOCK_STABLE() st( uint8 OSC_32KHZ = ((znpCfg0 == ZNP_CFG0_32K_XTAL) ? 0x00 : 0x80); \
  272. while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); )
  273. #if defined CC2530_MK
  274. #define OSC_32KHZ_VALUE 0x80
  275. #else
  276. /* Default powerup with P1_2 as input with pullup, so 1->0x00 external 32 kHz xosc & 0->0x80 for internal */\
  277. #define OSC_32KHZ_VALUE ((P1_2 == ZNP_CFG0_32K_XTAL) ? 0x00 : 0x80)
  278. #endif
  279. /* ----------- Board Initialization ---------- */
  280. #if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) && !defined (HAL_PA_LNA_CC2590)
  281. #define HAL_BOARD_INIT() st \
  282. ( \
  283. uint8 OSC_32KHZ = OSC_32KHZ_VALUE; \
  284. uint16 i; \
  285. \
  286. SLEEPCMD &= ~OSC_PD; /* turn on 16MHz RC and 32MHz XOSC */ \
  287. while (!(SLEEPSTA & XOSC_STB)); /* wait for 32MHz XOSC stable */ \
  288. asm("NOP"); /* chip bug workaround */ \
  289. for (i=0; i<504; i++) asm("NOP"); /* Require 63us delay for all revs */ \
  290. CLKCONCMD = (CLKCONCMD_32MHZ | OSC_32KHZ); /* Select 32MHz XOSC and the source for 32K clock */ \
  291. while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); /* Wait for the change to be effective */ \
  292. SLEEPCMD |= OSC_PD; /* turn off 16MHz RC */ \
  293. \
  294. /* Turn on cache prefetch mode */ \
  295. PREFETCH_ENABLE(); \
  296. )
  297. #elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) || defined (HAL_PA_LNA_CC2590)
  298. #define HAL_BOARD_INIT() st \
  299. ( \
  300. uint8 OSC_32KHZ = OSC_32KHZ_VALUE; \
  301. uint16 i; \
  302. \
  303. SLEEPCMD &= ~OSC_PD; /* turn on 16MHz RC and 32MHz XOSC */ \
  304. while (!(SLEEPSTA & XOSC_STB)); /* wait for 32MHz XOSC stable */ \
  305. asm("NOP"); /* chip bug workaround */ \
  306. for (i=0; i<504; i++) asm("NOP"); /* Require 63us delay for all revs */ \
  307. CLKCONCMD = (CLKCONCMD_32MHZ | OSC_32KHZ); /* Select 32MHz XOSC and the source for 32K clock */ \
  308. while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); /* Wait for the change to be effective */ \
  309. SLEEPCMD |= OSC_PD; /* turn off 16MHz RC */ \
  310. \
  311. /* Turn on cache prefetch mode */ \
  312. PREFETCH_ENABLE(); \
  313. \
  314. /* set direction for GPIO outputs */ \
  315. LED1_DDR |= LED1_BV; \
  316. \
  317. /* Set PA/LNA HGM control P0_7 */ \
  318. P0DIR |= BV(7); \
  319. \
  320. /* configure tristates */ \
  321. P0INP |= PUSH2_BV; \
  322. \
  323. /* setup RF frontend if necessary */ \
  324. HAL_BOARD_RF_FRONTEND_SETUP(); \
  325. )
  326. #endif
  327. /* ----------- Debounce ---------- */
  328. #define HAL_DEBOUNCE(expr) { int i; for (i=0; i<500; i++) { if (!(expr)) i = 0; } }
  329. /* ----------- Push Buttons ---------- */
  330. #define HAL_PUSH_BUTTON1() (PUSH1_POLARITY (PUSH1_SBIT))
  331. #define HAL_PUSH_BUTTON2() (PUSH2_POLARITY (PUSH2_SBIT))
  332. #define HAL_PUSH_BUTTON3() (0)
  333. #define HAL_PUSH_BUTTON4() (0)
  334. #define HAL_PUSH_BUTTON5() (0)
  335. #define HAL_PUSH_BUTTON6() (0)
  336. /* ----------- LED's ---------- */
  337. #if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) && !defined (HAL_PA_LNA_CC2590)
  338. #define HAL_TURN_OFF_LED1() st( LED1_SBIT = LED1_POLARITY (0); )
  339. #define HAL_TURN_OFF_LED2() st( LED2_SBIT = LED2_POLARITY (0); )
  340. #define HAL_TURN_OFF_LED3() st( LED3_SBIT = LED3_POLARITY (0); )
  341. #define HAL_TURN_OFF_LED4() HAL_TURN_OFF_LED1()
  342. #define HAL_TURN_ON_LED1() st( LED1_SBIT = LED1_POLARITY (1); )
  343. #define HAL_TURN_ON_LED2() st( LED2_SBIT = LED2_POLARITY (1); )
  344. #define HAL_TURN_ON_LED3() st( LED3_SBIT = LED3_POLARITY (1); )
  345. #define HAL_TURN_ON_LED4() HAL_TURN_ON_LED1()
  346. #define HAL_TOGGLE_LED1() st( if (LED1_SBIT) { LED1_SBIT = 0; } else { LED1_SBIT = 1;} )
  347. #define HAL_TOGGLE_LED2() st( if (LED2_SBIT) { LED2_SBIT = 0; } else { LED2_SBIT = 1;} )
  348. #define HAL_TOGGLE_LED3() st( if (LED3_SBIT) { LED3_SBIT = 0; } else { LED3_SBIT = 1;} )
  349. #define HAL_TOGGLE_LED4() HAL_TOGGLE_LED1()
  350. #define HAL_STATE_LED1() (LED1_POLARITY (LED1_SBIT))
  351. #define HAL_STATE_LED2() (LED2_POLARITY (LED2_SBIT))
  352. #define HAL_STATE_LED3() (LED3_POLARITY (LED3_SBIT))
  353. #define HAL_STATE_LED4() HAL_STATE_LED1()
  354. #elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) || defined (HAL_PA_LNA_CC2590)
  355. #define HAL_TURN_OFF_LED1() st( LED1_SBIT = LED1_POLARITY (0); )
  356. #define HAL_TURN_OFF_LED2() HAL_TURN_OFF_LED1()
  357. #define HAL_TURN_OFF_LED3() HAL_TURN_OFF_LED1()
  358. #define HAL_TURN_OFF_LED4() HAL_TURN_OFF_LED1()
  359. #define HAL_TURN_ON_LED1() st( LED1_SBIT = LED1_POLARITY (1); )
  360. #define HAL_TURN_ON_LED2() HAL_TURN_ON_LED1()
  361. #define HAL_TURN_ON_LED3() HAL_TURN_ON_LED1()
  362. #define HAL_TURN_ON_LED4() HAL_TURN_ON_LED1()
  363. #define HAL_TOGGLE_LED1() st( if (LED1_SBIT) { LED1_SBIT = 0; } else { LED1_SBIT = 1;} )
  364. #define HAL_TOGGLE_LED2() HAL_TOGGLE_LED1()
  365. #define HAL_TOGGLE_LED3() HAL_TOGGLE_LED1()
  366. #define HAL_TOGGLE_LED4() HAL_TOGGLE_LED1()
  367. #define HAL_STATE_LED1() (LED1_POLARITY (LED1_SBIT))
  368. #define HAL_STATE_LED2() HAL_STATE_LED1()
  369. #define HAL_STATE_LED3() HAL_STATE_LED1()
  370. #define HAL_STATE_LED4() HAL_STATE_LED1()
  371. #endif
  372. /* ----------- XNV ---------- */
  373. #define XNV_SPI_BEGIN() st(P1_3 = 0;)
  374. #define XNV_SPI_TX(x) st(U1CSR &= ~0x02; U1DBUF = (x);)
  375. #define XNV_SPI_RX() U1DBUF
  376. #define XNV_SPI_WAIT_RXRDY() st(while (!(U1CSR & 0x02));)
  377. #define XNV_SPI_END() st(P1_3 = 1;)
  378. // The TI reference design uses UART1 Alt. 2 in SPI mode.
  379. #define XNV_SPI_INIT() \
  380. st( \
  381. /* Mode select UART1 SPI Mode as master. */\
  382. U1CSR = 0; \
  383. \
  384. /* Setup for 115200 baud. */\
  385. U1GCR = 11; \
  386. U1BAUD = 216; \
  387. \
  388. /* Set bit order to MSB */\
  389. U1GCR |= BV(5); \
  390. \
  391. /* Set UART1 I/O to alternate 2 location on P1 pins. */\
  392. PERCFG |= 0x02; /* U1CFG */\
  393. \
  394. /* Select peripheral function on I/O pins but SS is left as GPIO for separate control. */\
  395. P1SEL |= 0xE0; /* SELP1_[7:4] */\
  396. /* P1.1,2,3: reset, LCD CS, XNV CS. */\
  397. P1SEL &= ~0x0E; \
  398. P1 |= 0x0E; \
  399. P1_1 = 0; \
  400. P1DIR |= 0x0E; \
  401. \
  402. /* Give UART1 priority over Timer3. */\
  403. P2SEL &= ~0x20; /* PRI2P1 */\
  404. \
  405. /* When SPI config is complete, enable it. */\
  406. U1CSR |= 0x40; \
  407. /* Release XNV reset. */\
  408. P1_1 = 1; \
  409. )
  410. /* ----------- Minimum safe bus voltage ---------- */
  411. // Vdd/3 / Internal Reference X ENOB --> (Vdd / 3) / 1.15 X 127
  412. #define VDD_2_0 74 // 2.0 V required to safely read/write internal flash.
  413. #define VDD_2_7 100 // 2.7 V required for the Numonyx device.
  414. #define VDD_MIN_RUN VDD_2_0
  415. #define VDD_MIN_NV (VDD_2_0+4) // 5% margin over minimum to survive a page erase and compaction.
  416. #define VDD_MIN_XNV (VDD_2_7+5) // 5% margin over minimum to survive a page erase and compaction.
  417. /* ------------------------------------------------------------------------------------------------
  418. * Driver Configuration
  419. * ------------------------------------------------------------------------------------------------
  420. */
  421. /* Set to TRUE enable H/W TIMER usage, FALSE disable it */
  422. #ifndef HAL_TIMER
  423. #define HAL_TIMER FALSE
  424. #endif
  425. /* Set to TRUE enable ADC usage, FALSE disable it */
  426. #ifndef HAL_ADC
  427. #define HAL_ADC TRUE
  428. #endif
  429. /* Set to TRUE enable DMA usage, FALSE disable it */
  430. #ifndef HAL_DMA
  431. #define HAL_DMA TRUE
  432. #endif
  433. /* Set to TRUE enable Flash access, FALSE disable it */
  434. #ifndef HAL_FLASH
  435. #define HAL_FLASH TRUE
  436. #endif
  437. /* Set to TRUE enable AES usage, FALSE disable it */
  438. #ifndef HAL_AES
  439. #define HAL_AES TRUE
  440. #endif
  441. #ifndef HAL_AES_DMA
  442. #define HAL_AES_DMA TRUE
  443. #endif
  444. /* Set to TRUE enable LCD usage, FALSE disable it */
  445. #ifndef HAL_LCD
  446. #define HAL_LCD FALSE
  447. #endif
  448. /* Set to TRUE enable LED usage, FALSE disable it */
  449. #ifndef HAL_LED
  450. #define HAL_LED FALSE
  451. #endif
  452. #if (!defined BLINK_LEDS) && (HAL_LED == TRUE)
  453. #define BLINK_LEDS
  454. #endif
  455. /* Set to TRUE enable KEY usage, FALSE disable it */
  456. #ifndef HAL_KEY
  457. #define HAL_KEY FALSE
  458. #endif
  459. #define HAL_SPI TRUE
  460. #define HAL_UART TRUE
  461. #if defined HAL_SB_BOOT_CODE
  462. #define HAL_UART_DMA 0
  463. #define HAL_UART_ISR 1
  464. #else
  465. #define HAL_UART_DMA 1
  466. #define HAL_UART_ISR 0
  467. #endif
  468. #define HAL_UART_USB 0
  469. // Used to set P2 priority - USART0 over USART1 if both are defined.
  470. #if ((HAL_UART_DMA == 1) || (HAL_UART_ISR == 1))
  471. #define HAL_UART_PRIPO 0x00
  472. #else
  473. #define HAL_UART_PRIPO 0x40
  474. #endif
  475. #endif
  476. /*******************************************************************************************************
  477. */