Sample program on how to use the LIS2MDL sensor on the RAKWirelss iTracker module

Committer:
knaresh89
Date:
Mon Feb 12 05:04:29 2018 +0000
Revision:
0:a8bfd25ff975
Sample program on how to use the BME280 sensor on the RAKWirelss iTracker module

Who changed what in which revision?

UserRevisionLine numberNew contents of line
knaresh89 0:a8bfd25ff975 1 /*********************************************************************
knaresh89 0:a8bfd25ff975 2 * SEGGER MICROCONTROLLER GmbH & Co. KG *
knaresh89 0:a8bfd25ff975 3 * Solutions for real time microcontroller applications *
knaresh89 0:a8bfd25ff975 4 **********************************************************************
knaresh89 0:a8bfd25ff975 5 * *
knaresh89 0:a8bfd25ff975 6 * (c) 2014 - 2016 SEGGER Microcontroller GmbH & Co. KG *
knaresh89 0:a8bfd25ff975 7 * *
knaresh89 0:a8bfd25ff975 8 * www.segger.com Support: support@segger.com *
knaresh89 0:a8bfd25ff975 9 * *
knaresh89 0:a8bfd25ff975 10 **********************************************************************
knaresh89 0:a8bfd25ff975 11 * *
knaresh89 0:a8bfd25ff975 12 * SEGGER RTT * Real Time Transfer for embedded targets *
knaresh89 0:a8bfd25ff975 13 * *
knaresh89 0:a8bfd25ff975 14 **********************************************************************
knaresh89 0:a8bfd25ff975 15 * *
knaresh89 0:a8bfd25ff975 16 * All rights reserved. *
knaresh89 0:a8bfd25ff975 17 * *
knaresh89 0:a8bfd25ff975 18 * SEGGER strongly recommends to not make any changes *
knaresh89 0:a8bfd25ff975 19 * to or modify the source code of this software in order to stay *
knaresh89 0:a8bfd25ff975 20 * compatible with the RTT protocol and J-Link. *
knaresh89 0:a8bfd25ff975 21 * *
knaresh89 0:a8bfd25ff975 22 * Redistribution and use in source and binary forms, with or *
knaresh89 0:a8bfd25ff975 23 * without modification, are permitted provided that the following *
knaresh89 0:a8bfd25ff975 24 * conditions are met: *
knaresh89 0:a8bfd25ff975 25 * *
knaresh89 0:a8bfd25ff975 26 * o Redistributions of source code must retain the above copyright *
knaresh89 0:a8bfd25ff975 27 * notice, this list of conditions and the following disclaimer. *
knaresh89 0:a8bfd25ff975 28 * *
knaresh89 0:a8bfd25ff975 29 * o Redistributions in binary form must reproduce the above *
knaresh89 0:a8bfd25ff975 30 * copyright notice, this list of conditions and the following *
knaresh89 0:a8bfd25ff975 31 * disclaimer in the documentation and/or other materials provided *
knaresh89 0:a8bfd25ff975 32 * with the distribution. *
knaresh89 0:a8bfd25ff975 33 * *
knaresh89 0:a8bfd25ff975 34 * o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
knaresh89 0:a8bfd25ff975 35 * nor the names of its contributors may be used to endorse or *
knaresh89 0:a8bfd25ff975 36 * promote products derived from this software without specific *
knaresh89 0:a8bfd25ff975 37 * prior written permission. *
knaresh89 0:a8bfd25ff975 38 * *
knaresh89 0:a8bfd25ff975 39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
knaresh89 0:a8bfd25ff975 40 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
knaresh89 0:a8bfd25ff975 41 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
knaresh89 0:a8bfd25ff975 42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
knaresh89 0:a8bfd25ff975 43 * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
knaresh89 0:a8bfd25ff975 44 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
knaresh89 0:a8bfd25ff975 45 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
knaresh89 0:a8bfd25ff975 46 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
knaresh89 0:a8bfd25ff975 47 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
knaresh89 0:a8bfd25ff975 48 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
knaresh89 0:a8bfd25ff975 49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
knaresh89 0:a8bfd25ff975 50 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
knaresh89 0:a8bfd25ff975 51 * DAMAGE. *
knaresh89 0:a8bfd25ff975 52 * *
knaresh89 0:a8bfd25ff975 53 **********************************************************************
knaresh89 0:a8bfd25ff975 54 ---------------------------END-OF-HEADER------------------------------
knaresh89 0:a8bfd25ff975 55 File : SEGGER_RTT.h
knaresh89 0:a8bfd25ff975 56 Purpose : Implementation of SEGGER real-time transfer which allows
knaresh89 0:a8bfd25ff975 57 real-time communication on targets which support debugger
knaresh89 0:a8bfd25ff975 58 memory accesses while the CPU is running.
knaresh89 0:a8bfd25ff975 59 Revision: $Rev: 4351 $
knaresh89 0:a8bfd25ff975 60 ----------------------------------------------------------------------
knaresh89 0:a8bfd25ff975 61 */
knaresh89 0:a8bfd25ff975 62
knaresh89 0:a8bfd25ff975 63 #ifndef SEGGER_RTT_H
knaresh89 0:a8bfd25ff975 64 #define SEGGER_RTT_H
knaresh89 0:a8bfd25ff975 65
knaresh89 0:a8bfd25ff975 66 #include "SEGGER_RTT_Conf.h"
knaresh89 0:a8bfd25ff975 67
knaresh89 0:a8bfd25ff975 68 /*********************************************************************
knaresh89 0:a8bfd25ff975 69 *
knaresh89 0:a8bfd25ff975 70 * Defines, fixed
knaresh89 0:a8bfd25ff975 71 *
knaresh89 0:a8bfd25ff975 72 **********************************************************************
knaresh89 0:a8bfd25ff975 73 */
knaresh89 0:a8bfd25ff975 74
knaresh89 0:a8bfd25ff975 75 /*********************************************************************
knaresh89 0:a8bfd25ff975 76 *
knaresh89 0:a8bfd25ff975 77 * Types
knaresh89 0:a8bfd25ff975 78 *
knaresh89 0:a8bfd25ff975 79 **********************************************************************
knaresh89 0:a8bfd25ff975 80 */
knaresh89 0:a8bfd25ff975 81
knaresh89 0:a8bfd25ff975 82 //
knaresh89 0:a8bfd25ff975 83 // Description for a circular buffer (also called "ring buffer")
knaresh89 0:a8bfd25ff975 84 // which is used as up-buffer (T->H)
knaresh89 0:a8bfd25ff975 85 //
knaresh89 0:a8bfd25ff975 86 typedef struct {
knaresh89 0:a8bfd25ff975 87 const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
knaresh89 0:a8bfd25ff975 88 char* pBuffer; // Pointer to start of buffer
knaresh89 0:a8bfd25ff975 89 unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
knaresh89 0:a8bfd25ff975 90 unsigned WrOff; // Position of next item to be written by either target.
knaresh89 0:a8bfd25ff975 91 volatile unsigned RdOff; // Position of next item to be read by host. Must be volatile since it may be modified by host.
knaresh89 0:a8bfd25ff975 92 unsigned Flags; // Contains configuration flags
knaresh89 0:a8bfd25ff975 93 } SEGGER_RTT_BUFFER_UP;
knaresh89 0:a8bfd25ff975 94
knaresh89 0:a8bfd25ff975 95 //
knaresh89 0:a8bfd25ff975 96 // Description for a circular buffer (also called "ring buffer")
knaresh89 0:a8bfd25ff975 97 // which is used as down-buffer (H->T)
knaresh89 0:a8bfd25ff975 98 //
knaresh89 0:a8bfd25ff975 99 typedef struct {
knaresh89 0:a8bfd25ff975 100 const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
knaresh89 0:a8bfd25ff975 101 char* pBuffer; // Pointer to start of buffer
knaresh89 0:a8bfd25ff975 102 unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
knaresh89 0:a8bfd25ff975 103 volatile unsigned WrOff; // Position of next item to be written by host. Must be volatile since it may be modified by host.
knaresh89 0:a8bfd25ff975 104 unsigned RdOff; // Position of next item to be read by target (down-buffer).
knaresh89 0:a8bfd25ff975 105 unsigned Flags; // Contains configuration flags
knaresh89 0:a8bfd25ff975 106 } SEGGER_RTT_BUFFER_DOWN;
knaresh89 0:a8bfd25ff975 107
knaresh89 0:a8bfd25ff975 108 //
knaresh89 0:a8bfd25ff975 109 // RTT control block which describes the number of buffers available
knaresh89 0:a8bfd25ff975 110 // as well as the configuration for each buffer
knaresh89 0:a8bfd25ff975 111 //
knaresh89 0:a8bfd25ff975 112 //
knaresh89 0:a8bfd25ff975 113 typedef struct {
knaresh89 0:a8bfd25ff975 114 char acID[16]; // Initialized to "SEGGER RTT"
knaresh89 0:a8bfd25ff975 115 int MaxNumUpBuffers; // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
knaresh89 0:a8bfd25ff975 116 int MaxNumDownBuffers; // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
knaresh89 0:a8bfd25ff975 117 SEGGER_RTT_BUFFER_UP aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS]; // Up buffers, transferring information up from target via debug probe to host
knaresh89 0:a8bfd25ff975 118 SEGGER_RTT_BUFFER_DOWN aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS]; // Down buffers, transferring information down from host via debug probe to target
knaresh89 0:a8bfd25ff975 119 } SEGGER_RTT_CB;
knaresh89 0:a8bfd25ff975 120
knaresh89 0:a8bfd25ff975 121 /*********************************************************************
knaresh89 0:a8bfd25ff975 122 *
knaresh89 0:a8bfd25ff975 123 * Global data
knaresh89 0:a8bfd25ff975 124 *
knaresh89 0:a8bfd25ff975 125 **********************************************************************
knaresh89 0:a8bfd25ff975 126 */
knaresh89 0:a8bfd25ff975 127 extern SEGGER_RTT_CB _SEGGER_RTT;
knaresh89 0:a8bfd25ff975 128
knaresh89 0:a8bfd25ff975 129 /*********************************************************************
knaresh89 0:a8bfd25ff975 130 *
knaresh89 0:a8bfd25ff975 131 * RTT API functions
knaresh89 0:a8bfd25ff975 132 *
knaresh89 0:a8bfd25ff975 133 **********************************************************************
knaresh89 0:a8bfd25ff975 134 */
knaresh89 0:a8bfd25ff975 135 #ifdef __cplusplus
knaresh89 0:a8bfd25ff975 136 extern "C" {
knaresh89 0:a8bfd25ff975 137 #endif
knaresh89 0:a8bfd25ff975 138 int SEGGER_RTT_AllocDownBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
knaresh89 0:a8bfd25ff975 139 int SEGGER_RTT_AllocUpBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
knaresh89 0:a8bfd25ff975 140 int SEGGER_RTT_ConfigUpBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
knaresh89 0:a8bfd25ff975 141 int SEGGER_RTT_ConfigDownBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
knaresh89 0:a8bfd25ff975 142 int SEGGER_RTT_GetKey (void);
knaresh89 0:a8bfd25ff975 143 unsigned SEGGER_RTT_HasData (unsigned BufferIndex);
knaresh89 0:a8bfd25ff975 144 int SEGGER_RTT_HasKey (void);
knaresh89 0:a8bfd25ff975 145 void SEGGER_RTT_Init (void);
knaresh89 0:a8bfd25ff975 146 unsigned SEGGER_RTT_Read (unsigned BufferIndex, void* pBuffer, unsigned BufferSize);
knaresh89 0:a8bfd25ff975 147 unsigned SEGGER_RTT_ReadNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize);
knaresh89 0:a8bfd25ff975 148 int SEGGER_RTT_SetNameDownBuffer (unsigned BufferIndex, const char* sName);
knaresh89 0:a8bfd25ff975 149 int SEGGER_RTT_SetNameUpBuffer (unsigned BufferIndex, const char* sName);
knaresh89 0:a8bfd25ff975 150 int SEGGER_RTT_SetFlagsDownBuffer (unsigned BufferIndex, unsigned Flags);
knaresh89 0:a8bfd25ff975 151 int SEGGER_RTT_SetFlagsUpBuffer (unsigned BufferIndex, unsigned Flags);
knaresh89 0:a8bfd25ff975 152 int SEGGER_RTT_WaitKey (void);
knaresh89 0:a8bfd25ff975 153 unsigned SEGGER_RTT_Write (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
knaresh89 0:a8bfd25ff975 154 unsigned SEGGER_RTT_WriteNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
knaresh89 0:a8bfd25ff975 155 unsigned SEGGER_RTT_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
knaresh89 0:a8bfd25ff975 156 unsigned SEGGER_RTT_WriteString (unsigned BufferIndex, const char* s);
knaresh89 0:a8bfd25ff975 157 void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
knaresh89 0:a8bfd25ff975 158 //
knaresh89 0:a8bfd25ff975 159 // Function macro for performance optimization
knaresh89 0:a8bfd25ff975 160 //
knaresh89 0:a8bfd25ff975 161 #define SEGGER_RTT_HASDATA(n) (_SEGGER_RTT.aDown[n].WrOff - _SEGGER_RTT.aDown[n].RdOff)
knaresh89 0:a8bfd25ff975 162
knaresh89 0:a8bfd25ff975 163 /*********************************************************************
knaresh89 0:a8bfd25ff975 164 *
knaresh89 0:a8bfd25ff975 165 * RTT "Terminal" API functions
knaresh89 0:a8bfd25ff975 166 *
knaresh89 0:a8bfd25ff975 167 **********************************************************************
knaresh89 0:a8bfd25ff975 168 */
knaresh89 0:a8bfd25ff975 169 int SEGGER_RTT_SetTerminal (char TerminalId);
knaresh89 0:a8bfd25ff975 170 int SEGGER_RTT_TerminalOut (char TerminalId, const char* s);
knaresh89 0:a8bfd25ff975 171
knaresh89 0:a8bfd25ff975 172 /*********************************************************************
knaresh89 0:a8bfd25ff975 173 *
knaresh89 0:a8bfd25ff975 174 * RTT printf functions (require SEGGER_RTT_printf.c)
knaresh89 0:a8bfd25ff975 175 *
knaresh89 0:a8bfd25ff975 176 **********************************************************************
knaresh89 0:a8bfd25ff975 177 */
knaresh89 0:a8bfd25ff975 178 int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
knaresh89 0:a8bfd25ff975 179 #ifdef __cplusplus
knaresh89 0:a8bfd25ff975 180 }
knaresh89 0:a8bfd25ff975 181 #endif
knaresh89 0:a8bfd25ff975 182
knaresh89 0:a8bfd25ff975 183 /*********************************************************************
knaresh89 0:a8bfd25ff975 184 *
knaresh89 0:a8bfd25ff975 185 * Defines
knaresh89 0:a8bfd25ff975 186 *
knaresh89 0:a8bfd25ff975 187 **********************************************************************
knaresh89 0:a8bfd25ff975 188 */
knaresh89 0:a8bfd25ff975 189
knaresh89 0:a8bfd25ff975 190 //
knaresh89 0:a8bfd25ff975 191 // Operating modes. Define behavior if buffer is full (not enough space for entire message)
knaresh89 0:a8bfd25ff975 192 //
knaresh89 0:a8bfd25ff975 193 #define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0U) // Skip. Do not block, output nothing. (Default)
knaresh89 0:a8bfd25ff975 194 #define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1U) // Trim: Do not block, output as much as fits.
knaresh89 0:a8bfd25ff975 195 #define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2U) // Block: Wait until there is space in the buffer.
knaresh89 0:a8bfd25ff975 196 #define SEGGER_RTT_MODE_MASK (3U)
knaresh89 0:a8bfd25ff975 197
knaresh89 0:a8bfd25ff975 198 //
knaresh89 0:a8bfd25ff975 199 // Control sequences, based on ANSI.
knaresh89 0:a8bfd25ff975 200 // Can be used to control color, and clear the screen
knaresh89 0:a8bfd25ff975 201 //
knaresh89 0:a8bfd25ff975 202 #define RTT_CTRL_RESET "" // Reset to default colors
knaresh89 0:a8bfd25ff975 203 #define RTT_CTRL_CLEAR "" // Clear screen, reposition cursor to top left
knaresh89 0:a8bfd25ff975 204
knaresh89 0:a8bfd25ff975 205 #define RTT_CTRL_TEXT_BLACK ""
knaresh89 0:a8bfd25ff975 206 #define RTT_CTRL_TEXT_RED ""
knaresh89 0:a8bfd25ff975 207 #define RTT_CTRL_TEXT_GREEN ""
knaresh89 0:a8bfd25ff975 208 #define RTT_CTRL_TEXT_YELLOW ""
knaresh89 0:a8bfd25ff975 209 #define RTT_CTRL_TEXT_BLUE ""
knaresh89 0:a8bfd25ff975 210 #define RTT_CTRL_TEXT_MAGENTA ""
knaresh89 0:a8bfd25ff975 211 #define RTT_CTRL_TEXT_CYAN ""
knaresh89 0:a8bfd25ff975 212 #define RTT_CTRL_TEXT_WHITE ""
knaresh89 0:a8bfd25ff975 213
knaresh89 0:a8bfd25ff975 214 #define RTT_CTRL_TEXT_BRIGHT_BLACK ""
knaresh89 0:a8bfd25ff975 215 #define RTT_CTRL_TEXT_BRIGHT_RED ""
knaresh89 0:a8bfd25ff975 216 #define RTT_CTRL_TEXT_BRIGHT_GREEN ""
knaresh89 0:a8bfd25ff975 217 #define RTT_CTRL_TEXT_BRIGHT_YELLOW ""
knaresh89 0:a8bfd25ff975 218 #define RTT_CTRL_TEXT_BRIGHT_BLUE ""
knaresh89 0:a8bfd25ff975 219 #define RTT_CTRL_TEXT_BRIGHT_MAGENTA ""
knaresh89 0:a8bfd25ff975 220 #define RTT_CTRL_TEXT_BRIGHT_CYAN ""
knaresh89 0:a8bfd25ff975 221 #define RTT_CTRL_TEXT_BRIGHT_WHITE ""
knaresh89 0:a8bfd25ff975 222
knaresh89 0:a8bfd25ff975 223 #define RTT_CTRL_BG_BLACK ""
knaresh89 0:a8bfd25ff975 224 #define RTT_CTRL_BG_RED ""
knaresh89 0:a8bfd25ff975 225 #define RTT_CTRL_BG_GREEN ""
knaresh89 0:a8bfd25ff975 226 #define RTT_CTRL_BG_YELLOW ""
knaresh89 0:a8bfd25ff975 227 #define RTT_CTRL_BG_BLUE ""
knaresh89 0:a8bfd25ff975 228 #define RTT_CTRL_BG_MAGENTA ""
knaresh89 0:a8bfd25ff975 229 #define RTT_CTRL_BG_CYAN ""
knaresh89 0:a8bfd25ff975 230 #define RTT_CTRL_BG_WHITE ""
knaresh89 0:a8bfd25ff975 231
knaresh89 0:a8bfd25ff975 232 #define RTT_CTRL_BG_BRIGHT_BLACK ""
knaresh89 0:a8bfd25ff975 233 #define RTT_CTRL_BG_BRIGHT_RED ""
knaresh89 0:a8bfd25ff975 234 #define RTT_CTRL_BG_BRIGHT_GREEN ""
knaresh89 0:a8bfd25ff975 235 #define RTT_CTRL_BG_BRIGHT_YELLOW ""
knaresh89 0:a8bfd25ff975 236 #define RTT_CTRL_BG_BRIGHT_BLUE ""
knaresh89 0:a8bfd25ff975 237 #define RTT_CTRL_BG_BRIGHT_MAGENTA ""
knaresh89 0:a8bfd25ff975 238 #define RTT_CTRL_BG_BRIGHT_CYAN ""
knaresh89 0:a8bfd25ff975 239 #define RTT_CTRL_BG_BRIGHT_WHITE ""
knaresh89 0:a8bfd25ff975 240
knaresh89 0:a8bfd25ff975 241
knaresh89 0:a8bfd25ff975 242 #endif
knaresh89 0:a8bfd25ff975 243
knaresh89 0:a8bfd25ff975 244 /*************************** End of file ****************************/