Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LG by
DeviceUserProtocol.h
- Committer:
- Diletant
- Date:
- 2016-06-05
- Revision:
- 167:bedc0a9d559a
- Parent:
- 161:efd949e8d536
- Child:
- 178:672ef279c8e0
File content as of revision 167:bedc0a9d559a:
#ifndef __DEVICE_USER_PROTOCOL_H__
#define __DEVICE_USER_PROTOCOL_H__
#include "stdint.h"
#include "DeviceUserProtocolRequest.h"
#include "DeviceUserProtocolResponse.h"
#include "DeviceUserProtocolDecoder.h"
#include "DeviceUserProtocolEncoder.h"
#define BROADCAST_ADDRESS 0x1f
#define BROADCAST_FRAME 100 //100 mks
//All commands
#define DELTA_PS 0xa000 //B_DeltaPS command code: output of accumulated pulses and ACS parameters as 22 indexed packets sequence
#define DELTA_BINS 0xb000 //B_DeltaBINS command code: output of accumulated pulses and data validity attribute in one packet
#define DELTA_SF 0xb200 //B_DeltaSF command code: scale factor measurement data output in one packet
#define DEV_MODE 0xa500 //e. the code of the Device_Mode command //r. код команды Device_Mode
#define BIT_MODE 0xa700 //e. the code of the B.I.T. command //r. код команды B.I.T.(встороенного тестирования)
#define RATE 0x0000 //e. the code of the Rate command //r. код команды Rate
#define DELTA 0x0f00 //e. the code of the Delta command //r. код команды Delta
#define D_PERIOD_W 0xf000 //e. the code of the D_Period_W command //r. код команды D_Period_W
#define MAINTENANCE 0x9900 //e. the code of the Maintenance mode command //r. код команды Maintenance mode
//Maintenance command set versions
#define M0_MAINTENANCE 0x99 //: initial version
//Maintenance basic commands group
#define M0_BASIC 0xda00 //Basic maintenance commands group code
#define M0_CLEAR 0xda00 //group command select: e. reset of the register of errors of line 485 //r. очистка регистра ошибок линии 485
#define M0_MIRROR 0xda01 //group command select: e. return previous contents of the receiver buffer //r. возврат предыдущего содержимого буфера приемника
#define M0_LDPAR_F 0xda02 //group command select: e. load GLD parameters from Flash-memory //r. загрузить параметры ГЛД из флэш-памяти
#define M0_LDPAR_D 0xda03 //group command select: e. set GLD parameters by procedure of initialization //r. установить параметры ГЛД процедурой инициализации
#define M0_START 0xda04 //group command select: e. switch on the GLD //r. включить ГЛД
#define M0_STOP 0xda40 //group command select: e. switch off the GLD //r. выключить ГЛД
#define M0_PULSE 0xda0a //group command select: e. generation of the light-up pulse //r. генерация импульса поджига
//Maintenance rate commands group
#define M0_RATE 0xdd00 //e. delivery of a stack of parameters M_Rate (Rate2, Rate3) //r. выдача набора параметров M_Rate (Rate2, Rate3)
#define M0_RATE_1 0xdd01 //group command select: output parameters set 1?
#define M0_RATE_2 0xdd02 //group command select: output parameters set 2
#define M0_RATE_3 0xdd03 //group command select: output parameters set 3
#define M0_RATE_4 0xdd04 //group command select: output parameters set 4
#define M0_RATE_7 0xdd07 //group command select: output parameters set 7
//Other maintenance commands
#define M0_STIMUL 0x0a00 //e. the code of the Stimul command //r. код команды Stimul
#define M0_RESET 0x8000 //e. software device reset(restart) //r. программный сброс (рестарт) прибора
#define M0_CTL_R 0xd900 //e. reading the control register RgConA/B of the device //r. чтение регистра управления устройства
#define M0_CTL_A_R 0xd900 //e. reading the control register RgConA of the device //r. чтение регистра управления устройства
#define M0_CTL_B_R 0xd910 //e. reading the control register RgConB of the device //r. чтение регистра управления устройства
#define M0_CTL_M 0xd800 //e. modification of bit of the control register //r. модификация бита регистра управления
#define M0_TMP_W 0xe000 //e. writing to the AD7714 circuit (temperature sensors) //r. запись в схемы AD7714 (измерители температуры)
#define M0_TMP_R 0xe100 //e. reading from the AD7714 circuit (temperature sensors) //r. чтение из схем AD7714 (измерители температуры)
#define M0_E5R_W 0xe200 //e. writing to the register of a mode of the Elio5 card //r. запись в регистр режима платы Elio5
#define M0_ADC_R 0xe300 //e. reading data from the ADC of the Elio5 card //r. чтение данных из АЦП платы Elio5
#define M0_VIB_W 0xe400 //e. loading of the oscillation period of the dither drive //r. загрузка периода колебаний вибропривода
#define M0_CNT_R 0xe500 //e. reading data from the counters of the Elio5 card //r. чтение данных из счетчиков платы Elio5
#define M0_GPH_W 0xe600 //e. loading gain factors of photodetector channels //r. загрузка коэффициентов усиления каналов фотоприемника
#define M0_FLG_R 0xe700 //e. reading data from the register of input flags //r. чтение данных из регистра входных флагов
#define M0_PARAM_W 0xe800 //e. writing working parameter to the data memory //r. запись рабочего параметра в память данных
#define M0_PARAM_R 0xe900 //e. reading working parameter of the GLD from the data memory //r. чтение рабочего параметра GLD из памяти данных
#define M0_E5RA_W 0xea00 //e. writing in 1st additional (A) register of a mode of the Elio5 card //r. запись в 1-ый дополнительный (А) регистр режима платы Elio5
//Factory maintenance commands
#define FACTORY_ACCESS 0xff00 //Factory access: command mask
#define H_PARAM8_R 0xff00 //Hash access: 0000b read 1-byte param
#define H_PARAM16_R 0xff01 //Hash access: 0001b read 2-byte param
#define H_PARAM32_R 0xff03 //Hash access: 0010b read 4-byte param
#define H_BYTES_R 0xff0f //Hash access: 1111b read bytes param
#define H_PARAM8_W 0xff10 //Hash access: 0000b write 1-byte param
#define H_PARAM16_W 0xff11 //Hash access: 0001b write 2-byte param
#define H_PARAM32_W 0xff13 //Hash access: 0010b write 4-byte param
#define H_BYTES_W 0xff1f //Hash access: 1111b write bytes param
#define H_FUNC_PARAM0_BY_IMM8 0xff20 //Hash access: 0000b set function parameter 0 by 8 bit immediate value
#define H_FUNC_PARAM1_BY_IMM8 0xff24 //Hash access: 0100b set function parameter 1 by 8 bit immediate value
#define H_FUNC_PARAM2_BY_IMM8 0xff28 //Hash access: 1000b set function parameter 2 by 8 bit immediate value
#define H_FUNC_PARAM3_BY_IMM8 0xff2c //Hash access: 1100b set function parameter 3 by 8 bit immediate value
#define H_FUNC_PARAM0_BY_IMM16 0xff21 //Hash access: 0001b set function parameter 0 by 16 bit immediate value
#define H_FUNC_PARAM1_BY_IMM16 0xff25 //Hash access: 0101b set function parameter 1 by 16 bit immediate value
#define H_FUNC_PARAM2_BY_IMM16 0xff29 //Hash access: 1001b set function parameter 2 by 16 bit immediate value
#define H_FUNC_PARAM3_BY_IMM16 0xff2d //Hash access: 1101b set function parameter 3 by 16 bit immediate value
#define H_FUNC_PARAM0_BY_IMM32 0xff23 //Hash access: 0011b set function parameter 0 by 32 bit immediate value
#define H_FUNC_PARAM1_BY_IMM32 0xff27 //Hash access: 0111b set function parameter 1 by 32 bit immediate value
#define H_FUNC_PARAM2_BY_IMM32 0xff2b //Hash access: 1011b set function parameter 2 by 32 bit immediate value
#define H_FUNC_PARAM3_BY_IMM32 0xff2f //Hash access: 1111b set function parameter 3 by 32 bit immediate value
#define H_FUNC_PARAM0_BY_VAL8 0xff30 //Hash access: 0000b set function parameter 0 by 8 bit variable value
#define H_FUNC_PARAM1_BY_VAL8 0xff34 //Hash access: 0100b set function parameter 1 by 8 bit variable value
#define H_FUNC_PARAM2_BY_VAL8 0xff38 //Hash access: 1000b set function parameter 2 by 8 bit variable value
#define H_FUNC_PARAM3_BY_VAL8 0xff3c //Hash access: 1100b set function parameter 3 by 8 bit variable value
#define H_FUNC_PARAM0_BY_VAL16 0xff31 //Hash access: 0001b set function parameter 0 by 16 bit variable value
#define H_FUNC_PARAM1_BY_VAL16 0xff35 //Hash access: 0101b set function parameter 1 by 16 bit variable value
#define H_FUNC_PARAM2_BY_VAL16 0xff39 //Hash access: 1001b set function parameter 2 by 16 bit variable value
#define H_FUNC_PARAM3_BY_VAL16 0xff3d //Hash access: 1101b set function parameter 3 by 16 bit variable value
#define H_FUNC_PARAM0_BY_VAL32 0xff33 //Hash access: 0011b set function parameter 0 by 32 bit variable value
#define H_FUNC_PARAM1_BY_VAL32 0xff37 //Hash access: 0111b set function parameter 1 by 32 bit variable value
#define H_FUNC_PARAM2_BY_VAL32 0xff3b //Hash access: 1011b set function parameter 2 by 32 bit variable value
#define H_FUNC_PARAM3_BY_VAL32 0xff3f //Hash access: 1111b set function parameter 3 by 32 bit variable value
#define H_FUNC_PARAM0_BY_REF8 0xff40 //Hash access: 0000b set function parameter 0 by 8 bit variable reference
#define H_FUNC_PARAM1_BY_REF8 0xff44 //Hash access: 0100b set function parameter 1 by 8 bit variable reference
#define H_FUNC_PARAM2_BY_REF8 0xff48 //Hash access: 1000b set function parameter 2 by 8 bit variable reference
#define H_FUNC_PARAM3_BY_REF8 0xff4c //Hash access: 1100b set function parameter 3 by 8 bit variable reference
#define H_FUNC_PARAM0_BY_REF16 0xff41 //Hash access: 0001b set function parameter 0 by 16 bit variable reference
#define H_FUNC_PARAM1_BY_REF16 0xff45 //Hash access: 0101b set function parameter 1 by 16 bit variable reference
#define H_FUNC_PARAM2_BY_REF16 0xff49 //Hash access: 1001b set function parameter 2 by 16 bit variable reference
#define H_FUNC_PARAM3_BY_REF16 0xff4d //Hash access: 1101b set function parameter 3 by 16 bit variable reference
#define H_FUNC_PARAM0_BY_REF32 0xff43 //Hash access: 0011b set function parameter 0 by 32 bit variable reference
#define H_FUNC_PARAM1_BY_REF32 0xff47 //Hash access: 0111b set function parameter 1 by 32 bit variable reference
#define H_FUNC_PARAM2_BY_REF32 0xff4b //Hash access: 1011b set function parameter 2 by 32 bit variable reference
#define H_FUNC_PARAM3_BY_REF32 0xff4f //Hash access: 1111b set function parameter 3 by 32 bit variable reference
#define FUNCTION_CALL 0xff50 //Hash access: function call - no parameters
#define FUNCTION_CALL_1 0xff51 //Hash access: function call - 1 parameter
#define FUNCTION_CALL_2 0xff52 //Hash access: function call - 2 parameters
#define FUNCTION_CALL_3 0xff53 //Hash access: function call - 3 parameters
#define FUNCTION_CALL_4 0xff54 //Hash access: function call - 4 parameters
#define FLASH_READ_ALL 0xff60 //Flash access: read all from flash
#define FLASH_WRITE_ALL 0xff70 //Flash access: write all to flash
//Common response messages
#define MESSAGE_OK 0x0000
#define MESSAGE_UNKNOWN_REQUEST_CODE 0x8000
#define MESSAGE_UNKNOWN_REQUEST_PARAMETER 0x8001
#define MESSAGE_UNKNOWN_REQUEST_HASH 0x8002
#define MESSAGE_WRONG_REQUEST_VALUE_SIZE 0x8003
#define MESSAGE_WRONG_REQUEST_VALUE_RANGE 0x8004
//Actual commands:
//BINS
// GLD initialization sequence:
// a5 04 - external latch with DeltaPS format
// a0 70 - DeltaPS 921600/921600 by request only
// Other:
// 80 00 - reset
//BINS/AskGLD/Techno
// 99 99 - maintenance
//Techno
// d8 90 - set bit 0 of RgConB
// d8 10 - reset bit 0 of RgConB
// dd 81 - periodic 38400 MRate
// a0 b0 - periodic 115200/115200 DeltaPS
//Registers:
// RgConA - flags of regulator loops
// RgConB - counting mode: 00 - reference counters, 01 - dither counters and moving average filter
//User protocol typedefs
typedef struct _DeviceUserProtocol {
//Device address
uint16_t address;
//Units
DeviceUserProtocolDecoder decoder;
DeviceUserProtocolEncoder encoder;
DeviceRequest request;
DeviceResponse response;
} DeviceUserProtocol;
//User communication initialization functions
void InitUserProtocolDefaultSettings(void);
void InitUserProtocolState(void);
void DeviceStartUserProtocol(void);
#endif /* __DEVICE_USER_PROTOCOL_H__ */
