Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
WifiRobot/RoombaControl/irobot/irobotUART.h@0:2deb247ab4bd, 2014-12-09 (annotated)
- Committer:
- wueric
- Date:
- Tue Dec 09 05:06:37 2014 +0000
- Revision:
- 0:2deb247ab4bd
sharing stuff;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wueric | 0:2deb247ab4bd | 1 | /** \file irobotUART.h |
| wueric | 0:2deb247ab4bd | 2 | * |
| wueric | 0:2deb247ab4bd | 3 | * UART wrappers for the iRobot Create. This library is not architecture |
| wueric | 0:2deb247ab4bd | 4 | specific, so these are only wrappers for UART functions that must |
| wueric | 0:2deb247ab4bd | 5 | be defined for your architecture. |
| wueric | 0:2deb247ab4bd | 6 | * |
| wueric | 0:2deb247ab4bd | 7 | * \author Jeff C. Jensen |
| wueric | 0:2deb247ab4bd | 8 | * \date 2013-12-09 |
| wueric | 0:2deb247ab4bd | 9 | * \copyright Copyright (C) 2013, Jeff C. Jensen, Edward A. Lee, and Sanjit A. Seshia. |
| wueric | 0:2deb247ab4bd | 10 | * This software accompanies An Introductory Lab in Embedded and Cyber-Physical Systems |
| wueric | 0:2deb247ab4bd | 11 | * and is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 |
| wueric | 0:2deb247ab4bd | 12 | * Unported License. See http://leeseshia.org/lab. |
| wueric | 0:2deb247ab4bd | 13 | |
| wueric | 0:2deb247ab4bd | 14 | * Dependencies and typedef for irobotUARTPort_t modified to |
| wueric | 0:2deb247ab4bd | 15 | support implementation for mbed |
| wueric | 0:2deb247ab4bd | 16 | */ |
| wueric | 0:2deb247ab4bd | 17 | |
| wueric | 0:2deb247ab4bd | 18 | #ifndef _IROBOT_UART_H |
| wueric | 0:2deb247ab4bd | 19 | #define _IROBOT_UART_H |
| wueric | 0:2deb247ab4bd | 20 | |
| wueric | 0:2deb247ab4bd | 21 | #include "irobotTypes.h" |
| wueric | 0:2deb247ab4bd | 22 | #include "irobotError.h" |
| wueric | 0:2deb247ab4bd | 23 | #include "xqueue.h" |
| wueric | 0:2deb247ab4bd | 24 | #include "mbed.h" |
| wueric | 0:2deb247ab4bd | 25 | #include "TimeoutMultipleSerial.h" |
| wueric | 0:2deb247ab4bd | 26 | //#include "UART.h" |
| wueric | 0:2deb247ab4bd | 27 | |
| wueric | 0:2deb247ab4bd | 28 | /// UART port wrapper; change for your UART API |
| wueric | 0:2deb247ab4bd | 29 | //typedef MyRio_Uart * irobotUARTPort_t; |
| wueric | 0:2deb247ab4bd | 30 | typedef TimeoutMultipleSerial* irobotUARTPort_t; |
| wueric | 0:2deb247ab4bd | 31 | |
| wueric | 0:2deb247ab4bd | 32 | /// Baud rate codes |
| wueric | 0:2deb247ab4bd | 33 | typedef enum{ |
| wueric | 0:2deb247ab4bd | 34 | IROBOT_BAUD_300 = 0, ///< UART baud rate 300bps |
| wueric | 0:2deb247ab4bd | 35 | IROBOT_BAUD_600 = 1, ///< UART baud rate 600bps |
| wueric | 0:2deb247ab4bd | 36 | IROBOT_BAUD_1200 = 2, ///< UART baud rate 1200bps |
| wueric | 0:2deb247ab4bd | 37 | IROBOT_BAUD_2400 = 3, ///< UART baud rate 2400bps |
| wueric | 0:2deb247ab4bd | 38 | IROBOT_BAUD_4800 = 4, ///< UART baud rate 4800bps |
| wueric | 0:2deb247ab4bd | 39 | IROBOT_BAUD_9600 = 5, ///< UART baud rate 9600bps |
| wueric | 0:2deb247ab4bd | 40 | IROBOT_BAUD_14400 = 6, ///< UART baud rate 14400bps |
| wueric | 0:2deb247ab4bd | 41 | IROBOT_BAUD_19200 = 7, ///< UART baud rate 19200bps |
| wueric | 0:2deb247ab4bd | 42 | IROBOT_BAUD_28800 = 8, ///< UART baud rate 28800bps |
| wueric | 0:2deb247ab4bd | 43 | IROBOT_BAUD_38400 = 9, ///< UART baud rate 38400bps |
| wueric | 0:2deb247ab4bd | 44 | IROBOT_BAUD_57600 = 10, ///< UART baud rate 57600bps |
| wueric | 0:2deb247ab4bd | 45 | IROBOT_BAUD_115200 = 11 ///< UART baud rate 115200bps \warning UNSTABLE |
| wueric | 0:2deb247ab4bd | 46 | } irobotBaud_t; |
| wueric | 0:2deb247ab4bd | 47 | |
| wueric | 0:2deb247ab4bd | 48 | /// Opens a UART session configured for the iRobot |
| wueric | 0:2deb247ab4bd | 49 | /// \return error code |
| wueric | 0:2deb247ab4bd | 50 | int32_t irobotUARTOpen( |
| wueric | 0:2deb247ab4bd | 51 | const irobotUARTPort_t port, ///< [in] UART port |
| wueric | 0:2deb247ab4bd | 52 | const irobotBaud_t baud ///< [in] baud rate of the port |
| wueric | 0:2deb247ab4bd | 53 | ); |
| wueric | 0:2deb247ab4bd | 54 | |
| wueric | 0:2deb247ab4bd | 55 | /// Closes the UART port connected to iRobot. The port must be reinitialized before reuse. |
| wueric | 0:2deb247ab4bd | 56 | /// \return error code |
| wueric | 0:2deb247ab4bd | 57 | int32_t irobotUARTClose( |
| wueric | 0:2deb247ab4bd | 58 | const irobotUARTPort_t port ///< [in] UART port |
| wueric | 0:2deb247ab4bd | 59 | ); |
| wueric | 0:2deb247ab4bd | 60 | |
| wueric | 0:2deb247ab4bd | 61 | /// Read data from the UART receive buffer until # have been |
| wueric | 0:2deb247ab4bd | 62 | /// received, or until a timeout occurs. A negative timeout means wait indefinitely. |
| wueric | 0:2deb247ab4bd | 63 | /// Read bytes are pushed to the queue; if the queue is full, its oldest bytes are dropped. |
| wueric | 0:2deb247ab4bd | 64 | /// \return error code |
| wueric | 0:2deb247ab4bd | 65 | int32_t irobotUARTRead( |
| wueric | 0:2deb247ab4bd | 66 | const irobotUARTPort_t port, ///< [in] UART port |
| wueric | 0:2deb247ab4bd | 67 | xqueue_t * const queue, ///< [out]Queue to receive read data |
| wueric | 0:2deb247ab4bd | 68 | size_t nData ///< [in] Number of bytes to read |
| wueric | 0:2deb247ab4bd | 69 | ); |
| wueric | 0:2deb247ab4bd | 70 | |
| wueric | 0:2deb247ab4bd | 71 | /// Read data from the UART receive buffer until # have been |
| wueric | 0:2deb247ab4bd | 72 | /// received, or until a timeout occurs. A negative timeout means wait indefinitely. |
| wueric | 0:2deb247ab4bd | 73 | /// \return error code |
| wueric | 0:2deb247ab4bd | 74 | int32_t irobotUARTReadRaw( |
| wueric | 0:2deb247ab4bd | 75 | const irobotUARTPort_t port, ///< [in] UART port |
| wueric | 0:2deb247ab4bd | 76 | uint8_t * const data, ///< [out]Buffer to receive read data |
| wueric | 0:2deb247ab4bd | 77 | const size_t nData ///< [in] Number of bytes to read |
| wueric | 0:2deb247ab4bd | 78 | ); |
| wueric | 0:2deb247ab4bd | 79 | |
| wueric | 0:2deb247ab4bd | 80 | /// Writes a queue to the UART port. If not enough space is available in the FIFO, |
| wueric | 0:2deb247ab4bd | 81 | /// this function blocks until sufficient space is available or a timeout occurs. |
| wueric | 0:2deb247ab4bd | 82 | /// Elements written are popped from the queue. |
| wueric | 0:2deb247ab4bd | 83 | /// \return error code |
| wueric | 0:2deb247ab4bd | 84 | int32_t irobotUARTWrite( |
| wueric | 0:2deb247ab4bd | 85 | const irobotUARTPort_t port, ///< [in] UART port to access |
| wueric | 0:2deb247ab4bd | 86 | xqueue_t * const queue ///< [in] Queue data to write; all will be written |
| wueric | 0:2deb247ab4bd | 87 | ); |
| wueric | 0:2deb247ab4bd | 88 | |
| wueric | 0:2deb247ab4bd | 89 | /// Writes data to the UART port. If not enough space is available in the FIFO, |
| wueric | 0:2deb247ab4bd | 90 | /// this function blocks until sufficient space is available or a timeout occurs. |
| wueric | 0:2deb247ab4bd | 91 | /// \return error code |
| wueric | 0:2deb247ab4bd | 92 | int32_t irobotUARTWriteRaw( |
| wueric | 0:2deb247ab4bd | 93 | const irobotUARTPort_t port, ///< [in] UART port to access |
| wueric | 0:2deb247ab4bd | 94 | const uint8_t * const data, ///< [in] Array of data to write |
| wueric | 0:2deb247ab4bd | 95 | const size_t nData ///< [in] Size of data array |
| wueric | 0:2deb247ab4bd | 96 | ); |
| wueric | 0:2deb247ab4bd | 97 | |
| wueric | 0:2deb247ab4bd | 98 | /// Clears the UART receive buffer. |
| wueric | 0:2deb247ab4bd | 99 | /// \return error code |
| wueric | 0:2deb247ab4bd | 100 | int32_t irobotUARTClear( |
| wueric | 0:2deb247ab4bd | 101 | const irobotUARTPort_t port ///< [in] UART port to access |
| wueric | 0:2deb247ab4bd | 102 | ); |
| wueric | 0:2deb247ab4bd | 103 | |
| wueric | 0:2deb247ab4bd | 104 | #endif // _IROBOT_UART_H |
