瀏覽代碼

iap настройки.

TelenkovDmitry 1 年之前
父節點
當前提交
d653c0d6c3

+ 1 - 1
fw/user/main.c

@@ -110,7 +110,7 @@ void init_task(void *argument)
     // Сброс счетчика попыток загрузок
     update_reset_boot_try();
       
-    vTaskDelete(NULL);
+    //vTaskDelete(NULL);
     
     
     for (;;)

+ 415 - 0
iap/modules/modbus/modbus.c

@@ -0,0 +1,415 @@
+#include "at32f403a_407.h"
+#include "common_config.h"
+#include "modbus.h"
+#include "modbus_params.h"
+#include "FreeRTOS.h"
+#include "task.h"
+#include "mb.h"
+#include "mbport.h"
+#include "mbrtu.h"
+#include "tim_delay.h"
+#include "settings_api.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+
+#define REG_HOLDING_START		( 1 )
+#define REG_HOLDING_NREGS		( 5 )
+
+
+
+static USHORT	usRegHoldingStart = REG_HOLDING_START;
+extern UCHAR    rcvAddress;
+
+//osThreadId modbus_task_handle;
+static void modbus_task(void *params);
+//osThreadId modbus_params_handle;
+static void modbus_params(void *params);
+
+//osTimerId reset_timer_handle;
+//osTimerId settings_timer_handle;
+//osTimerId modbus_timer_handle;
+
+mb_delay_action_t mb_action = MB_NO_ACTION;
+uint8_t new_slave_addr;
+bool mb_package_flag = false;
+
+
+
+//
+void mb_init(void)
+{
+    uint32_t baud = 115200;
+    eMBParity par = MB_PAR_NONE;
+    UCHAR mb_addr = 1;
+    unsigned int stop_bits = 1;
+	const UCHAR ucSlaveID[] = {0xAA, 0xBB, 0xCC};
+    
+	mb_init_params();
+
+    settings_set_modbus_params(settings.com_settings.mb_port);
+    
+    mb_helper_tim_init(baud);
+    eMBInit(MB_RTU, mb_addr, 4, baud, par, stop_bits);
+	eMBSetSlaveID(0x34, TRUE, ucSlaveID, 3);
+	eMBEnable();
+    
+    
+    xTaskCreate(modbus_task, "modbus_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
+    
+    xTaskCreate(modbus_params, "modbus_params", 4*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
+    
+    
+#if 0    
+	osTimerDef(vResetTimer, modbus_reset);
+	reset_timer_handle = osTimerCreate(osTimer(vResetTimer), osTimerOnce, NULL);
+    
+    osTimerDef(vSettingsTimer, settings_timer);
+    settings_timer_handle = osTimerCreate(osTimer(vSettingsTimer), osTimerOnce, NULL);
+    
+    osTimerDef(vModbusTimer, modbus_port_timer);
+    modbus_timer_handle = osTimerCreate(osTimer(vModbusTimer), osTimerOnce, NULL);
+#endif    
+}
+
+//
+void modbus_task(void *params)
+{
+	(void)params;
+
+	for (;;)
+	{
+		eMBPoll();
+	}
+
+}
+
+//
+void modbus_params(void *params)
+{
+    for (;;)
+    {
+        if (mb_action != MB_NO_ACTION)
+        {
+            switch (mb_action)
+            {
+                // Установка нового адреса
+                case MB_CHANGE_ADDR :
+    
+                    //settings.com_settings.mb_addr = new_slave_addr;  
+                    eMBSetSlaveAddr(new_slave_addr);
+                      
+                break;
+                
+                case MB_CHANGE_PORT_SETTINGS :
+#if 0                  
+                    osDelay(200);
+                    eMBRTUStop();
+                    settings_set_modbus_params(temp_modbus_port);
+                    settings_init_mb_port(settings.com_settings.mb_addr);
+                    MBDBG settings_print_modbus();
+                    eMBRTUStart();
+                    eMBEnable();
+                    mb_package_flag = false;
+                    osTimerStart(modbus_timer_handle, 9800);
+#endif                  
+                break;
+                
+                // Полное восстановление дефолтных настроек
+                case MB_DEF_SETTINGS :
+#if 0
+                    settings_set_default(true);
+                    settings_save();
+#endif                  
+                break;  
+                
+                // Частичное восстановление дефолтных настроек
+                case MB_PART_DEF_SETTINGS :
+#if 0
+                    settings_set_default(false);
+                    settings_save();
+#endif                  
+                break;
+                
+                  
+                case MB_SAVE_SETTINGS :
+#if 0                
+                    settings_save();
+#endif                  
+                break;
+                
+                case MB_SAVE_SYS_SETTINGS :
+#if 0
+                    if (set_sys_settings_flag) {
+                        memcpy(&sys_settings, &temp_sys_settings, sizeof(sys_settings));
+                        sys_settings_save();
+                    }
+#endif                  
+                break;
+                
+                case MB_RESET :
+                  
+                    vTaskDelay(100);
+                    NVIC_SystemReset();
+                  
+                break;
+                
+                default : break;
+            }
+            
+            mb_action = MB_NO_ACTION;
+        }
+        vTaskDelay(10);
+    }
+}
+
+
+// Отложенная перезагрузка в Bootloader
+void modbus_reset(void const * params)
+{
+#if 0  
+	MBDBG printf("Switch to bootloader!\r\n");
+	rtc_set_load_mode(1);
+	HAL_NVIC_SystemReset();
+#endif    
+}
+
+
+// Запуск таймера на изменение системных настроек
+void settings_timer(void const * params)
+{
+#if 0  
+    set_sys_settings_flag = false;
+    psw_ok = false;
+#endif    
+}
+
+
+// Запуск таймера для изменение настроек modbus
+void modbus_port_timer(void const * params)
+{
+#if 0
+    eMBRTUStop();
+  
+    // Были транзакции по modbus с новыми настройками. 
+    // Нужно сохранить новые настройки.
+    if (mb_package_flag)
+    {
+        settings.com_settings.mb_port = temp_modbus_port;
+        settings_set_modbus_params(settings.com_settings.mb_port);
+        settings_init_mb_port(settings.com_settings.mb_addr);
+        settings_save();
+        
+    }
+    // Нужно вернуть старые настройки
+    else
+    {
+        temp_modbus_port = settings.com_settings.mb_port;
+        settings_set_modbus_params(settings.com_settings.mb_port);
+        settings_init_mb_port(settings.com_settings.mb_addr);
+    }
+  
+    
+    MBDBG settings_print_modbus();
+    eMBRTUStart();
+    eMBEnable();
+#endif    
+}
+
+// ------------------------------------------------------------------- //
+//						Modbus callback's
+// ------------------------------------------------------------------- //
+
+//
+// 65 (0x41) Read Input Registers	 
+eMBErrorCode
+eMBUpdateCB( UCHAR * pucFrame, USHORT * usLen)
+{
+	eMBErrorCode    eStatus = MB_ENOERR;
+
+    mb_package_flag = true;
+    
+    return eStatus;
+}
+
+eMBErrorCode
+eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
+{
+	return MB_ENOREG;
+}
+
+
+// 03 (0x03) Read Holding Registers
+// чтение N регистров управления и уставок
+// 16 (0x10) Write Multiple registers
+// запись N регистров управления и уставок (0x10)
+eMBErrorCode
+eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegisterMode eMode )
+{
+	eMBErrorCode eStatus = MB_ENOERR;
+
+	int			 iRegIndex;
+    
+    mb_delay_action_t mb_act = MB_NO_ACTION;
+	uint16_t regs_cnt = usNRegs;
+	uint16_t index_param;
+	uint8_t *ptr_buf = pucRegBuffer;
+	uint16_t size;
+#if 0
+	printf("usAddress: 0x%X\r\n", usAddress);
+	printf("usNRegs: %u\r\n", usNRegs);
+	printf("eMode: %u\r\n", eMode);
+    printf("pucRegBuffer :%X\r\n", pucRegBuffer[0]);
+#endif
+    mb_package_flag = true;
+    
+	iRegIndex = (int)(usAddress - usRegHoldingStart);
+
+#if 1    
+	switch (eMode)
+	{
+		case MB_REG_READ :
+
+			while (regs_cnt)
+			{
+				// Поиск регистра
+				if (!mb_find_param(iRegIndex, &index_param, &size))
+				{
+					return MB_ENOREG; // нет запрашиваемого регистра
+				}
+				else
+				{
+					MBDBG printf("reg: %X, index: %u, size: %u\r\n", iRegIndex, index_param, size);
+                    MBDBG printf("reg: %X\r\n", iRegIndex);
+					mb_get_param(ptr_buf,  index_param); // Вызов функции записи
+					iRegIndex += size;
+					ptr_buf += 2*size;
+					regs_cnt -= size;
+				}
+			}
+
+
+		break;
+
+		case MB_REG_WRITE :
+
+			while (regs_cnt)
+			{
+				// Поиск регистра
+				if (!mb_find_param(iRegIndex, &index_param, &size))
+				{
+					return MB_ENOREG; // нет запрашиваемого регистра
+				}
+				else
+				{
+					MBDBG printf("reg: %X, index: %u, size: %u\r\n", iRegIndex, index_param, size);
+					mb_act = mb_set_param(ptr_buf, index_param); // Вызов функции записи
+
+                    if (mb_act != MB_NO_ACTION)
+                        mb_action = mb_act;
+                    
+					iRegIndex += size;
+					ptr_buf += 2*size;
+					regs_cnt -= size;
+                    
+                    if (mb_act == MB_PAS_ERR)
+                        return MB_EINVAL;
+				}
+			}
+
+		break;
+	}
+#endif
+	return eStatus;
+}
+
+// 17 (0x11) Report Slave ID (Serial Line only) 
+// чтение информации об устройстве (0x11)
+eMBException
+eMBFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen )
+{
+#if 0
+    mb_package_flag = true;
+    
+	*usLen = mb_get_info(&pucFrame[1]) + 3;
+#endif
+	return MB_EX_NONE;
+}
+
+
+// чтение/запись значений из нескольких регистров флагов (Coil Status).
+// чтения N регистров параметров
+eMBErrorCode
+eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNCoils, eMBRegisterMode eMode )
+{
+    return MB_ENOREG;
+}
+
+eMBErrorCode
+eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete )
+{
+    return MB_ENOREG;
+}
+
+
+// 0x42
+// Запрос на изменение адреса
+// Если запрос широковещательный, то нужно проверить присланный ID.
+eMBException    
+eMBSetAddrIdCB( UCHAR * pucFrame, USHORT * usLen )
+{
+#if 0  
+    mb_package_flag = true;
+    
+    if (rcvAddress == MB_ADDRESS_BROADCAST)
+    {
+        if (mb_set_addr_id(&pucFrame[1], &new_slave_addr))
+            mb_action = MB_CHANGE_ADDR;
+    }
+    // Адресный запрос. ID не проверяем
+    else
+    {
+        if (mb_set_addr(&pucFrame[1], &new_slave_addr))
+        {
+            pucFrame[1] = new_slave_addr;
+            mb_action = MB_CHANGE_ADDR;
+        }
+        else 
+            pucFrame[1] = MB_BOOT_ERR_WRONG_CONTENT;
+    }
+    
+    *usLen = 2;
+#endif    
+    return MB_EX_NONE;
+}
+
+
+// 0x43
+eMBException
+eMBSetAddrSerialCB( UCHAR * pucFrame, USHORT * usLen )
+{
+#if 0  
+    mb_package_flag = true;
+      
+    if (rcvAddress == MB_ADDRESS_BROADCAST)
+    {
+        if (mb_set_addr_serial(&pucFrame[1], &new_slave_addr))
+            mb_action = MB_CHANGE_ADDR;
+    }
+    // Адресный запрос. ID не проверяем
+    else
+    {
+        if (mb_set_addr(&pucFrame[1], &new_slave_addr))
+        {
+            pucFrame[1] = new_slave_addr;
+            mb_action = MB_CHANGE_ADDR;
+        }
+        else 
+            pucFrame[1] = MB_BOOT_ERR_WRONG_CONTENT;
+    }
+    
+    *usLen = 2;
+#endif    
+    return MB_EX_NONE;
+}
+

