hal_board_cfg.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /**************************************************************************************************
  2. Filename: hal_board_cfg.h
  3. Revised: $Date: 2012-03-29 12:09:02 -0700 (Thu, 29 Mar 2012) $
  4. Revision: $Revision: 29943 $
  5. Description: Declarations for the CC2531 USB dongle.
  6. Copyright 2009-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_BOARD_CFG_H
  34. #define HAL_BOARD_CFG_H
  35. /* ------------------------------------------------------------------------------------------------
  36. * Includes
  37. * ------------------------------------------------------------------------------------------------
  38. */
  39. #include "hal_mcu.h"
  40. #include "hal_defs.h"
  41. #include "hal_types.h"
  42. #include "usb_board_cfg.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. #define HAL_BOARD_CC2530USB
  63. /* ------------------------------------------------------------------------------------------------
  64. * Clock Speed
  65. * ------------------------------------------------------------------------------------------------
  66. */
  67. #define HAL_CPU_CLOCK_MHZ 32
  68. /* This flag should be defined if the SoC uses the 32MHz crystal
  69. * as the main clock source (instead of DCO).
  70. */
  71. #define HAL_CLOCK_CRYSTAL
  72. #define OSC32K_CRYSTAL_INSTALLED FALSE
  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 0x00 /* external 32 KHz xosc */
  76. #else
  77. #define OSC_32KHZ 0x80 /* internal 32 KHz rcosc */
  78. #endif
  79. #define HAL_CLOCK_STABLE() st( while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); )
  80. /* ------------------------------------------------------------------------------------------------
  81. * LED Configuration
  82. * ------------------------------------------------------------------------------------------------
  83. */
  84. #define HAL_NUM_LEDS 2
  85. #define HAL_LED_BLINK_DELAY() st( { volatile uint32 i; for (i=0; i<0x5800; i++) { }; } )
  86. /* 1 - Green */
  87. #define LED1_BV BV(0)
  88. #define LED1_SBIT P0_0
  89. #define LED1_DDR P0DIR
  90. #define LED1_POLARITY ACTIVE_LOW
  91. /* 2 - Red */
  92. #define LED2_BV BV(1)
  93. #define LED2_SBIT P1_1
  94. #define LED2_DDR P1DIR
  95. #define LED2_POLARITY ACTIVE_HIGH
  96. /* ------------------------------------------------------------------------------------------------
  97. * Push Button Configuration
  98. * ------------------------------------------------------------------------------------------------
  99. */
  100. #define ACTIVE_LOW !
  101. #define ACTIVE_HIGH !! /* double negation forces result to be '1' */
  102. /* S1 */
  103. #define PUSH1_BV BV(2)
  104. #define PUSH1_SBIT P1_2
  105. #define PUSH1_POLARITY ACTIVE_LOW
  106. /* S2 */
  107. #define PUSH2_BV BV(3)
  108. #define PUSH2_SBIT P1_3
  109. #define PUSH2_POLARITY ACTIVE_LOW
  110. /* ------------------------------------------------------------------------------------------------
  111. * OSAL NV implemented by internal flash pages.
  112. * ------------------------------------------------------------------------------------------------
  113. */
  114. // Flash is partitioned into 8 banks of 32 KB or 16 pages.
  115. #define HAL_FLASH_PAGE_PER_BANK 16
  116. // Flash is constructed of 128 pages of 2 KB.
  117. #define HAL_FLASH_PAGE_SIZE 2048
  118. #define HAL_FLASH_WORD_SIZE 4
  119. // CODE banks get mapped into the XDATA range 8000-FFFF.
  120. #define HAL_FLASH_PAGE_MAP 0x8000
  121. // The last 16 bytes of the last available page are reserved for flash lock bits.
  122. // NV page definitions must coincide with segment declaration in project *.xcl file.
  123. #if defined NON_BANKED
  124. #define HAL_FLASH_LOCK_BITS 16
  125. #define HAL_NV_PAGE_END 30
  126. #define HAL_NV_PAGE_CNT 2
  127. #else
  128. #define HAL_FLASH_LOCK_BITS 16
  129. #define HAL_NV_PAGE_END 126
  130. #define HAL_NV_PAGE_CNT 6
  131. #endif
  132. // Re-defining Z_EXTADDR_LEN here so as not to include a Z-Stack .h file.
  133. #define HAL_FLASH_IEEE_SIZE 8
  134. #define HAL_FLASH_IEEE_PAGE (HAL_NV_PAGE_END+1)
  135. #define HAL_FLASH_IEEE_OSET (HAL_FLASH_PAGE_SIZE - HAL_FLASH_LOCK_BITS - HAL_FLASH_IEEE_SIZE)
  136. #define HAL_INFOP_IEEE_OSET 0xC
  137. #define HAL_FLASH_DEV_PRIVATE_KEY_OSET 0x7D2
  138. #define HAL_FLASH_CA_PUBLIC_KEY_OSET 0x7BC
  139. #define HAL_FLASH_IMPLICIT_CERT_OSET 0x78C
  140. #define HAL_NV_PAGE_BEG (HAL_NV_PAGE_END-HAL_NV_PAGE_CNT+1)
  141. // Used by DMA macros to shift 1 to create a mask for DMA registers.
  142. #define HAL_NV_DMA_CH 0
  143. #define HAL_DMA_CH_RX 3
  144. #define HAL_DMA_CH_TX 4
  145. #define HAL_NV_DMA_GET_DESC() HAL_DMA_GET_DESC0()
  146. #define HAL_NV_DMA_SET_ADDR(a) HAL_DMA_SET_ADDR_DESC0((a))
  147. /* ------------------------------------------------------------------------------------------------
  148. * Serial Boot Loader: reserving the first 4 pages of flash and other memory in cc2530-sb.xcl.
  149. * ------------------------------------------------------------------------------------------------
  150. */
  151. #define HAL_SB_IMG_ADDR 0x2000
  152. #define HAL_SB_CRC_ADDR 0x2090
  153. // Size of internal flash less 4 pages for boot loader, 6 pages for NV, & 1 page for lock bits.
  154. #define HAL_SB_IMG_SIZE (0x40000 - 0x2000 - 0x3000 - 0x0800)
  155. /* ------------------------------------------------------------------------------------------------
  156. * Macros
  157. * ------------------------------------------------------------------------------------------------
  158. */
  159. /* ----------- Cache Prefetch control ---------- */
  160. #define PREFETCH_ENABLE() st( FCTL = 0x08; )
  161. #define PREFETCH_DISABLE() st( FCTL = 0x04; )
  162. /* ----------- Board Initialization ---------- */
  163. #define HAL_BOARD_INIT() \
  164. { \
  165. uint16 i; \
  166. \
  167. SLEEPCMD &= ~OSC_PD; /* turn on 16MHz RC and 32MHz XOSC */ \
  168. while (!(SLEEPSTA & XOSC_STB)); /* wait for 32MHz XOSC stable */ \
  169. asm("NOP"); /* chip bug workaround */ \
  170. for (i=0; i<504; i++) asm("NOP"); /* Require 63us delay for all revs */ \
  171. CLKCONCMD = (CLKCONCMD_32MHZ | OSC_32KHZ); /* Select 32MHz XOSC and the source for 32K clock */ \
  172. while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); /* Wait for the change to be effective */ \
  173. SLEEPCMD |= OSC_PD; /* turn off 16MHz RC */ \
  174. \
  175. /* Turn on cache prefetch mode */ \
  176. PREFETCH_ENABLE(); \
  177. \
  178. HAL_TURN_OFF_LED1(); \
  179. LED1_DDR |= LED1_BV; \
  180. HAL_TURN_OFF_LED2(); \
  181. LED2_DDR |= LED2_BV; \
  182. }
  183. /* ----------- Debounce ---------- */
  184. #define HAL_DEBOUNCE(expr) { int i; for (i=0; i<500; i++) { if (!(expr)) i = 0; } }
  185. /* ----------- Push Buttons ---------- */
  186. #define HAL_PUSH_BUTTON1() (PUSH1_POLARITY (PUSH1_SBIT))
  187. #define HAL_PUSH_BUTTON2() (PUSH2_POLARITY (PUSH2_SBIT))
  188. #define HAL_PUSH_BUTTON3() (0)
  189. #define HAL_PUSH_BUTTON4() (0)
  190. #define HAL_PUSH_BUTTON5() (0)
  191. #define HAL_PUSH_BUTTON6() (0)
  192. /* ----------- LED's ---------- */
  193. #define HAL_TURN_OFF_LED1() st( LED1_SBIT = LED1_POLARITY (0); )
  194. #define HAL_TURN_OFF_LED2() st( LED2_SBIT = LED2_POLARITY (0); )
  195. #define HAL_TURN_OFF_LED3() HAL_TURN_OFF_LED1()
  196. #define HAL_TURN_OFF_LED4() HAL_TURN_OFF_LED2()
  197. #define HAL_TURN_ON_LED1() st( LED1_SBIT = LED1_POLARITY (1); )
  198. #define HAL_TURN_ON_LED2() st( LED2_SBIT = LED2_POLARITY (1); )
  199. #define HAL_TURN_ON_LED3() HAL_TURN_ON_LED1()
  200. #define HAL_TURN_ON_LED4() HAL_TURN_ON_LED2()
  201. #define HAL_TOGGLE_LED1() st( if (LED1_SBIT) { LED1_SBIT = 0; } else { LED1_SBIT = 1;} )
  202. #define HAL_TOGGLE_LED2() st( if (LED2_SBIT) { LED2_SBIT = 0; } else { LED2_SBIT = 1;} )
  203. #define HAL_TOGGLE_LED3() HAL_TOGGLE_LED1()
  204. #define HAL_TOGGLE_LED4() HAL_TOGGLE_LED2()
  205. #define HAL_STATE_LED1() (LED1_POLARITY (LED1_SBIT))
  206. #define HAL_STATE_LED2() (LED2_POLARITY (LED2_SBIT))
  207. #define HAL_STATE_LED3() HAL_STATE_LED1()
  208. #define HAL_STATE_LED4() HAL_STATE_LED2()
  209. /* ----------- Minimum safe bus voltage ---------- */
  210. // Vdd/3 / Internal Reference X ENOB --> (Vdd / 3) / 1.15 X 127
  211. #define VDD_2_0 74 // 2.0 V required to safely read/write internal flash.
  212. #define VDD_MIN_RUN VDD_2_0
  213. #define VDD_MIN_NV (VDD_2_0+4) // 5% margin over minimum to survive a page erase and compaction.
  214. /* ------------------------------------------------------------------------------------------------
  215. * Driver Configuration
  216. * ------------------------------------------------------------------------------------------------
  217. */
  218. /* Set to TRUE enable H/W TIMER usage, FALSE disable it */
  219. #ifndef HAL_TIMER
  220. #define HAL_TIMER FALSE
  221. #endif
  222. /* Set to TRUE enable ADC usage, FALSE disable it */
  223. #ifndef HAL_ADC
  224. #define HAL_ADC TRUE
  225. #endif
  226. /* Set to TRUE enable DMA usage, FALSE disable it */
  227. #ifndef HAL_DMA
  228. #define HAL_DMA TRUE
  229. #endif
  230. /* Set to TRUE enable Flash access, FALSE disable it */
  231. #ifndef HAL_FLASH
  232. #define HAL_FLASH TRUE
  233. #endif
  234. /* Set to TRUE enable AES usage, FALSE disable it */
  235. #ifndef HAL_AES
  236. #define HAL_AES TRUE
  237. #endif
  238. #ifndef HAL_AES_DMA
  239. #define HAL_AES_DMA TRUE
  240. #endif
  241. /* Set to TRUE enable LCD usage, FALSE disable it */
  242. #ifndef HAL_LCD
  243. #define HAL_LCD FALSE
  244. #endif
  245. /* Set to TRUE enable LED usage, FALSE disable it */
  246. #ifndef HAL_LED
  247. #define HAL_LED TRUE
  248. #endif
  249. #if (!defined BLINK_LEDS) && (HAL_LED == TRUE)
  250. #define BLINK_LEDS
  251. #endif
  252. /* Set to TRUE enable KEY usage, FALSE disable it */
  253. #ifndef HAL_KEY
  254. #define HAL_KEY TRUE
  255. #endif
  256. /* Set to TRUE enable UART usage, FALSE disable it */
  257. #ifndef HAL_UART
  258. #define HAL_UART TRUE
  259. #define HAL_UART_DMA 0
  260. #define HAL_UART_ISR 0
  261. #define HAL_UART_USB 1
  262. #endif
  263. #ifndef HAL_UART_DMA
  264. #define HAL_UART_DMA 0
  265. #endif
  266. #ifndef HAL_UART_ISR
  267. #define HAL_UART_ISR 0
  268. #endif
  269. #ifndef HAL_UART_USB
  270. # if HAL_UART
  271. # define HAL_UART_USB 1
  272. # else
  273. # define HAL_UART_USB 0
  274. # endif
  275. #endif
  276. /* Set to TRUE enable HID usage, FALSE disable it */
  277. #ifndef HAL_HID
  278. #define HAL_HID FALSE
  279. #endif
  280. #endif
  281. /*******************************************************************************************************
  282. */