123

Dependencies:   mbed

Fork of LG by igor Apu

Committer:
Diletant
Date:
Sun Jul 03 13:40:48 2016 +0000
Revision:
177:672ef279c8e0
Parent:
167:bedc0a9d559a
Device&... update. Some Ask_Gld functionality. Not final!!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Diletant 161:efd949e8d536 1 #ifndef __DEVICE_USER_PROTOCOL_H__
Diletant 161:efd949e8d536 2 #define __DEVICE_USER_PROTOCOL_H__
Diletant 161:efd949e8d536 3
Diletant 161:efd949e8d536 4 #include "stdint.h"
Diletant 161:efd949e8d536 5 #include "DeviceUserProtocolRequest.h"
Diletant 161:efd949e8d536 6 #include "DeviceUserProtocolResponse.h"
Diletant 161:efd949e8d536 7 #include "DeviceUserProtocolDecoder.h"
Diletant 161:efd949e8d536 8 #include "DeviceUserProtocolEncoder.h"
Diletant 161:efd949e8d536 9
Diletant 161:efd949e8d536 10 #define BROADCAST_ADDRESS 0x1f
Diletant 161:efd949e8d536 11 #define BROADCAST_FRAME 100 //100 mks
Diletant 161:efd949e8d536 12
Diletant 161:efd949e8d536 13 //All commands
Diletant 161:efd949e8d536 14 #define DELTA_PS 0xa000 //B_DeltaPS command code: output of accumulated pulses and ACS parameters as 22 indexed packets sequence
Diletant 161:efd949e8d536 15 #define DELTA_BINS 0xb000 //B_DeltaBINS command code: output of accumulated pulses and data validity attribute in one packet
Diletant 161:efd949e8d536 16 #define DELTA_SF 0xb200 //B_DeltaSF command code: scale factor measurement data output in one packet
Diletant 177:672ef279c8e0 17 #define DEV_MODE 0xa500 //Device_Mode command code
Diletant 177:672ef279c8e0 18 #define BIT_MODE 0xa700 //B.I.T. (built-in test) command code
Diletant 161:efd949e8d536 19
Diletant 177:672ef279c8e0 20 #define MAINTENANCE 0x9900 //Maintenance mode command code
Diletant 161:efd949e8d536 21 //Maintenance command set versions
Diletant 161:efd949e8d536 22 #define M0_MAINTENANCE 0x99 //: initial version
Diletant 161:efd949e8d536 23 //Maintenance basic commands group
Diletant 161:efd949e8d536 24 #define M0_BASIC 0xda00 //Basic maintenance commands group code
Diletant 177:672ef279c8e0 25 #define M0_CLEAR 0xda00 //group command select: reset line 485 error register
Diletant 177:672ef279c8e0 26 #define M0_MIRROR 0xda01 //group command select: return previous contents of the receiver buffer
Diletant 177:672ef279c8e0 27 #define M0_LDPAR_F 0xda02 //group command select: load device parameters from Flash-memory
Diletant 177:672ef279c8e0 28 #define M0_LDPAR_D 0xda03 //group command select: set device parameters by procedure of initialization
Diletant 177:672ef279c8e0 29 #define M0_START 0xda04 //group command select: switch on the device
Diletant 177:672ef279c8e0 30 #define M0_STOP 0xda40 //group command select: switch off the device
Diletant 177:672ef279c8e0 31 #define M0_PULSE 0xda0a //group command select: generation of the light-up pulse
Diletant 161:efd949e8d536 32 //Maintenance rate commands group
Diletant 177:672ef279c8e0 33 #define M0_RATE 0xdd00 //M_Rate commands group code
Diletant 177:672ef279c8e0 34 #define M0_RATE_1 0xdd01 //group command select: output parameters set 1 (MRate)
Diletant 177:672ef279c8e0 35 #define M0_RATE_2 0xdd02 //group command select: output parameters set 2 (MRate2)
Diletant 177:672ef279c8e0 36 #define M0_RATE_3 0xdd03 //group command select: output parameters set 3 (MRate3)
Diletant 177:672ef279c8e0 37 #define M0_RATE_4 0xdd04 //group command select: output parameters set 4 (MRate4)
Diletant 177:672ef279c8e0 38 #define M0_RATE_7 0xdd07 //group command select: output parameters set 7 (MRate7)
Diletant 161:efd949e8d536 39
Diletant 161:efd949e8d536 40 //Other maintenance commands
Diletant 177:672ef279c8e0 41 #define M0_STIMUL 0x0a00 //MStimul command code
Diletant 177:672ef279c8e0 42 #define M0_RESET 0x8000 //software device reset(restart)
Diletant 161:efd949e8d536 43
Diletant 177:672ef279c8e0 44 #define M0_CTL_R 0xd900 //reading the control register RgConA/B of the device
Diletant 177:672ef279c8e0 45 #define M0_CTL_A_R 0xd900 //MCtlR command code mask: reading the control register RgConA of the device
Diletant 177:672ef279c8e0 46 #define M0_CTL_B_R 0xd910 //MCtlR command code mask: reading the control register RgConB of the device
Diletant 177:672ef279c8e0 47 #define M0_CTL_M 0xd800 //modification of bit of the control register
Diletant 177:672ef279c8e0 48 #define M0_CTL_A_M 0xd800 //MCtlM command code mask: modification control register RgConA of the device
Diletant 177:672ef279c8e0 49 #define M0_CTL_B_M 0xd810 //MCtlM command code mask: modification the control register RgConB of the device
Diletant 161:efd949e8d536 50
Diletant 177:672ef279c8e0 51 #define M0_TMP_W 0xe000 //writing to the AD7714 circuit (temperature sensors)
Diletant 177:672ef279c8e0 52 #define M0_TMP_R 0xe100 //reading from the AD7714 circuit (temperature sensors)
Diletant 177:672ef279c8e0 53 #define M0_E5R_W 0xe200 //writing to the register of a mode of the Elio5 card
Diletant 177:672ef279c8e0 54 #define M0_ADC_R 0xe300 //reading data from the ADC of the Elio5 card
Diletant 177:672ef279c8e0 55 #define M0_VIB_W 0xe400 //loading of the oscillation period of the dither drive
Diletant 177:672ef279c8e0 56 #define M0_CNT_R 0xe500 //reading data from the counters of the Elio5 card
Diletant 177:672ef279c8e0 57 #define M0_GPH_W 0xe600 //loading gain factors of photodetector channels
Diletant 177:672ef279c8e0 58 #define M0_FLG_R 0xe700 //reading data from the register of input flags
Diletant 177:672ef279c8e0 59 #define M0_PARAM_W 0xe800 //writing working parameter to the data memory
Diletant 177:672ef279c8e0 60 #define M0_PARAM_R 0xe900 //reading working parameter of the GLD from the data memory
Diletant 177:672ef279c8e0 61 #define M0_E5RA_W 0xea00 //writing in 1st additional (A) register of a mode of the Elio5 card
Diletant 161:efd949e8d536 62
Diletant 161:efd949e8d536 63 //Factory maintenance commands
Diletant 161:efd949e8d536 64 #define FACTORY_ACCESS 0xff00 //Factory access: command mask
Diletant 161:efd949e8d536 65
Diletant 161:efd949e8d536 66 #define H_PARAM8_R 0xff00 //Hash access: 0000b read 1-byte param
Diletant 161:efd949e8d536 67 #define H_PARAM16_R 0xff01 //Hash access: 0001b read 2-byte param
Diletant 161:efd949e8d536 68 #define H_PARAM32_R 0xff03 //Hash access: 0010b read 4-byte param
Diletant 161:efd949e8d536 69 #define H_BYTES_R 0xff0f //Hash access: 1111b read bytes param
Diletant 161:efd949e8d536 70
Diletant 161:efd949e8d536 71 #define H_PARAM8_W 0xff10 //Hash access: 0000b write 1-byte param
Diletant 161:efd949e8d536 72 #define H_PARAM16_W 0xff11 //Hash access: 0001b write 2-byte param
Diletant 161:efd949e8d536 73 #define H_PARAM32_W 0xff13 //Hash access: 0010b write 4-byte param
Diletant 161:efd949e8d536 74 #define H_BYTES_W 0xff1f //Hash access: 1111b write bytes param
Diletant 161:efd949e8d536 75
Diletant 161:efd949e8d536 76 #define H_FUNC_PARAM0_BY_IMM8 0xff20 //Hash access: 0000b set function parameter 0 by 8 bit immediate value
Diletant 161:efd949e8d536 77 #define H_FUNC_PARAM1_BY_IMM8 0xff24 //Hash access: 0100b set function parameter 1 by 8 bit immediate value
Diletant 161:efd949e8d536 78 #define H_FUNC_PARAM2_BY_IMM8 0xff28 //Hash access: 1000b set function parameter 2 by 8 bit immediate value
Diletant 161:efd949e8d536 79 #define H_FUNC_PARAM3_BY_IMM8 0xff2c //Hash access: 1100b set function parameter 3 by 8 bit immediate value
Diletant 161:efd949e8d536 80
Diletant 161:efd949e8d536 81 #define H_FUNC_PARAM0_BY_IMM16 0xff21 //Hash access: 0001b set function parameter 0 by 16 bit immediate value
Diletant 161:efd949e8d536 82 #define H_FUNC_PARAM1_BY_IMM16 0xff25 //Hash access: 0101b set function parameter 1 by 16 bit immediate value
Diletant 161:efd949e8d536 83 #define H_FUNC_PARAM2_BY_IMM16 0xff29 //Hash access: 1001b set function parameter 2 by 16 bit immediate value
Diletant 161:efd949e8d536 84 #define H_FUNC_PARAM3_BY_IMM16 0xff2d //Hash access: 1101b set function parameter 3 by 16 bit immediate value
Diletant 161:efd949e8d536 85
Diletant 161:efd949e8d536 86 #define H_FUNC_PARAM0_BY_IMM32 0xff23 //Hash access: 0011b set function parameter 0 by 32 bit immediate value
Diletant 161:efd949e8d536 87 #define H_FUNC_PARAM1_BY_IMM32 0xff27 //Hash access: 0111b set function parameter 1 by 32 bit immediate value
Diletant 161:efd949e8d536 88 #define H_FUNC_PARAM2_BY_IMM32 0xff2b //Hash access: 1011b set function parameter 2 by 32 bit immediate value
Diletant 161:efd949e8d536 89 #define H_FUNC_PARAM3_BY_IMM32 0xff2f //Hash access: 1111b set function parameter 3 by 32 bit immediate value
Diletant 161:efd949e8d536 90
Diletant 161:efd949e8d536 91 #define H_FUNC_PARAM0_BY_VAL8 0xff30 //Hash access: 0000b set function parameter 0 by 8 bit variable value
Diletant 161:efd949e8d536 92 #define H_FUNC_PARAM1_BY_VAL8 0xff34 //Hash access: 0100b set function parameter 1 by 8 bit variable value
Diletant 161:efd949e8d536 93 #define H_FUNC_PARAM2_BY_VAL8 0xff38 //Hash access: 1000b set function parameter 2 by 8 bit variable value
Diletant 161:efd949e8d536 94 #define H_FUNC_PARAM3_BY_VAL8 0xff3c //Hash access: 1100b set function parameter 3 by 8 bit variable value
Diletant 161:efd949e8d536 95
Diletant 161:efd949e8d536 96 #define H_FUNC_PARAM0_BY_VAL16 0xff31 //Hash access: 0001b set function parameter 0 by 16 bit variable value
Diletant 161:efd949e8d536 97 #define H_FUNC_PARAM1_BY_VAL16 0xff35 //Hash access: 0101b set function parameter 1 by 16 bit variable value
Diletant 161:efd949e8d536 98 #define H_FUNC_PARAM2_BY_VAL16 0xff39 //Hash access: 1001b set function parameter 2 by 16 bit variable value
Diletant 161:efd949e8d536 99 #define H_FUNC_PARAM3_BY_VAL16 0xff3d //Hash access: 1101b set function parameter 3 by 16 bit variable value
Diletant 161:efd949e8d536 100
Diletant 161:efd949e8d536 101 #define H_FUNC_PARAM0_BY_VAL32 0xff33 //Hash access: 0011b set function parameter 0 by 32 bit variable value
Diletant 161:efd949e8d536 102 #define H_FUNC_PARAM1_BY_VAL32 0xff37 //Hash access: 0111b set function parameter 1 by 32 bit variable value
Diletant 161:efd949e8d536 103 #define H_FUNC_PARAM2_BY_VAL32 0xff3b //Hash access: 1011b set function parameter 2 by 32 bit variable value
Diletant 161:efd949e8d536 104 #define H_FUNC_PARAM3_BY_VAL32 0xff3f //Hash access: 1111b set function parameter 3 by 32 bit variable value
Diletant 161:efd949e8d536 105
Diletant 161:efd949e8d536 106 #define H_FUNC_PARAM0_BY_REF8 0xff40 //Hash access: 0000b set function parameter 0 by 8 bit variable reference
Diletant 161:efd949e8d536 107 #define H_FUNC_PARAM1_BY_REF8 0xff44 //Hash access: 0100b set function parameter 1 by 8 bit variable reference
Diletant 161:efd949e8d536 108 #define H_FUNC_PARAM2_BY_REF8 0xff48 //Hash access: 1000b set function parameter 2 by 8 bit variable reference
Diletant 161:efd949e8d536 109 #define H_FUNC_PARAM3_BY_REF8 0xff4c //Hash access: 1100b set function parameter 3 by 8 bit variable reference
Diletant 161:efd949e8d536 110
Diletant 161:efd949e8d536 111 #define H_FUNC_PARAM0_BY_REF16 0xff41 //Hash access: 0001b set function parameter 0 by 16 bit variable reference
Diletant 161:efd949e8d536 112 #define H_FUNC_PARAM1_BY_REF16 0xff45 //Hash access: 0101b set function parameter 1 by 16 bit variable reference
Diletant 161:efd949e8d536 113 #define H_FUNC_PARAM2_BY_REF16 0xff49 //Hash access: 1001b set function parameter 2 by 16 bit variable reference
Diletant 161:efd949e8d536 114 #define H_FUNC_PARAM3_BY_REF16 0xff4d //Hash access: 1101b set function parameter 3 by 16 bit variable reference
Diletant 161:efd949e8d536 115
Diletant 161:efd949e8d536 116 #define H_FUNC_PARAM0_BY_REF32 0xff43 //Hash access: 0011b set function parameter 0 by 32 bit variable reference
Diletant 161:efd949e8d536 117 #define H_FUNC_PARAM1_BY_REF32 0xff47 //Hash access: 0111b set function parameter 1 by 32 bit variable reference
Diletant 161:efd949e8d536 118 #define H_FUNC_PARAM2_BY_REF32 0xff4b //Hash access: 1011b set function parameter 2 by 32 bit variable reference
Diletant 161:efd949e8d536 119 #define H_FUNC_PARAM3_BY_REF32 0xff4f //Hash access: 1111b set function parameter 3 by 32 bit variable reference
Diletant 161:efd949e8d536 120
Diletant 161:efd949e8d536 121 #define FUNCTION_CALL 0xff50 //Hash access: function call - no parameters
Diletant 161:efd949e8d536 122 #define FUNCTION_CALL_1 0xff51 //Hash access: function call - 1 parameter
Diletant 161:efd949e8d536 123 #define FUNCTION_CALL_2 0xff52 //Hash access: function call - 2 parameters
Diletant 161:efd949e8d536 124 #define FUNCTION_CALL_3 0xff53 //Hash access: function call - 3 parameters
Diletant 161:efd949e8d536 125 #define FUNCTION_CALL_4 0xff54 //Hash access: function call - 4 parameters
Diletant 161:efd949e8d536 126
Diletant 161:efd949e8d536 127 #define FLASH_READ_ALL 0xff60 //Flash access: read all from flash
Diletant 161:efd949e8d536 128 #define FLASH_WRITE_ALL 0xff70 //Flash access: write all to flash
Diletant 161:efd949e8d536 129
Diletant 161:efd949e8d536 130 //Common response messages
Diletant 161:efd949e8d536 131 #define MESSAGE_OK 0x0000
Diletant 161:efd949e8d536 132 #define MESSAGE_UNKNOWN_REQUEST_CODE 0x8000
Diletant 161:efd949e8d536 133 #define MESSAGE_UNKNOWN_REQUEST_PARAMETER 0x8001
Diletant 161:efd949e8d536 134 #define MESSAGE_UNKNOWN_REQUEST_HASH 0x8002
Diletant 161:efd949e8d536 135 #define MESSAGE_WRONG_REQUEST_VALUE_SIZE 0x8003
Diletant 161:efd949e8d536 136 #define MESSAGE_WRONG_REQUEST_VALUE_RANGE 0x8004
Diletant 161:efd949e8d536 137
Diletant 161:efd949e8d536 138 //Actual commands:
Diletant 161:efd949e8d536 139 //BINS
Diletant 161:efd949e8d536 140 // GLD initialization sequence:
Diletant 161:efd949e8d536 141 // a5 04 - external latch with DeltaPS format
Diletant 161:efd949e8d536 142 // a0 70 - DeltaPS 921600/921600 by request only
Diletant 161:efd949e8d536 143 // Other:
Diletant 161:efd949e8d536 144 // 80 00 - reset
Diletant 161:efd949e8d536 145 //BINS/AskGLD/Techno
Diletant 161:efd949e8d536 146 // 99 99 - maintenance
Diletant 161:efd949e8d536 147 //Techno
Diletant 161:efd949e8d536 148 // d8 90 - set bit 0 of RgConB
Diletant 161:efd949e8d536 149 // d8 10 - reset bit 0 of RgConB
Diletant 161:efd949e8d536 150 // dd 81 - periodic 38400 MRate
Diletant 161:efd949e8d536 151 // a0 b0 - periodic 115200/115200 DeltaPS
Diletant 161:efd949e8d536 152
Diletant 161:efd949e8d536 153 //Registers:
Diletant 161:efd949e8d536 154 // RgConA - flags of regulator loops
Diletant 161:efd949e8d536 155 // RgConB - counting mode: 00 - reference counters, 01 - dither counters and moving average filter
Diletant 161:efd949e8d536 156
Diletant 161:efd949e8d536 157 //User protocol typedefs
Diletant 161:efd949e8d536 158 typedef struct _DeviceUserProtocol {
Diletant 161:efd949e8d536 159 //Device address
Diletant 161:efd949e8d536 160 uint16_t address;
Diletant 161:efd949e8d536 161 //Units
Diletant 161:efd949e8d536 162 DeviceUserProtocolDecoder decoder;
Diletant 161:efd949e8d536 163 DeviceUserProtocolEncoder encoder;
Diletant 161:efd949e8d536 164 DeviceRequest request;
Diletant 161:efd949e8d536 165 DeviceResponse response;
Diletant 161:efd949e8d536 166 } DeviceUserProtocol;
Diletant 161:efd949e8d536 167
Diletant 161:efd949e8d536 168 //User communication initialization functions
Diletant 167:bedc0a9d559a 169 void InitUserProtocolDefaultSettings(void);
Diletant 167:bedc0a9d559a 170 void InitUserProtocolState(void);
Diletant 167:bedc0a9d559a 171 void DeviceStartUserProtocol(void);
Diletant 161:efd949e8d536 172
Diletant 161:efd949e8d536 173 #endif /* __DEVICE_USER_PROTOCOL_H__ */