diff options
Diffstat (limited to 'lib/chibios/os/hal/boards/OLIMEX_LPC_P2148')
-rw-r--r-- | lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/board.c | 94 | ||||
-rw-r--r-- | lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/board.h | 92 | ||||
-rw-r--r-- | lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/board.mk | 9 | ||||
-rw-r--r-- | lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/buzzer.c | 110 | ||||
-rw-r--r-- | lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/buzzer.h | 32 |
5 files changed, 337 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/board.c b/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/board.c new file mode 100644 index 000000000..5060e41ab --- /dev/null +++ b/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/board.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #include "hal.h" | ||
18 | |||
19 | #define VAL_TC0_PRESCALER 0 | ||
20 | |||
21 | /** | ||
22 | * @brief PAL setup. | ||
23 | * @details Digital I/O ports static configuration as defined in @p board.h. | ||
24 | * This variable is used by the HAL when initializing the PAL driver. | ||
25 | */ | ||
26 | #if HAL_USE_PAL || defined(__DOXYGEN__) | ||
27 | const PALConfig pal_default_config = | ||
28 | { | ||
29 | VAL_PINSEL0, | ||
30 | VAL_PINSEL1, | ||
31 | VAL_PINSEL2, | ||
32 | {VAL_FIO0PIN, VAL_FIO0DIR}, | ||
33 | {VAL_FIO1PIN, VAL_FIO1DIR} | ||
34 | }; | ||
35 | #endif | ||
36 | |||
37 | /* | ||
38 | * Timer 0 IRQ handling here. | ||
39 | */ | ||
40 | static CH_IRQ_HANDLER(T0IrqHandler) { | ||
41 | |||
42 | CH_IRQ_PROLOGUE(); | ||
43 | T0IR = 1; /* Clear interrupt on match MR0. */ | ||
44 | |||
45 | chSysLockFromISR(); | ||
46 | chSysTimerHandlerI(); | ||
47 | chSysUnlockFromISR(); | ||
48 | |||
49 | VICVectAddr = 0; | ||
50 | CH_IRQ_EPILOGUE(); | ||
51 | } | ||
52 | |||
53 | /* | ||
54 | * Early initialization code. | ||
55 | * This initialization must be performed just after stack setup and before | ||
56 | * any other initialization. | ||
57 | */ | ||
58 | void __early_init(void) { | ||
59 | |||
60 | lpc214x_clock_init(); | ||
61 | } | ||
62 | |||
63 | #if HAL_USE_MMC_SPI | ||
64 | /* Board-related functions related to the MMC_SPI driver.*/ | ||
65 | bool mmc_lld_is_card_inserted(MMCDriver *mmcp) { | ||
66 | |||
67 | (void)mmcp; | ||
68 | return !palReadPad(IOPORT2, PB_CP1); | ||
69 | } | ||
70 | |||
71 | bool mmc_lld_is_write_protected(MMCDriver *mmcp) { | ||
72 | |||
73 | (void)mmcp; | ||
74 | return palReadPad(IOPORT2, PB_WP1); | ||
75 | } | ||
76 | #endif | ||
77 | |||
78 | /* | ||
79 | * Board-specific initialization code. | ||
80 | */ | ||
81 | void boardInit(void) { | ||
82 | |||
83 | /* | ||
84 | * System Timer initialization, 1ms intervals. | ||
85 | */ | ||
86 | SetVICVector(T0IrqHandler, 0, SOURCE_Timer0); | ||
87 | VICIntEnable = INTMASK(SOURCE_Timer0); | ||
88 | TC *timer = T0Base; | ||
89 | timer->TC_PR = VAL_TC0_PRESCALER; | ||
90 | timer->TC_MR0 = (PCLK / CH_CFG_ST_FREQUENCY) / (VAL_TC0_PRESCALER + 1); | ||
91 | timer->TC_MCR = 3; /* Interrupt and clear TC on match MR0. */ | ||
92 | timer->TC_TCR = 2; /* Reset counter and prescaler. */ | ||
93 | timer->TC_TCR = 1; /* Timer enabled. */ | ||
94 | } | ||
diff --git a/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/board.h b/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/board.h new file mode 100644 index 000000000..3fe3f4d1d --- /dev/null +++ b/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/board.h | |||
@@ -0,0 +1,92 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #ifndef _BOARD_H_ | ||
18 | #define _BOARD_H_ | ||
19 | |||
20 | /* | ||
21 | * Setup for the Olimex LPC-P2148 proto board. | ||
22 | */ | ||
23 | |||
24 | /* | ||
25 | * Board identifier. | ||
26 | */ | ||
27 | #define BOARD_OLIMEX_LPC_P2148 | ||
28 | #define BOARD_NAME "Olimex LPC-P2148" | ||
29 | |||
30 | /* | ||
31 | * The following values are implementation dependent. You may change them in | ||
32 | * order to match your HW. | ||
33 | */ | ||
34 | #define FOSC 12000000 | ||
35 | #define CCLK 48000000 | ||
36 | #define PCLK 12000000 | ||
37 | |||
38 | /* | ||
39 | * Pins configuration for Olimex LPC-P2148. | ||
40 | * | ||
41 | * PINSEL0 | ||
42 | * P0 P0 P0 P0 P0 P0 RXD TXD SSE MOS MIS SCK SDA SCL RXD TXD | ||
43 | * 15 14 13 12 11 10 1 1 L0 I0 O0 0 0 0 0 0 | ||
44 | * 00 00 00 00 00 00 01 01 01 01 01 01 01 01 01 01 | ||
45 | * FIO0DIR (15...0) | ||
46 | * IN IN OUT OUT OUT OUT -- -- -- -- -- -- -- -- -- -- | ||
47 | * 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 | ||
48 | * | ||
49 | * PINSEL1 | ||
50 | * P0 AD P0 P0 -- -- AO -- VB P0 P0 P0 MOS MIS SCK P0 | ||
51 | * 31 03 29 28 -- -- UT -- US 22 21 20 I1 O1 1 16 | ||
52 | * 00 01 00 00 00 00 10 00 01 00 00 00 10 10 10 00 | ||
53 | * FIO0DIR (31...16) | ||
54 | * OUT -- OUT OUT -- -- -- -- -- OUT OUT OUT -- -- -- IN | ||
55 | * 1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 | ||
56 | * | ||
57 | * FIO1DIR (31...16) | ||
58 | * -- -- -- -- -- IN IN OUT OUT OUT OUT OUT OUT OUT OUT OUT | ||
59 | * 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 | ||
60 | */ | ||
61 | #define VAL_PINSEL0 0x00055555 | ||
62 | #define VAL_PINSEL1 0x100840A8 | ||
63 | #define VAL_PINSEL2 0x00000004 /* Do not modify */ | ||
64 | #define VAL_FIO0DIR 0xB0703C00 | ||
65 | #define VAL_FIO1DIR 0x01FF0000 | ||
66 | #define VAL_FIO0PIN 0xFFFFFFFF | ||
67 | #define VAL_FIO1PIN 0xFFFFFFFF | ||
68 | |||
69 | #define PA_LED1 10 | ||
70 | #define PA_LED2 11 | ||
71 | #define PA_BUZZ1 12 | ||
72 | #define PA_BUZZ2 13 | ||
73 | #define PA_BSL 14 | ||
74 | #define PA_BUTTON1 15 | ||
75 | #define PA_BUTTON2 16 | ||
76 | #define PA_SSEL1 20 | ||
77 | #define PA_LEDUSB 31 | ||
78 | |||
79 | #define PB_WP1 24 | ||
80 | #define PB_CP1 25 | ||
81 | |||
82 | #if !defined(_FROM_ASM_) | ||
83 | #ifdef __cplusplus | ||
84 | extern "C" { | ||
85 | #endif | ||
86 | void boardInit(void); | ||
87 | #ifdef __cplusplus | ||
88 | } | ||
89 | #endif | ||
90 | #endif /* _FROM_ASM_ */ | ||
91 | |||
92 | #endif /* _BOARD_H_ */ | ||
diff --git a/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/board.mk b/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/board.mk new file mode 100644 index 000000000..4ac25257e --- /dev/null +++ b/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/board.mk | |||
@@ -0,0 +1,9 @@ | |||
1 | # List of all the mandatory board related files. | ||
2 | BOARDSRC = ${CHIBIOS}/os/hal/boards/OLIMEX_LPC_P2148/board.c | ||
3 | |||
4 | # Required include directories | ||
5 | BOARDINC = ${CHIBIOS}/os/hal/boards/OLIMEX_LPC_P2148 | ||
6 | |||
7 | # Shared variables | ||
8 | ALLCSRC += $(BOARDSRC) | ||
9 | ALLINC += $(BOARDINC) | ||
diff --git a/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/buzzer.c b/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/buzzer.c new file mode 100644 index 000000000..165bd7a1e --- /dev/null +++ b/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/buzzer.c | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /* | ||
18 | * Buzzer driver for Olimex LPC-P2148. | ||
19 | * Uses the timer 1 for wave generation and a Virtual Timer for the sound | ||
20 | * duration. | ||
21 | * The driver also generates an event when the sound is done and the buzzer | ||
22 | * goes silent. | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | #include "buzzer.h" | ||
28 | |||
29 | EventSource BuzzerSilentEventSource; | ||
30 | |||
31 | #define StartCounter(t) ((t)->TC_EMR = 0xF1, (t)->TC_TCR = 1) | ||
32 | #define StopCounter(t) ((t)->TC_EMR = 0, (t)->TC_TCR = 2) | ||
33 | |||
34 | /** | ||
35 | * @brief Buzzer driver initialization. | ||
36 | */ | ||
37 | void buzzInit(void) { | ||
38 | |||
39 | chEvtInit(&BuzzerSilentEventSource); | ||
40 | |||
41 | /* | ||
42 | * Switches P0.12 and P0.13 to MAT1.0 and MAT1.1 functions. | ||
43 | * Enables Timer1 clock. | ||
44 | */ | ||
45 | PINSEL0 &= 0xF0FFFFFF; | ||
46 | PINSEL0 |= 0x0A000000; | ||
47 | PCONP = (PCONP & PCALL) | PCTIM1; | ||
48 | |||
49 | /* | ||
50 | * Timer setup. | ||
51 | */ | ||
52 | TC *tc = T1Base; | ||
53 | StopCounter(tc); | ||
54 | tc->TC_CTCR = 0; /* Clock source is PCLK. */ | ||
55 | tc->TC_PR = 0; /* Prescaler disabled. */ | ||
56 | tc->TC_MCR = 2; /* Clear TC on match MR0. */ | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | * @brief Stops the sound. | ||
61 | * | ||
62 | * @param[in] p pointer to the timer | ||
63 | */ | ||
64 | static void stop(void *p) { | ||
65 | |||
66 | StopCounter((TC *)p); | ||
67 | chSysLockFromIsr(); | ||
68 | chEvtBroadcastI(&BuzzerSilentEventSource); | ||
69 | chSysUnlockFromIsr(); | ||
70 | } | ||
71 | |||
72 | /** | ||
73 | * @brief Plays a tone asynchronously. | ||
74 | * | ||
75 | * @param[in] freq approximated tone frequency | ||
76 | * @param[in] duration tone duration in systicks | ||
77 | */ | ||
78 | void buzzPlay(uint32_t freq, systime_t duration) { | ||
79 | static VirtualTimer bvt; | ||
80 | TC *tc = T1Base; | ||
81 | |||
82 | chSysLock(); | ||
83 | |||
84 | if (chVTIsArmedI(&bvt)) { /* If a sound is already being */ | ||
85 | chVTResetI(&bvt); /* played then aborts it. */ | ||
86 | StopCounter(tc); | ||
87 | } | ||
88 | |||
89 | tc->TC_MR0 = tc->TC_MR1 = (PCLK / (freq * 2)); | ||
90 | StartCounter(tc); | ||
91 | chVTSetI(&bvt, duration, stop, tc); | ||
92 | |||
93 | chSysUnlock(); | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * @brief Plays a tone. | ||
98 | * | ||
99 | * @param[in] freq approximated tone frequency | ||
100 | * @param[in] duration tone duration in systicks | ||
101 | */ | ||
102 | void buzzPlayWait(uint32_t freq, systime_t duration) { | ||
103 | TC *tc = T1Base; | ||
104 | |||
105 | StopCounter(tc); | ||
106 | tc->TC_MR0 = tc->TC_MR1 = (PCLK / (freq * 2)); | ||
107 | StartCounter(tc); | ||
108 | chThdSleep(duration); | ||
109 | StopCounter(tc); | ||
110 | } | ||
diff --git a/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/buzzer.h b/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/buzzer.h new file mode 100644 index 000000000..998d31feb --- /dev/null +++ b/lib/chibios/os/hal/boards/OLIMEX_LPC_P2148/buzzer.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #ifndef _BUZZER_H_ | ||
18 | #define _BUZZER_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | void buzzInit(void); | ||
24 | void buzzPlay(uint32_t freq, systime_t duration); | ||
25 | void buzzPlayWait(uint32_t freq, systime_t duration); | ||
26 | #ifdef __cplusplus | ||
27 | } | ||
28 | #endif | ||
29 | |||
30 | extern EventSource BuzzerSilentEventSource; | ||
31 | |||
32 | #endif /* _BUZZER_H_ */ | ||