Changeset 78 for ctrl/firmware/Main/SES/Core
- Timestamp:
- Feb 4, 2025, 11:33:27 AM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ctrl/firmware/Main/SES/Core/Src/main_task.cpp
r77 r78 10 10 #include "utils.h" 11 11 12 #include "wizchip_conf.h" 12 13 #include "dhcp.h" 13 14 15 static constexpr unsigned ETH_MAX_BUF_SIZE = 2048U; 16 static constexpr unsigned SOCKET_DHCP = 1; 14 17 15 18 static const char* const TAG = "MAIN"; … … 22 25 23 26 static FATFS fs;// __attribute__((section(".DTCM_RAM"))); // Filesystem object 24 static uint8_t dhcp_buffer[256]; 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 25 38 26 39 FRESULT scan_files (TCHAR* path); 27 40 FRESULT list_dir (const char* path); 28 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 29 50 //------------------------------------------------------------------------------ 30 51 … … 33 54 (void)argument; 34 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 } 71 72 //DHCP_init(0, dhcp_buffer); 73 //reg_dhcp_cbfunc(ip_assigned, ip_updated, ip_conflict); 74 75 //MX_LWIP_Init(); 76 77 FRESULT r = f_mount(&fs, (const TCHAR*)"", 1); // Mount the default drive 78 if (r != FR_OK) printf("Cannot mount SD-card!\n"); 79 else 80 { 81 printf("SD-card was mounted.\n"); 82 83 static TCHAR buff[256]; 84 strcpy (buff, "/"); 85 list_dir(buff); 86 } 87 88 while(1) 89 { 90 vTaskDelay(pdMS_TO_TICKS(delay_ms)); 91 92 //DHCP_run(); 93 //printThreadStackInfo(TAG); 94 } 95 } 96 97 //------------------------------------------------------------------------------ 98 99 void wizchip_reset(void) 100 { 35 101 HAL_GPIO_WritePin(ETH_SPI_PWR_GPIO_Port, ETH_SPI_PWR_Pin, GPIO_PIN_RESET); 36 102 vTaskDelay(pdMS_TO_TICKS(100U)); 37 103 HAL_GPIO_WritePin(ETH_SPI_RST_GPIO_Port, ETH_SPI_RST_Pin, GPIO_PIN_SET); 38 104 vTaskDelay(pdMS_TO_TICKS(65U)); // Min 60.3ms 39 40 DHCP_init(0, dhcp_buffer); 41 42 //MX_LWIP_Init(); 43 44 FRESULT r = f_mount(&fs, (const TCHAR*)"", 1); // Mount the default drive 45 if (r != FR_OK) printf("Cannot mount SD-card!\n"); 46 else 47 { 48 printf("SD-card was mounted.\n"); 49 50 static TCHAR buff[256]; 51 strcpy (buff, "/"); 52 list_dir(buff); 53 } 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(); 54 124 55 125 while(1) 56 126 { 57 vTaskDelay(pdMS_TO_TICKS(delay_ms)); 58 59 //printThreadStackInfo(TAG); 60 } 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); 61 190 } 62 191
Note: See TracChangeset
for help on using the changeset viewer.