Simple mbed library with macros

Dependents:   SimpleTimer SimpleUART SimpleTimer Stoppuhr1

serial.h

Committer:
Alkorin
Date:
2010-11-09
Revision:
4:afddc4848b6c
Parent:
3:0b94bf95c552
Child:
5:b3aa0a49e21f

File content as of revision 4:afddc4848b6c:

#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