eth_worker.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. #include "eth_worker_i.h"
  2. #include "eth_worker.h"
  3. #include "eth_save_process.h"
  4. #include <furi_hal.h>
  5. #include "dhcp.h"
  6. #include "socket.h"
  7. #include "stm32wbxx_hal_gpio.h"
  8. #include <wizchip_conf.h>
  9. #define TAG "EthWorker"
  10. static EthWorker* static_worker = NULL;
  11. EthWorker* eth_worker_alloc() {
  12. EthWorker* worker = malloc(sizeof(EthWorker));
  13. worker->config = ehternet_save_process_malloc();
  14. furi_assert(worker->config);
  15. worker->init_process = ethernet_view_process_malloc(EthWorkerProcessInit, worker->config);
  16. worker->dhcp_process = ethernet_view_process_malloc(EthWorkerProcessDHCP, worker->config);
  17. worker->stat_process = ethernet_view_process_malloc(EthWorkerProcessStatic, worker->config);
  18. worker->ping_process = ethernet_view_process_malloc(EthWorkerProcessPing, worker->config);
  19. worker->reset_process = ethernet_view_process_malloc(EthWorkerProcessReset, worker->config);
  20. worker->active_process = worker->init_process;
  21. static_worker = worker;
  22. worker->state = worker->next_state = EthWorkerStateNotAllocated;
  23. eth_log(EthWorkerProcessReset, "Finik Ethernet [START]");
  24. return worker;
  25. }
  26. void eth_worker_free(EthWorker* worker) {
  27. eth_log(EthWorkerProcessReset, "Finik Ethernet [STOP]");
  28. eth_run(worker, EthWorkerProcessExit);
  29. static_worker = NULL;
  30. furi_assert(worker);
  31. ethernet_view_process_free(worker->init_process);
  32. ethernet_view_process_free(worker->dhcp_process);
  33. ethernet_view_process_free(worker->stat_process);
  34. ethernet_view_process_free(worker->ping_process);
  35. ethernet_view_process_free(worker->reset_process);
  36. ehternet_save_process_free(worker->config);
  37. free(worker);
  38. }
  39. void eth_worker_change_state(EthWorker* worker, EthWorkerState state) {
  40. furi_assert(worker);
  41. worker->state = state;
  42. }
  43. void eth_worker_set_active_process(EthWorker* worker, EthWorkerProcess state) {
  44. furi_assert(worker);
  45. switch(state) {
  46. case EthWorkerProcessInit:
  47. worker->active_process = worker->init_process;
  48. break;
  49. case EthWorkerProcessDHCP:
  50. worker->active_process = worker->dhcp_process;
  51. break;
  52. case EthWorkerProcessStatic:
  53. worker->active_process = worker->stat_process;
  54. break;
  55. case EthWorkerProcessPing:
  56. worker->active_process = worker->ping_process;
  57. break;
  58. case EthWorkerProcessReset:
  59. worker->active_process = worker->reset_process;
  60. break;
  61. }
  62. }
  63. void eth_worker_log(EthWorker* worker, const char* str) {
  64. furi_assert(worker);
  65. ehternet_save_process_print(worker->config, str);
  66. }
  67. static EthViewProcess* get_process(EthWorker* worker, EthWorkerProcess process) {
  68. furi_assert(worker);
  69. switch(process) {
  70. case EthWorkerProcessInit:
  71. return worker->init_process;
  72. case EthWorkerProcessDHCP:
  73. return worker->dhcp_process;
  74. case EthWorkerProcessStatic:
  75. return worker->stat_process;
  76. case EthWorkerProcessPing:
  77. return worker->ping_process;
  78. case EthWorkerProcessReset:
  79. return worker->reset_process;
  80. case EthWorkerProcessActive:
  81. return worker->active_process;
  82. default:
  83. NULL;
  84. }
  85. }
  86. void eth_log(EthWorkerProcess process, const char* format, ...) {
  87. furi_assert(static_worker);
  88. va_list args;
  89. va_start(args, format);
  90. FuriString* fstring = furi_string_alloc_vprintf(format, args);
  91. const char* string = furi_string_get_cstr(fstring);
  92. va_end(args);
  93. FURI_LOG_I(TAG, "%s", string);
  94. ehternet_save_process_print(static_worker->config, string);
  95. ethernet_view_process_print(get_process(static_worker, process), string);
  96. if(process != EthWorkerProcessReset) {
  97. ethernet_view_process_print(get_process(static_worker, EthWorkerProcessReset), string);
  98. }
  99. furi_string_free(fstring);
  100. }
  101. void eth_run(EthWorker* worker, EthWorkerProcess process) {
  102. furi_assert(worker);
  103. switch(process) {
  104. case EthWorkerProcessInit:
  105. if(worker->state == EthWorkerStateNotAllocated) {
  106. worker->thread = furi_thread_alloc();
  107. furi_thread_set_name(worker->thread, "EthWorker");
  108. furi_thread_set_stack_size(worker->thread, 8192);
  109. furi_thread_set_callback(worker->thread, eth_worker_task);
  110. furi_thread_set_context(worker->thread, worker);
  111. worker->state = EthWorkerStateNotInited;
  112. worker->next_state = EthWorkerStateInit;
  113. furi_thread_start(worker->thread);
  114. }
  115. worker->state = EthWorkerStateNotInited;
  116. worker->next_state = EthWorkerStateInit;
  117. break;
  118. case EthWorkerProcessDHCP:
  119. if((uint8_t)worker->state < EthWorkerStateInited) {
  120. eth_log(EthWorkerProcessDHCP, "[error] module not inited");
  121. break;
  122. }
  123. worker->next_state = EthWorkerStateDHCP;
  124. break;
  125. case EthWorkerProcessStatic:
  126. if((uint8_t)worker->state < EthWorkerStateInited) {
  127. eth_log(EthWorkerProcessStatic, "[error] module not inited");
  128. break;
  129. }
  130. worker->next_state = EthWorkerStateStaticIp;
  131. eth_log(EthWorkerProcessStatic, "Fuck you");
  132. break;
  133. case EthWorkerProcessPing:
  134. if((uint8_t)worker->state < EthWorkerStateInited) {
  135. eth_log(EthWorkerProcessPing, "[error] module not inited");
  136. break;
  137. }
  138. worker->next_state = EthWorkerStatePing;
  139. break;
  140. case EthWorkerProcessReset:
  141. worker->next_state = EthWorkerStateNotInited;
  142. if((uint8_t)worker->state > EthWorkerStateNotAllocated) {
  143. worker->state = EthWorkerStateNotInited;
  144. }
  145. eth_log(EthWorkerProcessReset, "reset module");
  146. break;
  147. case EthWorkerProcessExit:
  148. if(worker->state != EthWorkerStateNotAllocated) {
  149. worker->next_state = EthWorkerStateStop;
  150. worker->state = EthWorkerStateStop;
  151. furi_thread_join(worker->thread);
  152. furi_thread_free(worker->thread);
  153. worker->state = EthWorkerStateNotAllocated;
  154. }
  155. break;
  156. default:
  157. break;
  158. }
  159. }
  160. /************************** Ethernet Worker Thread *****************************/
  161. static uint8_t ip_assigned = 0;
  162. static GpioPin cspin = {.port = GPIOA, .pin = GPIO_PIN_4};
  163. static GpioPin resetpin = {.port = GPIOC, .pin = GPIO_PIN_3};
  164. static void W5500_Select(void) {
  165. furi_hal_gpio_write(&cspin, false);
  166. }
  167. static void W5500_Unselect(void) {
  168. furi_hal_gpio_write(&cspin, true);
  169. }
  170. static void Callback_IPAssigned(void) {
  171. eth_log(
  172. EthWorkerProcessDHCP, "Callback: IP assigned! Leased time: %d sec", getDHCPLeasetime());
  173. ip_assigned = 1;
  174. }
  175. static void Callback_IPConflict(void) {
  176. eth_log(EthWorkerProcessDHCP, "Callback: IP conflict!");
  177. }
  178. static void W5500_ReadBuff(uint8_t* buff, uint16_t len) {
  179. furi_hal_spi_bus_rx(&furi_hal_spi_bus_handle_external, buff, len, 1000);
  180. }
  181. static void W5500_WriteBuff(uint8_t* buff, uint16_t len) {
  182. furi_hal_spi_bus_tx(&furi_hal_spi_bus_handle_external, buff, len, 1000);
  183. }
  184. static uint8_t W5500_ReadByte(void) {
  185. uint8_t byte;
  186. W5500_ReadBuff(&byte, sizeof(byte));
  187. return byte;
  188. }
  189. static void W5500_WriteByte(uint8_t byte) {
  190. W5500_WriteBuff(&byte, sizeof(byte));
  191. }
  192. static void wait_ms(int ms) {
  193. furi_delay_ms(ms);
  194. }
  195. static wiz_NetInfo gWIZNETINFO;
  196. void update_WIZNETINFO(uint8_t is_dhcp) {
  197. furi_assert(static_worker);
  198. memcpy(gWIZNETINFO.mac, static_worker->config->mac, 6);
  199. if(is_dhcp) {
  200. memset(gWIZNETINFO.ip, 0, 4);
  201. memset(gWIZNETINFO.sn, 0, 4);
  202. memset(gWIZNETINFO.gw, 0, 4);
  203. memset(gWIZNETINFO.dns, 0, 4);
  204. gWIZNETINFO.dhcp = NETINFO_DHCP;
  205. } else {
  206. memcpy(gWIZNETINFO.ip, static_worker->config->ip, 4);
  207. memcpy(gWIZNETINFO.sn, static_worker->config->mask, 4);
  208. memcpy(gWIZNETINFO.gw, static_worker->config->gateway, 4);
  209. memcpy(gWIZNETINFO.dns, static_worker->config->dns, 4);
  210. gWIZNETINFO.dhcp = NETINFO_STATIC;
  211. }
  212. }
  213. int check_phylink(EthWorker* worker, EthWorkerState state, EthWorkerProcess proc, int timeout) {
  214. uint32_t start_time = furi_get_tick();
  215. uint32_t last_log_time = start_time;
  216. eth_log(proc, "phy link check 0");
  217. for(;;) {
  218. if(furi_get_tick() > start_time + timeout) {
  219. eth_log(proc, "phy link timeout");
  220. break;
  221. }
  222. if(worker->state != state) {
  223. eth_log(proc, "state changed");
  224. break;
  225. }
  226. uint8_t link = PHY_LINK_OFF;
  227. if(ctlwizchip(CW_GET_PHYLINK, (void*)&link) == -1) {
  228. eth_log(proc, "Unknown PHY link status");
  229. break;
  230. }
  231. if(link != PHY_LINK_OFF) {
  232. eth_log(proc, "phy link on");
  233. return 1;
  234. }
  235. furi_delay_ms(20);
  236. if(furi_get_tick() > last_log_time + 1000) {
  237. eth_log(proc, "phy link check %d", (last_log_time - start_time) / 1000);
  238. last_log_time = furi_get_tick();
  239. }
  240. }
  241. return 0;
  242. }
  243. #define DHCP_SOCKET 0
  244. uint8_t ping_auto(uint8_t s, uint8_t* addr);
  245. int32_t eth_worker_task(void* context) {
  246. furi_assert(context);
  247. EthWorker* worker = (EthWorker*)context;
  248. furi_hal_power_insomnia_enter();
  249. furi_hal_spi_acquire(&furi_hal_spi_bus_handle_external);
  250. uint8_t W5500FifoSize[2][8] = {{2, 2, 2, 2, 2, 2, 2, 2}, {2, 2, 2, 2, 2, 2, 2, 2}};
  251. uint8_t dhcp_buffer[2000];
  252. reg_wizchip_spi_cbfunc(W5500_ReadByte, W5500_WriteByte);
  253. reg_wizchip_spiburst_cbfunc(W5500_ReadBuff, W5500_WriteBuff);
  254. reg_wizchip_cs_cbfunc(W5500_Select, W5500_Unselect);
  255. furi_hal_gpio_write(&resetpin, true);
  256. furi_hal_gpio_write(&cspin, true);
  257. furi_hal_gpio_init(&resetpin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
  258. furi_hal_gpio_init(&cspin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
  259. while(worker->next_state != EthWorkerStateStop && worker->state != EthWorkerStateStop) {
  260. if(worker->state == EthWorkerStateNotInited) {
  261. if(worker->next_state != EthWorkerStateInit &&
  262. worker->next_state != EthWorkerStateNotInited) {
  263. eth_log(EthWorkerProcessActive, "[error] try using not inited module");
  264. worker->next_state = EthWorkerStateNotInited;
  265. }
  266. if(worker->next_state == EthWorkerStateInit) {
  267. worker->state = EthWorkerStateInit;
  268. furi_hal_power_enable_otg();
  269. furi_delay_ms(300);
  270. furi_hal_gpio_write(&resetpin, false);
  271. furi_delay_ms(50);
  272. furi_hal_gpio_write(&resetpin, true);
  273. if(ctlwizchip(CW_INIT_WIZCHIP, (void*)W5500FifoSize) == -1) {
  274. eth_log(EthWorkerProcessInit, "[error] W5500 init fail");
  275. worker->state = worker->next_state = EthWorkerStateNotInited;
  276. continue;
  277. }
  278. eth_log(EthWorkerProcessInit, "W5500 inited");
  279. furi_delay_ms(50);
  280. update_WIZNETINFO(false);
  281. wizchip_setnetinfo(&gWIZNETINFO);
  282. wiz_NetInfo readed_net_info;
  283. wizchip_getnetinfo(&readed_net_info);
  284. if(memcmp(&readed_net_info, &gWIZNETINFO, sizeof(wiz_NetInfo))) {
  285. eth_log(EthWorkerProcessInit, "[error] module not detected");
  286. worker->state = EthWorkerStateNotInited;
  287. continue;
  288. }
  289. setSHAR(gWIZNETINFO.mac);
  290. wiz_PhyConf conf;
  291. wizphy_getphyconf(&conf);
  292. eth_log(
  293. EthWorkerProcessInit,
  294. "conf %d %d %d %d",
  295. conf.by,
  296. conf.mode,
  297. conf.speed,
  298. conf.duplex);
  299. eth_log(EthWorkerProcessInit, "net info setted");
  300. eth_log(
  301. EthWorkerProcessInit,
  302. "mac: %02X-%02X-%02X-%02X-%02X-%02X",
  303. gWIZNETINFO.mac[0],
  304. gWIZNETINFO.mac[1],
  305. gWIZNETINFO.mac[2],
  306. gWIZNETINFO.mac[3],
  307. gWIZNETINFO.mac[4],
  308. gWIZNETINFO.mac[5]);
  309. worker->state = EthWorkerStateInited;
  310. continue;
  311. }
  312. } else if(worker->state == EthWorkerStateInited) {
  313. if(worker->next_state == EthWorkerStateDHCP) {
  314. worker->state = EthWorkerStateDHCP;
  315. if(!check_phylink(worker, EthWorkerStateDHCP, EthWorkerProcessDHCP, 5000)) {
  316. worker->state = EthWorkerStateInited;
  317. continue;
  318. }
  319. reg_dhcp_cbfunc(Callback_IPAssigned, Callback_IPAssigned, Callback_IPConflict);
  320. DHCP_init(DHCP_SOCKET, dhcp_buffer);
  321. uint8_t next_cycle = 1;
  322. uint8_t divider = 0;
  323. while(next_cycle && worker->state == EthWorkerStateDHCP) {
  324. uint8_t dhcp_ret = DHCP_run();
  325. switch(dhcp_ret) {
  326. case DHCP_IP_ASSIGN:
  327. case DHCP_IP_CHANGED:
  328. case DHCP_IP_LEASED:
  329. getIPfromDHCP(gWIZNETINFO.ip);
  330. getGWfromDHCP(gWIZNETINFO.gw);
  331. getSNfromDHCP(gWIZNETINFO.sn);
  332. getDNSfromDHCP(gWIZNETINFO.dns);
  333. gWIZNETINFO.dhcp = NETINFO_DHCP;
  334. ctlnetwork(CN_SET_NETINFO, (void*)&gWIZNETINFO);
  335. eth_log(
  336. EthWorkerProcessDHCP,
  337. "DHCP IP Leased Time : %ld Sec",
  338. getDHCPLeasetime());
  339. break;
  340. case DHCP_FAILED:
  341. eth_log(EthWorkerProcessDHCP, "DHCP Failed");
  342. break;
  343. }
  344. furi_delay_ms(100);
  345. if(divider++ % 10 == 0) {
  346. eth_log(EthWorkerProcessDHCP, "DHCP process %d", divider / 10);
  347. if(divider > 250) {
  348. DHCP_stop();
  349. eth_log(EthWorkerProcessDHCP, "DHCP Stop by timer");
  350. worker->state = EthWorkerStateInited;
  351. break;
  352. }
  353. }
  354. next_cycle = (dhcp_ret == DHCP_RUNNING);
  355. }
  356. if(worker->state != EthWorkerStateDHCP) {
  357. break;
  358. }
  359. //wizchip_getnetinfo(&gWIZNETINFO);
  360. eth_log(
  361. EthWorkerProcessDHCP,
  362. "IP address:\n %d.%d.%d.%d",
  363. gWIZNETINFO.ip[0],
  364. gWIZNETINFO.ip[1],
  365. gWIZNETINFO.ip[2],
  366. gWIZNETINFO.ip[3]);
  367. eth_log(
  368. EthWorkerProcessDHCP,
  369. "SM Mask:\n %d.%d.%d.%d",
  370. gWIZNETINFO.sn[0],
  371. gWIZNETINFO.sn[1],
  372. gWIZNETINFO.sn[2],
  373. gWIZNETINFO.sn[3]);
  374. eth_log(
  375. EthWorkerProcessDHCP,
  376. "Gate way:\n %d.%d.%d.%d",
  377. gWIZNETINFO.gw[0],
  378. gWIZNETINFO.gw[1],
  379. gWIZNETINFO.gw[2],
  380. gWIZNETINFO.gw[3]);
  381. eth_log(
  382. EthWorkerProcessDHCP,
  383. "DNS Server:\n %d.%d.%d.%d",
  384. gWIZNETINFO.dns[0],
  385. gWIZNETINFO.dns[1],
  386. gWIZNETINFO.dns[2],
  387. gWIZNETINFO.dns[3]);
  388. worker->state = EthWorkerStateOnline;
  389. }
  390. } else if(worker->state == EthWorkerStateOnline) {
  391. if(worker->next_state == EthWorkerStatePing) {
  392. worker->state = EthWorkerStatePing;
  393. uint8_t* adress = static_worker->config->ping_ip;
  394. eth_log(
  395. EthWorkerProcessPing,
  396. "ping %d.%d.%d.%d",
  397. adress[0],
  398. adress[1],
  399. adress[2],
  400. adress[3]);
  401. const uint8_t tryes = 4;
  402. uint8_t try = 0;
  403. while(try < tryes && worker->state == EthWorkerStatePing) {
  404. try++;
  405. uint32_t start_time = furi_get_tick();
  406. uint8_t res = ping_auto_interface(adress);
  407. uint32_t res_time = furi_get_tick();
  408. if(res == 3) {
  409. eth_log(
  410. EthWorkerProcessPing, "%d success %d ms", try, res_time - start_time);
  411. } else {
  412. eth_log(
  413. EthWorkerProcessPing,
  414. "%d error %d, %d",
  415. try,
  416. res,
  417. res_time - start_time);
  418. break;
  419. }
  420. }
  421. if(worker->state != EthWorkerStatePing) {
  422. break;
  423. }
  424. worker->state = EthWorkerStateOnline;
  425. worker->next_state = EthWorkerStateDefaultNext;
  426. } else {
  427. }
  428. }
  429. furi_delay_ms(50);
  430. }
  431. furi_hal_spi_release(&furi_hal_spi_bus_handle_external);
  432. furi_hal_power_disable_otg();
  433. furi_hal_power_insomnia_exit();
  434. return 0;
  435. }
  436. static void w5500_init() {
  437. furi_hal_spi_acquire(&furi_hal_spi_bus_handle_external);
  438. uint8_t W5500FifoSize[2][8] = {{2, 2, 2, 2, 2, 2, 2, 2}, {2, 2, 2, 2, 2, 2, 2, 2}};
  439. FURI_LOG_I(TAG, "Registering W5500 callbacks");
  440. reg_wizchip_spi_cbfunc(W5500_ReadByte, W5500_WriteByte);
  441. reg_wizchip_spiburst_cbfunc(W5500_ReadBuff, W5500_WriteBuff);
  442. reg_wizchip_cs_cbfunc(W5500_Select, W5500_Unselect);
  443. GpioPin resetpin = {.port = GPIOC, .pin = GPIO_PIN_3};
  444. furi_hal_gpio_write(&resetpin, true);
  445. furi_hal_gpio_write(&cspin, true);
  446. furi_hal_gpio_init(&resetpin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
  447. furi_hal_gpio_init(&cspin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
  448. }
  449. static void w5500_deinit() {
  450. furi_hal_spi_release(&furi_hal_spi_bus_handle_external);
  451. }
  452. void eth_worker_w5500(EthWorker* eth_worker) {
  453. furi_assert(eth_worker);
  454. //uint8_t temp;
  455. FURI_LOG_I(TAG, "Ehtping_Init");
  456. furi_hal_spi_acquire(&furi_hal_spi_bus_handle_external);
  457. uint8_t W5500FifoSize[2][8] = {{2, 2, 2, 2, 2, 2, 2, 2}, {2, 2, 2, 2, 2, 2, 2, 2}};
  458. FURI_LOG_I(TAG, "Registering W5500 callbacks");
  459. reg_wizchip_spi_cbfunc(W5500_ReadByte, W5500_WriteByte);
  460. reg_wizchip_spiburst_cbfunc(W5500_ReadBuff, W5500_WriteBuff);
  461. reg_wizchip_cs_cbfunc(W5500_Select, W5500_Unselect);
  462. FURI_LOG_I(TAG, "Registered W5500 callbacks");
  463. GpioPin resetpin = {.port = GPIOC, .pin = GPIO_PIN_3};
  464. furi_hal_gpio_write(&resetpin, true);
  465. furi_hal_gpio_write(&cspin, true);
  466. furi_hal_gpio_init(&resetpin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
  467. furi_hal_gpio_init(&cspin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
  468. FURI_LOG_I(TAG, "GPIO inited");
  469. furi_hal_power_enable_otg();
  470. furi_delay_ms(1000);
  471. //eth_worker->callback(EthCustomEventModulePowerOn, eth_worker->context);
  472. furi_delay_ms(2000);
  473. furi_hal_gpio_write(&resetpin, false);
  474. furi_delay_ms(10);
  475. furi_hal_gpio_write(&resetpin, true);
  476. FURI_LOG_I(TAG, "GPIO used");
  477. //eth_worker->callback(EthCustomEventModuleConnect, eth_worker->context);
  478. if(ctlwizchip(CW_INIT_WIZCHIP, (void*)W5500FifoSize) == -1) {
  479. FURI_LOG_I(TAG, "W5500 initialized fail.\r\n");
  480. //eth_worker->callback(EthCustomEventModuleError, eth_worker->context);
  481. }
  482. FURI_LOG_I(TAG, "W5500 initialized success.\r\n");
  483. furi_delay_ms(2000);
  484. wizchip_setnetinfo(&gWIZNETINFO);
  485. FURI_LOG_I(TAG, "W5500 info setted 1.\r\n");
  486. setSHAR(gWIZNETINFO.mac);
  487. FURI_LOG_I(TAG, "W5500 info setted 2.\r\n");
  488. //check phy status
  489. //do
  490. //{
  491. // if (ctlwizchip(CW_GET_PHYLINK, (void*)&temp) == -1)
  492. // {
  493. // FURI_LOG_I(TAG, "Unknown PHY link status.\r\n");
  494. // }
  495. // furi_delay_ms(1);
  496. //} while (temp == PHY_LINK_OFF);
  497. //FURI_LOG_I(TAG, "W5500 gWIZNETINFO success.\r\n");
  498. ////eth_worker->callback(EthCustomEventPHYConnect, eth_worker->context);
  499. FURI_LOG_I(TAG, "W5500 before delay\r\n");
  500. furi_delay_ms(2000);
  501. FURI_LOG_I(TAG, "W5500 after delay\r\n");
  502. //furi_hal_power_disable_otg();
  503. //FURI_LOG_I(TAG, "W5500 power off\r\n");
  504. ////eth_worker->callback(EthCustomEventModuleError, eth_worker->context);
  505. furi_delay_ms(2000);
  506. ////eth_worker->callback(EthCustomEventModuleConnected, eth_worker->context);
  507. furi_hal_spi_release(&furi_hal_spi_bus_handle_external);
  508. }