Changeset 79 for ctrl/firmware/Main/SES/Core
- Timestamp:
- Feb 4, 2025, 1:58:46 PM (3 months ago)
- Location:
- ctrl/firmware/Main/SES/Core
- Files:
-
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
ctrl/firmware/Main/SES/Core/Inc/eth_task.h
r78 r79 1 1 #ifndef __ETH_THREAD_H 2 2 #define __ETH_THREAD_H 3 4 #include "tx_api.h"5 3 6 4 #ifdef __cplusplus … … 9 7 #endif 10 8 11 VOID ethThread(ULONG initial_input);9 void ethTaskStart(void* argument); 12 10 13 11 #ifdef __cplusplus -
ctrl/firmware/Main/SES/Core/Src/eth_task.cpp
r78 r79 2 2 #include <cstdint> 3 3 4 #include "main.h" 5 #include "FreeRTOS.h" 6 #include "task.h" 4 7 5 #include "eth_thread.h" 8 #include "eth_task.h" 9 10 #include "loopback.h" 11 #include "wizchip_conf.h" 12 #include "dhcp.h" 6 13 7 14 8 VOID ethThread(ULONG initial_input) 15 static constexpr unsigned ETH_MAX_BUF_SIZE = 2048U; 16 static constexpr unsigned SOCKET_DHCP = 1; 17 18 static constexpr uint16_t delay_ms = 500U; 19 20 21 static uint8_t dhcp_buffer[ETH_MAX_BUF_SIZE]; 22 23 wiz_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 32 static void ip_assigned(void); 33 static void ip_updated(void); 34 static void ip_conflict(void); 35 static void wizchip_initialize(void); 36 static void wizchip_reset(void); 37 static void wizchip_check(void); 38 static void wizchip_dhcp_init(void); 39 40 //------------------------------------------------------------------------------ 41 42 void ethTaskStart(void* argument) 9 43 { 10 (void) initial_input;44 (void)argument; 11 45 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 } 12 61 13 62 while (1) 14 63 { 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); 16 69 } 17 70 } 71 72 //------------------------------------------------------------------------------ 73 74 void 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 84 void 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 110 static 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 135 static void ip_updated(void) 136 { 137 printf("IP-address was updated.\n"); 138 } 139 140 //------------------------------------------------------------------------------ 141 142 static void ip_conflict(void) 143 { 144 printf("IP-address conflict!.\n"); 145 } 146 147 //------------------------------------------------------------------------------ 148 149 void 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 161 void 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 10 10 #include "utils.h" 11 11 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;17 12 18 13 static const char* const TAG = "MAIN"; 19 14 20 15 static constexpr uint16_t delay_ms = 5000; 16 21 17 static constexpr unsigned MAX_CHARS_IN_VOLUME_NAME = 12U; 22 18 static uint8_t volumeName[MAX_CHARS_IN_VOLUME_NAME]; … … 25 21 26 22 static 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_DHCP36 };37 38 23 39 24 FRESULT scan_files (TCHAR* path); 40 25 FRESULT 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);49 26 50 27 //------------------------------------------------------------------------------ … … 53 30 { 54 31 (void)argument; 55 56 wizchip_initialize();57 58 if (gWIZNETINFO.dhcp == NETINFO_DHCP) // DHCP59 {60 wizchip_dhcp_init();61 62 while (DHCP_run() != DHCP_IP_LEASED)63 wiz_delay_ms(1000);64 }65 else // static66 {67 ctlnetwork(CN_SET_NETINFO, &gWIZNETINFO);68 printf("\r\n----------STATIC Net Information--------------\r\n");69 //print_network_information();70 }71 32 72 33 //DHCP_init(0, dhcp_buffer); … … 95 56 } 96 57 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.3ms105 }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 register177 if (getVER() != 0x51) // W5100S178 {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 //------------------------------------------------------------------------------193 58 194 59 /* List contents of a directory */
Note: See TracChangeset
for help on using the changeset viewer.