Explorar el Código

Разное. Работает смена адреса modbus переключателем.

TelenkovDmitry hace 1 año
padre
commit
c7792a9b6b

+ 8 - 8
fw/modules/io/input.c

@@ -8,14 +8,14 @@
 
 // *port; pin; mode; port_source; pin_source; deb_counter; p_flag; cnt;
 din_t inputs[DI_NUMBER] = {
-    {GPIOB, GPIO_PINS_11, 0, GPIO_PORT_SOURCE_GPIOB, GPIO_PINS_SOURCE11, 0, false, 0, EXINT_LINE_11}, // 1   
-    {GPIOB, GPIO_PINS_10, 0, GPIO_PORT_SOURCE_GPIOB, GPIO_PINS_SOURCE10, 0, false, 0, EXINT_LINE_10}, // 2
-    {GPIOE, GPIO_PINS_14, 0, GPIO_PORT_SOURCE_GPIOE, GPIO_PINS_SOURCE14, 0, false, 0, EXINT_LINE_14}, // 3 перенесли {GPIOB, GPIO_PINS_1,  1, GPIO_PORT_SOURCE_GPIOB, GPIO_PINS_SOURCE1,  0},
-    {GPIOE, GPIO_PINS_15, 0, GPIO_PORT_SOURCE_GPIOE, GPIO_PINS_SOURCE15, 0, false, 0, EXINT_LINE_15}, // 4 перенесли {GPIOB, GPIO_PINS_0,  1, GPIO_PORT_SOURCE_GPIOB, GPIO_PINS_SOURCE0,  0},
-    {GPIOA, GPIO_PINS_3,  0, GPIO_PORT_SOURCE_GPIOA, GPIO_PINS_SOURCE3,  0, false, 0, EXINT_LINE_3}, // 5
-    {GPIOA, GPIO_PINS_2,  0, GPIO_PORT_SOURCE_GPIOA, GPIO_PINS_SOURCE2,  0, false, 0, EXINT_LINE_2}, // 6
-    {GPIOA, GPIO_PINS_1,  0, GPIO_PORT_SOURCE_GPIOA, GPIO_PINS_SOURCE1,  0, false, 0, EXINT_LINE_1}, // 7
-    {GPIOA, GPIO_PINS_0,  0, GPIO_PORT_SOURCE_GPIOA, GPIO_PINS_SOURCE0,  0, false, 0, EXINT_LINE_0}  // 8
+    {GPIOB, GPIO_PINS_11, 0, 0, false, 0}, // 1   
+    {GPIOB, GPIO_PINS_10, 0, 0, false, 0}, // 2
+    {GPIOE, GPIO_PINS_14, 0, 0, false, 0}, // 3 перенесли {GPIOB, GPIO_PINS_1,  1, GPIO_PORT_SOURCE_GPIOB, GPIO_PINS_SOURCE1,  0},
+    {GPIOE, GPIO_PINS_15, 0, 0, false, 0}, // 4 перенесли {GPIOB, GPIO_PINS_0,  1, GPIO_PORT_SOURCE_GPIOB, GPIO_PINS_SOURCE0,  0},
+    {GPIOA, GPIO_PINS_3,  0, 0, false, 0}, // 5
+    {GPIOA, GPIO_PINS_2,  0, 0, false, 0}, // 6
+    {GPIOA, GPIO_PINS_1,  0, 0, false, 0}, // 7
+    {GPIOA, GPIO_PINS_0,  0, 0, false, 0}  // 8
 };
 
 

+ 0 - 1
fw/modules/io/io.c

@@ -75,7 +75,6 @@ void io_tim_init(void)
     tmr_counter_enable(TMR12, TRUE);  
 }
 
-
 void TMR8_BRK_TMR12_IRQHandler(void)
 {
     //static int i = 0;

+ 0 - 3
fw/modules/io/io.h

@@ -52,12 +52,9 @@ typedef struct
     gpio_type *port;
     uint16_t pin;
     uint16_t mode;  // 0 - обычный вход, 1 - счетный вход
-    gpio_port_source_type port_source;
-    uint16_t pin_source;
     uint32_t deb_counter;
     bool p_flag;
     uint32_t cnt;
-    uint32_t exint_line;
     
 } din_t;
 

+ 2 - 1
fw/modules/modbus/modbus.c

@@ -9,6 +9,7 @@
 #include "mbrtu.h"
 #include "tim_delay.h"
 #include "modbus_params.h"
+#include "common_gpio.h"
 #include <stdio.h>
 #include <string.h>
 #include <stdbool.h>
