OnBoard.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /**************************************************************************************************
  2. Filename: OnBoard.h
  3. Revised: $Date: 2012-03-29 12:09:02 -0700 (Thu, 29 Mar 2012) $
  4. Revision: $Revision: 29943 $
  5. Description: Defines stuff for EVALuation boards
  6. Notes: This file targets the Chipcon CC2530/31ZNP
  7. Copyright 2005-2012 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 ONBOARD_H
  35. #define ONBOARD_H
  36. #ifdef __cplusplus
  37. extern "C"
  38. {
  39. #endif
  40. /*********************************************************************
  41. * INCLUDES
  42. */
  43. #include "hal_mcu.h"
  44. #include "hal_uart.h"
  45. #include "hal_sleep.h"
  46. #include "osal.h"
  47. /*********************************************************************
  48. * GLOBAL VARIABLES
  49. */
  50. // 64-bit Extended Address of this device
  51. extern uint8 aExtendedAddress[8];
  52. /*********************************************************************
  53. * CONSTANTS
  54. */
  55. // Timer clock and power-saving definitions
  56. #define TIMER_DECR_TIME 1 // 1ms - has to be matched with TC_OCC
  57. /* OSAL timer defines */
  58. #define TICK_TIME 1000 // Timer per tick - in micro-sec
  59. /*
  60. Timer4 interrupts @ 1.0 msecs using 1/128 pre-scaler
  61. TICK_COUNT = (CPUMHZ / 128) / 1000
  62. */
  63. #define TICK_COUNT 1 // 32 Mhz Output Compare Count
  64. /* CC2430 DEFINITIONS */
  65. // MEMCTR bit definitions
  66. #define ALWAYS1 0x01 // Reserved: always=1
  67. #define CACHDIS 0x02 // Flash cache: disable=1
  68. #define FMAP0 0x10 // Flash bank map, bit0
  69. #define FMAP1 0x20 // Flash bank map, bit1
  70. #define FMAP 0x30 // Flash bank map, mask
  71. #define MUNIF 0x40 // Memory mapping: unified=1
  72. // PCON bit definitions
  73. #define PMODESET 0x01 // Power mode control: 1=set PMx
  74. // Reset bit definitions
  75. #define LRESET 0x18 // Last reset bit mask
  76. #define RESETPO 0x00 // Power-On reset
  77. #define RESETEX 0x08 // External reset
  78. #define RESETWD 0x10 // WatchDog reset
  79. /* GPIO PORT DEFINITIONS */
  80. // GPIO bit definitions
  81. #define GPIO_0 0x01 // Px_0: GPIO=0, PIO=1
  82. #define GPIO_1 0x02 // Px_1: GPIO=0, PIO=1
  83. #define GPIO_2 0x04 // Px_2: GPIO=0, PIO=1
  84. #define GPIO_3 0x08 // Px_3: GPIO=0, PIO=1
  85. #define GPIO_4 0x10 // Px_4: GPIO=0, PIO=1
  86. #define GPIO_5 0x20 // Px_5: GPIO=0, PIO=1
  87. #define GPIO_6 0x40 // Px_6: GPIO=0, PIO=1
  88. #define GPIO_7 0x80 // Px_7: GPIO=0, PIO=1
  89. /* WATCHDOG TIMER DEFINITIONS */
  90. // WDCTL bit definitions
  91. #define WDINT0 0x01 // Interval, bit0
  92. #define WDINT1 0x02 // Interval, bit1
  93. #define WDINT 0x03 // Interval, mask
  94. #define WDMODE 0x04 // Mode: watchdog=0, timer=1
  95. #define WDEN 0x08 // Timer: disabled=0, enabled=1
  96. #define WDCLR0 0x10 // Clear timer, bit0
  97. #define WDCLR1 0x20 // Clear timer, bit1
  98. #define WDCLR2 0x40 // Clear timer, bit2
  99. #define WDCLR3 0x80 // Clear timer, bit3
  100. #define WDCLR 0xF0 // Clear timer, mask
  101. // WD timer intervals
  102. #define WDTISH 0x03 // Short: clk * 64
  103. #define WDTIMD 0x02 // Medium: clk * 512
  104. #define WDTILG 0x01 // Long: clk * 8192
  105. #define WDTIMX 0x00 // Maximum: clk * 32768
  106. // WD clear timer patterns
  107. #define WDCLP1 0xA0 // Clear pattern 1
  108. #define WDCLP2 0x50 // Clear pattern 2
  109. #if defined CC2531ZNP
  110. #define ZNP_CFG1_UART 0
  111. #define ZNP_CFG1_SPI 1
  112. extern uint8 znpCfg1;
  113. #endif
  114. /*********************************************************************
  115. * MACROS
  116. */
  117. // These Key definitions are unique to this development system.
  118. // They are used to bypass functions when starting up the device.
  119. #define SW_BYPASS_NV HAL_KEY_SW_5 // Bypass Network layer NV restore
  120. #define SW_BYPASS_START HAL_KEY_SW_1 // Bypass Network initialization
  121. // LCD Support Defintions
  122. #ifdef LCD_SUPPORTED
  123. #if !defined DEBUG
  124. #define DEBUG 0
  125. #endif
  126. #if LCD_SUPPORTED==DEBUG
  127. #define SERIAL_DEBUG_SUPPORTED // Serial-debug
  128. #endif
  129. #else // No LCD support
  130. #undef SERIAL_DEBUG_SUPPORTED // No serial-debug
  131. #endif
  132. /* Serial Port Definitions */
  133. #if defined (ZAPP_P1)
  134. #define ZAPP_PORT HAL_UART_PORT_0
  135. #elif defined (ZAPP_P2)
  136. #define ZAPP_PORT HAL_UART_PORT_1
  137. #else
  138. #undef ZAPP_PORT
  139. #endif
  140. #if defined (ZTOOL_P1)
  141. #define ZTOOL_PORT HAL_UART_PORT_0
  142. #elif defined (ZTOOL_P2)
  143. #define ZTOOL_PORT HAL_UART_PORT_1
  144. #else
  145. #undef ZTOOL_PORT
  146. #endif
  147. #define MT_UART_TX_BUFF_MAX 254
  148. #define MT_UART_RX_BUFF_MAX 254
  149. #define MT_UART_THRESHOLD (MT_UART_RX_BUFF_MAX / 2)
  150. #define MT_UART_IDLE_TIMEOUT 2
  151. #define HAL_UART_PORT 0
  152. // SOC defines the ideal sizes in the individual _hal_uart_dma/isr.c modules.
  153. #define HAL_UART_FLOW_THRESHOLD 0
  154. #define HAL_UART_RX_BUF_SIZE 0
  155. #define HAL_UART_TX_BUF_SIZE 0
  156. #define HAL_UART_IDLE_TIMEOUT 0
  157. // Restart system from absolute beginning
  158. // Disables interrupts, forces WatchDog reset
  159. #define SystemReset() \
  160. { \
  161. HAL_DISABLE_INTERRUPTS(); \
  162. HAL_SYSTEM_RESET(); \
  163. }
  164. #define SystemResetSoft() Onboard_soft_reset()
  165. /* Reset reason for reset indication */
  166. #define ResetReason() ((SLEEPSTA >> 3) & 0x03)
  167. /* WATCHDOG TIMER DEFINITIONS */
  168. #define WatchDogEnable(wdti) \
  169. { \
  170. WDCTL = WDCLP1 | WDEN | (wdti & WDINT); \
  171. WDCTL = WDCLP2 | WDEN | (wdti & WDINT); \
  172. }
  173. // Wait for specified microseconds
  174. #define MicroWait(t) Onboard_wait(t)
  175. #define OSAL_SET_CPU_INTO_SLEEP(timeout) halSleep(timeout); /* Called from OSAL_PwrMgr */
  176. #ifdef __IAR_SYSTEMS_ICC__
  177. // Internal (MCU) Stack addresses
  178. #define CSTACK_BEG ((uint8 const *)(_Pragma("segment=\"XSTACK\"") __segment_begin("XSTACK")))
  179. #define CSTACK_END ((uint8 const *)(_Pragma("segment=\"XSTACK\"") __segment_end("XSTACK"))-1)
  180. // Stack Initialization Value
  181. #define STACK_INIT_VALUE 0xCD
  182. #else
  183. #error Check compiler compatibility.
  184. #endif
  185. #if !defined MAXMEMHEAP
  186. // Empirical number - compile the project to see what XDATA is left un-used and give it to the HEAP
  187. // TC_LINKKEY_JOIN brings in the bigger demand for ZDSECMGR_TC_DEVICE_MAX=16 vice 1.
  188. #if defined CC2531ZNP
  189. #if defined TC_LINKKEY_JOIN
  190. #define MAXMEMHEAP 3230
  191. #else
  192. #define MAXMEMHEAP 3400
  193. #endif
  194. #else
  195. #if defined TC_LINKKEY_JOIN
  196. #define MAXMEMHEAP 2600
  197. #else
  198. #define MAXMEMHEAP 2770
  199. #endif
  200. #endif
  201. #endif
  202. #define KEY_CHANGE_SHIFT_IDX 1
  203. #define KEY_CHANGE_KEYS_IDX 2
  204. // Initialization levels
  205. #define OB_COLD 0
  206. #define OB_WARM 1
  207. #define OB_READY 2
  208. #ifdef LCD_SUPPORTED
  209. #define BUZZER_OFF 0
  210. #define BUZZER_ON 1
  211. #define BUZZER_BLIP 2
  212. #endif
  213. typedef struct
  214. {
  215. osal_event_hdr_t hdr;
  216. uint8 state; // shift
  217. uint8 keys; // keys
  218. } keyChange_t;
  219. /*********************************************************************
  220. * FUNCTIONS
  221. */
  222. /*
  223. * Initialize the Peripherals
  224. * level: 0=cold, 1=warm, 2=ready
  225. */
  226. extern void InitBoard( uint8 level );
  227. /*
  228. * Get elapsed timer clock counts
  229. */
  230. extern uint32 TimerElapsed( void );
  231. /*
  232. * Register for all key events
  233. */
  234. extern uint8 RegisterForKeys( uint8 task_id );
  235. /* Keypad Control Functions */
  236. /*
  237. * Send "Key Pressed" message to application
  238. */
  239. extern uint8 OnBoard_SendKeys( uint8 keys, uint8 shift );
  240. /* LCD Emulation/Control Functions */
  241. /*
  242. * Convert an interger to an ascii string
  243. */
  244. extern void _itoa( uint16 num, uint8 *buf, uint8 radix );
  245. extern void Dimmer( uint8 lvl );
  246. /* External I/O Processing Functions */
  247. /*
  248. * Turn on an external lamp
  249. */
  250. extern void BigLight_On( void );
  251. /*
  252. * Turn off an external lamp
  253. */
  254. extern void BigLight_Off( void );
  255. /*
  256. * Turn on/off an external buzzer
  257. * on: BUZZER_ON or BUZZER_OFF
  258. */
  259. extern void BuzzerControl( uint8 on );
  260. /*
  261. * Get setting of external dip switch
  262. */
  263. extern uint8 GetUserDipSw( void );
  264. /*
  265. * Calculate the size of used stack
  266. */
  267. extern uint16 OnBoard_stack_used( void );
  268. /*
  269. * Callback routine to handle keys
  270. */
  271. extern void OnBoard_KeyCallback ( uint8 keys, uint8 state );
  272. /*
  273. * Board specific random number generator
  274. */
  275. extern uint16 Onboard_rand( void );
  276. /*
  277. * Board specific micro-second wait
  278. */
  279. extern void Onboard_wait( uint16 timeout );
  280. /*
  281. * Board specific soft reset.
  282. */
  283. extern __near_func void Onboard_soft_reset( void );
  284. /*********************************************************************
  285. *********************************************************************/
  286. #ifdef __cplusplus
  287. }
  288. #endif
  289. #endif // ONBOARD_H