Simple mbed library with macros

Dependents:   SimpleTimer SimpleUART SimpleTimer Stoppuhr1

Revision:
4:afddc4848b6c
Parent:
3:0b94bf95c552
Child:
5:b3aa0a49e21f
--- a/serial.h	Mon Nov 08 12:34:34 2010 +0000
+++ b/serial.h	Tue Nov 09 12:40:55 2010 +0000
@@ -1,54 +1,42 @@
-#ifndef __SERIAL_H__
-#define __SERIAL_H__
-
-#include "interrupt.h"
-#include "mbed_globals.h"
-
-/** Serial port (Choose UARTn (0,2,3)) **/
-#define UART_BASE LPC_UART0_BASE
-
-/** Registers **/
-// UARTn Receiver Buffer Register
-#define UnRBR 0x00
-// UARTn Transmit Holding Register
-#define UnTHR 0x00
-// UARTn Interrupt Enable Register
-#define UnIER 0x04
-// UARTn Interrupt Identification Register
-#define UnIIR 0x08
-// UARTn Line Status Register
-#define UnLSR 0x14
-
-/** Bits **/
-// RBR Interrupt Enable (UnIER, 14.4.4 p302)
-#define RBR_INT_BIT 0
-// Receiver Data Ready (UnLSR, 14.4.8 p306)
-#define RDR_BIT 0
-// Transmitter Holding Register Empty (UnLSR, 14.4.8 p306)
-#define THRE_BIT 5
-
-/** Macros **/
-#define SERIAL_PUTCHAR(c)           while (GET_BIT_VALUE(UART_BASE + UnLSR, THRE_BIT) == 0); \
-                                    SET_REGISTER8(UART_BASE + UnTHR, c)
-
-#define SERIAL_DATA_TO_READ()       (GET_BIT_VALUE(UART_BASE + UnLSR, RDR_BIT) == 1)
-
-#define SERIAL_GETCHAR()            GET_REGISTER8(UART_BASE + UnRBR)
-
-// See 14.4.5 p303
-inline int SERIAL_CHECK_INTERRUPT(void) {
-    unsigned int serialStatus = GET_REGISTER32(UART_BASE + UnIIR);
-
-    if (serialStatus & 1) // IntStatus, 1 = No Interrupt is pending.
-        return 0;
-
-    serialStatus = (serialStatus >> 1) & 0x3; // IntId, 2 = More than threshold data to read, 6 = Some caracters to read
-    if (serialStatus != 2 && serialStatus != 6)
-        return 0;
-
-    return 1;
-}
-
-#define SERIAL_SETBAUD(baud)
-
+#ifndef __SERIAL_H__
+#define __SERIAL_H__
+
+#include "interrupt.h"
+#include "mbed_globals.h"
+
+/** Serial port (Choose UARTn (0,2,3)) **/
+#define UART_BASE LPC_UART0
+
+/** Bits **/
+// RBR Interrupt Enable (UnIER, 14.4.4 p302)
+#define RBR_INT_BIT 0
+// Receiver Data Ready (UnLSR, 14.4.8 p306)
+#define RDR_BIT 0
+// Transmitter Holding Register Empty (UnLSR, 14.4.8 p306)
+#define THRE_BIT 5
+
+/** Macros **/
+#define SERIAL_PUTCHAR(c)           while (GET_BIT_VALUE(UART_BASE->LSR, THRE_BIT) == 0); \
+                                    UART_BASE->THR = c;
+
+#define SERIAL_DATA_TO_READ()       (GET_BIT_VALUE(UART_BASE->LSR, RDR_BIT) == 1)
+
+#define SERIAL_GETCHAR()            (UART_BASE->RBR)
+
+// See 14.4.5 p303
+inline int SERIAL_CHECK_INTERRUPT(void) {
+    uint32_t serialStatus = UART_BASE->IIR;
+
+    if (serialStatus & 1) // IntStatus, 1 = No Interrupt is pending.
+        return 0;
+
+    serialStatus = (serialStatus >> 1) & 0x3; // IntId, 2 = More than threshold data to read, 6 = Some caracters to read
+    if (serialStatus != 2 && serialStatus != 6)
+        return 0;
+
+    return 1;
+}
+
+#define SERIAL_SETBAUD(baud)
+
 #endif
\ No newline at end of file