add
This commit is contained in:
@@ -42,6 +42,17 @@ extern "C" {
|
||||
#include "PROJ_setup.h"
|
||||
#include "dallas_tools.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define MODBUS_REG_ORDER_BE 0
|
||||
#define MODBUS_REG_ORDER_LE 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FuncOK=0,
|
||||
@@ -111,7 +122,11 @@ void Check_Tconnect(MB_DataStructureTypeDef* MB_DATA, Flags_TypeDef* flag ,DALL
|
||||
FuncStat value_control(void );
|
||||
|
||||
void reinit_t_sens(void);
|
||||
uint16_t* U32_TO_MODBUS (uint32_t value, uint16_t reg_array[2], int order);
|
||||
|
||||
uint32_t get_cycle_count(void);
|
||||
void init_cycle_counter(void);
|
||||
uint32_t measure_execution_time_cycles(void (*func)(void));
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
@@ -51,7 +51,7 @@ void MX_GPIO_Init(void)
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4
|
||||
|
||||
@@ -45,344 +45,6 @@
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
const uint8_t sin_table_phase_a[256] = {
|
||||
127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157, 160, 163, 166, 169, 172,
|
||||
175, 178, 181, 184, 187, 190, 193, 196, 198, 201, 204, 207, 210, 212, 215, 218,
|
||||
220, 223, 225, 228, 230, 233, 235, 238, 240, 242, 244, 247, 249, 251, 253, 255,
|
||||
254, 252, 250, 248, 246, 244, 242, 240, 237, 235, 233, 230, 228, 225, 223, 220,
|
||||
218, 215, 212, 210, 207, 204, 201, 198, 196, 193, 190, 187, 184, 181, 178, 175,
|
||||
172, 169, 166, 163, 160, 157, 154, 151, 148, 145, 142, 139, 136, 133, 130, 127,
|
||||
124, 121, 118, 115, 112, 109, 106, 103, 100, 97, 94, 91, 88, 85, 82, 79,
|
||||
76, 73, 70, 67, 64, 61, 58, 55, 53, 50, 47, 44, 41, 39, 36, 33,
|
||||
31, 28, 26, 23, 21, 18, 16, 13, 11, 9, 7, 4, 2, 0, 1, 3,
|
||||
5, 7, 9, 11, 14, 16, 18, 21, 23, 26, 28, 31, 33, 36, 39, 41,
|
||||
44, 47, 50, 53, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88,
|
||||
91, 94, 97, 100, 103, 106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136,
|
||||
139, 142, 145, 148, 151, 154, 157, 160, 163, 166, 169, 172, 175, 178, 181, 184,
|
||||
187, 190, 193, 196, 198, 201, 204, 207, 210, 212, 215, 218, 220, 223, 225, 228,
|
||||
230, 233, 235, 238, 240, 242, 244, 247, 249, 251, 253, 255, 254, 252, 250, 248,
|
||||
246, 244, 242, 240, 237, 235, 233, 230, 228, 225, 223, 220, 218, 215, 212, 210
|
||||
};
|
||||
|
||||
|
||||
const uint8_t sin_table_phase_b[256] = {
|
||||
210, 207, 204, 201, 198, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166,
|
||||
163, 160, 157, 154, 151, 148, 145, 142, 139, 136, 133, 130, 127, 124, 121, 118,
|
||||
115, 112, 109, 106, 103, 100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 70,
|
||||
67, 64, 61, 58, 55, 53, 50, 47, 44, 41, 39, 36, 33, 31, 28, 26,
|
||||
23, 21, 18, 16, 13, 11, 9, 7, 4, 2, 0, 1, 3, 5, 7, 9,
|
||||
11, 14, 16, 18, 21, 23, 26, 28, 31, 33, 36, 39, 41, 44, 47, 50,
|
||||
53, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97,
|
||||
100, 103, 106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145,
|
||||
148, 151, 154, 157, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193,
|
||||
196, 198, 201, 204, 207, 210, 212, 215, 218, 220, 223, 225, 228, 230, 233, 235,
|
||||
238, 240, 242, 244, 247, 249, 251, 253, 255, 254, 252, 250, 248, 246, 244, 242,
|
||||
240, 237, 235, 233, 230, 228, 225, 223, 220, 218, 215, 212, 210, 207, 204, 201,
|
||||
198, 196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 157, 154,
|
||||
151, 148, 145, 142, 139, 136, 133, 130, 127, 124, 121, 118, 115, 112, 109, 106,
|
||||
103, 100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58,
|
||||
55, 53, 50, 47, 44, 41, 39, 36, 33, 31, 28, 26, 23, 21, 18, 16
|
||||
};
|
||||
|
||||
|
||||
|
||||
const uint8_t sin_table_phase_c[256] = {
|
||||
55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100,
|
||||
103, 106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148,
|
||||
151, 154, 157, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196,
|
||||
198, 201, 204, 207, 210, 212, 215, 218, 220, 223, 225, 228, 230, 233, 235, 238,
|
||||
240, 242, 244, 247, 249, 251, 253, 255, 254, 252, 250, 248, 246, 244, 242, 240,
|
||||
237, 235, 233, 230, 228, 225, 223, 220, 218, 215, 212, 210, 207, 204, 201, 198,
|
||||
196, 193, 190, 187, 184, 181, 178, 175, 172, 169, 166, 163, 160, 157, 154, 151,
|
||||
148, 145, 142, 139, 136, 133, 130, 127, 124, 121, 118, 115, 112, 109, 106, 103,
|
||||
100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58, 55,
|
||||
53, 50, 47, 44, 41, 39, 36, 33, 31, 28, 26, 23, 21, 18, 16, 13,
|
||||
11, 9, 7, 4, 2, 0, 1, 3, 5, 7, 9, 11, 14, 16, 18, 21,
|
||||
23, 26, 28, 31, 33, 36, 39, 41, 44, 47, 50, 53, 55, 58, 61, 64,
|
||||
67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 103, 106, 109, 112,
|
||||
115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157, 160,
|
||||
163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 198, 201, 204, 207,
|
||||
210, 212, 215, 218, 220, 223, 225, 228, 230, 233, 235, 238, 240, 242, 244, 247
|
||||
};
|
||||
|
||||
|
||||
|
||||
const uint8_t ramp_table[256] = {
|
||||
0, 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, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
|
||||
224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
|
||||
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
|
||||
};
|
||||
const uint8_t interleaved_tables[1024] = {
|
||||
127, 210, 55, 0, // i=0: A0, B0, C0, R0
|
||||
130, 207, 58, 1, // i=1: A1, B1, C1, R1
|
||||
133, 204, 61, 2, // i=2: A2, B2, C2, R2
|
||||
136, 201, 64, 3, // i=3: A3, B3, C3, R3
|
||||
139, 198, 67, 4, // i=4
|
||||
142, 196, 70, 5, // i=5
|
||||
145, 193, 73, 6, // i=6
|
||||
148, 190, 76, 7, // i=7
|
||||
151, 187, 79, 8, // i=8
|
||||
154, 184, 82, 9, // i=9
|
||||
157, 181, 85, 10, // i=10
|
||||
160, 178, 88, 11, // i=11
|
||||
163, 175, 91, 12, // i=12
|
||||
166, 172, 94, 13, // i=13
|
||||
169, 169, 97, 14, // i=14
|
||||
172, 166, 100, 15, // i=15
|
||||
175, 163, 103, 16, // i=16
|
||||
178, 160, 106, 17, // i=17
|
||||
181, 157, 109, 18, // i=18
|
||||
184, 154, 112, 19, // i=19
|
||||
187, 151, 115, 20, // i=20
|
||||
190, 148, 118, 21, // i=21
|
||||
193, 145, 121, 22, // i=22
|
||||
196, 142, 124, 23, // i=23
|
||||
198, 139, 127, 24, // i=24
|
||||
201, 136, 130, 25, // i=25
|
||||
204, 133, 133, 26, // i=26
|
||||
207, 130, 136, 27, // i=27
|
||||
210, 127, 139, 28, // i=28
|
||||
212, 124, 142, 29, // i=29
|
||||
215, 121, 145, 30, // i=30
|
||||
218, 118, 148, 31, // i=31
|
||||
220, 115, 151, 32, // i=32
|
||||
223, 112, 154, 33, // i=33
|
||||
225, 109, 157, 34, // i=34
|
||||
228, 106, 160, 35, // i=35
|
||||
230, 103, 163, 36, // i=36
|
||||
233, 100, 166, 37, // i=37
|
||||
235, 97, 169, 38, // i=38
|
||||
238, 94, 172, 39, // i=39
|
||||
240, 91, 175, 40, // i=40
|
||||
242, 88, 178, 41, // i=41
|
||||
244, 85, 181, 42, // i=42
|
||||
247, 82, 184, 43, // i=43
|
||||
249, 79, 187, 44, // i=44
|
||||
251, 76, 190, 45, // i=45
|
||||
253, 73, 193, 46, // i=46
|
||||
255, 70, 196, 47, // i=47
|
||||
254, 67, 198, 48, // i=48
|
||||
252, 64, 201, 49, // i=49
|
||||
250, 61, 204, 50, // i=50
|
||||
248, 58, 207, 51, // i=51
|
||||
246, 55, 210, 52, // i=52
|
||||
244, 53, 212, 53, // i=53
|
||||
242, 50, 215, 54, // i=54
|
||||
240, 47, 218, 55, // i=55
|
||||
237, 44, 220, 56, // i=56
|
||||
235, 41, 223, 57, // i=57
|
||||
233, 39, 225, 58, // i=58
|
||||
230, 36, 228, 59, // i=59
|
||||
228, 33, 230, 60, // i=60
|
||||
225, 31, 233, 61, // i=61
|
||||
223, 28, 235, 62, // i=62
|
||||
220, 26, 238, 63, // i=63
|
||||
218, 23, 240, 64, // i=64
|
||||
215, 21, 242, 65, // i=65
|
||||
212, 18, 244, 66, // i=66
|
||||
210, 16, 247, 67, // i=67
|
||||
207, 13, 249, 68, // i=68
|
||||
204, 11, 251, 69, // i=69
|
||||
201, 9, 253, 70, // i=70
|
||||
198, 7, 255, 71, // i=71
|
||||
196, 4, 254, 72, // i=72
|
||||
193, 2, 252, 73, // i=73
|
||||
190, 0, 250, 74, // i=74
|
||||
187, 1, 248, 75, // i=75
|
||||
184, 3, 246, 76, // i=76
|
||||
181, 5, 244, 77, // i=77
|
||||
178, 7, 242, 78, // i=78
|
||||
175, 9, 240, 79, // i=79
|
||||
172, 11, 237, 80, // i=80
|
||||
169, 14, 235, 81, // i=81
|
||||
166, 16, 233, 82, // i=82
|
||||
163, 18, 230, 83, // i=83
|
||||
160, 21, 228, 84, // i=84
|
||||
157, 23, 225, 85, // i=85
|
||||
154, 26, 223, 86, // i=86
|
||||
151, 28, 220, 87, // i=87
|
||||
148, 31, 218, 88, // i=88
|
||||
145, 33, 215, 89, // i=89
|
||||
142, 36, 212, 90, // i=90
|
||||
139, 39, 210, 91, // i=91
|
||||
136, 41, 207, 92, // i=92
|
||||
133, 44, 204, 93, // i=93
|
||||
130, 47, 201, 94, // i=94
|
||||
127, 50, 198, 95, // i=95
|
||||
124, 53, 196, 96, // i=96
|
||||
121, 55, 193, 97, // i=97
|
||||
118, 58, 190, 98, // i=98
|
||||
115, 61, 187, 99, // i=99
|
||||
112, 64, 184, 100, // i=100
|
||||
109, 67, 181, 101, // i=101
|
||||
106, 70, 178, 102, // i=102
|
||||
103, 73, 175, 103, // i=103
|
||||
100, 76, 172, 104, // i=104
|
||||
97, 79, 169, 105, // i=105
|
||||
94, 82, 166, 106, // i=106
|
||||
91, 85, 163, 107, // i=107
|
||||
88, 88, 160, 108, // i=108
|
||||
85, 91, 157, 109, // i=109
|
||||
82, 94, 154, 110, // i=110
|
||||
79, 97, 151, 111, // i=111
|
||||
76, 100, 148, 112, // i=112
|
||||
73, 103, 145, 113, // i=113
|
||||
70, 106, 142, 114, // i=114
|
||||
67, 109, 139, 115, // i=115
|
||||
64, 112, 136, 116, // i=116
|
||||
61, 115, 133, 117, // i=117
|
||||
58, 118, 130, 118, // i=118
|
||||
55, 121, 127, 119, // i=119
|
||||
53, 124, 124, 120, // i=120
|
||||
50, 127, 121, 121, // i=121
|
||||
47, 130, 118, 122, // i=122
|
||||
44, 133, 115, 123, // i=123
|
||||
41, 136, 112, 124, // i=124
|
||||
39, 139, 109, 125, // i=125
|
||||
36, 142, 106, 126, // i=126
|
||||
33, 145, 103, 127, // i=127
|
||||
31, 148, 100, 128, // i=128
|
||||
28, 151, 97, 129, // i=129
|
||||
26, 154, 94, 130, // i=130
|
||||
23, 157, 91, 131, // i=131
|
||||
21, 160, 88, 132, // i=132
|
||||
18, 163, 85, 133, // i=133
|
||||
16, 166, 82, 134, // i=134
|
||||
13, 169, 79, 135, // i=135
|
||||
11, 172, 76, 136, // i=136
|
||||
9, 175, 73, 137, // i=137
|
||||
7, 178, 70, 138, // i=138
|
||||
4, 181, 67, 139, // i=139
|
||||
2, 184, 64, 140, // i=140
|
||||
0, 187, 61, 141, // i=141
|
||||
1, 190, 58, 142, // i=142
|
||||
3, 193, 55, 143, // i=143
|
||||
5, 196, 53, 144, // i=144
|
||||
7, 198, 50, 145, // i=145
|
||||
9, 201, 47, 146, // i=146
|
||||
11, 204, 44, 147, // i=147
|
||||
14, 207, 41, 148, // i=148
|
||||
16, 210, 39, 149, // i=149
|
||||
18, 212, 36, 150, // i=150
|
||||
21, 215, 33, 151, // i=151
|
||||
23, 218, 31, 152, // i=152
|
||||
26, 220, 28, 153, // i=153
|
||||
28, 223, 26, 154, // i=154
|
||||
31, 225, 23, 155, // i=155
|
||||
33, 228, 21, 156, // i=156
|
||||
36, 230, 18, 157, // i=157
|
||||
39, 233, 16, 158, // i=158
|
||||
41, 235, 13, 159, // i=159
|
||||
44, 238, 11, 160, // i=160
|
||||
47, 240, 9, 161, // i=161
|
||||
50, 242, 7, 162, // i=162
|
||||
53, 244, 4, 163, // i=163
|
||||
55, 247, 2, 164, // i=164
|
||||
58, 249, 0, 165, // i=165
|
||||
61, 251, 1, 166, // i=166
|
||||
64, 253, 3, 167, // i=167
|
||||
67, 255, 5, 168, // i=168
|
||||
70, 254, 7, 169, // i=169
|
||||
73, 252, 9, 170, // i=170
|
||||
76, 250, 11, 171, // i=171
|
||||
79, 248, 14, 172, // i=172
|
||||
82, 246, 16, 173, // i=173
|
||||
85, 244, 18, 174, // i=174
|
||||
88, 242, 21, 175, // i=175
|
||||
91, 240, 23, 176, // i=176
|
||||
94, 237, 26, 177, // i=177
|
||||
97, 235, 28, 178, // i=178
|
||||
100, 233, 31, 179, // i=179
|
||||
103, 230, 33, 180, // i=180
|
||||
106, 228, 36, 181, // i=181
|
||||
109, 225, 39, 182, // i=182
|
||||
112, 223, 41, 183, // i=183
|
||||
115, 220, 44, 184, // i=184
|
||||
118, 218, 47, 185, // i=185
|
||||
121, 215, 50, 186, // i=186
|
||||
124, 212, 53, 187, // i=187
|
||||
127, 210, 55, 188, // i=188
|
||||
130, 207, 58, 189, // i=189
|
||||
133, 204, 61, 190, // i=190
|
||||
136, 201, 64, 191, // i=191
|
||||
139, 198, 67, 192, // i=192
|
||||
142, 196, 70, 193, // i=193
|
||||
145, 193, 73, 194, // i=194
|
||||
148, 190, 76, 195, // i=195
|
||||
151, 187, 79, 196, // i=196
|
||||
154, 184, 82, 197, // i=197
|
||||
157, 181, 85, 198, // i=198
|
||||
160, 178, 88, 199, // i=199
|
||||
163, 175, 91, 200, // i=200
|
||||
166, 172, 94, 201, // i=201
|
||||
169, 169, 97, 202, // i=202
|
||||
172, 166, 100, 203, // i=203
|
||||
175, 163, 103, 204, // i=204
|
||||
178, 160, 106, 205, // i=205
|
||||
181, 157, 109, 206, // i=206
|
||||
184, 154, 112, 207, // i=207
|
||||
187, 151, 115, 208, // i=208
|
||||
190, 148, 118, 209, // i=209
|
||||
193, 145, 121, 210, // i=210
|
||||
196, 142, 124, 211, // i=211
|
||||
198, 139, 127, 212, // i=212
|
||||
201, 136, 130, 213, // i=213
|
||||
204, 133, 133, 214, // i=214
|
||||
207, 130, 136, 215, // i=215
|
||||
210, 127, 139, 216, // i=216
|
||||
212, 124, 142, 217, // i=217
|
||||
215, 121, 145, 218, // i=218
|
||||
218, 118, 148, 219, // i=219
|
||||
220, 115, 151, 220, // i=220
|
||||
223, 112, 154, 221, // i=221
|
||||
225, 109, 157, 222, // i=222
|
||||
228, 106, 160, 223, // i=223
|
||||
230, 103, 163, 224, // i=224
|
||||
233, 100, 166, 225, // i=225
|
||||
235, 97, 169, 226, // i=226
|
||||
238, 94, 172, 227, // i=227
|
||||
240, 91, 175, 228, // i=228
|
||||
242, 88, 178, 229, // i=229
|
||||
244, 85, 181, 230, // i=230
|
||||
247, 82, 184, 231, // i=231
|
||||
249, 79, 187, 232, // i=232
|
||||
251, 76, 190, 233, // i=233
|
||||
253, 73, 193, 234, // i=234
|
||||
255, 70, 196, 235, // i=235
|
||||
254, 67, 198, 236, // i=236
|
||||
252, 64, 201, 237, // i=237
|
||||
250, 61, 204, 238, // i=238
|
||||
248, 58, 207, 239, // i=239
|
||||
246, 55, 210, 240, // i=240
|
||||
244, 53, 212, 241, // i=241
|
||||
242, 50, 215, 242, // i=242
|
||||
240, 47, 218, 243, // i=243
|
||||
237, 44, 220, 244, // i=244
|
||||
235, 41, 223, 245, // i=245
|
||||
233, 39, 225, 246, // i=246
|
||||
230, 36, 228, 247, // i=247
|
||||
228, 33, 230, 248, // i=248
|
||||
225, 31, 233, 249, // i=249
|
||||
223, 28, 235, 250, // i=250
|
||||
220, 26, 238, 251, // i=251
|
||||
218, 23, 240, 252, // i=252
|
||||
215, 21, 242, 253, // i=253
|
||||
212, 18, 244, 254, // i=254
|
||||
210, 16, 247, 255 // i=255
|
||||
};
|
||||
|
||||
|
||||
/* USER CODE END PTD */
|
||||
@@ -392,6 +54,8 @@ const uint8_t interleaved_tables[1024] = {
|
||||
uint16_t iter, cnt = 5;
|
||||
uint8_t init_retries = 5;
|
||||
uint8_t ralay_5v_on_var = 0;
|
||||
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
@@ -426,7 +90,7 @@ int last_page_addr = LAST_PAGE_ADDR;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
BufferState_t buffer_state = {0};
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
@@ -469,10 +133,10 @@ int main(void)
|
||||
MX_TIM2_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_RTC_Init();
|
||||
// MX_RTC_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
|
||||
BufferState_t buffer_init();
|
||||
|
||||
led_blink(GPIOC, 13, rest_iter, reset_blink_delay);
|
||||
MODBUS_FirstInit(&hmodbus1, &mb_huart, &mb_htim);
|
||||
@@ -499,39 +163,54 @@ int main(void)
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
if (MB_DATA.Coils.reserve3[0]==1)
|
||||
{
|
||||
MB_DATA.Coils.reserve3[0] = 0;
|
||||
BufferState_t state = buffer_init();
|
||||
uint32_t idx = (state.write_index ) % RECORDS_PER_PAGE;
|
||||
FlashRecord_t* record = buffer_read_record(idx);
|
||||
|
||||
// if (MB_DATA.Coils.relay_struct[0].state_val_bit.Temp11_relay_isOn)
|
||||
// {
|
||||
// MB_DATA.Coils.relay_struct[0].state_val_bit.Temp11_relay_isOn = 0;
|
||||
// BufferState_t state = buffer_init();
|
||||
// uint32_t idx = (state.write_index ) % RECORDS_PER_PAGE;
|
||||
// FlashRecord_t* record = buffer_read_record(idx);
|
||||
}
|
||||
if (MB_DATA.Coils.reserve3[1]==1)
|
||||
{
|
||||
MB_DATA.Coils.reserve3[1] = 0;
|
||||
FlashRecord_t new_record;
|
||||
new_record.timestamp = HAL_GetTick();
|
||||
memcpy(new_record.data, flash_buff, sizeof(new_record.data));
|
||||
|
||||
// }
|
||||
// if (MB_DATA.Coils.relay_struct[0].state_val_bit.Temp10_relay_isOn)
|
||||
// {
|
||||
// MB_DATA.Coils.relay_struct[0].state_val_bit.Temp10_relay_isOn = 0;
|
||||
// FlashRecord_t new_record;
|
||||
// new_record.timestamp = HAL_GetTick();
|
||||
// memcpy(new_record.data, flash_buff, sizeof(new_record.data));
|
||||
HAL_StatusTypeDef status = buffer_write_record(&new_record, &buffer_state);
|
||||
|
||||
// HAL_StatusTypeDef status = buffer_write_record(&new_record, &buffer_state);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
// printf("Record written successfully\n");
|
||||
GPIOC->ODR |= 1 << 13;
|
||||
}
|
||||
|
||||
// if (status == HAL_OK)
|
||||
// {
|
||||
// // printf("Record written successfully\n");
|
||||
// GPIOC->ODR |= 1 << 13;
|
||||
// }
|
||||
|
||||
// }
|
||||
}
|
||||
temp_sense[0].t_close = 1;
|
||||
Field_modbus(&MB_DATA, &flag);
|
||||
Check_Tconnect(&MB_DATA, &flag, &hdallas, 0);
|
||||
value_control();
|
||||
init_setpoint_all_T_sense(temp_sense, hdallas.onewire->RomCnt);
|
||||
// handle_valves(temp_sense[]);
|
||||
Dallas_StartConvertTAll(&hdallas, DALLAS_WAIT_BUS, 0);
|
||||
init_cycle_counter();
|
||||
static uint16_t dataBE[2];
|
||||
static uint16_t dataLE[2];
|
||||
uint32_t start_dwt = get_cycle_count();
|
||||
uint32_t start = HAL_GetTick();
|
||||
Dallas_StartConvertTAll(&hdallas, DALLAS_WAIT_NONE, 0);
|
||||
uint32_t end_dwt = get_cycle_count();
|
||||
uint32_t end = HAL_GetTick();
|
||||
uint32_t time_DWT=end_dwt-start_dwt;
|
||||
uint32_t time_hal=end-start;
|
||||
U32_TO_MODBUS(time_DWT, dataBE, MODBUS_REG_ORDER_BE);
|
||||
U32_TO_MODBUS(time_DWT, dataLE, MODBUS_REG_ORDER_LE);
|
||||
|
||||
|
||||
for(int i = 0; i < hdallas.onewire->RomCnt; i++)
|
||||
{
|
||||
if(sens[i].isLost)
|
||||
@@ -542,7 +221,7 @@ int main(void)
|
||||
|
||||
Dallas_ReadTemperature(&sens[i]);
|
||||
MB_DATA.InRegs.sens_Temp[i] = sens[i].temperature * 10;
|
||||
/////////////////////////заменить на define ralay_5v_on_var GPIOA->ODR|=1<<10;
|
||||
|
||||
ralay_5v_on_var = MB_DATA.Coils.coils[1].state_val_bit.state_val_05;
|
||||
if (ralay_5v_on_var)
|
||||
{
|
||||
@@ -619,6 +298,40 @@ void SystemClock_Config(void)
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
uint32_t get_cycle_count(void) {
|
||||
return DWT->CYCCNT;
|
||||
}
|
||||
|
||||
void init_cycle_counter(void) {
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
DWT->CYCCNT = 0;
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
}
|
||||
|
||||
// Замер времени в тактах процессора
|
||||
uint32_t measure_execution_time_cycles(void (*func)(void)) {
|
||||
uint32_t start = get_cycle_count();
|
||||
func();
|
||||
uint32_t end = get_cycle_count();
|
||||
return end - start;
|
||||
}
|
||||
|
||||
|
||||
uint16_t* U32_TO_MODBUS (uint32_t value, uint16_t reg_array[2], int order)
|
||||
{
|
||||
|
||||
if (order == MODBUS_REG_ORDER_BE)
|
||||
{
|
||||
(reg_array)[0] = (uint16_t)((value) >> 16);
|
||||
(reg_array)[1] = (uint16_t)(value);
|
||||
} else
|
||||
{
|
||||
(reg_array)[0] = (uint16_t)(value);
|
||||
(reg_array)[1] = (uint16_t)((value) >> 16);
|
||||
}
|
||||
return reg_array;
|
||||
}
|
||||
|
||||
void iwdg_refresh(void)
|
||||
{
|
||||
IWDG->KR = 0xAAAA; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
@@ -23,6 +23,12 @@
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "modbus.h"
|
||||
|
||||
|
||||
|
||||
|
||||
//#include "PROJ_setup.h"
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -314,7 +320,10 @@ static uint8_t first_in=1;
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN USART1_IRQn 0 */
|
||||
RS_UART_Handler(&hmodbus1);
|
||||
RS_UART_Handler(&hmodbus1);
|
||||
|
||||
|
||||
|
||||
return;
|
||||
/* USER CODE END USART1_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart1);
|
||||
|
||||
@@ -257,6 +257,7 @@
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f1xx_hal.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32F1xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
@@ -2362,6 +2363,8 @@ void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
|
||||
/* UART in mode Receiver -------------------------------------------------*/
|
||||
if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
|
||||
{
|
||||
|
||||
|
||||
UART_Receive_IT(huart);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -148,7 +148,56 @@
|
||||
<Name>(105=-1,-1,-1,-1,0)</Name>
|
||||
</SetRegEntry>
|
||||
</TargetDriverDllRegistry>
|
||||
<Breakpoint/>
|
||||
<Breakpoint>
|
||||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>180</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134248318</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>../Core/Src/main.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\\../Core/Src/main.c\180</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>1</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>37</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134247384</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>..\EEPROM_Emul\src\flash_ring.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\john103C6T6\../EEPROM_Emul/src/flash_ring.c\37</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>2</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>175</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134248290</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>../Core/Src/main.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\john103C6T6\../Core/Src/main.c\175</Expression>
|
||||
</Bp>
|
||||
</Breakpoint>
|
||||
<WatchWindow1>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
@@ -220,6 +269,76 @@
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>flag,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>14</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>time_DWT,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>15</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>dataBE,0x10</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>16</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>dataLE,0x10</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>17</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>time_DWT,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>18</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>time_hal,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>19</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>hmodbus1,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>20</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>count,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>21</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>a,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>22</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>b,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>23</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>hblinker</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>24</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>hled</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>25</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>new_record</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>26</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>record_addr</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>27</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>record</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<WatchWindow2>
|
||||
<Ww>
|
||||
@@ -301,6 +420,10 @@
|
||||
<Name>System Viewer\GPIOC</Name>
|
||||
<WinId>35905</WinId>
|
||||
</Entry>
|
||||
<Entry>
|
||||
<Name>System Viewer\USART1</Name>
|
||||
<WinId>35903</WinId>
|
||||
</Entry>
|
||||
</SystemViewers>
|
||||
<DebugDescription>
|
||||
<Enable>1</Enable>
|
||||
@@ -940,6 +1063,26 @@
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
<GroupName>linkBlink</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>50</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\linkBlink\linkBlink.c</PathWithFileName>
|
||||
<FilenameWithoutPath>linkBlink.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
<GroupName>::CMSIS</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
|
||||
@@ -341,7 +341,7 @@
|
||||
<MiscControls></MiscControls>
|
||||
<Define>USE_HAL_DRIVER,STM32F103xB</Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>../Core/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include;../Modbus;../EEPROM_Emul/lib;../../core/STM32_Modbus/Inc</IncludePath>
|
||||
<IncludePath>../Core/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include;../Modbus;../EEPROM_Emul/lib;../../core/STM32_Modbus/Inc;..\linkBlink</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
@@ -1060,6 +1060,16 @@
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>linkBlink</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>linkBlink.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\linkBlink\linkBlink.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>::CMSIS</GroupName>
|
||||
</Group>
|
||||
|
||||
@@ -26,11 +26,11 @@
|
||||
#define MODBUS_TIMEOUT 5000 ///< Таймаут в тиках таймера
|
||||
|
||||
// Строковые идентификаторы устройства
|
||||
#define MODBUS_VENDOR_NAME "NIO-12"
|
||||
#define MODBUS_PRODUCT_CODE ""
|
||||
#define MODBUS_REVISION ""
|
||||
#define MODBUS_VENDOR_NAME "super mega vendor"
|
||||
#define MODBUS_PRODUCT_CODE "Climate control"
|
||||
#define MODBUS_REVISION "1.0"
|
||||
#define MODBUS_VENDOR_URL ""
|
||||
#define MODBUS_PRODUCT_NAME ""
|
||||
#define MODBUS_PRODUCT_NAME "Climate control"
|
||||
#define MODBUS_MODEL_NAME ""
|
||||
#define MODBUS_USER_APPLICATION_NAME ""
|
||||
|
||||
|
||||
@@ -84,12 +84,13 @@
|
||||
|
||||
typedef __PACKED_STRUCT//MB_DataInRegsTypeDef
|
||||
{
|
||||
|
||||
uint16_t num_Tsens;
|
||||
uint16_t sens_Temp[MAX_SENSE];
|
||||
uint16_t reserve[mb_fill_rsv(1000, uint16_t[MAX_SENSE])];
|
||||
uint16_t reserve[mb_fill_rsv(1000, uint16_t[MAX_SENSE+1])];
|
||||
DS18B20_Drv_t ID;
|
||||
uint16_t reserve1[mb_fill_rsv(200, DS18B20_Drv_t)];
|
||||
uint16_t num_Tsens;
|
||||
uint16_t system[158];
|
||||
uint16_t reserve2[mb_fill_rsv(200, uint16_t [158])];
|
||||
|
||||
|
||||
} MB_DataInRegsTypeDef;
|
||||
|
||||
@@ -127,7 +127,9 @@ PB8.Mode=I2C
|
||||
PB8.Signal=I2C1_SCL
|
||||
PB9.Mode=I2C
|
||||
PB9.Signal=I2C1_SDA
|
||||
PC13-TAMPER-RTC.GPIOParameters=PinState
|
||||
PC13-TAMPER-RTC.Locked=true
|
||||
PC13-TAMPER-RTC.PinState=GPIO_PIN_SET
|
||||
PC13-TAMPER-RTC.Signal=GPIO_Output
|
||||
PD0-OSC_IN.Mode=HSE-External-Oscillator
|
||||
PD0-OSC_IN.Signal=RCC_OSC_IN
|
||||
@@ -149,7 +151,7 @@ ProjectManager.FreePins=false
|
||||
ProjectManager.HalAssertFull=false
|
||||
ProjectManager.HeapSize=0x200
|
||||
ProjectManager.KeepUserCode=true
|
||||
ProjectManager.LastFirmware=true
|
||||
ProjectManager.LastFirmware=false
|
||||
ProjectManager.LibraryCopy=0
|
||||
ProjectManager.MainLocation=Core/Src
|
||||
ProjectManager.NoMain=false
|
||||
|
||||
161
john103C6T6NewVer/linkBlink/linkBlink.c
Normal file
161
john103C6T6NewVer/linkBlink/linkBlink.c
Normal file
@@ -0,0 +1,161 @@
|
||||
#include "linkBlink.h"
|
||||
|
||||
|
||||
static uint32_t GetTick(LedBlinker_HandleTypeDef* hblinker) {
|
||||
if (hblinker->htim != NULL) {
|
||||
return __HAL_TIM_GET_COUNTER(hblinker->htim);
|
||||
}
|
||||
return HAL_GetTick(); // Èñïîëüçóåì ñèñòåìíûé òàéìåð åñëè ñâîé íå çàäàí
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef LedBlinker_Init(LedBlinker_HandleTypeDef* hblinker,
|
||||
GPIO_TypeDef* led_port, uint16_t led_pin,
|
||||
GPIO_TypeDef* de_re_port, uint16_t de_re_pin,
|
||||
TIM_HandleTypeDef* htim) {
|
||||
if (hblinker == NULL || led_port == NULL) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
// Èíèöèàëèçàöèÿ ïîëåé
|
||||
hblinker->led_port = led_port;
|
||||
hblinker->led_pin = led_pin;
|
||||
hblinker->de_re_port = de_re_port;
|
||||
hblinker->de_re_pin = de_re_pin;
|
||||
hblinker->htim = htim;
|
||||
hblinker->blink_duration = 100;
|
||||
hblinker->last_blink_tick = 0;
|
||||
hblinker->led_state = false;
|
||||
hblinker->blinking = false;
|
||||
hblinker->blink_count = 0;
|
||||
hblinker->target_blink_count = 1;
|
||||
hblinker->last_packet_tick = 0;
|
||||
|
||||
// Íàñòðîéêà ïèíà ñâåòîäèîäà
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
GPIO_InitStruct.Pin = led_pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(led_port, &GPIO_InitStruct);
|
||||
|
||||
// Âûêëþ÷àåì ñâåòîäèîä
|
||||
HAL_GPIO_WritePin(led_port, led_pin, GPIO_PIN_RESET);
|
||||
|
||||
// Íàñòðîéêà ïèíà óïðàâëåíèÿ RS485 åñëè èñïîëüçóåòñÿ
|
||||
if (de_re_port != NULL && de_re_pin != 0) {
|
||||
GPIO_InitStruct.Pin = de_re_pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(de_re_port, &GPIO_InitStruct);
|
||||
|
||||
// Ðåæèì ïðèåìà ïî óìîë÷àíèþ
|
||||
HAL_GPIO_WritePin(de_re_port, de_re_pin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
void LedBlinker_Update(LedBlinker_HandleTypeDef* hblinker) {
|
||||
if (hblinker == NULL || !hblinker->blinking) return;
|
||||
|
||||
uint32_t current_tick = HAL_GetTick();
|
||||
|
||||
if ((current_tick - hblinker->last_blink_tick) >= hblinker->blink_duration) {
|
||||
hblinker->last_blink_tick = current_tick;
|
||||
|
||||
// Ïåðåêëþ÷àåì ñîñòîÿíèå ñâåòîäèîäà
|
||||
hblinker->led_state = !hblinker->led_state;
|
||||
HAL_GPIO_WritePin(hblinker->led_port, hblinker->led_pin,
|
||||
hblinker->led_state ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
|
||||
// Åñëè ñâåòîäèîä âûêëþ÷èëñÿ, óìåíüøàåì ñ÷åò÷èê
|
||||
if (!hblinker->led_state) {
|
||||
hblinker->blink_count++;
|
||||
if (hblinker->blink_count >= hblinker->target_blink_count) {
|
||||
hblinker->blinking = false;
|
||||
HAL_GPIO_WritePin(hblinker->led_port, hblinker->led_pin, GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LedBlinker_ProcessPacket(LedBlinker_HandleTypeDef* hblinker,
|
||||
uint8_t* data, uint16_t len) {
|
||||
if (hblinker == NULL || data == NULL || len == 0) return;
|
||||
|
||||
hblinker->last_packet_tick = HAL_GetTick();
|
||||
|
||||
// Àíàëèç ïàêåòà è âûáîð ïàòòåðíà ìèãàíèÿ
|
||||
if (len >= 1) {
|
||||
// Ïðèìåð: ïåðâûé áàéò îïðåäåëÿåò êîëè÷åñòâî ìèãàíèé
|
||||
uint8_t blink_count = data[0];
|
||||
if (blink_count == 0) blink_count = 1;
|
||||
if (blink_count > 20) blink_count = 20; // Îãðàíè÷åíèå
|
||||
|
||||
// Âòîðîé áàéò ìîæåò îïðåäåëÿòü äëèòåëüíîñòü (åñëè åñòü)
|
||||
uint32_t duration = 100;
|
||||
if (len >= 2) {
|
||||
duration = 50 + (data[1] * 10);
|
||||
if (duration > 1000) duration = 1000;
|
||||
}
|
||||
|
||||
LedBlinker_BlinkPattern(hblinker, blink_count, duration);
|
||||
}
|
||||
|
||||
// Äîïîëíèòåëüíûå ïàòòåðíû â çàâèñèìîñòè îò äàííûõ
|
||||
if (len >= 4 && data[0] == 0xFF) {
|
||||
// Ñïåöèàëüíûé ïàòòåðí äëÿ êîìàíä
|
||||
LedBlinker_BlinkPattern(hblinker, 5, 50);
|
||||
}
|
||||
}
|
||||
|
||||
void LedBlinker_BlinkOnce(LedBlinker_HandleTypeDef* hblinker, uint32_t duration) {
|
||||
if (hblinker == NULL) return;
|
||||
|
||||
hblinker->blink_duration = duration;
|
||||
hblinker->target_blink_count = 1;
|
||||
hblinker->blink_count = 0;
|
||||
hblinker->blinking = true;
|
||||
hblinker->led_state = false;
|
||||
hblinker->last_blink_tick = GetTick(hblinker);
|
||||
|
||||
// Íåìåäëåííîå âêëþ÷åíèå
|
||||
HAL_GPIO_WritePin(hblinker->led_port, hblinker->led_pin, GPIO_PIN_SET);
|
||||
hblinker->led_state = true;
|
||||
}
|
||||
|
||||
void LedBlinker_BlinkPattern(LedBlinker_HandleTypeDef* hblinker,
|
||||
uint8_t count, uint32_t duration) {
|
||||
if (hblinker == NULL || count == 0) return;
|
||||
|
||||
hblinker->blink_duration = duration;
|
||||
hblinker->target_blink_count = count;
|
||||
hblinker->blink_count = 0;
|
||||
hblinker->blinking = true;
|
||||
hblinker->led_state = false;
|
||||
hblinker->last_blink_tick = HAL_GetTick();
|
||||
|
||||
// Íåìåäëåííîå âêëþ÷åíèå
|
||||
HAL_GPIO_WritePin(hblinker->led_port, hblinker->led_pin, GPIO_PIN_SET);
|
||||
hblinker->led_state = true;
|
||||
}
|
||||
|
||||
void LedBlinker_SetRS485Mode(LedBlinker_HandleTypeDef* hblinker, bool transmit) {
|
||||
if (hblinker == NULL || hblinker->de_re_port == NULL) return;
|
||||
|
||||
HAL_GPIO_WritePin(hblinker->de_re_port, hblinker->de_re_pin,
|
||||
transmit ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
bool LedBlinker_IsBlinking(LedBlinker_HandleTypeDef* hblinker) {
|
||||
return (hblinker != NULL) ? hblinker->blinking : false;
|
||||
}
|
||||
|
||||
uint32_t LedBlinker_GetTimeSinceLastPacket(LedBlinker_HandleTypeDef* hblinker) {
|
||||
if (hblinker == NULL) return 0;
|
||||
|
||||
if (hblinker->last_packet_tick == 0) return 0;
|
||||
|
||||
return GetTick(hblinker) - hblinker->last_packet_tick;
|
||||
}
|
||||
90
john103C6T6NewVer/linkBlink/linkBlink.h
Normal file
90
john103C6T6NewVer/linkBlink/linkBlink.h
Normal file
@@ -0,0 +1,90 @@
|
||||
#ifndef LED_BLINKER_RS485_H
|
||||
#define LED_BLINKER_RS485_H
|
||||
|
||||
#include "stm32f1xx_hal.h" // Èçìåíèòå ïîä ñâîé êîíêðåòíûé ìèêðîêîíòðîëëåð
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
GPIO_TypeDef* led_port; // Ïîðò ñâåòîäèîäà
|
||||
uint16_t led_pin; // Ïèí ñâåòîäèîäà
|
||||
GPIO_TypeDef* de_re_port; // Ïîðò óïðàâëåíèÿ RS485 (NULL åñëè íå èñïîëüçóåòñÿ)
|
||||
uint16_t de_re_pin; // Ïèí óïðàâëåíèÿ RS485
|
||||
TIM_HandleTypeDef* htim; // Òàéìåð äëÿ îòñ÷åòà âðåìåíè
|
||||
uint32_t blink_duration; // Äëèòåëüíîñòü ìèãàíèÿ â ìñ
|
||||
uint32_t last_blink_tick; // Âðåìÿ ïîñëåäíåãî ìèãàíèÿ (â òèêàõ)
|
||||
bool led_state; // Òåêóùåå ñîñòîÿíèå ñâåòîäèîäà
|
||||
bool blinking; // Ôëàã ìèãàíèÿ
|
||||
uint8_t blink_count; // Ñ÷åò÷èê ìèãàíèé
|
||||
uint8_t target_blink_count; // Öåëåâîå êîëè÷åñòâî ìèãàíèé
|
||||
uint32_t last_packet_tick; // Âðåìÿ ïîñëåäíåãî ïàêåòà
|
||||
} LedBlinker_HandleTypeDef;
|
||||
|
||||
/**
|
||||
* Èíèöèàëèçàöèÿ ñòðóêòóðû ìèãàëêè
|
||||
* @param hblinker - óêàçàòåëü íà ñòðóêòóðó
|
||||
* @param led_port - ïîðò ñâåòîäèîäà
|
||||
* @param led_pin - ïèí ñâåòîäèîäà
|
||||
* @param de_re_port - ïîðò óïðàâëåíèÿ RS485 (NULL åñëè íå èñïîëüçóåòñÿ)
|
||||
* @param de_re_pin - ïèí óïðàâëåíèÿ RS485
|
||||
* @param htim - òàéìåð äëÿ âðåìåííûõ îòñ÷åòîâ
|
||||
* @return HAL_OK èëè HAL_ERROR
|
||||
*/
|
||||
HAL_StatusTypeDef LedBlinker_Init(LedBlinker_HandleTypeDef* hblinker,
|
||||
GPIO_TypeDef* led_port, uint16_t led_pin,
|
||||
GPIO_TypeDef* de_re_port, uint16_t de_re_pin,
|
||||
TIM_HandleTypeDef* htim);
|
||||
|
||||
/**
|
||||
* Îáðàáîò÷èê ìèãàíèÿ (âûçûâàòü â îñíîâíîì öèêëå)
|
||||
* @param hblinker - óêàçàòåëü íà ñòðóêòóðó
|
||||
*/
|
||||
void LedBlinker_Update(LedBlinker_HandleTypeDef* hblinker);
|
||||
|
||||
/**
|
||||
* Îáðàáîòêà ïîëó÷åííîãî ïàêåòà
|
||||
* @param hblinker - óêàçàòåëü íà ñòðóêòóðó
|
||||
* @param data - óêàçàòåëü íà äàííûå
|
||||
* @param len - äëèíà äàííûõ
|
||||
*/
|
||||
void LedBlinker_ProcessPacket(LedBlinker_HandleTypeDef* hblinker,
|
||||
uint8_t* data, uint16_t len);
|
||||
|
||||
/**
|
||||
* Ïðîñòîå ìèãàíèå ïðè ïîëó÷åíèè ïàêåòà
|
||||
* @param hblinker - óêàçàòåëü íà ñòðóêòóðó
|
||||
* @param duration - äëèòåëüíîñòü ìèãàíèÿ â ìñ
|
||||
*/
|
||||
void LedBlinker_BlinkOnce(LedBlinker_HandleTypeDef* hblinker, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Ìèãàíèå ñ îïðåäåëåííûì ïàòòåðíîì
|
||||
* @param hblinker - óêàçàòåëü íà ñòðóêòóðó
|
||||
* @param count - êîëè÷åñòâî ìèãàíèé
|
||||
* @param duration - äëèòåëüíîñòü îäíîãî ìèãàíèÿ â ìñ
|
||||
*/
|
||||
void LedBlinker_BlinkPattern(LedBlinker_HandleTypeDef* hblinker,
|
||||
uint8_t count, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Óñòàíîâêà ðåæèìà RS485
|
||||
* @param hblinker - óêàçàòåëü íà ñòðóêòóðó
|
||||
* @param transmit - true äëÿ ïåðåäà÷è, false äëÿ ïðèåìà
|
||||
*/
|
||||
void LedBlinker_SetRS485Mode(LedBlinker_HandleTypeDef* hblinker, bool transmit);
|
||||
|
||||
/**
|
||||
* Ïðîâåðêà, ìèãàåò ëè ñåé÷àñ ñâåòîäèîä
|
||||
* @param hblinker - óêàçàòåëü íà ñòðóêòóðó
|
||||
* @return true åñëè ìèãàåò
|
||||
*/
|
||||
bool LedBlinker_IsBlinking(LedBlinker_HandleTypeDef* hblinker);
|
||||
|
||||
/**
|
||||
* Ïîëó÷åíèå âðåìåíè ñ ïîñëåäíåãî ïàêåòà
|
||||
* @param hblinker - óêàçàòåëü íà ñòðóêòóðó
|
||||
* @return âðåìÿ â ìñ ñ ïîñëåäíåãî ïàêåòà
|
||||
*/
|
||||
uint32_t LedBlinker_GetTimeSinceLastPacket(LedBlinker_HandleTypeDef* hblinker);
|
||||
|
||||
#endif // LED_BLINKER_RS485_H
|
||||
Reference in New Issue
Block a user