+ 46 - 0
iap/modules/modbus/modbus.h

@@ -0,0 +1,46 @@
+#ifndef __MODBUS_H
+#define __MODBUS_H
+
+
+//#define MB__DEBUG
+
+#ifdef MB__DEBUG
+#define MBDBG
+#else
+#define MBDBG if (0)
+#endif
+
+
+//
+typedef enum 
+{
+    MB_NO_ACTION = 0,
+    MB_CHANGE_ADDR,
+    MB_CHANGE_PORT_SETTINGS,
+    MB_DEF_SETTINGS,
+    MB_PART_DEF_SETTINGS,
+    MB_SAVE_SETTINGS,
+    MB_SAVE_SYS_SETTINGS,
+    MB_CHANGE_PWM_FREQ_1,
+    MB_CHANGE_PWM_FREQ_2,
+    MB_CHANGE_PWM_FREQ_3,
+    MB_RESET,
+    MB_PAS_OK,
+    MB_PAS_ERR
+  
+} mb_delay_action_t ;
+
+
+//
+void mb_init(void);
+
+//
+void modbus_reset(void const * params);
+
+//
+void settings_timer(void const * params);
+
+//
+void modbus_port_timer(void const * params);
+
+#endif // __MODBUS_H

+ 99 - 0
iap/modules/modbus/modbus_params.c

