Skip to content

Commit

Permalink
Merge pull request #3 from Maxjta/developer
Browse files Browse the repository at this point in the history
Add Support USART6, UART7, UART8
  • Loading branch information
ArteryTek authored Oct 11, 2024
2 parents 405727c + 599e4f7 commit 1539209
Show file tree
Hide file tree
Showing 4 changed files with 652 additions and 2 deletions.
163 changes: 163 additions & 0 deletions os/hal/ports/AT32/LLD/USARTv2/hal_serial_lld.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ SerialDriver SD4;
SerialDriver SD5;
#endif

/** @brief USART6 serial driver identifier.*/
#if AT32_SERIAL_USE_USART6 || defined(__DOXYGEN__)
SerialDriver SD6;
#endif

/** @brief UART7 serial driver identifier.*/
#if AT32_SERIAL_USE_UART7 || defined(__DOXYGEN__)
SerialDriver SD7;
#endif

/** @brief UART8 serial driver identifier.*/
#if AT32_SERIAL_USE_UART8 || defined(__DOXYGEN__)
SerialDriver SD8;
#endif

/*===========================================================================*/
/* Driver local variables and types. */
/*===========================================================================*/
Expand Down Expand Up @@ -189,6 +204,30 @@ static void notify5(io_queue_t *qp) {
}
#endif

#if AT32_SERIAL_USE_USART6 || defined(__DOXYGEN__)
static void notify6(io_queue_t *qp) {

(void)qp;
USART6->CTRL1 |= USART_CTRL1_TDBEIEN | USART_CTRL1_TDCIEN;
}
#endif

#if AT32_SERIAL_USE_UART7 || defined(__DOXYGEN__)
static void notify7(io_queue_t *qp) {

(void)qp;
UART7->CTRL1 |= USART_CTRL1_TDBEIEN | USART_CTRL1_TDCIEN;
}
#endif

#if AT32_SERIAL_USE_UART8 || defined(__DOXYGEN__)
static void notify8(io_queue_t *qp) {

(void)qp;
UART8->CTRL1 |= USART_CTRL1_TDBEIEN | USART_CTRL1_TDCIEN;
}
#endif

