Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sage psp free rtos #3

Draft
wants to merge 6 commits into
base: sage-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions fsw/freertos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
add_library(psp-${CFE_PSP_TARGETNAME}-impl OBJECT
src/cfe_psp_exceptions.c
src/cfe_psp_memory.c
src/cfe_psp_memtab.c
src/cfe_psp_support.c
src/cfe_psp_timer.c
src/cfe_psp_watchdog.c
)

target_compile_definitions(psp-${CFE_SYSTEM_PSPNAME}-impl PRIVATE
$<TARGET_PROPERTY:psp_module_api,INTERFACE_COMPILE_DEFINITIONS>
)

target_include_directories(psp-${CFE_PSP_TARGETNAME}-impl PRIVATE
inc
$<TARGET_PROPERTY:psp_module_api,INTERFACE_INCLUDE_DIRECTORIES>
)
16 changes: 16 additions & 0 deletions fsw/freertos/inc/cfe_psp_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef _cfe_psp_config_
#define _cfe_psp_config_


// FreeRTOS headers
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"


// Watchdog
#define CFE_PSP_WATCHDOG_MIN 0
#define CFE_PSP_WATCHDOG_MAX 0xFFFFFFFF

#endif
771 changes: 771 additions & 0 deletions fsw/freertos/inc/cmsis_os.h

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions fsw/freertos/inc/psp_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

/*! @file freertos/inc/psp_version.h
* @brief Purpose:
* @details Provide version identifiers for the cFE Platform Support Packages (PSP).
* See @ref cfsversions for version and build number and description
*/
#ifndef _psp_version_
#define _psp_version_

/*
* Development Build Macro Definitions
*/
#define CFE_PSP_IMPL_BUILD_NUMBER 1
#define CFE_PSP_IMPL_BUILD_BASELINE "v0.0.1-rc1"

/*
* Version Macro Definitions
*/
#define CFE_PSP_IMPL_MAJOR_VERSION 10/*!< @brief ONLY APPLY for OFFICIAL releases. Major version number. */
#define CFE_PSP_IMPL_MINOR_VERSION 0 /*!< @brief ONLY APPLY for OFFICIAL releases. Minor version number. */
#define CFE_PSP_IMPL_REVISION 1 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision number. */
#define CFE_PSP_IMPL_MISSION_REV 99 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision version number. A value of "99" indicates an unreleased development version. */

/*
* Tools to construct version string
*/
#define CFE_PSP_IMPL_STR_HELPER(x) #x /*!< @brief Helper function to concatenate strings from integer */
#define CFE_PSP_IMPL_STR(x) \
CFE_PSP_IMPL_STR_HELPER(x) /*!< @brief Helper function to concatenate strings from integer */

/*! @brief Development Build Version Number.
* @details Baseline git tag + Number of commits since baseline. @n
* See @ref cfsversions for format differences between development and release versions.
*/
#define CFE_PSP_IMPL_VERSION CFE_PSP_IMPL_BUILD_BASELINE CFE_PSP_IMPL_STR(CFE_PSP_IMPL_BUILD_NUMBER)

/*! @brief Development Build Version String.
* @details Reports the current development build's baseline, number, and name. Also includes a note about the latest
* official version. @n See @ref cfsversions for format differences between development and release versions.
*/
#define CFE_PSP_IMPL_VERSION_STRING \
" PSP DEVELOPMENT BUILD " CFE_PSP_IMPL_VERSION /* Codename for current development */ \
", Last Official Release: psp v0.0.0" /* For full support please use this version */

#endif /* _psp_version_ */
15 changes: 15 additions & 0 deletions fsw/freertos/src/cfe_psp_exceptions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

void CFE_PSP_AttachExceptions(void)
{
/* TODO */
}

void CFE_PSP_SetDefaultExceptionEnvironment(void)
{
/* TODO */
}

void CFE_PSP_ExceptionGetSummary_Impl(void *Buffer, char *ReasonBuf, uint32 ReasonSize)
{
/* TODO (change buffer pointer) */
}
217 changes: 217 additions & 0 deletions fsw/freertos/src/cfe_psp_memory.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
#include "cfe_psp_memory.h"
#include "cfe_psp.h"
#include "cfe_psp_config.h" // TODO: set up (for reservedbootrecord and memalign mask)
#include "common_types.h" // defined in osal/src/os/inc

/* macros */
#define CFE_PSP_CDS_SIZE (GLOBAL_CONFIGDATA.CfeConfig->CdsSize)
#define CFE_PSP_RESET_AREA_SIZE (GLOBAL_CONFIGDATA.CfeConfig->ResetAreaSize)
#define CFE_PSP_USER_RESERVED_SIZE \
(GLOBAL_CONFIGDATA.CfeConfig->UserReservedSize)
#define CFE_PSP_RAM_DISK_SECTOR_SIZE \
(GLOBAL_CONFIGDATA.CfeConfig->RamDiskSectorSize)
#define CFE_PSP_RAM_DISK_NUM_SECTORS \
(GLOBAL_CONFIGDATA.CfeConfig->RamDiskTotalSectors)

