diff --git a/Project Backups/schem [Autosaved].pdsprj b/Project Backups/schem [Autosaved].pdsprj
new file mode 100644
index 0000000..692609a
Binary files /dev/null and b/Project Backups/schem [Autosaved].pdsprj differ
diff --git a/john103C6T6NewVer/Core/Inc/main.h b/john103C6T6NewVer/Core/Inc/main.h
index eee2e6b..1f42a55 100644
--- a/john103C6T6NewVer/Core/Inc/main.h
+++ b/john103C6T6NewVer/Core/Inc/main.h
@@ -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 --------------------------------------------------------*/
diff --git a/john103C6T6NewVer/Core/Src/gpio.c b/john103C6T6NewVer/Core/Src/gpio.c
index 3b7b6f4..597e8c4 100644
--- a/john103C6T6NewVer/Core/Src/gpio.c
+++ b/john103C6T6NewVer/Core/Src/gpio.c
@@ -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
diff --git a/john103C6T6NewVer/Core/Src/main.c b/john103C6T6NewVer/Core/Src/main.c
index 5dd3ab8..5b53c19 100644
--- a/john103C6T6NewVer/Core/Src/main.c
+++ b/john103C6T6NewVer/Core/Src/main.c
@@ -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; // �������� ������
diff --git a/john103C6T6NewVer/Core/Src/stm32f1xx_it.c b/john103C6T6NewVer/Core/Src/stm32f1xx_it.c
index 3ba5380..44966ce 100644
--- a/john103C6T6NewVer/Core/Src/stm32f1xx_it.c
+++ b/john103C6T6NewVer/Core/Src/stm32f1xx_it.c
@@ -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);
diff --git a/john103C6T6NewVer/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c b/john103C6T6NewVer/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c
index b7cf66c..519a82f 100644
--- a/john103C6T6NewVer/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c
+++ b/john103C6T6NewVer/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c
@@ -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;
}
diff --git a/john103C6T6NewVer/MDK-ARM/john103C6T6.uvoptx b/john103C6T6NewVer/MDK-ARM/john103C6T6.uvoptx
index 0be1343..626a087 100644
--- a/john103C6T6NewVer/MDK-ARM/john103C6T6.uvoptx
+++ b/john103C6T6NewVer/MDK-ARM/john103C6T6.uvoptx
@@ -148,7 +148,56 @@
(105=-1,-1,-1,-1,0)
-
+
+
+ 0
+ 0
+ 180
+ 1
+ 134248318
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ ../Core/Src/main.c
+
+ \\\../Core/Src/main.c\180
+
+
+ 1
+ 0
+ 37
+ 1
+ 134247384
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ ..\EEPROM_Emul\src\flash_ring.c
+
+ \\john103C6T6\../EEPROM_Emul/src/flash_ring.c\37
+
+
+ 2
+ 0
+ 175
+ 1
+ 134248290
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ ../Core/Src/main.c
+
+ \\john103C6T6\../Core/Src/main.c\175
+
+
0
@@ -220,6 +269,76 @@
1
flag,0x0A
+
+ 14
+ 1
+ time_DWT,0x0A
+
+
+ 15
+ 1
+ dataBE,0x10
+
+
+ 16
+ 1
+ dataLE,0x10
+
+
+ 17
+ 1
+ time_DWT,0x0A
+
+
+ 18
+ 1
+ time_hal,0x0A
+
+
+ 19
+ 1
+ hmodbus1,0x0A
+
+
+ 20
+ 1
+ count,0x0A
+
+
+ 21
+ 1
+ a,0x0A
+
+
+ 22
+ 1
+ b,0x0A
+
+
+ 23
+ 1
+ hblinker
+
+
+ 24
+ 1
+ hled
+
+
+ 25
+ 1
+ new_record
+
+
+ 26
+ 1
+ record_addr
+
+
+ 27
+ 1
+ record
+
@@ -301,6 +420,10 @@
System Viewer\GPIOC
35905
+
+ System Viewer\USART1
+ 35903
+
1
@@ -940,6 +1063,26 @@
+
+ linkBlink
+ 1
+ 0
+ 0
+ 0
+
+ 6
+ 50
+ 1
+ 1
+ 0
+ 0
+ ..\linkBlink\linkBlink.c
+ linkBlink.c
+ 0
+ 0
+
+
+
::CMSIS
0
diff --git a/john103C6T6NewVer/MDK-ARM/john103C6T6.uvprojx b/john103C6T6NewVer/MDK-ARM/john103C6T6.uvprojx
index e532081..d1eadd1 100644
--- a/john103C6T6NewVer/MDK-ARM/john103C6T6.uvprojx
+++ b/john103C6T6NewVer/MDK-ARM/john103C6T6.uvprojx
@@ -341,7 +341,7 @@
USE_HAL_DRIVER,STM32F103xB
- ../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
+ ../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
@@ -1060,6 +1060,16 @@
+
+ linkBlink
+
+
+ linkBlink.c
+ 1
+ ..\linkBlink\linkBlink.c
+
+
+
::CMSIS
diff --git a/john103C6T6NewVer/Modbus/modbus_config.h b/john103C6T6NewVer/Modbus/modbus_config.h
index af82833..74850b2 100644
--- a/john103C6T6NewVer/Modbus/modbus_config.h
+++ b/john103C6T6NewVer/Modbus/modbus_config.h
@@ -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 ""
diff --git a/john103C6T6NewVer/Modbus/modbus_data.h b/john103C6T6NewVer/Modbus/modbus_data.h
index 8019c11..5aaf53f 100644
--- a/john103C6T6NewVer/Modbus/modbus_data.h
+++ b/john103C6T6NewVer/Modbus/modbus_data.h
@@ -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;
diff --git a/john103C6T6NewVer/john103C6T6.ioc b/john103C6T6NewVer/john103C6T6.ioc
index ebe3a0f..436a169 100644
--- a/john103C6T6NewVer/john103C6T6.ioc
+++ b/john103C6T6NewVer/john103C6T6.ioc
@@ -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
diff --git a/john103C6T6NewVer/linkBlink/linkBlink.c b/john103C6T6NewVer/linkBlink/linkBlink.c
new file mode 100644
index 0000000..94da588
--- /dev/null
+++ b/john103C6T6NewVer/linkBlink/linkBlink.c
@@ -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;
+}
\ No newline at end of file
diff --git a/john103C6T6NewVer/linkBlink/linkBlink.h b/john103C6T6NewVer/linkBlink/linkBlink.h
new file mode 100644
index 0000000..e3115fb
--- /dev/null
+++ b/john103C6T6NewVer/linkBlink/linkBlink.h
@@ -0,0 +1,90 @@
+#ifndef LED_BLINKER_RS485_H
+#define LED_BLINKER_RS485_H
+
+#include "stm32f1xx_hal.h" //
+#include
+#include
+
+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
\ No newline at end of file
diff --git a/schem.pdsprj.DESKTOP-RQ2QP65.z.workspace b/schem.pdsprj.DESKTOP-RQ2QP65.z.workspace
index 7865128..4da3025 100644
--- a/schem.pdsprj.DESKTOP-RQ2QP65.z.workspace
+++ b/schem.pdsprj.DESKTOP-RQ2QP65.z.workspace
@@ -1,9 +1,9 @@
- 2c0000000000000001000000ffffffffffffffffffffffffffffffff340100008500000080090000db050000
+ 2c0000000200000003000000ffffffffffffffffffffffffffffffff40000000670000008c080000bd050000
-
+
@@ -18,13 +18,41 @@
-
+
-
+
+
+
+ - -22
+ - No
+ - 100
+ - 100
+
+
+
+
+ - 100
+ - No
+ - Yes
+ - 100
+ - 100
+ - Yes
+ - Yes
+ - Yes
+ - Yes
+ - 0
+ - 100
+ - 100
+ - 100
+ - 100
+ - 0
+
+
+