@@ -0,0 +1,99 @@
+#include "at32f403a_407.h"
+#include "modbus_params.h"
+#include <string.h>
+
+
+mb_param_t mb_param[MB_PARAM_MAX];
+
+
+//
+void mb_init_params(void)
+{   
+    uint16_t foo = 12345;
+  
+    mb_param[0].reg = 0x0100;
+	mb_param[0].size = 1;
+	mb_param[0].param = (uint8_t*)&foo;  
+	mb_param[0].set_handler = NULL;
+    mb_param[0].check_handler = mb_check_dummy;
+}
+
+
+// Возвращает размер параметра в регистрах
+bool mb_find_param(uint16_t reg, uint16_t *index, uint16_t *size)
+{
+	for (uint16_t i = 0; i < MB_PARAM_MAX; i++)
+	{
+		if (mb_param[i].reg == reg)
+		{
+			*index = i;
+			*size = mb_param[i].size;
+			return true;
+		}
+	}
+	return false;
+}
+
+
+//
+mb_delay_action_t mb_set_param(uint8_t *buf, uint16_t index)
+{
+	uint8_t *ptr = mb_param[index].param;
+
+    // Если параметр только для чтения
+    if (mb_param[index].check_handler == NULL)
+        return MB_NO_ACTION;
+    
+	for (uint16_t i = 0; i < 2*mb_param[index].size; i++)
+	{
+		*ptr = buf[2*mb_param[index].size - 1 - i];
+		ptr++;
+	}
+  
+/*    
+    if (mb_param[index].check_handler != NULL)
+        mb_param[index].check_handler();
+*/    
+    
+    mb_param[index].check_handler();
+    
+    if (mb_param[index].set_handler != NULL)
+        return mb_param[index].set_handler();
+    else
+        return MB_NO_ACTION;
+    
+/*    
+    if (mb_param[index].f_activity)
+        return mb_param[index].set_handler();
+    else
+        return MB_NO_ACTION;
+*/    
+}
+
+
+//
+void mb_get_param(uint8_t *buf, uint16_t index)
+{
+	uint8_t *ptr = mb_param[index].param + 2*mb_param[index].size - 1;
+
+	for (uint16_t i = 0; i < 2*mb_param[index].size; i++)
+	{
+		*buf = *ptr;
+		buf++;
+		ptr--;
+	}
+
+}
+
+
+// -------------------------------------------------------------------------- //
+//                      Проверка параметров                                   //
+// -------------------------------------------------------------------------- //
+
+//
+void mb_check_dummy(void)
+{
+}
+
+
+

+ 49 - 0
iap/modules/modbus/modbus_params.h

@@ -0,0 +1,49 @@
+#ifndef __MODBUS_PARAMS_H
+#define __MODBUS_PARAMS_H
+
+#include "mb.h"
+#include "mbport.h"
+#include "modbus.h"
+
+#include <stdbool.h>
+
+
+#define MB_PARAM_MAX			1
+
+
+//
+typedef struct {
+
+	uint16_t reg;
+	uint16_t size;
+	uint8_t *param;
+	bool f_activity;	
+	mb_delay_action_t (*set_handler)(void);
+    void (*check_handler)(void);
+
+} mb_param_t;
+
+
+//
+void mb_init_params(void);
+
+// Возвращает размер параметра в регистрах
+bool mb_find_param(uint16_t reg, uint16_t *index, uint16_t *size);
+
+//
+mb_delay_action_t mb_set_param(uint8_t *buf, uint16_t index);
+
+//
+void mb_get_param(uint8_t *buf, uint16_t index);
+
+
+// -------------------------------------------------------------------------- //
+//                      Проверка параметров                                   //
+// -------------------------------------------------------------------------- //
+
+//
+void mb_check_dummy(void);
+
+
+
+#endif // __MODBUS_PARAMS_H

+ 291 - 0
iap/modules/settings/settings_api.c

