UCOS_TI_LM3S_Keil
 全部 结构体 文件 函数 变量 类型定义 宏定义 
bsp.c
浏览该文件的文档.
1 /*
2 *********************************************************************************************************
3 * MICIRUM BOARD SUPPORT PACKAGE
4 *
5 * (c) Copyright 2009; Micrium, Inc.; Weston, FL
6 *
7 * All rights reserved. Protected by international copyright laws.
8 * Knowledge of the source code may not be used to write a similar
9 * product. This file may only be used in accordance with a license
10 * and should not be redistributed in any way.
11 *********************************************************************************************************
12 */
13 
14 /*
15 *********************************************************************************************************
16 *
17 * BOARD SUPPORT PACKAGE
18 *
19 * LUMINARY MICRO LM3S1968 on the EK-LM3S1968
20 *
21 * Filename : bsp.c
22 * Version : V1.02
23 * Programmer(s) : BAN
24 *********************************************************************************************************
25 */
26 
27 
28 /*
29 *********************************************************************************************************
30 * INCLUDE FILES
31 *********************************************************************************************************
32 */
33 
34 #define BSP_MODULE
35 #include <bsp.h>
36 
37 
38 /*
39 *********************************************************************************************************
40 * LOCAL DEFINES
41 *********************************************************************************************************
42 */
43 
44  /* -------------------- GPIOA PINS -------------------- */
45 #define BSP_GPIOA_U0RX DEF_BIT_00 /* UART0 Receive. */
46 #define BSP_GPIOA_U0TX DEF_BIT_01 /* UART1 Transmit. */
47 #define BSP_GPIOA_SSI0CLK DEF_BIT_02 /* OLED. */
48 #define BSP_GPIOA_OLEDCSN DEF_BIT_03 /* OLED Chip Select. */
49 #define BSP_GPIOA_SSI0RX DEF_BIT_04 /* OLED. */
50 
51  /* -------------------- GPIOC PINS -------------------- */
52 #define BSP_GPIOC_OLEDDC DEF_BIT_07 /* OLED. */
53 
54  /* -------------------- GPIOG PINS -------------------- */
55 #define BSP_GPIOG_PWM0 DEF_BIT_02 /* User LED. */
56 #define BSP_GPIOG_SW_UP DEF_BIT_03 /* User Button: Up. */
57 #define BSP_GPIOG_SW_DOWN DEF_BIT_04 /* User Button: Down. */
58 #define BSP_GPIOG_SW_LEFT DEF_BIT_05 /* User Button: Left. */
59 #define BSP_GPIOG_SW_RIGHT DEF_BIT_06 /* User Button: Right. */
60 #define BSP_GPIOG_SW_SELECT DEF_BIT_07 /* User Button: Select. */
61 
62  /* -------------------- GPIOH PINS -------------------- */
63 #define BSP_GPIOH_PWM2 DEF_BIT_00 /* Sound. */
64 #define BSP_GPIOH_PWM3 DEF_BIT_01 /* Sound. */
65 
66 
67 /*
68 *********************************************************************************************************
69 * LOCAL CONSTANTS
70 *********************************************************************************************************
71 */
72 
73 
74 /*
75 *********************************************************************************************************
76 * LOCAL DATA TYPES
77 *********************************************************************************************************
78 */
79 
80 
81 /*
82 *********************************************************************************************************
83 * LOCAL TABLES
84 *********************************************************************************************************
85 */
86 
87 
88 /*
89 *********************************************************************************************************
90 * LOCAL GLOBAL VARIABLES
91 *********************************************************************************************************
92 */
93 
94 
95 /*
96 *********************************************************************************************************
97 * LOCAL FUNCTION PROTOTYPES
98 *********************************************************************************************************
99 */
100 
101 static void BSP_LED_Init(void);
102 
103 static void BSP_PB_Init (void);
104 
105 
106 /*
107 *********************************************************************************************************
108 * LOCAL CONFIGURATION ERRORS
109 *********************************************************************************************************
110 */
111 
112 
113 /*
114 *********************************************************************************************************
115 * BSP_Init()
116 *
117 * Description : Initialize the Board Support Package (BSP).
118 *
119 * Argument(s) : none.
120 *
121 * Return(s) : none.
122 *
123 * Caller(s) : Application.
124 *
125 * Note(s) : (1) This function SHOULD be called before any other BSP function is called.
126 *********************************************************************************************************
127 */
128 
129 void BSP_Init (void)
130 {
131  SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
132  BSP_IntInit();
133 
134  RIT128x96x4Init(3500000);
135 
136  BSP_LED_Init(); /* Initialize the I/Os for the LED controls. */
137  BSP_PB_Init(); /* Initialize the I/Os for the PB controls. */
138 }
139 
140 
141 /*
142 *********************************************************************************************************
143 * BSP_CPU_ClkFreq()
144 *
145 * Description : Read CPU registers to determine the CPU clock frequency of the chip.
146 *
147 * Argument(s) : none.
148 *
149 * Return(s) : The CPU clock frequency, in Hz.
150 *
151 * Caller(s) : Application.
152 *
153 * Note(s) : none.
154 *********************************************************************************************************
155 */
156 
158 {
159  CPU_INT32U freq;
160 
161 
162  freq = SysCtlClockGet();
163  return (freq);
164 }
165 
166 
167 /*
168 *********************************************************************************************************
169 *********************************************************************************************************
170 * LED FUNCTIONS
171 *********************************************************************************************************
172 *********************************************************************************************************
173 */
174 
175 /*
176 *********************************************************************************************************
177 * BSP_LED_Init()
178 *
179 * Description : Initialize the I/O for the LEDs
180 *
181 * Argument(s) : none.
182 *
183 * Return(s) : none.
184 *
185 * Caller(s) : BSP_Init().
186 *
187 * Note(s) : none.
188 *********************************************************************************************************
189 */
190 
191 static void BSP_LED_Init (void)
192 {
193  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
194  GPIODirModeSet(GPIO_PORTG_BASE, BSP_GPIOG_PWM0, GPIO_DIR_MODE_OUT);
195  GPIOPadConfigSet(GPIO_PORTG_BASE, BSP_GPIOG_PWM0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
196  BSP_LED_Off(0); /* Turn OFF all the LEDs. */
197 }
198 
199 
200 /*
201 *********************************************************************************************************
202 * BSP_LED_On()
203 *
204 * Description : Turn ON any or all the LEDs on the board.
205 *
206 * Argument(s) : led The ID of the LED to control:
207 *
208 * 0 turn ON all LEDs on the board
209 * 1 turn ON LED
210 *
211 * Return(s) : none.
212 *
213 * Caller(s) : Application.
214 *
215 * Note(s) : none.
216 *********************************************************************************************************
217 */
218 
220 {
221  switch (led) {
222  case 0:
223  case 1:
224  GPIOPinWrite(GPIO_PORTG_BASE, BSP_GPIOG_PWM0, 0);
225  break;
226 
227  default:
228  break;
229  }
230 }
231 
232 
233 /*
234 *********************************************************************************************************
235 * BSP_LED_Off()
236 *
237 * Description : Turn OFF any or all the LEDs on the board.
238 *
239 * Argument(s) : led The ID of the LED to control:
240 *
241 * 0 turn OFF all LEDs on the board
242 * 1 turn OFF LED
243 *
244 * Return(s) : none.
245 *
246 * Caller(s) : Application.
247 *
248 * Note(s) : none.
249 *********************************************************************************************************
250 */
251 
253 {
254  switch (led) {
255  case 0:
256  case 1:
257  GPIOPinWrite(GPIO_PORTG_BASE, BSP_GPIOG_PWM0, BSP_GPIOG_PWM0);
258  break;
259 
260  default:
261  break;
262  }
263 }
264 
265 
266 /*
267 *********************************************************************************************************
268 * BSP_LED_Toggle()
269 *
270 * Description : TOGGLE any or all the LEDs on the board.
271 *
272 * Argument(s) : led The ID of the LED to control:
273 *
274 * 0 TOGGLE all LEDs on the board
275 * 1 TOGGLE LED
276 *
277 * Return(s) : none.
278 *
279 * Caller(s) : Application.
280 *
281 * Note(s) : none.
282 *********************************************************************************************************
283 */
284 
286 {
287  CPU_INT32U pins;
288 
289 
290  switch (led) {
291  case 0:
292  case 1:
293  pins = GPIOPinRead(GPIO_PORTG_BASE, BSP_GPIOG_PWM0);
294  if (DEF_BIT_IS_CLR(pins, BSP_GPIOG_PWM0) == DEF_YES) {
295  GPIOPinWrite(GPIO_PORTG_BASE, BSP_GPIOG_PWM0, BSP_GPIOG_PWM0);
296  } else {
297  GPIOPinWrite(GPIO_PORTG_BASE, BSP_GPIOG_PWM0, 0);
298  }
299  break;
300 
301  default:
302  break;
303  }
304 }
305 
306 
307 /*
308 *********************************************************************************************************
309 *********************************************************************************************************
310 * PB FUNCTIONS
311 *********************************************************************************************************
312 *********************************************************************************************************
313 */
314 
315 /*
316 *********************************************************************************************************
317 * BSP_PB_Init()
318 *
319 * Description : Initialize the board's PB.
320 *
321 * Argument(s) : none.
322 *
323 * Return(s) : none.
324 *
325 * Caller(s) : BSP_Init().
326 *
327 * Note(s) : none.
328 *********************************************************************************************************
329 */
330 
331 static void BSP_PB_Init (void)
332 {
333  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
334 
335  GPIODirModeSet( GPIO_PORTG_BASE, BSP_GPIOG_SW_SELECT | BSP_GPIOG_SW_UP | BSP_GPIOG_SW_DOWN | BSP_GPIOG_SW_LEFT | BSP_GPIOG_SW_RIGHT, GPIO_DIR_MODE_IN);
336  GPIOPadConfigSet(GPIO_PORTG_BASE, BSP_GPIOG_SW_SELECT | BSP_GPIOG_SW_UP | BSP_GPIOG_SW_DOWN | BSP_GPIOG_SW_LEFT | BSP_GPIOG_SW_RIGHT, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
337 }
338 
339 
340 /*
341 *********************************************************************************************************
342 * BSP_PB_GetStatus()
343 *
344 * Description : Get the status of a push button on the board.
345 *
346 * Argument(s) : pb The ID of the push button to probe
347 *
348 * 1 probe the SELECT push button
349 * 2 probe the UP push button
350 * 3 probe the DOWN push button
351 * 4 probe the LEFT push button
352 * 5 probe the RIGHT push button
353 *
354 * Return(s) : DEF_FALSE if the push button is pressed.
355 * DEF_TRUE if the push button is not pressed.
356 *
357 * Caller(s) : Application.
358 *
359 * Note(s) : none.
360 *********************************************************************************************************
361 */
362 
364 {
365  CPU_BOOLEAN status;
366  CPU_INT32U pins;
367 
368 
369  status = DEF_FALSE;
370 
371  switch (pb) {
372  case 1:
373  pins = GPIOPinRead(GPIO_PORTG_BASE, BSP_GPIOG_SW_SELECT);
374  if (pins == 0) {
375  status = DEF_TRUE;
376  }
377  break;
378 
379  case 2:
380  pins = GPIOPinRead(GPIO_PORTG_BASE, BSP_GPIOG_SW_UP);
381  if (pins == 0) {
382  status = DEF_TRUE;
383  }
384  break;
385 
386  case 3:
387  pins = GPIOPinRead(GPIO_PORTG_BASE, BSP_GPIOG_SW_DOWN);
388  if (pins == 0) {
389  status = DEF_TRUE;
390  }
391  break;
392 
393  case 4:
394  pins = GPIOPinRead(GPIO_PORTG_BASE, BSP_GPIOG_SW_LEFT);
395  if (pins == 0) {
396  status = DEF_TRUE;
397  }
398  break;
399 
400  case 5:
401  pins = GPIOPinRead(GPIO_PORTG_BASE, BSP_GPIOG_SW_RIGHT);
402  if (pins == 0) {
403  status = DEF_TRUE;
404  }
405  break;
406 
407  default:
408  break;
409  }
410 
411  return (status);
412 }