aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/platforms')
-rw-r--r--os/hal/platforms/SPC560Pxx/spc560p_registry.h21
-rw-r--r--os/hal/platforms/SPC5xx/LINFlex_v1/serial_lld.c231
-rw-r--r--os/hal/platforms/SPC5xx/LINFlex_v1/serial_lld.h69
-rw-r--r--os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.h4
4 files changed, 205 insertions, 120 deletions
diff --git a/os/hal/platforms/SPC560Pxx/spc560p_registry.h b/os/hal/platforms/SPC560Pxx/spc560p_registry.h
index b17b4962f..131201ed2 100644
--- a/os/hal/platforms/SPC560Pxx/spc560p_registry.h
+++ b/os/hal/platforms/SPC560Pxx/spc560p_registry.h
@@ -37,6 +37,27 @@
* @name SPC560Pxx capabilities
* @{
*/
+/* LINFlex attributes.*/
+#define SPC5_HAS_LINFLEX0 TRUE
+#define SPC5_LINFLEX0_RXI_HANDLER vector79
+#define SPC5_LINFLEX0_TXI_HANDLER vector80
+#define SPC5_LINFLEX0_ERR_HANDLER vector81
+#define SPC5_LINFLEX0_RXI_NUMBER 79
+#define SPC5_LINFLEX0_TXI_NUMBER 80
+#define SPC5_LINFLEX0_ERR_NUMBER 81
+
+#define SPC5_HAS_LINFLEX1 TRUE
+#define SPC5_LINFLEX1_RXI_HANDLER vector99
+#define SPC5_LINFLEX1_TXI_HANDLER vector100
+#define SPC5_LINFLEX1_ERR_HANDLER vector101
+#define SPC5_LINFLEX1_RXI_NUMBER 99
+#define SPC5_LINFLEX1_TXI_NUMBER 100
+#define SPC5_LINFLEX1_ERR_NUMBER 101
+
+#define SPC5_HAS_LINFLEX2 FALSE
+
+#define SPC5_HAS_LINFLEX3 FALSE
+
/* SIU/SIUL attributes.*/
#define SPC5_HAS_SIU FALSE
#define SPC5_SIU_SUPPORTS_PORTS TRUE
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 */
diff --git a/os/hal/platforms/SPC5xx/LINFlex_v1/serial_lld.h b/os/hal/platforms/SPC5xx/LINFlex_v1/serial_lld.h
index fcc2273bd..0568310a3 100644
--- a/os/hal/platforms/SPC5xx/LINFlex_v1/serial_lld.h
+++ b/os/hal/platforms/SPC5xx/LINFlex_v1/serial_lld.h
@@ -40,41 +40,60 @@
/*===========================================================================*/
/**
- * @brief eSCI-A driver enable switch.
- * @details If set to @p TRUE the support for eSCI-A is included.
- * @note The default is @p TRUE.
+ * @brief LINFlex-0 driver enable switch.
+ * @details If set to @p TRUE the support for LINFlex-0 is included.
*/
-#if !defined(USE_SPC563_ESCIA) || defined(__DOXYGEN__)
-#define USE_SPC563_ESCIA FALSE
+#if !defined(SPC5_SERIAL_USE_LINFLEX0) || defined(__DOXYGEN__)
+#define SPC5_SERIAL_USE_LINFLEX0 TRUE
#endif
/**
- * @brief eSCI-B driver enable switch.
- * @details If set to @p TRUE the support for eSCI-B is included.
- * @note The default is @p TRUE.
+ * @brief LINFlex-1 driver enable switch.
+ * @details If set to @p TRUE the support for LINFlex-1 is included.
*/
-#if !defined(USE_SPC563_ESCIB) || defined(__DOXYGEN__)
-#define USE_SPC563_ESCIB FALSE
+#if !defined(SPC5_SERIAL_USE_LINFLEX1) || defined(__DOXYGEN__)
+#define SPC5_SERIAL_USE_LINFLEX1 TRUE
#endif
/**
- * @brief eSCI-A interrupt priority level setting.
+ * @brief LINFlex-0 interrupt priority level setting.
*/
-#if !defined(SPC563_ESCIA_PRIORITY) || defined(__DOXYGEN__)
-#define SPC563_ESCIA_PRIORITY 8
+#if !defined(SPC5_SERIAL_LINFLEX0_PRIORITY) || defined(__DOXYGEN__)
+#define SPC5_SERIAL_LINFLEX0_PRIORITY 8
#endif
/**
- * @brief eSCI-B interrupt priority level setting.
+ * @brief LINFlex-1 interrupt priority level setting.
*/
-#if !defined(SPC563_ESCIB_PRIORITY) || defined(__DOXYGEN__)
-#define SPC563_ESCIB_PRIORITY 8
+#if !defined(SPC5_SERIAL_LINFLEX1_PRIORITY) || defined(__DOXYGEN__)
+#define SPC5_SERIAL_LINFLEX1_PRIORITY 8
#endif
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
+#if SPC5_SERIAL_USE_LINFLEX0 && !SPC5_HAS_LINFLEX0
+#error "LINFlex-0 not present in the selected device"
+#endif
+
+#if SPC5_SERIAL_USE_LINFLEX1 && !SPC5_HAS_LINFLEX1
+#error "LINFlex-1 not present in the selected device"
+#endif
+
+#if SPC5_SERIAL_USE_LINFLEX2 && !SPC5_HAS_LINFLEX2
+#error "LINFlex-2 not present in the selected device"
+#endif
+
+#if SPC5_SERIAL_USE_LINFLEX3 && !SPC5_HAS_LINFLEX3
+#error "LINFlex-3 not present in the selected device"
+#endif
+
+#if !SPC5_SERIAL_USE_LINFLEX0 && !SPC5_SERIAL_USE_LINFLEX1 && \
+ !SPC5_SERIAL_USE_LINFLEX2 && !SPC5_SERIAL_USE_LINFLEX3
+#error "SERIAL driver activated but no LINFlex peripheral assigned"
+#endif
+
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
@@ -91,11 +110,11 @@ typedef struct {
/**
* @brief Bit rate.
*/
- uint32_t sc_speed;
+ uint32_t speed;
/**
* @brief Mode flags.
*/
- uint8_t sc_mode;
+ uint8_t mode;
} SerialConfig;
/**
@@ -114,8 +133,8 @@ typedef struct {
/* Output circular buffer.*/ \
uint8_t ob[SERIAL_BUFFERS_SIZE]; \
/* End of the mandatory fields.*/ \
- /* Pointer to the volatile eSCI registers block.*/ \
- volatile struct ESCI_tag *escip;
+ /* Pointer to the volatile LINFlex registers block.*/ \
+ volatile struct LINFLEX_tag *linflexp;
/*===========================================================================*/
/* Driver macros. */
@@ -125,12 +144,18 @@ typedef struct {
/* External declarations. */
/*===========================================================================*/
-#if USE_SPC563_ESCIA && !defined(__DOXYGEN__)
+#if SPC5_SERIAL_USE_LINFLEX0 && !defined(__DOXYGEN__)
extern SerialDriver SD1;
#endif
-#if USE_SPC563_ESCIB && !defined(__DOXYGEN__)
+#if SPC5_SERIAL_USE_LINFLEX1 && !defined(__DOXYGEN__)
extern SerialDriver SD2;
#endif
+#if SPC5_SERIAL_USE_LINFLEX2 && !defined(__DOXYGEN__)
+extern SerialDriver SD3;
+#endif
+#if SPC5_SERIAL_USE_LINFLEX3 && !defined(__DOXYGEN__)
+extern SerialDriver SD4;
+#endif
#ifdef __cplusplus
extern "C" {
diff --git a/os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.h b/os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.h
index a8bc7b332..e747139f8 100644
--- a/os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.h
+++ b/os/hal/platforms/SPC5xx/SIUL_v1/pal_lld.h
@@ -45,7 +45,7 @@
#undef PAL_MODE_OUTPUT_OPENDRAIN
/**
- * @name SIUL-specific PAL modes
+ * @name SIU/SIUL-specific PAL modes
* @{
*/
#define PAL_SPC5_SMC (1U << 14)
@@ -141,7 +141,7 @@ typedef uint16_t iomode_t;
typedef uint32_t ioportid_t;
/**
- * @brief SIUL register initializer type.
+ * @brief SIU/SIUL register initializer type.
*/
typedef struct {
uint8_t pcr_index;