Eric Wu / Mbed 2 deprecated WifiRobot

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers irobotUART.h Source File

irobotUART.h

Go to the documentation of this file.
00001 /** \file irobotUART.h
00002  *
00003  * UART wrappers for the iRobot Create. This library is not architecture
00004                 specific, so these are only wrappers for UART functions that must
00005                 be defined for your architecture.
00006  *
00007  * \author Jeff C. Jensen
00008  * \date 2013-12-09
00009  * \copyright Copyright (C) 2013, Jeff C. Jensen, Edward A. Lee, and Sanjit A. Seshia.
00010  *            This software accompanies An Introductory Lab in Embedded and Cyber-Physical Systems
00011  *            and is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0
00012  *            Unported License. See http://leeseshia.org/lab.
00013 
00014  * Dependencies and typedef for irobotUARTPort_t modified to
00015         support implementation for mbed
00016  */
00017 
00018 #ifndef _IROBOT_UART_H
00019 #define _IROBOT_UART_H
00020 
00021 #include "irobotTypes.h"
00022 #include "irobotError.h"
00023 #include "xqueue.h"
00024 #include "mbed.h"
00025 #include "TimeoutMultipleSerial.h"
00026 //#include "UART.h"
00027 
00028 /// UART port wrapper; change for your UART API
00029 //typedef MyRio_Uart * irobotUARTPort_t;
00030 typedef TimeoutMultipleSerial* irobotUARTPort_t;
00031 
00032 /// Baud rate codes
00033 typedef enum{
00034     IROBOT_BAUD_300     = 0,    ///< UART baud rate 300bps
00035     IROBOT_BAUD_600     = 1,    ///< UART baud rate 600bps
00036     IROBOT_BAUD_1200    = 2,    ///< UART baud rate 1200bps
00037     IROBOT_BAUD_2400    = 3,    ///< UART baud rate 2400bps
00038     IROBOT_BAUD_4800    = 4,    ///< UART baud rate 4800bps
00039     IROBOT_BAUD_9600    = 5,    ///< UART baud rate 9600bps
00040     IROBOT_BAUD_14400   = 6,    ///< UART baud rate 14400bps
00041     IROBOT_BAUD_19200   = 7,    ///< UART baud rate 19200bps
00042     IROBOT_BAUD_28800   = 8,    ///< UART baud rate 28800bps
00043     IROBOT_BAUD_38400   = 9,    ///< UART baud rate 38400bps
00044     IROBOT_BAUD_57600   = 10,   ///< UART baud rate 57600bps
00045     IROBOT_BAUD_115200  = 11    ///< UART baud rate 115200bps   \warning UNSTABLE
00046 } irobotBaud_t;
00047 
00048 /// Opens a UART session configured for the iRobot
00049 /// \return error code
00050 int32_t irobotUARTOpen(
00051     const irobotUARTPort_t  port,       ///< [in] UART port
00052     const irobotBaud_t      baud        ///< [in] baud rate of the port
00053 );
00054 
00055 /// Closes the UART port connected to iRobot. The port must be reinitialized before reuse.
00056 /// \return error code
00057 int32_t irobotUARTClose(
00058     const irobotUARTPort_t  port        ///< [in] UART port
00059 );
00060 
00061 /// Read data from the UART receive buffer until # have been
00062 /// received, or until a timeout occurs. A negative timeout means wait indefinitely.
00063 /// Read bytes are pushed to the queue; if the queue is full, its oldest bytes are dropped.
00064 /// \return error code
00065 int32_t irobotUARTRead(
00066     const irobotUARTPort_t  port,       ///< [in] UART port
00067     xqueue_t * const        queue,      ///< [out]Queue to receive read data
00068     size_t                  nData       ///< [in] Number of bytes to read
00069 );
00070 
00071 /// Read data from the UART receive buffer until # have been
00072 /// received, or until a timeout occurs. A negative timeout means wait indefinitely.
00073 /// \return error code
00074 int32_t irobotUARTReadRaw(
00075     const irobotUARTPort_t  port,       ///< [in] UART port
00076     uint8_t * const         data,       ///< [out]Buffer to receive read data
00077     const size_t            nData       ///< [in] Number of bytes to read
00078 );
00079 
00080 /// Writes a queue to the UART port. If not enough space is available in the FIFO,
00081 /// this function blocks until sufficient space is available or a timeout occurs.
00082 /// Elements written are popped from the queue.
00083 /// \return error code
00084 int32_t irobotUARTWrite(
00085     const irobotUARTPort_t  port,       ///< [in] UART port to access
00086     xqueue_t * const        queue       ///< [in] Queue data to write; all will be written
00087 );
00088 
00089 /// Writes data to the UART port. If not enough space is available in the FIFO,
00090 /// this function blocks until sufficient space is available or a timeout occurs.
00091 /// \return error code
00092 int32_t irobotUARTWriteRaw(
00093     const irobotUARTPort_t  port,       ///< [in] UART port to access
00094     const uint8_t * const   data,       ///< [in] Array of data to write
00095     const size_t            nData       ///< [in] Size of data array
00096 );
00097 
00098 /// Clears the UART receive buffer.
00099 /// \return error code
00100 int32_t irobotUARTClear(
00101     const irobotUARTPort_t  port        ///< [in] UART port to access
00102 );
00103 
00104 #endif  // _IROBOT_UART_H