Ethernet_Test.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Ethernet_Test.c
  3. *
  4. * Created on: 2020¦~4¤ë21¤é
  5. * Author: Wendell
  6. */
  7. #include "Ethernet_Test.h"
  8. #include "IO_Test.h"
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <unistd.h> //write, close, usleep, read
  12. #include <string.h>
  13. void InitEthernetResetIO(void)
  14. {
  15. /*MCASP0_ACLKX => GPIO3_14*//*Ethernet PHY reset*/
  16. gpio_set_direction(PIN_ETHERNET_RESET, GPIO_DIR_OUTPUT);
  17. gpio_write(PIN_ETHERNET_RESET, 0);
  18. usleep(100000);
  19. gpio_write(PIN_ETHERNET_RESET, 1);
  20. usleep(100000);
  21. }
  22. void EthernetDown(int channel)
  23. {
  24. char tmpbuf[256];
  25. memset(tmpbuf, 0, 256);
  26. sprintf(tmpbuf, "/sbin/ifconfig eth%d down", channel > 0 ? 1 : 0);
  27. system(tmpbuf);
  28. }
  29. void InitEthernet0(void)
  30. {
  31. char tmpbuf[256];
  32. //Init Eth0 for internet
  33. memset(tmpbuf, 0, 256);
  34. sprintf(tmpbuf, "/sbin/ifconfig eth0 %s netmask %s up", "192.168.1.10", "255.255.255.0");
  35. system(tmpbuf);
  36. //memset(tmpbuf,0,256);
  37. //sprintf(tmpbuf,"route add default gw %s eth0 ", "192.168.1.254");
  38. //system(tmpbuf);
  39. }
  40. void InitEthernet1(void)
  41. {
  42. char tmpbuf[256];
  43. //Init Eth1 for administrator tool
  44. memset(tmpbuf, 0, 256);
  45. sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up", "192.168.1.20", "255.255.255.0");
  46. system(tmpbuf);
  47. //memset(tmpbuf,0,256);
  48. //sprintf(tmpbuf,"route add default gw %s eth1 ", "192.168.1.254");
  49. //system(tmpbuf);
  50. }
  51. void DoEthernet0Test(void)
  52. {
  53. InitEthernetResetIO();
  54. EthernetDown(0);
  55. EthernetDown(1);
  56. InitEthernet0();
  57. printf("\r\nEthernet 0 Test Done!");
  58. printf("\r\nSuccess!\r\n");
  59. }
  60. void DoEthernet1Test(void)
  61. {
  62. InitEthernetResetIO();
  63. EthernetDown(0);
  64. EthernetDown(1);
  65. InitEthernet1();
  66. printf("\r\nEthernet 1 Test Done!");
  67. printf("\r\nSuccess!\r\n");
  68. }