Segger rtt lib
Dependents: acnSensa_LIS acd52832_Indoor_Posit_Peripheral acd52832_Indoor_Posit_Central iBeacon acnsensa ... more
SEGGER_RTT_Syscalls_GCC.c@0:e61e7fc7cfe1, 2017-09-22 (annotated)
- Committer:
- jurica238814
- Date:
- Fri Sep 22 10:36:47 2017 +0000
- Revision:
- 0:e61e7fc7cfe1
- Child:
- 1:5acbf302ee01
SEGER RTT library init commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 0:e61e7fc7cfe1 | 1 | /********************************************************************* |
jurica238814 | 0:e61e7fc7cfe1 | 2 | * SEGGER MICROCONTROLLER GmbH & Co. KG * |
jurica238814 | 0:e61e7fc7cfe1 | 3 | * Solutions for real time microcontroller applications * |
jurica238814 | 0:e61e7fc7cfe1 | 4 | ********************************************************************** |
jurica238814 | 0:e61e7fc7cfe1 | 5 | * * |
jurica238814 | 0:e61e7fc7cfe1 | 6 | * (c) 2014 - 2015 SEGGER Microcontroller GmbH & Co. KG * |
jurica238814 | 0:e61e7fc7cfe1 | 7 | * * |
jurica238814 | 0:e61e7fc7cfe1 | 8 | * www.segger.com Support: support@segger.com * |
jurica238814 | 0:e61e7fc7cfe1 | 9 | * * |
jurica238814 | 0:e61e7fc7cfe1 | 10 | ********************************************************************** |
jurica238814 | 0:e61e7fc7cfe1 | 11 | * * |
jurica238814 | 0:e61e7fc7cfe1 | 12 | * All rights reserved. * |
jurica238814 | 0:e61e7fc7cfe1 | 13 | * * |
jurica238814 | 0:e61e7fc7cfe1 | 14 | * * This software may in its unmodified form be freely redistributed * |
jurica238814 | 0:e61e7fc7cfe1 | 15 | * in source form. * |
jurica238814 | 0:e61e7fc7cfe1 | 16 | * * The source code may be modified, provided the source code * |
jurica238814 | 0:e61e7fc7cfe1 | 17 | * retains the above copyright notice, this list of conditions and * |
jurica238814 | 0:e61e7fc7cfe1 | 18 | * the following disclaimer. * |
jurica238814 | 0:e61e7fc7cfe1 | 19 | * * Modified versions of this software in source or linkable form * |
jurica238814 | 0:e61e7fc7cfe1 | 20 | * may not be distributed without prior consent of SEGGER. * |
jurica238814 | 0:e61e7fc7cfe1 | 21 | * * This software may only be used for communication with SEGGER * |
jurica238814 | 0:e61e7fc7cfe1 | 22 | * J-Link debug probes. * |
jurica238814 | 0:e61e7fc7cfe1 | 23 | * * |
jurica238814 | 0:e61e7fc7cfe1 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * |
jurica238814 | 0:e61e7fc7cfe1 | 25 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * |
jurica238814 | 0:e61e7fc7cfe1 | 26 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * |
jurica238814 | 0:e61e7fc7cfe1 | 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * |
jurica238814 | 0:e61e7fc7cfe1 | 28 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * |
jurica238814 | 0:e61e7fc7cfe1 | 29 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * |
jurica238814 | 0:e61e7fc7cfe1 | 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * |
jurica238814 | 0:e61e7fc7cfe1 | 31 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * |
jurica238814 | 0:e61e7fc7cfe1 | 32 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * |
jurica238814 | 0:e61e7fc7cfe1 | 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * |
jurica238814 | 0:e61e7fc7cfe1 | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * |
jurica238814 | 0:e61e7fc7cfe1 | 35 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * |
jurica238814 | 0:e61e7fc7cfe1 | 36 | * DAMAGE. * |
jurica238814 | 0:e61e7fc7cfe1 | 37 | * * |
jurica238814 | 0:e61e7fc7cfe1 | 38 | ********************************************************************** |
jurica238814 | 0:e61e7fc7cfe1 | 39 | -------- END-OF-HEADER --------------------------------------------- |
jurica238814 | 0:e61e7fc7cfe1 | 40 | File : SEGGER_RTT_Syscalls_GCC.c |
jurica238814 | 0:e61e7fc7cfe1 | 41 | Purpose : Low-level functions for using printf() via RTT in GCC. |
jurica238814 | 0:e61e7fc7cfe1 | 42 | To use RTT for printf output, include this file in your |
jurica238814 | 0:e61e7fc7cfe1 | 43 | application. |
jurica238814 | 0:e61e7fc7cfe1 | 44 | ---------------------------------------------------------------------- |
jurica238814 | 0:e61e7fc7cfe1 | 45 | */ |
jurica238814 | 0:e61e7fc7cfe1 | 46 | //#include <reent.h> // required for _write_r |
jurica238814 | 0:e61e7fc7cfe1 | 47 | #include "SEGGER_RTT.h" |
jurica238814 | 0:e61e7fc7cfe1 | 48 | #include <stdint.h> |
jurica238814 | 0:e61e7fc7cfe1 | 49 | typedef uint32_t size_t; |
jurica238814 | 0:e61e7fc7cfe1 | 50 | |
jurica238814 | 0:e61e7fc7cfe1 | 51 | /********************************************************************* |
jurica238814 | 0:e61e7fc7cfe1 | 52 | * |
jurica238814 | 0:e61e7fc7cfe1 | 53 | * Types |
jurica238814 | 0:e61e7fc7cfe1 | 54 | * |
jurica238814 | 0:e61e7fc7cfe1 | 55 | ********************************************************************** |
jurica238814 | 0:e61e7fc7cfe1 | 56 | */ |
jurica238814 | 0:e61e7fc7cfe1 | 57 | // |
jurica238814 | 0:e61e7fc7cfe1 | 58 | // If necessary define the _reent struct |
jurica238814 | 0:e61e7fc7cfe1 | 59 | // to match the one passed by the used standard library. |
jurica238814 | 0:e61e7fc7cfe1 | 60 | // |
jurica238814 | 0:e61e7fc7cfe1 | 61 | struct _reent; |
jurica238814 | 0:e61e7fc7cfe1 | 62 | |
jurica238814 | 0:e61e7fc7cfe1 | 63 | /********************************************************************* |
jurica238814 | 0:e61e7fc7cfe1 | 64 | * |
jurica238814 | 0:e61e7fc7cfe1 | 65 | * Function prototypes |
jurica238814 | 0:e61e7fc7cfe1 | 66 | * |
jurica238814 | 0:e61e7fc7cfe1 | 67 | ********************************************************************** |
jurica238814 | 0:e61e7fc7cfe1 | 68 | */ |
jurica238814 | 0:e61e7fc7cfe1 | 69 | int _write(int file, char *ptr, int len); |
jurica238814 | 0:e61e7fc7cfe1 | 70 | int _write_r(struct _reent *r, int file, const void *ptr, size_t len); |
jurica238814 | 0:e61e7fc7cfe1 | 71 | |
jurica238814 | 0:e61e7fc7cfe1 | 72 | /********************************************************************* |
jurica238814 | 0:e61e7fc7cfe1 | 73 | * |
jurica238814 | 0:e61e7fc7cfe1 | 74 | * Global functions |
jurica238814 | 0:e61e7fc7cfe1 | 75 | * |
jurica238814 | 0:e61e7fc7cfe1 | 76 | ********************************************************************** |
jurica238814 | 0:e61e7fc7cfe1 | 77 | */ |
jurica238814 | 0:e61e7fc7cfe1 | 78 | |
jurica238814 | 0:e61e7fc7cfe1 | 79 | /********************************************************************* |
jurica238814 | 0:e61e7fc7cfe1 | 80 | * |
jurica238814 | 0:e61e7fc7cfe1 | 81 | * _write() |
jurica238814 | 0:e61e7fc7cfe1 | 82 | * |
jurica238814 | 0:e61e7fc7cfe1 | 83 | * Function description |
jurica238814 | 0:e61e7fc7cfe1 | 84 | * Low-level write function. |
jurica238814 | 0:e61e7fc7cfe1 | 85 | * libc subroutines will use this system routine for output to all files, |
jurica238814 | 0:e61e7fc7cfe1 | 86 | * including stdout. |
jurica238814 | 0:e61e7fc7cfe1 | 87 | * Write data via RTT. |
jurica238814 | 0:e61e7fc7cfe1 | 88 | */ |
jurica238814 | 0:e61e7fc7cfe1 | 89 | int _write(int file, char *ptr, int len) { |
jurica238814 | 0:e61e7fc7cfe1 | 90 | (void) file; /* Not used, avoid warning */ |
jurica238814 | 0:e61e7fc7cfe1 | 91 | SEGGER_RTT_Write(0, ptr, len); |
jurica238814 | 0:e61e7fc7cfe1 | 92 | return len; |
jurica238814 | 0:e61e7fc7cfe1 | 93 | } |
jurica238814 | 0:e61e7fc7cfe1 | 94 | |
jurica238814 | 0:e61e7fc7cfe1 | 95 | /********************************************************************* |
jurica238814 | 0:e61e7fc7cfe1 | 96 | * |
jurica238814 | 0:e61e7fc7cfe1 | 97 | * _write_r() |
jurica238814 | 0:e61e7fc7cfe1 | 98 | * |
jurica238814 | 0:e61e7fc7cfe1 | 99 | * Function description |
jurica238814 | 0:e61e7fc7cfe1 | 100 | * Low-level reentrant write function. |
jurica238814 | 0:e61e7fc7cfe1 | 101 | * libc subroutines will use this system routine for output to all files, |
jurica238814 | 0:e61e7fc7cfe1 | 102 | * including stdout. |
jurica238814 | 0:e61e7fc7cfe1 | 103 | * Write data via RTT. |
jurica238814 | 0:e61e7fc7cfe1 | 104 | */ |
jurica238814 | 0:e61e7fc7cfe1 | 105 | int _write_r(struct _reent *r, int file, const void *ptr, size_t len) { |
jurica238814 | 0:e61e7fc7cfe1 | 106 | (void) file; /* Not used, avoid warning */ |
jurica238814 | 0:e61e7fc7cfe1 | 107 | (void) r; /* Not used, avoid warning */ |
jurica238814 | 0:e61e7fc7cfe1 | 108 | SEGGER_RTT_Write(0, ptr, len); |
jurica238814 | 0:e61e7fc7cfe1 | 109 | return len; |
jurica238814 | 0:e61e7fc7cfe1 | 110 | } |
jurica238814 | 0:e61e7fc7cfe1 | 111 | |
jurica238814 | 0:e61e7fc7cfe1 | 112 | /****** End Of File *************************************************/ |