@@ -41,7 +42,7 @@ void mb_init(void)
 {
     uint32_t baud = 115200;
     eMBParity par = MB_PAR_NONE;
-    UCHAR mb_addr = 1;
+    UCHAR mb_addr = cm_gpio_get_mb_addr();
     unsigned int stop_bits = 1;
 	const UCHAR ucSlaveID[] = {0xAA, 0xBB, 0xCC};
     

+ 17 - 3
fw/user/main.c

@@ -5,6 +5,7 @@ void init_task(void *argument);
 void test_hw_task(void *argument);
 void soft_wdt(void *params);
 void test_gpio(void *params);
+void misc_task(void *params);   // TODO перенести в другой модуль
 
 void usb_clock48m_select(usb_clk48_s clk_s);
 
@@ -34,8 +35,7 @@ int main(void)
     io_port_init();
     in_exint_init();
     cm_gpio_init();
-       
-      
+          
     
     printf("\n\n\n\nModule universal IO [FW %s] loading....\r\n\n", VERSION);
         
@@ -55,6 +55,8 @@ int main(void)
     
     xTaskCreate(input_task, "input_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
     
+    xTaskCreate(misc_task, "misc_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
+    
     taskEXIT_CRITICAL();
     
     vTaskStartScheduler();
@@ -180,10 +182,22 @@ void test_gpio(void *params)
         vTaskDelay(1000);
         //io_test();
         //out_test();
+        
+        //printf("HW rev: %u\r\n", cm_gpio_get_rev());
     }
 }
 
-
+//
+void misc_task(void *params)
+{
+    (void)params;
+    
+    for (;;)
+    {
+        vTaskDelay(1000);
+        eMBSetSlaveAddr(cm_gpio_get_mb_addr());
+    }
+}
 
 //
 void usb_clock48m_select(usb_clk48_s clk_s)

+ 1 - 0
fw/user/main.h

@@ -27,6 +27,7 @@
 #include "update.h"
 #include "uptime.h"
 #include "rtc.h"
+#include "mb.h"
 #include <stdio.h>
 #include <stdbool.h>
 #include <string.h>

+ 1 - 1
iap/modules/modbus/modbus.c

@@ -42,7 +42,7 @@ void mb_init(void)
 {
     uint32_t baud;
     eMBParity par;
-    UCHAR mb_addr = 1;
+    UCHAR mb_addr = cm_gpio_get_mb_addr();
     unsigned int stop_bits = 1;
 	const UCHAR ucSlaveID[] = {0xAA, 0xBB, 0xCC};
 

BIN
output/fw.bin


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 398 - 383
project/ewarm/iap/iap.dep


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 968 - 977
project/ewarm/module_universal_io.dep


+ 9 - 0
shared/peripherals/inc/common_gpio.h

@@ -4,6 +4,15 @@
 //
 void cm_gpio_init(void);
 
+//
+void cm_gpio_addr_init(void);
+
+//
+uint8_t cm_gpio_get_mb_addr(void);
+
+// Ревизия платы
+uint8_t cm_gpio_get_rev(void);
+
 //
 void extern_wdt_togle(void);
 

+ 83 - 0
shared/peripherals/src/common_gpio.c

@@ -2,9 +2,31 @@
 #include "common_gpio.h"
 #include "FreeRTOS.h"
 #include "task.h"
+#include "io.h"
 #include <stdbool.h>
 
 
+#define ADDR_PIN_NUM    4
+
+#define HW_REV_PIN_NUM  3
+
+//
+din_t addr_in[ADDR_PIN_NUM] = {
+    {GPIOC, GPIO_PINS_4, 0, 0, false, 0}, // 1   
+    {GPIOA, GPIO_PINS_7, 0, 0, false, 0}, // 2
+    {GPIOA, GPIO_PINS_6, 0, 0, false, 0}, // 3 
+    {GPIOA, GPIO_PINS_5, 0, 0, false, 0}, // 4 
+};
+
+//
+din_t rev_in[ADDR_PIN_NUM] = {
+    {GPIOB, GPIO_PINS_13, 0, 0, false, 0}, // 1   
+    {GPIOB, GPIO_PINS_14, 0, 0, false, 0}, // 2
+    {GPIOB, GPIO_PINS_15, 0, 0, false, 0}, // 3 
+};
+
+
+
 //
 void cm_gpio_init(void)
 {
@@ -19,8 +41,69 @@ void cm_gpio_init(void)
     gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
     gpio_initstructure.gpio_pins           = GPIO_PINS_7;
     gpio_init(GPIOC, &gpio_initstructure); 
+    
+    cm_gpio_addr_init();
 }
 
+// Пины переключателя modbus-адреса
+void cm_gpio_addr_init(void)
+{
+    gpio_init_type gpio_init_struct;
+
+    gpio_default_para_init(&gpio_init_struct);
+        
+    for (uint8_t i = 0; i < ADDR_PIN_NUM; i++)
+    {
+        gpio_init_struct.gpio_pull           = GPIO_PULL_UP;  
+        gpio_init_struct.gpio_mode           = GPIO_MODE_INPUT;  
+        gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+        gpio_init_struct.gpio_pins           = addr_in[i].pin ;
+        gpio_init(addr_in[i].port, &gpio_init_struct);
+    }
+}
+
+//
+uint8_t cm_gpio_get_mb_addr(void)
+{
+    uint8_t ret = 0;
+    
+    for (uint8_t i = 0; i < ADDR_PIN_NUM; i++)
+    {
+        ret |= (uint8_t)gpio_input_data_bit_read(addr_in[i].port, addr_in[i].pin) << i;
+    }
+    
+    ret = ret > 1 ? ret : 1;
+    
+    return ret;
+}
+
+// Ревизия платы
+uint8_t cm_gpio_get_rev(void)
+{
+    uint8_t ret = 0;
+    
+    gpio_init_type gpio_init_struct;
+
+    gpio_default_para_init(&gpio_init_struct);
+        
+    for (uint8_t i = 0; i < HW_REV_PIN_NUM; i++)
+    {
+        gpio_init_struct.gpio_pull           = GPIO_PULL_UP;  
+        gpio_init_struct.gpio_mode           = GPIO_MODE_INPUT;  
+        gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+        gpio_init_struct.gpio_pins           = rev_in[i].pin ;
+        gpio_init(rev_in[i].port, &gpio_init_struct);
+    }
+    
+    for (uint8_t i = 0; i < HW_REV_PIN_NUM; i++)
+    {
+        ret |= (uint8_t)gpio_input_data_bit_read(rev_in[i].port, rev_in[i].pin) << i;
+    }
+    
+    ret = ret > 1 ? ret : 1;
+    
+    return ret;
+}
 
 //
 void extern_wdt_togle(void)

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio