* @brief This Socket function initialize the channel in perticular mode, and set the port and wait for w5500 done it. * @return 1 for success else 0. */
| 14 | * @return 1 for success else 0. |
| 15 | */ |
| 16 | uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag) |
| 17 | { |
| 18 | if ((protocol == SnMR::TCP) || (protocol == SnMR::UDP) || (protocol == SnMR::IPRAW) || (protocol == SnMR::MACRAW) || (protocol == SnMR::PPPOE)) |
| 19 | { |
| 20 | close(s); |
| 21 | w5500.writeSnMR(s, protocol | flag); |
| 22 | if (port != 0) { |
| 23 | w5500.writeSnPORT(s, port); |
| 24 | } |
| 25 | else { |
| 26 | local_port++; // if don't set the source port, set local_port number. |
| 27 | w5500.writeSnPORT(s, local_port); |
| 28 | } |
| 29 | |
| 30 | w5500.execCmdSn(s, Sock_OPEN); |
| 31 | |
| 32 | return 1; |
| 33 | } |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | |
| 39 | /** |