CAC_smartcushion / Mbed OS AdiSense1000_V21_Smartcushion

Fork of Sean_AdiSense1000_V21 by Rohan Gurav

Committer:
nfathurr
Date:
Thu Oct 25 08:59:30 2018 +0000
Revision:
36:4aded4b4f060
Parent:
34:029fc3b83f78
modified output into one line

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nfathurr 34:029fc3b83f78 1
nfathurr 34:029fc3b83f78 2
nfathurr 34:029fc3b83f78 3 /**
nfathurr 34:029fc3b83f78 4 * @file pc_interface.h
nfathurr 34:029fc3b83f78 5 * @author Jake Greaves
nfathurr 34:029fc3b83f78 6 * @date 21 Dec 2017
nfathurr 34:029fc3b83f78 7 * @brief The main interface to the pc application.
nfathurr 34:029fc3b83f78 8 *
nfathurr 34:029fc3b83f78 9 * This file handles all commands to and from the PC
nfathurr 34:029fc3b83f78 10 * application.
nfathurr 34:029fc3b83f78 11 */
nfathurr 34:029fc3b83f78 12
nfathurr 34:029fc3b83f78 13 #ifndef __PC_INTERFACE_H_
nfathurr 34:029fc3b83f78 14 #define __PC_INTERFACE_H_
nfathurr 34:029fc3b83f78 15
nfathurr 34:029fc3b83f78 16 #include "string.h"
nfathurr 34:029fc3b83f78 17 #include "adi_sense_api.h"
nfathurr 34:029fc3b83f78 18 #include "adi_sense_1000/adi_sense_1000_api.h"
nfathurr 36:4aded4b4f060 19 #include "pc_serial.h"
nfathurr 36:4aded4b4f060 20 #include "pc_conversions.h"
nfathurr 34:029fc3b83f78 21 #include "myproswift_periph.h"
nfathurr 34:029fc3b83f78 22 #include "core_cm4.h"
nfathurr 34:029fc3b83f78 23 #include "myproswift_error_codes.h"
nfathurr 34:029fc3b83f78 24 #include "rcc_backup_registers/rcc_backup_registers.h"
nfathurr 34:029fc3b83f78 25 #include "eeprom_virtual/eeprom.h"
nfathurr 34:029fc3b83f78 26
nfathurr 34:029fc3b83f78 27 /*
nfathurr 34:029fc3b83f78 28 Definitions
nfathurr 34:029fc3b83f78 29 */
nfathurr 34:029fc3b83f78 30
nfathurr 34:029fc3b83f78 31 #define RESPONSE_BUFFER_SIZE 256
nfathurr 34:029fc3b83f78 32 #define PC_DELIMITER '\n'
nfathurr 34:029fc3b83f78 33 #define PC_SEPERATOR ','
nfathurr 34:029fc3b83f78 34
nfathurr 34:029fc3b83f78 35 #undef DEBUG
nfathurr 34:029fc3b83f78 36 #define BITP_VALID_DATA (7)
nfathurr 34:029fc3b83f78 37
nfathurr 34:029fc3b83f78 38 /*
nfathurr 34:029fc3b83f78 39 Command List
nfathurr 34:029fc3b83f78 40 */
nfathurr 34:029fc3b83f78 41
nfathurr 34:029fc3b83f78 42
nfathurr 34:029fc3b83f78 43 #define COMMAND_DEVICE_INFO 'i'
nfathurr 34:029fc3b83f78 44 #define COMMAND_FLASH_LED 'f'
nfathurr 34:029fc3b83f78 45 #define COMMAND_RESET 'r'
nfathurr 34:029fc3b83f78 46 #define COMMAND_CONFIGURE 'c'
nfathurr 34:029fc3b83f78 47 #define COMMAND_APPLY 'u'
nfathurr 34:029fc3b83f78 48 #define COMMAND_SAMPLE 's'
nfathurr 34:029fc3b83f78 49 #define COMMAND_START_STREAM 'd'
nfathurr 34:029fc3b83f78 50 #define COMMAND_STOP_STREAM 'h'
nfathurr 34:029fc3b83f78 51 #define COMMAND_UPDATE_FW_VERSION 'v'
nfathurr 34:029fc3b83f78 52
nfathurr 34:029fc3b83f78 53 //not sure why this is needed by the eeprom library
nfathurr 34:029fc3b83f78 54 extern uint16_t VirtAddVarTab[NB_OF_VAR];
nfathurr 34:029fc3b83f78 55
nfathurr 34:029fc3b83f78 56 /*
nfathurr 34:029fc3b83f78 57 Function Prototypes
nfathurr 34:029fc3b83f78 58 */
nfathurr 34:029fc3b83f78 59
nfathurr 34:029fc3b83f78 60 /**
nfathurr 34:029fc3b83f78 61 * @brief Tell any connected device that device is ready to use
nfathurr 34:029fc3b83f78 62 *
nfathurr 34:029fc3b83f78 63 * @param bBootLoader If device is entering bootloader, a different success code is given.
nfathurr 34:029fc3b83f78 64 */
nfathurr 34:029fc3b83f78 65 int Pc_ResetSuccess(bool_t bBootLoader);
nfathurr 34:029fc3b83f78 66
nfathurr 34:029fc3b83f78 67 /**
nfathurr 34:029fc3b83f78 68 * @brief Read the next arg from a string.
nfathurr 34:029fc3b83f78 69 *
nfathurr 34:029fc3b83f78 70 * This function scans through the given command string
nfathurr 34:029fc3b83f78 71 * searching for either the seperator value or the delimiter.
nfathurr 34:029fc3b83f78 72 * On finding either of these chars, all text before is returned
nfathurr 34:029fc3b83f78 73 * as the argument. If the size limit is reached before a delimiter
nfathurr 34:029fc3b83f78 74 * this functions returns an error. The flag variable is set when
nfathurr 34:029fc3b83f78 75 * the delimiter is found, useful for debugging and error handling
nfathurr 34:029fc3b83f78 76 * when more arguments might be expected.
nfathurr 34:029fc3b83f78 77 *
nfathurr 34:029fc3b83f78 78 * @param command Command string to be analysed.
nfathurr 34:029fc3b83f78 79 * @param arg A found arg will be returned to this address.
nfathurr 34:029fc3b83f78 80 * @param size The max size of the arg buffer.
nfathurr 34:029fc3b83f78 81 * @param flag Set when delimiter is found.
nfathurr 34:029fc3b83f78 82 *
nfathurr 34:029fc3b83f78 83 * @return Returns 0 on success, 1 on error.
nfathurr 34:029fc3b83f78 84 *
nfathurr 34:029fc3b83f78 85 * @see PC_DELIMITER
nfathurr 34:029fc3b83f78 86 * @see PC_SEPERATOR
nfathurr 34:029fc3b83f78 87 */
nfathurr 34:029fc3b83f78 88 static int pc_read_next_arg(char *command, char *arg, int size, bool *flag);
nfathurr 34:029fc3b83f78 89
nfathurr 34:029fc3b83f78 90 /**
nfathurr 34:029fc3b83f78 91 * @brief Parse the device info command.
nfathurr 34:029fc3b83f78 92 *
nfathurr 34:029fc3b83f78 93 * This function handles the device info command, responding to the PC
nfathurr 34:029fc3b83f78 94 * with the device name, battery voltage and firmware version.
nfathurr 34:029fc3b83f78 95 *
nfathurr 34:029fc3b83f78 96 * @return Returns 0 on success, 1 on error.
nfathurr 34:029fc3b83f78 97 */
nfathurr 34:029fc3b83f78 98 static int pc_parse_device_info(void);
nfathurr 34:029fc3b83f78 99
nfathurr 34:029fc3b83f78 100 /**
nfathurr 34:029fc3b83f78 101 * @brief Parse the flash led command.
nfathurr 34:029fc3b83f78 102 *
nfathurr 34:029fc3b83f78 103 * This function handles the flash led command, pulsing an led
nfathurr 34:029fc3b83f78 104 * to identify this device. This function also responds to the PC
nfathurr 34:029fc3b83f78 105 * with the status code.
nfathurr 34:029fc3b83f78 106 *
nfathurr 34:029fc3b83f78 107 * @return Returns 0 on success, 1 on error.
nfathurr 34:029fc3b83f78 108 */
nfathurr 34:029fc3b83f78 109 static int pc_parse_flash_led(void);
nfathurr 34:029fc3b83f78 110
nfathurr 34:029fc3b83f78 111 /**
nfathurr 34:029fc3b83f78 112 * @brief Reset the device.
nfathurr 34:029fc3b83f78 113 *
nfathurr 34:029fc3b83f78 114 * This function handles the reset command, performing a soft
nfathurr 34:029fc3b83f78 115 * reset on the device. The reponse to the pc is handled in the boot
nfathurr 34:029fc3b83f78 116 * sequence for this device.
nfathurr 34:029fc3b83f78 117 *
nfathurr 34:029fc3b83f78 118 * @return Returns 0 on success, 1 on error.
nfathurr 34:029fc3b83f78 119 */
nfathurr 34:029fc3b83f78 120 static int pc_parse_reset(void);
nfathurr 34:029fc3b83f78 121
nfathurr 34:029fc3b83f78 122 /**
nfathurr 34:029fc3b83f78 123 * @brief Parse the configure command.
nfathurr 34:029fc3b83f78 124 *
nfathurr 34:029fc3b83f78 125 * This function handles the configure command. Identifiers such as channel,
nfathurr 34:029fc3b83f78 126 * keyword and value are parsed and converted to struct values. The
nfathurr 34:029fc3b83f78 127 * configure struct is updated and applied to the device.
nfathurr 34:029fc3b83f78 128 *
nfathurr 34:029fc3b83f78 129 * @param commandString Args are parsed from this string.
nfathurr 34:029fc3b83f78 130 *
nfathurr 34:029fc3b83f78 131 * @return Returns 0 on success, 1 on error.
nfathurr 34:029fc3b83f78 132 */
nfathurr 34:029fc3b83f78 133 static int pc_parse_configure(char *commandString);
nfathurr 34:029fc3b83f78 134
nfathurr 34:029fc3b83f78 135 /**
nfathurr 34:029fc3b83f78 136 * @brief Support for the parse configure command.
nfathurr 34:029fc3b83f78 137 *
nfathurr 34:029fc3b83f78 138 * If the configure command receives no channel, the configuration is for the
nfathurr 34:029fc3b83f78 139 * entire device. This function parses and applies the new value to the
nfathurr 34:029fc3b83f78 140 * configuration struct.
nfathurr 34:029fc3b83f78 141 *
nfathurr 34:029fc3b83f78 142 * @param attribute The attribute enum identifying which part of the struct
nfathurr 34:029fc3b83f78 143 * is to be changed.
nfathurr 34:029fc3b83f78 144 *
nfathurr 34:029fc3b83f78 145 * @param commandString The command string incase arguments are expected.
nfathurr 34:029fc3b83f78 146 *
nfathurr 34:029fc3b83f78 147 * @return Returns 0 on success, 1 on error.
nfathurr 34:029fc3b83f78 148 */
nfathurr 34:029fc3b83f78 149 static int pc_parse_configure_device(CONFIG_ATTRIBUTE attribute, char *commandString);
nfathurr 34:029fc3b83f78 150
nfathurr 34:029fc3b83f78 151 /**
nfathurr 34:029fc3b83f78 152 * @brief Support for the parse configure command.
nfathurr 34:029fc3b83f78 153 *
nfathurr 34:029fc3b83f78 154 * If the configure command receives a channel, the configuration is channel
nfathurr 34:029fc3b83f78 155 * specific. This function parses and applies the new value to the
nfathurr 34:029fc3b83f78 156 * configuration struct.
nfathurr 34:029fc3b83f78 157 *
nfathurr 34:029fc3b83f78 158 * @param channelIndex Which channel is to be configured.
nfathurr 34:029fc3b83f78 159 *
nfathurr 34:029fc3b83f78 160 * @param attribute The attribute enum identifying which part of the struct
nfathurr 34:029fc3b83f78 161 * is to be changed.
nfathurr 34:029fc3b83f78 162 *
nfathurr 34:029fc3b83f78 163 * @param commandString The command string incase arguments are expected.
nfathurr 34:029fc3b83f78 164 *
nfathurr 34:029fc3b83f78 165 * @return Returns 0 on success, 1 on error.
nfathurr 34:029fc3b83f78 166 */
nfathurr 34:029fc3b83f78 167 static int pc_parse_configure_channel(ADI_SENSE_1000_CHANNEL_ID channelIndex, CONFIG_ATTRIBUTE attribute, char *commandString);
nfathurr 34:029fc3b83f78 168
nfathurr 34:029fc3b83f78 169 /**
nfathurr 34:029fc3b83f78 170 * @brief Callback for sampling. Drdy is tied to this.
nfathurr 34:029fc3b83f78 171 */
nfathurr 34:029fc3b83f78 172 static void pc_data_ready_callback(
nfathurr 34:029fc3b83f78 173 ADI_SENSE_GPIO_PIN ePinId,
nfathurr 34:029fc3b83f78 174 void *pArg);
nfathurr 34:029fc3b83f78 175
nfathurr 34:029fc3b83f78 176 /**
nfathurr 34:029fc3b83f78 177 * @brief Parse the sample command.
nfathurr 34:029fc3b83f78 178 *
nfathurr 34:029fc3b83f78 179 * Obtain as many samples as required for the given channels and return the raw
nfathurr 34:029fc3b83f78 180 * 32-bit floats to the PC.
nfathurr 34:029fc3b83f78 181 *
nfathurr 34:029fc3b83f78 182 * @param commandString The amount of measurement cycles are obtained from this.
nfathurr 34:029fc3b83f78 183 *
nfathurr 34:029fc3b83f78 184 * @return Returns 0 on success, 1 on error.
nfathurr 34:029fc3b83f78 185 */
nfathurr 34:029fc3b83f78 186 static int pc_parse_sample(char *commandString);
nfathurr 34:029fc3b83f78 187
nfathurr 34:029fc3b83f78 188 /**
nfathurr 34:029fc3b83f78 189 * @brief Parse the start stream command.
nfathurr 34:029fc3b83f78 190 *
nfathurr 34:029fc3b83f78 191 * Begin the sample stream, pushing out samples as fast as possible to the PC.
nfathurr 34:029fc3b83f78 192 *
nfathurr 34:029fc3b83f78 193 * @return Returns 0 on success, 1 on error.
nfathurr 34:029fc3b83f78 194 */
nfathurr 34:029fc3b83f78 195 static int pc_parse_start_stream(void);
nfathurr 34:029fc3b83f78 196
nfathurr 34:029fc3b83f78 197 /**
nfathurr 34:029fc3b83f78 198 * @brief Handle an error.
nfathurr 34:029fc3b83f78 199 *
nfathurr 34:029fc3b83f78 200 * Send an error code to the PC.
nfathurr 34:029fc3b83f78 201 *
nfathurr 34:029fc3b83f78 202 * @return Returns 0 on success, 1 on error.
nfathurr 34:029fc3b83f78 203 */
nfathurr 34:029fc3b83f78 204 int pc_handle_error(ErrorType error);
nfathurr 34:029fc3b83f78 205
nfathurr 34:029fc3b83f78 206 /**
nfathurr 34:029fc3b83f78 207 * @brief Find which command to be executed.
nfathurr 34:029fc3b83f78 208 *
nfathurr 34:029fc3b83f78 209 * parse the command character and execute the appropriate command.
nfathurr 34:029fc3b83f78 210 *
nfathurr 34:029fc3b83f78 211 * @param commandString the received command from the PC
nfathurr 34:029fc3b83f78 212 *
nfathurr 34:029fc3b83f78 213 * @return Returns 0 on success, 1 on error.
nfathurr 34:029fc3b83f78 214 */
nfathurr 34:029fc3b83f78 215 int Pc_ParseCommand( char *commandString );
nfathurr 34:029fc3b83f78 216
nfathurr 34:029fc3b83f78 217 #endif