aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms/SPC5xx/LINFlex_v1/serial_lld.c
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/platforms/SPC5xx/LINFlex_v1/serial_lld.c')
-rw-r--r--os/hal/platforms/SPC5xx/LINFlex_v1/serial_lld.c231
1 files changed, 135 insertions, 96 deletions
diff --git a/os/hal/platforms/SPC5xx/LINFlex_v1/serial_lld.c b/os/hal/platforms/SPC5xx/LINFlex_v1/serial_lld.c
index e562b6c2d..077d61b06 100644
--- a/os/hal/platforms/SPC5xx/LINFlex_v1/serial_lld.c
+++ b/os/hal/platforms/SPC5xx/LINFlex_v1/serial_lld.c
@@ -19,8 +19,8 @@
*/
/**
- * @file SPC56x/serial_lld.c
- * @brief SPC563 low level serial driver code.
+ * @file SPC5xx/serial_lld.c
+ * @brief SPC5xx low level serial driver code.
*
* @addtogroup SERIAL
* @{
@@ -36,19 +36,33 @@
/*===========================================================================*/
/**
- * @brief eSCI-A serial driver identifier.
+ * @brief LIINFlex-0 serial driver identifier.
*/
-#if USE_SPC563_ESCIA || defined(__DOXYGEN__)
+#if SPC5_SERIAL_USE_LINFLEX0 || defined(__DOXYGEN__)
SerialDriver SD1;
#endif
/**
- * @brief eSCI-B serial driver identifier.
+ * @brief LIINFlex-1 serial driver identifier.
*/
-#if USE_SPC563_ESCIB || defined(__DOXYGEN__)
+#if SPC5_SERIAL_USE_LINFLEX1 || defined(__DOXYGEN__)
SerialDriver SD2;
#endif
+/**
+ * @brief LIINFlex-2 serial driver identifier.
+ */
+#if SPC5_SERIAL_USE_LINFLEX2 || defined(__DOXYGEN__)
+SerialDriver SD3;
+#endif
+
+/**
+ * @brief LIINFlex-3 serial driver identifier.
+ */
+#if SPC5_SERIAL_USE_LINFLEX3 || defined(__DOXYGEN__)
+SerialDriver SD4;
+#endif
+
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
@@ -58,7 +72,7 @@ SerialDriver SD2;
*/
static const SerialConfig default_config = {
SERIAL_DEFAULT_BITRATE,
- SD_MODE_NORMAL | SD_MODE_PARITY_NONE
+ 0
};
/*===========================================================================*/
@@ -66,48 +80,36 @@ static const SerialConfig default_config = {
/*===========================================================================*/
/**
- * @brief eSCI initialization.
+ * @brief LINFlex initialization.
* @details This function must be invoked with interrupts disabled.
*
* @param[in] sdp pointer to a @p SerialDriver object
* @param[in] config the architecture-dependent serial driver configuration
*/
-static void esci_init(SerialDriver *sdp, const SerialConfig *config) {
- volatile struct ESCI_tag *escip = sdp->escip;
- uint8_t mode = config->sc_mode;
-
- escip->CR2.R = 0; /* MDIS off. */
- escip->CR1.R = 0;
- escip->LCR.R = 0;
- escip->CR1.B.SBR = SPC563_SYSCLK / (16 * config->sc_speed);
- if (mode & SD_MODE_LOOPBACK)
- escip->CR1.B.LOOPS = 1;
- switch (mode & SD_MODE_PARITY) {
- case SD_MODE_PARITY_ODD:
- escip->CR1.B.PT = 1;
- case SD_MODE_PARITY_EVEN:
- escip->CR1.B.PE = 1;
- escip->CR1.B.M = 1; /* Makes it 8 bits data + 1 bit parity. */
- default:
- ;
- }
- escip->LPR.R = 0;
- escip->CR1.R |= 0x0000002C; /* RIE, TE, RE to 1. */
- escip->CR2.R |= 0x000F; /* ORIE, NFIE, FEIE, PFIE to 1. */
+static void spc5_linflex_init(SerialDriver *sdp, const SerialConfig *config) {
+ volatile struct LINFLEX_tag *linflexp = sdp->linflexp;
+
+ linflexp->LINFBRR.R = 0; /* Fractional divider. */
+ linflexp->LINIBRR.R = 0; /* Integer divider. */
+ linflexp->UARTSR.R = 0xFFFF; /* Clearing UART status register. */
+ linflexp->UARTCR.R = config->mode | 1;/* Enforced UART mode. */
+ linflexp->LINIER.R = 0; /* Interrupts enabled. */
}
/**
- * @brief eSCI de-initialization.
+ * @brief LINFlex de-initialization.
* @details This function must be invoked with interrupts disabled.
*
- * @param[in] escip pointer to an eSCI I/O block
+ * @param[in] linflexp pointer to a LINFlex I/O block
*/
-static void esci_deinit(volatile struct ESCI_tag *escip) {
+static void spc5_linflex_deinit(volatile struct LINFLEX_tag *linflexp) {
+#if 0
escip->LPR.R = 0;
escip->SR.R = 0xFFFFFFFF;
escip->CR1.R = 0;
escip->CR2.R = 0x8000; /* MDIS on. */
+#endif
}
/**
@@ -119,6 +121,7 @@ static void esci_deinit(volatile struct ESCI_tag *escip) {
static void set_error(SerialDriver *sdp, uint32_t sr) {
flagsmask_t sts = 0;
+#if 0
if (sr & 0x08000000)
sts |= SD_OVERRUN_ERROR;
if (sr & 0x04000000)
@@ -129,71 +132,47 @@ static void set_error(SerialDriver *sdp, uint32_t sr) {
sts |= SD_PARITY_ERROR;
/* if (sr & 0x00000000)
sts |= SD_BREAK_DETECTED;*/
+#endif
chSysLockFromIsr();
chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
/**
- * @brief Common IRQ handler.
+ * @brief Common RXI IRQ handler.
*
* @param[in] sdp pointer to a @p SerialDriver object
*/
-static void serve_interrupt(SerialDriver *sdp) {
- volatile struct ESCI_tag *escip = sdp->escip;
-
- uint32_t sr = escip->SR.R;
- escip->SR.R = 0x3FFFFFFF; /* Does not clear TDRE | TC.*/
- if (sr & 0x0F000000) /* OR | NF | FE | PF. */
- set_error(sdp, sr);
- if (sr & 0x20000000) { /* RDRF. */
- chSysLockFromIsr();
- sdIncomingDataI(sdp, escip->DR.B.D);
- chSysUnlockFromIsr();
- }
- if (escip->CR1.B.TIE && (sr & 0x80000000)) { /* TDRE. */
- msg_t b;
- chSysLockFromIsr();
- b = chOQGetI(&sdp->oqueue);
- if (b < Q_OK) {
- chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
- escip->CR1.B.TIE = 0;
- }
- else {
- ESCI_A.SR.B.TDRE = 1;
- escip->DR.R = (uint16_t)b;
- }
- chSysUnlockFromIsr();
- }
+static void spc5xx_serve_rxi_interrupt(SerialDriver *sdp) {
}
-#if USE_SPC563_ESCIA || defined(__DOXYGEN__)
+/**
+ * @brief Common TXI IRQ handler.
+ *
+ * @param[in] sdp pointer to a @p SerialDriver object
+ */
+static void spc5xx_serve_txi_interrupt(SerialDriver *sdp) {
+}
+
+/**
+ * @brief Common ERR IRQ handler.
+ *
+ * @param[in] sdp pointer to a @p SerialDriver object
+ */
+static void spc5xx_serve_err_interrupt(SerialDriver *sdp) {
+}
+
+#if SPC5_SERIAL_USE_LINFLEX0 || defined(__DOXYGEN__)
static void notify1(GenericQueue *qp) {
(void)qp;
- if (ESCI_A.SR.B.TDRE) {
- msg_t b = sdRequestDataI(&SD1);
- if (b != Q_EMPTY) {
- ESCI_A.SR.B.TDRE = 1;
- ESCI_A.CR1.B.TIE = 1;
- ESCI_A.DR.R = (uint16_t)b;
- }
- }
}
#endif
-#if USE_SPC563_ESCIB || defined(__DOXYGEN__)
+#if SPC5_SERIAL_USE_LINFLEX1 || defined(__DOXYGEN__)
static void notify2(GenericQueue *qp) {
(void)qp;
- if (ESCI_B.SR.B.TDRE) {
- msg_t b = sdRequestDataI(&SD2);
- if (b != Q_EMPTY) {
- ESCI_B.SR.B.TDRE = 1;
- ESCI_B.CR1.B.TIE = 1;
- ESCI_B.DR.R = (uint16_t)b;
- }
- }
}
#endif
@@ -201,33 +180,89 @@ static void notify2(GenericQueue *qp) {
/* Driver interrupt handlers. */
/*===========================================================================*/
-#if USE_SPC563_ESCIA || defined(__DOXYGEN__)
+#if SPC5_SERIAL_USE_LINFLEX0 || defined(__DOXYGEN__)
/**
- * @brief eSCI-A interrupt handler.
+ * @brief LINFlex-0 RXI interrupt handler.
*
* @isr
*/
-CH_IRQ_HANDLER(vector146) {
+CH_IRQ_HANDLER(SPC5_LINFLEX0_RXI_HANDLER) {
CH_IRQ_PROLOGUE();
- serve_interrupt(&SD1);
+ spc5xx_serve_rxi_interrupt(&SD1);
+
+ CH_IRQ_EPILOGUE();
+}
+
+/**
+ * @brief LINFlex-0 TXI interrupt handler.
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(SPC5_LINFLEX0_TXI_HANDLER) {
+
+ CH_IRQ_PROLOGUE();
+
+ spc5xx_serve_txi_interrupt(&SD1);
+
+ CH_IRQ_EPILOGUE();
+}
+
+/**
+ * @brief LINFlex-0 ERR interrupt handler.
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(SPC5_LINFLEX0_ERR_HANDLER) {
+
+ CH_IRQ_PROLOGUE();
+
+ spc5xx_serve_err_interrupt(&SD1);
CH_IRQ_EPILOGUE();
}
#endif
-#if USE_SPC563_ESCIB || defined(__DOXYGEN__)
+#if SPC5_SERIAL_USE_LINFLEX1 || defined(__DOXYGEN__)
+/**
+ * @brief LINFlex-1 RXI interrupt handler.
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(SPC5_LINFLEX1_RXI_HANDLER) {
+
+ CH_IRQ_PROLOGUE();
+
+ spc5xx_serve_rxi_interrupt(&SD2);
+
+ CH_IRQ_EPILOGUE();
+}
+
+/**
+ * @brief LINFlex-1 TXI interrupt handler.
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(SPC5_LINFLEX1_TXI_HANDLER) {
+
+ CH_IRQ_PROLOGUE();
+
+ spc5xx_serve_txi_interrupt(&SD2);
+
+ CH_IRQ_EPILOGUE();
+}
+
/**
- * @brief eSCI-B interrupt handler.
+ * @brief LINFlex-1 ERR interrupt handler.
*
* @isr
*/
-CH_IRQ_HANDLER(vector149) {
+CH_IRQ_HANDLER(SPC5_LINFLEX1_ERR_HANDLER) {
CH_IRQ_PROLOGUE();
- serve_interrupt(&SD2);
+ spc5xx_serve_err_interrupt(&SD2);
CH_IRQ_EPILOGUE();
}
@@ -244,18 +279,22 @@ CH_IRQ_HANDLER(vector149) {
*/
void sd_lld_init(void) {
-#if USE_SPC563_ESCIA
+#if SPC5_SERIAL_USE_LINFLEX0
sdObjectInit(&SD1, NULL, notify1);
- SD1.escip = &ESCI_A;
- ESCI_A.CR2.R = 0x8000; /* MDIS ON. */
- INTC.PSR[146].R = SPC563_ESCIA_PRIORITY;
+ SD1.linflexp = &LINFLEX_0;
+// ESCI_A.CR2.R = 0x8000; /* MDIS ON. */
+ INTC.PSR[SPC5_LINFLEX0_RXI_NUMBER].R = SPC5_SERIAL_LINFLEX0_PRIORITY;
+ INTC.PSR[SPC5_LINFLEX0_TXI_NUMBER].R = SPC5_SERIAL_LINFLEX0_PRIORITY;
+ INTC.PSR[SPC5_LINFLEX0_ERR_NUMBER].R = SPC5_SERIAL_LINFLEX0_PRIORITY;
#endif
-#if USE_SPC563_ESCIB
+#if SPC5_SERIAL_USE_LINFLEX1
sdObjectInit(&SD2, NULL, notify2);
- SD2.escip = &ESCI_B;
- ESCI_B.CR2.R = 0x8000; /* MDIS ON. */
- INTC.PSR[149].R = SPC563_ESCIB_PRIORITY;
+ SD2.linflexp = &LINFLEX_1;
+// ESCI_B.CR2.R = 0x8000; /* MDIS ON. */
+ INTC.PSR[SPC5_LINFLEX1_RXI_NUMBER].R = SPC5_SERIAL_LINFLEX1_PRIORITY;
+ INTC.PSR[SPC5_LINFLEX1_TXI_NUMBER].R = SPC5_SERIAL_LINFLEX1_PRIORITY;
+ INTC.PSR[SPC5_LINFLEX1_ERR_NUMBER].R = SPC5_SERIAL_LINFLEX1_PRIORITY;
#endif
}
@@ -273,7 +312,7 @@ void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {
if (config == NULL)
config = &default_config;
- esci_init(sdp, config);
+ spc5_linflex_init(sdp, config);
}
/**
@@ -286,7 +325,7 @@ void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {
void sd_lld_stop(SerialDriver *sdp) {
if (sdp->state == SD_READY)
- esci_deinit(sdp->escip);
+ spc5_linflex_deinit(sdp->linflexp);
}
#endif /* HAL_USE_SERIAL */