forked from nasa/PSP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
931 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |