OnBoard.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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/31
  7. Copyright 2005-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 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. /*********************************************************************
  110. * MACROS
  111. */
  112. // These Key definitions are unique to this development system.
  113. // They are used to bypass functions when starting up the device.
  114. #define SW_BYPASS_NV HAL_KEY_SW_5 // Bypass Network layer NV restore
  115. #define SW_BYPASS_START HAL_KEY_SW_1 // Bypass Network initialization
  116. // LCD Support Defintions
  117. #ifdef LCD_SUPPORTED
  118. #if !defined DEBUG
  119. #define DEBUG 0
  120. #endif
  121. #if LCD_SUPPORTED==DEBUG
  122. #define SERIAL_DEBUG_SUPPORTED // Serial-debug
  123. #endif
  124. #else // No LCD support
  125. #undef SERIAL_DEBUG_SUPPORTED // No serial-debug
  126. #endif
  127. /* Serial Port Definitions */
  128. #if defined (ZAPP_P1)
  129. #define ZAPP_PORT HAL_UART_PORT_0
  130. #elif defined (ZAPP_P2)
  131. #define ZAPP_PORT HAL_UART_PORT_1
  132. #else
  133. #undef ZAPP_PORT
  134. #endif
  135. #if defined (ZTOOL_P1)
  136. #define ZTOOL_PORT HAL_UART_PORT_0
  137. #elif defined (ZTOOL_P2)
  138. #define ZTOOL_PORT HAL_UART_PORT_1
  139. #else
  140. #undef ZTOOL_PORT
  141. #endif
  142. #define MT_UART_TX_BUFF_MAX 128
  143. #define MT_UART_RX_BUFF_MAX 128
  144. #define MT_UART_THRESHOLD (MT_UART_RX_BUFF_MAX / 2)
  145. #define MT_UART_IDLE_TIMEOUT 6
  146. // Restart system from absolute beginning
  147. // Disables interrupts, forces WatchDog reset
  148. #define SystemReset() \
  149. { \
  150. HAL_DISABLE_INTERRUPTS(); \
  151. HAL_SYSTEM_RESET(); \
  152. }
  153. #define SystemResetSoft() Onboard_soft_reset()
  154. /* Reset reason for reset indication */
  155. #define ResetReason() ((SLEEPSTA >> 3) & 0x03)
  156. /* WATCHDOG TIMER DEFINITIONS */
  157. #define WatchDogEnable(wdti) \
  158. { \
  159. WDCTL = WDCLP1 | WDEN | (wdti & WDINT); \
  160. WDCTL = WDCLP2 | WDEN | (wdti & WDINT); \
  161. }
  162. // Wait for specified microseconds
  163. #define MicroWait(t) Onboard_wait(t)
  164. #define OSAL_SET_CPU_INTO_SLEEP(timeout) halSleep(timeout); /* Called from OSAL_PwrMgr */
  165. #ifdef __IAR_SYSTEMS_ICC__
  166. // Internal (MCU) Stack addresses
  167. #define CSTACK_BEG ((uint8 const *)(_Pragma("segment=\"XSTACK\"") __segment_begin("XSTACK")))
  168. #define CSTACK_END ((uint8 const *)(_Pragma("segment=\"XSTACK\"") __segment_end("XSTACK"))-1)
  169. // Stack Initialization Value
  170. #define STACK_INIT_VALUE 0xCD
  171. #else
  172. #error Check compiler compatibility.
  173. #endif
  174. /* The following Heap sizes are setup for typical TI sample applications,
  175. * and should be adjusted to your systems requirements.
  176. */
  177. #if !defined INT_HEAP_LEN
  178. #if defined RTR_NWK
  179. #define INT_HEAP_LEN 3072
  180. #else
  181. #define INT_HEAP_LEN 2048
  182. #endif
  183. #endif
  184. #define MAXMEMHEAP INT_HEAP_LEN
  185. #define KEY_CHANGE_SHIFT_IDX 1
  186. #define KEY_CHANGE_KEYS_IDX 2
  187. // Initialization levels
  188. #define OB_COLD 0
  189. #define OB_WARM 1
  190. #define OB_READY 2
  191. #ifdef LCD_SUPPORTED
  192. #define BUZZER_OFF 0
  193. #define BUZZER_ON 1
  194. #define BUZZER_BLIP 2
  195. #endif
  196. typedef struct
  197. {
  198. osal_event_hdr_t hdr;
  199. uint8 state; // shift
  200. uint8 keys; // keys
  201. } keyChange_t;
  202. /*********************************************************************
  203. * FUNCTIONS
  204. */
  205. /*
  206. * Initialize the Peripherals
  207. * level: 0=cold, 1=warm, 2=ready
  208. */
  209. extern void InitBoard( uint8 level );
  210. /*
  211. * Get elapsed timer clock counts
  212. */
  213. extern uint32 TimerElapsed( void );
  214. /*
  215. * Register for all key events
  216. */
  217. extern uint8 RegisterForKeys( uint8 task_id );
  218. /* Keypad Control Functions */
  219. /*
  220. * Send "Key Pressed" message to application
  221. */
  222. extern uint8 OnBoard_SendKeys( uint8 keys, uint8 shift );
  223. /* LCD Emulation/Control Functions */
  224. /*
  225. * Convert an interger to an ascii string
  226. */
  227. extern void _itoa( uint16 num, uint8 *buf, uint8 radix );
  228. extern void Dimmer( uint8 lvl );
  229. /* External I/O Processing Functions */
  230. /*
  231. * Turn on an external lamp
  232. */
  233. extern void BigLight_On( void );
  234. /*
  235. * Turn off an external lamp
  236. */
  237. extern void BigLight_Off( void );
  238. /*
  239. * Turn on/off an external buzzer
  240. * on: BUZZER_ON or BUZZER_OFF
  241. */
  242. extern void BuzzerControl( uint8 on );
  243. /*
  244. * Get setting of external dip switch
  245. */
  246. extern uint8 GetUserDipSw( void );
  247. /*
  248. * Calculate the size of used stack
  249. */
  250. extern uint16 OnBoard_stack_used( void );
  251. /*
  252. * Callback routine to handle keys
  253. */
  254. extern void OnBoard_KeyCallback ( uint8 keys, uint8 state );
  255. /*
  256. * Board specific random number generator
  257. */
  258. extern uint16 Onboard_rand( void );
  259. /*
  260. * Board specific micro-second wait
  261. */
  262. extern void Onboard_wait( uint16 timeout );
  263. /*
  264. * Board specific soft reset.
  265. */
  266. extern __near_func void Onboard_soft_reset( void );
  267. /*********************************************************************
  268. *********************************************************************/
  269. #ifdef __cplusplus
  270. }
  271. #endif
  272. #endif // ONBOARD_H