blob: 027c2e166e219250780e8208bc79d2e2b636083f [file] [log] [blame]
/*
* FreeRTOS Kernel V10.0.1
* 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
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* 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,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* 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
* 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.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
/* Standard includes. */
#include <string.h>
#include <stdio.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "queue.h"
/* FreeRTOS+UDP includes. */
#include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_Sockets.h"
/* Example includes. */
#include "TwoEchoClients.h"
#include "CDCCommandConsole.h"
/* Library includes. */
#include "LPC18xx.h"
/* The size of the stack and the priority used by the two echo client tasks. */
#define mainECHO_CLIENT_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
#define mainECHO_CLIENT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* The size of the stack and the priority used by the USB CDC command console
task. */
#define mainCDC_COMMAND_CONSOLE_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
#define mainCDC_COMMAND_CONSOLE_TASK_PRIORITY ( 4U )
/*
* Register commands that can be used with FreeRTOS+CLI. The commands are
* defined in CLI-commands.c.
*/
extern void vRegisterCLICommands( void );
/*
* Initialise the LED ports, and create a timer that periodically toggles an LED
* just to provide a visual indication that the program is running.
*/
extern void vLEDsInitialise( void );
/*-----------------------------------------------------------*/
/* The default IP and MAC address used by the demo. The address configuration
defined here will be used if ipconfigUSE_DHCP is 0, or if ipconfigUSE_DHCP is
1 but a DHCP server could not be contacted. See the online documentation for
more information. */
static const uint8_t ucIPAddress[ 4 ] = { configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 };
static const uint8_t ucNetMask[ 4 ] = { configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 };
static const uint8_t ucGatewayAddress[ 4 ] = { configGATEWAY_ADDR0, configGATEWAY_ADDR1, configGATEWAY_ADDR2, configGATEWAY_ADDR3 };
static const uint8_t ucDNSServerAddress[ 4 ] = { configDNS_SERVER_ADDR0, configDNS_SERVER_ADDR1, configDNS_SERVER_ADDR2, configDNS_SERVER_ADDR3 };
/* The MAC address used by the demo. In production units the MAC address would
probably be read from flash memory or an EEPROM. Here it is just hard coded. */
const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };
/*-----------------------------------------------------------*/
/******************************************************************************
*
* See the following web page for information on using this demo.
* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/RTOS_UDP_and_CLI_LPC1830_NGX.shtml
*
******************************************************************************/
int main( void )
{
/* Prepare the trace recorder library. */
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
vTraceInitTraceData();
#endif
/* The examples assume that all priority bits are assigned as preemption
priority bits. */
NVIC_SetPriorityGrouping( 0UL );
/* Start the timer that just toggles an LED to show the demo is running. */
vLEDsInitialise();
/* Start the tasks that implements the command console on the UART, as
described above. */
vCDCCommandConsoleStart( mainCDC_COMMAND_CONSOLE_STACK_SIZE, mainCDC_COMMAND_CONSOLE_TASK_PRIORITY );
/* Register CLI commands. */
vRegisterCLICommands();
/* Initialise the network interface. Tasks that use the network are
created in the network event hook when the network is connected and ready
for use. The address values passed in here are used if ipconfigUSE_DHCP is
set to 0, or if ipconfigUSE_DHCP is set to 1 but a DHCP server cannot be
contacted. */
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
/* If the trace recorder code is included... */
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
{
extern xQueueHandle xNetworkEventQueue;
/* Name the queue for viewing in FreeRTOS+Trace. */
vTraceSetQueueName( xNetworkEventQueue, "IPStackEvent" );
}
#endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 */
/* Start the FreeRTOS scheduler. */
vTaskStartScheduler();
/* The following line should never execute. If it does, it means there was
insufficient FreeRTOS heap memory available to create the Idle and/or timer
tasks. See the memory management section on the http://www.FreeRTOS.org web
site for more information. */
for( ;; );
}
/*-----------------------------------------------------------*/
void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName )
{
( void ) pcTaskName;
( void ) pxTask;
/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
function is called if a stack overflow is detected. */
taskDISABLE_INTERRUPTS();
for( ;; );
}
/*-----------------------------------------------------------*/
void vApplicationMallocFailedHook( void )
{
/* vApplicationMallocFailedHook() will only be called if
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
function that will get called if a call to pvPortMalloc() fails.
pvPortMalloc() is called internally by the kernel whenever a task, queue,
timer or semaphore is created. It is also called by various parts of the
demo application. If heap_1.c, heap_2.c or heap_4.c are used, then the
size of the heap available to pvPortMalloc() is defined by
configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()
API function can be used to query the size of free heap space that remains
(although it does not provide information on how the remaining heap might
be fragmented). */
taskDISABLE_INTERRUPTS();
for( ;; );
}
/*-----------------------------------------------------------*/
/* Called by FreeRTOS+UDP when the network connects. */
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
{
static BaseType_t xTaskAlreadyCreated = pdFALSE;
if( eNetworkEvent == eNetworkUp )
{
/* Create the tasks that transmit to and receive from a standard
echo server (see the web documentation for this port) in both
standard and zero copy mode. */
if( xTaskAlreadyCreated == pdFALSE )
{
vStartEchoClientTasks( mainECHO_CLIENT_TASK_STACK_SIZE, mainECHO_CLIENT_TASK_PRIORITY );
xTaskAlreadyCreated = pdTRUE;
}
}
}
/*-----------------------------------------------------------*/
/* Called by FreeRTOS+UDP when a reply is received to an outgoing ping request. */
void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier )
{
static const char *pcSuccess = "\r\n\r\nPing reply received - ";
static const char *pcInvalidChecksum = "\r\n\r\nPing reply received with invalid checksum - ";
static const char *pcInvalidData = "\r\n\r\nPing reply received with invalid data - ";
static char cMessage[ 50 ];
void vOutputString( const char * const pcMessage );
switch( eStatus )
{
case eSuccess :
vOutputString( pcSuccess );
break;
case eInvalidChecksum :
vOutputString( pcInvalidChecksum );
break;
case eInvalidData :
vOutputString( pcInvalidData );
break;
default :
/* It is not possible to get here as all enums have their own
case. */
break;
}
sprintf( cMessage, "identifier %d\r\n\r\n", ( int ) usIdentifier );
vOutputString( cMessage );
}