-
Notifications
You must be signed in to change notification settings - Fork 0
/
globdefs.h
212 lines (156 loc) · 4.92 KB
/
globdefs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#ifndef _GLOBDEFS_H
#define _GLOBDEFS_H
#include <signal.h>
#include <stdint.h>
#include <inttypes.h>
#include <time.h>
#include <float.h>
#include "stm32f4xx.h"
typedef uint64_t u64;
typedef int64_t s64;
typedef float f32; /* long double íå ïîääåðæûâàåöà */
typedef char c8;
typedef unsigned char const ucint8_t;
typedef volatile unsigned char vuint8_t;
typedef volatile unsigned long vuint32_t;
typedef enum {false, true} bool;
#if 0
#ifndef u8
#define u8 uint8_t
#endif
#ifndef c8
#define c8 char
#endif
#ifndef u32
#define u32 uint32_t
#endif
#ifndef s32
#define s32 int32_t
#endif
#ifndef bool
#define bool uint8_t
#endif
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#endif
#ifndef IDEF
#define IDEF static inline
#endif
/* Íà ýòîò àäðåñ áóäåò îòâå÷àòü íàøå óñòðîéñòâî */
#define BROADCAST_ADDR 0xff
/* Ìàêñèìàëüíîå ÷èñëî âñåõ êàíàëîâ äëÿ íàñòðîéêè */
#define NUM_ALL_CHAN 8
/* ×èñëî äàò÷èêîâ íà LMP91ê */
#define NUM_LMP91K_SENS 4
/* ×èñëî èçìåðåíèé â îäíîì ïàêåòå äàíûõ çà ñåêóíäó */
#define NUM_ACQUIS_IN_PACK 5
#define MAGIC 0x4b495245
/* Äåëèòåëè */
#define TIMER_NS_DIVIDER (1000000000UL)
#define TIMER_US_DIVIDER (1000000)
#define TIMER_MS_DIVIDER (1000)
/* Ïðè÷èíû ñáðîñà ïðèáîðà - ïåðå÷èñëåíû çäåñü. Èç çàïèøåì â eeprom */
#define CAUSE_POWER_OFF 0x12345678 /* Âûêëþ÷åíèå ïèòàíèÿ */
#define CAUSE_EXT_RESET 0xabcdef90 /* Âíåøíèé ðåñåò */
#define CAUSE_BROWN_OUT 0xaa55aa55 /* Ñíèæåíèå ïèòàíèÿ */
#define CAUSE_WDT_RESET 0x07070707 /* WDT reset (âî âðåìÿ ðåãèñòðàöèè) */
#define CAUSE_NO_LINK 0xE7E7E7E7 /* Íåò ñâÿçè - ñàìîâûêëþ÷åíèå ïðèáîðà */
#define CAUSE_UNKNOWN_RESET 0xFFFFFFFF /* Íåèçâåñòíàÿ ïðè÷èíà-âûäåðíóëè ïèòàíèå */
/* Ãëàâíûé ñòàòóñ */
#define STATUS_NO_TIME 1
#define STATUS_NO_CONST_EEPROM 2
#define STATUS_VCP_CONNECTED 4
#define STATUS_CMD_ERROR 8
#define STATUS_DEV_DEFECT 16
#define STATUS_MEM_OVERFLOW 32
#define STATUS_DEV_TEST 64
#define STATUS_DEV_RUN 128
/**
* Ñîñòîÿíèå ñåíñîðîâ
*/
typedef enum {
SENS_SLEEP,
SENS_RUN,
SENS_STOPED,
SENS_ERR = 0x0F,
} SENS_STATE_TYPE;
/**
* Ñîñòîÿíèå ñåíñîðîâ. 8 øòóê
*/
typedef struct {
unsigned sens0 : 4;
unsigned sens1 : 4;
unsigned sens2 : 4;
unsigned sens3 : 4;
unsigned sens4 : 4;
unsigned sens5 : 4;
unsigned sens6 : 4;
unsigned sens7 : 4;
} SENS_ERROR_t;
/**
* Îïèñûâàåò êîãäà ñëó÷èëñÿ òàéìàóò êàðòû è ïðî÷èå îøèáêè
*/
typedef struct {
uint32_t cmd_error;
uint32_t read_timeout;
uint32_t write_timeout;
uint32_t any_error;
} SD_CARD_ERROR_STRUCT;
/**
* Èìÿ è àäðåñ ïðèáîðà-8 áàéò
*/
typedef struct {
uint8_t addr; /* Àäðåñ ïëàòû */
uint8_t ver; /* Âåðñèÿ ÏÎ: 1, 2, 3, 4 èòä */
uint8_t rev; /* Ðåâèçèÿ ÏÎ 0, 1, 2 èòä */
uint8_t res0; /* Ðåçåðâ */
uint32_t cmpl_time; /* Âðåìÿ êîìïèëÿöèè */
} DEV_ADDR_PACK;
/**
* Ñ÷åò÷èêè îáìåíîâ ïî ÓÀÐÒ
*/
typedef struct {
uint32_t rx_pack; /* Ïðèíÿòûå ïàêåòû */
uint32_t rx_cmd_err; /* Îøèáêà â êîìàíäå */
uint32_t rx_stat_err; /* Îøèáêè íàáåãàíèÿ, êàäðà (áåç ñòîïîâ) è ïð */
uint32_t rx_crc_err; /* Îøèáêè êîíòðîëüíîé ñóììû */
uint32_t tx_pack; /* ïåðåäàííûå ïàêåòû */
uint32_t tx_err;
} UART_COUNTS_PACK;
/* Äëÿ âåùåñòâåíûõ ÷èñåë */
typedef union {
f32 f_val;
u32 u_val;
} FLT_2_INT;
/**
* Ñòàòóñ è îøèáêè óñòðîéñòâ íà îòïðàâëåíèå
* Êîðîòêèé ñòàòóñ (main_status) ïîñûëàåòñÿ ïðè îøèáêå (òîëüêî 1 áàéòà + 1 len + 2 CRC16)
* ñìåñòèì íà ïîçèöèþ äëÿ ñîâìåñòèìîñòè
*/
#pragma pack(4)
typedef struct {
uint8_t main_status; /* ãëàâíûé: íåò âðåìåíè, íåò êîíñòàíò, íåò SD, îøèáêà â êîìàíäå, íåèñïðàâåí, ïåðåïîëíåíèå ïàìÿòè, òåñòèðîâàíèå, çàïóùåí */
uint8_t self_test0; /* Ñàìîòåñòèðîâàíèå è îøèáêè0: 0 - ÷àñû, 1 - äàò÷èê òåìïåðàòóðû, 2 - äàò÷èê äàâëåíèÿ, 3 - EEPROM, 4 - êàðòà SD, 5 - flash... */
uint8_t self_test1; /* ïðî÷èå óñòðîéñòâà: 0 - íàñîñ */
#define devices self_test1
uint8_t reset_cause; /* Ïðè÷èíà ïðåäûäóùåãî ñáðîñà */
SENS_ERROR_t sensor_error; /* ERROR îøèáêè-ñòàòóñû 8 ñåíñîðîâ. Ïîòîì ðàñïèøåì */
uint32_t eeprom; /* Ñòàòóñ EEPROM. Âûñòàâëåííûé áèò - îøèáêà ê/ë ïàðàìåòðà */
int32_t gs_time; /* Âðåìÿ ïðèáîðà. Ñåêóíäû âðåìåíè UNIX */
int16_t temperature; /* Òåìïåðàòóðà âíóòðè ïðèáîðà * 10 */
int16_t humidity; /* Îòíîñèòåëüíàÿ âëàæíîñòü ïðèáîðà * 10 % */
uint32_t pressure; /* Äàâëåíèå êÏà */
int16_t batt_curr; /* Òîê ïîòðåáëåíèÿ. ìÀ */
int16_t batt_pow; /* Íàïðÿæåíèå áàòàðåè ïèòàíèÿ. ì */
uint32_t freq; /* ÷àñòîòà ïðîöà */
DEV_ADDR_PACK dev_addr; /* Âåðñèÿ/ðåâèçèÿ/âðåìÿ êîìïèëÿöèè */
uint32_t rsvd[6];
} DEV_STATUS_PACK;
/* Ïåðåîïðåäåëåíèÿ malloc è free */
#define MALLOC(x) pvPortMalloc(x)
#define FREE(x) vPortFree(x)
#endif /* globdefs.h */