Changeset 79 for ctrl/firmware/Main/SES


Ignore:
Timestamp:
Feb 4, 2025, 1:58:46 PM (3 months ago)
Author:
Zed
Message:

DHCP client can get IP-address from fritz!box

Location:
ctrl/firmware/Main/SES
Files:
13 added
2 edited
2 moved

Legend:

Unmodified
Added
Removed
  • ctrl/firmware/Main/SES/Core/Inc/eth_task.h

    r78 r79  
    11#ifndef __ETH_THREAD_H
    22#define __ETH_THREAD_H
    3 
    4 #include "tx_api.h"
    53
    64#ifdef __cplusplus
     
    97#endif
    108
    11 VOID ethThread(ULONG initial_input);
     9void ethTaskStart(void* argument);
    1210
    1311#ifdef __cplusplus
  • ctrl/firmware/Main/SES/Core/Src/eth_task.cpp

    r78 r79  
    22#include <cstdint>
    33
     4#include "main.h"
     5#include "FreeRTOS.h"
     6#include "task.h"
    47
    5 #include "eth_thread.h"
     8#include "eth_task.h"
     9
     10#include "loopback.h"
     11#include "wizchip_conf.h"
     12#include "dhcp.h"
    613
    714
    8 VOID ethThread(ULONG initial_input)
     15static constexpr unsigned ETH_MAX_BUF_SIZE = 2048U;
     16static constexpr unsigned SOCKET_DHCP = 1;
     17
     18static constexpr uint16_t delay_ms = 500U;
     19
     20
     21static uint8_t dhcp_buffer[ETH_MAX_BUF_SIZE];
     22
     23wiz_NetInfo gWIZNETINFO = {
     24                .mac = {0x00, 0x08, 0xdc, 0x6f, 0x00, 0x8a},
     25                .ip = {192, 168, 11, 109},
     26                .sn = {255, 255, 255, 0},
     27                .gw = {192, 168, 11, 1},
     28                .dns = {8, 8, 8, 8},
     29                .dhcp = NETINFO_DHCP
     30};
     31
     32static void ip_assigned(void);
     33static void ip_updated(void);
     34static void ip_conflict(void);
     35static void wizchip_initialize(void);
     36static void wizchip_reset(void);
     37static void wizchip_check(void);
     38static void wizchip_dhcp_init(void);
     39
     40//------------------------------------------------------------------------------
     41
     42void ethTaskStart(void* argument)
    943{
    10         (void)initial_input;
     44        (void)argument;
    1145
     46        wizchip_initialize();
     47
     48        if (gWIZNETINFO.dhcp == NETINFO_DHCP) // DHCP
     49        {
     50                wizchip_dhcp_init();
     51
     52                while (DHCP_run() != DHCP_IP_LEASED)
     53              wiz_delay_ms(1000);
     54        }
     55        else // static
     56        {
     57                ctlnetwork(CN_SET_NETINFO, &gWIZNETINFO);
     58                printf("\r\n----------STATIC Net Information--------------\r\n");
     59                //print_network_information();
     60        }
    1261
    1362        while (1)
    1463        {
    15                 tx_thread_sleep(1000U);
     64                if (gWIZNETINFO.dhcp == NETINFO_DHCP) DHCP_run();
     65
     66                loopback_tcps(2, dhcp_buffer, 5000U);
     67
     68                vTaskDelay(delay_ms);
    1669        }
    1770}
     71
     72//------------------------------------------------------------------------------
     73
     74void wizchip_reset(void)
     75{
     76        HAL_GPIO_WritePin(ETH_SPI_PWR_GPIO_Port, ETH_SPI_PWR_Pin, GPIO_PIN_RESET);
     77        vTaskDelay(pdMS_TO_TICKS(100U));
     78        HAL_GPIO_WritePin(ETH_SPI_RST_GPIO_Port, ETH_SPI_RST_Pin, GPIO_PIN_SET);
     79        vTaskDelay(pdMS_TO_TICKS(65U));   // Min 60.3ms
     80}
     81
     82//------------------------------------------------------------------------------
     83
     84void wizchip_initialize(void)
     85{
     86        uint8_t W5100S_AdrSet[2][4]= {{2,2,2,2},{2,2,2,2}};
     87    uint8_t tmp1, tmp2;
     88        intr_kind temp= IK_DEST_UNREACH;
     89
     90        wizchip_reset();
     91
     92        if (ctlwizchip(CW_INIT_WIZCHIP, (void*)W5100S_AdrSet) == -1)
     93                printf(">>>>W5100s memory initialization failed\r\n");
     94
     95        if(ctlwizchip(CW_SET_INTRMASK,&temp) == -1)
     96                printf("W5100S interrupt\r\n");
     97
     98        wizchip_check();
     99
     100        while(1)
     101        {
     102                ctlwizchip(CW_GET_PHYLINK, &tmp1 );
     103                ctlwizchip(CW_GET_PHYLINK, &tmp2 );
     104                if (tmp1 == PHY_LINK_ON && tmp2 == PHY_LINK_ON) break;
     105        }
     106}
     107
     108//------------------------------------------------------------------------------
     109
     110static void ip_assigned(void)
     111{
     112        printf("IP-address was assigned.\n");
     113
     114        uint8_t ip[4];
     115        getIPfromDHCP(ip);
     116        printf("IP-address: %u.%u.%u.%u\n", ip[0], ip[1], ip[2], ip[3]);
     117
     118        uint8_t nm[4];
     119        getSNfromDHCP(nm);
     120        printf("Subnet mask: %u.%u.%u.%u\n", nm[0], nm[1], nm[2], nm[3]);
     121
     122        uint8_t gw[4];
     123        getGWfromDHCP(gw);
     124        printf("Gateway address: %u.%u.%u.%u\n", gw[0], gw[1], gw[2], gw[3]);
     125
     126        uint8_t dns[4];
     127        getDNSfromDHCP(dns);
     128        printf("DNS address: %u.%u.%u.%u\n", dns[0], dns[1], dns[2], dns[3]);
     129
     130        printf("Lease time: %u\n", getDHCPLeasetime());
     131}
     132
     133//------------------------------------------------------------------------------
     134
     135static void ip_updated(void)
     136{
     137        printf("IP-address was updated.\n");
     138}
     139
     140//------------------------------------------------------------------------------
     141
     142static void ip_conflict(void)
     143{
     144        printf("IP-address conflict!.\n");
     145}
     146
     147//------------------------------------------------------------------------------
     148
     149void wizchip_check(void)
     150{
     151        // Read version register
     152    if (getVER() != 0x51) // W5100S
     153    {
     154        printf(" ACCESS ERR : VERSIONR != 0x51, read value = 0x%02x\n", getVER());
     155        while (1);
     156    }
     157}
     158
     159//------------------------------------------------------------------------------
     160
     161void wizchip_dhcp_init(void)
     162{
     163    DHCP_init(SOCKET_DHCP, dhcp_buffer);
     164    reg_dhcp_cbfunc(ip_assigned, ip_updated, ip_conflict);
     165}
     166
     167//------------------------------------------------------------------------------
  • ctrl/firmware/Main/SES/Core/Src/main_task.cpp

    r78 r79  
    1010#include "utils.h"
    1111
    12 #include "wizchip_conf.h"
    13 #include "dhcp.h"
    14 
    15 static constexpr unsigned ETH_MAX_BUF_SIZE = 2048U;
    16 static constexpr unsigned SOCKET_DHCP = 1;
    1712
    1813static const char* const TAG = "MAIN";
    1914
    2015static constexpr uint16_t delay_ms = 5000;
     16
    2117static constexpr unsigned MAX_CHARS_IN_VOLUME_NAME = 12U;
    2218static uint8_t volumeName[MAX_CHARS_IN_VOLUME_NAME];
     
    2521
    2622static FATFS fs;// __attribute__((section(".DTCM_RAM")));     // Filesystem object
    27 static uint8_t dhcp_buffer[ETH_MAX_BUF_SIZE];
    28 
    29 wiz_NetInfo gWIZNETINFO = {
    30                 .mac = {0x00, 0x08, 0xdc, 0x6f, 0x00, 0x8a},
    31                 .ip = {192, 168, 11, 109},
    32                 .sn = {255, 255, 255, 0},
    33                 .gw = {192, 168, 11, 1},
    34                 .dns = {8, 8, 8, 8},
    35                 .dhcp = NETINFO_DHCP
    36 };
    37 
    3823
    3924FRESULT scan_files (TCHAR* path);
    4025FRESULT list_dir (const char* path);
    41 
    42 static void ip_assigned(void);
    43 static void ip_updated(void);
    44 static void ip_conflict(void);
    45 static void wizchip_initialize(void);
    46 static void wizchip_reset(void);
    47 static void wizchip_check(void);
    48 static void wizchip_dhcp_init(void);
    4926
    5027//------------------------------------------------------------------------------
     
    5330{
    5431        (void)argument;
    55 
    56         wizchip_initialize();
    57 
    58         if (gWIZNETINFO.dhcp == NETINFO_DHCP) // DHCP
    59         {
    60                 wizchip_dhcp_init();
    61 
    62                 while (DHCP_run() != DHCP_IP_LEASED)
    63               wiz_delay_ms(1000);
    64         }
    65         else // static
    66         {
    67                 ctlnetwork(CN_SET_NETINFO, &gWIZNETINFO);
    68                 printf("\r\n----------STATIC Net Information--------------\r\n");
    69                 //print_network_information();
    70         }
    7132
    7233        //DHCP_init(0, dhcp_buffer);
     
    9556}
    9657
    97 //------------------------------------------------------------------------------
    98 
    99 void wizchip_reset(void)
    100 {
    101         HAL_GPIO_WritePin(ETH_SPI_PWR_GPIO_Port, ETH_SPI_PWR_Pin, GPIO_PIN_RESET);
    102         vTaskDelay(pdMS_TO_TICKS(100U));
    103         HAL_GPIO_WritePin(ETH_SPI_RST_GPIO_Port, ETH_SPI_RST_Pin, GPIO_PIN_SET);
    104         vTaskDelay(pdMS_TO_TICKS(65U));   // Min 60.3ms
    105 }
    106 
    107 //------------------------------------------------------------------------------
    108 
    109 void wizchip_initialize(void)
    110 {
    111         uint8_t W5100S_AdrSet[2][4]= {{2,2,2,2},{2,2,2,2}};
    112     uint8_t tmp1, tmp2;
    113         intr_kind temp= IK_DEST_UNREACH;
    114 
    115         wizchip_reset();
    116 
    117         if (ctlwizchip(CW_INIT_WIZCHIP, (void*)W5100S_AdrSet) == -1)
    118                 printf(">>>>W5100s memory initialization failed\r\n");
    119 
    120         if(ctlwizchip(CW_SET_INTRMASK,&temp) == -1)
    121                 printf("W5100S interrupt\r\n");
    122 
    123         wizchip_check();
    124 
    125         while(1)
    126         {
    127                 ctlwizchip(CW_GET_PHYLINK, &tmp1 );
    128                 ctlwizchip(CW_GET_PHYLINK, &tmp2 );
    129                 if (tmp1 == PHY_LINK_ON && tmp2 == PHY_LINK_ON) break;
    130         }
    131 }
    132 
    133 //------------------------------------------------------------------------------
    134 
    135 static void ip_assigned(void)
    136 {
    137         printf("IP-address was assigned.\n");
    138 
    139         uint8_t ip[4];
    140         getIPfromDHCP(ip);
    141         printf("IP-address: %u.%u.%u.%u\n", ip[0], ip[1], ip[2], ip[3]);
    142 
    143         uint8_t nm[4];
    144         getSNfromDHCP(nm);
    145         printf("Subnet mask: %u.%u.%u.%u\n", nm[0], nm[1], nm[2], nm[3]);
    146 
    147         uint8_t gw[4];
    148         getGWfromDHCP(gw);
    149         printf("Gateway address: %u.%u.%u.%u\n", gw[0], gw[1], gw[2], gw[3]);
    150 
    151         uint8_t dns[4];
    152         getDNSfromDHCP(dns);
    153         printf("DNS address: %u.%u.%u.%u\n", dns[0], dns[1], dns[2], dns[3]);
    154 
    155         printf("Lease time: %u\n", getDHCPLeasetime());
    156 }
    157 
    158 //------------------------------------------------------------------------------
    159 
    160 static void ip_updated(void)
    161 {
    162         printf("IP-address was updated.\n");
    163 }
    164 
    165 //------------------------------------------------------------------------------
    166 
    167 static void ip_conflict(void)
    168 {
    169         printf("IP-address conflict!.\n");
    170 }
    171 
    172 //------------------------------------------------------------------------------
    173 
    174 void wizchip_check(void)
    175 {
    176         // Read version register
    177     if (getVER() != 0x51) // W5100S
    178     {
    179         printf(" ACCESS ERR : VERSIONR != 0x51, read value = 0x%02x\n", getVER());
    180         while (1);
    181     }
    182 }
    183 
    184 //------------------------------------------------------------------------------
    185 
    186 void wizchip_dhcp_init(void)
    187 {
    188     DHCP_init(SOCKET_DHCP, dhcp_buffer);
    189     reg_dhcp_cbfunc(ip_assigned, ip_updated, ip_conflict);
    190 }
    191 
    192 //------------------------------------------------------------------------------
    19358
    19459/* List contents of a directory */
  • ctrl/firmware/Main/SES/charger.emProject

    r78 r79  
    3535      c_enforce_ansi_checking="Yes"
    3636      c_preprocessor_definitions="STM32H723xx;_DHCP_DEBUG_"
    37       c_user_include_directories="./../CubeMX/Core/Inc;./../CubeMX/Drivers/STM32H7xx_HAL_Driver/Inc;./../CubeMX/Drivers/CMSIS/Device/ST/STM32H7xx/Include;./../CubeMX/Drivers/CMSIS/Core/Include;./../CubeMX/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2;./../CubeMX/Middlewares/Third_Party/FreeRTOS/Source/include;./../CubeMX/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F;./../CubeMX/FATFS/App;./../CubeMX/Middlewares/Third_Party/FatFs/src;./../CubeMX/FATFS/Target;$(ProjectDir)/Core/Inc;$(ProjectDir)/Wiznet/Ethernet/W5100S;$(ProjectDir)/Wiznet/Ethernet;$(ProjectDir)/Wiznet/Internet/DHCP"
     37      c_user_include_directories="./../CubeMX/Core/Inc;./../CubeMX/Drivers/STM32H7xx_HAL_Driver/Inc;./../CubeMX/Drivers/CMSIS/Device/ST/STM32H7xx/Include;./../CubeMX/Drivers/CMSIS/Core/Include;./../CubeMX/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2;./../CubeMX/Middlewares/Third_Party/FreeRTOS/Source/include;./../CubeMX/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F;./../CubeMX/FATFS/App;./../CubeMX/Middlewares/Third_Party/FatFs/src;./../CubeMX/FATFS/Target;$(ProjectDir)/Core/Inc;$(ProjectDir)/Wiznet/Ethernet/W5100S;$(ProjectDir)/Wiznet/Ethernet;$(ProjectDir)/Wiznet/Internet/DHCP;$(ProjectDir)/Wiznet/Application/loopback"
    3838      compiler_color_diagnostics="Yes"
    3939      debug_initial_breakpoint_set_option="Never"
     
    6969      <folder Name="Inc">
    7070        <file file_name="../CubeMX/Core/Inc/dma.h" />
    71         <file file_name="Core/Inc/eth_thread.h">
    72           <configuration Name="Debug" build_exclude_from_build="Yes" />
    73           <configuration Name="Release" build_exclude_from_build="Yes" />
    74         </file>
    7571        <file file_name="Core/Inc/fan_thread.h">
    7672          <configuration Name="Release" build_exclude_from_build="No" />
     
    7975        <file file_name="Core/Inc/gsm_rx_thread.h" />
    8076        <file file_name="Core/Inc/gsm_thread.h" />
    81         <file file_name="Core/Inc/keys_task.h" />
    8277        <file file_name="../CubeMX/Core/Inc/main.h" />
    83         <file file_name="Core/Inc/main_task.h" />
    8478        <file file_name="../CubeMX/Core/Inc/memorymap.h" />
    8579        <file file_name="../CubeMX/Core/Inc/rtc.h" />
     
    9488      <folder Name="Src">
    9589        <file file_name="../CubeMX/Core/Src/dma.c" />
    96         <file file_name="Core/Src/eth_thread.cpp">
    97           <configuration Name="Debug" build_exclude_from_build="Yes" />
    98           <configuration Name="Release" build_exclude_from_build="Yes" />
    99         </file>
    10090        <file file_name="Core/Src/fan_thread.cpp">
    10191          <configuration Name="Debug" build_exclude_from_build="Yes" />
     
    112102          <configuration Name="Release" build_exclude_from_build="Yes" />
    113103        </file>
    114         <file file_name="Core/Src/keys_task.cpp" />
    115104        <file file_name="../CubeMX/Core/Src/main.c" />
    116         <file file_name="Core/Src/main_task.cpp" />
    117105        <file file_name="../CubeMX/Core/Src/memorymap.c" />
    118106        <file file_name="../CubeMX/Core/Src/rtc.c" />
     
    208196          </folder>
    209197        </folder>
     198        <folder Name="Loopback">
     199          <folder Name="Inc">
     200            <file file_name="Wiznet/Application/loopback/loopback.h" />
     201          </folder>
     202          <folder Name="Src">
     203            <file file_name="Wiznet/Application/loopback/loopback.c" />
     204          </folder>
     205        </folder>
    210206      </folder>
    211207    </folder>
     
    294290      <file file_name="STM32H7xx/Source/stm32h723xx_Vectors.s" />
    295291    </folder>
     292    <folder Name="Tasks">
     293      <folder Name="Inc">
     294        <file file_name="Core/Inc/eth_task.h" />
     295        <file file_name="Core/Inc/keys_task.h" />
     296        <file file_name="Core/Inc/main_task.h" />
     297      </folder>
     298      <folder Name="Src">
     299        <file file_name="Core/Src/eth_task.cpp" />
     300        <file file_name="Core/Src/keys_task.cpp" />
     301        <file file_name="Core/Src/main_task.cpp" />
     302      </folder>
     303    </folder>
    296304  </project>
    297305</solution>
Note: See TracChangeset for help on using the changeset viewer.