Skip to content

Commit

Permalink
further implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiaPT committed Jul 26, 2024
1 parent 5419a00 commit 04f2912
Show file tree
Hide file tree
Showing 7 changed files with 931 additions and 97 deletions.
11 changes: 9 additions & 2 deletions fsw/freertos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include_directories(inc)

add_library(psp-${CFE_PSP_TARGETNAME}-impl OBJECT
src/cfe_psp_exceptions.c
src/cfe_psp_memory.c
Expand All @@ -8,3 +6,12 @@ add_library(psp-${CFE_PSP_TARGETNAME}-impl OBJECT
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>
)
771 changes: 771 additions & 0 deletions fsw/freertos/inc/cmsis_os.h

Large diffs are not rendered by default.

18 changes: 7 additions & 11 deletions fsw/freertos/src/cfe_psp_memory.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include <sysLib.h>

#include "cfe_psp_memory.h"
#include "cfe_psp.h"
#include "cfe_psp_config.h" // TODO: set up (for reservedbootrecord and memalign mask)
#include "cfe_psp_memory.h"
#include "common_types.h" // defined in osal/src/os/inc

/* macros */
Expand All @@ -22,17 +20,14 @@

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

/* ------ */

/* Global Variables */
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
*/
Expand Down Expand Up @@ -134,6 +129,7 @@ int32 CFE_PSP_GetVolatileDiskMem(cpuaddr *PtrToVolDisk, uint32 *SizeOfVolDisk) {

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

int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment,
Expand All @@ -145,8 +141,8 @@ int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment,
return CFE_PSP_ERROR;
}

StartAddress = 0; // TODO: get kernel start address
EndAddress = 0; // TODO: get kernel end address
StartAddress = (cpuaddr)&__text_start__;
EndAddress = (cpuaddr)&__text_end__;

*PtrToKernelSegment = StartAddress;
*SizeOfKernelSegment = (uint32)(EndAddress - StartAddress);
Expand Down Expand Up @@ -217,5 +213,5 @@ void CFE_PSP_SetupReservedMemoryMap(void) {
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.
}

// TODO: is an action needed?
// no action needed
void CFE_PSP_DeleteProcessorReservedMemory(void) {}
105 changes: 55 additions & 50 deletions fsw/freertos/src/cfe_psp_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,67 @@

#define CFE_PSP_MAIN_FUNCTION (*GLOBAL_CONFIGDATA.CfeConfig->SystemMain)

#define CFE_PSP_NONVOL_STARTUP_FILE (GLOBAL_CONFIGDATA.CfeConfig->NonvolStartupFile)


void CFE_PSP_Restart(uint32 resetType)
{
if (resetType == CFE_PSP_RST_TYPE_POWERON)
{
CFE_PSP_ReservedMemoryMap.BootPtr->bsp_reset_type = CFE_PSP_RST_TYPE_POWERON;
CFE_PSP_FlushCaches(1, ReservedMemBlock.BlockPtr, ReservedMemBlock.BlockSize);
NVIC_SystemReset();
}
else
{
CFE_PSP_ReservedMemoryMap.BootPtr->bsp_reset_type = CFE_PSP_RST_TYPE_PROCESSOR;
CFE_PSP_FlushCaches(1, ReservedMemBlock.BlockPtr, ReservedMemBlock.BlockSize);
/* FIXME: reboot without wiping memory */
}
#define CFE_PSP_NONVOL_STARTUP_FILE \
(GLOBAL_CONFIGDATA.CfeConfig->NonvolStartupFile)

void CFE_PSP_Restart(uint32 resetType) {
if (resetType == CFE_PSP_RST_TYPE_POWERON) {
CFE_PSP_ReservedMemoryMap.BootPtr->bsp_reset_type =
CFE_PSP_RST_TYPE_POWERON;
CFE_PSP_FlushCaches(1, ReservedMemBlock.BlockPtr,
ReservedMemBlock.BlockSize);

NVIC_SystemReset();
} else {
CFE_PSP_ReservedMemoryMap.BootPtr->bsp_reset_type =
CFE_PSP_RST_TYPE_PROCESSOR;
CFE_PSP_FlushCaches(1, ReservedMemBlock.BlockPtr,
ReservedMemBlock.BlockSize);
/* FIXME: reboot without wiping memory */
}
}

uint32 CFE_PSP_GetRestartType(uint32 *restartSubType) {
if (restartSubType != NULL) {
restartSubType = CFE_PSP_ReservedMemoryMap.BootPtr->bsp_reset_type;

Check warning

Code scanning / CppCheck

Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? Warning

Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?

Check warning

Code scanning / CppCheck

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

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

/* TODO: review this implementation by pztrick */

int CFE_PSP_Setup(void){
return CFE_PSP_SUCCESS;
return CFE_PSP_ReservedMemoryMap.BootPtr->bsp_reset_type;
}

void CFE_PSP_Panic(int32 ErrorCode){
__asm("bkpt 1");
// vTaskEndScheduler();
OS_ApplicationExit(ErrorCode);
/* TODO: review this implementation by pztrick */
int CFE_PSP_Setup(void) { return CFE_PSP_SUCCESS; }

void CFE_PSP_Panic(int32 ErrorCode) {
__asm("bkpt 1");
// vTaskEndScheduler();
OS_ApplicationExit(ErrorCode);
}

// OSAL:main() invokes PSP:OS_Application_Startup() inside a FreeRTOS task
void OS_Application_Startup(void){
int32 status;
uint32 reset_type;
uint32 reset_subtype;

CFE_PSP_SetupReservedMemoryMap();

status = OS_API_Init();
if(status != OS_SUCCESS){
OS_ApplicationExit(status);
}

if(CFE_PSP_Setup() != CFE_PSP_SUCCESS){
CFE_PSP_Panic(CFE_PSP_ERROR);
}

// @FIXME should try to read reset_type from NVM BootPtr
reset_type = CFE_PSP_RST_TYPE_POWERON;
reset_subtype = CFE_PSP_RST_SUBTYPE_POWER_CYCLE;
CFE_PSP_InitProcessorReservedMemory(reset_type);

CFE_PSP_MAIN_FUNCTION(reset_type, reset_subtype, 1, CFE_PSP_NONVOL_STARTUP_FILE);

vTaskDelete(NULL);
void OS_Application_Startup(void) {
int32 status;
uint32 reset_type;
uint32 reset_subtype;

CFE_PSP_SetupReservedMemoryMap();

status = OS_API_Init();
if (status != OS_SUCCESS) {
OS_ApplicationExit(status);
}

if (CFE_PSP_Setup() != CFE_PSP_SUCCESS) {
CFE_PSP_Panic(CFE_PSP_ERROR);
}

// FIXME: should try to read reset_type from NVM BootPtr
reset_type = CFE_PSP_RST_TYPE_POWERON;
reset_subtype = CFE_PSP_RST_SUBTYPE_POWER_CYCLE;
CFE_PSP_InitProcessorReservedMemory(reset_type);

CFE_PSP_MAIN_FUNCTION(reset_type, reset_subtype, 1,
CFE_PSP_NONVOL_STARTUP_FILE);

vTaskDelete(NULL);
}
24 changes: 21 additions & 3 deletions fsw/freertos/src/cfe_psp_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
************************************************************************/

#include "cmsis_os.h"

#include "target_config.h"

#include <zlib.h>

#define CHUNK 16384

#define CFE_PSP_CPU_ID (GLOBAL_CONFIGDATA.CpuId)
#define CFE_PSP_CPU_NAME (GLOBAL_CONFIGDATA.CpuName)
#define CFE_PSP_SPACECRAFT_ID (GLOBAL_CONFIGDATA.SpacecraftId)

// TODO
void CFE_PSP_FlushCaches(uint32 type, void *address, uint32 size) {
if (type != 1) {
return;
Expand All @@ -47,4 +49,20 @@ uint32 CFE_PSP_GetSpacecraftId(void) { return CFE_PSP_SPACECRAFT_ID; }

const char *CFE_PSP_GetProcessorName(void) { return CFE_PSP_CPU_NAME; }

uint32 CFE_PSP_Get_Timer_Tick(void) { /* TODO */ }
void CFE_PSP_Decompress(char *srcFileName, char *dstFileName) {
char buffer[CHUNK];
int bytes_read;

// Open the gzip file
gzFile gz = gzopen(input_file, "rb");
FILE *out = fopen(output_file, "wb");

// Decompress the file
while ((bytes_read = gzread(gz, buffer, CHUNK)) > 0) {
fwrite(buffer, 1, bytes_read, out);
}

// Close the files
gzclose(gz);
fclose(out);
}
36 changes: 25 additions & 11 deletions fsw/freertos/src/cfe_psp_timer.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
#define CFE_PSP_TIMER_TICKS_PER_SECOND ((int32) configTICK_RATE_HZ)
#include "common_types.h"

uint32 CFE_PSP_GetTimerTicksPerSecond(void)
{
return CFE_PSP_TIMER_TICKS_PER_SECOND;
#define CFE_PSP_TIMER_TICKS_PER_SECOND ((int32)configTICK_RATE_HZ)

uint32 CFE_PSP_GetTimerTicksPerSecond(void) {
return CFE_PSP_TIMER_TICKS_PER_SECOND;
}

uint32 CFE_PSP_GetTimerLow32Rollover(void)
{
return 0;
uint32 CFE_PSP_GetTimerLow32Rollover(void) { return 0; }

void CFE_PSP_Get_Timebase(uint32 *Tbu, uint32 *Tbl) {
*Tbu = 0;
*Tbl = HAL_GetTick();
}

void CFE_PSP_Get_Timebase(uint32 *Tbu, uint32 *Tbl)
{
// SysTick is set up in HAL_Init
return xTaskGetTickCount;
uint32 CFE_PSP_Get_Timer_Tick(void) { return HAL_GetTick(); }

void CFE_PSP_GetTime(OS_time_t *LocalTime) {
uint64 NormalizedTicks;
uint32 RegUpper, RegLower;

CFE_PSP_Get_Timebase(&RegUpper, &RegLower);

NormalizedTicks = RegUpper;
NormalizedTicks <<= 32;
NormalizedTicks |= RegLower;

NormalizedTicks *= portTICK_PERIOD_MS;

*LocalTime = (OS_time_t){NormalizedTicks};
}
63 changes: 43 additions & 20 deletions fsw/freertos/src/cfe_psp_watchdog.c
Original file line number Diff line number Diff line change
@@ -1,34 +1,57 @@
#include "FreeRTOS.h"
#include "cfe_psp.h"
#include "cfe_psp_config.h"
#include "stm32h7xx_hal.h"
#include "task.h"

uint32 CFE_PSP_WatchdogValue = CFE_PSP_WATCHDOG_MAX;
bool watchdog_enabled = false;
IWDG_HandleTypeDef IwdgHandle;

void CFE_PSP_WatchdogInit(void)
{
CFE_PSP_WatchdogValue = CFE_PSP_WATCHDOG_MAX;
}
// TODO: relies on already called in main HAL_Init() and SystemClock_Config()
void CFE_PSP_WatchdogInit(void) {
__HAL_RCC_WWDG_CLK_ENABLE();

// Set up the IWDG handle
IwdgHandle.Instance = IWDG1;
IwdgHandle.Init.Prescaler = IWDG_PRESCALER_64;
IwdgHandle.Init.Reload = CFE_PSP_WATCHDOG_MAX; // Maximum timeout ms

void CFE_PSP_WatchdogEnable(void)
{
/* TODO */
// Initialize the IWDG
if (HAL_IWDG_Init(&IwdgHandle) != HAL_OK) {
return CFE_PSP_ERROR;
}
}

void CFE_PSP_WatchdogDisable(void)
{
/* TODO */
void WatchdogTask(void *pvParameters) {
for (;;) {
if (watchdog_enabled) {
HAL_IWDG_Refresh(&IwdgHandle);
}
// Delay for a period shorter than the watchdog timeout
vTaskDelay(pdMS_TO_TICKS(1000));
}
}

void CFE_PSP_WatchdogService(void)
{
/* TODO */
void CFE_PSP_WatchdogEnable(void) {
xTaskCreate(WatchdogTask, "WatchdogTask", configMINIMAL_STACK_SIZE, NULL,
tskIDLE_PRIORITY, NULL);
}

uint32 CFE_PSP_WatchdogGet(void)
{
return CFE_PSP_WatchdogValue;
void CFE_PSP_WatchdogDisable(void) { watchdog_enabled = true; }

void CFE_PSP_WatchdogService(void) { /* TODO: What to do when a timer expires */
}

void CFE_PSP_WatchdogSet(uint32 WatchdogValue)
{
CFE_PSP_WatchdogValue = WatchdogValue;
uint32 CFE_PSP_WatchdogGet(void) { return IwdgHandle->SR; }

void CFE_PSP_WatchdogSet(uint32 WatchdogValue) {
CFE_PSP_WatchdogDisable();

// Reinitialize the IWDG with new configuration
IwdgHandle.Init.Reload = WatchdogValue;
if (HAL_IWDG_Init(&IwdgHandle) != HAL_OK) {
return CFE_PSP_ERROR;
}

Enable_Watchdog();
}

0 comments on commit 04f2912

Please sign in to comment.