@@ -0,0 +1,291 @@
+#include "at32f403a_407.h" 
+#include "settings_api.h"
+#include "sys_api.h"
+#include "FreeRTOS.h"
+#include "task.h"
+#include "queue.h"
+#include "semphr.h"
+#include "common_config.h"
+#include "common.h"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+SemaphoreHandle_t flash_mutex;
+
+  
+// Системные настройки
+sys_settings_t sys_settings;
+
+// Общая структура настроек
+settings_t settings;
+
+modbus_t mb_port_settings;
+
+
+//
+void init_settings(void)
+{
+    flash_mutex = xSemaphoreCreateMutex();
+}
+
+// Загрузка структуры настроек из flesh
+void settings_load(settings_t *settings)
+{
+    uint32_t loadCRC;  // CRC из flash
+    uint32_t newCRC;   // CRC загруженной структуры настроек
+    bool need_default = false;
+    
+    settings_read_from_flash((uint8_t*)settings, sizeof(settings_t));
+    
+    // Считываем CRC из флеш памяти
+    loadCRC = (*(uint32_t*)CRC_ADDRESS);
+    
+    // Рассчитываем CRC для структуры настроек
+    newCRC = settings_get_crc(settings);
+
+    // Если CRC не совпадают нужно прошивать дефолтные настройки
+    if (loadCRC != newCRC) {
+        need_default = true;
+    }
+    
+    // Прошиваем дефолтные настройки если нужно
+    if (need_default) 
+    {
+        settings_set_all_default();
+        settings_save(settings);
+    }
+}
+
+//
+void settings_read_from_flash(uint8_t *data, uint32_t size)
+{
+    uint32_t baseAddress = SETTINGS_SECTOR;
+        
+    for (uint32_t i = 0; i < size; i++)
+        *data++ = (*(uint32_t*)baseAddress++);;
+}
+
+//
+uint32_t settings_get_crc(settings_t *settings)
+{
+    crc_data_reset();
+    return crc_block_calculate((uint32_t*)settings, sizeof(settings_t)/4 - 1);
+}
+
+//
+uint32_t settings_get_crit_sec_crc(settings_t *settings)
+{
+    crc_data_reset();
+    uint32_t critsec_len = (uint32_t)((uint8_t *)(&settings->critical_section_crc) - (uint8_t *)settings) / 4;
+    return crc_block_calculate((uint32_t *)settings, critsec_len);
+}
+
+// Сброс всех настроек в значения по умолчанию
+void settings_set_all_default(void)
+{
+    settings_set_modbus_def(&settings.com_settings.mb_port);
+    settings.critical_section_crc = settings_get_crit_sec_crc(&settings);
+}
+
+// -------------------------------------------------------------------------- //
+// Настройки по умолчанию
+
+//
+void settings_set_modbus_def(uint16_t *mb_port)
+{
+    modbus_t mb_settings;
+    
+    mb_settings.baud = BRD_115200;
+	mb_settings.parity = NO_PAR;
+	mb_settings.databits = DATABITS_8;
+	mb_settings.stopbits = STOP_1;
+    
+    settings_conv_modbus_def(&mb_settings, mb_port);
+}
+
+//
+void settings_conv_modbus_def(modbus_t *mb_settings, uint16_t *mb_port)
+{
+	uint16_t param = 0;
+
+	// Количестро стоп бит (0-1 биты)
+	if (mb_settings->stopbits == STOP_1)
+		param = 0x00;
+	else if (mb_settings->stopbits == STOP_2)
+		param = 0x02; 		
+
+	// Длина слова (2ой бит)
+	param |= 0x00 << 2;
+
+	// Контроль четности (3-4 биты)
+	if (mb_settings->parity == NO_PAR)
+		param |= 0x00 << 3;
+	else if (mb_settings->parity == EVEN_PAR)
+		param |= 0x02 << 3;
+	else if (mb_settings->parity == ODD_PAR)
+		param |= 0x03 << 3;
+
+	// Скорость (5 - 7 биты)
+	switch (mb_settings->baud)
+	{
+		case BRD_2400 :
+			param |= 0x00 << 5;
+		break;
+
+		case BRD_4800 :
+			param |= 0x01 << 5;
+		break;
+
+		case BRD_9600 :
+			param |= 0x02 << 5;
+		break;
+
+		case BRD_19200 :
+			param |= 0x03 << 5;
+		break;
+
+		case BRD_38400 :
+			param |= 0x04 << 5;
+		break;
+
+		case BRD_57600 :
+			param |= 0x05 << 5;
+		break;
+
+		case BRD_115200 :
+			param |= 0x06 << 5;
+		break;
+
+		default : break;
+	}
+
+	*mb_port = param;
+}
+
+// Установка параметров Modbus
+void settings_set_modbus_params(uint16_t mb_port)
+{
+	uint16_t param = 0;
+
+	// Количестро стоп бит (0-1 биты)
+	param = 0x0003 & mb_port; 
+
+	if (param == 0x00)
+		mb_port_settings.stopbits = STOP_1;
+	else if (param == 0x02)
+		mb_port_settings.stopbits = STOP_2;
+
+	// Длина слова (2ой бит)
+	param = (0x0004 & mb_port) >> 2;
+
+	mb_port_settings.databits = DATABITS_8;
+	
+	// Контроль четности (3-4 биты)
+	param = (0x0018 & mb_port) >> 3; 
+
+	if (param == 0x00)
+		mb_port_settings.parity = NO_PAR;
+	else if (param == 0x02)
+		mb_port_settings.parity = EVEN_PAR;
+	else if (param == 0x03)
+		mb_port_settings.parity = ODD_PAR;
+
+	// Скорость (5 - 7 биты)
+	param = (0x00E0 & mb_port) >> 5; 
+
+	switch (param)
+	{
+		case 0x00 :
+			mb_port_settings.baud = BRD_2400;
+		break;
+
+		case 0x01 :
+			mb_port_settings.baud = BRD_4800;
+		break;
+
+		case 0x02 :
+			mb_port_settings.baud = BRD_9600;
+		break;
+
+		case 0x03 :
+			mb_port_settings.baud = BRD_19200;
+		break;
+
+		case 0x04 :
+			mb_port_settings.baud = BRD_38400;
+		break;
+
+		case 0x05 :
+			mb_port_settings.baud = BRD_57600;
+		break;
+
+		case 0x06 :
+			mb_port_settings.baud = BRD_115200;
+		break;
+
+		default : break;
+	}
+}
+
+// -------------------------------------------------------------------------- //
+
+// Запись структуры настроек во flash
+void settings_save(settings_t *settings)
+{
+    xSemaphoreTake(flash_mutex, portMAX_DELAY);
+    
+    settings->critical_section_crc = settings_get_crit_sec_crc(settings);
+    
+    settings_write_to_flash((uint8_t*)settings, sizeof(settings_t));
+    xSemaphoreGive(flash_mutex);
+}
+
+//
+void settings_write_to_flash(uint8_t *data, uint32_t size)
+{
+    uint32_t baseAddress = SETTINGS_SECTOR;
+    uint32_t checkCrc = 0;
+    uint32_t crc = settings_get_crc((settings_t*)data);
+    flash_status_type status;
+    uint8_t *ptr = data;
+    
+    for (uint8_t i = 0; i < 3; i++)
+    {	
+        flash_unlock();
+    
+        settings_erase_flash_sector();
+
+        for (uint32_t i = 0; i < size; i++)
+            if ((status = flash_byte_program(baseAddress++, *data++)) != FLASH_OPERATE_DONE) {
+                DBG printf("FLASH_ProgramByte error: status = %d\r\n", status);
+                break;
+            }
+    
+        if ((status = flash_word_program((uint32_t)CRC_ADDRESS, crc)) != FLASH_OPERATE_DONE) {
+            DBG printf("FLASH_ProgramWord error: status = %d\r\n", status);
+        }
+    
+        flash_lock();
+    
+        /* Считываем что записали */
+        settings_read_from_flash(ptr, sizeof(settings_t));
+    
+        checkCrc = settings_get_crc((settings_t*)ptr);
+    
+        /* Проверяем  CRC того что было записано */
+        if (checkCrc == crc)
+            break;
+    }
+}
+
+// Очистка сектора настроек
+void settings_erase_flash_sector(void)
+{
+    flash_status_type status;
+
+    if ((status = flash_sector_erase(SETTINGS_SECTOR)) != FLASH_OPERATE_DONE) {
+        DBG printf("SETTINGS_EraseFlashSector error: status = %d/r/n", status);
+    }
+}