#define CFE_PSP_RESERVED_MEMORY_SIZE 200 * 1024

#define CFE_PSP_BOOT_RECORD_SIZE (sizeof(CFE_PSP_ReservedMemoryBootRecord_t))
#define CFE_PSP_EXCEPTION_RECORD_SIZE (sizeof(CFE_PSP_ExceptionStorage_t))

#define memalign(x) (x + CFE_PSP_MEMALIGN_MASK) & ~CFE_PSP_MEMALIGN_MASK

extern char __text_start__;
extern char __text_end__;

CFE_PSP_ReservedMemoryMap_t CFE_PSP_ReservedMemoryMap = {0};

__attribute__((section(".psp_reserved"))) __attribute__((
aligned(8))) char pspReservedMemoryAlloc[CFE_PSP_RESERVED_MEMORY_SIZE];

/*
* CDS related functions
*/

init32 CFE_PSP_GetCDSSize(uint32 *SizeOfCDS) {

if (SizeOfCDS == NULL) {
return CFE_PSP_ERROR;
}

*SizeOfCDS = CFE_PSP_ReservedMemoryMap.CDSMemory.BlockSize;

return CFE_PSP_SUCCESS;
}

int32 CFE_PSP_WriteToCDS(const void *PtrToDataToWrite, uint32 CDSOffset,
uint32 NumBytes) {
uint8 *CopyPtr;

if (PtrToDataToWrite == NULL ||
(CDSOffset >= CFE_PSP_ReservedMemoryMap.CDSMemory.BlockSize) ||
((CDSOffset + NumBytes) >
CFE_PSP_ReservedMemoryMap.CDSMemory.BlockSize)) {
return CFE_PSP_ERROR;
}

CopyPtr = CFE_PSP_ReservedMemoryMap.CDSMemory.BlockPtr;
CopyPtr += CDSOffset;
memcpy((char *)CopyPtr, (char *)PtrToDataToWrite, NumBytes);

return CFE_PSP_SUCCESS;
}

int32 CFE_PSP_ReadFromCDS(void *PtrToDataToRead, uint32 CDSOffset,
uint32 NumBytes) {
uint8 *CopyPtr;

if (PtrToDataToRead == NULL ||
(CDSOffset >= CFE_PSP_ReservedMemoryMap.CDSMemory.BlockSize) ||
((CDSOffset + NumBytes) >
CFE_PSP_ReservedMemoryMap.CDSMemory.BlockSize)) {
return CFE_PSP_ERROR;
}

CopyPtr = CFE_PSP_ReservedMemoryMap.CDSMemory.BlockPtr;
CopyPtr += CDSOffset;
memcpy((char *)PtrToDataToRead, (char *)CopyPtr, NumBytes);

return CFE_PSP_SUCCESS;
}

/*
* Reset Area related functions
*/

int32 CFE_PSP_GetResetArea(cpuaddr *PtrToResetArea, uint32 *SizeOfResetArea) {
if (PtrToResetArea == NULL || SizeOfResetArea == NULL) {
return CFE_PSP_ERROR;
}

*PtrToResetArea = (cpuaddr)CFE_PSP_ReservedMemoryMap.ResetMemory.BlockPtr;
*SizeOfResetArea = CFE_PSP_ReservedMemoryMap.ResetMemory.BlockSize;

return CFE_PSP_SUCCESS;
}

/*
* Reserved Area related functions
*/

int32 CFE_PSP_GetUserReservedArea(cpuaddr *PtrToUserArea,
uint32 *SizeOfUserArea) {
if (PtrToUserArea == NULL || SizeOfUserArea == NULL) {
return CFE_PSP_ERROR;
}

*PtrToUserArea =
(cpuaddr)CFE_PSP_ReservedMemoryMap.UserReservedMemory.BlockPtr;
*SizeOfUserArea = CFE_PSP_ReservedMemoryMap.UserReservedMemory.BlockSize;

return CFE_PSP_SUCCESS;
}

/*
* Volatile Disk Memory related functions
*/

int32 CFE_PSP_GetVolatileDiskMem(cpuaddr *PtrToVolDisk, uint32 *SizeOfVolDisk) {
if (PtrToVolDisk == NULL || SizeOfVolDisk == NULL) {
return CFE_PSP_ERROR;
}

*PtrToVolDisk =
(cpuaddr)CFE_PSP_ReservedMemoryMap.VolatileDiskMemory.BlockPtr;
*SizeOfVolDisk = CFE_PSP_ReservedMemoryMap.VolatileDiskMemory.BlockSize;

return CFE_PSP_SUCCESS;
}

/*
* Kernel Memory functions
* TODO: relies on __text_start__ and __text_end__ defined in linker
*/

