Simple mbed library with macros
Dependents: SimpleTimer SimpleUART SimpleTimer Stoppuhr1
serial.h
- Committer:
- Alkorin
- Date:
- 2010-11-08
- Revision:
- 3:0b94bf95c552
- Parent:
- 0:aa3c3d1a5918
- Child:
- 4:afddc4848b6c
File content as of revision 3:0b94bf95c552:
#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) #endif