X-Git-Url: https://git.sur5r.net/?p=freertos;a=blobdiff_plain;f=FreeRTOS-Plus%2FSource%2FFreeRTOS-Plus-TCP%2Fportable%2FNetworkInterface%2FZynq%2Funcached_memory.c;fp=FreeRTOS-Plus%2FSource%2FFreeRTOS-Plus-TCP%2Fportable%2FNetworkInterface%2FZynq%2Funcached_memory.c;h=bfbdc341b50f06557d04e7c301da965f719edda1;hp=b43e50ec20f4bc5f410b39d1653cc6d0767b3982;hb=584c29e09cf7a95184b0e32718e8f711b781ffea;hpb=c5efd011e8c638d413ac395419119a451a0cb169 diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/uncached_memory.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/uncached_memory.c index b43e50ec2..bfbdc341b 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/uncached_memory.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/uncached_memory.c @@ -1,10 +1,35 @@ +/* + * FreeRTOS V202002.00 + * Copyright (C) 2020 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://aws.amazon.com/freertos + * http://www.FreeRTOS.org + */ + /* * uncached_memory.c * * This module will declare 1 MB of memory and switch off the caching for it. * * pucGetUncachedMemory( ulSize ) returns a trunc of this memory with a length - * rounded up to a multiple of 4 KB + * rounded up to a multiple of 4 KB. * * ucIsCachedMemory( pucBuffer ) returns non-zero if a given pointer is NOT * within the range of the 1 MB non-cached memory. @@ -43,23 +68,35 @@ #include "uncached_memory.h" -#define UNCACHED_MEMORY_SIZE 0x100000ul +/* Reserve 1 MB of memory. */ +#define uncMEMORY_SIZE 0x100000uL + +/* Make sure that each pointer has an alignment of 4 KB. */ +#define uncALIGNMENT_SIZE 0x1000uL #define DDR_MEMORY_END (XPAR_PS7_DDR_0_S_AXI_HIGHADDR+1) +#define uncMEMORY_ATTRIBUTE 0x1C02 + static void vInitialiseUncachedMemory( void ); static uint8_t *pucHeadOfMemory; static uint32_t ulMemorySize; static uint8_t *pucStartOfMemory = NULL; +/* The linker file defines some pseudo variables. '_end' is one of them. +It is located at the first free byte in RAM. */ +extern u8 _end; + +/*-----------------------------------------------------------*/ + uint8_t ucIsCachedMemory( const uint8_t *pucBuffer ) { uint8_t ucReturn; if( ( pucStartOfMemory != NULL ) && ( pucBuffer >= pucStartOfMemory ) && - ( pucBuffer < ( pucStartOfMemory + UNCACHED_MEMORY_SIZE ) ) ) + ( pucBuffer < ( pucStartOfMemory + uncMEMORY_SIZE ) ) ) { ucReturn = pdFALSE; } @@ -70,10 +107,12 @@ uint8_t ucReturn; return ucReturn; } +/*-----------------------------------------------------------*/ uint8_t *pucGetUncachedMemory( uint32_t ulSize ) { uint8_t *pucReturn; +uint32_t ulSkipSize; if( pucStartOfMemory == NULL ) { @@ -85,48 +124,40 @@ uint8_t *pucReturn; } else { - uint32_t ulSkipSize; - pucReturn = pucHeadOfMemory; - ulSkipSize = ( ulSize + 0x1000ul ) & ~0xffful; + /* Make sure that the next pointer return will have a good alignment. */ + ulSkipSize = ( ulSize + uncALIGNMENT_SIZE ) & ~( uncALIGNMENT_SIZE - 1uL ); pucHeadOfMemory += ulSkipSize; ulMemorySize -= ulSkipSize; } return pucReturn; } - -extern u8 _end; +/*-----------------------------------------------------------*/ static void vInitialiseUncachedMemory( ) { /* At the end of program's space... */ - pucStartOfMemory = (uint8_t *) &_end; - /* - * Align the start address to 1 MB boundary. - */ - pucStartOfMemory = (uint8_t *)( ( ( uint32_t )pucStartOfMemory + UNCACHED_MEMORY_SIZE ) & ( ~( UNCACHED_MEMORY_SIZE - 1 ) ) ); + pucStartOfMemory = ( uint8_t * ) &( _end ); - if( ( ( u32 )pucStartOfMemory ) + UNCACHED_MEMORY_SIZE > DDR_MEMORY_END ) + /* Align the start address to 1 MB boundary. */ + pucStartOfMemory = ( uint8_t * )( ( ( uint32_t )pucStartOfMemory + uncMEMORY_SIZE ) & ( ~( uncMEMORY_SIZE - 1 ) ) ); + + if( ( ( u32 )pucStartOfMemory ) + uncMEMORY_SIZE > DDR_MEMORY_END ) { -// vLoggingPrintf("vInitialiseUncachedMemory: Can not allocate uncached memory\n" ); + FreeRTOS_printf( ( "vInitialiseUncachedMemory: Can not allocate uncached memory\n" ) ); } else { - /* - * Some objects want to be stored in uncached memory. Hence the 1 MB - * address range that starts after "_end" is made uncached - * by setting appropriate attributes in the translation table. - */ - /* FIXME claudio rossi. Modified to prevent data abort exception (misaligned access) - * when application is compiled with -O1 or more optimization flag. - */ -/* Xil_SetTlbAttributes( ( uint32_t )pucStartOfMemory, 0xc02 ); // addr, attr */ - Xil_SetTlbAttributes( ( uint32_t )pucStartOfMemory, 0x1c02 ); // addr, attr - - /* For experiments in the SDIO driver, make the remaining uncached memory public */ + /* Some objects want to be stored in uncached memory. Hence the 1 MB + address range that starts after "_end" is made uncached by setting + appropriate attributes in the translation table. */ + Xil_SetTlbAttributes( ( uint32_t ) pucStartOfMemory, uncMEMORY_ATTRIBUTE ); + + /* For experiments in the SDIO driver, make the remaining uncached memory + public */ pucHeadOfMemory = pucStartOfMemory; - ulMemorySize = UNCACHED_MEMORY_SIZE; - memset( pucStartOfMemory, '\0', UNCACHED_MEMORY_SIZE ); + ulMemorySize = uncMEMORY_SIZE; + memset( pucStartOfMemory, '\0', uncMEMORY_SIZE ); } }