123
Fork of LG by
Device.h@161:efd949e8d536, 2016-05-15 (annotated)
- Committer:
- Diletant
- Date:
- Sun May 15 19:12:12 2016 +0000
- Revision:
- 161:efd949e8d536
- Parent:
- 156:e68ee0bcdcda
- Child:
- 166:c3c0b8a90d81
Device & ... update. Not final!!!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Diletant | 74:f4d9c3403578 | 1 | #ifndef __DEVICE_H__ |
Diletant | 74:f4d9c3403578 | 2 | #define __DEVICE_H__ |
Diletant | 74:f4d9c3403578 | 3 | |
Diletant | 156:e68ee0bcdcda | 4 | #define DEV_BOARD_HAOYU |
Diletant | 156:e68ee0bcdcda | 5 | #ifdef DEV_BOARD_HAOYU |
Diletant | 149:abbf7663d27d | 6 | #warning "Program config: development board!!!" |
Diletant | 149:abbf7663d27d | 7 | #endif |
Diletant | 149:abbf7663d27d | 8 | |
Diletant | 149:abbf7663d27d | 9 | #include "LPC17xx.h" |
Diletant | 149:abbf7663d27d | 10 | #include "system_LPC17xx.h" |
Diletant | 156:e68ee0bcdcda | 11 | #include "DeviceController.h" |
Diletant | 156:e68ee0bcdcda | 12 | #include "DeviceDAC.h" |
Diletant | 161:efd949e8d536 | 13 | #include "DeviceUserProtocol.h" |
Diletant | 156:e68ee0bcdcda | 14 | #include "DeviceCounters.h" |
Diletant | 161:efd949e8d536 | 15 | #include "DeviceDither.h" |
Diletant | 149:abbf7663d27d | 16 | #include "DeviceLightUp.h" |
Diletant | 161:efd949e8d536 | 17 | #include "DeviceISACS.h" |
Diletant | 149:abbf7663d27d | 18 | #include "DevicePLCS.h" |
Diletant | 74:f4d9c3403578 | 19 | |
Diletant | 74:f4d9c3403578 | 20 | typedef enum _DeviceLatchMode { |
Diletant | 82:82d7073d36ef | 21 | DeviceLatch10kHz, //internal latch by pulses 10 kHz (power on default mode) |
Diletant | 82:82d7073d36ef | 22 | DeviceLatchMeander, //internal latch by signed meander pulses (not used?) |
Diletant | 82:82d7073d36ef | 23 | DeviceLatchRS422, //external latch by RS422 request |
Diletant | 82:82d7073d36ef | 24 | DeviceLatchPin //external latch by hardware pin request |
Diletant | 74:f4d9c3403578 | 25 | } DeviceLatchMode; |
Diletant | 74:f4d9c3403578 | 26 | |
Diletant | 77:8d582faecf6b | 27 | typedef enum _DeviceLatchFormat { |
Diletant | 82:82d7073d36ef | 28 | DeviceLatchFormatDeltaPS, //latch data in DELTA_PS response format |
Diletant | 82:82d7073d36ef | 29 | DeviceLatchFormatDeltaBINS, //latch data in DELTA_BINS response format |
Diletant | 82:82d7073d36ef | 30 | DeviceLatchFormatDeltaSF //latch data in DELTA_SF response format |
Diletant | 77:8d582faecf6b | 31 | } DeviceLatchFormat; |
Diletant | 74:f4d9c3403578 | 32 | |
Diletant | 74:f4d9c3403578 | 33 | typedef struct _DeviceLatchState { |
Diletant | 82:82d7073d36ef | 34 | uint8_t ready; |
Diletant | 82:82d7073d36ef | 35 | DeviceLatchMode mode; //latch source |
Diletant | 82:82d7073d36ef | 36 | DeviceLatchFormat format; //data to latch |
Diletant | 82:82d7073d36ef | 37 | uint8_t reset; //set to reset counters on each latch (default), clear to keep (DELTA_SF) |
Diletant | 74:f4d9c3403578 | 38 | } DeviceLatchState; |
Diletant | 74:f4d9c3403578 | 39 | |
Diletant | 82:82d7073d36ef | 40 | typedef enum _DeviceCountingSource { |
Diletant | 82:82d7073d36ef | 41 | DeviceCountingSourceReference, //Accumulate pulses using reference +/- counters as source |
Diletant | 161:efd949e8d536 | 42 | DeviceCountingSourceDither, //Accumulate pulses using dither counters as source |
Diletant | 82:82d7073d36ef | 43 | } DeviceCountingSource; |
Diletant | 82:82d7073d36ef | 44 | |
Diletant | 161:efd949e8d536 | 45 | //Device service communication typedefs |
Diletant | 137:14a0c452cf32 | 46 | typedef struct _Service { |
Diletant | 156:e68ee0bcdcda | 47 | char buffer[512]; |
Diletant | 161:efd949e8d536 | 48 | uint16_t position; //Transmission position |
Diletant | 137:14a0c452cf32 | 49 | } Service; |
Diletant | 137:14a0c452cf32 | 50 | |
Diletant | 161:efd949e8d536 | 51 | //Device measurement cycle typedefs |
Diletant | 156:e68ee0bcdcda | 52 | typedef struct _DeviceMeasurementCycle { |
Diletant | 156:e68ee0bcdcda | 53 | uint32_t length; //Measurement cycle length |
Diletant | 156:e68ee0bcdcda | 54 | uint32_t counter; //Measurement cycle counter |
Diletant | 156:e68ee0bcdcda | 55 | } DeviceMeasurementCycle; |
Diletant | 156:e68ee0bcdcda | 56 | |
Diletant | 161:efd949e8d536 | 57 | //Device regular cycle typedefs |
Diletant | 156:e68ee0bcdcda | 58 | typedef struct _DeviceRegularCycle { |
Diletant | 161:efd949e8d536 | 59 | volatile uint32_t event1Hz; |
Diletant | 161:efd949e8d536 | 60 | volatile uint32_t event500Hz; |
Diletant | 161:efd949e8d536 | 61 | volatile uint32_t event1K; |
Diletant | 161:efd949e8d536 | 62 | volatile uint32_t event10K; |
Diletant | 161:efd949e8d536 | 63 | volatile uint32_t event100K; |
Diletant | 156:e68ee0bcdcda | 64 | |
Diletant | 161:efd949e8d536 | 65 | volatile uint32_t time100K; |
Diletant | 161:efd949e8d536 | 66 | volatile uint32_t time10K; |
Diletant | 161:efd949e8d536 | 67 | volatile uint32_t time1K; |
Diletant | 161:efd949e8d536 | 68 | volatile uint32_t time500Hz; |
Diletant | 161:efd949e8d536 | 69 | volatile uint32_t time1Hz; |
Diletant | 156:e68ee0bcdcda | 70 | } DeviceRegularCycle; |
Diletant | 156:e68ee0bcdcda | 71 | |
Diletant | 161:efd949e8d536 | 72 | //Device sensor typedefs |
Diletant | 161:efd949e8d536 | 73 | typedef struct _DeviceSensorSettings { |
Diletant | 161:efd949e8d536 | 74 | //Device ID |
Diletant | 161:efd949e8d536 | 75 | uint16_t id; |
Diletant | 161:efd949e8d536 | 76 | //Block ID |
Diletant | 161:efd949e8d536 | 77 | uint16_t block; |
Diletant | 161:efd949e8d536 | 78 | } DeviceSensorSettings; |
Diletant | 156:e68ee0bcdcda | 79 | |
Diletant | 161:efd949e8d536 | 80 | typedef struct _DeviceSensorState { |
Diletant | 161:efd949e8d536 | 81 | } DeviceSensorState; |
Diletant | 161:efd949e8d536 | 82 | |
Diletant | 161:efd949e8d536 | 83 | typedef struct _DeviceSensor { |
Diletant | 161:efd949e8d536 | 84 | DeviceSensorSettings settings; |
Diletant | 161:efd949e8d536 | 85 | DeviceSensorState state; |
Diletant | 161:efd949e8d536 | 86 | } DeviceSensor; |
Diletant | 161:efd949e8d536 | 87 | |
Diletant | 161:efd949e8d536 | 88 | //Device typedefs |
Diletant | 74:f4d9c3403578 | 89 | typedef struct _Device { |
Diletant | 156:e68ee0bcdcda | 90 | //Measurement cycle |
Diletant | 156:e68ee0bcdcda | 91 | DeviceMeasurementCycle measurement; |
Diletant | 156:e68ee0bcdcda | 92 | //Control cycle |
Diletant | 156:e68ee0bcdcda | 93 | DeviceRegularCycle regular; |
Diletant | 77:8d582faecf6b | 94 | //Counting |
Diletant | 77:8d582faecf6b | 95 | DeviceLatchState latch; |
Diletant | 156:e68ee0bcdcda | 96 | DeviceCounters counters; |
Diletant | 161:efd949e8d536 | 97 | //Controller |
Diletant | 161:efd949e8d536 | 98 | DeviceController controller; |
Diletant | 161:efd949e8d536 | 99 | //Protocols |
Diletant | 161:efd949e8d536 | 100 | Service service; //Service communication protocol - asynchronous serial port 0 |
Diletant | 161:efd949e8d536 | 101 | DeviceUserProtocol user; //Host communication protocol - asynchronous serial port 1 |
Diletant | 137:14a0c452cf32 | 102 | //Units |
Diletant | 161:efd949e8d536 | 103 | DeviceSensor sensor; |
Diletant | 149:abbf7663d27d | 104 | DeviceLightUp lightUp; |
Diletant | 149:abbf7663d27d | 105 | DeviceDither dither; |
Diletant | 161:efd949e8d536 | 106 | DeviceDAC dac; //2-channel DAC of isas & plcs |
Diletant | 161:efd949e8d536 | 107 | DeviceISACS isacs; //Information signal amplitude stabilizer |
Diletant | 161:efd949e8d536 | 108 | DevicePathLengthControlSystem plcs; //Path length control system |
Diletant | 74:f4d9c3403578 | 109 | } Device; |
Diletant | 74:f4d9c3403578 | 110 | |
Diletant | 137:14a0c452cf32 | 111 | typedef struct _HashParam { |
Diletant | 137:14a0c452cf32 | 112 | uint32_t hash; |
Diletant | 137:14a0c452cf32 | 113 | void * ref; |
Diletant | 137:14a0c452cf32 | 114 | uint32_t size; |
Diletant | 137:14a0c452cf32 | 115 | } HashParam; |
Diletant | 137:14a0c452cf32 | 116 | |
Diletant | 161:efd949e8d536 | 117 | #define HASH_PARAM_COUNT 153 |
Diletant | 149:abbf7663d27d | 118 | |
Diletant | 149:abbf7663d27d | 119 | typedef struct _HashFunc { |
Diletant | 149:abbf7663d27d | 120 | uint32_t hash; |
Diletant | 149:abbf7663d27d | 121 | void * ref; |
Diletant | 149:abbf7663d27d | 122 | uint32_t resultSize; |
Diletant | 149:abbf7663d27d | 123 | uint32_t paramCount; |
Diletant | 149:abbf7663d27d | 124 | } HashFunc; |
Diletant | 149:abbf7663d27d | 125 | |
Diletant | 149:abbf7663d27d | 126 | #define HASH_FUNC_COUNT 3 |
Diletant | 149:abbf7663d27d | 127 | |
Diletant | 149:abbf7663d27d | 128 | void InitDevice(void); |
Diletant | 156:e68ee0bcdcda | 129 | void DeviceStart(void); |
Diletant | 156:e68ee0bcdcda | 130 | |
Diletant | 156:e68ee0bcdcda | 131 | void DeviceInitAllWithDefaults(void); |
Diletant | 156:e68ee0bcdcda | 132 | void DeviceInitAll(void); |
Diletant | 161:efd949e8d536 | 133 | void InitHashParamTable(void); |
Diletant | 149:abbf7663d27d | 134 | |
Diletant | 156:e68ee0bcdcda | 135 | void DeviceRegularEvent1Hz(void); |
Diletant | 156:e68ee0bcdcda | 136 | void DeviceRegularEvent500Hz(void); |
Diletant | 156:e68ee0bcdcda | 137 | void DeviceRegularEvent1KHz(void); |
Diletant | 156:e68ee0bcdcda | 138 | void DeviceRegularEvent10KHz(void); |
Diletant | 156:e68ee0bcdcda | 139 | void DeviceRegularEvent100KHz(void); |
Diletant | 137:14a0c452cf32 | 140 | |
Diletant | 156:e68ee0bcdcda | 141 | void DeviceMeasurementInterruptHandler(void); |
Diletant | 156:e68ee0bcdcda | 142 | void DeviceRegularInterruptHandler(void); |
Diletant | 74:f4d9c3403578 | 143 | #endif /* __DEVICE_H__ */ |