修订版 | 1896 (tree) |
---|---|
时间 | 2010-04-30 00:57:42 |
作者 | lbednarz |
ready for merge
@@ -1,6 +1,6 @@ | ||
1 | 1 | |
2 | -#include <ch.h> | |
3 | -#include <hal.h> | |
2 | +#include "ch.h" | |
3 | +#include "hal.h" | |
4 | 4 | |
5 | 5 | #include "board.h" |
6 | 6 |
@@ -15,6 +15,7 @@ | ||
15 | 15 | chSysUnlockFromIsr(); |
16 | 16 | |
17 | 17 | sim->timer.TER1 |= mcf5206e_TIMER_TER_REF; |
18 | + | |
18 | 19 | CH_IRQ_EPILOGUE(); |
19 | 20 | } |
20 | 21 |
@@ -31,12 +32,12 @@ | ||
31 | 32 | /* |
32 | 33 | * PAL initialization. |
33 | 34 | */ |
34 | -// palClearPad(IOPORT1, PIO_LED); | |
35 | - palSetPad(IOPORT1, PIO_LED); | |
36 | - palSetPadMode(IOPORT1, PIO_LED, PAL_MODE_OUTPUT_PUSHPULL); | |
35 | +// palClearPad(IOPORT1, GPIO_LED); | |
36 | + palSetPad(IOPORT1, GPIO_LED); | |
37 | + palSetPadMode(IOPORT1, GPIO_LED, PAL_MODE_OUTPUT_PUSHPULL); | |
37 | 38 | |
38 | 39 | /* |
39 | - * Disable interrupts. | |
40 | + * Disable interrupts from SIM. | |
40 | 41 | */ |
41 | 42 | sim->sim.IMR = 0xFFFF; |
42 | 43 |
@@ -44,21 +45,21 @@ | ||
44 | 45 | * Timer 1 setup. |
45 | 46 | */ |
46 | 47 | sim->timer.TMR1 = 0; // disable timer |
47 | - *(volatile uint32_t *)0x30000074 = (uint32_t)SYSIrqHandler; | |
48 | - sim->sim.ICR9 = mcf5206e_SIM_ICR_AVEC| | |
49 | - mcf5206e_SIM_ICR_IL(5)| | |
50 | - mcf5206e_SIM_ICR_IP(3); | |
48 | + *(volatile uint32_t *)(VBR+0x74) = (uint32_t)SYSIrqHandler; | |
49 | + sim->sim.ICR9 = mcf5206e_SIM_ICR_AVEC| | |
50 | + mcf5206e_SIM_ICR_IL(5)| | |
51 | + mcf5206e_SIM_ICR_IP(3); | |
51 | 52 | |
52 | - sim->timer.TCN1 = 0; | |
53 | - sim->timer.TRR1 = 200000L/CH_FREQUENCY; // period = 200 / 200000 = 0.001s | |
54 | - sim->timer.TER1 = 0xFF; | |
55 | - sim->timer.TMR1 = mcf5206e_TIMER_TMR_PS(250-1)| // prescaler: 50MHz/250=200kHz | |
56 | - mcf5206e_TIMER_TMR_CE_NONE| // disable interrupt on capture event | |
57 | - mcf5206e_TIMER_TMR_ORI| // enable interrupt upon reaching the reference value (trr) | |
58 | - mcf5206e_TIMER_TMR_FRR| // timer count is reset immediately after reaching the reference value | |
59 | - mcf5206e_TIMER_TMR_CLK_MSCLK| // input clock source is F_CPU | |
60 | - mcf5206e_TIMER_TMR_RST; // enable timer | |
61 | - sim->sim.IMR &= ~mcf5206e_SIM_IMR_T1; // enable timer interrupt | |
53 | + sim->timer.TCN1 = 0; | |
54 | + sim->timer.TRR1 = 200000L/CH_FREQUENCY; // period = 200 / 200000 = 0.001s | |
55 | + sim->timer.TER1 = 0xFF; | |
56 | + sim->timer.TMR1 = mcf5206e_TIMER_TMR_PS(250-1)| // prescaler: 50MHz/250=200kHz | |
57 | + mcf5206e_TIMER_TMR_CE_NONE| // disable interrupt on capture event | |
58 | + mcf5206e_TIMER_TMR_ORI| // enable interrupt upon reaching the reference value (trr) | |
59 | + mcf5206e_TIMER_TMR_FRR| // timer count is reset immediately after reaching the reference value | |
60 | + mcf5206e_TIMER_TMR_CLK_MSCLK| // input clock source is F_CPU | |
61 | + mcf5206e_TIMER_TMR_RST; // enable timer | |
62 | + sim->sim.IMR &= ~mcf5206e_SIM_IMR_T1; // enable timer interrupt | |
62 | 63 | |
63 | 64 | /* |
64 | 65 | * Other initializations. |
@@ -31,26 +31,27 @@ | ||
31 | 31 | |
32 | 32 | #define BOARD_MY_COLDFIRE |
33 | 33 | |
34 | -#define MBAR 0x10000000 | |
34 | +#define MBAR 0x10000000 | |
35 | +#define VBR 0x30000000 | |
35 | 36 | |
36 | -#define _BV(x) (1<<x) | |
37 | +#define _BV(x) (1<<x) | |
37 | 38 | |
38 | -#define bitLED 0 | |
39 | +//#define bitLED 0 | |
39 | 40 | |
40 | -#define LEDOn() sim->pp.PPDAT &= ~_BV(bitLED) | |
41 | -#define LEDOff() sim->pp.PPDAT |= _BV(bitLED) | |
41 | +//#define LEDOn() sim->pp.PPDAT &= ~_BV(bitLED) | |
42 | +//#define LEDOff() sim->pp.PPDAT |= _BV(bitLED) | |
42 | 43 | |
43 | 44 | /* |
44 | 45 | * Initial I/O setup. |
45 | 46 | */ |
46 | -#define VAL_PIO_OUT 0x00 /* Output data. */ | |
47 | -#define VAL_PIO_DIR 0x01 /* Direction. */ | |
47 | +#define VAL_GPIO_OUT 0x00 /* Output data. */ | |
48 | +#define VAL_GPIO_DIR 0x01 /* Direction. */ | |
48 | 49 | |
49 | 50 | /* |
50 | 51 | * I/O definitions. |
51 | 52 | */ |
52 | -#define PIO_LED 0 | |
53 | -#define PIO_LED_MASK (1<<PIO_LED) | |
53 | +#define GPIO_LED 0 | |
54 | +#define GPIO_LED_MASK (1<<GPIO_LED) | |
54 | 55 | |
55 | 56 | extern volatile mcf5206e_IMM *sim; |
56 | 57 |
@@ -12,13 +12,13 @@ | ||
12 | 12 | mcf5206e_UART_UMR1_PM_NONE|mcf5206e_UART_UMR1_BC_8 |
13 | 13 | }; |
14 | 14 | |
15 | -static WORKING_AREA(waThread1, 64); | |
16 | -static msg_t Thread1(void *arg) { | |
15 | +static WORKING_AREA(waBlinker, 64); | |
16 | +static msg_t blinker_thread(void *arg) { | |
17 | 17 | |
18 | 18 | while (TRUE) { |
19 | - palClearPad(IOPORT1, PIO_LED); | |
19 | + palClearPad(IOPORT1, GPIO_LED); | |
20 | 20 | chThdSleepMilliseconds(100); |
21 | - palSetPad(IOPORT1, PIO_LED); | |
21 | + palSetPad(IOPORT1, GPIO_LED); | |
22 | 22 | chThdSleepMilliseconds(900); |
23 | 23 | } |
24 | 24 | return 0; |
@@ -36,7 +36,7 @@ | ||
36 | 36 | /* |
37 | 37 | * Creates the blinker thread. |
38 | 38 | */ |
39 | - chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); | |
39 | + chThdCreateStatic(waBlinker, sizeof(waBlinker), NORMALPRIO, blinker_thread, NULL); | |
40 | 40 | |
41 | 41 | /* |
42 | 42 | * Normal main() thread activity. |
@@ -45,19 +45,7 @@ | ||
45 | 45 | chThdSleepMilliseconds(1000); |
46 | 46 | sdWrite(&SD1, (uint8_t *)"Hello World!\r\n", 14); |
47 | 47 | TestThread(&SD1); |
48 | + } | |
48 | 49 | |
49 | - | |
50 | -/* | |
51 | - switch (chFDDGetTimeout(&COM1, 500)) | |
52 | - { | |
53 | - case '1': | |
54 | - chFDDWrite(&COM1, (uint8_t *)"Hello World!\r\n", 14); | |
55 | - break; | |
56 | - case '2': | |
57 | - TestThread(&COM1); | |
58 | - break; | |
59 | - } | |
60 | -*/ | |
61 | - } | |
62 | 50 | return 0; |
63 | 51 | } |
@@ -46,10 +46,10 @@ | ||
46 | 46 | */ |
47 | 47 | #define USE_COLDFIRE_UART1 TRUE |
48 | 48 | #define USE_COLDFIRE_UART2 FALSE |
49 | -//#define MCF5206E_UART1_PRIORITY 1 | |
50 | -//#define MCF5206E_UART2_PRIORITY 2 | |
49 | +#define COLDFIRE_UART1_PRIORITY 2 | |
50 | +#define COLDFIRE_UART2_PRIORITY 2 | |
51 | 51 | |
52 | 52 | /* |
53 | 53 | * SPI driver system settings. |
54 | 54 | */ |
55 | -//#define USE_MCF5206E_SPI1 TRUE | |
55 | +//#define USE_COLDFIRE_SPI1 TRUE |
@@ -18,9 +18,9 @@ | ||
18 | 18 | */ |
19 | 19 | |
20 | 20 | /** |
21 | - * @file templates/hal_lld.c | |
22 | - * @brief HAL Driver subsystem low level driver source template. | |
23 | - * @addtogroup HAL_LLD | |
21 | + * @file COLDFIRE/hal_lld.c | |
22 | + * @brief COLDFIRE HAL subsystem low level driver source template. | |
23 | + * @addtogroup COLDFIRE_HAL | |
24 | 24 | * @{ |
25 | 25 | */ |
26 | 26 |
@@ -39,9 +39,9 @@ | ||
39 | 39 | * @brief PAL setup. |
40 | 40 | * @details Digital I/O ports static configuration as defined in @p board.h. |
41 | 41 | */ |
42 | -const MCF5206ePIOConfig pal_default_config = | |
42 | +const MCF5206eGPIOConfig pal_default_config = | |
43 | 43 | { |
44 | - {VAL_PIO_OUT, VAL_PIO_DIR}, | |
44 | + {VAL_GPIO_OUT, VAL_GPIO_DIR}, | |
45 | 45 | }; |
46 | 46 | |
47 | 47 | /*===========================================================================*/ |
@@ -52,6 +52,15 @@ | ||
52 | 52 | /* Driver interrupt handlers. */ |
53 | 53 | /*===========================================================================*/ |
54 | 54 | |
55 | +CH_IRQ_HANDLER(SpuriousIrqHandler) { | |
56 | + | |
57 | + CH_IRQ_PROLOGUE(); | |
58 | + | |
59 | + COLDFIRE_SPURIOUS_HANDLER_HOOK(); | |
60 | + | |
61 | + CH_IRQ_EPILOGUE(); | |
62 | +} | |
63 | + | |
55 | 64 | /*===========================================================================*/ |
56 | 65 | /* Driver exported functions. */ |
57 | 66 | /*===========================================================================*/ |
@@ -61,6 +70,11 @@ | ||
61 | 70 | */ |
62 | 71 | void hal_lld_init(void) { |
63 | 72 | |
73 | + /* | |
74 | + * Spurious interrupt setup | |
75 | + */ | |
76 | + *(volatile uint32_t *)(VBR+0x60) = (uint32_t)SpuriousIrqHandler; | |
77 | + | |
64 | 78 | } |
65 | 79 | |
66 | 80 | /** @} */ |
@@ -18,9 +18,9 @@ | ||
18 | 18 | */ |
19 | 19 | |
20 | 20 | /** |
21 | - * @file templates/hal_lld.h | |
22 | - * @brief HAL subsystem low level driver header template. | |
23 | - * @addtogroup HAL_LLD | |
21 | + * @file COLDFIRE/hal_lld.h | |
22 | + * @brief COLDFIRE HAL subsystem low level driver header. | |
23 | + * @addtogroup COLDFIRE_HAL | |
24 | 24 | * @{ |
25 | 25 | */ |
26 | 26 |
@@ -38,6 +38,13 @@ | ||
38 | 38 | /* Driver pre-compile time settings. */ |
39 | 39 | /*===========================================================================*/ |
40 | 40 | |
41 | +/** | |
42 | + * @brief Default action for the spurious handler, nothing. | |
43 | + */ | |
44 | +#if !defined(COLDFIRE_SPURIOUS_HANDLER_HOOK) || defined(__DOXYGEN__) | |
45 | +#define COLDFIRE_SPURIOUS_HANDLER_HOOK() | |
46 | +#endif | |
47 | + | |
41 | 48 | /*===========================================================================*/ |
42 | 49 | /* Derived constants and error checks. */ |
43 | 50 | /*===========================================================================*/ |
@@ -18,9 +18,9 @@ | ||
18 | 18 | */ |
19 | 19 | |
20 | 20 | /** |
21 | - * @file templates/pal_lld.c | |
22 | - * @brief PAL subsystem low level driver template. | |
23 | - * @addtogroup PAL_LLD | |
21 | + * @file COLDFIRE/pal_lld.c | |
22 | + * @brief COLDFIRE GPIO low level driver template. | |
23 | + * @addtogroup COLDFIRE_LLD | |
24 | 24 | * @{ |
25 | 25 | */ |
26 | 26 |
@@ -50,12 +50,12 @@ | ||
50 | 50 | /*===========================================================================*/ |
51 | 51 | |
52 | 52 | /** |
53 | - * @brief AT91SAM7 I/O ports configuration. | |
54 | - * @details PIO registers initialization. | |
53 | + * @brief COLDFIRE GPIO ports configuration. | |
54 | + * @details GPIO registers initialization. | |
55 | 55 | * |
56 | - * @param[in] config the AT91SAM7 ports configuration | |
56 | + * @param[in] config the COLDFIRE ports configuration | |
57 | 57 | */ |
58 | -void _pal_lld_init(const MCF5206ePIOConfig *config) { | |
58 | +void _pal_lld_init(const MCF5206eGPIOConfig *config) { | |
59 | 59 | |
60 | 60 | sim->pp.PPDDR = config->P0data.dir; |
61 | 61 | sim->pp.PPDAT = config->P0data.out; |
@@ -18,9 +18,9 @@ | ||
18 | 18 | */ |
19 | 19 | |
20 | 20 | /** |
21 | - * @file templates/pal_lld.h | |
22 | - * @brief PAL subsystem low level driver header template. | |
23 | - * @addtogroup PAL_LLD | |
21 | + * @file COLDFIRE/pal_lld.h | |
22 | + * @brief COLDFIRE GPIO low level driver header. | |
23 | + * @addtogroup COLDFIRE_PAL | |
24 | 24 | * @{ |
25 | 25 | */ |
26 | 26 |
@@ -44,12 +44,12 @@ | ||
44 | 44 | /*===========================================================================*/ |
45 | 45 | |
46 | 46 | /** |
47 | - * @brief Setup registers common to all the Coldfire ports. | |
47 | + * @brief MCF5206e setup registers. | |
48 | 48 | */ |
49 | 49 | typedef struct { |
50 | 50 | uint8_t out; |
51 | 51 | uint8_t dir; |
52 | -} mcf5206e_pio_setup_t; | |
52 | +} mcf5206e_gpio_setup_t; | |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @brief Generic I/O ports static initializer. |
@@ -67,19 +67,19 @@ | ||
67 | 67 | * . |
68 | 68 | */ |
69 | 69 | typedef struct { |
70 | - mcf5206e_pio_setup_t P0data; | |
71 | -} MCF5206ePIOConfig; | |
70 | + mcf5206e_gpio_setup_t P0data; | |
71 | +} MCF5206eGPIOConfig; | |
72 | 72 | |
73 | 73 | /** |
74 | 74 | * @brief Width, in bits, of an I/O port. |
75 | 75 | */ |
76 | -#define PAL_IOPORTS_WIDTH 16 | |
76 | +#define PAL_IOPORTS_WIDTH 8 | |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @brief Whole port mask. |
80 | 80 | * @brief This macro specifies all the valid bits into a port. |
81 | 81 | */ |
82 | -#define PAL_WHOLE_PORT ((ioportmask_t)0xFFFFFFFF) | |
82 | +#define PAL_WHOLE_PORT ((ioportmask_t)0xFF) | |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * @brief Digital I/O port sized unsigned type. |
@@ -333,12 +333,12 @@ | ||
333 | 333 | */ |
334 | 334 | //#define pal_lld_setpadmode(port, pad, mode) |
335 | 335 | |
336 | -extern const MCF5206ePIOConfig pal_default_config; | |
336 | +extern const MCF5206eGPIOConfig pal_default_config; | |
337 | 337 | |
338 | 338 | #ifdef __cplusplus |
339 | 339 | extern "C" { |
340 | 340 | #endif |
341 | - void _pal_lld_init(const MCF5206ePIOConfig *config); | |
341 | + void _pal_lld_init(const MCF5206eGPIOConfig *config); | |
342 | 342 | void _pal_lld_setgroupmode(ioportid_t port, |
343 | 343 | ioportmask_t mask, |
344 | 344 | uint_fast8_t mode); |
@@ -25,7 +25,7 @@ | ||
25 | 25 | */ |
26 | 26 | |
27 | 27 | /** |
28 | - * @file ColdFire/coldfire_serial.c | |
28 | + * @file COLDFIRE/coldfire_serial.c | |
29 | 29 | * @brief ColdFire low level serial driver code. |
30 | 30 | * @addtogroup COLDFIRE_SERIAL |
31 | 31 | * @{ |
@@ -102,15 +102,16 @@ | ||
102 | 102 | sdp->uart1->UIR = mcf5206e_UART_UIMR_FFULL; |
103 | 103 | |
104 | 104 | sdp->uart1->UIR = mcf5206e_UART_UIMR_FFULL; |
105 | - *(volatile uint32_t *)0x30000078 = (uint32_t)UART1IrqHandler; | |
105 | + *(volatile uint32_t *)(VBR+0x78) = (uint32_t)UART1IrqHandler; | |
106 | 106 | sim->sim.ICR12 = mcf5206e_SIM_ICR_AVEC| |
107 | 107 | mcf5206e_SIM_ICR_IL(6)| |
108 | - mcf5206e_SIM_ICR_IP(2); | |
108 | + mcf5206e_SIM_ICR_IP(COLDFIRE_UART1_PRIORITY); | |
109 | 109 | sim->sim.IMR &= ~mcf5206e_SIM_IMR_UART1; |
110 | 110 | } |
111 | 111 | #endif |
112 | 112 | |
113 | 113 | #if USE_COLDFIRE_UART2 || defined(__DOXYGEN__) |
114 | +#error CODE NOT TESTED | |
114 | 115 | if (sdp == &SD2) |
115 | 116 | { |
116 | 117 | sdp->uart2->UCR = mcf5206e_UART_UCR_RESET_TX; |
@@ -124,10 +125,10 @@ | ||
124 | 125 | sdp->uart2->UIR = mcf5206e_UART_UIMR_FFULL; |
125 | 126 | |
126 | 127 | sdp->uart2->UIR = mcf5206e_UART_UIMR_FFULL; |
127 | -// *(volatile uint32_t *)0x30000078 = (uint32_t)UART2IrqHandler; | |
128 | -// sim->sim.ICR12 = mcf5206e_SIM_ICR_AVEC| | |
129 | -// mcf5206e_SIM_ICR_IL(6)| | |
130 | -// mcf5206e_SIM_ICR_IP(2); | |
128 | +// *(volatile uint32_t *)(VBR+0x70) = (uint32_t)UART2IrqHandler; | |
129 | +// sim->sim.ICR13 = mcf5206e_SIM_ICR_AVEC| | |
130 | +// mcf5206e_SIM_ICR_IL(4)| | |
131 | +// mcf5206e_SIM_ICR_IP(COLDFIRE_UART1_PRIORITY); | |
131 | 132 | // sim->sim.IMR &= ~mcf5206e_SIM_IMR_UART2; |
132 | 133 | } |
133 | 134 | #endif |
@@ -208,32 +209,32 @@ | ||
208 | 209 | */ |
209 | 210 | void serve_interrupt1(SerialDriver *sdp) |
210 | 211 | { |
211 | - uint8_t usr = sdp->uart1->USR; | |
212 | + uint8_t usr = sdp->uart1->USR; | |
212 | 213 | |
213 | -// TODO: test it | |
214 | - if (usr & (mcf5206e_UART_USR_RB | mcf5206e_UART_USR_FE | mcf5206e_UART_USR_PE | mcf5206e_UART_USR_OE)) { | |
215 | - set_error(sdp, usr); | |
214 | +// TODO: test it | |
215 | + if (usr & (mcf5206e_UART_USR_RB | mcf5206e_UART_USR_FE | mcf5206e_UART_USR_PE | mcf5206e_UART_USR_OE)) { | |
216 | + set_error(sdp, usr); | |
217 | + } | |
218 | + if (usr & mcf5206e_UART_USR_RXRDY) | |
219 | + { | |
220 | + chSysLockFromIsr(); | |
221 | + sdIncomingDataI(sdp, (uint8_t)sdp->uart1->UBUF); | |
222 | + chSysUnlockFromIsr(); | |
223 | + } | |
224 | + if (usr & mcf5206e_UART_USR_TXRDY) | |
225 | + { | |
226 | + msg_t b; | |
227 | + | |
228 | + chSysLockFromIsr(); | |
229 | + b = chOQGetI(&sdp->oqueue); | |
230 | + if (b < Q_OK) { | |
231 | + chEvtBroadcastI(&sdp->oevent); | |
232 | + sdp->uart1->UIR = mcf5206e_UART_UIMR_FFULL; | |
216 | 233 | } |
217 | - if (usr & mcf5206e_UART_USR_RXRDY) | |
218 | - { | |
219 | - chSysLockFromIsr(); | |
220 | - sdIncomingDataI(sdp, (uint8_t)sdp->uart1->UBUF); | |
221 | - chSysUnlockFromIsr(); | |
222 | - } | |
223 | - if (usr & mcf5206e_UART_USR_TXRDY) | |
224 | - { | |
225 | - msg_t b; | |
226 | - | |
227 | - chSysLockFromIsr(); | |
228 | - b = chOQGetI(&sdp->oqueue); | |
229 | - if (b < Q_OK) { | |
230 | - chEvtBroadcastI(&sdp->oevent); | |
231 | - sdp->uart1->UIR = mcf5206e_UART_UIMR_FFULL; | |
232 | - } | |
233 | - else | |
234 | - sdp->uart1->UBUF = b; | |
235 | - chSysUnlockFromIsr(); | |
236 | - } | |
234 | + else | |
235 | + sdp->uart1->UBUF = b; | |
236 | + chSysUnlockFromIsr(); | |
237 | + } | |
237 | 238 | } |
238 | 239 | |
239 | 240 | /** |
@@ -243,34 +244,34 @@ | ||
243 | 244 | */ |
244 | 245 | void serve_interrupt2(SerialDriver *sdp) |
245 | 246 | { |
246 | - uint8_t usr = sdp->uart2->USR; | |
247 | + uint8_t usr = sdp->uart2->USR; | |
247 | 248 | |
248 | 249 | /* |
249 | 250 | TODO: test it |
250 | 251 | if (usr & (mcf5206e_UART_USR_RB | mcf5206e_UART_USR_FE | mcf5206e_UART_USR_PE | mcf5206e_UART_USR_OE)) { |
251 | - SetError(usr, com); | |
252 | + set_error(sdp, usr); | |
252 | 253 | } |
253 | 254 | */ |
254 | - if (usr & mcf5206e_UART_USR_RXRDY) | |
255 | - { | |
256 | - chSysLockFromIsr(); | |
257 | - sdIncomingDataI(sdp, (uint8_t)sdp->uart2->UBUF); | |
258 | - chSysUnlockFromIsr(); | |
259 | - } | |
260 | - if (usr & mcf5206e_UART_USR_TXRDY) | |
261 | - { | |
262 | - msg_t b; | |
255 | + if (usr & mcf5206e_UART_USR_RXRDY) | |
256 | + { | |
257 | + chSysLockFromIsr(); | |
258 | + sdIncomingDataI(sdp, (uint8_t)sdp->uart2->UBUF); | |
259 | + chSysUnlockFromIsr(); | |
260 | + } | |
261 | + if (usr & mcf5206e_UART_USR_TXRDY) | |
262 | + { | |
263 | + msg_t b; | |
263 | 264 | |
264 | - chSysLockFromIsr(); | |
265 | - b = chOQGetI(&sdp->oqueue); | |
266 | - if (b < Q_OK) { | |
267 | - chEvtBroadcastI(&sdp->oevent); | |
268 | - sdp->uart2->UIR = mcf5206e_UART_UIMR_FFULL; | |
269 | - } | |
270 | - else | |
271 | - sdp->uart2->UBUF = b; | |
272 | - chSysUnlockFromIsr(); | |
273 | - } | |
265 | + chSysLockFromIsr(); | |
266 | + b = chOQGetI(&sdp->oqueue); | |
267 | + if (b < Q_OK) { | |
268 | + chEvtBroadcastI(&sdp->oevent); | |
269 | + sdp->uart2->UIR = mcf5206e_UART_UIMR_FFULL; | |
270 | + } | |
271 | + else | |
272 | + sdp->uart2->UBUF = b; | |
273 | + chSysUnlockFromIsr(); | |
274 | + } | |
274 | 275 | } |
275 | 276 | |
276 | 277 | /*===========================================================================*/ |
@@ -332,43 +333,6 @@ | ||
332 | 333 | if (sdp->state == SD_STOP) { |
333 | 334 | uart_init(sdp); |
334 | 335 | } |
335 | -/* | |
336 | - if (sdp->state == SD_STOP) { | |
337 | -#if USE_STM32_USART1 | |
338 | - if (&SD1 == sdp) { | |
339 | - RCC->APB2ENR |= RCC_APB2ENR_USART1EN; | |
340 | - NVICEnableVector(USART1_IRQn, STM32_USART1_PRIORITY); | |
341 | - } | |
342 | -#endif | |
343 | -#if USE_STM32_USART2 | |
344 | - if (&SD2 == sdp) { | |
345 | - RCC->APB1ENR |= RCC_APB1ENR_USART2EN; | |
346 | - NVICEnableVector(USART2_IRQn, STM32_USART2_PRIORITY); | |
347 | - } | |
348 | -#endif | |
349 | -#if USE_STM32_USART3 | |
350 | - if (&SD3 == sdp) { | |
351 | - RCC->APB1ENR |= RCC_APB1ENR_USART3EN; | |
352 | - NVICEnableVector(USART3_IRQn, STM32_USART3_PRIORITY); | |
353 | - } | |
354 | -#endif | |
355 | -#if defined(STM32F10X_HD) || defined(STM32F10X_CL) | |
356 | -#if USE_STM32_UART4 | |
357 | - if (&SD4 == sdp) { | |
358 | - RCC->APB1ENR |= RCC_APB1ENR_UART4EN; | |
359 | - NVICEnableVector(UART4_IRQn, STM32_UART4_PRIORITY); | |
360 | - } | |
361 | -#endif | |
362 | -#if USE_STM32_UART5 | |
363 | - if (&SD5 == sdp) { | |
364 | - RCC->APB1ENR |= RCC_APB1ENR_UART5EN; | |
365 | - NVICEnableVector(UART5_IRQn, STM32_UART5_PRIORITY); | |
366 | - } | |
367 | -#endif | |
368 | -#endif | |
369 | - } | |
370 | -*/ | |
371 | -// uart_init(sdp); | |
372 | 336 | } |
373 | 337 | |
374 | 338 | /** |
@@ -382,22 +346,6 @@ | ||
382 | 346 | |
383 | 347 | if (sdp->state == SD_READY) { |
384 | 348 | uart_deinit(sdp); |
385 | -/* | |
386 | -#if USE_STM32_USART1 | |
387 | - if (&SD1 == sdp) { | |
388 | - RCC->APB2ENR &= ~RCC_APB2ENR_USART1EN; | |
389 | - NVICDisableVector(USART1_IRQn); | |
390 | - return; | |
391 | - } | |
392 | -#endif | |
393 | -#if USE_STM32_USART2 | |
394 | - if (&SD2 == sdp) { | |
395 | - RCC->APB1ENR &= ~RCC_APB1ENR_USART2EN; | |
396 | - NVICDisableVector(USART2_IRQn); | |
397 | - return; | |
398 | - } | |
399 | -#endif | |
400 | -*/ | |
401 | 349 | } |
402 | 350 | } |
403 | 351 |
@@ -404,155 +352,3 @@ | ||
404 | 352 | #endif /* CH_HAL_USE_SERIAL */ |
405 | 353 | |
406 | 354 | /** @} */ |
407 | - | |
408 | - | |
409 | - | |
410 | - | |
411 | - | |
412 | - | |
413 | - | |
414 | - | |
415 | - | |
416 | - | |
417 | - | |
418 | - | |
419 | - | |
420 | - | |
421 | -#if 0 | |
422 | -#include <ch.h> | |
423 | -#include <signal.h> | |
424 | - | |
425 | -#include "board.h" | |
426 | -//#include "coldfire_serial.h" | |
427 | -#include "mcf5206e.h" | |
428 | - | |
429 | -//static void SetError(uint8_t usr, FullDuplexDriver *com) { | |
430 | -/* | |
431 | - TODO: test it | |
432 | - dflags_t sts = 0; | |
433 | - | |
434 | - if (usr & mcf5206e_UART_USR_OE) | |
435 | - sts |= SD_OVERRUN_ERROR; | |
436 | - if (usr & mcf5206e_UART_USR_PE) | |
437 | - sts |= SD_PARITY_ERROR; | |
438 | - if (usr & mcf5206e_UART_USR_FE) | |
439 | - sts |= SD_FRAMING_ERROR; | |
440 | - if (usr & mcf5206e_UART_USR_RB) | |
441 | - sts |= SD_BREAK_DETECTED; | |
442 | - chSysLockFromIsr(); | |
443 | - chFDDAddFlagsI(com, sts); | |
444 | - chSysUnlockFromIsr(); | |
445 | -*/ | |
446 | -//} | |
447 | - | |
448 | -#if USE_COLDFIRE_USART0 || defined(__DOXYGEN__) | |
449 | - | |
450 | -/** @brief USART0 serial driver identifier.*/ | |
451 | -FullDuplexDriver COM1; | |
452 | - | |
453 | -static uint8_t ib1[SERIAL_BUFFERS_SIZE]; | |
454 | -static uint8_t ob1[SERIAL_BUFFERS_SIZE]; | |
455 | - | |
456 | - | |
457 | -void ServeInterrupt(mcf5206e_UART1 *u, FullDuplexDriver *com) | |
458 | -{ | |
459 | - uint8_t usr = u->USR; | |
460 | - | |
461 | -/* | |
462 | - TODO: test it | |
463 | - if (usr & (mcf5206e_UART_USR_RB | mcf5206e_UART_USR_FE | mcf5206e_UART_USR_PE | mcf5206e_UART_USR_OE)) { | |
464 | - SetError(usr, com); | |
465 | - } | |
466 | -*/ | |
467 | - if (usr & mcf5206e_UART_USR_RXRDY) | |
468 | - { | |
469 | - chSysLockFromIsr(); | |
470 | - chFDDIncomingDataI(com, u->UBUF); | |
471 | - chSysUnlockFromIsr(); | |
472 | - } | |
473 | - if (usr & mcf5206e_UART_USR_TXRDY) | |
474 | - { | |
475 | - chSysLockFromIsr(); | |
476 | - msg_t b = chFDDRequestDataI(com); | |
477 | - chSysUnlockFromIsr(); | |
478 | - if (b < Q_OK) { | |
479 | - u->UIR = mcf5206e_UART_UIMR_FFULL; | |
480 | - } else { | |
481 | - u->UBUF = b; | |
482 | - } | |
483 | - } | |
484 | -} | |
485 | - | |
486 | - | |
487 | -CH_IRQ_HANDLER(UARTIrqHandler) { | |
488 | - | |
489 | - CH_IRQ_PROLOGUE(); | |
490 | - | |
491 | - ServeInterrupt((mcf5206e_UART1 *)&sim->uart1, &COM1); | |
492 | - | |
493 | - CH_IRQ_EPILOGUE(); | |
494 | -} | |
495 | - | |
496 | - | |
497 | -static void OutNotify1(void) { | |
498 | - | |
499 | - sim->uart1.UIR = mcf5206e_UART_UIMR_FFULL | mcf5206e_UART_UIMR_TXRDY; | |
500 | -} | |
501 | - | |
502 | -/** | |
503 | - * @brief USART0 setup. | |
504 | - * @details This function must be invoked with interrupts disabled. | |
505 | - * @param div The divider value as calculated by the @p UBR() macro. | |
506 | - * @param mod The value for the @p U0MCTL register. | |
507 | - * @param ctl The value for the @p U0CTL register. | |
508 | - * @note Does not reset the I/O queues. | |
509 | - */ | |
510 | -void usart0_setup(uint32_t baud) { | |
511 | - uint32_t b; | |
512 | - | |
513 | - b = F_CPU*10/32L; | |
514 | - if (baud) | |
515 | - b /= baud; | |
516 | - if ((b % 10) >= 5) | |
517 | - b += 10; | |
518 | - | |
519 | - sim->uart1.UCR = mcf5206e_UART_UCR_RESET_TX; | |
520 | - sim->uart1.UCR = mcf5206e_UART_UCR_RESET_RX; | |
521 | - sim->uart1.UCR = mcf5206e_UART_UCR_RESET_MR; | |
522 | - sim->uart1.UBG1 = (b/10)>>8; | |
523 | - sim->uart1.UBG2 = (b/10)&0xFF; | |
524 | - sim->uart1.USR = mcf5206e_UART_UCSR_RX_TIMER|mcf5206e_UART_UCSR_TX_TIMER; | |
525 | - sim->uart1.UMR = mcf5206e_UART_UMR1_PM_NONE|mcf5206e_UART_UMR1_BC_8; | |
526 | - sim->uart1.UCR = mcf5206e_UART_UCR_TX_ENABLED|mcf5206e_UART_UCR_RX_ENABLED; | |
527 | - sim->uart1.UIR = mcf5206e_UART_UIMR_FFULL; | |
528 | - | |
529 | - sim->uart1.UIR = mcf5206e_UART_UIMR_FFULL; | |
530 | - *(volatile uint32_t *)0x78 = (uint32_t)UARTIrqHandler; | |
531 | - sim->sim.ICR12 = mcf5206e_SIM_ICR_AVEC| | |
532 | - mcf5206e_SIM_ICR_IL(6)| | |
533 | - mcf5206e_SIM_ICR_IP(2); | |
534 | - sim->sim.IMR &= ~mcf5206e_SIM_IMR_UART1; | |
535 | -} | |
536 | -#endif /* USE_COLDFIRE_USART0 */ | |
537 | - | |
538 | -#if USE_COLDFIRE_USART1 || defined(__DOXYGEN__) | |
539 | -#endif | |
540 | - | |
541 | -/** | |
542 | - * @brief Serial driver initialization. | |
543 | - * @note The serial ports are initialized at @p 57600-8-N-1 by default. | |
544 | - */ | |
545 | -void serial_init(void) { | |
546 | - | |
547 | - /* I/O queues setup.*/ | |
548 | -#if USE_COLDFIRE_USART0 | |
549 | - chFDDInit(&COM1, ib1, sizeof ib1, NULL, ob1, sizeof ob1, OutNotify1); | |
550 | - usart0_setup(DEFAULT_USART_BITRATE); | |
551 | -#endif | |
552 | - | |
553 | -#if USE_COLDFIRE_USART1 | |
554 | -#endif | |
555 | -} | |
556 | - | |
557 | -/** @} */ | |
558 | -#endif |
@@ -25,7 +25,7 @@ | ||
25 | 25 | */ |
26 | 26 | |
27 | 27 | /** |
28 | - * @file ColdFire/serial_lld.h | |
28 | + * @file COLDFIRE/serial_lld.h | |
29 | 29 | * @brief COLDFIRE low level serial driver header. |
30 | 30 | * @addtogroup COLDFIRE_SERIAL |
31 | 31 | * @{ |
@@ -82,7 +82,7 @@ | ||
82 | 82 | */ |
83 | 83 | typedef struct { |
84 | 84 | /** |
85 | - * @brief Initialization value for the UBG register. | |
85 | + * @brief Bit rate. | |
86 | 86 | */ |
87 | 87 | uint32_t sc_speed; |
88 | 88 | /** |
@@ -97,6 +97,7 @@ | ||
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @brief @p SerialDriver specific data. |
100 | + * @note Structure mcf5206e_UART1 differs from mcf5206e_UART2 !!!. | |
100 | 101 | */ |
101 | 102 | #define _serial_driver_data \ |
102 | 103 | _base_asynchronous_channel_data \ |
@@ -117,7 +118,7 @@ | ||
117 | 118 | /* Output circular buffer.*/ \ |
118 | 119 | uint8_t ob[SERIAL_BUFFERS_SIZE]; \ |
119 | 120 | /* End of the mandatory fields.*/ \ |
120 | - /* Pointer to the USART registers block.*/ \ | |
121 | + /* Pointers to the UART registers blocks.*/ \ | |
121 | 122 | mcf5206e_UART1 *uart1; \ |
122 | 123 | mcf5206e_UART2 *uart2; |
123 | 124 |
@@ -137,7 +138,6 @@ | ||
137 | 138 | #if USE_COLDFIRE_UART2 |
138 | 139 | extern SerialDriver SD2; |
139 | 140 | #endif |
140 | -#endif | |
141 | 141 | |
142 | 142 | #ifdef __cplusplus |
143 | 143 | extern "C" { |
@@ -150,6 +150,8 @@ | ||
150 | 150 | #endif |
151 | 151 | /** @endcond*/ |
152 | 152 | |
153 | +#endif /* CH_HAL_USE_SERIAL */ | |
154 | + | |
153 | 155 | #endif /* _SERIAL_LLD_H_ */ |
154 | 156 | |
155 | 157 | /** @} */ |
@@ -56,6 +56,7 @@ | ||
56 | 56 | * @brief Interrupt saved context. |
57 | 57 | * @details This structure represents the stack frame saved during a |
58 | 58 | * preemption-capable interrupt handler. |
59 | + * @note Checked for O2 and Os optimizations only. | |
59 | 60 | */ |
60 | 61 | struct extctx { |
61 | 62 | uint32_t d0; |
@@ -102,6 +103,7 @@ | ||
102 | 103 | * @brief Platform dependent part of the @p chThdInit() API. |
103 | 104 | * @details This code usually setup the context switching frame represented |
104 | 105 | * by an @p intctx structure. |
106 | + * @note Initial values for registers d2-d7 and a3-a4 are for test purposes only. | |
105 | 107 | */ |
106 | 108 | #define SETUP_CONTEXT(workspace, wsize, pf, arg) { \ |
107 | 109 | tp->p_ctx.sp = (struct intctx *)((uint8_t *)workspace + \ |
@@ -20,12 +20,12 @@ | ||
20 | 20 | */ |
21 | 21 | movel #__ram_end__, %a7 |
22 | 22 | |
23 | - | |
23 | +/* enable cache */ | |
24 | 24 | movel #0x01000000, %d0 |
25 | 25 | movec %d0, %CACR |
26 | 26 | movel #0x80000100, %d0 |
27 | 27 | movec %d0, %CACR |
28 | - | |
28 | +/* init bss section */ | |
29 | 29 | movel #__bss_start,%d1 |
30 | 30 | movel #__bss_end, %d0 |
31 | 31 | cmpl %d0, %d1 |
@@ -36,7 +36,7 @@ | ||
36 | 36 | 1: clrb (%a0)+ |
37 | 37 | subql #1, %d0 |
38 | 38 | bpl 1b |
39 | - | |
39 | +/* init data section */ | |
40 | 40 | 2: lea _etext,%a1 |
41 | 41 | lea _data,%a0 |
42 | 42 | cmpl %a0,%a1 |
@@ -49,7 +49,7 @@ | ||
49 | 49 | cmpl %d0,%a0 |
50 | 50 | bcs.s COPYLOOP |
51 | 51 | NOCOPY: |
52 | - | |
52 | +/* init hardware */ | |
53 | 53 | jsr hwinit |
54 | 54 | |
55 | 55 | /* |
@@ -56,6 +56,7 @@ | ||
56 | 56 | TODO: Insert ctors init here. |
57 | 57 | */ |
58 | 58 | |
59 | +/* enable global interrupts */ | |
59 | 60 | move #0x2000, %sr |
60 | 61 | jsr main |
61 | 62 | rts |