Dmitry Kovalev / Mbed 2 deprecated LG2

Dependencies:   mbed

Fork of LG by igor Apu

Committer:
Diletant
Date:
Sat Mar 05 14:36:42 2016 +0000
Revision:
77:8d582faecf6b
Parent:
76:1c54a614564d
Child:
78:0ea9d02b7b46
Device&Settings&Protocol update. Not final!!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Diletant 54:d94145ba23f4 1 #ifndef __DEVICEPROTOCOL_H__
Diletant 54:d94145ba23f4 2 #define __DEVICEPROTOCOL_H__
Diletant 54:d94145ba23f4 3
Diletant 54:d94145ba23f4 4 #include "DeviceSettings.h"
Diletant 54:d94145ba23f4 5 #include "stdint.h"
Diletant 54:d94145ba23f4 6
Diletant 74:f4d9c3403578 7 #define BROADCAST_ADDRESS 0x1f
Diletant 74:f4d9c3403578 8 #define BROADCAST_FRAME 100 //100 mks
Diletant 74:f4d9c3403578 9
Diletant 76:1c54a614564d 10 #define DELTA_PS 0xa000 //B_DeltaPS command code: output of accumulated pulses and ACS parameters as 22 indexed packets sequence
Diletant 76:1c54a614564d 11 #define DELTA_BINS 0xb000 //B_DeltaBINS command code: output of accumulated pulses and data validity attribute in one packet
Diletant 76:1c54a614564d 12 #define DELTA_SF 0xb200 //B_DeltaSF command code: scale factor measurement data output in one packet
Diletant 76:1c54a614564d 13 #define DEV_MODE 0xa500 //e. the code of the Device_Mode command //r. код команды Device_Mode
Diletant 76:1c54a614564d 14 #define BIT_MODE 0xa700 //e. the code of the B.I.T. command //r. код команды B.I.T.(встороенного тестирования)
Diletant 76:1c54a614564d 15 #define RATE 0x0000 //e. the code of the Rate command //r. код команды Rate
Diletant 76:1c54a614564d 16 #define DELTA 0x0f00 //e. the code of the Delta command //r. код команды Delta
Diletant 76:1c54a614564d 17 #define D_PERIOD_W 0xf000 //e. the code of the D_Period_W command //r. код команды D_Period_W
Diletant 74:f4d9c3403578 18
Diletant 76:1c54a614564d 19 #define MAINTENANCE 0x9900 //e. the code of the Maintenance mode command //r. код команды Maintenance mode
Diletant 74:f4d9c3403578 20 //Maintenance command set versions
Diletant 74:f4d9c3403578 21 #define M0_MAINTENANCE 0x99 //: initial version
Diletant 74:f4d9c3403578 22 //Maintenance basic commands group
Diletant 76:1c54a614564d 23 #define M0_BASIC 0xda00 //Basic maintenance commands group code
Diletant 76:1c54a614564d 24 #define M0_CLEAR 0xda00 //group command select: e. reset of the register of errors of line 485 //r. очистка регистра ошибок линии 485
Diletant 76:1c54a614564d 25 #define M0_MIRROR 0xda01 //group command select: e. return previous contents of the receiver buffer //r. возврат предыдущего содержимого буфера приемника
Diletant 76:1c54a614564d 26 #define M0_LDPAR_F 0xda02 //group command select: e. load GLD parameters from Flash-memory //r. загрузить параметры ГЛД из флэш-памяти
Diletant 76:1c54a614564d 27 #define M0_LDPAR_D 0xda03 //group command select: e. set GLD parameters by procedure of initialization //r. установить параметры ГЛД процедурой инициализации
Diletant 76:1c54a614564d 28 #define M0_START 0xda04 //group command select: e. switch on the GLD //r. включить ГЛД
Diletant 76:1c54a614564d 29 #define M0_STOP 0xda40 //group command select: e. switch off the GLD //r. выключить ГЛД
Diletant 76:1c54a614564d 30 #define M0_PULSE 0xda0a //group command select: e. generation of the light-up pulse //r. генерация импульса поджига
Diletant 74:f4d9c3403578 31 //Maintenance rate commands group
Diletant 76:1c54a614564d 32 #define M0_RATE 0xdd00 //e. delivery of a stack of parameters M_Rate (Rate2, Rate3) //r. выдача набора параметров M_Rate (Rate2, Rate3)
Diletant 76:1c54a614564d 33 #define M0_RATE_0 0xdd00 //group command select: output parameters set 0?
Diletant 76:1c54a614564d 34 #define M0_RATE_1 0xdd01 //group command select: output parameters set 1?
Diletant 76:1c54a614564d 35 #define M0_RATE_2 0xdd02 //group command select: output parameters set 2
Diletant 76:1c54a614564d 36 #define M0_RATE_3 0xdd03 //group command select: output parameters set 3
Diletant 76:1c54a614564d 37 #define M0_RATE_4 0xdd04 //group command select: output parameters set 4
Diletant 76:1c54a614564d 38 #define M0_RATE_7 0xdd07 //group command select: output parameters set 7
Diletant 74:f4d9c3403578 39
Diletant 74:f4d9c3403578 40 //Other maintenance commands
Diletant 76:1c54a614564d 41 #define M0_STIMUL 0x0a00 //e. the code of the Stimul command //r. код команды Stimul
Diletant 76:1c54a614564d 42 #define M0_RESET 0x8000 //e. software device reset(restart) //r. программный сброс (рестарт) прибора
Diletant 74:f4d9c3403578 43
Diletant 76:1c54a614564d 44 #define M0_CTL_R 0xd900 //e. reading the control register of the device //r. чтение регистра управления устройства
Diletant 76:1c54a614564d 45 #define M0_CTL_M 0xd800 //e. modification of bit of the control register //r. модификация бита регистра управления
Diletant 74:f4d9c3403578 46
Diletant 76:1c54a614564d 47 #define M0_TMP_W 0xe000 //e. writing to the AD7714 circuit (temperature sensors) //r. запись в схемы AD7714 (измерители температуры)
Diletant 76:1c54a614564d 48 #define M0_TMP_R 0xe100 //e. reading from the AD7714 circuit (temperature sensors) //r. чтение из схем AD7714 (измерители температуры)
Diletant 76:1c54a614564d 49 #define M0_E5R_W 0xe200 //e. writing to the register of a mode of the Elio5 card //r. запись в регистр режима платы Elio5
Diletant 76:1c54a614564d 50 #define M0_ADC_R 0xe300 //e. reading data from the ADC of the Elio5 card //r. чтение данных из АЦП платы Elio5
Diletant 76:1c54a614564d 51 #define M0_VIB_W 0xe400 //e. loading of the oscillation period of the dither drive //r. загрузка периода колебаний вибропривода
Diletant 76:1c54a614564d 52 #define M0_CNT_R 0xe500 //e. reading data from the counters of the Elio5 card //r. чтение данных из счетчиков платы Elio5
Diletant 76:1c54a614564d 53 #define M0_GPH_W 0xe600 //e. loading gain factors of photodetector channels //r. загрузка коэффициентов усиления каналов фотоприемника
Diletant 76:1c54a614564d 54 #define M0_FLG_R 0xe700 //e. reading data from the register of input flags //r. чтение данных из регистра входных флагов
Diletant 76:1c54a614564d 55 #define M0_PARAM_W 0xe800 //e. writing working parameter to the data memory //r. запись рабочего параметра в память данных
Diletant 76:1c54a614564d 56 #define M0_PARAM_R 0xe900 //e. reading working parameter of the GLD from the data memory //r. чтение рабочего параметра GLD из памяти данных
Diletant 76:1c54a614564d 57 #define M0_E5RA_W 0xea00 //e. writing in 1st additional (A) register of a mode of the Elio5 card //r. запись в 1-ый дополнительный (А) регистр режима платы Elio5
Diletant 74:f4d9c3403578 58
Diletant 74:f4d9c3403578 59 typedef enum _ResponseType {
Diletant 76:1c54a614564d 60 RESPONSE_NONE, //no sheduled response
Diletant 74:f4d9c3403578 61 RESPONSE_IMMEDIATE, //immediate response for most of requests
Diletant 74:f4d9c3403578 62 RESPONSE_DELAYED, //delayed response for broadcast requests
Diletant 74:f4d9c3403578 63 RESPONSE_PERIODIC //periodic response for some of requests
Diletant 74:f4d9c3403578 64 } ResponseType;
Diletant 74:f4d9c3403578 65
Diletant 74:f4d9c3403578 66 typedef enum _ResponseData {
Diletant 74:f4d9c3403578 67 RESPONSE_BUFFER, //response buffer content as is if not empty
Diletant 74:f4d9c3403578 68 RESPONSE_DELTA_BINS, //fill buffer with Delta_BINS data set
Diletant 74:f4d9c3403578 69 RESPONSE_DELTA_PS, //fill buffer with Delta_PS data set
Diletant 74:f4d9c3403578 70 RESPONSE_DELTA_SF, //fill buffer with Delta_SF data set
Diletant 74:f4d9c3403578 71 RESPONSE_RATE //fill buffer with M_Rate data set
Diletant 74:f4d9c3403578 72 } ResponseData;
Diletant 74:f4d9c3403578 73
Diletant 74:f4d9c3403578 74 #define OutputBufferSize 64
Diletant 74:f4d9c3403578 75 typedef struct _DeviceOutputBuffer {
Diletant 74:f4d9c3403578 76 uint8_t data[OutputBufferSize];
Diletant 74:f4d9c3403578 77 int count; //byte count
Diletant 74:f4d9c3403578 78 } DeviceOutputBuffer;
Diletant 74:f4d9c3403578 79
Diletant 77:8d582faecf6b 80 //Response state
Diletant 74:f4d9c3403578 81 typedef struct _DeviceResponse {
Diletant 77:8d582faecf6b 82 uint8_t enabled; //set enabled when response required
Diletant 74:f4d9c3403578 83 ResponseType type; //how send: immediately/delayed/periodic
Diletant 77:8d582faecf6b 84 uint16_t code; //request code
Diletant 77:8d582faecf6b 85 uint32_t counter; //time from: broadcast line request/broadcast pin request/latest periodic response; values in mks;
Diletant 77:8d582faecf6b 86 uint32_t trigger; //counter trigger value to response; values in mks;
Diletant 75:cc1942179a2f 87 uint32_t rate; //response baud rate
Diletant 74:f4d9c3403578 88 DeviceOutputBuffer buffer;
Diletant 74:f4d9c3403578 89 uint8_t ready;
Diletant 74:f4d9c3403578 90 } DeviceResponse;
Diletant 74:f4d9c3403578 91
Diletant 74:f4d9c3403578 92 #define InputBufferSize 1024
Diletant 69:70849751d98e 93 typedef struct _DeviceInputBuffer {
Diletant 74:f4d9c3403578 94 uint8_t data[InputBufferSize];
Diletant 71:7835a18110bd 95 int start; //read start position
Diletant 71:7835a18110bd 96 int end; //write start position
Diletant 69:70849751d98e 97 } DeviceInputBuffer;
Diletant 69:70849751d98e 98
Diletant 77:8d582faecf6b 99 //Requests queue state
Diletant 74:f4d9c3403578 100 typedef struct _DeviceRequest {
Diletant 74:f4d9c3403578 101 uint32_t rate; //response baud rate
Diletant 74:f4d9c3403578 102 DeviceInputBuffer buffer;
Diletant 74:f4d9c3403578 103 } DeviceRequest;
Diletant 71:7835a18110bd 104
Diletant 77:8d582faecf6b 105 //Requests decoding state
Diletant 74:f4d9c3403578 106 typedef struct _DeviceProtocolDecoder {
Diletant 75:cc1942179a2f 107 uint8_t error; //Decode error encountered
Diletant 75:cc1942179a2f 108 uint8_t count; //Decoded bytes count
Diletant 76:1c54a614564d 109 uint8_t address; //Decoded request address
Diletant 76:1c54a614564d 110 uint8_t version; //Decoded protocol version (currently only 0 version exist)
Diletant 77:8d582faecf6b 111 uint16_t code; //Decoded command code
Diletant 75:cc1942179a2f 112 uint16_t position;//Current decoder position in input buffer
Diletant 75:cc1942179a2f 113 uint16_t CRC; //Current/final CRC of decoded packet
Diletant 74:f4d9c3403578 114 } DeviceProtocolDecoder;
Diletant 54:d94145ba23f4 115
Diletant 77:8d582faecf6b 116 //Response encoding state
Diletant 74:f4d9c3403578 117 typedef struct _DeviceProtocolEncoder {
Diletant 77:8d582faecf6b 118 uint8_t error; //Encode error encountered
Diletant 77:8d582faecf6b 119 uint8_t count; //Encoded bytes count
Diletant 77:8d582faecf6b 120 //uint16_t position;
Diletant 77:8d582faecf6b 121 uint16_t CRC; //Current/final CRC of encoded packet
Diletant 74:f4d9c3403578 122 } DeviceProtocolEncoder;
Diletant 54:d94145ba23f4 123
Diletant 77:8d582faecf6b 124 void Receive(void); //Receive requests to receive buffer
Diletant 77:8d582faecf6b 125 void LineDecode(void); //Decode requests from receive buffer
Diletant 77:8d582faecf6b 126 void PinDecode(void); //Decode hardware pin request
Diletant 77:8d582faecf6b 127 void Encode(void); //Encode response to transmit buffer
Diletant 77:8d582faecf6b 128 void Transmit(void); //Transmit response from transmit buffer
Diletant 61:1b76fe74a0d9 129
Diletant 74:f4d9c3403578 130 uint8_t Decode8(void);
Diletant 74:f4d9c3403578 131 uint16_t Decode16(void);
Diletant 74:f4d9c3403578 132 void DecodeStart(void);
Diletant 74:f4d9c3403578 133 void DecodeEnd(void);
Diletant 74:f4d9c3403578 134 void DecodeCancel(void);
Diletant 74:f4d9c3403578 135 void DecodeFail(void);
Diletant 77:8d582faecf6b 136
Diletant 74:f4d9c3403578 137 void DecodeAddress(void);
Diletant 76:1c54a614564d 138 void DecodeCode(void);
Diletant 76:1c54a614564d 139 void DecodeCode2(void);
Diletant 74:f4d9c3403578 140 void DecodeCRC(void);
Diletant 54:d94145ba23f4 141
Diletant 74:f4d9c3403578 142 void DecodeDeviceMode(void);
Diletant 76:1c54a614564d 143 void DecodeDelta(void);
Diletant 74:f4d9c3403578 144 void DecodeMaintenanceMode(void);
Diletant 76:1c54a614564d 145 void DecodeMBasic(void);
Diletant 74:f4d9c3403578 146 void DecodeMStymul(void);
Diletant 74:f4d9c3403578 147 void DecodeMADCR(void);
Diletant 74:f4d9c3403578 148 void DecodeMTmpW(void);
Diletant 74:f4d9c3403578 149 void DecodeMe5rW(void);
Diletant 74:f4d9c3403578 150 void DecodeMCntR(void);
Diletant 74:f4d9c3403578 151 void DecodeMFlgR(void);
Diletant 74:f4d9c3403578 152 void DecodeMVibW(void);
Diletant 74:f4d9c3403578 153 void DecodeMGphW(void);
Diletant 74:f4d9c3403578 154 void DecodeMRate(void);
Diletant 74:f4d9c3403578 155 void DecodeMParamR(void);
Diletant 74:f4d9c3403578 156 void DecodeMParamW(void);
Diletant 74:f4d9c3403578 157 void DecodeMControl(void);
Diletant 74:f4d9c3403578 158 void DecodeMClear(void);
Diletant 74:f4d9c3403578 159 void DecodeMMirror(void);
Diletant 74:f4d9c3403578 160 void DecodeMLdParF(void);
Diletant 74:f4d9c3403578 161 void DecodeMLdParD(void);
Diletant 74:f4d9c3403578 162 void DecodeMStart(void);
Diletant 74:f4d9c3403578 163 void DecodeMStop(void);
Diletant 74:f4d9c3403578 164 void DecodeMPulse(void);
Diletant 74:f4d9c3403578 165 void DecodeMRate2(void);
Diletant 74:f4d9c3403578 166 void DecodeMRate3(void);
Diletant 74:f4d9c3403578 167 void DecodeMe5raW(void);
Diletant 64:8179dacbf32b 168
Diletant 72:f5e189c62bcb 169 void Encode8(uint8_t);
Diletant 72:f5e189c62bcb 170 void Encode16(uint16_t);
Diletant 73:29fccfe239a3 171
Diletant 73:29fccfe239a3 172 void EncodeStart(void);
Diletant 73:29fccfe239a3 173 void EncodeEnd(void);
Diletant 77:8d582faecf6b 174 void EncodeFail(void);
Diletant 76:1c54a614564d 175 void EncodeAddress(void);
Diletant 76:1c54a614564d 176 void EncodeCRC(void);
Diletant 73:29fccfe239a3 177
Diletant 72:f5e189c62bcb 178 void EncodeDeviceMode(void);
Diletant 72:f5e189c62bcb 179 void EncodeSysRgR(void);
Diletant 73:29fccfe239a3 180
Diletant 76:1c54a614564d 181 void EncodeBINSDiff(void);
Diletant 76:1c54a614564d 182 void EncodeValidBINS(void);
Diletant 72:f5e189c62bcb 183
Diletant 54:d94145ba23f4 184 #endif /* __DEVICEPROTOCOL_H__ */