Demo: qemu mps2 echo client cleanup (#833)

This commit is contained in:
alfred gedeon
2022-08-02 15:05:14 -07:00
committed by GitHub
parent 9058c39aed
commit 4242c47a8d
5 changed files with 386 additions and 399 deletions
@@ -47,10 +47,6 @@ SOURCE_FILES += ${FREERTOS_TCP}/portable/NetworkInterface/MPS2_AN385/NetworkInte
SOURCE_FILES += TCPEchoClient_SingleTasks.c
SOURCE_FILES += ${FREERTOS_TCP}/portable/NetworkInterface/MPS2_AN385/ether_lan9118/smsc9220_eth_drv.c
# networking specific cflags
CFLAGS := -DmainCREATE_NETWORKING_DEMO_ONLY=1
CFLAGS += -DmainCREATE_TCP_ECHO_TASKS_SINGLE=1
DEFINES := -DprojCOVERAGE_TEST -DQEMU_SOC_MPS2 -DHEAP3
LDFLAGS = -T ./scripts/mps2_m3.ld -specs=nano.specs --specs=rdimon.specs -lc -lrdimon
File diff suppressed because it is too large Load Diff
@@ -37,48 +37,50 @@ extern void xPortSysTickHandler( void );
extern void uart_init();
extern int main();
void __attribute__((weak)) EthernetISR (void);
void __attribute__( ( weak ) ) EthernetISR( void );
extern uint32_t _estack, _sidata, _sdata, _edata, _sbss, _ebss;
/* Prevent optimization so gcc does not replace code with memcpy */
__attribute__((optimize("O0")))
__attribute__((naked))
void Reset_Handler(void)
{
// set stack pointer
__asm volatile ("ldr r0, =_estack");
__asm volatile ("mov sp, r0");
// copy .data section from flash to RAM
for (uint32_t *src = &_sidata, *dest = &_sdata; dest < &_edata;)
__attribute__( ( optimize( "O0" ) ) )
__attribute__( ( naked ) )
void Reset_Handler( void )
{
/* set stack pointer */
__asm volatile ( "ldr r0, =_estack" );
__asm volatile ( "mov sp, r0" );
/* copy .data section from flash to RAM */
for( uint32_t * src = &_sidata, * dest = &_sdata; dest < &_edata; )
{
*dest++ = *src++;
}
// zero out .bss section
for (uint32_t *dest = &_sbss; dest < &_ebss;)
/* zero out .bss section */
for( uint32_t * dest = &_sbss; dest < &_ebss; )
{
*dest++ = 0;
}
// jump to board initialisation
void _start(void);
/* jump to board initialisation */
void _start( void );
_start();
}
void prvGetRegistersFromStack( uint32_t *pulFaultStackAddress )
void prvGetRegistersFromStack( uint32_t * pulFaultStackAddress )
{
/* These are volatile to try and prevent the compiler/linker optimising them
away as the variables never actually get used. If the debugger won't show the
values of the variables, make them global my moving their declaration outside
of this function. */
* away as the variables never actually get used. If the debugger won't show the
* values of the variables, make them global my moving their declaration outside
* of this function. */
volatile uint32_t r0;
volatile uint32_t r1;
volatile uint32_t r2;
volatile uint32_t r3;
volatile uint32_t r12;
volatile uint32_t lr; /* Link register. */
volatile uint32_t pc; /* Program counter. */
volatile uint32_t psr;/* Program status register. */
volatile uint32_t lr; /* Link register. */
volatile uint32_t pc; /* Program counter. */
volatile uint32_t psr; /* Program status register. */
r0 = pulFaultStackAddress[ 0 ];
r1 = pulFaultStackAddress[ 1 ];
@@ -91,11 +93,13 @@ of this function. */
psr = pulFaultStackAddress[ 7 ];
/* When the following line is hit, the variables contain the register values. */
for( ;; );
for( ; ; )
{
}
}
static void Default_Handler( void ) __attribute__( ( naked ) );
void Default_Handler(void)
void Default_Handler( void )
{
__asm volatile
(
@@ -111,9 +115,8 @@ void Default_Handler(void)
);
}
static void HardFault_Handler( void ) __attribute__( ( naked ) );
void Default_Handler2(void)
void Default_Handler2( void )
{
__asm volatile
(
" tst lr, #4 \n"
@@ -127,79 +130,86 @@ void Default_Handler2(void)
);
}
void Default_Handler3(void)
void Default_Handler3( void )
{
for (;;) { }
for( ; ; )
{
}
}
void Default_Handler4(void)
void Default_Handler4( void )
{
for (;;) { }
for( ; ; )
{
}
}
void Default_Handler5(void)
void Default_Handler5( void )
{
for (;;) { }
for( ; ; )
{
}
}
void Default_Handler6(void)
void Default_Handler6( void )
{
for (;;) { }
for( ; ; )
{
}
}
const uint32_t* isr_vector[] __attribute__((section(".isr_vector"))) =
const uint32_t * isr_vector[] __attribute__( ( section( ".isr_vector" ) ) ) =
{
(uint32_t*)&_estack,
(uint32_t*)&Reset_Handler, // Reset -15
(uint32_t*)&Default_Handler, // NMI_Handler -14
(uint32_t*)&Default_Handler2, // HardFault_Handler -13
(uint32_t*)&Default_Handler3, // MemManage_Handler -12
(uint32_t*)&Default_Handler4, // BusFault_Handler -11
(uint32_t*)&Default_Handler5, // UsageFault_Handler -10
0, // reserved
0, // reserved
0, // reserved
0, // reserved -6
(uint32_t*)&vPortSVCHandler, // SVC_Handler -5
(uint32_t*)&Default_Handler6, // DebugMon_Handler -4
0, // reserved
(uint32_t*)&xPortPendSVHandler, // PendSV handler -2
(uint32_t*)&xPortSysTickHandler, // SysTick_Handler -1
0, // uart0 receive 0
0, // uart0 transmit
0, // uart1 receive
0, // uart1 transmit
0, // uart 2 receive
0, // uart 2 transmit
0, // GPIO 0 combined interrupt
0, // GPIO 2 combined interrupt
0, // Timer 0
0, // Timer 1
0, // Dial Timer
0, // SPI0 SPI1
0, // uart overflow 1 2,3 12
(uint32_t*)&EthernetISR, // Ethernet 13
( uint32_t * ) &_estack,
( uint32_t * ) &Reset_Handler, /* Reset -15 */
( uint32_t * ) &Default_Handler, /* NMI_Handler -14 */
( uint32_t * ) &Default_Handler2, /* HardFault_Handler -13 */
( uint32_t * ) &Default_Handler3, /* MemManage_Handler -12 */
( uint32_t * ) &Default_Handler4, /* BusFault_Handler -11 */
( uint32_t * ) &Default_Handler5, /* UsageFault_Handler -10 */
0, /* reserved */
0, /* reserved */
0, /* reserved */
0, /* reserved -6 */
( uint32_t * ) &vPortSVCHandler, /* SVC_Handler -5 */
( uint32_t * ) &Default_Handler6, /* DebugMon_Handler -4 */
0, /* reserved */
( uint32_t * ) &xPortPendSVHandler, /* PendSV handler -2 */
( uint32_t * ) &xPortSysTickHandler, /* SysTick_Handler -1 */
0, /* uart0 receive 0 */
0, /* uart0 transmit */
0, /* uart1 receive */
0, /* uart1 transmit */
0, /* uart 2 receive */
0, /* uart 2 transmit */
0, /* GPIO 0 combined interrupt */
0, /* GPIO 2 combined interrupt */
0, /* Timer 0 */
0, /* Timer 1 */
0, /* Dial Timer */
0, /* SPI0 SPI1 */
0, /* uart overflow 1 2,3 12 */
( uint32_t * ) &EthernetISR, /* Ethernet 13 */
};
void _start(void)
void _start( void )
{
uart_init();
main(0, 0);
exit(0);
main( 0, 0 );
exit( 0 );
}
__attribute__((naked)) void exit(int status)
__attribute__( ( naked ) ) void exit( int status )
{
// Force qemu to exit using ARM Semihosting
/* Force qemu to exit using ARM Semihosting */
__asm volatile (
"mov r1, r0\n"
"cmp r1, #0\n"
"bne .notclean\n"
"ldr r1, =0x20026\n" // ADP_Stopped_ApplicationExit, a clean exit
"ldr r1, =0x20026\n" /* ADP_Stopped_ApplicationExit, a clean exit */
".notclean:\n"
"movs r0, #0x18\n" // SYS_EXIT
"movs r0, #0x18\n" /* SYS_EXIT */
"bkpt 0xab\n"
"end: b end\n"
);
}
@@ -43,16 +43,7 @@ extern void initialise_monitor_handles(void);
int main ()
{
#if ( mainCREATE_NETWORKING_DEMO_ONLY == 1 )
{
main_tcp_echo_client_tasks();
}
#else
{
#error "Invalid Selection..." \
"\nPlease Select a Demo application from the main command"
}
#endif
main_tcp_echo_client_tasks();
return 0;
}
@@ -26,8 +26,7 @@
/*
* This project is a cut down version of the project described on the following
* link. Only the simple UDP client and server and the TCP echo clients are
* included in the build:
* link. Only the TCP echo clients is included in the build:
* https://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html
*/
@@ -44,26 +43,15 @@
/* Demo application includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
/*#include "SimpleUDPClientAndServer.h" */
/*#include "SimpleTCPEchoServer.h" */
/*#include "logging.h" */
#include "TCPEchoClient_SingleTasks.h"
/* Simple UDP client and server task parameters. */
#define mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainSIMPLE_UDP_CLIENT_SERVER_PORT ( 5005UL )
/* Echo client task parameters - used for both TCP and UDP echo clients. */
#define mainECHO_CLIENT_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 ) /* Not used in the linux port. */
#define mainECHO_CLIENT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* Echo server task parameters. */
#define mainECHO_SERVER_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 ) /* Not used in the linux port. */
#define mainECHO_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* Echo client task parameters */
#define mainECHO_CLIENT_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 ) /* Not used in the linux port. */
#define mainECHO_CLIENT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* Define a name that will be used for LLMNR and NBNS searches. */
#define mainHOST_NAME "RTOSDemo"
#define mainDEVICE_NICK_NAME "qemu_demo"
#define mainHOST_NAME "RTOSDemo"
#define mainDEVICE_NICK_NAME "qemu_demo"
/* Set the following constants to 1 or 0 to define which tasks to include and
* exclude:
@@ -94,43 +82,43 @@ static void prvMiscInitialisation( void );
* 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
};
const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0,
configMAC_ADDR1,
configMAC_ADDR2,
configMAC_ADDR3,
configMAC_ADDR4,
configMAC_ADDR5
};
/* Set the following constant to pdTRUE to log using the method indicated by the
* name of the constant, or pdFALSE to not log using the method indicated by the
* name of the constant. Options include to standard out (xLogToStdout), to a disk
* file (xLogToFile), and to a UDP port (xLogToUDP). If xLogToUDP is set to pdTRUE
* then UDP messages are sent to the IP address configured as the echo server
* address (see the configECHO_SERVER_ADDR0 definitions in FreeRTOSConfig.h) and
* the port number set by configPRINT_PORT in FreeRTOSConfig.h. */
//const BaseType_t xLogToStdout = pdTRUE, xLogToFile = pdFALSE, xLogToUDP = pdFALSE;
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
};
const uint8_t ucMACAddress[ 6 ] =
{
configMAC_ADDR0,
configMAC_ADDR1,
configMAC_ADDR2,
configMAC_ADDR3,
configMAC_ADDR4,
configMAC_ADDR5
};
/* Use by the pseudo random number generator. */
static UBaseType_t ulNextRand;
@@ -182,7 +170,8 @@ void main_tcp_echo_client_tasks( void )
}
/*-----------------------------------------------------------*/
BaseType_t xTasksAlreadyCreated = pdFALSE;
BaseType_t xTasksAlreadyCreated = pdFALSE;
/* Called by FreeRTOS+TCP when the network connects or disconnects. Disconnect
* events are only received if implemented in the MAC driver. */
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
@@ -205,10 +194,10 @@ void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
* demo tasks. */
#if ( mainCREATE_TCP_ECHO_TASKS_SINGLE == 1 )
{
vStartTCPEchoClientTasks_SingleTasks( mainECHO_CLIENT_TASK_STACK_SIZE,
mainECHO_CLIENT_TASK_PRIORITY );
}
{
vStartTCPEchoClientTasks_SingleTasks( mainECHO_CLIENT_TASK_STACK_SIZE,
mainECHO_CLIENT_TASK_PRIORITY );
}
#endif /* mainCREATE_TCP_ECHO_TASKS_SINGLE */
xTasksAlreadyCreated = pdTRUE;
@@ -231,7 +220,7 @@ void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
}
else
{
FreeRTOS_printf( ("Application idle hook network down\n") );
FreeRTOS_printf( ( "Application idle hook network down\n" ) );
}
}
/*-----------------------------------------------------------*/