Dmitry Kovalev / Mbed 2 deprecated LG2

Dependencies:   mbed

Fork of LG by igor Apu

Committer:
Diletant
Date:
Mon Mar 21 13:29:41 2016 +0000
Revision:
84:82d7073d36ef
Parent:
81:a809491285c9
Child:
138:14a0c452cf32
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 "stdint.h"
Diletant 54:d94145ba23f4 5
Diletant 74:f4d9c3403578 6 #define BROADCAST_ADDRESS 0x1f
Diletant 74:f4d9c3403578 7 #define BROADCAST_FRAME 100 //100 mks
Diletant 74:f4d9c3403578 8
Diletant 84:82d7073d36ef 9 //All commands
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_1 0xdd01 //group command select: output parameters set 1?
Diletant 76:1c54a614564d 34 #define M0_RATE_2 0xdd02 //group command select: output parameters set 2
Diletant 76:1c54a614564d 35 #define M0_RATE_3 0xdd03 //group command select: output parameters set 3
Diletant 76:1c54a614564d 36 #define M0_RATE_4 0xdd04 //group command select: output parameters set 4
Diletant 76:1c54a614564d 37 #define M0_RATE_7 0xdd07 //group command select: output parameters set 7
Diletant 74:f4d9c3403578 38
Diletant 74:f4d9c3403578 39 //Other maintenance commands
Diletant 76:1c54a614564d 40 #define M0_STIMUL 0x0a00 //e. the code of the Stimul command //r. код команды Stimul
Diletant 76:1c54a614564d 41 #define M0_RESET 0x8000 //e. software device reset(restart) //r. программный сброс (рестарт) прибора
Diletant 74:f4d9c3403578 42
Diletant 84:82d7073d36ef 43 #define M0_CTL_R 0xd900 //e. reading the control register RgConA/B of the device //r. чтение регистра управления устройства
Diletant 84:82d7073d36ef 44 #define M0_CTL_A_R 0xd900 //e. reading the control register RgConA of the device //r. чтение регистра управления устройства
Diletant 84:82d7073d36ef 45 #define M0_CTL_B_R 0xd910 //e. reading the control register RgConB of the device //r. чтение регистра управления устройства
Diletant 76:1c54a614564d 46 #define M0_CTL_M 0xd800 //e. modification of bit of the control register //r. модификация бита регистра управления
Diletant 74:f4d9c3403578 47
Diletant 76:1c54a614564d 48 #define M0_TMP_W 0xe000 //e. writing to the AD7714 circuit (temperature sensors) //r. запись в схемы AD7714 (измерители температуры)
Diletant 76:1c54a614564d 49 #define M0_TMP_R 0xe100 //e. reading from the AD7714 circuit (temperature sensors) //r. чтение из схем AD7714 (измерители температуры)
Diletant 76:1c54a614564d 50 #define M0_E5R_W 0xe200 //e. writing to the register of a mode of the Elio5 card //r. запись в регистр режима платы Elio5
Diletant 76:1c54a614564d 51 #define M0_ADC_R 0xe300 //e. reading data from the ADC of the Elio5 card //r. чтение данных из АЦП платы Elio5
Diletant 76:1c54a614564d 52 #define M0_VIB_W 0xe400 //e. loading of the oscillation period of the dither drive //r. загрузка периода колебаний вибропривода
Diletant 76:1c54a614564d 53 #define M0_CNT_R 0xe500 //e. reading data from the counters of the Elio5 card //r. чтение данных из счетчиков платы Elio5
Diletant 76:1c54a614564d 54 #define M0_GPH_W 0xe600 //e. loading gain factors of photodetector channels //r. загрузка коэффициентов усиления каналов фотоприемника
Diletant 76:1c54a614564d 55 #define M0_FLG_R 0xe700 //e. reading data from the register of input flags //r. чтение данных из регистра входных флагов
Diletant 76:1c54a614564d 56 #define M0_PARAM_W 0xe800 //e. writing working parameter to the data memory //r. запись рабочего параметра в память данных
Diletant 76:1c54a614564d 57 #define M0_PARAM_R 0xe900 //e. reading working parameter of the GLD from the data memory //r. чтение рабочего параметра GLD из памяти данных
Diletant 76:1c54a614564d 58 #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 59
Diletant 84:82d7073d36ef 60 //Actual commands:
Diletant 84:82d7073d36ef 61 //BINS
Diletant 84:82d7073d36ef 62 // GLD initialization sequence:
Diletant 84:82d7073d36ef 63 // a5 04 - external latch with DeltaPS format
Diletant 84:82d7073d36ef 64 // a0 70 - DeltaPS 921600/921600 by request only
Diletant 84:82d7073d36ef 65 // Other:
Diletant 84:82d7073d36ef 66 // 80 00 - reset
Diletant 84:82d7073d36ef 67 //BINS/AskGLD/Techno
Diletant 84:82d7073d36ef 68 // 99 99 - mainteneance
Diletant 84:82d7073d36ef 69 //Techno
Diletant 84:82d7073d36ef 70 // d8 90 - set bit 0 of RgConB
Diletant 84:82d7073d36ef 71 // d8 10 - reset bit 0 of RgConB
Diletant 84:82d7073d36ef 72 // dd 81 - periodic 38400 MRate
Diletant 84:82d7073d36ef 73 // a0 b0 - periodic 115200/115200 DeltaPS
Diletant 84:82d7073d36ef 74
Diletant 84:82d7073d36ef 75 //Registers:
Diletant 84:82d7073d36ef 76 // RgConA - flags of regulator loops
Diletant 84:82d7073d36ef 77 // RgConB - counting mode: 00 - reference counters, 01 - dither counters and moving average filter
Diletant 84:82d7073d36ef 78
Diletant 84:82d7073d36ef 79
Diletant 74:f4d9c3403578 80 typedef enum _ResponseType {
Diletant 76:1c54a614564d 81 RESPONSE_NONE, //no sheduled response
Diletant 74:f4d9c3403578 82 RESPONSE_IMMEDIATE, //immediate response for most of requests
Diletant 74:f4d9c3403578 83 RESPONSE_DELAYED, //delayed response for broadcast requests
Diletant 74:f4d9c3403578 84 RESPONSE_PERIODIC //periodic response for some of requests
Diletant 74:f4d9c3403578 85 } ResponseType;
Diletant 74:f4d9c3403578 86
Diletant 74:f4d9c3403578 87 typedef enum _ResponseData {
Diletant 74:f4d9c3403578 88 RESPONSE_BUFFER, //response buffer content as is if not empty
Diletant 74:f4d9c3403578 89 RESPONSE_DELTA_BINS, //fill buffer with Delta_BINS data set
Diletant 74:f4d9c3403578 90 RESPONSE_DELTA_PS, //fill buffer with Delta_PS data set
Diletant 74:f4d9c3403578 91 RESPONSE_DELTA_SF, //fill buffer with Delta_SF data set
Diletant 74:f4d9c3403578 92 RESPONSE_RATE //fill buffer with M_Rate data set
Diletant 74:f4d9c3403578 93 } ResponseData;
Diletant 74:f4d9c3403578 94
Diletant 74:f4d9c3403578 95 #define OutputBufferSize 64
Diletant 74:f4d9c3403578 96 typedef struct _DeviceOutputBuffer {
Diletant 74:f4d9c3403578 97 uint8_t data[OutputBufferSize];
Diletant 81:a809491285c9 98 uint8_t count; //byte count
Diletant 74:f4d9c3403578 99 } DeviceOutputBuffer;
Diletant 74:f4d9c3403578 100
Diletant 77:8d582faecf6b 101 //Response state
Diletant 74:f4d9c3403578 102 typedef struct _DeviceResponse {
Diletant 77:8d582faecf6b 103 uint8_t enabled; //set enabled when response required
Diletant 74:f4d9c3403578 104 ResponseType type; //how send: immediately/delayed/periodic
Diletant 77:8d582faecf6b 105 uint16_t code; //request code
Diletant 80:7eb5dbb80c81 106 uint32_t counter; //time from: broadcast line request/broadcast pin request/latest periodic response; values in mks; access this only from timer interrupt
Diletant 77:8d582faecf6b 107 uint32_t trigger; //counter trigger value to response; values in mks;
Diletant 80:7eb5dbb80c81 108 uint8_t triggered;//set this only from timer interrupt, clear from main loop
Diletant 75:cc1942179a2f 109 uint32_t rate; //response baud rate
Diletant 74:f4d9c3403578 110 DeviceOutputBuffer buffer;
Diletant 74:f4d9c3403578 111 uint8_t ready;
Diletant 74:f4d9c3403578 112 } DeviceResponse;
Diletant 74:f4d9c3403578 113
Diletant 74:f4d9c3403578 114 #define InputBufferSize 1024
Diletant 69:70849751d98e 115 typedef struct _DeviceInputBuffer {
Diletant 74:f4d9c3403578 116 uint8_t data[InputBufferSize];
Diletant 71:7835a18110bd 117 int start; //read start position
Diletant 71:7835a18110bd 118 int end; //write start position
Diletant 69:70849751d98e 119 } DeviceInputBuffer;
Diletant 69:70849751d98e 120
Diletant 77:8d582faecf6b 121 //Requests queue state
Diletant 74:f4d9c3403578 122 typedef struct _DeviceRequest {
Diletant 74:f4d9c3403578 123 uint32_t rate; //response baud rate
Diletant 74:f4d9c3403578 124 DeviceInputBuffer buffer;
Diletant 74:f4d9c3403578 125 } DeviceRequest;
Diletant 71:7835a18110bd 126
Diletant 77:8d582faecf6b 127 //Requests decoding state
Diletant 74:f4d9c3403578 128 typedef struct _DeviceProtocolDecoder {
Diletant 75:cc1942179a2f 129 uint8_t error; //Decode error encountered
Diletant 75:cc1942179a2f 130 uint8_t count; //Decoded bytes count
Diletant 76:1c54a614564d 131 uint8_t address; //Decoded request address
Diletant 76:1c54a614564d 132 uint8_t version; //Decoded protocol version (currently only 0 version exist)
Diletant 77:8d582faecf6b 133 uint16_t code; //Decoded command code
Diletant 75:cc1942179a2f 134 uint16_t position;//Current decoder position in input buffer
Diletant 75:cc1942179a2f 135 uint16_t CRC; //Current/final CRC of decoded packet
Diletant 74:f4d9c3403578 136 } DeviceProtocolDecoder;
Diletant 54:d94145ba23f4 137
Diletant 77:8d582faecf6b 138 //Response encoding state
Diletant 74:f4d9c3403578 139 typedef struct _DeviceProtocolEncoder {
Diletant 77:8d582faecf6b 140 uint8_t error; //Encode error encountered
Diletant 77:8d582faecf6b 141 uint8_t count; //Encoded bytes count
Diletant 77:8d582faecf6b 142 //uint16_t position;
Diletant 77:8d582faecf6b 143 uint16_t CRC; //Current/final CRC of encoded packet
Diletant 74:f4d9c3403578 144 } DeviceProtocolEncoder;
Diletant 54:d94145ba23f4 145
Diletant 78:0ea9d02b7b46 146 //void Receive(void); //Receive requests to receive buffer - receive in UART1 interrupt handler
Diletant 77:8d582faecf6b 147 void LineDecode(void); //Decode requests from receive buffer
Diletant 77:8d582faecf6b 148 void PinDecode(void); //Decode hardware pin request
Diletant 77:8d582faecf6b 149 void Encode(void); //Encode response to transmit buffer
Diletant 77:8d582faecf6b 150 void Transmit(void); //Transmit response from transmit buffer
Diletant 61:1b76fe74a0d9 151
Diletant 81:a809491285c9 152 //Decoder elementary functions
Diletant 74:f4d9c3403578 153 uint8_t Decode8(void);
Diletant 74:f4d9c3403578 154 uint16_t Decode16(void);
Diletant 81:a809491285c9 155
Diletant 81:a809491285c9 156 //Decoder common functions
Diletant 74:f4d9c3403578 157 void DecodeStart(void);
Diletant 74:f4d9c3403578 158 void DecodeEnd(void);
Diletant 74:f4d9c3403578 159 void DecodeCancel(void);
Diletant 74:f4d9c3403578 160 void DecodeFail(void);
Diletant 77:8d582faecf6b 161
Diletant 74:f4d9c3403578 162 void DecodeAddress(void);
Diletant 76:1c54a614564d 163 void DecodeCode(void);
Diletant 79:aecee1718d6a 164 void DecodeExtentionCode(void);
Diletant 74:f4d9c3403578 165 void DecodeCRC(void);
Diletant 54:d94145ba23f4 166
Diletant 81:a809491285c9 167 //Decoder data output functions
Diletant 74:f4d9c3403578 168 void DecodeDeviceMode(void);
Diletant 76:1c54a614564d 169 void DecodeDelta(void);
Diletant 81:a809491285c9 170
Diletant 81:a809491285c9 171 //Decoder maintenance functions
Diletant 74:f4d9c3403578 172 void DecodeMaintenanceMode(void);
Diletant 81:a809491285c9 173
Diletant 76:1c54a614564d 174 void DecodeMBasic(void);
Diletant 81:a809491285c9 175 void DoMaintenanceClear(void);
Diletant 81:a809491285c9 176 void DoMaintenanceMirror(void);
Diletant 81:a809491285c9 177 void DoMaintenanceLdParF(void);
Diletant 81:a809491285c9 178 void DoMaintenanceLdParD(void);
Diletant 81:a809491285c9 179 void DoMaintenanceStart(void);
Diletant 81:a809491285c9 180 void DoMaintenanceStop(void);
Diletant 81:a809491285c9 181 void DoMaintenancePulse(void);
Diletant 81:a809491285c9 182
Diletant 74:f4d9c3403578 183 void DecodeMStymul(void);
Diletant 84:82d7073d36ef 184 void DecodeMReset(void);
Diletant 84:82d7073d36ef 185 void DecodeMControlRead(void);
Diletant 84:82d7073d36ef 186 void DecodeMControlWrite(void);
Diletant 74:f4d9c3403578 187 void DecodeMADCR(void);
Diletant 74:f4d9c3403578 188 void DecodeMTmpW(void);
Diletant 74:f4d9c3403578 189 void DecodeMe5rW(void);
Diletant 74:f4d9c3403578 190 void DecodeMCntR(void);
Diletant 74:f4d9c3403578 191 void DecodeMFlgR(void);
Diletant 74:f4d9c3403578 192 void DecodeMVibW(void);
Diletant 74:f4d9c3403578 193 void DecodeMGphW(void);
Diletant 81:a809491285c9 194
Diletant 74:f4d9c3403578 195 void DecodeMRate(void);
Diletant 81:a809491285c9 196 void DecodeMRate2(void);
Diletant 81:a809491285c9 197 void DecodeMRate3(void);
Diletant 81:a809491285c9 198
Diletant 74:f4d9c3403578 199 void DecodeMParamR(void);
Diletant 74:f4d9c3403578 200 void DecodeMParamW(void);
Diletant 74:f4d9c3403578 201 void DecodeMe5raW(void);
Diletant 64:8179dacbf32b 202
Diletant 81:a809491285c9 203 //Encoder elementary functions
Diletant 72:f5e189c62bcb 204 void Encode8(uint8_t);
Diletant 72:f5e189c62bcb 205 void Encode16(uint16_t);
Diletant 73:29fccfe239a3 206
Diletant 81:a809491285c9 207 //Encoder common functions
Diletant 73:29fccfe239a3 208 void EncodeStart(void);
Diletant 73:29fccfe239a3 209 void EncodeEnd(void);
Diletant 77:8d582faecf6b 210 void EncodeFail(void);
Diletant 76:1c54a614564d 211 void EncodeAddress(void);
Diletant 76:1c54a614564d 212 void EncodeCRC(void);
Diletant 73:29fccfe239a3 213
Diletant 81:a809491285c9 214 //Encoder specific functions
Diletant 72:f5e189c62bcb 215 void EncodeDeviceMode(void);
Diletant 72:f5e189c62bcb 216 void EncodeSysRgR(void);
Diletant 73:29fccfe239a3 217
Diletant 76:1c54a614564d 218 void EncodeBINSDiff(void);
Diletant 76:1c54a614564d 219 void EncodeValidBINS(void);
Diletant 72:f5e189c62bcb 220
Diletant 54:d94145ba23f4 221 #endif /* __DEVICEPROTOCOL_H__ */