mirror of
https://github.com/FreeRTOS/FreeRTOS.git
synced 2025-06-10 09:48:39 +08:00
Fix Posix demo build and remove src directory (#213)
* Fix: build errors, remove src directory and bring all files up * Fix: Remove not needed header * Doc: fix main comments * Doc: fix comment Co-authored-by: Alfred Gedeon <gedeonag@amazon.com>
This commit is contained in:
@ -44,7 +44,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <sys/sysinfo.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <pcap.h>
|
#include <pcap.h>
|
||||||
|
|
||||||
|
@ -1,307 +1,307 @@
|
|||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.3.0
|
* FreeRTOS Kernel V10.3.0
|
||||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
* the Software without restriction, including without limitation the rights to
|
* the Software without restriction, including without limitation the rights to
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
* subject to the following conditions:
|
* subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
* copies or substantial portions of the Software.
|
* copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* http://www.FreeRTOS.org
|
* http://www.FreeRTOS.org
|
||||||
* http://aws.amazon.com/freertos
|
* http://aws.amazon.com/freertos
|
||||||
*
|
*
|
||||||
* 1 tab == 4 spaces!
|
* 1 tab == 4 spaces!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* See the following URL for configuration information.
|
* See the following URL for configuration information.
|
||||||
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
|
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#ifndef FREERTOS_IP_CONFIG_H
|
#ifndef FREERTOS_IP_CONFIG_H
|
||||||
#define FREERTOS_IP_CONFIG_H
|
#define FREERTOS_IP_CONFIG_H
|
||||||
|
|
||||||
/* Prototype for the function used to print out. In this case it prints to the
|
/* Prototype for the function used to print out. In this case it prints to the
|
||||||
console before the network is connected then a UDP port after the network has
|
console before the network is connected then a UDP port after the network has
|
||||||
connected. */
|
connected. */
|
||||||
extern void vLoggingPrintf( const char *pcFormatString, ... );
|
extern void vLoggingPrintf( const char *pcFormatString, ... );
|
||||||
|
|
||||||
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
|
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
|
||||||
1 then FreeRTOS_debug_printf should be defined to the function used to print
|
1 then FreeRTOS_debug_printf should be defined to the function used to print
|
||||||
out the debugging messages. */
|
out the debugging messages. */
|
||||||
#define ipconfigHAS_DEBUG_PRINTF 1
|
#define ipconfigHAS_DEBUG_PRINTF 1
|
||||||
#if( ipconfigHAS_DEBUG_PRINTF == 1 )
|
#if( ipconfigHAS_DEBUG_PRINTF == 1 )
|
||||||
#define FreeRTOS_debug_printf(X) vLoggingPrintf X
|
#define FreeRTOS_debug_printf(X) vLoggingPrintf X
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Set to 1 to print out non debugging messages, for example the output of the
|
/* Set to 1 to print out non debugging messages, for example the output of the
|
||||||
FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
|
FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
|
||||||
then FreeRTOS_printf should be set to the function used to print out the
|
then FreeRTOS_printf should be set to the function used to print out the
|
||||||
messages. */
|
messages. */
|
||||||
#define ipconfigHAS_PRINTF 1
|
#define ipconfigHAS_PRINTF 0
|
||||||
#if( ipconfigHAS_PRINTF == 1 )
|
#if( ipconfigHAS_PRINTF == 1 )
|
||||||
#define FreeRTOS_printf(X) vLoggingPrintf X
|
#define FreeRTOS_printf(X) vLoggingPrintf X
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
|
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
|
||||||
on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
|
on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
|
||||||
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
|
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
|
||||||
|
|
||||||
/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums)
|
/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums)
|
||||||
then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
|
then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
|
||||||
stack repeating the checksum calculations. */
|
stack repeating the checksum calculations. */
|
||||||
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
|
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
|
||||||
|
|
||||||
/* Several API's will block until the result is known, or the action has been
|
/* Several API's will block until the result is known, or the action has been
|
||||||
performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
|
performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
|
||||||
set per socket, using setsockopt(). If not set, the times below will be
|
set per socket, using setsockopt(). If not set, the times below will be
|
||||||
used as defaults. */
|
used as defaults. */
|
||||||
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
|
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
|
||||||
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
|
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
|
||||||
|
|
||||||
/* Include support for LLMNR: Link-local Multicast Name Resolution
|
/* Include support for LLMNR: Link-local Multicast Name Resolution
|
||||||
(non-Microsoft) */
|
(non-Microsoft) */
|
||||||
#define ipconfigUSE_LLMNR ( 1 )
|
#define ipconfigUSE_LLMNR ( 1 )
|
||||||
|
|
||||||
/* Include support for NBNS: NetBIOS Name Service (Microsoft) */
|
/* Include support for NBNS: NetBIOS Name Service (Microsoft) */
|
||||||
#define ipconfigUSE_NBNS ( 1 )
|
#define ipconfigUSE_NBNS ( 1 )
|
||||||
|
|
||||||
/* Include support for DNS caching. For TCP, having a small DNS cache is very
|
/* Include support for DNS caching. For TCP, having a small DNS cache is very
|
||||||
useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
|
useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
|
||||||
and also DNS may use small timeouts. If a DNS reply comes in after the DNS
|
and also DNS may use small timeouts. If a DNS reply comes in after the DNS
|
||||||
socket has been destroyed, the result will be stored into the cache. The next
|
socket has been destroyed, the result will be stored into the cache. The next
|
||||||
call to FreeRTOS_gethostbyname() will return immediately, without even creating
|
call to FreeRTOS_gethostbyname() will return immediately, without even creating
|
||||||
a socket. */
|
a socket. */
|
||||||
#define ipconfigUSE_DNS_CACHE ( 1 )
|
#define ipconfigUSE_DNS_CACHE ( 1 )
|
||||||
#define ipconfigDNS_CACHE_NAME_LENGTH ( 16 )
|
#define ipconfigDNS_CACHE_NAME_LENGTH ( 16 )
|
||||||
#define ipconfigDNS_CACHE_ENTRIES ( 4 )
|
#define ipconfigDNS_CACHE_ENTRIES ( 4 )
|
||||||
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
|
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
|
||||||
|
|
||||||
/* The IP stack executes it its own task (although any application task can make
|
/* The IP stack executes it its own task (although any application task can make
|
||||||
use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
|
use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
|
||||||
sets the priority of the task that executes the IP stack. The priority is a
|
sets the priority of the task that executes the IP stack. The priority is a
|
||||||
standard FreeRTOS task priority so can take any value from 0 (the lowest
|
standard FreeRTOS task priority so can take any value from 0 (the lowest
|
||||||
priority) to (configMAX_PRIORITIES - 1) (the highest priority).
|
priority) to (configMAX_PRIORITIES - 1) (the highest priority).
|
||||||
configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
|
configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
|
||||||
FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
|
FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
|
||||||
the priority assigned to the task executing the IP stack relative to the
|
the priority assigned to the task executing the IP stack relative to the
|
||||||
priority assigned to tasks that use the IP stack. */
|
priority assigned to tasks that use the IP stack. */
|
||||||
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
|
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
|
||||||
|
|
||||||
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
|
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
|
||||||
task. This setting is less important when the FreeRTOS Win32 simulator is used
|
task. This setting is less important when the FreeRTOS Win32 simulator is used
|
||||||
as the Win32 simulator only stores a fixed amount of information on the task
|
as the Win32 simulator only stores a fixed amount of information on the task
|
||||||
stack. FreeRTOS includes optional stack overflow detection, see:
|
stack. FreeRTOS includes optional stack overflow detection, see:
|
||||||
http://www.freertos.org/Stacks-and-stack-overflow-checking.html */
|
http://www.freertos.org/Stacks-and-stack-overflow-checking.html */
|
||||||
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
|
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
|
||||||
|
|
||||||
/* ipconfigRAND32() is called by the IP stack to generate random numbers for
|
/* ipconfigRAND32() is called by the IP stack to generate random numbers for
|
||||||
things such as a DHCP transaction number or initial sequence number. Random
|
things such as a DHCP transaction number or initial sequence number. Random
|
||||||
number generation is performed via this macro to allow applications to use their
|
number generation is performed via this macro to allow applications to use their
|
||||||
own random number generation method. For example, it might be possible to
|
own random number generation method. For example, it might be possible to
|
||||||
generate a random number by sampling noise on an analogue input. */
|
generate a random number by sampling noise on an analogue input. */
|
||||||
extern UBaseType_t uxRand();
|
extern UBaseType_t uxRand();
|
||||||
#define ipconfigRAND32() uxRand()
|
#define ipconfigRAND32() uxRand()
|
||||||
|
|
||||||
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
|
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
|
||||||
network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
|
network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
|
||||||
is not set to 1 then the network event hook will never be called. See
|
is not set to 1 then the network event hook will never be called. See
|
||||||
http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/API/vApplicationIPNetworkEventHook.shtml
|
http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/API/vApplicationIPNetworkEventHook.shtml
|
||||||
*/
|
*/
|
||||||
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
|
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
|
||||||
|
|
||||||
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
|
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
|
||||||
a network buffer cannot be obtained then the calling task is held in the Blocked
|
a network buffer cannot be obtained then the calling task is held in the Blocked
|
||||||
state (so other tasks can continue to executed) until either a network buffer
|
state (so other tasks can continue to executed) until either a network buffer
|
||||||
becomes available or the send block time expires. If the send block time expires
|
becomes available or the send block time expires. If the send block time expires
|
||||||
then the send operation is aborted. The maximum allowable send block time is
|
then the send operation is aborted. The maximum allowable send block time is
|
||||||
capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
|
capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
|
||||||
maximum allowable send block time prevents prevents a deadlock occurring when
|
maximum allowable send block time prevents prevents a deadlock occurring when
|
||||||
all the network buffers are in use and the tasks that process (and subsequently
|
all the network buffers are in use and the tasks that process (and subsequently
|
||||||
free) the network buffers are themselves blocked waiting for a network buffer.
|
free) the network buffers are themselves blocked waiting for a network buffer.
|
||||||
ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
|
ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
|
||||||
milliseconds can be converted to a time in ticks by dividing the time in
|
milliseconds can be converted to a time in ticks by dividing the time in
|
||||||
milliseconds by portTICK_PERIOD_MS. */
|
milliseconds by portTICK_PERIOD_MS. */
|
||||||
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS )
|
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS )
|
||||||
|
|
||||||
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
|
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
|
||||||
address, netmask, DNS server address and gateway address from a DHCP server. If
|
address, netmask, DNS server address and gateway address from a DHCP server. If
|
||||||
ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
|
ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
|
||||||
stack will revert to using the static IP address even when ipconfigUSE_DHCP is
|
stack will revert to using the static IP address even when ipconfigUSE_DHCP is
|
||||||
set to 1 if a valid configuration cannot be obtained from a DHCP server for any
|
set to 1 if a valid configuration cannot be obtained from a DHCP server for any
|
||||||
reason. The static configuration used is that passed into the stack by the
|
reason. The static configuration used is that passed into the stack by the
|
||||||
FreeRTOS_IPInit() function call. */
|
FreeRTOS_IPInit() function call. */
|
||||||
#define ipconfigUSE_DHCP 0
|
#define ipconfigUSE_DHCP 0
|
||||||
|
|
||||||
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
|
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
|
||||||
increasing time intervals until either a reply is received from a DHCP server
|
increasing time intervals until either a reply is received from a DHCP server
|
||||||
and accepted, or the interval between transmissions reaches
|
and accepted, or the interval between transmissions reaches
|
||||||
ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
|
ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
|
||||||
static IP address passed as a parameter to FreeRTOS_IPInit() if the
|
static IP address passed as a parameter to FreeRTOS_IPInit() if the
|
||||||
re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
|
re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
|
||||||
a DHCP reply being received. */
|
a DHCP reply being received. */
|
||||||
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD ( 120000U / portTICK_PERIOD_MS )
|
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD ( 120000U / portTICK_PERIOD_MS )
|
||||||
|
|
||||||
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
|
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
|
||||||
stack can only send a UDP message to a remove IP address if it knowns the MAC
|
stack can only send a UDP message to a remove IP address if it knowns the MAC
|
||||||
address associated with the IP address, or the MAC address of the router used to
|
address associated with the IP address, or the MAC address of the router used to
|
||||||
contact the remote IP address. When a UDP message is received from a remote IP
|
contact the remote IP address. When a UDP message is received from a remote IP
|
||||||
address the MAC address and IP address are added to the ARP cache. When a UDP
|
address the MAC address and IP address are added to the ARP cache. When a UDP
|
||||||
message is sent to a remote IP address that does not already appear in the ARP
|
message is sent to a remote IP address that does not already appear in the ARP
|
||||||
cache then the UDP message is replaced by a ARP message that solicits the
|
cache then the UDP message is replaced by a ARP message that solicits the
|
||||||
required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
|
required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
|
||||||
number of entries that can exist in the ARP table at any one time. */
|
number of entries that can exist in the ARP table at any one time. */
|
||||||
#define ipconfigARP_CACHE_ENTRIES 6
|
#define ipconfigARP_CACHE_ENTRIES 6
|
||||||
|
|
||||||
/* ARP requests that do not result in an ARP response will be re-transmitted a
|
/* ARP requests that do not result in an ARP response will be re-transmitted a
|
||||||
maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
|
maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
|
||||||
aborted. */
|
aborted. */
|
||||||
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
|
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
|
||||||
|
|
||||||
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
|
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
|
||||||
table being created or refreshed and the entry being removed because it is stale.
|
table being created or refreshed and the entry being removed because it is stale.
|
||||||
New ARP requests are sent for ARP cache entries that are nearing their maximum
|
New ARP requests are sent for ARP cache entries that are nearing their maximum
|
||||||
age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
|
age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
|
||||||
equal to 1500 seconds (or 25 minutes). */
|
equal to 1500 seconds (or 25 minutes). */
|
||||||
#define ipconfigMAX_ARP_AGE 150
|
#define ipconfigMAX_ARP_AGE 150
|
||||||
|
|
||||||
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
|
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
|
||||||
routines, which are relatively large. To save code space the full
|
routines, which are relatively large. To save code space the full
|
||||||
FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
|
FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
|
||||||
alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
|
alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
|
||||||
takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
|
takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
|
||||||
FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
|
FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
|
||||||
(for example, 192, 168, 0, 1) as its parameters. If
|
(for example, 192, 168, 0, 1) as its parameters. If
|
||||||
ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
|
ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
|
||||||
FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
|
FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
|
||||||
not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
|
not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
|
||||||
#define ipconfigINCLUDE_FULL_INET_ADDR 1
|
#define ipconfigINCLUDE_FULL_INET_ADDR 1
|
||||||
|
|
||||||
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
|
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
|
||||||
are available to the IP stack. The total number of network buffers is limited
|
are available to the IP stack. The total number of network buffers is limited
|
||||||
to ensure the total amount of RAM that can be consumed by the IP stack is capped
|
to ensure the total amount of RAM that can be consumed by the IP stack is capped
|
||||||
to a pre-determinable value. */
|
to a pre-determinable value. */
|
||||||
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
|
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
|
||||||
|
|
||||||
/* A FreeRTOS queue is used to send events from application tasks to the IP
|
/* A FreeRTOS queue is used to send events from application tasks to the IP
|
||||||
stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
|
stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
|
||||||
be queued for processing at any one time. The event queue must be a minimum of
|
be queued for processing at any one time. The event queue must be a minimum of
|
||||||
5 greater than the total number of network buffers. */
|
5 greater than the total number of network buffers. */
|
||||||
#define ipconfigEVENT_QUEUE_LENGTH ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
|
#define ipconfigEVENT_QUEUE_LENGTH ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
|
||||||
|
|
||||||
/* The address of a socket is the combination of its IP address and its port
|
/* The address of a socket is the combination of its IP address and its port
|
||||||
number. FreeRTOS_bind() is used to manually allocate a port number to a socket
|
number. FreeRTOS_bind() is used to manually allocate a port number to a socket
|
||||||
(to 'bind' the socket to a port), but manual binding is not normally necessary
|
(to 'bind' the socket to a port), but manual binding is not normally necessary
|
||||||
for client sockets (those sockets that initiate outgoing connections rather than
|
for client sockets (those sockets that initiate outgoing connections rather than
|
||||||
wait for incoming connections on a known port number). If
|
wait for incoming connections on a known port number). If
|
||||||
ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
|
ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
|
||||||
FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
|
FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
|
||||||
stack automatically binding the socket to a port number from the range
|
stack automatically binding the socket to a port number from the range
|
||||||
socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
|
socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
|
||||||
ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
|
ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
|
||||||
on a socket that has not yet been bound will result in the send operation being
|
on a socket that has not yet been bound will result in the send operation being
|
||||||
aborted. */
|
aborted. */
|
||||||
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
|
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
|
||||||
|
|
||||||
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
|
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
|
||||||
#define ipconfigUDP_TIME_TO_LIVE 128
|
#define ipconfigUDP_TIME_TO_LIVE 128
|
||||||
#define ipconfigTCP_TIME_TO_LIVE 128 /* also defined in FreeRTOSIPConfigDefaults.h */
|
#define ipconfigTCP_TIME_TO_LIVE 128 /* also defined in FreeRTOSIPConfigDefaults.h */
|
||||||
|
|
||||||
/* USE_TCP: Use TCP and all its features */
|
/* USE_TCP: Use TCP and all its features */
|
||||||
#define ipconfigUSE_TCP ( 1 )
|
#define ipconfigUSE_TCP ( 1 )
|
||||||
|
|
||||||
/* USE_WIN: Let TCP use windowing mechanism. */
|
/* USE_WIN: Let TCP use windowing mechanism. */
|
||||||
#define ipconfigUSE_TCP_WIN ( 1 )
|
#define ipconfigUSE_TCP_WIN ( 1 )
|
||||||
|
|
||||||
/* The MTU is the maximum number of bytes the payload of a network frame can
|
/* The MTU is the maximum number of bytes the payload of a network frame can
|
||||||
contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
|
contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
|
||||||
lower value can save RAM, depending on the buffer management scheme used. If
|
lower value can save RAM, depending on the buffer management scheme used. If
|
||||||
ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
|
ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
|
||||||
be divisible by 8. */
|
be divisible by 8. */
|
||||||
#define ipconfigNETWORK_MTU 1200U
|
#define ipconfigNETWORK_MTU 1200U
|
||||||
|
|
||||||
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
|
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
|
||||||
through the FreeRTOS_gethostbyname() API function. */
|
through the FreeRTOS_gethostbyname() API function. */
|
||||||
#define ipconfigUSE_DNS 1
|
#define ipconfigUSE_DNS 1
|
||||||
|
|
||||||
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
|
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
|
||||||
generate replies to incoming ICMP echo (ping) requests. */
|
generate replies to incoming ICMP echo (ping) requests. */
|
||||||
#define ipconfigREPLY_TO_INCOMING_PINGS 1
|
#define ipconfigREPLY_TO_INCOMING_PINGS 1
|
||||||
|
|
||||||
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
|
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
|
||||||
FreeRTOS_SendPingRequest() API function is available. */
|
FreeRTOS_SendPingRequest() API function is available. */
|
||||||
#define ipconfigSUPPORT_OUTGOING_PINGS 0
|
#define ipconfigSUPPORT_OUTGOING_PINGS 0
|
||||||
|
|
||||||
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
|
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
|
||||||
(and associated) API function is available. */
|
(and associated) API function is available. */
|
||||||
#define ipconfigSUPPORT_SELECT_FUNCTION 1
|
#define ipconfigSUPPORT_SELECT_FUNCTION 1
|
||||||
|
|
||||||
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
|
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
|
||||||
that are not in Ethernet II format will be dropped. This option is included for
|
that are not in Ethernet II format will be dropped. This option is included for
|
||||||
potential future IP stack developments. */
|
potential future IP stack developments. */
|
||||||
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
|
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
|
||||||
|
|
||||||
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
|
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
|
||||||
responsibility of the Ethernet interface to filter out packets that are of no
|
responsibility of the Ethernet interface to filter out packets that are of no
|
||||||
interest. If the Ethernet interface does not implement this functionality, then
|
interest. If the Ethernet interface does not implement this functionality, then
|
||||||
set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
|
set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
|
||||||
perform the filtering instead (it is much less efficient for the stack to do it
|
perform the filtering instead (it is much less efficient for the stack to do it
|
||||||
because the packet will already have been passed into the stack). If the
|
because the packet will already have been passed into the stack). If the
|
||||||
Ethernet driver does all the necessary filtering in hardware then software
|
Ethernet driver does all the necessary filtering in hardware then software
|
||||||
filtering can be removed by using a value other than 1 or 0. */
|
filtering can be removed by using a value other than 1 or 0. */
|
||||||
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
|
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
|
||||||
|
|
||||||
/* The windows simulator cannot really simulate MAC interrupts, and needs to
|
/* The windows simulator cannot really simulate MAC interrupts, and needs to
|
||||||
block occasionally to allow other tasks to run. */
|
block occasionally to allow other tasks to run. */
|
||||||
#define configWINDOWS_MAC_INTERRUPT_SIMULATOR_DELAY ( 20 / portTICK_PERIOD_MS )
|
#define configWINDOWS_MAC_INTERRUPT_SIMULATOR_DELAY ( 20 / portTICK_PERIOD_MS )
|
||||||
|
|
||||||
/* Advanced only: in order to access 32-bit fields in the IP packets with
|
/* Advanced only: in order to access 32-bit fields in the IP packets with
|
||||||
32-bit memory instructions, all packets will be stored 32-bit-aligned, plus 16-bits.
|
32-bit memory instructions, all packets will be stored 32-bit-aligned, plus 16-bits.
|
||||||
This has to do with the contents of the IP-packets: all 32-bit fields are
|
This has to do with the contents of the IP-packets: all 32-bit fields are
|
||||||
32-bit-aligned, plus 16-bit(!) */
|
32-bit-aligned, plus 16-bit(!) */
|
||||||
#define ipconfigPACKET_FILLER_SIZE 2U
|
#define ipconfigPACKET_FILLER_SIZE 2U
|
||||||
|
|
||||||
/* Define the size of the pool of TCP window descriptors. On the average, each
|
/* Define the size of the pool of TCP window descriptors. On the average, each
|
||||||
TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
|
TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
|
||||||
outstanding packets (for Rx and Tx). When using up to 10 TP sockets
|
outstanding packets (for Rx and Tx). When using up to 10 TP sockets
|
||||||
simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
|
simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
|
||||||
#define ipconfigTCP_WIN_SEG_COUNT 240
|
#define ipconfigTCP_WIN_SEG_COUNT 240
|
||||||
|
|
||||||
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
|
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
|
||||||
maximum size. Define the size of Rx buffer for TCP sockets. */
|
maximum size. Define the size of Rx buffer for TCP sockets. */
|
||||||
#define ipconfigTCP_RX_BUFFER_LENGTH ( 1000 )
|
#define ipconfigTCP_RX_BUFFER_LENGTH ( 1000 )
|
||||||
|
|
||||||
/* Define the size of Tx buffer for TCP sockets. */
|
/* Define the size of Tx buffer for TCP sockets. */
|
||||||
#define ipconfigTCP_TX_BUFFER_LENGTH ( 1000 )
|
#define ipconfigTCP_TX_BUFFER_LENGTH ( 1000 )
|
||||||
|
|
||||||
/* When using call-back handlers, the driver may check if the handler points to
|
/* When using call-back handlers, the driver may check if the handler points to
|
||||||
real program memory (RAM or flash) or just has a random non-zero value. */
|
real program memory (RAM or flash) or just has a random non-zero value. */
|
||||||
#define ipconfigIS_VALID_PROG_ADDRESS(x) ( (x) != NULL )
|
#define ipconfigIS_VALID_PROG_ADDRESS(x) ( (x) != NULL )
|
||||||
|
|
||||||
/* Include support for TCP hang protection. All sockets in a connecting or
|
/* Include support for TCP hang protection. All sockets in a connecting or
|
||||||
disconnecting stage will timeout after a period of non-activity. */
|
disconnecting stage will timeout after a period of non-activity. */
|
||||||
#define ipconfigTCP_HANG_PROTECTION ( 1 )
|
#define ipconfigTCP_HANG_PROTECTION ( 1 )
|
||||||
#define ipconfigTCP_HANG_PROTECTION_TIME ( 30 )
|
#define ipconfigTCP_HANG_PROTECTION_TIME ( 30 )
|
||||||
|
|
||||||
/* Include support for TCP keep-alive messages. */
|
/* Include support for TCP keep-alive messages. */
|
||||||
#define ipconfigTCP_KEEP_ALIVE ( 1 )
|
#define ipconfigTCP_KEEP_ALIVE ( 1 )
|
||||||
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* in seconds */
|
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* in seconds */
|
||||||
|
|
||||||
#define portINLINE __inline
|
#define portINLINE __inline
|
||||||
|
|
||||||
#endif /* FREERTOS_IP_CONFIG_H */
|
#endif /* FREERTOS_IP_CONFIG_H */
|
@ -27,10 +27,10 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
# Create a symlink to the FreeRTOS sources.
|
# Create a symlink to the FreeRTOS sources.
|
||||||
if not os.path.exists("src/FreeRTOS"):
|
if not os.path.exists("FreeRTOS"):
|
||||||
os.symlink("../../..", "src/FreeRTOS")
|
os.symlink("../..", "FreeRTOS")
|
||||||
if not os.path.exists("src/FreeRTOS-Plus"):
|
if not os.path.exists("FreeRTOS-Plus"):
|
||||||
os.symlink("../../../../FreeRTOS-Plus", "src/FreeRTOS-Plus")
|
os.symlink("../../../FreeRTOS-Plus", "FreeRTOS-Plus")
|
||||||
|
|
||||||
AddOption("--simple",
|
AddOption("--simple",
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -49,4 +49,4 @@ env.Append(CFLAGS = [
|
|||||||
"-O2",
|
"-O2",
|
||||||
])
|
])
|
||||||
|
|
||||||
SConscript("src/SConscript", variant_dir="build", duplicate=0)
|
SConscript("./SConscript", variant_dir="build", duplicate=0)
|
||||||
|
@ -1,288 +1,288 @@
|
|||||||
/*
|
/*
|
||||||
FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
|
FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
|
||||||
All rights reserved
|
All rights reserved
|
||||||
|
|
||||||
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||||
|
|
||||||
This file is part of the FreeRTOS distribution.
|
This file is part of the FreeRTOS distribution.
|
||||||
|
|
||||||
FreeRTOS is free software; you can redistribute it and/or modify it under
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||||
the terms of the GNU General Public License (version 2) as published by the
|
the terms of the GNU General Public License (version 2) as published by the
|
||||||
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
||||||
|
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
>>! NOTE: The modification to the GPL is included to allow you to !<<
|
>>! NOTE: The modification to the GPL is included to allow you to !<<
|
||||||
>>! distribute a combined work that includes FreeRTOS without being !<<
|
>>! distribute a combined work that includes FreeRTOS without being !<<
|
||||||
>>! obliged to provide the source code for proprietary components !<<
|
>>! obliged to provide the source code for proprietary components !<<
|
||||||
>>! outside of the FreeRTOS kernel. !<<
|
>>! outside of the FreeRTOS kernel. !<<
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
|
|
||||||
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
FOR A PARTICULAR PURPOSE. Full license text is available on the following
|
FOR A PARTICULAR PURPOSE. Full license text is available on the following
|
||||||
link: http://www.freertos.org/a00114.html
|
link: http://www.freertos.org/a00114.html
|
||||||
|
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
* *
|
* *
|
||||||
* FreeRTOS provides completely free yet professionally developed, *
|
* FreeRTOS provides completely free yet professionally developed, *
|
||||||
* robust, strictly quality controlled, supported, and cross *
|
* robust, strictly quality controlled, supported, and cross *
|
||||||
* platform software that is more than just the market leader, it *
|
* platform software that is more than just the market leader, it *
|
||||||
* is the industry's de facto standard. *
|
* is the industry's de facto standard. *
|
||||||
* *
|
* *
|
||||||
* Help yourself get started quickly while simultaneously helping *
|
* Help yourself get started quickly while simultaneously helping *
|
||||||
* to support the FreeRTOS project by purchasing a FreeRTOS *
|
* to support the FreeRTOS project by purchasing a FreeRTOS *
|
||||||
* tutorial book, reference manual, or both: *
|
* tutorial book, reference manual, or both: *
|
||||||
* http://www.FreeRTOS.org/Documentation *
|
* http://www.FreeRTOS.org/Documentation *
|
||||||
* *
|
* *
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
|
|
||||||
http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
|
http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
|
||||||
the FAQ page "My application does not run, what could be wrong?". Have you
|
the FAQ page "My application does not run, what could be wrong?". Have you
|
||||||
defined configASSERT()?
|
defined configASSERT()?
|
||||||
|
|
||||||
http://www.FreeRTOS.org/support - In return for receiving this top quality
|
http://www.FreeRTOS.org/support - In return for receiving this top quality
|
||||||
embedded software for free we request you assist our global community by
|
embedded software for free we request you assist our global community by
|
||||||
participating in the support forum.
|
participating in the support forum.
|
||||||
|
|
||||||
http://www.FreeRTOS.org/training - Investing in training allows your team to
|
http://www.FreeRTOS.org/training - Investing in training allows your team to
|
||||||
be as productive as possible as early as possible. Now you can receive
|
be as productive as possible as early as possible. Now you can receive
|
||||||
FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
|
FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
|
||||||
Ltd, and the world's leading authority on the world's leading RTOS.
|
Ltd, and the world's leading authority on the world's leading RTOS.
|
||||||
|
|
||||||
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||||
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
||||||
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
||||||
|
|
||||||
http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
|
http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
|
||||||
Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
|
Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
|
||||||
|
|
||||||
http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
|
http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
|
||||||
Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
|
Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
|
||||||
licenses offer ticketed support, indemnification and commercial middleware.
|
licenses offer ticketed support, indemnification and commercial middleware.
|
||||||
|
|
||||||
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||||
engineered and independently SIL3 certified version for use in safety and
|
engineered and independently SIL3 certified version for use in safety and
|
||||||
mission critical applications that require provable dependability.
|
mission critical applications that require provable dependability.
|
||||||
|
|
||||||
1 tab == 4 spaces!
|
1 tab == 4 spaces!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FreeRTOS tasks are used with FreeRTOS+TCP to create a TCP echo server on the
|
* FreeRTOS tasks are used with FreeRTOS+TCP to create a TCP echo server on the
|
||||||
* standard echo port number (7).
|
* standard echo port number (7).
|
||||||
*
|
*
|
||||||
* See the following web page for essential demo usage and configuration
|
* See the following web page for essential demo usage and configuration
|
||||||
* details:
|
* details:
|
||||||
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Echo_Server.html
|
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Echo_Server.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Standard includes. */
|
/* Standard includes. */
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/* FreeRTOS includes. */
|
/* FreeRTOS includes. */
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "semphr.h"
|
#include "semphr.h"
|
||||||
|
|
||||||
/* FreeRTOS+TCP includes. */
|
/* FreeRTOS+TCP includes. */
|
||||||
#include "FreeRTOS_IP.h"
|
#include "FreeRTOS_IP.h"
|
||||||
#include "FreeRTOS_Sockets.h"
|
#include "FreeRTOS_Sockets.h"
|
||||||
|
|
||||||
/* Remove the whole file if FreeRTOSIPConfig.h is set to exclude TCP. */
|
/* Remove the whole file if FreeRTOSIPConfig.h is set to exclude TCP. */
|
||||||
#if( ipconfigUSE_TCP == 1 )
|
#if( ipconfigUSE_TCP == 1 )
|
||||||
|
|
||||||
/* The maximum time to wait for a closing socket to close. */
|
/* The maximum time to wait for a closing socket to close. */
|
||||||
#define tcpechoSHUTDOWN_DELAY ( pdMS_TO_TICKS( 5000 ) )
|
#define tcpechoSHUTDOWN_DELAY ( pdMS_TO_TICKS( 5000 ) )
|
||||||
|
|
||||||
/* The standard echo port number. */
|
/* The standard echo port number. */
|
||||||
#define tcpechoPORT_NUMBER 7
|
#define tcpechoPORT_NUMBER 7
|
||||||
|
|
||||||
/* If ipconfigUSE_TCP_WIN is 1 then the Tx sockets will use a buffer size set by
|
/* If ipconfigUSE_TCP_WIN is 1 then the Tx sockets will use a buffer size set by
|
||||||
ipconfigTCP_TX_BUFFER_LENGTH, and the Tx window size will be
|
ipconfigTCP_TX_BUFFER_LENGTH, and the Tx window size will be
|
||||||
configECHO_SERVER_TX_WINDOW_SIZE times the buffer size. Note
|
configECHO_SERVER_TX_WINDOW_SIZE times the buffer size. Note
|
||||||
ipconfigTCP_TX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP
|
ipconfigTCP_TX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP
|
||||||
stack constant, whereas configECHO_SERVER_TX_WINDOW_SIZE is set in
|
stack constant, whereas configECHO_SERVER_TX_WINDOW_SIZE is set in
|
||||||
FreeRTOSConfig.h as it is a demo application constant. */
|
FreeRTOSConfig.h as it is a demo application constant. */
|
||||||
#ifndef configECHO_SERVER_TX_WINDOW_SIZE
|
#ifndef configECHO_SERVER_TX_WINDOW_SIZE
|
||||||
#define configECHO_SERVER_TX_WINDOW_SIZE 2
|
#define configECHO_SERVER_TX_WINDOW_SIZE 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* If ipconfigUSE_TCP_WIN is 1 then the Rx sockets will use a buffer size set by
|
/* If ipconfigUSE_TCP_WIN is 1 then the Rx sockets will use a buffer size set by
|
||||||
ipconfigTCP_RX_BUFFER_LENGTH, and the Rx window size will be
|
ipconfigTCP_RX_BUFFER_LENGTH, and the Rx window size will be
|
||||||
configECHO_SERVER_RX_WINDOW_SIZE times the buffer size. Note
|
configECHO_SERVER_RX_WINDOW_SIZE times the buffer size. Note
|
||||||
ipconfigTCP_RX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP
|
ipconfigTCP_RX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP
|
||||||
stack constant, whereas configECHO_SERVER_RX_WINDOW_SIZE is set in
|
stack constant, whereas configECHO_SERVER_RX_WINDOW_SIZE is set in
|
||||||
FreeRTOSConfig.h as it is a demo application constant. */
|
FreeRTOSConfig.h as it is a demo application constant. */
|
||||||
#ifndef configECHO_SERVER_RX_WINDOW_SIZE
|
#ifndef configECHO_SERVER_RX_WINDOW_SIZE
|
||||||
#define configECHO_SERVER_RX_WINDOW_SIZE 2
|
#define configECHO_SERVER_RX_WINDOW_SIZE 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Uses FreeRTOS+TCP to listen for incoming echo connections, creating a task
|
* Uses FreeRTOS+TCP to listen for incoming echo connections, creating a task
|
||||||
* to handle each connection.
|
* to handle each connection.
|
||||||
*/
|
*/
|
||||||
static void prvConnectionListeningTask( void *pvParameters );
|
static void prvConnectionListeningTask( void *pvParameters );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Created by the connection listening task to handle a single connection.
|
* Created by the connection listening task to handle a single connection.
|
||||||
*/
|
*/
|
||||||
static void prvServerConnectionInstance( void *pvParameters );
|
static void prvServerConnectionInstance( void *pvParameters );
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/* Stores the stack size passed into vStartSimpleTCPServerTasks() so it can be
|
/* Stores the stack size passed into vStartSimpleTCPServerTasks() so it can be
|
||||||
reused when the server listening task creates tasks to handle connections. */
|
reused when the server listening task creates tasks to handle connections. */
|
||||||
static uint16_t usUsedStackSize = 0;
|
static uint16_t usUsedStackSize = 0;
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vStartSimpleTCPServerTasks( uint16_t usStackSize, UBaseType_t uxPriority )
|
void vStartSimpleTCPServerTasks( uint16_t usStackSize, UBaseType_t uxPriority )
|
||||||
{
|
{
|
||||||
/* Create the TCP echo server. */
|
/* Create the TCP echo server. */
|
||||||
xTaskCreate( prvConnectionListeningTask, "ServerListener", usStackSize, NULL, uxPriority + 1, NULL );
|
xTaskCreate( prvConnectionListeningTask, "ServerListener", usStackSize, NULL, uxPriority + 1, NULL );
|
||||||
|
|
||||||
/* Remember the requested stack size so it can be re-used by the server
|
/* Remember the requested stack size so it can be re-used by the server
|
||||||
listening task when it creates tasks to handle connections. */
|
listening task when it creates tasks to handle connections. */
|
||||||
usUsedStackSize = usStackSize;
|
usUsedStackSize = usStackSize;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static void prvConnectionListeningTask( void *pvParameters )
|
static void prvConnectionListeningTask( void *pvParameters )
|
||||||
{
|
{
|
||||||
struct freertos_sockaddr xClient, xBindAddress;
|
struct freertos_sockaddr xClient, xBindAddress;
|
||||||
Socket_t xListeningSocket, xConnectedSocket;
|
Socket_t xListeningSocket, xConnectedSocket;
|
||||||
socklen_t xSize = sizeof( xClient );
|
socklen_t xSize = sizeof( xClient );
|
||||||
static const TickType_t xReceiveTimeOut = portMAX_DELAY;
|
static const TickType_t xReceiveTimeOut = portMAX_DELAY;
|
||||||
const BaseType_t xBacklog = 20;
|
const BaseType_t xBacklog = 20;
|
||||||
|
|
||||||
#if( ipconfigUSE_TCP_WIN == 1 )
|
#if( ipconfigUSE_TCP_WIN == 1 )
|
||||||
WinProperties_t xWinProps;
|
WinProperties_t xWinProps;
|
||||||
|
|
||||||
/* Fill in the buffer and window sizes that will be used by the socket. */
|
/* Fill in the buffer and window sizes that will be used by the socket. */
|
||||||
xWinProps.lTxBufSize = ipconfigTCP_TX_BUFFER_LENGTH;
|
xWinProps.lTxBufSize = ipconfigTCP_TX_BUFFER_LENGTH;
|
||||||
xWinProps.lTxWinSize = configECHO_SERVER_TX_WINDOW_SIZE;
|
xWinProps.lTxWinSize = configECHO_SERVER_TX_WINDOW_SIZE;
|
||||||
xWinProps.lRxBufSize = ipconfigTCP_RX_BUFFER_LENGTH;
|
xWinProps.lRxBufSize = ipconfigTCP_RX_BUFFER_LENGTH;
|
||||||
xWinProps.lRxWinSize = configECHO_SERVER_RX_WINDOW_SIZE;
|
xWinProps.lRxWinSize = configECHO_SERVER_RX_WINDOW_SIZE;
|
||||||
#endif /* ipconfigUSE_TCP_WIN */
|
#endif /* ipconfigUSE_TCP_WIN */
|
||||||
|
|
||||||
/* Just to prevent compiler warnings. */
|
/* Just to prevent compiler warnings. */
|
||||||
( void ) pvParameters;
|
( void ) pvParameters;
|
||||||
|
|
||||||
/* Attempt to open the socket. */
|
/* Attempt to open the socket. */
|
||||||
xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
|
xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
|
||||||
configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );
|
configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );
|
||||||
|
|
||||||
/* Set a time out so accept() will just wait for a connection. */
|
/* Set a time out so accept() will just wait for a connection. */
|
||||||
FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
|
FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
|
||||||
|
|
||||||
/* Set the window and buffer sizes. */
|
/* Set the window and buffer sizes. */
|
||||||
#if( ipconfigUSE_TCP_WIN == 1 )
|
#if( ipconfigUSE_TCP_WIN == 1 )
|
||||||
{
|
{
|
||||||
FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
|
FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
|
||||||
}
|
}
|
||||||
#endif /* ipconfigUSE_TCP_WIN */
|
#endif /* ipconfigUSE_TCP_WIN */
|
||||||
|
|
||||||
/* Bind the socket to the port that the client task will send to, then
|
/* Bind the socket to the port that the client task will send to, then
|
||||||
listen for incoming connections. */
|
listen for incoming connections. */
|
||||||
xBindAddress.sin_port = tcpechoPORT_NUMBER;
|
xBindAddress.sin_port = tcpechoPORT_NUMBER;
|
||||||
xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port );
|
xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port );
|
||||||
FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
|
FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
|
||||||
FreeRTOS_listen( xListeningSocket, xBacklog );
|
FreeRTOS_listen( xListeningSocket, xBacklog );
|
||||||
|
|
||||||
for( ;; )
|
for( ;; )
|
||||||
{
|
{
|
||||||
/* Wait for a client to connect. */
|
/* Wait for a client to connect. */
|
||||||
xConnectedSocket = FreeRTOS_accept( xListeningSocket, &xClient, &xSize );
|
xConnectedSocket = FreeRTOS_accept( xListeningSocket, &xClient, &xSize );
|
||||||
configASSERT( xConnectedSocket != FREERTOS_INVALID_SOCKET );
|
configASSERT( xConnectedSocket != FREERTOS_INVALID_SOCKET );
|
||||||
|
|
||||||
/* Spawn a task to handle the connection. */
|
/* Spawn a task to handle the connection. */
|
||||||
xTaskCreate( prvServerConnectionInstance, "EchoServer", usUsedStackSize, ( void * ) xConnectedSocket, tskIDLE_PRIORITY, NULL );
|
xTaskCreate( prvServerConnectionInstance, "EchoServer", usUsedStackSize, ( void * ) xConnectedSocket, tskIDLE_PRIORITY, NULL );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static void prvServerConnectionInstance( void *pvParameters )
|
static void prvServerConnectionInstance( void *pvParameters )
|
||||||
{
|
{
|
||||||
int32_t lBytes, lSent, lTotalSent;
|
int32_t lBytes, lSent, lTotalSent;
|
||||||
Socket_t xConnectedSocket;
|
Socket_t xConnectedSocket;
|
||||||
static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 );
|
static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 );
|
||||||
static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 5000 );
|
static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 5000 );
|
||||||
TickType_t xTimeOnShutdown;
|
TickType_t xTimeOnShutdown;
|
||||||
uint8_t *pucRxBuffer;
|
uint8_t *pucRxBuffer;
|
||||||
|
|
||||||
xConnectedSocket = ( Socket_t ) pvParameters;
|
xConnectedSocket = ( Socket_t ) pvParameters;
|
||||||
|
|
||||||
/* Attempt to create the buffer used to receive the string to be echoed
|
/* Attempt to create the buffer used to receive the string to be echoed
|
||||||
back. This could be avoided using a zero copy interface that just returned
|
back. This could be avoided using a zero copy interface that just returned
|
||||||
the same buffer. */
|
the same buffer. */
|
||||||
pucRxBuffer = ( uint8_t * ) pvPortMalloc( ipconfigTCP_MSS );
|
pucRxBuffer = ( uint8_t * ) pvPortMalloc( ipconfigTCP_MSS );
|
||||||
|
|
||||||
if( pucRxBuffer != NULL )
|
if( pucRxBuffer != NULL )
|
||||||
{
|
{
|
||||||
FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
|
FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
|
||||||
FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xReceiveTimeOut ) );
|
FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xReceiveTimeOut ) );
|
||||||
|
|
||||||
for( ;; )
|
for( ;; )
|
||||||
{
|
{
|
||||||
/* Zero out the receive array so there is NULL at the end of the string
|
/* Zero out the receive array so there is NULL at the end of the string
|
||||||
when it is printed out. */
|
when it is printed out. */
|
||||||
memset( pucRxBuffer, 0x00, ipconfigTCP_MSS );
|
memset( pucRxBuffer, 0x00, ipconfigTCP_MSS );
|
||||||
|
|
||||||
/* Receive data on the socket. */
|
/* Receive data on the socket. */
|
||||||
lBytes = FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 );
|
lBytes = FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 );
|
||||||
|
|
||||||
/* If data was received, echo it back. */
|
/* If data was received, echo it back. */
|
||||||
if( lBytes >= 0 )
|
if( lBytes >= 0 )
|
||||||
{
|
{
|
||||||
lSent = 0;
|
lSent = 0;
|
||||||
lTotalSent = 0;
|
lTotalSent = 0;
|
||||||
|
|
||||||
/* Call send() until all the data has been sent. */
|
/* Call send() until all the data has been sent. */
|
||||||
while( ( lSent >= 0 ) && ( lTotalSent < lBytes ) )
|
while( ( lSent >= 0 ) && ( lTotalSent < lBytes ) )
|
||||||
{
|
{
|
||||||
lSent = FreeRTOS_send( xConnectedSocket, pucRxBuffer, lBytes - lTotalSent, 0 );
|
lSent = FreeRTOS_send( xConnectedSocket, pucRxBuffer, lBytes - lTotalSent, 0 );
|
||||||
lTotalSent += lSent;
|
lTotalSent += lSent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( lSent < 0 )
|
if( lSent < 0 )
|
||||||
{
|
{
|
||||||
/* Socket closed? */
|
/* Socket closed? */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Socket closed? */
|
/* Socket closed? */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initiate a shutdown in case it has not already been initiated. */
|
/* Initiate a shutdown in case it has not already been initiated. */
|
||||||
FreeRTOS_shutdown( xConnectedSocket, FREERTOS_SHUT_RDWR );
|
FreeRTOS_shutdown( xConnectedSocket, FREERTOS_SHUT_RDWR );
|
||||||
|
|
||||||
/* Wait for the shutdown to take effect, indicated by FreeRTOS_recv()
|
/* Wait for the shutdown to take effect, indicated by FreeRTOS_recv()
|
||||||
returning an error. */
|
returning an error. */
|
||||||
xTimeOnShutdown = xTaskGetTickCount();
|
xTimeOnShutdown = xTaskGetTickCount();
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if( FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 ) < 0 )
|
if( FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 ) < 0 )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while( ( xTaskGetTickCount() - xTimeOnShutdown ) < tcpechoSHUTDOWN_DELAY );
|
} while( ( xTaskGetTickCount() - xTimeOnShutdown ) < tcpechoSHUTDOWN_DELAY );
|
||||||
|
|
||||||
/* Finished with the socket, buffer, the task. */
|
/* Finished with the socket, buffer, the task. */
|
||||||
vPortFree( pucRxBuffer );
|
vPortFree( pucRxBuffer );
|
||||||
FreeRTOS_closesocket( xConnectedSocket );
|
FreeRTOS_closesocket( xConnectedSocket );
|
||||||
|
|
||||||
vTaskDelete( NULL );
|
vTaskDelete( NULL );
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/* The whole file is excluded if TCP is not compiled in. */
|
/* The whole file is excluded if TCP is not compiled in. */
|
||||||
#endif /* ipconfigUSE_TCP */
|
#endif /* ipconfigUSE_TCP */
|
||||||
|
|
@ -1,372 +1,372 @@
|
|||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.3.0
|
* FreeRTOS Kernel V10.3.0
|
||||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
* the Software without restriction, including without limitation the rights to
|
* the Software without restriction, including without limitation the rights to
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
* subject to the following conditions:
|
* subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
* copies or substantial portions of the Software.
|
* copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* http://www.FreeRTOS.org
|
* http://www.FreeRTOS.org
|
||||||
* http://aws.amazon.com/freertos
|
* http://aws.amazon.com/freertos
|
||||||
*
|
*
|
||||||
* 1 tab == 4 spaces!
|
* 1 tab == 4 spaces!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A set of tasks are created that send TCP echo requests to the standard echo
|
* A set of tasks are created that send TCP echo requests to the standard echo
|
||||||
* port (port 7) on the IP address set by the configECHO_SERVER_ADDR0 to
|
* port (port 7) on the IP address set by the configECHO_SERVER_ADDR0 to
|
||||||
* configECHO_SERVER_ADDR3 constants, then wait for and verify the reply
|
* configECHO_SERVER_ADDR3 constants, then wait for and verify the reply
|
||||||
* (another demo is avilable that demonstrates the reception being performed in
|
* (another demo is avilable that demonstrates the reception being performed in
|
||||||
* a task other than that from with the request was made).
|
* a task other than that from with the request was made).
|
||||||
*
|
*
|
||||||
* See the following web page for essential demo usage and configuration
|
* See the following web page for essential demo usage and configuration
|
||||||
* details:
|
* details:
|
||||||
* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html
|
* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Standard includes. */
|
/* Standard includes. */
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* FreeRTOS includes. */
|
/* FreeRTOS includes. */
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
/* FreeRTOS+TCP includes. */
|
/* FreeRTOS+TCP includes. */
|
||||||
#include "FreeRTOS_IP.h"
|
#include "FreeRTOS_IP.h"
|
||||||
#include "FreeRTOS_Sockets.h"
|
#include "FreeRTOS_Sockets.h"
|
||||||
|
|
||||||
/* Exclude the whole file if FreeRTOSIPConfig.h is configured to use UDP only. */
|
/* Exclude the whole file if FreeRTOSIPConfig.h is configured to use UDP only. */
|
||||||
#if ( ipconfigUSE_TCP == 1 )
|
#if ( ipconfigUSE_TCP == 1 )
|
||||||
|
|
||||||
/* The echo tasks create a socket, send out a number of echo requests, listen
|
/* The echo tasks create a socket, send out a number of echo requests, listen
|
||||||
for the echo reply, then close the socket again before starting over. This
|
for the echo reply, then close the socket again before starting over. This
|
||||||
delay is used between each iteration to ensure the network does not get too
|
delay is used between each iteration to ensure the network does not get too
|
||||||
congested. */
|
congested. */
|
||||||
#define echoLOOP_DELAY ( ( TickType_t ) 150 / portTICK_PERIOD_MS )
|
#define echoLOOP_DELAY ( ( TickType_t ) 150 / portTICK_PERIOD_MS )
|
||||||
|
|
||||||
/* The echo server is assumed to be on port 7, which is the standard echo
|
/* The echo server is assumed to be on port 7, which is the standard echo
|
||||||
protocol port. */
|
protocol port. */
|
||||||
#define echoECHO_PORT ( 7 )
|
#define echoECHO_PORT ( 7 )
|
||||||
|
|
||||||
/* The size of the buffers is a multiple of the MSS - the length of the data
|
/* The size of the buffers is a multiple of the MSS - the length of the data
|
||||||
sent is a pseudo random size between 20 and echoBUFFER_SIZES. */
|
sent is a pseudo random size between 20 and echoBUFFER_SIZES. */
|
||||||
#define echoBUFFER_SIZE_MULTIPLIER ( 3 )
|
#define echoBUFFER_SIZE_MULTIPLIER ( 3 )
|
||||||
#define echoBUFFER_SIZES ( ipconfigTCP_MSS * echoBUFFER_SIZE_MULTIPLIER )
|
#define echoBUFFER_SIZES ( ipconfigTCP_MSS * echoBUFFER_SIZE_MULTIPLIER )
|
||||||
|
|
||||||
/* The number of instances of the echo client task to create. */
|
/* The number of instances of the echo client task to create. */
|
||||||
#define echoNUM_ECHO_CLIENTS ( 1 )
|
#define echoNUM_ECHO_CLIENTS ( 1 )
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Uses a socket to send data to, then receive data from, the standard echo
|
* Uses a socket to send data to, then receive data from, the standard echo
|
||||||
* port number 7.
|
* port number 7.
|
||||||
*/
|
*/
|
||||||
static void prvEchoClientTask( void *pvParameters );
|
static void prvEchoClientTask( void *pvParameters );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates a pseudo random sized buffer of data to send to the echo server.
|
* Creates a pseudo random sized buffer of data to send to the echo server.
|
||||||
*/
|
*/
|
||||||
static BaseType_t prvCreateTxData( char *ucBuffer,
|
static BaseType_t prvCreateTxData( char *ucBuffer,
|
||||||
uint32_t ulBufferLength );
|
uint32_t ulBufferLength );
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/* Rx and Tx time outs are used to ensure the sockets do not wait too long for
|
/* Rx and Tx time outs are used to ensure the sockets do not wait too long for
|
||||||
missing data. */
|
missing data. */
|
||||||
static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 4000 );
|
static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 4000 );
|
||||||
static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 2000 );
|
static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 2000 );
|
||||||
|
|
||||||
/* Counters for each created task - for inspection only. */
|
/* Counters for each created task - for inspection only. */
|
||||||
static uint32_t ulTxRxCycles[ echoNUM_ECHO_CLIENTS ] = { 0 },
|
static uint32_t ulTxRxCycles[ echoNUM_ECHO_CLIENTS ] = { 0 },
|
||||||
ulTxRxFailures[ echoNUM_ECHO_CLIENTS ] = { 0 },
|
ulTxRxFailures[ echoNUM_ECHO_CLIENTS ] = { 0 },
|
||||||
ulConnections[ echoNUM_ECHO_CLIENTS ] = { 0 };
|
ulConnections[ echoNUM_ECHO_CLIENTS ] = { 0 };
|
||||||
|
|
||||||
/* Rx and Tx buffers for each created task. */
|
/* Rx and Tx buffers for each created task. */
|
||||||
static char cTxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ],
|
static char cTxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ],
|
||||||
cRxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ];
|
cRxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ];
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize,
|
void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize,
|
||||||
UBaseType_t uxTaskPriority )
|
UBaseType_t uxTaskPriority )
|
||||||
{
|
{
|
||||||
BaseType_t x;
|
BaseType_t x;
|
||||||
|
|
||||||
/* Create the echo client tasks. */
|
/* Create the echo client tasks. */
|
||||||
for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ )
|
for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ )
|
||||||
{
|
{
|
||||||
xTaskCreate( prvEchoClientTask, /* The function that implements the task. */
|
xTaskCreate( prvEchoClientTask, /* The function that implements the task. */
|
||||||
"Echo0", /* Just a text name for the task to aid debugging. */
|
"Echo0", /* Just a text name for the task to aid debugging. */
|
||||||
usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */
|
usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */
|
||||||
( void * ) x, /* The task parameter, not used in this case. */
|
( void * ) x, /* The task parameter, not used in this case. */
|
||||||
uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */
|
uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */
|
||||||
NULL ); /* The task handle is not used. */
|
NULL ); /* The task handle is not used. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static void prvEchoClientTask( void *pvParameters )
|
static void prvEchoClientTask( void *pvParameters )
|
||||||
{
|
{
|
||||||
Socket_t xSocket;
|
Socket_t xSocket;
|
||||||
struct freertos_sockaddr xEchoServerAddress;
|
struct freertos_sockaddr xEchoServerAddress;
|
||||||
int32_t lLoopCount = 0UL;
|
int32_t lLoopCount = 0UL;
|
||||||
const int32_t lMaxLoopCount = 1;
|
const int32_t lMaxLoopCount = 1;
|
||||||
volatile uint32_t ulTxCount = 0UL;
|
volatile uint32_t ulTxCount = 0UL;
|
||||||
BaseType_t xReceivedBytes, xReturned, xInstance;
|
BaseType_t xReceivedBytes, xReturned, xInstance;
|
||||||
BaseType_t lTransmitted, lStringLength;
|
BaseType_t lTransmitted, lStringLength;
|
||||||
char *pcTransmittedString, *pcReceivedString;
|
char *pcTransmittedString, *pcReceivedString;
|
||||||
WinProperties_t xWinProps;
|
WinProperties_t xWinProps;
|
||||||
TickType_t xTimeOnEntering;
|
TickType_t xTimeOnEntering;
|
||||||
BaseType_t ret;
|
BaseType_t ret;
|
||||||
|
|
||||||
/* Fill in the buffer and window sizes that will be used by the socket. */
|
/* Fill in the buffer and window sizes that will be used by the socket. */
|
||||||
xWinProps.lTxBufSize = 6 * ipconfigTCP_MSS;
|
xWinProps.lTxBufSize = 6 * ipconfigTCP_MSS;
|
||||||
xWinProps.lTxWinSize = 3;
|
xWinProps.lTxWinSize = 3;
|
||||||
xWinProps.lRxBufSize = 6 * ipconfigTCP_MSS;
|
xWinProps.lRxBufSize = 6 * ipconfigTCP_MSS;
|
||||||
xWinProps.lRxWinSize = 3;
|
xWinProps.lRxWinSize = 3;
|
||||||
|
|
||||||
/* This task can be created a number of times. Each instance is numbered
|
/* This task can be created a number of times. Each instance is numbered
|
||||||
to enable each instance to use a different Rx and Tx buffer. The number is
|
to enable each instance to use a different Rx and Tx buffer. The number is
|
||||||
passed in as the task's parameter. */
|
passed in as the task's parameter. */
|
||||||
xInstance = ( BaseType_t ) pvParameters;
|
xInstance = ( BaseType_t ) pvParameters;
|
||||||
|
|
||||||
/* Point to the buffers to be used by this instance of this task. */
|
/* Point to the buffers to be used by this instance of this task. */
|
||||||
pcTransmittedString = &( cTxBuffers[ xInstance ][ 0 ] );
|
pcTransmittedString = &( cTxBuffers[ xInstance ][ 0 ] );
|
||||||
pcReceivedString = &( cRxBuffers[ xInstance ][ 0 ] );
|
pcReceivedString = &( cRxBuffers[ xInstance ][ 0 ] );
|
||||||
|
|
||||||
/* Echo requests are sent to the echo server. The address of the echo
|
/* Echo requests are sent to the echo server. The address of the echo
|
||||||
server is configured by the constants configECHO_SERVER_ADDR0 to
|
server is configured by the constants configECHO_SERVER_ADDR0 to
|
||||||
configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */
|
configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */
|
||||||
xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT );
|
xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT );
|
||||||
xEchoServerAddress.sin_addr = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0,
|
xEchoServerAddress.sin_addr = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0,
|
||||||
configECHO_SERVER_ADDR1,
|
configECHO_SERVER_ADDR1,
|
||||||
configECHO_SERVER_ADDR2,
|
configECHO_SERVER_ADDR2,
|
||||||
configECHO_SERVER_ADDR3 );
|
configECHO_SERVER_ADDR3 );
|
||||||
|
|
||||||
for( ; ; )
|
for( ; ; )
|
||||||
{
|
{
|
||||||
/* Create a TCP socket. */
|
/* Create a TCP socket. */
|
||||||
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
|
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
|
||||||
configASSERT( xSocket != FREERTOS_INVALID_SOCKET );
|
configASSERT( xSocket != FREERTOS_INVALID_SOCKET );
|
||||||
|
|
||||||
/* Set a time out so a missing reply does not cause the task to block
|
/* Set a time out so a missing reply does not cause the task to block
|
||||||
indefinitely. */
|
indefinitely. */
|
||||||
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
|
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
|
||||||
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xSendTimeOut ) );
|
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xSendTimeOut ) );
|
||||||
|
|
||||||
/* Set the window and buffer sizes. */
|
/* Set the window and buffer sizes. */
|
||||||
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
|
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
|
||||||
|
|
||||||
/* Connect to the echo server. */
|
/* Connect to the echo server. */
|
||||||
printf( "connecting to echo server....\n" );
|
printf( "connecting to echo server....\n" );
|
||||||
|
|
||||||
ret = FreeRTOS_connect( xSocket, &xEchoServerAddress, sizeof( xEchoServerAddress ) );
|
ret = FreeRTOS_connect( xSocket, &xEchoServerAddress, sizeof( xEchoServerAddress ) );
|
||||||
|
|
||||||
if( ret == 0 )
|
if( ret == 0 )
|
||||||
{
|
{
|
||||||
printf( "Connected to server.. \n" );
|
printf( "Connected to server.. \n" );
|
||||||
ulConnections[ xInstance ]++;
|
ulConnections[ xInstance ]++;
|
||||||
|
|
||||||
/* Send a number of echo requests. */
|
/* Send a number of echo requests. */
|
||||||
for( lLoopCount = 0; lLoopCount < lMaxLoopCount; lLoopCount++ )
|
for( lLoopCount = 0; lLoopCount < lMaxLoopCount; lLoopCount++ )
|
||||||
{
|
{
|
||||||
/* Create the string that is sent to the echo server. */
|
/* Create the string that is sent to the echo server. */
|
||||||
lStringLength = prvCreateTxData( pcTransmittedString, echoBUFFER_SIZES );
|
lStringLength = prvCreateTxData( pcTransmittedString, echoBUFFER_SIZES );
|
||||||
|
|
||||||
/* Add in some unique text at the front of the string. */
|
/* Add in some unique text at the front of the string. */
|
||||||
sprintf( pcTransmittedString, "TxRx message number %u", ulTxCount );
|
sprintf( pcTransmittedString, "TxRx message number %u", ulTxCount );
|
||||||
ulTxCount++;
|
ulTxCount++;
|
||||||
|
|
||||||
printf( "sending data to the echo server \n" );
|
printf( "sending data to the echo server \n" );
|
||||||
/* Send the string to the socket. */
|
/* Send the string to the socket. */
|
||||||
lTransmitted = FreeRTOS_send( xSocket, /* The socket being sent to. */
|
lTransmitted = FreeRTOS_send( xSocket, /* The socket being sent to. */
|
||||||
( void * ) pcTransmittedString, /* The data being sent. */
|
( void * ) pcTransmittedString, /* The data being sent. */
|
||||||
lStringLength, /* The length of the data being sent. */
|
lStringLength, /* The length of the data being sent. */
|
||||||
0 ); /* No flags. */
|
0 ); /* No flags. */
|
||||||
|
|
||||||
if( lTransmitted < 0 )
|
if( lTransmitted < 0 )
|
||||||
{
|
{
|
||||||
/* Error? */
|
/* Error? */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear the buffer into which the echoed string will be
|
/* Clear the buffer into which the echoed string will be
|
||||||
placed. */
|
placed. */
|
||||||
memset( ( void * ) pcReceivedString, 0x00, echoBUFFER_SIZES );
|
memset( ( void * ) pcReceivedString, 0x00, echoBUFFER_SIZES );
|
||||||
xReceivedBytes = 0;
|
xReceivedBytes = 0;
|
||||||
|
|
||||||
/* Receive data echoed back to the socket. */
|
/* Receive data echoed back to the socket. */
|
||||||
while( xReceivedBytes < lTransmitted )
|
while( xReceivedBytes < lTransmitted )
|
||||||
{
|
{
|
||||||
xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */
|
xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */
|
||||||
&( pcReceivedString[ xReceivedBytes ] ), /* The buffer into which the received data will be written. */
|
&( pcReceivedString[ xReceivedBytes ] ), /* The buffer into which the received data will be written. */
|
||||||
lStringLength - xReceivedBytes, /* The size of the buffer provided to receive the data. */
|
lStringLength - xReceivedBytes, /* The size of the buffer provided to receive the data. */
|
||||||
0 ); /* No flags. */
|
0 ); /* No flags. */
|
||||||
|
|
||||||
if( xReturned < 0 )
|
if( xReturned < 0 )
|
||||||
{
|
{
|
||||||
/* Error occurred. Latch it so it can be detected
|
/* Error occurred. Latch it so it can be detected
|
||||||
below. */
|
below. */
|
||||||
xReceivedBytes = xReturned;
|
xReceivedBytes = xReturned;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if( xReturned == 0 )
|
else if( xReturned == 0 )
|
||||||
{
|
{
|
||||||
/* Timed out. */
|
/* Timed out. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Keep a count of the bytes received so far. */
|
/* Keep a count of the bytes received so far. */
|
||||||
xReceivedBytes += xReturned;
|
xReceivedBytes += xReturned;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If an error occurred it will be latched in xReceivedBytes,
|
/* If an error occurred it will be latched in xReceivedBytes,
|
||||||
otherwise xReceived bytes will be just that - the number of
|
otherwise xReceived bytes will be just that - the number of
|
||||||
bytes received from the echo server. */
|
bytes received from the echo server. */
|
||||||
if( xReceivedBytes > 0 )
|
if( xReceivedBytes > 0 )
|
||||||
{
|
{
|
||||||
/* Compare the transmitted string to the received string. */
|
/* Compare the transmitted string to the received string. */
|
||||||
configASSERT( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 );
|
configASSERT( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 );
|
||||||
|
|
||||||
if( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 )
|
if( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 )
|
||||||
{
|
{
|
||||||
/* The echo reply was received without error. */
|
/* The echo reply was received without error. */
|
||||||
ulTxRxCycles[ xInstance ]++;
|
ulTxRxCycles[ xInstance ]++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* The received string did not match the transmitted
|
/* The received string did not match the transmitted
|
||||||
string. */
|
string. */
|
||||||
ulTxRxFailures[ xInstance ]++;
|
ulTxRxFailures[ xInstance ]++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( xReceivedBytes < 0 )
|
else if( xReceivedBytes < 0 )
|
||||||
{
|
{
|
||||||
/* FreeRTOS_recv() returned an error. */
|
/* FreeRTOS_recv() returned an error. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Timed out without receiving anything? */
|
/* Timed out without receiving anything? */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Finished using the connected socket, initiate a graceful close:
|
/* Finished using the connected socket, initiate a graceful close:
|
||||||
FIN, FIN+ACK, ACK. */
|
FIN, FIN+ACK, ACK. */
|
||||||
FreeRTOS_shutdown( xSocket, FREERTOS_SHUT_RDWR );
|
FreeRTOS_shutdown( xSocket, FREERTOS_SHUT_RDWR );
|
||||||
|
|
||||||
/* Expect FreeRTOS_recv() to return an error once the shutdown is
|
/* Expect FreeRTOS_recv() to return an error once the shutdown is
|
||||||
complete. */
|
complete. */
|
||||||
xTimeOnEntering = xTaskGetTickCount();
|
xTimeOnEntering = xTaskGetTickCount();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */
|
xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */
|
||||||
&( pcReceivedString[ 0 ] ), /* The buffer into which the received data will be written. */
|
&( pcReceivedString[ 0 ] ), /* The buffer into which the received data will be written. */
|
||||||
echoBUFFER_SIZES, /* The size of the buffer provided to receive the data. */
|
echoBUFFER_SIZES, /* The size of the buffer provided to receive the data. */
|
||||||
0 );
|
0 );
|
||||||
|
|
||||||
if( xReturned < 0 )
|
if( xReturned < 0 )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while( ( xTaskGetTickCount() - xTimeOnEntering ) < xReceiveTimeOut );
|
} while( ( xTaskGetTickCount() - xTimeOnEntering ) < xReceiveTimeOut );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf( "Could not connect to server %ld\n", ret );
|
printf( "Could not connect to server %ld\n", ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close this socket before looping back to create another. */
|
/* Close this socket before looping back to create another. */
|
||||||
FreeRTOS_closesocket( xSocket );
|
FreeRTOS_closesocket( xSocket );
|
||||||
|
|
||||||
/* Pause for a short while to ensure the network is not too
|
/* Pause for a short while to ensure the network is not too
|
||||||
congested. */
|
congested. */
|
||||||
vTaskDelay( echoLOOP_DELAY );
|
vTaskDelay( echoLOOP_DELAY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static BaseType_t prvCreateTxData( char *cBuffer,
|
static BaseType_t prvCreateTxData( char *cBuffer,
|
||||||
uint32_t ulBufferLength )
|
uint32_t ulBufferLength )
|
||||||
{
|
{
|
||||||
BaseType_t lCharactersToAdd, lCharacter;
|
BaseType_t lCharactersToAdd, lCharacter;
|
||||||
char cChar = '0';
|
char cChar = '0';
|
||||||
const BaseType_t lMinimumLength = 60;
|
const BaseType_t lMinimumLength = 60;
|
||||||
|
|
||||||
/* Randomise the number of characters that will be sent in the echo
|
/* Randomise the number of characters that will be sent in the echo
|
||||||
request. */
|
request. */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
lCharactersToAdd = ipconfigRAND32() % ( ulBufferLength - 20UL );
|
lCharactersToAdd = ipconfigRAND32() % ( ulBufferLength - 20UL );
|
||||||
} while( ( lCharactersToAdd == 0 ) || ( lCharactersToAdd < lMinimumLength ) ); /* Must be at least enough to add the unique text to the start of the string later. */
|
} while( ( lCharactersToAdd == 0 ) || ( lCharactersToAdd < lMinimumLength ) ); /* Must be at least enough to add the unique text to the start of the string later. */
|
||||||
|
|
||||||
/* Fill the buffer. */
|
/* Fill the buffer. */
|
||||||
for( lCharacter = 0; lCharacter < lCharactersToAdd; lCharacter++ )
|
for( lCharacter = 0; lCharacter < lCharactersToAdd; lCharacter++ )
|
||||||
{
|
{
|
||||||
cBuffer[ lCharacter ] = cChar;
|
cBuffer[ lCharacter ] = cChar;
|
||||||
cChar++;
|
cChar++;
|
||||||
|
|
||||||
if( cChar > '~' )
|
if( cChar > '~' )
|
||||||
{
|
{
|
||||||
cChar = '0';
|
cChar = '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lCharactersToAdd;
|
return lCharactersToAdd;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void )
|
BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void )
|
||||||
{
|
{
|
||||||
static uint32_t ulLastEchoSocketCount[ echoNUM_ECHO_CLIENTS ] = { 0 }, ulLastConnections[ echoNUM_ECHO_CLIENTS ] = { 0 };
|
static uint32_t ulLastEchoSocketCount[ echoNUM_ECHO_CLIENTS ] = { 0 }, ulLastConnections[ echoNUM_ECHO_CLIENTS ] = { 0 };
|
||||||
BaseType_t xReturn = pdPASS, x;
|
BaseType_t xReturn = pdPASS, x;
|
||||||
|
|
||||||
/* Return fail is the number of cycles does not increment between
|
/* Return fail is the number of cycles does not increment between
|
||||||
consecutive calls. */
|
consecutive calls. */
|
||||||
for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ )
|
for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ )
|
||||||
{
|
{
|
||||||
if( ulTxRxCycles[ x ] == ulLastEchoSocketCount[ x ] )
|
if( ulTxRxCycles[ x ] == ulLastEchoSocketCount[ x ] )
|
||||||
{
|
{
|
||||||
xReturn = pdFAIL;
|
xReturn = pdFAIL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ulLastEchoSocketCount[ x ] = ulTxRxCycles[ x ];
|
ulLastEchoSocketCount[ x ] = ulTxRxCycles[ x ];
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ulConnections[ x ] == ulLastConnections[ x ] )
|
if( ulConnections[ x ] == ulLastConnections[ x ] )
|
||||||
{
|
{
|
||||||
xReturn = pdFAIL;
|
xReturn = pdFAIL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ulConnections[ x ] = ulLastConnections[ x ];
|
ulConnections[ x ] = ulLastConnections[ x ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return xReturn;
|
return xReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* ipconfigUSE_TCP */
|
#endif /* ipconfigUSE_TCP */
|
@ -1,40 +1,40 @@
|
|||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.3.0
|
* FreeRTOS Kernel V10.3.0
|
||||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
* the Software without restriction, including without limitation the rights to
|
* the Software without restriction, including without limitation the rights to
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
* subject to the following conditions:
|
* subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
* copies or substantial portions of the Software.
|
* copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* http://www.FreeRTOS.org
|
* http://www.FreeRTOS.org
|
||||||
* http://aws.amazon.com/freertos
|
* http://aws.amazon.com/freertos
|
||||||
*
|
*
|
||||||
* 1 tab == 4 spaces!
|
* 1 tab == 4 spaces!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SINGLE_TASK_TCP_ECHO_CLIENTS_H
|
#ifndef SINGLE_TASK_TCP_ECHO_CLIENTS_H
|
||||||
#define SINGLE_TASK_TCP_ECHO_CLIENTS_H
|
#define SINGLE_TASK_TCP_ECHO_CLIENTS_H
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the TCP echo client tasks. This is the version where an echo request
|
* Create the TCP echo client tasks. This is the version where an echo request
|
||||||
* is made from the same task that listens for the echo reply.
|
* is made from the same task that listens for the echo reply.
|
||||||
*/
|
*/
|
||||||
void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority );
|
void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority );
|
||||||
BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void );
|
BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void );
|
||||||
|
|
||||||
#endif /* SINGLE_TASK_TCP_ECHO_CLIENTS_H */
|
#endif /* SINGLE_TASK_TCP_ECHO_CLIENTS_H */
|
||||||
|
|
||||||
|
|
@ -26,25 +26,26 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* This project provides two demo applications. A simple blinky style project,
|
* This project provides three demo applications. A simple blinky style project,
|
||||||
* and a more comprehensive test and demo application. The
|
* a more comprehensive test and demo application, and a TCP echo application.
|
||||||
* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two.
|
* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between
|
||||||
|
* the two if mainCREATE_TCP_ECHO_TASKS_SINGLE is 0.
|
||||||
* The simply blinky demo is implemented and described in main_blinky.c. The
|
* The simply blinky demo is implemented and described in main_blinky.c. The
|
||||||
* more comprehensive test and demo application is implemented and described in
|
* more comprehensive test and demo application is implemented and described in
|
||||||
* main_full.c.
|
* main_full.c.
|
||||||
|
* The mainCREATE_TCP_ECHO_TASKS_SINGLE setting is used to select the tcp echo
|
||||||
|
* application regardless of the value of mainCREATE_SIMPLE_BLINKY_DEMO_ONLY.
|
||||||
*
|
*
|
||||||
* This file implements the code that is not demo specific, including the
|
* This file implements the code that is not demo specific, including the
|
||||||
* hardware setup and FreeRTOS hook functions.
|
* hardware setup and FreeRTOS hook functions.
|
||||||
*
|
*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
* NOTE: Windows will not be running the FreeRTOS demo threads continuously, so
|
* NOTE: Linux will not be running the FreeRTOS demo threads continuously, so
|
||||||
* do not expect to get real time behaviour from the FreeRTOS Windows port, or
|
* do not expect to get real time behaviour from the FreeRTOS Linux port, or
|
||||||
* this demo application. Also, the timing information in the FreeRTOS+Trace
|
* this demo application. Also, the timing information in the FreeRTOS+Trace
|
||||||
* logs have no meaningful units. See the documentation page for the Windows
|
* logs have no meaningful units. See the documentation page for the Linux
|
||||||
* port for further information:
|
* port for further information:
|
||||||
* http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html
|
* https://freertos.org/FreeRTOS-simulator-for-Linux.html
|
||||||
*
|
|
||||||
|
|
||||||
*
|
*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
@ -62,16 +63,21 @@
|
|||||||
/* Local includes. */
|
/* Local includes. */
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
|
|
||||||
/* This project provides two demo applications. A simple blinky style demo
|
/* This project provides three demo applications. A simple blinky style demo
|
||||||
application, and a more comprehensive test and demo application. The
|
application, a more comprehensive test and demo application, and a TCP
|
||||||
mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two.
|
echo application. The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY and
|
||||||
|
mainCREATE_TCP_ECHO_TASKS_SINGLE settings are used to select between the three.
|
||||||
|
|
||||||
If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is 1 then the blinky demo will be built.
|
If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is 1 & mainCREATE_TCP_ECHO_TASKS_SINGLE
|
||||||
|
is not 1 then the blinky demo will be built.
|
||||||
The blinky demo is implemented and described in main_blinky.c.
|
The blinky demo is implemented and described in main_blinky.c.
|
||||||
|
|
||||||
If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is not 1 then the comprehensive test and
|
If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is not 1 &
|
||||||
|
mainCREATE_TCP_ECHO_TASKS_SINGLE is not 1 then the comprehensive test and
|
||||||
demo application will be built. The comprehensive test and demo application is
|
demo application will be built. The comprehensive test and demo application is
|
||||||
implemented and described in main_full.c. */
|
implemented and described in main_full.c the tcp echo demo application
|
||||||
|
is implemented in main_networking.c. */
|
||||||
|
|
||||||
#ifndef mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
|
#ifndef mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
|
||||||
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
|
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
|
||||||
#endif
|
#endif
|
||||||
@ -223,7 +229,7 @@ void vApplicationStackOverflowHook( TaskHandle_t pxTask,
|
|||||||
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
|
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
|
||||||
function is called if a stack overflow is detected. This function is
|
function is called if a stack overflow is detected. This function is
|
||||||
provided as an example only as stack overflow checking does not function
|
provided as an example only as stack overflow checking does not function
|
||||||
when running the FreeRTOS Windows port. */
|
when running the FreeRTOS POSIX port. */
|
||||||
vAssertCalled( __FILE__, __LINE__ );
|
vAssertCalled( __FILE__, __LINE__ );
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
@ -113,7 +113,7 @@ extern "C" {
|
|||||||
* TRC_FREERTOS_VERSION_9_0_2 If using FreeRTOS v9.0.2
|
* TRC_FREERTOS_VERSION_9_0_2 If using FreeRTOS v9.0.2
|
||||||
* TRC_FREERTOS_VERSION_10_0_0 If using FreeRTOS v10.0.0 or later
|
* TRC_FREERTOS_VERSION_10_0_0 If using FreeRTOS v10.0.0 or later
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
#define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_0_0
|
#define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_4_0
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* TRC_CFG_SCHEDULING_ONLY
|
* TRC_CFG_SCHEDULING_ONLY
|
Reference in New Issue
Block a user