cursada_mc2
Base de control de temperatura para EDU-CIAA-NXP
Loading...
Searching...
No Matches
uart_driver.c
Go to the documentation of this file.
1
12#include "uart_driver.h"
13
14LPC_USART_T* uart_channel_;
15
16void driver_uart_init(uint8_t channel)
17{
18 switch (channel) {
19 case 0:
20 uart_channel_ = LPC_USART0;
21 Chip_SCU_PinMux(9, 5, MD_PDN, FUNC7); /* P2 3: USART3 TXD */
22 Chip_SCU_PinMux(9, 6, MD_PLN | MD_EZI | MD_ZI, FUNC7); /* P2 4: USART3 RXD */
23 break;
24 case 2:
25 uart_channel_ = LPC_USART2;
26 Chip_SCU_PinMux(7, 1, MD_PDN, FUNC6); /* P2 3: USART3 TXD */
27 Chip_SCU_PinMux(7, 2, MD_PLN | MD_EZI | MD_ZI, FUNC6); /* P2 4: USART3 RXD */
28 break;
29 case 3:
30 uart_channel_ = LPC_USART3;
31 Chip_SCU_PinMux(2, 3, MD_PDN, FUNC2); /* P2 3: USART3 TXD */
32 Chip_SCU_PinMux(2, 4, MD_PLN | MD_EZI | MD_ZI, FUNC2); /* P2 4: USART3 RXD */
33 break;
34 default:
35 uart_channel_ = LPC_USART3;
36 Chip_SCU_PinMux(2, 3, MD_PDN, FUNC2); /* P2 3: USART3 TXD */
37 Chip_SCU_PinMux(2, 4, MD_PLN | MD_EZI | MD_ZI, FUNC2); /* P2 4: USART3 RXD */
38 break;
39 }
40 Chip_UART_Init(uart_channel_);
41 Chip_UART_SetBaud(uart_channel_, BAUD_115K);
42 Chip_UART_SetupFIFOS(uart_channel_, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0);
43 Chip_UART_TXEnable(uart_channel_);
44}
45
46void driver_uart_int_enable(uint8_t rx_or_tx)
47{
48 NVIC_ClearPendingIRQ(USART3_IRQn);
49 NVIC_EnableIRQ(USART3_IRQn);
50 if (rx_or_tx == INT_RX) { Chip_UART_IntEnable(uart_channel_, UART_IER_RBRINT); }
51 if (rx_or_tx == INT_TX) { Chip_UART_IntEnable(uart_channel_, UART_IER_THREINT); }
52 if (rx_or_tx == (INT_TX | INT_RX)) { Chip_UART_IntEnable(uart_channel_, (UART_IER_RBRINT | UART_IER_THREINT)); }
53}
54
55void driver_uart_send_char(uint8_t data)
56{ //
57 Chip_UART_SendByte(uart_channel_, data);
58}
59
60void driver_uart_send_string(const void* data, uint16_t numBytes)
61{ //
62 Chip_UART_SendBlocking(uart_channel_, data, numBytes);
63}
64
66{ //
67 Chip_UART_ReadBlocking(uart_channel_, data, 1);
68}
void driver_uart_send_string(const void *data, uint16_t numBytes)
Transmite una secuencia de bytes por UART en modo bloqueante.
Definition uart_driver.c:60
LPC_USART_T * uart_channel_
Definition uart_driver.c:14
void driver_uart_receive_char(void *data)
Recibe un byte por UART en modo bloqueante.
Definition uart_driver.c:65
void driver_uart_send_char(uint8_t data)
Transmite un byte por UART en modo bloqueante.
Definition uart_driver.c:55
void driver_uart_init(uint8_t channel)
Inicializa un canal UART en modo bloqueante.
Definition uart_driver.c:16
void driver_uart_int_enable(uint8_t rx_or_tx)
Habilita una interrupcion UART sobre el canal ya configurado.
Definition uart_driver.c:46
Interfaz del driver UART bloqueante.
#define INT_RX
Habilita interrupcion de recepcion.
Definition uart_driver.h:12
#define BAUD_115K
Constante de baudrate a 115200 baudios.
Definition uart_driver.h:19
#define INT_TX
Habilita interrupcion de transmision.
Definition uart_driver.h:14