hal_board_cfg.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /**************************************************************************************************
  2. Filename: hal_board_cfg.h
  3. Revised: $Date: 2009-03-27 14:32:42 -0700 (Fri, 27 Mar 2009) $
  4. Revision: $Revision: 19584 $
  5. Description: Describe the purpose and contents of the file.
  6. Copyright 2006-2009 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_BOARD_CFG_H
  34. #define HAL_BOARD_CFG_H
  35. /*
  36. * =============================================================
  37. * | Chipcon SmartRF05EB Evaluation Board, plus |
  38. * | Texas Instruments CC2530EM Evaluation Module |
  39. * | --------------------------------------------------------- |
  40. * | mcu : 8051 core |
  41. * | clock : 32MHz |
  42. * =============================================================
  43. */
  44. /* ------------------------------------------------------------------------------------------------
  45. * Includes
  46. * ------------------------------------------------------------------------------------------------
  47. */
  48. #include "hal_mcu.h"
  49. #include "hal_defs.h"
  50. #include "hal_types.h"
  51. /* ------------------------------------------------------------------------------------------------
  52. * CC2590/CC2591 support
  53. *
  54. * Define HAL_PA_LNA_CC2590 if CC2530+CC2590EM is used
  55. * Define HAL_PA_LNA if CC2530+CC2591EM is used
  56. * ------------------------------------------------------------------------------------------------
  57. */
  58. #define xHAL_PA_LNA
  59. /* ------------------------------------------------------------------------------------------------
  60. * Board Indentifier
  61. *
  62. * Define the Board Identifier to HAL_BOARD_CC2530EB_REV13 for SmartRF05 EB 1.3 board
  63. * ------------------------------------------------------------------------------------------------
  64. */
  65. #if !defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_BOARD_CC2530EB_REV13)
  66. #define HAL_BOARD_CC2530EB_REV17
  67. #endif
  68. /* ------------------------------------------------------------------------------------------------
  69. * Clock Speed
  70. * ------------------------------------------------------------------------------------------------
  71. */
  72. #define HAL_CPU_CLOCK_MHZ 32
  73. /* 32 kHz clock source select in CLKCONCMD */
  74. #if !defined (OSC32K_CRYSTAL_INSTALLED) || (defined (OSC32K_CRYSTAL_INSTALLED) && (OSC32K_CRYSTAL_INSTALLED == TRUE))
  75. #define OSC_32KHZ 0x80 /* 0x00 external 32 KHz xosc */
  76. #else
  77. #define OSC_32KHZ 0x80 /* 0x80 internal 32 KHz rcosc */
  78. #endif
  79. /* ------------------------------------------------------------------------------------------------
  80. * LED Configuration
  81. * ------------------------------------------------------------------------------------------------
  82. */
  83. #if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) && !defined (HAL_PA_LNA_CC2590)
  84. #define HAL_NUM_LEDS 3
  85. #elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) || defined (HAL_PA_LNA_CC2590)
  86. #define HAL_NUM_LEDS 1
  87. #else
  88. #error Unknown Board Indentifier
  89. #endif
  90. #define HAL_LED_BLINK_DELAY() st( { volatile uint32 i; for (i=0; i<0x5800; i++) { }; } )
  91. /* 1 - Green */
  92. #define LED1_BV BV(0)
  93. #define LED1_SBIT P1_0
  94. #define LED1_DDR P1DIR
  95. #define LED1_POLARITY ACTIVE_LOW //ACTIVE_HIGH
  96. #ifdef HAL_BOARD_CC2530EB_REV17
  97. /* 2 - Red */
  98. #define LED2_BV BV(1)
  99. #define LED2_SBIT P1_1
  100. #define LED2_DDR P1DIR
  101. #define LED2_POLARITY ACTIVE_LOW //ACTIVE_HIGH
  102. /* 3 - Yellow */
  103. #define LED3_BV BV(4)
  104. #define LED3_SBIT P0_4
  105. #define LED3_DDR P0DIR
  106. #define LED3_POLARITY ACTIVE_LOW //ACTIVE_HIGH
  107. #endif
  108. /* ------------------------------------------------------------------------------------------------
  109. * Push Button Configuration
  110. * ------------------------------------------------------------------------------------------------
  111. */
  112. #define ACTIVE_LOW !
  113. #define ACTIVE_HIGH !! /* double negation forces result to be '1' */
  114. /* S1 */
  115. #define PUSH1_BV BV(1)
  116. #define PUSH1_SBIT P0_1
  117. #ifdef HAL_BOARD_CC2530EB_REV17
  118. #define PUSH1_POLARITY ACTIVE_HIGH
  119. #elif defined (HAL_BOARD_CC2530EB_REV13)
  120. #define PUSH1_POLARITY ACTIVE_LOW
  121. #else
  122. #error Unknown Board Indentifier
  123. #endif
  124. /* Joystick Center Press */
  125. #define PUSH2_BV BV(0)
  126. #define PUSH2_SBIT P2_0
  127. #define PUSH2_POLARITY ACTIVE_HIGH
  128. /* ------------------------------------------------------------------------------------------------
  129. * OSAL NV implemented by internal flash pages.
  130. * ------------------------------------------------------------------------------------------------
  131. */
  132. // Flash is partitioned into 8 banks of 32 KB or 16 pages.
  133. #define HAL_FLASH_PAGE_PER_BANK 16
  134. // Flash is constructed of 128 pages of 2 KB.
  135. #define HAL_FLASH_PAGE_SIZE 2048
  136. #define HAL_FLASH_WORD_SIZE 4
  137. // CODE banks get mapped into the XDATA range 8000-FFFF.
  138. #define HAL_FLASH_PAGE_MAP 0x8000
  139. // The last 16 bytes of the last available page are reserved for flash lock bits.
  140. #if defined NON_BANKED
  141. #define HAL_FLASH_LOCK_BITS 16
  142. #define HAL_NV_PAGE_END 30
  143. #else
  144. #define HAL_FLASH_LOCK_BITS 16
  145. #define HAL_NV_PAGE_END 126
  146. #endif
  147. // Re-defining Z_EXTADDR_LEN here so as not to include a Z-Stack .h file.
  148. #define HAL_FLASH_IEEE_SIZE 8
  149. #define HAL_FLASH_IEEE_PAGE (HAL_NV_PAGE_END+1)
  150. #define HAL_FLASH_IEEE_OSET (HAL_FLASH_PAGE_SIZE - HAL_FLASH_LOCK_BITS - HAL_FLASH_IEEE_SIZE)
  151. #define HAL_INFOP_IEEE_OSET 0xC
  152. #define HAL_NV_PAGE_CNT 6
  153. #define HAL_NV_PAGE_BEG (HAL_NV_PAGE_END-HAL_NV_PAGE_CNT+1)
  154. // Used by DMA macros to shift 1 to create a mask for DMA registers.
  155. #define HAL_NV_DMA_CH 0
  156. #define HAL_DMA_CH_RX 3
  157. #define HAL_DMA_CH_TX 4
  158. #define HAL_NV_DMA_GET_DESC() HAL_DMA_GET_DESC0()
  159. #define HAL_NV_DMA_SET_ADDR(a) HAL_DMA_SET_ADDR_DESC0((a))
  160. /* ------------------------------------------------------------------------------------------------
  161. * Macros
  162. * ------------------------------------------------------------------------------------------------
  163. */
  164. /* ----------- Board Initialization ---------- */
  165. #if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) && !defined (HAL_PA_LNA_CC2590)
  166. #define HAL_BOARD_INIT() \
  167. { \
  168. uint16 i; \
  169. \
  170. SLEEPCMD &= ~OSC_PD; /* turn on 16MHz RC and 32MHz XOSC */ \
  171. while (!(SLEEPSTA & XOSC_STB)); /* wait for 32MHz XOSC stable */ \
  172. asm("NOP"); /* chip bug workaround */ \
  173. for (i=0; i<504; i++) asm("NOP"); /* Require 63us delay for all revs */ \
  174. CLKCONCMD = (CLKCONCMD_32MHZ | OSC_32KHZ); /* Select 32MHz XOSC and the source for 32K clock */ \
  175. while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); /* Wait for the change to be effective */ \
  176. SLEEPCMD |= OSC_PD; /* turn off 16MHz RC */ \
  177. \
  178. /* set direction for GPIO outputs */ \
  179. LED1_DDR |= LED1_BV; \
  180. LED2_DDR |= LED2_BV; \
  181. LED3_DDR |= LED3_BV; \
  182. \
  183. /* configure tristates */ \
  184. P0INP |= PUSH2_BV; \
  185. }
  186. #elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) || defined (HAL_PA_LNA_CC2590)
  187. #define HAL_BOARD_INIT() \
  188. { \
  189. uint16 i; \
  190. \
  191. SLEEPCMD &= ~OSC_PD; /* turn on 16MHz RC and 32MHz XOSC */ \
  192. while (!(SLEEPSTA & XOSC_STB)); /* wait for 32MHz XOSC stable */ \
  193. asm("NOP"); /* chip bug workaround */ \
  194. for (i=0; i<504; i++) asm("NOP"); /* Require 63us delay for all revs */ \
  195. CLKCONCMD = (CLKCONCMD_32MHZ | OSC_32KHZ); /* Select 32MHz XOSC and the source for 32K clock */ \
  196. while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); /* Wait for the change to be effective */ \
  197. SLEEPCMD |= OSC_PD; /* turn off 16MHz RC */ \
  198. \
  199. /* set direction for GPIO outputs */ \
  200. LED1_DDR |= LED1_BV; \
  201. \
  202. /* Set PA/LNA HGM control P0_7 */ \
  203. P0DIR |= BV(7); \
  204. \
  205. /* configure tristates */ \
  206. P0INP |= PUSH2_BV; \
  207. }
  208. #endif
  209. /* ----------- Debounce ---------- */
  210. #define HAL_DEBOUNCE(expr) { int i; for (i=0; i<500; i++) { if (!(expr)) i = 0; } }
  211. /* ----------- Push Buttons ---------- */
  212. #define HAL_PUSH_BUTTON1() (PUSH1_POLARITY (PUSH1_SBIT))
  213. #define HAL_PUSH_BUTTON2() (PUSH2_POLARITY (PUSH2_SBIT))
  214. #define HAL_PUSH_BUTTON3() (0)
  215. #define HAL_PUSH_BUTTON4() (0)
  216. #define HAL_PUSH_BUTTON5() (0)
  217. #define HAL_PUSH_BUTTON6() (0)
  218. /* ----------- LED's ---------- */
  219. #if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) && !defined (HAL_PA_LNA_CC2590)
  220. #define HAL_TURN_OFF_LED1() st( LED1_SBIT = LED1_POLARITY (0); )
  221. #define HAL_TURN_OFF_LED2() st( LED2_SBIT = LED2_POLARITY (0); )
  222. #define HAL_TURN_OFF_LED3() st( LED3_SBIT = LED3_POLARITY (0); )
  223. #define HAL_TURN_OFF_LED4() HAL_TURN_OFF_LED1()
  224. #define HAL_TURN_ON_LED1() st( LED1_SBIT = LED1_POLARITY (1); )
  225. #define HAL_TURN_ON_LED2() st( LED2_SBIT = LED2_POLARITY (1); )
  226. #define HAL_TURN_ON_LED3() st( LED3_SBIT = LED3_POLARITY (1); )
  227. #define HAL_TURN_ON_LED4() HAL_TURN_ON_LED1()
  228. #define HAL_TOGGLE_LED1() st( if (LED1_SBIT) { LED1_SBIT = 0; } else { LED1_SBIT = 1;} )
  229. #define HAL_TOGGLE_LED2() st( if (LED2_SBIT) { LED2_SBIT = 0; } else { LED2_SBIT = 1;} )
  230. #define HAL_TOGGLE_LED3() st( if (LED3_SBIT) { LED3_SBIT = 0; } else { LED3_SBIT = 1;} )
  231. #define HAL_TOGGLE_LED4() HAL_TOGGLE_LED1()
  232. #define HAL_STATE_LED1() (LED1_POLARITY (LED1_SBIT))
  233. #define HAL_STATE_LED2() (LED2_POLARITY (LED2_SBIT))
  234. #define HAL_STATE_LED3() (LED3_POLARITY (LED3_SBIT))
  235. #define HAL_STATE_LED4() HAL_STATE_LED1()
  236. #elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) || defined (HAL_PA_LNA_CC2590)
  237. #define HAL_TURN_OFF_LED1() st( LED1_SBIT = LED1_POLARITY (0); )
  238. #define HAL_TURN_OFF_LED2() HAL_TURN_OFF_LED1()
  239. #define HAL_TURN_OFF_LED3() HAL_TURN_OFF_LED1()
  240. #define HAL_TURN_OFF_LED4() HAL_TURN_OFF_LED1()
  241. #define HAL_TURN_ON_LED1() st( LED1_SBIT = LED1_POLARITY (1); )
  242. #define HAL_TURN_ON_LED2() HAL_TURN_ON_LED1()
  243. #define HAL_TURN_ON_LED3() HAL_TURN_ON_LED1()
  244. #define HAL_TURN_ON_LED4() HAL_TURN_ON_LED1()
  245. #define HAL_TOGGLE_LED1() st( if (LED1_SBIT) { LED1_SBIT = 0; } else { LED1_SBIT = 1;} )
  246. #define HAL_TOGGLE_LED2() HAL_TOGGLE_LED1()
  247. #define HAL_TOGGLE_LED3() HAL_TOGGLE_LED1()
  248. #define HAL_TOGGLE_LED4() HAL_TOGGLE_LED1()
  249. #define HAL_STATE_LED1() (LED1_POLARITY (LED1_SBIT))
  250. #define HAL_STATE_LED2() HAL_STATE_LED1()
  251. #define HAL_STATE_LED3() HAL_STATE_LED1()
  252. #define HAL_STATE_LED4() HAL_STATE_LED1()
  253. #endif
  254. /* ----------- XNV ---------- */
  255. #define XNV_SPI_BEGIN() st(P1_3 = 0;)
  256. #define XNV_SPI_TX(x) st(U1CSR &= ~0x02; U1DBUF = (x);)
  257. #define XNV_SPI_RX() U1DBUF
  258. #define XNV_SPI_WAIT_RXRDY() st(while (!(U1CSR & 0x02));)
  259. #define XNV_SPI_END() st(P1_3 = 1;)
  260. // The TI reference design uses UART1 Alt. 2 in SPI mode.
  261. #define XNV_SPI_INIT() \
  262. st( \
  263. /* Mode select UART1 SPI Mode as master. */\
  264. U1CSR = 0; \
  265. \
  266. /* Setup for 115200 baud. */\
  267. U1GCR = 11; \
  268. U1BAUD = 216; \
  269. \
  270. /* Set bit order to MSB */\
  271. U1GCR |= BV(5); \
  272. \
  273. /* Set UART1 I/O to alternate 2 location on P1 pins. */\
  274. PERCFG |= 0x02; /* U1CFG */\
  275. \
  276. /* Select peripheral function on I/O pins but SS is left as GPIO for separate control. */\
  277. P1SEL |= 0xE0; /* SELP1_[7:4] */\
  278. /* P1.1,2,3: reset, LCD CS, XNV CS. */\
  279. P1SEL &= ~0x0E; \
  280. P1 |= 0x0E; \
  281. P1_1 = 0; \
  282. P1DIR |= 0x0E; \
  283. \
  284. /* Give UART1 priority over Timer3. */\
  285. P2SEL &= ~0x20; /* PRI2P1 */\
  286. \
  287. /* When SPI config is complete, enable it. */\
  288. U1CSR |= 0x40; \
  289. /* Release XNV reset. */\
  290. P1_1 = 1; \
  291. )
  292. /* ------------------------------------------------------------------------------------------------
  293. * Driver Configuration
  294. * ------------------------------------------------------------------------------------------------
  295. */
  296. /* Set to TRUE enable H/W TIMER usage, FALSE disable it */
  297. #ifndef HAL_TIMER
  298. #define HAL_TIMER FALSE
  299. #endif
  300. /* Set to TRUE enable ADC usage, FALSE disable it */
  301. #ifndef HAL_ADC
  302. #define HAL_ADC TRUE
  303. #endif
  304. /* Set to TRUE enable DMA usage, FALSE disable it */
  305. #ifndef HAL_DMA
  306. #define HAL_DMA TRUE
  307. #endif
  308. /* Set to TRUE enable Flash access, FALSE disable it */
  309. #ifndef HAL_FLASH
  310. #define HAL_FLASH TRUE
  311. #endif
  312. /* Set to TRUE enable AES usage, FALSE disable it */
  313. #ifndef HAL_AES
  314. #define HAL_AES TRUE
  315. #endif
  316. #ifndef HAL_AES_DMA
  317. #define HAL_AES_DMA TRUE
  318. #endif
  319. /* Set to TRUE enable LCD usage, FALSE disable it */
  320. #ifndef HAL_LCD
  321. #define HAL_LCD TRUE
  322. #endif
  323. /* Set to TRUE enable LED usage, FALSE disable it */
  324. #ifndef HAL_LED
  325. #define HAL_LED TRUE
  326. #endif
  327. #if (!defined BLINK_LEDS) && (HAL_LED == TRUE)
  328. #define BLINK_LEDS
  329. #endif
  330. /* Set to TRUE enable KEY usage, FALSE disable it */
  331. #ifndef HAL_KEY
  332. #define HAL_KEY TRUE
  333. #endif
  334. /* Set to TRUE enable UART usage, FALSE disable it */
  335. #ifndef HAL_UART
  336. #if (defined ZAPP_P1) || (defined ZAPP_P2) || (defined ZTOOL_P1) || (defined ZTOOL_P2)
  337. #define HAL_UART TRUE
  338. #else
  339. #define HAL_UART FALSE
  340. #endif
  341. #endif
  342. #if HAL_UART
  343. // Always prefer to use DMA over ISR.
  344. #if HAL_DMA
  345. #ifndef HAL_UART_DMA
  346. #if (defined ZAPP_P1) || (defined ZTOOL_P1)
  347. #define HAL_UART_DMA 1
  348. #elif (defined ZAPP_P2) || (defined ZTOOL_P2)
  349. #define HAL_UART_DMA 2
  350. #else
  351. #define HAL_UART_DMA 1
  352. #endif
  353. #endif
  354. #define HAL_UART_ISR 0
  355. #else
  356. #ifndef HAL_UART_ISR
  357. #if (defined ZAPP_P1) || (defined ZTOOL_P1)
  358. #define HAL_UART_ISR 1
  359. #elif (defined ZAPP_P2) || (defined ZTOOL_P2)
  360. #define HAL_UART_ISR 2
  361. #else
  362. #define HAL_UART_ISR 1
  363. #endif
  364. #endif
  365. #define HAL_UART_DMA 0
  366. #endif
  367. // Used to set P2 priority - USART0 over USART1 if both are defined.
  368. #if ((HAL_UART_DMA == 1) || (HAL_UART_ISR == 1))
  369. #define HAL_UART_PRIPO 0x00
  370. #else
  371. #define HAL_UART_PRIPO 0x40
  372. #endif
  373. #else
  374. #define HAL_UART_DMA 0
  375. #define HAL_UART_ISR 0
  376. #endif
  377. /*******************************************************************************************************
  378. */
  379. #endif