+ 101 - 0
iap/modules/settings/settings_api.h

@@ -0,0 +1,101 @@
+#ifndef SETTINGS_API_H
+#define SETTINGS_API_H
+
+#include "at32f403a_407.h"
+#include <stdbool.h>
+#include "usart.h"
+#include "sys_api.h"
+
+
+
+
+// ------------------------------------------------------------------- //
+//					 		Modbus
+// ------------------------------------------------------------------- //
+
+// Modbus 
+typedef struct
+{
+	rate_t     baud;		// Скорость порта 
+	parity_t   parity;		// Четность 
+	databits_t databits;	// Число бит данных
+	stopbits_t stopbits;	// Число стоп-бит  
+
+} modbus_t;
+
+
+// Общая структура настроек для IAP и FW
+typedef struct
+{
+    uint16_t    mb_port;    // Настройки порта для modbus
+    
+} com_settings_t;
+
+
+
+// Полная структура настроек
+typedef struct
+{
+    com_settings_t  com_settings;
+    uint32_t        critical_section_crc;
+    
+} settings_t;
+
+
+
+// Загрузка структуры настроек из flesh
+void settings_load(settings_t *settings);
+
+//
+void init_settings(void);
+
+//
+void settings_read_from_flash(uint8_t *data, uint32_t size);
+
+//
+uint32_t settings_get_crc(settings_t *settings);
+
+//
+uint32_t settings_get_crit_sec_crc(settings_t *settings);
+
+// Сброс всех настроек в значения по умолчанию
+void settings_set_all_default(void);
+
+
+// -------------------------------------------------------------------------- //
+// Настройки по умолчанию
+
+//
+void settings_set_modbus_def(uint16_t *mb_port);
+
+//
+void settings_conv_modbus_def(modbus_t *mb_settings, uint16_t *mb_port);
+
+// Установка параметров Modbus
+void settings_set_modbus_params(uint16_t mb_port);
+
+// -------------------------------------------------------------------------- //
+
+// Запись структуры настроек во flash
+void settings_save(settings_t *settings);
+
+//
+void settings_write_to_flash(uint8_t *data, uint32_t size);
+
+// Очистка сектора настроек
+void settings_erase_flash_sector(void);
+
+
+
+
+// Системные настройки
+extern sys_settings_t sys_settings;
+
+//
+extern settings_t settings;
+
+//
+extern modbus_t mb_port_settings;
+
+#endif /* #ifndef SETTINGS_API_H */
+

+ 174 - 0
iap/user/FreeRTOSConfig.h

