Advertisement
Guest User

Untitled

a guest
Jun 16th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.68 KB | None | 0 0
  1. // socket.h
  2.  
  3. struct skt_t {
  4.     uint8_t         *dst_mac;
  5.     uint8_t         *dst_ip;
  6.     uint16_t  base_addr;
  7.     uint16_t  tx_reg_addr;
  8.     uint16_t  rx_reg_addr;
  9.     uint16_t        src_port;
  10.     uint16_t        dst_port;
  11.     uint8_t   id;
  12.     socket_sts      status;
  13.     socket_protocol protocol;
  14.     uint8_t         tx_memory_kb;
  15.     uint8_t         rx_memory_kb;
  16.     uint8_t         imr;
  17. } skt_t;
  18.  
  19. void W5500_socket_init(struct skt_t *skt, socket_id socket, socket_protocol mode);
  20. void W5500_socket_open(struct skt_t *skt);
  21.  
  22. // socket.c
  23.  
  24. struct skt_t _skt[8];
  25.  
  26. void W5500_socket_init(struct skt_t *skt, socket_id socket, socket_protocol mode)
  27. {
  28.     // pointing to the 'socket' element on the _skt struct
  29.     skt = &_skt[socket];
  30.     // changing the configuration
  31.     skt->base_addr      = SKT_SOCKET_BASE(socket);
  32.     skt->tx_reg_addr    = SKT_TX_BASE(socket);
  33.     skt->rx_reg_addr    = SKT_RX_BASE(socket);
  34.     skt->src_port       = 0x0000;
  35.     skt->status         = SOCKET_STS_CLOSED;
  36.     skt->protocol       = mode;
  37.     skt->tx_memory_kb   = 2;
  38.     skt->rx_memory_kb   = 2;
  39. }
  40.  
  41. // here i'm trying to access a member of the skt_t struct array i previously
  42. // accessed
  43. void W5500_socket_open(struct skt_t *skt)
  44. {
  45.     if (skt->protocol == SOCKET_MODE_TCP) {
  46.         LED_Write(1);
  47.     }
  48. }
  49.  
  50. // main.c
  51.  
  52. // tcp_server will be a pointer to a member of the _skt struct array
  53. struct skt_t *tcp_server;
  54.  
  55. int main(void)
  56. {
  57.     // with this function i set _skt[0].protocol to SOCKET_MODE_TCP
  58.     W5500_socket_init(tcp_server, 0, SOCKET_MODE_TCP);
  59.  
  60.     // after this function LED should be turned on
  61.     // but it doesn't
  62.     W5500_socket_open(tcp_server);
  63.  
  64.     while (1) {
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement