uart_dev.hpp
Go to the documentation of this file.
1 /*
2  * SocialLedge.com - Copyright (C) 2013
3  *
4  * This file is part of free software framework for embedded processors.
5  * You can use it and/or distribute it as long as this copyright header
6  * remains unmodified. The code is free for personal use and requires
7  * permission to use in a commercial product.
8  *
9  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
10  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
12  * I SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
13  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
14  *
15  * You can reach the author of this software at :
16  * p r e e t . w i k i @ g m a i l . c o m
17  */
18 
27 #ifndef UART_DEV_HPP_
28 #define UART_DEV_HPP_
29 
30 #include "FreeRTOS.h"
31 #include "queue.h"
32 #include "semphr.h"
33 #include "task.h"
34 
35 #include "char_dev.hpp"
36 #include "LPC17xx.h"
37 
38 
39 
61 class UartDev : public CharDev
62 {
63  public:
64 
66  void setBaudRate(unsigned int baudRate);
67 
75  bool getChar(char* pInputChar, unsigned int timeout=portMAX_DELAY);
76 
84  bool putChar(char out, unsigned int timeout=portMAX_DELAY);
85 
87  bool flush(void);
88 
93  inline unsigned int getRxQueueSize() const { return uxQueueMessagesWaiting(mRxQueue); }
94  inline unsigned int getTxQueueSize() const { return uxQueueMessagesWaiting(mTxQueue); }
95  inline unsigned int getRxQueueWatermark() const { return mRxQWatermark; }
96  inline unsigned int getTxQueueWatermark() const { return mTxQWatermark; }
104  bool recentlyActive(unsigned int ms=3000) const;
105  inline TickType_t getLastActivityTime(void) const { return mLastActivityTime; }
106  inline void resetActivity(void) { mLastActivityTime = xTaskGetMsCount(); }
113  void handleInterrupt();
114 
115  protected:
129  bool init(unsigned int pclk, unsigned int baudRate, int rxQSize=32, int txQSize=32);
130 
135  UartDev(unsigned int* pUARTBaseAddr);
136  ~UartDev() { }
138  private:
139  UartDev();
141  LPC_UART_TypeDef* mpUARTRegBase;
142  QueueHandle_t mRxQueue;
143  QueueHandle_t mTxQueue;
144  uint32_t mPeripheralClock;
145  uint16_t mRxQWatermark;
146  uint16_t mTxQWatermark;
147  TickType_t mLastActivityTime;
148 };
149 
150 
151 
152 #endif /* UART_DEV_HPP_ */
bool putChar(char out, unsigned int timeout=portMAX_DELAY)
Definition: uart_dev.cpp:50
bool flush(void)
Flushed all pending transmission of the uart queue.
Definition: uart_dev.cpp:78
#define portMAX_DELAY
Definition: portmacro.h:106
void setBaudRate(unsigned int baudRate)
Reset the baud-rate after UART has been initialized.
Definition: uart_dev.cpp:96
bool getChar(char *pInputChar, unsigned int timeout=portMAX_DELAY)
Definition: uart_dev.cpp:31
Definition: LPC17xx.h:340
Provides a 'char' device base class functionality for stream oriented char devices.
~UartDev()
Definition: uart_dev.hpp:136
unsigned int getTxQueueWatermark() const
Definition: uart_dev.hpp:96
unsigned int getTxQueueSize() const
Definition: uart_dev.hpp:94
uint32_t TickType_t
Definition: portmacro.h:105
bool recentlyActive(unsigned int ms=3000) const
Definition: uart_dev.cpp:89
unsigned int getRxQueueSize() const
Definition: uart_dev.hpp:93
Definition: uart_dev.hpp:61
unsigned int getRxQueueWatermark() const
Definition: uart_dev.hpp:95
CMSIS Cortex-M3 Core Peripheral Access Layer Header File for NXP LPC17xx Device Series.
void * QueueHandle_t
Definition: queue.h:88
TickType_t getLastActivityTime(void) const
Definition: uart_dev.hpp:105
Definition: char_dev.hpp:43
UBaseType_t uxQueueMessagesWaiting(const QueueHandle_t xQueue) PRIVILEGED_FUNCTION
Definition: queue.c:1579
void resetActivity(void)
Definition: uart_dev.hpp:106
bool init(unsigned int pclk, unsigned int baudRate, int rxQSize=32, int txQSize=32)
Definition: uart_dev.cpp:206
#define xTaskGetMsCount()
Definition: FreeRTOSConfig.h:113
void handleInterrupt()
Definition: uart_dev.cpp:111