Contiki 2.5
board.h
Go to the documentation of this file.
1 /** @file board.h
2  * @brief Header file x STM32W108 Kits boards abstraction.
3  * See @ref board for documentation.
4  *
5  *
6  * See hal/micro/cortexm3/stm32w108/board.h for source code.
7  *
8  * <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
9  */
10 #ifndef _BOARD_H_
11 #define _BOARD_H_
12 
13 /** @addtogroup board
14  * @brief ST board abstraction layer
15  *
16  * This header defines API and data structures to handle ST boards with thei associated resources
17  * on algorithm behavior.
18  * See hal/micro/cortexm3/stm32w108/board.h for source code.
19  *@{
20  */
21 
22 /**
23  * @brief Define the number of LEDs in the specific board revision
24  */
25 #define LEDS_MB851A 2
26 /**
27  * @brief Define the number of LEDs in the specific board revision
28  */
29 #define LEDS_MB851B 2
30 /**
31  * @brief Define the number of LEDs in the specific board revision
32  */
33 #define LEDS_MB851C 2
34 /**
35  * @brief Define the number of LEDs in the specific board revision
36  */
37 #define LEDS_MB954A 2
38 /**
39  * @brief Define the number of LEDs in the specific board revision
40  */
41 #define LEDS_MB954B 2
42 /**
43  * @brief Define the number of LEDs in the specific board revision
44  */
45 #define LEDS_MB950A 2
46 /**
47  * @brief Define the number of LEDs in the specific board revision
48  */
49 #define LEDS_MB951A 2
50 
51 /**
52  * @brief Define the number of user buttons in the specific board revision
53  */
54 #define BUTTONS_MB851A 1
55 /**
56  * @brief Define the number of user buttons in the specific board revision
57  */
58 #define BUTTONS_MB851B 1
59 /**
60  * @brief Define the number of user buttons in the specific board revision
61  */
62 #define BUTTONS_MB851C 1
63 /**
64  * @brief Define the number of user buttons in the specific board revision
65  */
66 #define BUTTONS_MB954A 1
67 /**
68  * @brief Define the number of user buttons in the specific board revision
69  */
70 #define BUTTONS_MB954B 1
71 /**
72  * @brief Define the number of user buttons in the specific board revision
73  */
74 #define BUTTONS_MB950A 5
75 /**
76  * @brief Define the number of user buttons in the specific board revision
77  */
78 #define BUTTONS_MB951A 1
79 
80 /**
81  * @brief Data structure for led description
82  */
83 typedef struct LedResourceStruct {
84  /** Name of the LED as printed in the board */
85  char *name;
86  /** GPIO port associated with the LED */
87  int8u gpioPort;
88  /** GPIO pin associated with the LED */
89  int8u gpioPin;
91 
93 
94 /**
95  * @brief Data structure for button description
96  */
97 typedef struct ButtonResourceStruct {
98  /** Name of the button as printed in the board */
99  char *name;
100  /** GPIO port associated with the button */
101  int8u gpioPort;
102  /** GPIO pin associated with the button */
103  int8u gpioPin;
105 
106 /**
107  * @brief Data structure for MEMS description
108  */
109 typedef struct MemsResourceStruct {
110  /** Name of the MEMS device */
111  char *name;
112  /** Serial communication port associated with the MEMS */
113  int8u scPort;
115 
116 /**
117  * @brief Data structure for temperature sensor description
118  */
119 typedef struct TempSensorResourceStruct {
120  /** Name of the temperature sensor device */
121  char *name;
122  /** GPIO port associated with the sensor */
123  int8u gpioPort;
124  /** GPIO pin associated with the sensor */
125  int8u gpioPin;
126  /** Flag to indicate whether the ADC range extension bug fix is implemented */
127  boolean adcFix;
129 
130 /**
131  * @brief Data structure for board user I/O
132  */
133 typedef struct BoardIOStruct {
134  /** Pointer to LED resources */
136  /** Pointer to button resources */
138 } BoardIOType;
139 
140 /**
141  * @brief Flag to indicate if MEMS is present
142  */
143 #define BOARD_HAS_MEMS (1 << 0)
144 /**
145  * @brief Flag to indicate if temeprature sensor is present
146  */
147 #define BOARD_HAS_TEMP_SENSOR (1 << 1)
148 /**
149  * @brief Flag to indicate if external power amplifier is present
150  */
151 #define BOARD_HAS_PA (1 << 2)
152 /**
153  * @brief Flag to indicate if EEPROM is present
154  */
155 #define BOARD_HAS_EEPROM (1 << 3)
156 /**
157  * @brief Flag to indicate if FTDI is used as PC interface
158  */
159 #define BOARD_HAS_FTDI (1 << 4)
160 /**
161  * @brief Flag to indicate if STM32F is used as PC interface
162  */
163 #define BOARD_HAS_STM32F (1 << 5)
164 
165 /**
166  * @brief Data structure describing board features
167  */
168 typedef struct BoardResourcesStruct {
169  const char *name;
170  const int32u flags;
171  /** Number of buttons */
172  int8u buttons;
173  /** Number of leds */
174  int8u leds;
175  /** Board I/O description */
176  const BoardIOType *io;
177  /** Board infrared led description */
179  /** Board infrared MEMS description */
181  /** Board infrared temeprature sensor description */
184 
185 extern BoardResourcesType const *boardDescription;
186 
187 // Generic definitions
188 #define GPIO_PxCLR_BASE (GPIO_PACLR_ADDR)
189 #define GPIO_PxSET_BASE (GPIO_PASET_ADDR)
190 #define GPIO_PxOUT_BASE (GPIO_PAOUT_ADDR)
191 #define GPIO_PxIN_BASE (GPIO_PAIN_ADDR)
192 // Each port is offset from the previous port by the same amount
193 #define GPIO_Px_OFFSET (GPIO_PBCFGL_ADDR-GPIO_PACFGL_ADDR)
194 
195 
196 /* leds definitions */
197 #define LED_D1 PORTx_PIN(boardDescription->io->leds[0].gpioPort, boardDescription->io->leds[0].gpioPin) //PORTB_PIN(6)
198 #define LED_D3 PORTx_PIN(boardDescription->io->leds[1].gpioPort, boardDescription->io->leds[1].gpioPin) // PORTB_PIN(5)
199 #define DUMMY_LED 0xff
200 
201 
202 /** Description buttons definition */
203 #define BUTTON_Sn(n) (PORTx_PIN(boardDescription->io->buttons[n].gpioPort, boardDescription->io->buttons[n].gpioPin))
204 #define BUTTON_Sn_WAKE_SOURCE(n) (1 << ((boardDescription->io->buttons[n].gpioPin) + (8 * (boardDescription->io->buttons[n].gpioPort >> 3))))
205 #define BUTTON_INPUT_GPIO(port) *((volatile int32u *) (GPIO_PxIN_BASE + GPIO_Px_OFFSET * port))
206 #define DUMMY_BUTTON 0xff
207 
208 #define BUTTON_S1 (boardDescription->buttons>0 ? BUTTON_Sn(0): DUMMY_BUTTON)
209 #define BUTTON_S2 (boardDescription->buttons>1 ? BUTTON_Sn(1): DUMMY_BUTTON)
210 #define BUTTON_S3 (boardDescription->buttons>2 ? BUTTON_Sn(2): DUMMY_BUTTON)
211 #define BUTTON_S4 (boardDescription->buttons>3 ? BUTTON_Sn(3): DUMMY_BUTTON)
212 #define BUTTON_S5 (boardDescription->buttons>4 ? BUTTON_Sn(4): DUMMY_BUTTON)
213 
214 #define BUTTON_S1_WAKE_SOURCE (boardDescription->buttons>0 ? BUTTON_Sn_WAKE_SOURCE(0): 0)
215 #define BUTTON_S2_WAKE_SOURCE (boardDescription->buttons>1 ? BUTTON_Sn_WAKE_SOURCE(1): 0)
216 #define BUTTON_S3_WAKE_SOURCE (boardDescription->buttons>2 ? BUTTON_Sn_WAKE_SOURCE(2): 0)
217 #define BUTTON_S4_WAKE_SOURCE (boardDescription->buttons>3 ? BUTTON_Sn_WAKE_SOURCE(3): 0)
218 #define BUTTON_S5_WAKE_SOURCE (boardDescription->buttons>4 ? BUTTON_Sn_WAKE_SOURCE(4): 0)
219 
220 /** Description uart definition */
221 #define UART_TX PORTB_PIN(1)
222 #define UART_RX PORTB_PIN(2)
223 #define UART_RX_WAKE_SOURCE 0x00000400
224 
225 /** Description temperature sensor GPIO */
226 #define TEMPERATURE_SENSOR_GPIO PORTx_PIN(boardDescription->temperatureSensor->gpioPort, boardDescription->temperatureSensor->gpioPin) // PORTB_PIN(7)
227 
228 /** @brief Return pointer to board description structure
229  *
230  *
231  * @return Pointer to board description structure
232  */
234 /**
235  * @brief Initialize the board description data structure after
236  * autodetect of the boards based on the CIB Board name field
237  * content. In case of invalid CIB data it will default to MB851A.
238  * Customer normally needs to modify this file to adapt it to their specific board.
239  */
240 void halBoardInit(void);
241 /**
242  * @brief Perform board specific action to power up the system.
243  * This code depends on the actual board features and configure
244  * the stm32w and on board devices for proper operation.
245  * Customer normally needs to modify this file to adapt it to their specific board.
246  */
247 void halBoardPowerUp(void);
248 /**
249  * @brief Perform board specific action to power down the system, usually before going to deep sleep.
250  * This code depends on the actual board features and configure
251  * the stm32w and on board devices for minimal power consumption.
252  * Customer normally needs to modify this file to adapt it to their specific board.
253  */
254 void halBoardPowerDown(void);
255 
256 #endif /* _BOARD_H_ */
257 
258 /** @} // END addtogroup
259  */