Преглед изворни кода

Работа с системными переменными и параметрами.

TelenkovDmitry пре 9 месеци
родитељ
комит
e4c82d055a

+ 36 - 2
fw/modules/modbus/modbus_params.c

@@ -13,9 +13,14 @@
 mb_param_t mb_param[MB_PARAM_MAX];
 
 uint32_t rtc_sinhro;
-uint16_t psw;   // Пароль для установки системных настроек
+
+// Пароль для установки системных настроек
+uint16_t psw;   
 bool psw_ok = false;
 
+// Копия системных настроек
+sys_settings_t temp_sys_settings;
+
 void get_time(uint8_t* buf, uint8_t size);
 void get_din_mode(uint8_t* buf, uint8_t size);
 
@@ -226,7 +231,36 @@ void mb_init_params(void)
 	//	Системные настройки
 	// ---------------------------------------------------------------------- //
 
+    // Модель
+    mb_param[index].reg = 0x0080;
+	mb_param[index].size = 1;
+	mb_param[index].param = (uint8_t*)&model_code; // 
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
+
+/*    
+    // Дата производства
+    mb_param[index].reg = 0x0081;
+	mb_param[index].size = 2;
+	mb_param[index].param = (uint8_t*)&temp_sys_settings.prod_date; // 
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
     
+    index++;
+    
+    // Серийный номер
+    mb_param[index].reg = 0x0083;
+	mb_param[index].size = 2;
+	mb_param[index].param = (uint8_t*)&temp_sys_settings.sn; // 
+	mb_param[index].set = NULL;
+    mb_param[index].get = NULL;
+    mb_param[index].check_handler = mb_check_dummy;
+    
+    index++;
     
     // Пароль
     mb_param[index].reg = 0x008A;
@@ -237,7 +271,7 @@ void mb_init_params(void)
     mb_param[index].check_handler = mb_check_dummy;
     
     index++;
-    
+*/    
     
 }
 

+ 1 - 1
fw/modules/modbus/modbus_params.h

