summaryrefslogtreecommitdiff
path: root/firmware/drivers/uart.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/uart.c')
-rw-r--r--firmware/drivers/uart.c89
1 files changed, 71 insertions, 18 deletions
diff --git a/firmware/drivers/uart.c b/firmware/drivers/uart.c
index 28a6e00..1e7960b 100644
--- a/firmware/drivers/uart.c
+++ b/firmware/drivers/uart.c
@@ -17,11 +17,33 @@
* notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified
* use without further testing or modification.
-****************************************************************************/
-#include <LPC17xx.h>
-#include <stdint.h>//"type.h"
+ ****************************************************************************/
#include "uart.h"
+#include <LPC17xx.h>
+#include <stdint.h>
+
+#define IER_RBR 0x01
+#define IER_THRE 0x02
+#define IER_RLS 0x04
+
+#define IIR_PEND 0x01
+#define IIR_RLS 0x03
+#define IIR_RDA 0x02
+#define IIR_CTI 0x06
+#define IIR_THRE 0x01
+
+#define LSR_RDR 0x01
+#define LSR_OE 0x02
+#define LSR_PE 0x04
+#define LSR_FE 0x08
+#define LSR_BI 0x10
+#define LSR_THRE 0x20
+#define LSR_TEMT 0x40
+#define LSR_RXFE 0x80
+
+#define BUFSIZE 0x40
+
#define TRUE 1
#define FALSE 0
@@ -40,11 +62,13 @@ volatile uint8_t UART0TxEmpty = 1, UART1TxEmpty = 1;
** VIC table
**
*****************************************************************************/
-uint32_t UARTInit( uint32_t PortNum, uint32_t baudrate )
+uint32_t uart_init( uint32_t PortNum, uint32_t baudrate )
{
uint32_t Fdiv;
uint32_t pclkdiv, pclk;
+ SystemCoreClockUpdate();
+
uint32_t SystemFrequency = SystemCoreClock;
if ( PortNum == 0 )
@@ -77,7 +101,7 @@ uint32_t UARTInit( uint32_t PortNum, uint32_t baudrate )
LPC_UART0->DLM = Fdiv / 256;
LPC_UART0->DLL = Fdiv % 256;
LPC_UART0->LCR = 0x03; /* DLAB = 0 */
- LPC_UART0->FCR = 0x07; /* Enable and reset TX and RX FIFO. */
+ LPC_UART0->FCR = 0b111; /* Enable and reset TX and RX FIFO. */
// NVIC_EnableIRQ(UART0_IRQn);
@@ -135,31 +159,60 @@ uint32_t UARTInit( uint32_t PortNum, uint32_t baudrate )
** Returned value: None
**
*****************************************************************************/
-void UARTSend( uint32_t portNum, char *BufferPtr, uint32_t Length )
+void uart_send( uint32_t portNum, const char *BufferPtr, uint32_t Length )
{
- if ( portNum == 0 )
- {
- while ( Length != 0 )
+ //unsigned int *U0LSR = (unsigned int *)0x4000C014;
+
+ if(portNum == 0) {
+ while(Length != 0) {
+ /* THRE status, contain valid data */
+ //while ( !(UART0TxEmpty & 0x01) );
+ // while(((*U0LSR) & 0b100000) != 0);
+ while((LPC_UART0->LSR & 0b100000) == 0);
+
+ LPC_UART0->THR = *BufferPtr;
+ UART0TxEmpty = 0; /* not empty in the THR until it shifts out */
+ BufferPtr++;
+ Length--;
+ }
+ } else {
+ while ( Length != 0 )
{
/* THRE status, contain valid data */
- //while ( !(UART0TxEmpty & 0x01) );
- LPC_UART0->THR = *BufferPtr;
- UART0TxEmpty = 0; /* not empty in the THR until it shifts out */
+ while ( !(UART1TxEmpty & 0x01) );
+ LPC_UART1->THR = *BufferPtr;
+ UART1TxEmpty = 0; /* not empty in the THR until it shifts out */
BufferPtr++;
Length--;
- }
+ }
}
- else
- {
- while ( Length != 0 )
+ return;
+}
+
+void uart_receive(uint32_t portNum, char *BufferPtr, uint32_t Length)
+{
+ if(portNum == 0) {
+ while(Length != 0) {
+ /* THRE status, contain valid data */
+ //while ( !(UART0TxEmpty & 0x01) );
+ // while(((*U0LSR) & 0b100000) != 0);
+ while((LPC_UART0->LSR & 0b1) == 0);
+
+ *BufferPtr = LPC_UART0->RBR;
+ BufferPtr++;
+ Length--;
+ }
+ } else {
+ /*
+ while ( Length != 0 )
{
- /* THRE status, contain valid data */
while ( !(UART1TxEmpty & 0x01) );
LPC_UART1->THR = *BufferPtr;
- UART1TxEmpty = 0; /* not empty in the THR until it shifts out */
+ UART1TxEmpty = 0; // not empty in the THR until it shifts out
BufferPtr++;
Length--;
}
+ */
}
return;
}