@@ -0,0 +1,174 @@
+/*
+    FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.
+    All rights reserved
+
+    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
+
+    This file is part of the FreeRTOS distribution.
+
+    FreeRTOS is free software; you can redistribute it and/or modify it under
+    the terms of the GNU General Public License (version 2) as published by the
+    Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
+
+	***************************************************************************
+    >>!   NOTE: The modification to the GPL is included to allow you to     !<<
+    >>!   distribute a combined work that includes FreeRTOS without being   !<<
+    >>!   obliged to provide the source code for proprietary components     !<<
+    >>!   outside of the FreeRTOS kernel.                                   !<<
+	***************************************************************************
+
+    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
+    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+    FOR A PARTICULAR PURPOSE.  Full license text is available on the following
+    link: http://www.freertos.org/a00114.html
+
+    ***************************************************************************
+     *                                                                       *
+     *    FreeRTOS provides completely free yet professionally developed,    *
+     *    robust, strictly quality controlled, supported, and cross          *
+     *    platform software that is more than just the market leader, it     *
+     *    is the industry's de facto standard.                               *
+     *                                                                       *
+     *    Help yourself get started quickly while simultaneously helping     *
+     *    to support the FreeRTOS project by purchasing a FreeRTOS           *
+     *    tutorial book, reference manual, or both:                          *
+     *    http://www.FreeRTOS.org/Documentation                              *
+     *                                                                       *
+    ***************************************************************************
+
+    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
+	the FAQ page "My application does not run, what could be wrong?".  Have you
+	defined configASSERT()?
+
+	http://www.FreeRTOS.org/support - In return for receiving this top quality
+	embedded software for free we request you assist our global community by
+	participating in the support forum.
+
+	http://www.FreeRTOS.org/training - Investing in training allows your team to
+	be as productive as possible as early as possible.  Now you can receive
+	FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
+	Ltd, and the world's leading authority on the world's leading RTOS.
+
+    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
+    including FreeRTOS+Trace - an indispensable productivity tool, a DOS
+    compatible FAT file system, and our tiny thread aware UDP/IP stack.
+
+    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
+    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
+
+    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
+    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
+    licenses offer ticketed support, indemnification and commercial middleware.
+
+    http://www.SafeRTOS.com - High Integrity Systems also provide a safety
+    engineered and independently SIL3 certified version for use in safety and
+    mission critical applications that require provable dependability.
+
+    1 tab == 4 spaces!
+*/
+
+
+#ifndef FREERTOS_CONFIG_H
+#define FREERTOS_CONFIG_H
+
+/*-----------------------------------------------------------
+ * Application specific definitions.
+ *
+ * These definitions should be adjusted for your particular hardware and
+ * application requirements.
+ *
+ * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
+ * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
+ *
+ * See http://www.freertos.org/a00110.html.
+ *----------------------------------------------------------*/
+
+/* Use a guard to ensure the following few definitions are'nt included in
+assembly files that include this header file. */
+#ifndef __IASMARM__
+	#include <stdint.h>
+	extern unsigned int system_core_clock;
+//    extern volatile unsigned long ulHighFrequencyTimerTicks;
+#endif
+
+#define configENABLE_BACKWARD_COMPATIBILITY 1
+
+#define configUSE_PREEMPTION			1
+#define configUSE_IDLE_HOOK				0
+#define configUSE_TICK_HOOK				0
+#define configCPU_CLOCK_HZ				( system_core_clock )
+#define configTICK_RATE_HZ				( ( TickType_t ) 1000 )
+#define configMAX_PRIORITIES			( 5 )
+#define configMINIMAL_STACK_SIZE		( ( unsigned short ) 128 )
+#define configTOTAL_HEAP_SIZE			( ( size_t ) ( 64 * 1024 ) )
+#define configMAX_TASK_NAME_LEN			( 16 )
+#define configUSE_TRACE_FACILITY		1
+#define configUSE_16_BIT_TICKS			0
+#define configIDLE_SHOULD_YIELD			1
+#define configUSE_MUTEXES				1
+#define configQUEUE_REGISTRY_SIZE		8
+#define configGENERATE_RUN_TIME_STATS	0
+#define configCHECK_FOR_STACK_OVERFLOW	2
+#define configUSE_RECURSIVE_MUTEXES		1
+#define configUSE_MALLOC_FAILED_HOOK	1
+#define configUSE_APPLICATION_TASK_TAG	0
+#define configUSE_COUNTING_SEMAPHORES	1
+#define configUSE_STATS_FORMATTING_FUNCTIONS	1
+#define configAPPLICATION_ALLOCATED_HEAP        0
+    
+//#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() ( ulHighFrequencyTimerTicks = 0UL )
+//#define portGET_RUN_TIME_COUNTER_VALUE()         ulHighFrequencyTimerTicks    
+
+/* Co-routine definitions. */
+#define configUSE_CO_ROUTINES 		0
+#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
+
+/* Software timer definitions. */
+#define configUSE_TIMERS				1
+#define configTIMER_TASK_PRIORITY		( 2 )
+#define configTIMER_QUEUE_LENGTH		10
+#define configTIMER_TASK_STACK_DEPTH	( configMINIMAL_STACK_SIZE * 2 )
+
+/* Set the following definitions to 1 to include the API function, or zero
+to exclude the API function. */
+#define INCLUDE_vTaskPrioritySet		1
+#define INCLUDE_uxTaskPriorityGet		1
+#define INCLUDE_vTaskDelete				1
+#define INCLUDE_vTaskCleanUpResources	1
+#define INCLUDE_vTaskSuspend			1
+#define INCLUDE_vTaskDelayUntil			1
+#define INCLUDE_vTaskDelay				1
+
+/* Use the system definition, if there is one */
+#ifdef __NVIC_PRIO_BITS
+	#define configPRIO_BITS       		__NVIC_PRIO_BITS
+#else
+	#define configPRIO_BITS       		4        /* 15 priority levels */
+#endif
+
+#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY			0xf
+#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY	5
+
+/* The lowest priority. */
+#define configKERNEL_INTERRUPT_PRIORITY 	( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
+/* Priority 5, or 160 as only the top three bits are implemented. */
+/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
+See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
+#define configMAX_SYSCALL_INTERRUPT_PRIORITY 	( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
+	
+#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }	
+	
+#define vPortSVCHandler SVC_Handler
+#define xPortPendSVHandler PendSV_Handler
+#define vPortSVCHandler SVC_Handler
+#define xPortSysTickHandler SysTick_Handler
+
+/* Dimensions a buffer that can be used by the FreeRTOS+CLI command
+interpreter.  Set this value to 1 to save RAM if FreeRTOS+CLI does not supply
+the output butter.  See the FreeRTOS+CLI documentation for more information:
+http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_CLI/ */
+#define configCOMMAND_INT_MAX_OUTPUT_SIZE			3*1024
+
+#endif /* FREERTOS_CONFIG_H */
+
+  

+ 75 - 0
iap/user/at32f403a_407_int.c

@@ -0,0 +1,75 @@
+#include "at32f403a_407_int.h"
+
+
+/**
+  * @brief  this function handles nmi exception.
+  * @param  none
+  * @retval none
+  */
+void NMI_Handler(void)
+{
+}
+
+/**
+  * @brief  this function handles hard fault exception.
+  * @param  none
+  * @retval none
+  */
+void HardFault_Handler(void)
+{
+  /* go to infinite loop when hard fault exception occurs */
+  while(1)
+  {
+  }
+}
+
+/**
+  * @brief  this function handles memory manage exception.
+  * @param  none
+  * @retval none
+  */
+void MemManage_Handler(void)
+{
+  /* go to infinite loop when memory manage exception occurs */
+  while(1)
+  {
+  }
+}
+
+/**
+  * @brief  this function handles bus fault exception.
+  * @param  none
+  * @retval none
+  */
+void BusFault_Handler(void)
+{
+  /* go to infinite loop when bus fault exception occurs */
+  while(1)
+  {
+  }
+}
+
+/**
+  * @brief  this function handles usage fault exception.
+  * @param  none
+  * @retval none
+  */
+void UsageFault_Handler(void)
+{
+  /* go to infinite loop when usage fault exception occurs */
+  while(1)
+  {
+  }
+}
+
+
+/**
+  * @brief  this function handles debug monitor exception.
+  * @param  none
+  * @retval none
+  */
+void DebugMon_Handler(void)
+{
+}
+
+

+ 56 - 0
iap/user/at32f403a_407_int.h

