0x6d61726b / mbed-os-retarget-segger-rtt

Dependents:   3_Test_AFE 1_Test_Flash_ADC_RTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers retarget_segger_rtt.h Source File

retarget_segger_rtt.h

00001 //----------------------------------------------------------------------------
00002 // Namespace:   mbed
00003 // Class:       SeggerRTT
00004 // Description: Alternative stdio read/write interface function for Segger RTT
00005 // Copyright:   (c) 2017-2019 Mark <0x6d61726b@gmail.com>
00006 // License:     MIT License
00007 // SVN:         $Id: retarget_segger_rtt.h 382 2019-05-18 22:37:59Z 0x6d61726b $
00008 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00009 // Permission is hereby granted, free of charge, to any person obtaining a
00010 // copy of this software and associated documentation files (the "Software"),
00011 // to deal in the Software without restriction, including without limitation
00012 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
00013 // and/or sell copies of the Software, and to permit persons to whom the
00014 // Software is furnished to do so, subject to the following conditions:
00015 // 
00016 // The above copyright notice and this permission notice shall be included in
00017 // all copies or substantial portions of the Software.
00018 // 
00019 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00022 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00024 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00025 // DEALINGS IN THE SOFTWARE.
00026 //----------------------------------------------------------------------------
00027 #include "platform/FileHandle.h"
00028 #include "SeggerRTT/SEGGER_RTT.h"
00029 
00030 namespace mbed {
00031     
00032     /** Class SeggerRTT
00033     *
00034     *  An interface to perform file-like operations for Segger RTT.
00035     *  The "file" in this implementation is the Segger RTT terminal itself.
00036     */
00037     class SeggerRTT : public FileHandle {
00038     public:
00039         /** Write the contents of a buffer to the terminal
00040          *
00041          *  @param buffer   The buffer to write from
00042          *  @param size     The number of bytes to write 
00043          *  @return         The number of bytes written, negative error on failure
00044          */
00045         virtual ssize_t write(const void *buffer, size_t size);
00046         
00047         /** Read the contents from the terminal into a buffer (blocking access)
00048          *
00049          *  @param buffer   The buffer to read in to
00050          *  @param size     The number of bytes to read
00051          *  @return         The number of bytes read, 0 at end of file, negative error on failure
00052          */
00053         virtual ssize_t read(void *buffer, size_t size);
00054         
00055         /** Move the file position to a given offset from a given location
00056          *  (this operation is not supported by SeggerRTT)
00057          *
00058          *  @return         -ESPIPE (illegal seek)
00059          */
00060         virtual off_t seek(off_t offset, int whence = SEEK_SET) {
00061             return -ESPIPE;
00062         }
00063         
00064         /** Get the size of the file
00065          *  (this operation is not supported by SeggerRTT)
00066          *
00067          *  @return         -EINVAL (invalid argument)
00068          */
00069         virtual off_t size() {
00070             return -EINVAL;
00071         }
00072         
00073         /** Check if the file in an interactive terminal device
00074          *
00075          *  @return         true (SeggerRTT is a terminal)
00076          */
00077         virtual int isatty() {
00078             return true;
00079         }
00080         
00081         /** Close the file to the terminal
00082          *
00083          *  @return         0 on success (no explicit open/close possible)
00084          */
00085         virtual int close() {
00086             return 0;
00087         }
00088         
00089         /** Check for poll event flags
00090          * Call is non-blocking - returns instantaneous state of events.
00091          *
00092          * @param events        bitmask of poll events we're interested in - POLLIN/POLLOUT etc.
00093          *
00094          * @returns             bitmask of poll events that have occurred.
00095          */
00096         virtual short poll(short events) const;
00097     };
00098 }