/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
Expand Down Expand Up @@ -298,6 +337,69 @@ OSAL_IRQ_HANDLER(AT32_UART5_HANDLER) {
#endif
#endif

#if AT32_SERIAL_USE_USART6 || defined(__DOXYGEN__)
#if !defined(AT32_USART6_SUPPRESS_ISR)
#if !defined(AT32_USART6_HANDLER)
#error "AT32_USART6_HANDLER not defined"
#endif
/**
* @brief USART6 interrupt handler.
*
* @isr
*/
OSAL_IRQ_HANDLER(AT32_USART6_HANDLER) {

OSAL_IRQ_PROLOGUE();

sd_lld_serve_interrupt(&SD6);

OSAL_IRQ_EPILOGUE();
}
#endif
#endif

#if AT32_SERIAL_USE_UART7 || defined(__DOXYGEN__)
#if !defined(AT32_UART7_SUPPRESS_ISR)
#if !defined(AT32_UART7_HANDLER)
#error "AT32_UART7_HANDLER not defined"
#endif
/**
* @brief UART7 interrupt handler.
*
* @isr
*/
OSAL_IRQ_HANDLER(AT32_UART7_HANDLER) {

OSAL_IRQ_PROLOGUE();

sd_lld_serve_interrupt(&SD7);

OSAL_IRQ_EPILOGUE();
}
#endif
#endif

#if AT32_SERIAL_USE_UART8 || defined(__DOXYGEN__)
#if !defined(AT32_UART8_SUPPRESS_ISR)
#if !defined(AT32_UART8_HANDLER)
#error "AT32_UART8_HANDLER not defined"
#endif
/**
* @brief UART8 interrupt handler.
*
* @isr
*/
OSAL_IRQ_HANDLER(AT32_UART8_HANDLER) {

OSAL_IRQ_PROLOGUE();

sd_lld_serve_interrupt(&SD8);

OSAL_IRQ_EPILOGUE();
}
#endif
#endif

/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
Expand Down Expand Up @@ -353,6 +455,34 @@ void sd_lld_init(void) {
nvicEnableVector(AT32_UART5_NUMBER, AT32_SERIAL_UART5_PRIORITY);
#endif
#endif

#if AT32_SERIAL_USE_USART6
sdObjectInit(&SD6, NULL, notify3);
SD6.usart = USART6;
SD6.clock = AT32_PCLK2;
#if !defined(AT32_USART6_SUPPRESS_ISR) && defined(AT32_USART6_NUMBER)
nvicEnableVector(AT32_USART6_NUMBER, AT32_SERIAL_USART6_PRIORITY);
#endif
#endif

#if AT32_SERIAL_USE_UART7
sdObjectInit(&SD7, NULL, notify4);
SD7.usart = UART7;
SD7.clock = AT32_PCLK1;
#if !defined(AT32_UART7_SUPPRESS_ISR) && defined(AT32_UART7_NUMBER)
nvicEnableVector(AT32_UART7_NUMBER, AT32_SERIAL_UART7_PRIORITY);
#endif
#endif

#if AT32_SERIAL_USE_UART8
sdObjectInit(&SD8, NULL, notify5);
SD8.usart = UART8;
SD8.clock = AT32_PCLK1;
#if !defined(AT32_UART8_SUPPRESS_ISR) && defined(AT32_UART8_NUMBER)
nvicEnableVector(AT32_UART8_NUMBER, AT32_SERIAL_UART8_PRIORITY);
#endif
#endif

}

/**
Expand Down Expand Up @@ -395,6 +525,21 @@ void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {
if (&SD5 == sdp) {
crmEnableUART5(true);
}
#endif
#if AT32_SERIAL_USE_USART6
if (&SD6 == sdp) {
crmEnableUSART6(true);
}
#endif
#if AT32_SERIAL_USE_UART7
if (&SD7 == sdp) {
crmEnableUART7(true);
}
#endif
#if AT32_SERIAL_USE_UART8
if (&SD8 == sdp) {
crmEnableUART8(true);
}
#endif
}
usart_init(sdp, config);
Expand Down Expand Up @@ -442,6 +587,24 @@ void sd_lld_stop(SerialDriver *sdp) {
crmDisableUART5();
return;
}
#endif
#if AT32_SERIAL_USE_USART6
if (&SD6 == sdp) {
crmDisableUSART6();
return;
}
#endif
#if AT32_SERIAL_USE_UART7
if (&SD7 == sdp) {
crmDisableUART7();
return;
}
#endif
#if AT32_SERIAL_USE_UART8
if (&SD8 == sdp) {
crmDisableUART8();
return;
}
#endif
}
}
Expand Down
112 changes: 111 additions & 1 deletion os/hal/ports/AT32/LLD/USARTv2/hal_serial_lld.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,33 @@
#define AT32_SERIAL_USE_UART5 FALSE
#endif

/**
* @brief USART6 driver enable switch.
* @details If set to @p TRUE the support for USART6 is included.
* @note The default is @p FALSE.
*/
#if !defined(AT32_SERIAL_USE_USART6) || defined(__DOXYGEN__)
#define AT32_SERIAL_USE_USART6 FALSE
#endif

/**
* @brief UART7 driver enable switch.
* @details If set to @p TRUE the support for UART7 is included.
* @note The default is @p FALSE.
*/
#if !defined(AT32_SERIAL_USE_UART7) || defined(__DOXYGEN__)
#define AT32_SERIAL_USE_UART7 FALSE
#endif

/**
* @brief UART8 driver enable switch.
* @details If set to @p TRUE the support for UART8 is included.
* @note The default is @p FALSE.
*/
#if !defined(AT32_SERIAL_USE_UART8) || defined(__DOXYGEN__)
#define AT32_SERIAL_USE_UART8 FALSE
#endif

/**
* @brief USART1 interrupt priority level setting.
*/
Expand Down Expand Up @@ -121,6 +148,28 @@
#if !defined(AT32_SERIAL_UART5_PRIORITY) || defined(__DOXYGEN__)
#define AT32_SERIAL_UART5_PRIORITY 12
#endif

/**
* @brief USART6 interrupt priority level setting.
*/
#if !defined(AT32_SERIAL_USART6_PRIORITY) || defined(__DOXYGEN__)
#define AT32_SERIAL_USART6_PRIORITY 12
#endif

/**
* @brief UART7 interrupt priority level setting.
*/
#if !defined(AT32_SERIAL_UART7_PRIORITY) || defined(__DOXYGEN__)
#define AT32_SERIAL_UART7_PRIORITY 12
#endif

/**
* @brief UART8 interrupt priority level setting.
*/
#if !defined(AT32_SERIAL_UART8_PRIORITY) || defined(__DOXYGEN__)
#define AT32_SERIAL_UART8_PRIORITY 12
#endif

/** @} */

/*===========================================================================*/
Expand All @@ -147,9 +196,22 @@
#error "UART5 not present in the selected device"
#endif

#if AT32_SERIAL_USE_USART6 && !AT32_HAS_USART6
#error "USART6 not present in the selected device"
#endif

#if AT32_SERIAL_USE_UART7 && !AT32_HAS_UART7
#error "UART7 not present in the selected device"
#endif

#if AT32_SERIAL_USE_UART8 && !AT32_HAS_UART8
#error "UART8 not present in the selected device"
#endif

#if !AT32_SERIAL_USE_USART1 && !AT32_SERIAL_USE_USART2 && \
!AT32_SERIAL_USE_USART3 && !AT32_SERIAL_USE_UART4 && \
!AT32_SERIAL_USE_UART5
!AT32_SERIAL_USE_UART5 && !AT32_SERIAL_USE_USART6 && \
!AT32_SERIAL_USE_UART7 && !AT32_SERIAL_USE_UART8
#error "SERIAL driver activated but no USART/UART peripheral assigned"
#endif

Expand Down Expand Up @@ -178,6 +240,21 @@
#error "Invalid IRQ priority assigned to UART5"
#endif

#if AT32_SERIAL_USE_USART6 && \
!OSAL_IRQ_IS_VALID_PRIORITY(AT32_SERIAL_USART6_PRIORITY)
#error "Invalid IRQ priority assigned to USART6"
#endif

#if AT32_SERIAL_USE_UART7 && \
!OSAL_IRQ_IS_VALID_PRIORITY(AT32_SERIAL_UART7_PRIORITY)
#error "Invalid IRQ priority assigned to UART7"
#endif

#if AT32_SERIAL_USE_UART8 && \
!OSAL_IRQ_IS_VALID_PRIORITY(AT32_SERIAL_UART8_PRIORITY)
#error "Invalid IRQ priority assigned to UART8"
#endif

/* Checks on allocation of USARTx units.*/
#if AT32_SERIAL_USE_USART1
#if defined(AT32_USART1_IS_USED)
Expand Down Expand Up @@ -219,6 +296,30 @@
#endif
#endif

#if AT32_SERIAL_USE_USART6
#if defined(AT32_USART6_IS_USED)
#error "SD6 requires USART6 but it is already used"
#else
#define AT32_USART6_IS_USED
#endif
#endif

#if AT32_SERIAL_USE_UART7
#if defined(AT32_UART7_IS_USED)
#error "SD7 requires UART7 but it is already used"
#else
#define AT32_UART7_IS_USED
#endif
#endif

#if AT32_SERIAL_USE_UART8
#if defined(AT32_UART8_IS_USED)
#error "SD8 requires UART8 but it is already used"
#else
#define AT32_UART8_IS_USED
#endif
#endif

/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
Expand Down Expand Up @@ -305,6 +406,15 @@ extern SerialDriver SD4;
#if AT32_SERIAL_USE_UART5 && !defined(__DOXYGEN__)
extern SerialDriver SD5;
#endif
#if AT32_SERIAL_USE_USART6 && !defined(__DOXYGEN__)
extern SerialDriver SD6;
#endif
#if AT32_SERIAL_USE_UART7 && !defined(__DOXYGEN__)
extern SerialDriver SD7;
#endif
#if AT32_SERIAL_USE_UART8 && !defined(__DOXYGEN__)
extern SerialDriver SD8;
#endif

#ifdef __cplusplus
extern "C" {
Expand Down
Loading

0 comments on commit 1539209

Please sign in to comment.