@@ -0,0 +1,56 @@
+/**
+  **************************************************************************
+  * @file     at32f403a_407_int.h
+  * @brief    header file of main interrupt service routines.
+  **************************************************************************
+  *                       Copyright notice & Disclaimer
+  *
+  * The software Board Support Package (BSP) that is made available to
+  * download from Artery official website is the copyrighted work of Artery.
+  * Artery authorizes customers to use, copy, and distribute the BSP
+  * software and its related documentation for the purpose of design and
+  * development in conjunction with Artery microcontrollers. Use of the
+  * software is governed by this copyright notice and the following disclaimer.
+  *
+  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+  *
+  **************************************************************************
+  */
+
+/* define to prevent recursive inclusion -------------------------------------*/
+#ifndef __AT32F403A_407_INT_H
+#define __AT32F403A_407_INT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* includes ------------------------------------------------------------------*/
+#include "at32f403a_407.h"
+
+/* exported types ------------------------------------------------------------*/
+/* exported constants --------------------------------------------------------*/
+/* exported macro ------------------------------------------------------------*/
+/* exported functions ------------------------------------------------------- */
+
+void NMI_Handler(void);
+void HardFault_Handler(void);
+void MemManage_Handler(void);
+void BusFault_Handler(void);
+void UsageFault_Handler(void);
+void SVC_Handler(void);
+void DebugMon_Handler(void);
+void PendSV_Handler(void);
+void SysTick_Handler(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+

+ 50 - 23
iap/user/main.c

@@ -1,27 +1,8 @@
-#include "at32f403a_407.h"
-#include "at32f403a_407_board.h"
-#include "at32f403a_407_clock.h"
-#include "common_config.h"
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-#include "usb_eth.h"
-#include "mux.h"
-#include "misc.h"
-#include "spi_common.h"
-#include "extended_sram.h"
-#include "modbus.h"
-#include "common_gpio.h"
-#include "io.h"
-#include "input.h"
-#include "wdt.h"
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
+#include "main.h"
 
 
-// 
+void soft_wdt(void *params);
+void init_task(void *params);
 bool jump_to_app(uint32_t address);
 void (*pftarget)(void);
 
@@ -91,13 +72,28 @@ int main()
     
         
     DBG printf("IAP starting...\r\n");
-        
+
+#if 0    
+    // -------------------------------------------------------------------------
     // Для теста. Сброс.
     DBG printf("For test reset load_mode flag and jump to FW\r\n");
     bpr_data_write(BPR_DATA1, 0);
     jump_to_app(0x08021000); 
+#endif
+    
+    //
+    cm_gpio_init();
+
+    taskENTER_CRITICAL();      
+    
+    xTaskCreate(soft_wdt, "soft_wdt", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);    
     
+    xTaskCreate(init_task, "init_task", 10*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
     
+    taskEXIT_CRITICAL();
+    
+    vTaskStartScheduler();
+
     while (1) {}
 }
 
@@ -118,3 +114,34 @@ bool jump_to_app(uint32_t address)
     return false;
 }
 
+
+//
+void soft_wdt(void *params)
+{
+    (void)params;
+    
+    for (;;)
+    {
+        extern_wdt_togle(); // extern WDT
+        vTaskDelay(500);
+    }
+}
+
+//
+void init_task(void *params)
+{
+    (void)params;
+    
+    crm_periph_clock_enable(CRM_CRC_PERIPH_CLOCK, TRUE);
+    
+    init_settings();
+    settings_load(&settings);    
+    
+    mb_init();
+    
+    for (;;)
+    {
+      
+        vTaskDelay(500);
+    }
+}

+ 23 - 0
iap/user/main.h

@@ -0,0 +1,23 @@
+#ifndef __MAIN_H
+#define __MAIN_H
+
+#include "at32f403a_407.h"
+#include "at32f403a_407_board.h"
+#include "at32f403a_407_clock.h"
+#include "common_config.h"
+#include "FreeRTOS.h"
+#include "task.h"
+#include "queue.h"
+#include "semphr.h"
+//#include "extended_sram.h"
+#include "modbus.h"
+#include "common_gpio.h"
+#include "settings_api.h"
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+
+
+
+#endif

File diff suppressed because it is too large
+ 768 - 218
project/ewarm/iap/iap.dep


+ 81 - 9
project/ewarm/iap/iap.ewp

@@ -363,19 +363,16 @@
                     <state>$PROJ_DIR$\..\..\..\shared\wdt</state>
                     <state>$PROJ_DIR$\..\..\..\shared\board</state>
                     <state>$PROJ_DIR$\..\..\..\shared\utils</state>
+                    <state>$PROJ_DIR$\..\..\..\shared\sys</state>
                     <state>$PROJ_DIR$\..\..\..\shared\freemodbus</state>
                     <state>$PROJ_DIR$\..\..\..\shared\freemodbus\ascii</state>
                     <state>$PROJ_DIR$\..\..\..\shared\freemodbus\functions</state>
                     <state>$PROJ_DIR$\..\..\..\shared\freemodbus\include</state>
                     <state>$PROJ_DIR$\..\..\..\shared\freemodbus\port</state>
                     <state>$PROJ_DIR$\..\..\..\shared\freemodbus\rtu</state>
-                    <state>$PROJ_DIR$\..\..\..\fw\modules\usb</state>
-                    <state>$PROJ_DIR$\..\..\..\fw\modules\io</state>
-                    <state>$PROJ_DIR$\..\..\..\fw\modules\misc</state>
-                    <state>$PROJ_DIR$\..\..\..\fw\modules\spi_flash</state>
-                    <state>$PROJ_DIR$\..\..\..\fw\modules\user_fatfs</state>
-                    <state>$PROJ_DIR$\..\..\..\fw\modules\modbus</state>
-                    <state>$PROJ_DIR$\..\..\..\fw\user</state>
+                    <state>$PROJ_DIR$\..\..\..\iap\modules\modbus</state>
+                    <state>$PROJ_DIR$\..\..\..\iap\modules\settings</state>
+                    <state>$PROJ_DIR$\..\..\..\iap\user</state>
                     <state>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\include</state>
                     <state>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\portable\IAR\ARM_CM4F</state>
                 </option>
@@ -643,7 +640,7 @@
                 </option>
                 <option>
                     <name>AUserIncludes</name>
-                    <state></state>
+                    <state>$PROJ_DIR$\..\..\..\iap\user</state>
                 </option>
                 <option>
                     <name>AExtraOptionsCheckV2</name>
@@ -677,7 +674,7 @@
                 </option>
                 <option>
                     <name>OOCOutputFile</name>
-                    <state></state>
+                    <state>iap.srec</state>
                 </option>
                 <option>
                     <name>OOCCommandLineProducer</name>
@@ -2135,9 +2132,30 @@
         <name>iap</name>
         <group>
             <name>modules</name>
