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.
Dependents: 3_Test_AFE 1_Test_Flash_ADC_RTT
retarget_segger_rtt.cpp
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.cpp 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 "retarget_segger_rtt.h" 00028 #include "platform/mbed_retarget.h" 00029 #include "platform/mbed_poll.h" 00030 00031 namespace mbed { 00032 00033 // retarget stdin/stdout/stderr to Segger RTT 00034 static SeggerRTT fhSeggerRtt; 00035 FileHandle *mbed_target_override_console(int fd) { 00036 return &fhSeggerRtt; 00037 } 00038 00039 ssize_t SeggerRTT::write(const void *buffer, size_t size) { 00040 // write the buffer content to the terminal 00041 return SEGGER_RTT_Write(0, buffer, size); 00042 } 00043 00044 ssize_t SeggerRTT::read(void *buffer, size_t size) { 00045 // wait until a character becomes available 00046 while (!SEGGER_RTT_HasKey()) {} 00047 00048 // read the characters from the terminal into the buffer 00049 return SEGGER_RTT_Read(0, buffer, size); 00050 } 00051 00052 short SeggerRTT::poll(short events) const { 00053 short revents = 0; 00054 if ((events & POLLIN) && SEGGER_RTT_HasKey()) { 00055 revents |= POLLIN; 00056 } 00057 if (events & POLLOUT) { 00058 revents |= POLLOUT; 00059 } 00060 return revents; 00061 } 00062 }
Generated on Tue Jul 12 2022 22:00:51 by
1.7.2