From 32a8740a7c92fef75497779f31a940b2dbec436c Mon Sep 17 00:00:00 2001 From: edolomb Date: Thu, 21 Sep 2017 16:07:49 +0000 Subject: Minor changes in hal_serial_lld driver git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10661 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/SAMA/LLD/USARTv1/hal_serial_lld.c | 36 +++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'os/hal/ports') diff --git a/os/hal/ports/SAMA/LLD/USARTv1/hal_serial_lld.c b/os/hal/ports/SAMA/LLD/USARTv1/hal_serial_lld.c index 62e5e260d..9b7735114 100644 --- a/os/hal/ports/SAMA/LLD/USARTv1/hal_serial_lld.c +++ b/os/hal/ports/SAMA/LLD/USARTv1/hal_serial_lld.c @@ -30,6 +30,32 @@ /* Driver local definitions. */ /*===========================================================================*/ +/*===========================================================================*/ +/* Driver local macros. */ +/*===========================================================================*/ + +/** + * @brief Enable write protection on SD registers block. + * + * @param[in] sdp pointer to a SD register block + * + * @notapi + */ +#define sdEnableWP(sdp) { \ + sdp->UART_WPMR = UART_WPMR_WPKEY_PASSWD | UART_WPMR_WPEN; \ +} + +/** + * @brief Disable write protection on SD registers block. + * + * @param[in] sdp pointer to a SD register block + * + * @notapi + */ +#define sdDisableWP(sdp) { \ + sdp->UART_WPMR = UART_WPMR_WPKEY_PASSWD; \ +} + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ @@ -46,7 +72,7 @@ SerialDriver SD1; /** @brief UART2 serial driver identifier.*/ #if SAMA_SERIAL_USE_UART2 || defined(__DOXYGEN__) -SerialDriver SD3; +SerialDriver SD2; #endif /** @brief UART3 serial driver identifier.*/ @@ -125,6 +151,8 @@ static uint8_t sd_out_buf4[SAMA_SERIAL_UART4_IN_BUF_SIZE]; static void uart_init(SerialDriver *sdp, const SerialConfig *config) { Uart *u = sdp->uart; + /* Disabling write protection */ + sdDisableWP(u); /* Baud rate setting.*/ u->UART_BRGR = UART_BRGR_CD(sdp->clock / (16 * config->speed)); @@ -136,6 +164,8 @@ static void uart_init(SerialDriver *sdp, const SerialConfig *config) { u->UART_CR |= UART_CR_RSTSTA; /* Enabling Tx and Rx */ u->UART_CR |= UART_CR_RXEN | UART_CR_TXEN; + /* Enabling write protection */ + sdEnableWP(u); } @@ -147,8 +177,12 @@ static void uart_init(SerialDriver *sdp, const SerialConfig *config) { */ static void uart_deinit(Uart *u) { + /* Disabling write protection */ + sdDisableWP(u); u->UART_CR = 0; u->UART_MR = 0; + /* Enabling write protection */ + sdEnableWP(u); } -- cgit v1.2.3