int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment,
uint32 *SizeOfKernelSegment) {
cpuaddr StartAddress;
cpuaddr EndAddress;

if (SizeOfKernelSegment == NULL) {
return CFE_PSP_ERROR;
}

StartAddress = (cpuaddr)&__text_start__;
EndAddress = (cpuaddr)&__text_end__;

*PtrToKernelSegment = StartAddress;
*SizeOfKernelSegment = (uint32)(EndAddress - StartAddress);

return CFE_PSP_SUCCESS;
}

/*
* Top Level Reserved Memory initialization
*/

int32 CFE_PSP_InitProcessorReservedMemory(uint32 RestartType) {
if (RestartType != CFE_PSP_RST_TYPE_PROCESSOR) {
memset(ReservedMemBlock.BlockPtr, 0, ReservedMemBlock.BlockSize);

CFE_PSP_ReservedMemoryMap.BootPtr->bsp_reset_type =
CFE_PSP_RST_TYPE_PROCESSOR;
}

return CFE_PSP_SUCCESS;
}

void CFE_PSP_SetupReservedMemoryMap(void) {
cpuaddr ReservedMemoryAddr;

size_t ResetSize = memalign(CFE_PSP_RESET_AREA_SIZE);
size_t CDSSize = memalign(CFE_PSP_CDS_SIZE);
size_t UserReservedSize = memalign(CFE_PSP_USER_RESERVED_SIZE);
size_t VolatileDiskSize =
memalign(CFE_PSP_RAM_DISK_SECTOR_SIZE * CFE_PSP_RAM_DISK_NUM_SECTORS);
size_t RequiredSize = 0;

RequiredSize += ResetSize;
RequiredSize += CDSSize;
RequiredSize += UserReservedSize;
RequiredSize += VolatileDiskSize;

if ((unsigned int)RequiredSize > CFE_PSP_RESERVED_MEMORY_SIZE) {
return;
}

ReservedMemoryAddr = pspReservedMemoryAlloc;

CFE_PSP_ReservedMemoryMap.BootPtr = (void *)ReservedMemoryAddr;
ReservedMemoryAddr += CFE_PSP_BOOT_RECORD_SIZE;

CFE_PSP_ReservedMemoryMap.ExceptionStoragePtr = (void *)ReservedMemoryAddr;
ReservedMemoryAddr += CFE_PSP_EXCEPTION_RECORD_SIZE;

CFE_PSP_ReservedMemoryMap.ResetMemory.BlockPtr = (void *)ReservedMemoryAddr;
CFE_PSP_ReservedMemoryMap.ResetMemory.BlockSize = CFE_PSP_RESET_AREA_SIZE;
ReservedMemoryAddr += ResetSize;

CFE_PSP_ReservedMemoryMap.VolatileDiskMemory.BlockPtr =
(void *)ReservedMemoryAddr;
CFE_PSP_ReservedMemoryMap.VolatileDiskMemory.BlockSize =
CFE_PSP_RAM_DISK_SECTOR_SIZE * CFE_PSP_RAM_DISK_NUM_SECTORS;
ReservedMemoryAddr += VolatileDiskSize;

CFE_PSP_ReservedMemoryMap.CDSMemory.BlockPtr = (void *)ReservedMemoryAddr;
CFE_PSP_ReservedMemoryMap.CDSMemory.BlockSize = CFE_PSP_CDS_SIZE;
ReservedMemoryAddr += CDSSize;

CFE_PSP_ReservedMemoryMap.UserReservedMemory.BlockPtr =
(void *)ReservedMemoryAddr;
CFE_PSP_ReservedMemoryMap.UserReservedMemory.BlockSize =
CFE_PSP_USER_RESERVED_SIZE;
ReservedMemoryAddr += UserReservedSize;

Check warning

Code scanning / CppCheck

Variable 'ReservedMemoryAddr' is assigned a value that is never used. Warning

Variable 'ReservedMemoryAddr' is assigned a value that is never used.
}

// no action needed
void CFE_PSP_DeleteProcessorReservedMemory(void) {}
42 changes: 42 additions & 0 deletions fsw/freertos/src/cfe_psp_memtab.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#include "common_types.h"
#include "osapi.h"
#include "cfe_psp.h"
#include "cfe_psp_config.h"

/*
** Valid memory map for this target.
** If you need to add more entries, increase CFE_PSP_MEM_TABLE_SIZE in the osconfig.h file.
*/
CFE_PSP_MemTable_t CFE_PSP_MemoryTable[CFE_PSP_MEM_TABLE_SIZE] =
{
{ CFE_PSP_MEM_RAM, CFE_PSP_MEM_SIZE_DWORD, 0, 0xFFFFFFFF, CFE_PSP_MEM_ATTR_READWRITE },
{ CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE },
{ CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE },
{ CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE },
{ CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE },
{ CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE },
{ CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE },
{ CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE },
{ CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE },
{ CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE },
};
Loading
Loading