OnBoard.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. /**************************************************************************************************
  2. Filename: OnBoard.h
  3. Revised: $Date: 2009-03-12 16:26:27 -0700 (Thu, 12 Mar 2009) $
  4. Revision: $Revision: 19405 $
  5. Description: Defines stuff for EVALuation boards
  6. Notes: This file targets the Chipcon CC2530
  7. Copyright 2005-2008 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. // Chipcon/Figure8 compatibility
  44. #include "hal_mcu.h"
  45. #include "hal_uart.h"
  46. #include "hal_sleep.h"
  47. #include "osal.h"
  48. /*********************************************************************
  49. * GLOBAL VARIABLES
  50. */
  51. // 64-bit Extended Address of this device
  52. extern uint8 aExtendedAddress[8];
  53. /*********************************************************************
  54. * CONSTANTS
  55. */
  56. // Timer clock and power-saving definitions
  57. #define TIMER_DECR_TIME 1 // 1ms - has to be matched with TC_OCC
  58. /* OSAL timer defines */
  59. #define TICK_TIME 1000 // Timer per tick - in micro-sec
  60. /*
  61. Timer4 interrupts @ 1.0 msecs using 1/128 pre-scaler
  62. TICK_COUNT = (CPUMHZ / 128) / 1000
  63. */
  64. #ifdef CPU_16MHZ
  65. #define TICK_COUNT 1 // 16 Mhz Output Compare Count
  66. #define RETUNE_THRESHOLD 1 // Threshold for power saving algorithm
  67. #elif defined CPU32MHZ
  68. #define TICK_COUNT 1 // 32 Mhz Output Compare Count
  69. #define RETUNE_THRESHOLD 1 // Threshold for power saving algorithm
  70. #endif
  71. /* OSAL Timer define */
  72. #define OSAL_TIMER HAL_TIMER_2
  73. /* CC2430 DEFINITIONS */
  74. // MEMCTR bit definitions
  75. #define ALWAYS1 0x01 // Reserved: always=1
  76. #define CACHDIS 0x02 // Flash cache: disable=1
  77. #define FMAP0 0x10 // Flash bank map, bit0
  78. #define FMAP1 0x20 // Flash bank map, bit1
  79. #define FMAP 0x30 // Flash bank map, mask
  80. #define MUNIF 0x40 // Memory mapping: unified=1
  81. // PCON bit definitions
  82. #define PMODESET 0x01 // Power mode control: 1=set PMx
  83. // Reset bit definitions
  84. #define LRESET 0x18 // Last reset bit mask
  85. #define RESETPO 0x00 // Power-On reset
  86. #define RESETEX 0x08 // External reset
  87. #define RESETWD 0x10 // WatchDog reset
  88. /* GPIO PORT DEFINITIONS */
  89. // GPIO bit definitions
  90. #define GPIO_0 0x01 // Px_0: GPIO=0, PIO=1
  91. #define GPIO_1 0x02 // Px_1: GPIO=0, PIO=1
  92. #define GPIO_2 0x04 // Px_2: GPIO=0, PIO=1
  93. #define GPIO_3 0x08 // Px_3: GPIO=0, PIO=1
  94. #define GPIO_4 0x10 // Px_4: GPIO=0, PIO=1
  95. #define GPIO_5 0x20 // Px_5: GPIO=0, PIO=1
  96. #define GPIO_6 0x40 // Px_6: GPIO=0, PIO=1
  97. #define GPIO_7 0x80 // Px_7: GPIO=0, PIO=1
  98. /* WATCHDOG TIMER DEFINITIONS */
  99. // WDCTL bit definitions
  100. #define WDINT0 0x01 // Interval, bit0
  101. #define WDINT1 0x02 // Interval, bit1
  102. #define WDINT 0x03 // Interval, mask
  103. #define WDMODE 0x04 // Mode: watchdog=0, timer=1
  104. #define WDEN 0x08 // Timer: disabled=0, enabled=1
  105. #define WDCLR0 0x10 // Clear timer, bit0
  106. #define WDCLR1 0x20 // Clear timer, bit1
  107. #define WDCLR2 0x40 // Clear timer, bit2
  108. #define WDCLR3 0x80 // Clear timer, bit3
  109. #define WDCLR 0xF0 // Clear timer, mask
  110. // WD timer intervals
  111. #define WDTISH 0x03 // Short: clk * 64
  112. #define WDTIMD 0x02 // Medium: clk * 512
  113. #define WDTILG 0x01 // Long: clk * 8192
  114. #define WDTIMX 0x00 // Maximum: clk * 32768
  115. // WD clear timer patterns
  116. #define WDCLP1 0xA0 // Clear pattern 1
  117. #define WDCLP2 0x50 // Clear pattern 2
  118. /*********************************************************************
  119. * MACROS
  120. */
  121. // DB peripheral VDD control
  122. #ifdef CC2430DB
  123. #define INIT_DBIO() { P1DIR |= GPIO_2; P1_2 = 0; }
  124. #define STOP_DBIO() { P1_2 = 1; }
  125. #else // CC2430BB or CC2430EB
  126. #define INIT_DBIO()
  127. #define STOP_DBIO()
  128. #endif
  129. // These Key definitions are unique to this development system.
  130. // They are used to bypass functions when starting up the device.
  131. #define SW_BYPASS_NV HAL_KEY_SW_5 // Bypass Network layer NV restore
  132. #define SW_BYPASS_START HAL_KEY_SW_1 // Bypass Network initialization
  133. /* LIQUID CRYSTAL DISPLAY DEFINITIONS */
  134. // LCD Support Defintions
  135. #ifdef LCD_SUPPORTED
  136. #if !defined DEBUG
  137. #define DEBUG 0
  138. #endif
  139. #if LCD_SUPPORTED==DEBUG
  140. #define SERIAL_DEBUG_SUPPORTED // Serial-debug
  141. #endif
  142. #else // No LCD support
  143. #undef SERIAL_DEBUG_SUPPORTED // No serial-debug
  144. #endif
  145. /* SERIAL PORT DEFINITIONS */
  146. // Serial Ports ID Codes
  147. #if defined (ZAPP_P1) || defined (ZTOOL_P1)
  148. #define SERIAL_PORT1 HAL_UART_PORT_0
  149. #else
  150. #undef SERIAL_PORT1
  151. #endif
  152. #if defined (ZAPP_P2) || defined (ZTOOL_P2)
  153. #define SERIAL_PORT2 HAL_UART_PORT_1
  154. #else
  155. #undef SERIAL_PORT2
  156. #endif
  157. // Application Serial Port Assignments
  158. #if defined (ZAPP_P1)
  159. #define ZAPP_PORT SERIAL_PORT1
  160. #elif defined (ZAPP_P2)
  161. #define ZAPP_PORT SERIAL_PORT2
  162. #else
  163. #undef ZAPP_PORT
  164. #endif
  165. #if defined (ZTOOL_P1)
  166. #define ZTOOL_PORT SERIAL_PORT1
  167. #elif defined (ZTOOL_P2)
  168. #define ZTOOL_PORT SERIAL_PORT2
  169. #else
  170. #undef ZTOOL_PORT
  171. #endif
  172. #define MT_UART_TX_BUFF_MAX 128
  173. #define MT_UART_RX_BUFF_MAX 128
  174. #define MT_UART_THRESHOLD (MT_UART_RX_BUFF_MAX / 2)
  175. #define MT_UART_IDLE_TIMEOUT 6
  176. /* Reset reason for reset indication */
  177. #define ResetReason() ((SLEEPSTA >> 3) & 0x03)
  178. /* WATCHDOG TIMER DEFINITIONS */
  179. #define WatchDogEnable(wdti) \
  180. { \
  181. WDCTL = WDCLP1 | WDEN | (wdti & WDINT); \
  182. WDCTL = WDCLP2 | WDEN | (wdti & WDINT); \
  183. }
  184. // Restart system from absolute beginning
  185. // Disables interrupts, forces WatchDog reset
  186. #define SystemReset() \
  187. { \
  188. HAL_DISABLE_INTERRUPTS(); \
  189. WatchDogEnable( WDTISH ); \
  190. while (1) asm("NOP"); \
  191. }
  192. // Jump to F8W Serial Port Bootloader
  193. #define BootLoader() \
  194. { \
  195. HAL_DISABLE_INTERRUPTS(); \
  196. mboxMsg.BootRead = MBOX_SBL_SHELL; \
  197. WatchDogEnable( WDTISH ); \
  198. while (1) asm("NOP"); \
  199. }
  200. // read boot message to application.
  201. #define READ_BOOT_MBOX(x) \
  202. { \
  203. x = (uint32)mboxMsg.AppRead; \
  204. mboxMsg.BootRead = 0; \
  205. }
  206. // Wait for specified microseconds
  207. #define MicroWait(t) Onboard_wait(t)
  208. #define OSAL_SET_CPU_INTO_SLEEP(timeout) halSleep(timeout); /* Called from OSAL_PwrMgr */
  209. // Internal (MCU) RAM addresses
  210. #define MCU_RAM_BEG 0xE000
  211. #define MCU_RAM_END 0xFFFF
  212. #define MCU_RAM_LEN (MCU_RAM_END - MCU_RAM_BEG + 1)
  213. // Internal (MCU) Stack addresses
  214. #define CSTK_PTR _Pragma("segment=\"XSP\"") __segment_begin("XSP")
  215. #define CSTK_BEG _Pragma("segment=\"XSTACK\"") __segment_begin("XSTACK")
  216. #define RSTK_END _Pragma("segment=\"ISTACK\"") __segment_end("ISTACK")
  217. // Stack Initialization Value
  218. #define STACK_INIT_VALUE 0xCD
  219. // Internal (MCU) heap size
  220. #if !defined( INT_HEAP_LEN )
  221. #if defined( ZDO_COORDINATOR )
  222. #define INT_HEAP_LEN 3072
  223. #elif defined( RTR_NWK )
  224. #define INT_HEAP_LEN 3072
  225. #else
  226. #define INT_HEAP_LEN 2048
  227. #endif
  228. #endif
  229. // Memory Allocation Heap
  230. #define MAXMEMHEAP INT_HEAP_LEN // Typically, 0.70-1.50K
  231. #define KEY_CHANGE_SHIFT_IDX 1
  232. #define KEY_CHANGE_KEYS_IDX 2
  233. // Eval board LCD emulation
  234. #define MAX_LCD_CHARS 16
  235. // Initialization levels
  236. #define OB_COLD 0
  237. #define OB_WARM 1
  238. #define OB_READY 2
  239. #ifdef LCD_SUPPORTED
  240. #define BUZZER_OFF 0
  241. #define BUZZER_ON 1
  242. #define BUZZER_BLIP 2
  243. #endif
  244. typedef struct
  245. {
  246. osal_event_hdr_t hdr;
  247. uint8 state; // shift
  248. uint8 keys; // keys
  249. } keyChange_t;
  250. /*********************************************************************
  251. * TYPEDEFS
  252. */
  253. /*********************************************************************
  254. * FUNCTIONS
  255. */
  256. /*
  257. * Initialize the Peripherals
  258. * level: 0=cold, 1=warm, 2=ready
  259. */
  260. extern void InitBoard( uint8 level );
  261. /*
  262. * Get elapsed timer clock counts
  263. */
  264. extern uint32 TimerElapsed( void );
  265. /*
  266. * Register for all key events
  267. */
  268. extern uint8 RegisterForKeys( uint8 task_id );
  269. /* Keypad Control Functions */
  270. /*
  271. * Send "Key Pressed" message to application
  272. */
  273. extern uint8 OnBoard_SendKeys( uint8 keys, uint8 shift);
  274. /*
  275. * Read the keyboard on eval board.
  276. */
  277. extern uint8 OnBoard_GetKeys( void );
  278. /* LCD Emulation/Control Functions */
  279. /*
  280. * Convert an interger to an ascii string
  281. */
  282. extern void _itoa(uint16 num, uint8 *buf, uint8 radix);
  283. extern void Dimmer( uint8 lvl );
  284. /* External I/O Processing Functions */
  285. /*
  286. * Turn on an external lamp
  287. */
  288. extern void BigLight_On( void );
  289. /*
  290. * Turn off an external lamp
  291. */
  292. extern void BigLight_Off( void );
  293. /*
  294. * Turn on/off an external buzzer
  295. * on: BUZZER_ON or BUZZER_OFF
  296. */
  297. extern void BuzzerControl( uint8 on );
  298. /*
  299. * Get setting of external dip switch
  300. */
  301. extern uint8 GetUserDipSw( void );
  302. /*
  303. * Calculate the size of used stack
  304. */
  305. extern uint16 OnBoard_stack_used( void );
  306. /*
  307. * Callback routine to handle keys
  308. */
  309. extern void OnBoard_KeyCallback ( uint8 keys, uint8 state );
  310. /*
  311. * Board specific random number generator
  312. */
  313. extern uint16 Onboard_rand( void );
  314. /*
  315. * Board specific micro-second wait
  316. */
  317. extern void Onboard_wait( uint16 timeout );
  318. /*********************************************************************
  319. *********************************************************************/
  320. #ifdef __cplusplus
  321. }
  322. #endif
  323. #endif // ONBOARD_H