This class provides an API to communicate with a u-blox GNSS chip. The files here were originally part of the C027_Support library (https://developer.mbed.org/teams/ublox/code/C027_Support/ at revision 138:dafbbf31bf76) but have been separated out, primarily for use on the u-blox C030 board where the cellular interace portion of the C027_Support library will instead be provided through the new mbed Cellular API.

Dependents:   example-ublox-at-cellular-interface-ext example-low-power-sleep example-C030-out-of-box-demo example-C030-out-of-box-demo ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers serial_pipe.h Source File

serial_pipe.h

00001 /* Copyright (c) 2017 Michael Ammann
00002  *
00003  * Licensed under the Apache License, Version 2.0 (the "License");
00004  * you may not use this file except in compliance with the License.
00005  * You may obtain a copy of the License at
00006  *
00007  *     http://www.apache.org/licenses/LICENSE-2.0
00008  *
00009  * Unless required by applicable law or agreed to in writing, software
00010  * distributed under the License is distributed on an "AS IS" BASIS,
00011  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012  * See the License for the specific language governing permissions and
00013  * limitations under the License.
00014  */
00015 
00016 #ifndef SERIAL_PIPE_H
00017 #define SERIAL_PIPE_H
00018 
00019 #include "mbed.h"
00020 #include "pipe.h"
00021 
00022 #define _SerialPipeBase SerialBase //!< base class used by this class
00023 
00024 /** Buffered serial interface (rtos capable/interrupt driven)
00025 */
00026 class SerialPipe : public _SerialPipeBase
00027 {
00028 public:
00029     /** Constructor
00030         \param tx the trasmitting pin
00031         \param rx the receiving pin
00032         \param baudate the serial baud rate
00033         \param rxSize the size of the receiving buffer
00034         \param txSize the size of the transmitting buffer
00035     */
00036     SerialPipe(PinName tx, PinName rx, int baudrate, int rxSize = 128, int txSize = 128);
00037     
00038     /** Destructor
00039     */
00040     virtual ~SerialPipe(void);
00041     
00042     // tx channel
00043     //----------------------------------------------------
00044     
00045     /** check if writable 
00046         return the number of free bytes
00047     */
00048     int writeable(void);
00049     
00050     /** send a character (blocking)
00051         \param c the character to send
00052         \return c
00053     */
00054     int putc(int c);
00055     
00056     /** send a buffer
00057         \param buffer the buffer to send
00058         \param length the size of the buffer to send
00059         \param blocking, if true this function will block 
00060                until all bytes placed in the buffer. 
00061         \return the number of bytes written 
00062     */
00063     int put(const void* buffer, int length, bool blocking);
00064     
00065     // rx channel
00066     //----------------------------------------------------
00067     
00068     /** check if readable
00069      *
00070         \return the size available in the buffer.
00071     */
00072     int readable(void);
00073     
00074     /** receive one character from the serial port (blocking)
00075         \param the character received 
00076     */
00077     int getc(void);
00078     
00079     /** read a buffer from the serial port
00080         \param pointer to the buffer to read.
00081         \param length number of bytes to read 
00082         \param blocking true if all bytes shall be read. false if only the available bytes.
00083         \return the number of bytes read.
00084     */
00085     int get(void* buffer, int length, bool blocking);
00086     
00087 protected:
00088     //! receive interrupt routine
00089     void rxIrqBuf(void);
00090     //! transmit interrupt woutine 
00091     void txIrqBuf(void);
00092     //! start transmission helper
00093     void txStart(void);
00094     //! move bytes to hardware
00095     void txCopy(void);
00096     Pipe<char>  _pipeRx; //!< receive pipe
00097     Pipe<char>  _pipeTx; //!< transmit pipe
00098 };
00099 
00100 #endif
00101 
00102 // End Of File