+            <group>
+                <name>modbus</name>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\iap\modules\modbus\modbus.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\iap\modules\modbus\modbus_params.c</name>
+                </file>
+            </group>
+            <group>
+                <name>settings</name>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\iap\modules\settings\settings_api.c</name>
+                </file>
+            </group>
         </group>
         <group>
             <name>user</name>
+            <file>
+                <name>$PROJ_DIR$\..\..\..\iap\user\at32f403a_407_int.c</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\..\..\..\iap\user\FreeRTOSConfig.h</name>
+            </file>
             <file>
                 <name>$PROJ_DIR$\..\..\..\iap\user\main.c</name>
             </file>
@@ -2252,6 +2270,48 @@
         </group>
         <group>
             <name>thirdparty</name>
+            <group>
+                <name>freertos</name>
+                <group>
+                    <name>portable</name>
+                    <group>
+                        <name>memmang</name>
+                        <file>
+                            <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\portable\memmang\heap_4.c</name>
+                        </file>
+                    </group>
+                    <file>
+                        <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\portable\IAR\ARM_CM4F\port.c</name>
+                    </file>
+                    <file>
+                        <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\portable\IAR\ARM_CM4F\portasm.s</name>
+                    </file>
+                    <file>
+                        <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\portable\IAR\ARM_CM4F\portmacro.h</name>
+                    </file>
+                </group>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\croutine.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\event_groups.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\fr_timers.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\FreeRTOS-openocd.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\list.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\queue.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\tasks.c</name>
+                </file>
+            </group>
         </group>
     </group>
     <group>
@@ -2360,6 +2420,18 @@
         </group>
         <group>
             <name>peripherals</name>
+            <file>
+                <name>$PROJ_DIR$\..\..\..\shared\peripherals\src\common_gpio.c</name>
+            </file>
+        </group>
+        <group>
+            <name>sys</name>
+            <file>
+                <name>$PROJ_DIR$\..\..\..\shared\sys\sys_api.c</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\..\..\..\shared\sys\sys_hal.c</name>
+            </file>
         </group>
         <group>
             <name>utils</name>

+ 75 - 0
project/ewarm/iap/iap.ewt

@@ -2373,9 +2373,30 @@
         <name>iap</name>
         <group>
             <name>modules</name>
+            <group>
+                <name>modbus</name>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\iap\modules\modbus\modbus.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\iap\modules\modbus\modbus_params.c</name>
+                </file>
+            </group>
+            <group>
+                <name>settings</name>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\iap\modules\settings\settings_api.c</name>
+                </file>
+            </group>
         </group>
         <group>
             <name>user</name>
+            <file>
+                <name>$PROJ_DIR$\..\..\..\iap\user\at32f403a_407_int.c</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\..\..\..\iap\user\FreeRTOSConfig.h</name>
+            </file>
             <file>
                 <name>$PROJ_DIR$\..\..\..\iap\user\main.c</name>
             </file>
@@ -2490,6 +2511,48 @@
         </group>
         <group>
             <name>thirdparty</name>
+            <group>
+                <name>freertos</name>
+                <group>
+                    <name>portable</name>
+                    <group>
+                        <name>memmang</name>
+                        <file>
+                            <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\portable\memmang\heap_4.c</name>
+                        </file>
+                    </group>
+                    <file>
+                        <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\portable\IAR\ARM_CM4F\port.c</name>
+                    </file>
+                    <file>
+                        <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\portable\IAR\ARM_CM4F\portasm.s</name>
+                    </file>
+                    <file>
+                        <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\portable\IAR\ARM_CM4F\portmacro.h</name>
+                    </file>
+                </group>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\croutine.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\event_groups.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\fr_timers.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\FreeRTOS-openocd.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\list.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\queue.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\..\libs\thirdparty\freertos\tasks.c</name>
+                </file>
+            </group>
         </group>
     </group>
     <group>
@@ -2598,6 +2661,18 @@
         </group>
         <group>
             <name>peripherals</name>
+            <file>
+                <name>$PROJ_DIR$\..\..\..\shared\peripherals\src\common_gpio.c</name>
+            </file>
+        </group>
+        <group>
+            <name>sys</name>
+            <file>
+                <name>$PROJ_DIR$\..\..\..\shared\sys\sys_api.c</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\..\..\..\shared\sys\sys_hal.c</name>
+            </file>
         </group>
         <group>
             <name>utils</name>

File diff suppressed because it is too large
+ 644 - 648
project/ewarm/module_universal_io.dep


+ 3 - 3
project/ewarm/module_universal_io.ewp

@@ -2154,9 +2154,6 @@
             <name>modules</name>
             <group>
                 <name>io</name>
-                <file>
-                    <name>$PROJ_DIR$\..\..\fw\modules\io\common_gpio.c</name>
-                </file>
                 <file>
                     <name>$PROJ_DIR$\..\..\fw\modules\io\input.c</name>
                 </file>
@@ -2680,6 +2677,9 @@
         </group>
         <group>
             <name>peripherals</name>
+            <file>
+                <name>$PROJ_DIR$\..\..\shared\peripherals\src\common_gpio.c</name>
+            </file>
             <file>
                 <name>$PROJ_DIR$\..\..\shared\peripherals\src\rng.c</name>
             </file>

+ 3 - 3
project/ewarm/module_universal_io.ewt

@@ -2375,9 +2375,6 @@
             <name>modules</name>
             <group>
                 <name>io</name>
-                <file>
-                    <name>$PROJ_DIR$\..\..\fw\modules\io\common_gpio.c</name>
-                </file>
                 <file>
                     <name>$PROJ_DIR$\..\..\fw\modules\io\input.c</name>
                 </file>
@@ -2901,6 +2898,9 @@
         </group>
         <group>
             <name>peripherals</name>
+            <file>
+                <name>$PROJ_DIR$\..\..\shared\peripherals\src\common_gpio.c</name>
+            </file>
             <file>
                 <name>$PROJ_DIR$\..\..\shared\peripherals\src\rng.c</name>
             </file>

+ 0 - 0
fw/modules/io/common_gpio.h → shared/peripherals/inc/common_gpio.h


+ 0 - 0
fw/modules/io/common_gpio.c → shared/peripherals/src/common_gpio.c


Some files were not shown because too many files changed in this diff