kh

Dependencies:   Adafruit_SGP30_mbed mbed CCS811 mbed-rtos ALPHASENSE Adafruit_ADS1015_ BME680

Committer:
etiene32
Date:
Wed Mar 06 14:03:41 2019 +0000
Revision:
0:43070b2dfc87
,hb

Who changed what in which revision?

UserRevisionLine numberNew contents of line
etiene32 0:43070b2dfc87 1 /*
etiene32 0:43070b2dfc87 2 * -------------------------------------------------------------------------
etiene32 0:43070b2dfc87 3 * Copyright (C) 2017 STMicroelectronics
etiene32 0:43070b2dfc87 4 * Author: Francesco M. Virlinzi <francesco.virlinzi@st.com>
etiene32 0:43070b2dfc87 5 *
etiene32 0:43070b2dfc87 6 * May be copied or modified under the terms of the GNU General Public
etiene32 0:43070b2dfc87 7 * License V.2 ONLY. See linux/COPYING for more information.
etiene32 0:43070b2dfc87 8 *
etiene32 0:43070b2dfc87 9 * -------------------------------------------------------------------------
etiene32 0:43070b2dfc87 10 */
etiene32 0:43070b2dfc87 11 #ifndef __TESEO_LIV3F_H__
etiene32 0:43070b2dfc87 12 #define __TESEO_LIV3F_H__
etiene32 0:43070b2dfc87 13
etiene32 0:43070b2dfc87 14 #include "mbed.h"
etiene32 0:43070b2dfc87 15 #include "rtos/rtos.h"
etiene32 0:43070b2dfc87 16
etiene32 0:43070b2dfc87 17 extern char _OK[];
etiene32 0:43070b2dfc87 18 extern char _Failed[];
etiene32 0:43070b2dfc87 19 extern char X_Nucleo_name[];
etiene32 0:43070b2dfc87 20
etiene32 0:43070b2dfc87 21 enum nmea_msg_id {
etiene32 0:43070b2dfc87 22 NMEA_GPGGA,
etiene32 0:43070b2dfc87 23 NMEA_GPGLL,
etiene32 0:43070b2dfc87 24 NMEA_GNGSA,
etiene32 0:43070b2dfc87 25 NMEA_GPTXT,
etiene32 0:43070b2dfc87 26 NMEA_GPVTG,
etiene32 0:43070b2dfc87 27 NMEA_GPRMC,
etiene32 0:43070b2dfc87 28 NMEA_PSTMCPU,
etiene32 0:43070b2dfc87 29 NMEA_PSTMVER,
etiene32 0:43070b2dfc87 30 NMEA_END__
etiene32 0:43070b2dfc87 31 };
etiene32 0:43070b2dfc87 32
etiene32 0:43070b2dfc87 33 #define TESEO_RXBUF_LEN 128
etiene32 0:43070b2dfc87 34
etiene32 0:43070b2dfc87 35 struct teseo_msg {
etiene32 0:43070b2dfc87 36 unsigned char len;
etiene32 0:43070b2dfc87 37 char buf[TESEO_RXBUF_LEN];
etiene32 0:43070b2dfc87 38 };
etiene32 0:43070b2dfc87 39
etiene32 0:43070b2dfc87 40
etiene32 0:43070b2dfc87 41 class Teseo_LIV3F {
etiene32 0:43070b2dfc87 42 public:
etiene32 0:43070b2dfc87 43 enum cmd_enum {
etiene32 0:43070b2dfc87 44 GETSWVER,
etiene32 0:43070b2dfc87 45 FORCESTANDBY,
etiene32 0:43070b2dfc87 46 RFTESTON,
etiene32 0:43070b2dfc87 47 RFTESTOFF,
etiene32 0:43070b2dfc87 48 LOWPOWER,
etiene32 0:43070b2dfc87 49 FWUPDATE,
etiene32 0:43070b2dfc87 50 };
etiene32 0:43070b2dfc87 51
etiene32 0:43070b2dfc87 52 private:
etiene32 0:43070b2dfc87 53 DigitalOut _reset;
etiene32 0:43070b2dfc87 54 DigitalIn _pps;
etiene32 0:43070b2dfc87 55 DigitalOut _wakeup;
etiene32 0:43070b2dfc87 56
etiene32 0:43070b2dfc87 57 #define SDT_UART_BAUD 9600
etiene32 0:43070b2dfc87 58 #define FWU_UART_BAUD 115200
etiene32 0:43070b2dfc87 59 #define TESEO_I2C_ADDRESS 0x3A
etiene32 0:43070b2dfc87 60 #if 1
etiene32 0:43070b2dfc87 61 #define POWERON_STABLE_SIGNAL_DELAY_MS 150
etiene32 0:43070b2dfc87 62 #else
etiene32 0:43070b2dfc87 63 #define POWERON_STABLE_SIGNAL_DELAY_MS 500
etiene32 0:43070b2dfc87 64 #endif
etiene32 0:43070b2dfc87 65
etiene32 0:43070b2dfc87 66 Serial _uart;
etiene32 0:43070b2dfc87 67 bool _uart_interleaded;
etiene32 0:43070b2dfc87 68 bool _uart_discard;
etiene32 0:43070b2dfc87 69 #if 1
etiene32 0:43070b2dfc87 70 Mutex _uart_mutex;
etiene32 0:43070b2dfc87 71 #define _uart_mutex_lock() _uart_mutex.lock()
etiene32 0:43070b2dfc87 72 #define _uart_mutex_unlock() _uart_mutex.unlock()
etiene32 0:43070b2dfc87 73 #else
etiene32 0:43070b2dfc87 74 #define _uart_mutex_lock()
etiene32 0:43070b2dfc87 75 #define _uart_mutex_unlock()
etiene32 0:43070b2dfc87 76 #endif
etiene32 0:43070b2dfc87 77 Serial *_serial_debug;
etiene32 0:43070b2dfc87 78 I2C *_i2c;
etiene32 0:43070b2dfc87 79
etiene32 0:43070b2dfc87 80 int FwWaitAck();
etiene32 0:43070b2dfc87 81
etiene32 0:43070b2dfc87 82 int CRC_(char *buf, int size);
etiene32 0:43070b2dfc87 83
etiene32 0:43070b2dfc87 84 int SendString(char *buf, int len);
etiene32 0:43070b2dfc87 85
etiene32 0:43070b2dfc87 86 int ReadMessage(char *buf, unsigned long len, Timer *t = NULL, float timout = 0.0);
etiene32 0:43070b2dfc87 87
etiene32 0:43070b2dfc87 88 char *DetectSentence(const char *cmd, char *buf, unsigned long len);
etiene32 0:43070b2dfc87 89
etiene32 0:43070b2dfc87 90 Thread serialStreamThread;
etiene32 0:43070b2dfc87 91
etiene32 0:43070b2dfc87 92 public:
etiene32 0:43070b2dfc87 93 enum nmea_msg_id MsgDetect(char *buf, int buf_len, Serial *serial_debug);
etiene32 0:43070b2dfc87 94
etiene32 0:43070b2dfc87 95 void UARTStreamProcess(Serial *serial_debug);
etiene32 0:43070b2dfc87 96
etiene32 0:43070b2dfc87 97 Teseo_LIV3F(PinName reset_pin, PinName wakeup_pin, PinName pps_pin, PinName uart_tx_pin, PinName uart_rx_pin, Serial *serial_debug = NULL);
etiene32 0:43070b2dfc87 98
etiene32 0:43070b2dfc87 99 Teseo_LIV3F(PinName reset_pin, PinName wakeup_pin, PinName pps_pin, PinName uart_tx_pin, PinName uart_rx_pin, I2C *i2c_bus, Serial *serial_debug = NULL);
etiene32 0:43070b2dfc87 100
etiene32 0:43070b2dfc87 101 void SendCommand(enum Teseo_LIV3F::cmd_enum c);
etiene32 0:43070b2dfc87 102
etiene32 0:43070b2dfc87 103 void Reset(Serial *serial_debug = NULL);
etiene32 0:43070b2dfc87 104
etiene32 0:43070b2dfc87 105 bool CheckPPSWorking();
etiene32 0:43070b2dfc87 106
etiene32 0:43070b2dfc87 107 int CheckI2C();
etiene32 0:43070b2dfc87 108
etiene32 0:43070b2dfc87 109 void RFTest(bool enable);
etiene32 0:43070b2dfc87 110
etiene32 0:43070b2dfc87 111 bool WaitBooting(Timer *t, float timout = 8.0);
etiene32 0:43070b2dfc87 112
etiene32 0:43070b2dfc87 113 int WakeUp();
etiene32 0:43070b2dfc87 114
etiene32 0:43070b2dfc87 115 int EnableLowPower();
etiene32 0:43070b2dfc87 116
etiene32 0:43070b2dfc87 117 char *ReadSentence(const char *cmd, char *buf, unsigned long len);
etiene32 0:43070b2dfc87 118
etiene32 0:43070b2dfc87 119 bool FirmwareUpdate(bool is_recovery, char *data, unsigned int data_len, unsigned long crc, Serial *serial_debug);
etiene32 0:43070b2dfc87 120
etiene32 0:43070b2dfc87 121 void ReadLoop(Serial *serial_debug);
etiene32 0:43070b2dfc87 122
etiene32 0:43070b2dfc87 123 void startListener(Serial *serial_debug);
etiene32 0:43070b2dfc87 124 void stopListener(Serial *serial_debug);
etiene32 0:43070b2dfc87 125
etiene32 0:43070b2dfc87 126 MemoryPool<struct teseo_msg, 8> mpool;
etiene32 0:43070b2dfc87 127 Queue<struct teseo_msg, 8> queue;
etiene32 0:43070b2dfc87 128 };
etiene32 0:43070b2dfc87 129
etiene32 0:43070b2dfc87 130 #endif