]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace(streaming)/trcTCPIPConfig.h
Update FreeRTOS+Trace recorder library to v3.0.2
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-Trace(streaming) / trcTCPIPConfig.h
1 /*******************************************************************************\r
2  * Trace Recorder Library for Tracealyzer v3.0.2\r
3  * Percepio AB, www.percepio.com\r
4  *\r
5  * trcTCPIPConfig.h\r
6  *\r
7  * Trace TCP/IP configuration. Modify these includes and functions to perform \r
8  * the same functionality using your specific TCP/IP stack.\r
9  * Will only be included by trcTCPIP.c.\r
10  *\r
11  * Terms of Use\r
12  * This software (the "Tracealyzer Recorder Library") is the intellectual\r
13  * property of Percepio AB and may not be sold or in other ways commercially\r
14  * redistributed without explicit written permission by Percepio AB.\r
15  *\r
16  * Separate conditions applies for the SEGGER branded source code included.\r
17  *\r
18  * The recorder library is free for use together with Percepio products.\r
19  * You may distribute the recorder library in its original form, but public\r
20  * distribution of modified versions require approval by Percepio AB.\r
21  *\r
22  * Disclaimer\r
23  * The trace tool and recorder library is being delivered to you AS IS and\r
24  * Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
25  * not and cannot warrant the performance or results you may obtain by using the\r
26  * software or documentation. Percepio AB make no warranties, express or\r
27  * implied, as to noninfringement of third party rights, merchantability, or\r
28  * fitness for any particular purpose. In no event will Percepio AB, its\r
29  * technology partners, or distributors be liable to you for any consequential,\r
30  * incidental or special damages, including any lost profits or lost savings,\r
31  * even if a representative of Percepio AB has been advised of the possibility\r
32  * of such damages, or for any claim by any third party. Some jurisdictions do\r
33  * not allow the exclusion or limitation of incidental, consequential or special\r
34  * damages, or the exclusion of implied warranties or limitations on how long an\r
35  * implied warranty may last, so the above limitations may not apply to you.\r
36  *\r
37  * Tabs are used for indent in this file (1 tab = 4 spaces)\r
38  *\r
39  * Copyright Percepio AB, 2015.\r
40  * www.percepio.com\r
41  ******************************************************************************/\r
42 \r
43 #ifndef TRC_TCPIP_CONFIG_H\r
44 #define TRC_TCPIP_CONFIG_H\r
45 \r
46 #ifdef __cplusplus\r
47 extern \93C\94 {\r
48 #endif\r
49 \r
50 /* TCP/IP includes*/\r
51 #include "tcpip.h"\r
52 \r
53 #define TRC_TCPIP_PORT 12000\r
54 \r
55 socket* sock = NULL;\r
56 socket* listenerSocket = NULL;\r
57 \r
58 int32_t trcSocketSend(void* data, int32_t size, int32_t* bytesWritten)\r
59 {\r
60   int32_t error;\r
61   if (sock == NULL)\r
62     return 1;\r
63   \r
64   error = socket_send(sock, data, size, (size_t*)bytesWritten, 0);\r
65   if (error)\r
66   {\r
67     socket_close(sock);\r
68     sock = NULL;\r
69   }\r
70   \r
71   return (int32_t)error;\r
72 }\r
73 \r
74 int32_t trcSocketReceive(void* data, int32_t size, int32_t* bytesRead)\r
75 {\r
76   int32_t error;\r
77   if (sock == NULL)\r
78     return 1;\r
79   \r
80   error = socket_receive(sock, data, size, (size_t*)bytesRead, SOCKET_WAIT_ALL);\r
81   if (error != ERROR_NONE && error != ERROR_TIMEOUT) /* Timeout may be expected when there is no data */\r
82   {\r
83     socket_close(sock);\r
84     sock = NULL;\r
85     return error;\r
86   }\r
87 \r
88   return 0;\r
89 }\r
90 \r
91 int32_t trcSocketInitializeListener()\r
92 {\r
93   int32_t error;\r
94   \r
95   if (listenerSocket)\r
96     return 0;\r
97   \r
98   //Start of exception handling block\r
99   do\r
100   {\r
101     listenerSocket = socket_open(SOCKET_STREAM, SOCKET_TCP);\r
102     if(listenerSocket == NULL)\r
103     {\r
104        error = 1;\r
105        break;\r
106     }\r
107 \r
108     error = socket_set_timeout(listenerSocket, INFINITE);\r
109     if(error) break;\r
110 \r
111     error = socket_set_tx_buffer_size(listenerSocket, 1440 * 2);\r
112     if(error) break;\r
113 \r
114     error = socket_set_rx_buffer_size(listenerSocket, 128);\r
115     if(error) break;\r
116 \r
117     error = socket_bind_to_interface(listenerSocket, pNetInterface);\r
118     if(error) break;\r
119 \r
120     error = socket_bind(listenerSocket, ADDR_ANY, TRC_TCPIP_PORT);\r
121     if(error) break;\r
122 \r
123     error = socket_listen(listenerSocket);\r
124     if(error) break;\r
125     } while(0);\r
126 \r
127     if(error)\r
128     {\r
129         socket_close(listenerSocket);\r
130         listenerSocket = NULL;\r
131     }\r
132    \r
133     return error;\r
134 }\r
135 \r
136 int32_t trcSocketAccept()\r
137 {\r
138   ip_addr clientIpAddr;\r
139   uint16_t clientPort;\r
140   \r
141   if (sock != NULL)\r
142     return 0;\r
143 \r
144   if (listenerSocket == NULL)\r
145     return 1;\r
146   \r
147   /* Wait for connection */\r
148   sock = socket_accept(listenerSocket, &clientIpAddr, &clientPort);\r
149   if(sock != NULL)\r
150   {\r
151     socket_set_timeout(sock, 20);\r
152   }\r
153   else\r
154     return 1;\r
155   \r
156   return 0;\r
157 }\r
158 \r
159 #ifdef __cplusplus\r
160 }\r
161 #endif\r
162 \r
163 #endif /*TRC_TCPIP_CONFIG_H*/