"Sensors Reader" Sample Application for X-NUCLEO-IKS01A1 Expansion Board

Dependencies:   X_NUCLEO_IKS01A2 mbed

Fork of Sensors_Reader by ST

Committer:
Wolfgang Betz
Date:
Mon Aug 31 12:07:22 2015 +0200
Revision:
61:77f043ac766b
Parent:
58:e1b83db148d0
Child:
62:67e2353604be
Rename 'pressure_sensor' in 'pt_sensor'

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 58:e1b83db148d0 1 /**
Wolfgang Betz 58:e1b83db148d0 2 ******************************************************************************
Wolfgang Betz 58:e1b83db148d0 3 * @file main.cpp
Wolfgang Betz 58:e1b83db148d0 4 * @author AST / EST
Wolfgang Betz 58:e1b83db148d0 5 * @version V0.0.1
Wolfgang Betz 58:e1b83db148d0 6 * @date 14-April-2015
Wolfgang Betz 58:e1b83db148d0 7 * @brief Example application for using the X_NUCLEO_IKS01A1
Wolfgang Betz 58:e1b83db148d0 8 * MEMS Inertial & Environmental Sensor Nucleo expansion board.
Wolfgang Betz 58:e1b83db148d0 9 ******************************************************************************
Wolfgang Betz 58:e1b83db148d0 10 * @attention
Wolfgang Betz 58:e1b83db148d0 11 *
Wolfgang Betz 58:e1b83db148d0 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
Wolfgang Betz 58:e1b83db148d0 13 *
Wolfgang Betz 58:e1b83db148d0 14 * Redistribution and use in source and binary forms, with or without modification,
Wolfgang Betz 58:e1b83db148d0 15 * are permitted provided that the following conditions are met:
Wolfgang Betz 58:e1b83db148d0 16 * 1. Redistributions of source code must retain the above copyright notice,
Wolfgang Betz 58:e1b83db148d0 17 * this list of conditions and the following disclaimer.
Wolfgang Betz 58:e1b83db148d0 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Wolfgang Betz 58:e1b83db148d0 19 * this list of conditions and the following disclaimer in the documentation
Wolfgang Betz 58:e1b83db148d0 20 * and/or other materials provided with the distribution.
Wolfgang Betz 58:e1b83db148d0 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Wolfgang Betz 58:e1b83db148d0 22 * may be used to endorse or promote products derived from this software
Wolfgang Betz 58:e1b83db148d0 23 * without specific prior written permission.
Wolfgang Betz 58:e1b83db148d0 24 *
Wolfgang Betz 58:e1b83db148d0 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Wolfgang Betz 58:e1b83db148d0 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Wolfgang Betz 58:e1b83db148d0 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Wolfgang Betz 58:e1b83db148d0 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Wolfgang Betz 58:e1b83db148d0 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Wolfgang Betz 58:e1b83db148d0 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Wolfgang Betz 58:e1b83db148d0 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Wolfgang Betz 58:e1b83db148d0 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Wolfgang Betz 58:e1b83db148d0 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Wolfgang Betz 58:e1b83db148d0 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wolfgang Betz 58:e1b83db148d0 35 *
Wolfgang Betz 58:e1b83db148d0 36 ******************************************************************************
Wolfgang Betz 58:e1b83db148d0 37 */
Wolfgang Betz 58:e1b83db148d0 38
Wolfgang Betz 58:e1b83db148d0 39 /**
Wolfgang Betz 58:e1b83db148d0 40 * @mainpage X_NUCLEO_IKS01A1 MEMS Inertial & Environmental Sensor Nucleo Expansion Board Firmware Package
Wolfgang Betz 58:e1b83db148d0 41 *
Wolfgang Betz 58:e1b83db148d0 42 * <b>Introduction</b>
Wolfgang Betz 58:e1b83db148d0 43 *
Wolfgang Betz 58:e1b83db148d0 44 * This firmware package includes Components Device Drivers, Board Support Package
Wolfgang Betz 58:e1b83db148d0 45 * and example application for STMicroelectronics X_NUCLEO_IKS01A1 MEMS Inertial & Environmental Nucleo
Wolfgang Betz 58:e1b83db148d0 46 * Expansion Board
Wolfgang Betz 58:e1b83db148d0 47 *
Wolfgang Betz 58:e1b83db148d0 48 * <b>Example Application</b>
Wolfgang Betz 58:e1b83db148d0 49 *
Wolfgang Betz 58:e1b83db148d0 50 */
Wolfgang Betz 58:e1b83db148d0 51
Wolfgang Betz 58:e1b83db148d0 52
Wolfgang Betz 58:e1b83db148d0 53 /*** Includes ----------------------------------------------------------------- ***/
Wolfgang Betz 58:e1b83db148d0 54 #include "mbed.h"
Wolfgang Betz 58:e1b83db148d0 55 #include "assert.h"
Wolfgang Betz 58:e1b83db148d0 56 #include "x_nucleo_iks01a1.h"
Wolfgang Betz 58:e1b83db148d0 57
Wolfgang Betz 58:e1b83db148d0 58 #include <Ticker.h>
Wolfgang Betz 58:e1b83db148d0 59
Wolfgang Betz 58:e1b83db148d0 60
Wolfgang Betz 58:e1b83db148d0 61 /*** Constants ---------------------------------------------------------------- ***/
Wolfgang Betz 58:e1b83db148d0 62 namespace {
Wolfgang Betz 58:e1b83db148d0 63 const int MS_INTERVALS = 1000;
Wolfgang Betz 58:e1b83db148d0 64 }
Wolfgang Betz 58:e1b83db148d0 65
Wolfgang Betz 58:e1b83db148d0 66
Wolfgang Betz 58:e1b83db148d0 67 /*** Macros ------------------------------------------------------------------- ***/
Wolfgang Betz 58:e1b83db148d0 68 #define APP_LOOP_PERIOD 3000 // in ms
Wolfgang Betz 58:e1b83db148d0 69
Wolfgang Betz 58:e1b83db148d0 70 #if defined(TARGET_STM)
Wolfgang Betz 58:e1b83db148d0 71 #define LED_OFF (0)
Wolfgang Betz 58:e1b83db148d0 72 #else
Wolfgang Betz 58:e1b83db148d0 73 #define LED_OFF (1)
Wolfgang Betz 58:e1b83db148d0 74 #endif
Wolfgang Betz 58:e1b83db148d0 75 #define LED_ON (!LED_OFF)
Wolfgang Betz 58:e1b83db148d0 76
Wolfgang Betz 58:e1b83db148d0 77
Wolfgang Betz 58:e1b83db148d0 78 /*** Typedefs ----------------------------------------------------------------- ***/
Wolfgang Betz 58:e1b83db148d0 79 typedef struct {
Wolfgang Betz 58:e1b83db148d0 80 int32_t AXIS_X;
Wolfgang Betz 58:e1b83db148d0 81 int32_t AXIS_Y;
Wolfgang Betz 58:e1b83db148d0 82 int32_t AXIS_Z;
Wolfgang Betz 58:e1b83db148d0 83 } AxesRaw_TypeDef;
Wolfgang Betz 58:e1b83db148d0 84
Wolfgang Betz 58:e1b83db148d0 85
Wolfgang Betz 58:e1b83db148d0 86 /*** Static variables --------------------------------------------------------- ***/
Wolfgang Betz 58:e1b83db148d0 87 #ifdef DBG_MCU
Wolfgang Betz 58:e1b83db148d0 88 /* betzw: enable debugging while using sleep modes */
Wolfgang Betz 58:e1b83db148d0 89 #include "DbgMCU.h"
Wolfgang Betz 58:e1b83db148d0 90 static DbgMCU enable_dbg;
Wolfgang Betz 58:e1b83db148d0 91 #endif // DBG_MCU
Wolfgang Betz 58:e1b83db148d0 92
Wolfgang Betz 58:e1b83db148d0 93 static X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance();
Wolfgang Betz 58:e1b83db148d0 94 static GyroSensor *gyroscope = mems_expansion_board->GetGyroscope();
Wolfgang Betz 58:e1b83db148d0 95 static MotionSensor *accelerometer = mems_expansion_board->GetAccelerometer();
Wolfgang Betz 58:e1b83db148d0 96 static MagneticSensor *magnetometer = mems_expansion_board->magnetometer;
Wolfgang Betz 58:e1b83db148d0 97 static HumiditySensor *humidity_sensor = mems_expansion_board->ht_sensor;;
Wolfgang Betz 61:77f043ac766b 98 static PressureSensor *pressure_sensor = mems_expansion_board->pt_sensor;
Wolfgang Betz 58:e1b83db148d0 99 static TempSensor *temp_sensor1 = mems_expansion_board->ht_sensor;
Wolfgang Betz 61:77f043ac766b 100 static TempSensor *temp_sensor2 = mems_expansion_board->pt_sensor;
Wolfgang Betz 58:e1b83db148d0 101
Wolfgang Betz 58:e1b83db148d0 102 static Ticker ticker;
Wolfgang Betz 58:e1b83db148d0 103 static DigitalOut myled(LED1, LED_OFF);
Wolfgang Betz 58:e1b83db148d0 104
Wolfgang Betz 58:e1b83db148d0 105 static volatile bool timer_irq_triggered = false;
Wolfgang Betz 58:e1b83db148d0 106 static volatile bool ff_irq_triggered = false;
Wolfgang Betz 58:e1b83db148d0 107
Wolfgang Betz 58:e1b83db148d0 108
Wolfgang Betz 58:e1b83db148d0 109 /*** Helper Functions (1/2) ------------------------------------------------------------ ***/
Wolfgang Betz 58:e1b83db148d0 110
Wolfgang Betz 58:e1b83db148d0 111
Wolfgang Betz 58:e1b83db148d0 112 /*** Interrupt Handler Top-Halves ------------------------------------------------------ ***/
Wolfgang Betz 58:e1b83db148d0 113 /* Called in interrupt context, therefore just set a trigger variable */
Wolfgang Betz 58:e1b83db148d0 114 static void timer_irq(void) {
Wolfgang Betz 58:e1b83db148d0 115 timer_irq_triggered = true;
Wolfgang Betz 58:e1b83db148d0 116 }
Wolfgang Betz 58:e1b83db148d0 117
Wolfgang Betz 58:e1b83db148d0 118 /* Called in interrupt context, therefore just set a trigger variable */
Wolfgang Betz 58:e1b83db148d0 119 static void ff_irq(void) {
Wolfgang Betz 58:e1b83db148d0 120 ff_irq_triggered = true;
Wolfgang Betz 58:e1b83db148d0 121
Wolfgang Betz 58:e1b83db148d0 122 /* Disable IRQ until handled */
Wolfgang Betz 58:e1b83db148d0 123 mems_expansion_board->gyro_lsm6ds3->Disable_Free_Fall_Detection_IRQ();
Wolfgang Betz 58:e1b83db148d0 124 }
Wolfgang Betz 58:e1b83db148d0 125
Wolfgang Betz 58:e1b83db148d0 126
Wolfgang Betz 58:e1b83db148d0 127 /*** Interrupt Handler Bottom-Halves ------------------------------------------------- ***/
Wolfgang Betz 58:e1b83db148d0 128 /* Handle Free Fall Interrupt
Wolfgang Betz 58:e1b83db148d0 129 (here we are in "normal" context, i.e. not in IRQ context)
Wolfgang Betz 58:e1b83db148d0 130 */
Wolfgang Betz 58:e1b83db148d0 131 static void handle_ff_irq(void) {
Wolfgang Betz 58:e1b83db148d0 132 printf("\nFree Fall Detected!\n\n");
Wolfgang Betz 58:e1b83db148d0 133
Wolfgang Betz 58:e1b83db148d0 134 /* Re-enable IRQ */
Wolfgang Betz 58:e1b83db148d0 135 mems_expansion_board->gyro_lsm6ds3->Enable_Free_Fall_Detection_IRQ();
Wolfgang Betz 58:e1b83db148d0 136 }
Wolfgang Betz 58:e1b83db148d0 137
Wolfgang Betz 58:e1b83db148d0 138
Wolfgang Betz 58:e1b83db148d0 139 /*** Helper Functions (2/2) ------------------------------------------------------------ ***/
Wolfgang Betz 58:e1b83db148d0 140 /* print floats & doubles */
Wolfgang Betz 58:e1b83db148d0 141 static char *printDouble(char* str, double v, int decimalDigits=2)
Wolfgang Betz 58:e1b83db148d0 142 {
Wolfgang Betz 58:e1b83db148d0 143 int i = 1;
Wolfgang Betz 58:e1b83db148d0 144 int intPart, fractPart;
Wolfgang Betz 58:e1b83db148d0 145 int len;
Wolfgang Betz 58:e1b83db148d0 146 char *ptr;
Wolfgang Betz 58:e1b83db148d0 147
Wolfgang Betz 58:e1b83db148d0 148 /* prepare decimal digits multiplicator */
Wolfgang Betz 58:e1b83db148d0 149 for (;decimalDigits!=0; i*=10, decimalDigits--);
Wolfgang Betz 58:e1b83db148d0 150
Wolfgang Betz 58:e1b83db148d0 151 /* calculate integer & fractinal parts */
Wolfgang Betz 58:e1b83db148d0 152 intPart = (int)v;
Wolfgang Betz 58:e1b83db148d0 153 fractPart = (int)((v-(double)(int)v)*i);
Wolfgang Betz 58:e1b83db148d0 154
Wolfgang Betz 58:e1b83db148d0 155 /* fill in integer part */
Wolfgang Betz 58:e1b83db148d0 156 sprintf(str, "%i.", intPart);
Wolfgang Betz 58:e1b83db148d0 157
Wolfgang Betz 58:e1b83db148d0 158 /* prepare fill in of fractional part */
Wolfgang Betz 58:e1b83db148d0 159 len = strlen(str);
Wolfgang Betz 58:e1b83db148d0 160 ptr = &str[len];
Wolfgang Betz 58:e1b83db148d0 161
Wolfgang Betz 58:e1b83db148d0 162 /* fill in leading fractional zeros */
Wolfgang Betz 58:e1b83db148d0 163 for (i/=10;i>1; i/=10, ptr++) {
Wolfgang Betz 58:e1b83db148d0 164 if(fractPart >= i) break;
Wolfgang Betz 58:e1b83db148d0 165 *ptr = '0';
Wolfgang Betz 58:e1b83db148d0 166 }
Wolfgang Betz 58:e1b83db148d0 167
Wolfgang Betz 58:e1b83db148d0 168 /* fill in (rest of) fractional part */
Wolfgang Betz 58:e1b83db148d0 169 sprintf(ptr, "%i", fractPart);
Wolfgang Betz 58:e1b83db148d0 170
Wolfgang Betz 58:e1b83db148d0 171 return str;
Wolfgang Betz 58:e1b83db148d0 172 }
Wolfgang Betz 58:e1b83db148d0 173
Wolfgang Betz 58:e1b83db148d0 174 /* Initialization function */
Wolfgang Betz 58:e1b83db148d0 175 static void init(void) {
Wolfgang Betz 58:e1b83db148d0 176 uint8_t id1, id2;
Wolfgang Betz 58:e1b83db148d0 177
Wolfgang Betz 58:e1b83db148d0 178 /* Determine ID of Humidity & Temperature Sensor */
Wolfgang Betz 58:e1b83db148d0 179 CALL_METH(humidity_sensor, ReadID, &id1, 0x0);
Wolfgang Betz 58:e1b83db148d0 180 CALL_METH(temp_sensor1, ReadID, &id2, 0x0);
Wolfgang Betz 58:e1b83db148d0 181 printf("Humidity | Temperature Sensor ID = %s (0x%x | 0x%x)\n",
Wolfgang Betz 58:e1b83db148d0 182 ((id1 == I_AM_HTS221) ? "HTS221 " : "UNKNOWN"),
Wolfgang Betz 58:e1b83db148d0 183 id1, id2
Wolfgang Betz 58:e1b83db148d0 184 );
Wolfgang Betz 58:e1b83db148d0 185 assert(id1 == id2);
Wolfgang Betz 58:e1b83db148d0 186
Wolfgang Betz 58:e1b83db148d0 187 /* Determine ID of Gyro & Motion Sensor */
Wolfgang Betz 58:e1b83db148d0 188 assert((mems_expansion_board->gyro_lsm6ds0 == NULL) ||
Wolfgang Betz 58:e1b83db148d0 189 (mems_expansion_board->gyro_lsm6ds3 == NULL));
Wolfgang Betz 58:e1b83db148d0 190 CALL_METH(gyroscope, ReadID, &id1, 0x0);
Wolfgang Betz 58:e1b83db148d0 191 CALL_METH(accelerometer, ReadID, &id2, 0x0);
Wolfgang Betz 58:e1b83db148d0 192 printf("Gyroscope | Motion Sensor ID = %s (0x%x | 0x%x)\n",
Wolfgang Betz 58:e1b83db148d0 193 ((id1 == I_AM_LSM6DS3_XG) ? "LSM6DS3" :
Wolfgang Betz 58:e1b83db148d0 194 ((id1 == I_AM_LSM6DS0_XG) ? "LSM6DS0" : "UNKNOWN")),
Wolfgang Betz 58:e1b83db148d0 195 id1, id2
Wolfgang Betz 58:e1b83db148d0 196 );
Wolfgang Betz 58:e1b83db148d0 197 assert(id1 == id2);
Wolfgang Betz 58:e1b83db148d0 198
Wolfgang Betz 58:e1b83db148d0 199 /* Register Free Fall Detection IRQ Handler & Enable Detection */
Wolfgang Betz 58:e1b83db148d0 200 if(mems_expansion_board->gyro_lsm6ds3 != NULL) {
Wolfgang Betz 58:e1b83db148d0 201 mems_expansion_board->gyro_lsm6ds3->Attach_Free_Fall_Detection_IRQ(ff_irq);
Wolfgang Betz 58:e1b83db148d0 202 mems_expansion_board->gyro_lsm6ds3->Enable_Free_Fall_Detection();
Wolfgang Betz 58:e1b83db148d0 203 }
Wolfgang Betz 58:e1b83db148d0 204 }
Wolfgang Betz 58:e1b83db148d0 205
Wolfgang Betz 58:e1b83db148d0 206 /* Main cycle function */
Wolfgang Betz 58:e1b83db148d0 207 static void main_cycle(void) {
Wolfgang Betz 58:e1b83db148d0 208 float TEMPERATURE_Value;
Wolfgang Betz 58:e1b83db148d0 209 float HUMIDITY_Value;
Wolfgang Betz 58:e1b83db148d0 210 float PRESSURE_Value;
Wolfgang Betz 58:e1b83db148d0 211 float PRESSURE_Temp_Value;
Wolfgang Betz 58:e1b83db148d0 212 AxesRaw_TypeDef MAG_Value;
Wolfgang Betz 58:e1b83db148d0 213 AxesRaw_TypeDef ACC_Value;
Wolfgang Betz 58:e1b83db148d0 214 AxesRaw_TypeDef GYR_Value;
Wolfgang Betz 58:e1b83db148d0 215 char buffer1[32];
Wolfgang Betz 58:e1b83db148d0 216 char buffer2[32];
Wolfgang Betz 58:e1b83db148d0 217 char buffer3[32];
Wolfgang Betz 58:e1b83db148d0 218 char buffer4[32];
Wolfgang Betz 58:e1b83db148d0 219 unsigned int ret = 0;
Wolfgang Betz 58:e1b83db148d0 220
Wolfgang Betz 58:e1b83db148d0 221 /* Switch LED On */
Wolfgang Betz 58:e1b83db148d0 222 myled = LED_ON;
Wolfgang Betz 58:e1b83db148d0 223 printf("===\n");
Wolfgang Betz 58:e1b83db148d0 224
Wolfgang Betz 58:e1b83db148d0 225 /* Determine Environmental Values */
Wolfgang Betz 58:e1b83db148d0 226 ret |= (!CALL_METH(temp_sensor1, GetTemperature, &TEMPERATURE_Value, 0.0f) ? 0x0 : 0x1);
Wolfgang Betz 58:e1b83db148d0 227 ret |= (!CALL_METH(humidity_sensor, GetHumidity, &HUMIDITY_Value, 0.0f) ? 0x0 : 0x2);;
Wolfgang Betz 58:e1b83db148d0 228 ret |= (!CALL_METH(pressure_sensor, GetPressure, &PRESSURE_Value, 0.0f) ? 0x0 : 0x4);;
Wolfgang Betz 58:e1b83db148d0 229 ret |= (!CALL_METH(temp_sensor2, GetFahrenheit, &PRESSURE_Temp_Value, 0.0f) ? 0x0 : 0x8);;
Wolfgang Betz 58:e1b83db148d0 230 ret |= (!CALL_METH(magnetometer, Get_M_Axes, (int32_t *)&MAG_Value, 0) ? 0x0 : 0x10);;
Wolfgang Betz 58:e1b83db148d0 231 ret |= (!CALL_METH(accelerometer, Get_X_Axes, (int32_t *)&ACC_Value, 0) ? 0x0 : 0x20);;
Wolfgang Betz 58:e1b83db148d0 232 ret |= (!CALL_METH(gyroscope, Get_G_Axes, (int32_t *)&GYR_Value, 0) ? 0x0 : 0x40);
Wolfgang Betz 58:e1b83db148d0 233
Wolfgang Betz 58:e1b83db148d0 234 /* Print Values Out */
Wolfgang Betz 58:e1b83db148d0 235 printf("I2C [errors]: 0x%.2x X Y Z\n", ret);
Wolfgang Betz 58:e1b83db148d0 236 printf("MAG [mgauss]: %9ld %9ld %9ld\n",
Wolfgang Betz 58:e1b83db148d0 237 MAG_Value.AXIS_X, MAG_Value.AXIS_Y, MAG_Value.AXIS_Z);
Wolfgang Betz 58:e1b83db148d0 238 printf("ACC [mg]: %9ld %9ld %9ld\n",
Wolfgang Betz 58:e1b83db148d0 239 ACC_Value.AXIS_X, ACC_Value.AXIS_Y, ACC_Value.AXIS_Z);
Wolfgang Betz 58:e1b83db148d0 240 printf("GYR [mdps]: %9ld %9ld %9ld\n",
Wolfgang Betz 58:e1b83db148d0 241 GYR_Value.AXIS_X, GYR_Value.AXIS_Y, GYR_Value.AXIS_Z);
Wolfgang Betz 61:77f043ac766b 242 printf("---\nTEMP | HUMIDITY: %s°C | %s%%\nTEMP | PRESSURE: %s°F | %smbar\n",
Wolfgang Betz 58:e1b83db148d0 243 printDouble(buffer1, TEMPERATURE_Value),
Wolfgang Betz 58:e1b83db148d0 244 printDouble(buffer2, HUMIDITY_Value),
Wolfgang Betz 58:e1b83db148d0 245 printDouble(buffer4, PRESSURE_Temp_Value),
Wolfgang Betz 58:e1b83db148d0 246 printDouble(buffer3, PRESSURE_Value));
Wolfgang Betz 58:e1b83db148d0 247
Wolfgang Betz 58:e1b83db148d0 248 /* Switch LED Off */
Wolfgang Betz 58:e1b83db148d0 249 myled = LED_OFF;
Wolfgang Betz 58:e1b83db148d0 250 }
Wolfgang Betz 58:e1b83db148d0 251
Wolfgang Betz 58:e1b83db148d0 252
Wolfgang Betz 58:e1b83db148d0 253 /*** Main function ------------------------------------------------------------- ***/
Wolfgang Betz 58:e1b83db148d0 254 /* Generic main function/loop for enabling WFE in case of
Wolfgang Betz 58:e1b83db148d0 255 interrupt based cyclic execution
Wolfgang Betz 58:e1b83db148d0 256 */
Wolfgang Betz 58:e1b83db148d0 257 int main()
Wolfgang Betz 58:e1b83db148d0 258 {
Wolfgang Betz 58:e1b83db148d0 259 /* Start & initialize */
Wolfgang Betz 58:e1b83db148d0 260 printf("\n--- Starting new run ---\n");
Wolfgang Betz 58:e1b83db148d0 261 init();
Wolfgang Betz 58:e1b83db148d0 262
Wolfgang Betz 58:e1b83db148d0 263 /* Start timer irq */
Wolfgang Betz 58:e1b83db148d0 264 ticker.attach_us(timer_irq, MS_INTERVALS * APP_LOOP_PERIOD);
Wolfgang Betz 58:e1b83db148d0 265
Wolfgang Betz 58:e1b83db148d0 266 while (true) {
Wolfgang Betz 58:e1b83db148d0 267 if(timer_irq_triggered) {
Wolfgang Betz 58:e1b83db148d0 268 timer_irq_triggered = false;
Wolfgang Betz 58:e1b83db148d0 269 main_cycle();
Wolfgang Betz 58:e1b83db148d0 270 } else if(ff_irq_triggered) {
Wolfgang Betz 58:e1b83db148d0 271 ff_irq_triggered = false;
Wolfgang Betz 58:e1b83db148d0 272 handle_ff_irq();
Wolfgang Betz 58:e1b83db148d0 273 } else {
Wolfgang Betz 58:e1b83db148d0 274 __WFE(); /* it is recommended that SEVONPEND in the
Wolfgang Betz 58:e1b83db148d0 275 System Control Register is NOT set */
Wolfgang Betz 58:e1b83db148d0 276 }
Wolfgang Betz 58:e1b83db148d0 277 }
Wolfgang Betz 58:e1b83db148d0 278 }