@@ -16,7 +16,7 @@ extern "C" {
 
 #define SWAP_16(x, y)   {x[0] = y >> 8; x[1] = y & 0x0FF;}
   
-#define MB_PARAM_MAX			59//54
+#define MB_PARAM_MAX			60//54
 
 
 //

+ 12 - 0
fw/user/flash_ram_const.c

@@ -0,0 +1,12 @@
+#include "at32f403a_407.h"
+#include "model_cfg.h"
+
+
+
+#ifdef __ICCARM__
+#pragma location = ".model"
+const char model[16] = MODEL_STR;
+#else
+char model[16] __attribute__ ((section (".model"))) = MODEL_STR;
+#endif
+

+ 3 - 0
fw/user/main.cpp

@@ -41,6 +41,8 @@ extern "C" {
 #include <stdbool.h>
 #include <string.h>
 
+
+
 void init_task(void *argument);
 void test_hw_task(void *argument);
 void soft_wdt(void *params);
@@ -49,6 +51,7 @@ void misc_task(void *params);   // TODO перенести в другой мо
 
 void usb_clock48m_select(usb_clk48_s clk_s);
 
+
 //
 int main(void)
 {


+ 4 - 5
project/ewarm/AT32F403AxG.icf

@@ -1,11 +1,8 @@
-/*###ICF### Section handled by ICF editor, don't touch! ****/
-/*-Editor annotation file-*/
-/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
-/*-Specials-*/
 define symbol __ICFEDIT_intvec_start__ = 0x08021000;
 /*-Memory Regions-*/
-define symbol __ICFEDIT_region_ROM_start__ = 0x08021000;
+define symbol __ICFEDIT_region_ROM_start__ = 0x08021400;
 define symbol __ICFEDIT_region_ROM_end__   = 0x080FFFFF;
+define symbol __MODEL_ADDR__               = 0x080211F0;
 define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
 define symbol __ICFEDIT_region_RAM_end__   = 0x20037FFF;
 /*-Sizes-*/
@@ -24,6 +21,8 @@ initialize by copy { readwrite, section .sram };
 do not initialize  { section .noinit };
 
 place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
+place at address mem: __MODEL_ADDR__   { readonly section .model };
+keep { section .model };
 
 place in ROM_region   { readonly };
 place in RAM_region   { readwrite, block CSTACK, block HEAP };

+ 7 - 2
project/ewarm/fw/AT32F403AxG.icf

@@ -2,12 +2,15 @@
 /*-Editor annotation file-*/
 /* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
 /*-Specials-*/
-define symbol __ICFEDIT_intvec_start__ = 0x08000000;
+define symbol __ICFEDIT_intvec_start__ = 0x08021000;
+
 /*-Memory Regions-*/
-define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
+define symbol __ICFEDIT_region_ROM_start__ = 0x08021200;
 define symbol __ICFEDIT_region_ROM_end__   = 0x080FFFFF;
+define symbol __MODEL_ADDR__               = 0x080211F0;
 define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
 define symbol __ICFEDIT_region_RAM_end__   = 0x20037FFF;
+
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x1000;
 define symbol __ICFEDIT_size_heap__   = 0x1000;
@@ -24,6 +27,8 @@ initialize by copy { readwrite, section .sram };
 do not initialize  { section .noinit };
 
 place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
+place at address mem: __MODEL_ADDR__   { readonly section .model };
+keep { section .model };
 
 place in ROM_region   { readonly };
 place in RAM_region   { readwrite, block CSTACK, block HEAP };

Разлика између датотеке није приказан због своје велике величине
+ 398 - 399
project/ewarm/iap/iap.dep


Разлика између датотеке није приказан због своје велике величине
+ 531 - 540
project/ewarm/module_universal_io.dep


+ 3 - 0
project/ewarm/module_universal_io.ewp

@@ -2288,6 +2288,9 @@
             <file>
                 <name>$PROJ_DIR$\..\..\fw\user\at32f403a_407_int.c</name>
             </file>
+            <file>
+                <name>$PROJ_DIR$\..\..\fw\user\flash_ram_const.c</name>
+            </file>
             <file>
                 <name>$PROJ_DIR$\..\..\fw\user\FreeRTOSConfig.h</name>
             </file>

+ 3 - 0
project/ewarm/module_universal_io.ewt

@@ -2499,6 +2499,9 @@
             <file>
                 <name>$PROJ_DIR$\..\..\fw\user\at32f403a_407_int.c</name>
             </file>
+            <file>
+                <name>$PROJ_DIR$\..\..\fw\user\flash_ram_const.c</name>
+            </file>
             <file>
                 <name>$PROJ_DIR$\..\..\fw\user\FreeRTOSConfig.h</name>
             </file>

+ 30 - 16
shared/model/model_cfg.h

@@ -1,16 +1,30 @@
-#ifndef MODEL_CFG_H
-#define MODEL_CFG_H
-
-#include "at32f403a_407.h"
-#include <stdbool.h>
-
-
-#define MODEL_STR           "MDIO-88"
-
-
-#define MODEL_LEN           16
-
-
-
-#endif /* #ifndef MODEL_CFG_H */
-
+#ifndef MODEL_CFG_H
+#define MODEL_CFG_H
+
+#include "at32f403a_407.h"
+#include <stdbool.h>
+
+
+#if defined (MDIO_88)
+#define MODEL_STR           "MDIO-88"
+#define MODEL_CODE          0x0100
+#elif defined (MAO_8)
+#define MODEL_STR           "MAO_8"
+#define MODEL_CODE          0x0200
+#elif defined (MAI_12)
+#define MODEL_STR           "MAI_12"
+#define MODEL_CODE          0x0300
+#else
+#define MODEL_STR           ""
+#define MODEL_CODE          0x0
+#endif
+
+
+static const uint16_t model_code = MODEL_CODE;
+
+#define MODEL_LEN           16
+
+
+
+#endif /* #ifndef MODEL_CFG_H */
+

+ 21 - 20
shared/utils/extended_sram.c

@@ -1,21 +1,22 @@
-#include "at32f403a_407.h"
-#include "extended_sram.h"
-
-
-
-void extend_SRAM(void)
-{
-    // check if RAM has been set to 224K, if not, change EOPB0
-    if(((USD->eopb0)&0xFF)!=0xFE)
-    {
-        // Unlock Option Bytes Program Erase controller
-        flash_unlock();
-        
-        // erase user system data bytes 
-        flash_user_system_data_erase();
-
-        // Change SRAM size to 224KB
-        flash_user_system_data_program((uint32_t)&USD->eopb0, 0xFE);
-        nvic_system_reset();
-    }
+#include "at32f403a_407.h"
+#include "extended_sram.h"
+#include "model_cfg.h"
+
+
+//
+void extend_SRAM(void)
+{
+    // check if RAM has been set to 224K, if not, change EOPB0
+    if(((USD->eopb0)&0xFF)!=0xFE)
+    {
+        // Unlock Option Bytes Program Erase controller
+        flash_unlock();
+        
+        // erase user system data bytes 
+        flash_user_system_data_erase();
+
+        // Change SRAM size to 224KB
+        flash_user_system_data_program((uint32_t)&USD->eopb0, 0xFE);
+        nvic_system_reset();
+    }
 }

+ 39 - 4
tools/io_module.py

@@ -4,13 +4,25 @@ from colorama import Fore
 import time
 import os
 import struct
+import random
+
+models = {0x100: 'MDIO_88', 0x200: 'MAO_8', 0x300: 'MAI_12'}
+
+MODEL_MDIO_88 = 0x0100
+MODEL_MAO_8 = 0x0200
+MODEL_MAI_12 = 0x0300
+
+SYS_TEST_OK = 0x0001
+
+
 
 reg_table = {'in_bits': 0x0100, 'in_cnt': 0x0102, 'in_mode': 0x0120, 'in_norm': 0x0122, 'in_deb_start': 0x124,
              'out_cur': 0x0200, 'out_mode': 0x0202, 'out_mode_save': 0x0203, 'pwm_duty': 0x0210,
              'pwm_duty_save': 0x0220, 'pwm_per': 0x0230, 'pwm_per_save': 0x0240, 
              'rtc_unix': 0x0802, 'rtc_sinhro': 0x0804, 'uptime': 0x0800, 'log_info': 0x0900, 
              'log_ent': 0x0901, 'arch_cap': 0x0902, 'arch_ent': 0x0903,
-             'password': 0x008A}
+             'model': 0x0080, 'prod_time': 0x0081, 'serial': 0x0083, 'fw_ver': 0x0085, 
+             'test_status': 0x0089, 'password': 0x008A}
 
 
 class IO_Module(Modbus):
@@ -216,8 +228,31 @@ class IO_Module(Modbus):
     def set_rtc(self, utc):
         self.write_uint32(reg_table['rtc_sinhro'], utc)
 
-    def set_password(self, password):
-        self.write_holding_register(reg_table['password'], password)
+
+
+def set_system_vars(dev: IO_Module, password: int):
+    # Отправка пароля для разблокирования доступа к системным настройкам
+    dev.write_holding_register(reg_table['password'], password)
+    time.sleep(0.1)
+    # Модель
+    dev.write_holding_register(reg_table['model'], SYS_MODEL_MDIO_88)
+    # Дата производства
+    dev.write_holding_register(reg_table['prod_time'], int(time.time()) - 3600*24)
+    # Серийный номер
+    dev.write_holding_register(reg_table['serial'], random.randint(10000, 1000000))
+
+    # Статус тестирования
+    dev.write_holding_register(reg_table['test_status'], SYS_TEST_OK)
+
+def get_system_vars(dev: IO_Module):
+    # Модель
+    model = dev.read_holding_registers(reg_table['model'], 1)[0]
+    print(type(model))
+    print(models.get(int(model)))
+    print(models[model])
+    
+    
+
 
 def main():
     colorama.init(autoreset=True)
@@ -237,7 +272,7 @@ def main():
     # unix_time = dev.get_rtc()
     # print(f'RTC: {time.ctime(unix_time)}. Unix time stamp:  {unix_time}')
     
-    dev.set_password(1234)
+    get_system_vars(dev)
     
     return
 

Неке датотеке нису приказане због велике количине промена