Skip to content

Commit

Permalink
NVM library bringup
Browse files Browse the repository at this point in the history
- BMS Boss NVM bringup
- BMS Worker NVM bringup
- Support NVM in Bootloader to not overwrite NVM on download
- Support NVM in the F105
- Added NVM FeatureDef
  • Loading branch information
JoshLafleur committed Feb 1, 2025
1 parent b7efd8e commit 2b92b1e
Show file tree
Hide file tree
Showing 41 changed files with 1,379 additions and 28 deletions.
7 changes: 6 additions & 1 deletion components/bms_boss/FeatureSels.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
featureDefs: "#/components/bms_boss/FeatureDefs.yaml"
featureDefs:
- "#/components/bms_boss/FeatureDefs.yaml"
- "#/components/shared/FeatureDefs/NVM_FeatureDefs.yaml"
features:
feature_cantx_swi:
feature_canrx_swi:
nvm_lib_enabled: true
nvm_flash_backed: true
nvm_block_size: 2048
4 changes: 4 additions & 0 deletions components/bms_boss/HW/HW.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// Firmware Includes
#include "stm32f1xx.h"
#include "include/HW_tim.h"
#include "LIB_nvm.h"

typedef struct
{
Expand Down Expand Up @@ -87,5 +88,8 @@ void HW_usDelay(uint8_t us)

void HW_systemHardReset(void)
{
#if FEATURE_IS_ENABLED(NVM_LIB_ENABLED)
lib_nvm_cleanUp();
#endif
pSCB->AIRCR = AIRCR_RESET_REQ;
}
4 changes: 4 additions & 0 deletions components/bms_boss/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ project_source_files = [
SRC_DIR.File("Utility.c"),
SRC_DIR.File("UDS.c"),
SHARED_LIBS.File("LIB_app.c"),
SHARED_LIBS.File("LIB_nvm.c"),
SHARED_LIBS.File("libcrc.c"),
SRC_DIR.File("LIB_nvm_componentSpecific.c"),
]

project_hw_files = [
Expand All @@ -161,6 +164,7 @@ project_hw_files = [
HW_DIR.File("HW_HIH.c"),
SHARED_HW.File("HW_can.c"),
SHARED_HW.File("HW_gpio.c"),
SHARED_HW.File("HW_flash.c"),
]

project_source_files += project_hw_files
Expand Down
5 changes: 5 additions & 0 deletions components/bms_boss/include/CANIO_componentSpecific.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "IMD.h"
#include "ENV.h"
#include "Module.h"
#include "LIB_nvm.h"

/******************************************************************************
* P R I V A T E F U N C T I O N P R O T O T Y P E S
Expand All @@ -49,6 +50,10 @@ CAN_prechargeContactorState_E CANIO_tx_getContactorState(void);
#define set_nlg513MaxChargeVoltage(m,b,n,s) set(m,b,n,s, BMS_CONFIGURED_PACK_MAX_VOLTAGE)
#define set_nlg513MaxChargeCurrent(m,b,n,s) set(m,b,n,s, BMS.pack_charge_limit)
#define transmit_BMSB_brusaChargeCommand (SYS_SFT_checkChargerTimeout() == false)
#define set_nvmBootCycles(m,b,n,s) set(m,b,n,s, lib_nvm_getTotalCycles())
#define set_nvmRecordWrites(m,b,n,s) set(m,b,n,s, lib_nvm_getTotalRecordWrites())
#define set_nvmBlockErases(m,b,n,s) set(m,b,n,s, lib_nvm_getTotalBlockErases())
#define set_nvmFailedCrc(m,b,n,s) set(m,b,n,s, lib_nvm_getTotalFailedCrc())
#define set_taskUsage1kHz(m,b,n,s) set(m,b,n,s, Module_getTotalRuntimePercentage(MODULE_1kHz_TASK));
#define set_taskUsage100Hz(m,b,n,s) set(m,b,n,s, Module_getTotalRuntimePercentage(MODULE_100Hz_TASK));
#define set_taskUsage10Hz(m,b,n,s) set(m,b,n,s, Module_getTotalRuntimePercentage(MODULE_10Hz_TASK));
Expand Down
24 changes: 24 additions & 0 deletions components/bms_boss/include/LIB_nvm_componentSpecific.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* LIB_nvm_config.h
* LIB_nvm Component Specific file
*/

#pragma once

#include "HW_tim.h"
#include "HW_flash.h"
#include "LIB_nvm.h"

/******************************************************************************
* T Y P E D E F S
******************************************************************************/

#define LIB_NVM_GET_TIME_MS HW_TIM_getTimeMS
#define LIB_NVM_GET_FLASH_PAGE_SIZE FLASH_getPageSize
#define LIB_NVM_CLEAR_FLASH_PAGES FLASH_erasePages
#define LIB_NVM_WRITE_TO_FLASH(addr, data, bytes) FLASH_writeHalfwords(addr, data, bytes / sizeof(storage_t))

typedef enum
{
NVM_ENTRYID_COUNT = 0U,
} lib_nvm_entryId_E;
7 changes: 7 additions & 0 deletions components/bms_boss/include/libcrc_componentSpecific.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* libcrc_componentSpecific.h
*
* Configuration for the libcrc module
*/

#define LIBCRC_CRC8_FAST
16 changes: 16 additions & 0 deletions components/bms_boss/src/LIB_nvm_componentSpecific.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file NVM.c
* @brief Source code for Non Volatile Memory Manager
*/

/******************************************************************************
* I N C L U D E S
******************************************************************************/

#include "LIB_nvm.h"

/******************************************************************************
* P U B L I C V A R S
******************************************************************************/

const lib_nvm_entry_S lib_nvm_entries[NVM_ENTRYID_COUNT];
3 changes: 3 additions & 0 deletions components/bms_boss/src/Module.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/**< Other Includes */
#include "Utility.h"
#include "FeatureDefines_generated.h"
#include "LIB_nvm.h"

/******************************************************************************
* P R I V A T E V A R S
Expand Down Expand Up @@ -53,6 +54,7 @@ static Module_taskStats_S stats[MODULE_TASK_CNT] = { 0 };
*/
void Module_Init(void)
{
lib_nvm_init();
/**< Run each of the modules Init function in order */
for (uint8_t i = 0U; i < COUNTOF(modules); i++)
{
Expand Down Expand Up @@ -93,6 +95,7 @@ void Module_100Hz_TSK(void)
(*modules[i]->periodic100Hz_CLK)();
}
}
lib_nvm_run();

stats[MODULE_100Hz_TASK].total_percentage = ulTaskGetRunTimePercent(NULL);
}
Expand Down
2 changes: 2 additions & 0 deletions components/bms_boss/src/SystemManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "HW_gpio.h"
#include "HW_i2c.h"
#include "HW_tim.h"
#include "HW_flash.h"

/**< FreeRTOS Includes */
#include "FreeRTOS.h"
Expand Down Expand Up @@ -82,6 +83,7 @@ int main(void)
HW_CAN_init();
HW_DMA_init();
HW_ADC_init();
FLASH_init();
HW_GPIO_init();

///**< Create RTOS Tasks, Timers, etc... */
Expand Down
46 changes: 46 additions & 0 deletions components/bms_boss/src/UDS.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "uds.h"
#include "LIB_app.h"
#include "Utility.h"
#include "LIB_nvm.h"

// system includes
#include <string.h>
Expand Down Expand Up @@ -66,6 +67,48 @@ extern void isotp_user_debug(const char* message, ...);
* P R I V A T E F U N C T I O N S
******************************************************************************/

static void routine_0xf0f0(udsRoutineControlType_E routineControlType, uint8_t *payload, uint8_t payloadLengthBytes)
{
UNUSED(payloadLengthBytes);
UNUSED(payload);

switch (routineControlType)
{
case UDS_ROUTINE_CONTROL_START:
{
uds_sendPositiveResponse(UDS_SID_ROUTINE_CONTROL,
UDS_ROUTINE_CONTROL_START,
payload,
payloadLengthBytes);
lib_nvm_nvmHardReset();
}
break;

case UDS_ROUTINE_CONTROL_GET_RESULT:
{
bool completed = lib_nvm_nvmHardResetGetStatus();
if (completed)
{
uds_sendPositiveResponse(UDS_SID_ROUTINE_CONTROL,
UDS_ROUTINE_CONTROL_GET_RESULT,
(uint8_t*)&completed,
sizeof(completed));
}
else
{
uds_sendNegativeResponse(UDS_SID_ROUTINE_CONTROL, UDS_NRC_CONDITIONS_NOT_CORRECT);
}
}
break;

case UDS_ROUTINE_CONTROL_STOP:
case UDS_ROUTINE_CONTROL_NONE:
default:
uds_sendNegativeResponse(UDS_SID_ROUTINE_CONTROL, UDS_NRC_SUB_FUNCTION_NOT_SUPPORTED);
break;
}

}

/******************************************************************************
* P U B L I C F U N C T I O N S
Expand Down Expand Up @@ -175,6 +218,9 @@ void uds_cb_routineControl(udsRoutineControlType_E routineControlType, uint8_t *

switch (routineId.u16)
{
case 0xf0f0:
routine_0xf0f0(routineControlType, payload, payloadLengthBytes);;
break;
default:
uds_sendNegativeResponse(UDS_SID_ROUTINE_CONTROL, UDS_NRC_SERVICE_NOT_SUPPORTED);
break;
Expand Down
7 changes: 6 additions & 1 deletion components/bms_worker/FeatureSels.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
featureDefs: "#/components/bms_worker/FeatureDefs.yaml"
featureDefs:
- "#/components/bms_worker/FeatureDefs.yaml"
- "#/components/shared/FeatureDefs/NVM_FeatureDefs.yaml"
features:
feature_max14921_calibrate:
feature_cantx_swi:
feature_canrx_swi:
feature_cell_diagnostics:
nvm_lib_enabled: true
nvm_flash_backed: true
nvm_block_size: 2048
4 changes: 4 additions & 0 deletions components/bms_worker/HW/HW.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// Firmware Includes
#include "include/HW_tim.h"
#include "stm32f1xx.h"
#include "LIB_nvm.h"

typedef struct
{
Expand Down Expand Up @@ -67,5 +68,8 @@ HW_StatusTypeDef_E HW_deInit(void)

void HW_systemHardReset(void)
{
#if FEATURE_IS_ENABLED(NVM_LIB_ENABLED)
lib_nvm_cleanUp();
#endif
pSCB->AIRCR = AIRCR_RESET_REQ;
}
4 changes: 4 additions & 0 deletions components/bms_worker/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ src_files = [
THERMS_DIR.File("NCP21XV103J03RA.c"),
THERMS_DIR.File("MF52C1103F3380.c"),
SHARED_LIBS.File("LIB_app.c"),
SHARED_LIBS.File("LIB_nvm.c"),
SRC_DIR.File("LIB_nvm_componentSpecific.c"),
SHARED_LIBS.File("libcrc.c"),
SRC_DIR.File("CANIO_componentSpecific.c"),
]

Expand All @@ -182,6 +185,7 @@ hw_files = [
HW_DIR.File("HW_NX3L4051PW.c"),
SHARED_HW.File("HW_can.c"),
SHARED_HW.File("HW_gpio.c"),
SHARED_HW.File("HW_flash.c"),
]

src_files += hw_files
Expand Down
5 changes: 5 additions & 0 deletions components/bms_worker/include/CANIO_componentSpecific.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "Environment.h"
#include "BatteryMonitoring.h"
#include "Module.h"
#include "LIB_nvm.h"

/******************************************************************************
* D E F I N E S
Expand Down Expand Up @@ -95,5 +96,9 @@
#define set_taskUsage10Hz(m,b,n,s) set(m,b,n,s, Module_getTotalRuntimePercentage(MODULE_10Hz_TASK));
#define set_taskUsage1Hz(m,b,n,s) set(m,b,n,s, Module_getTotalRuntimePercentage(MODULE_1Hz_TASK));
#define set_taskUsageIdle(m,b,n,s) set(m,b,n,s, Module_getTotalRuntimePercentage(MODULE_IDLE_TASK));
#define set_nvmBootCycles(m,b,n,s) set(m,b,n,s, (uint16_t)lib_nvm_getTotalCycles())
#define set_nvmRecordWrites(m,b,n,s) set(m,b,n,s, (uint16_t)lib_nvm_getTotalRecordWrites())
#define set_nvmBlockErases(m,b,n,s) set(m,b,n,s, (uint16_t)lib_nvm_getTotalBlockErases())
#define set_nvmFailedCrc(m,b,n,s) set(m,b,n,s, (uint16_t)lib_nvm_getTotalFailedCrc())

#include "TemporaryStubbing.h"
24 changes: 24 additions & 0 deletions components/bms_worker/include/LIB_nvm_componentSpecific.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* LIB_nvm_config.h
* LIB_nvm Component Specific file
*/

#pragma once

#include "HW_tim.h"
#include "HW_flash.h"
#include "LIB_nvm.h"

/******************************************************************************
* T Y P E D E F S
******************************************************************************/

#define LIB_NVM_GET_TIME_MS HW_TIM_getTimeMS
#define LIB_NVM_GET_FLASH_PAGE_SIZE FLASH_getPageSize
#define LIB_NVM_CLEAR_FLASH_PAGES FLASH_erasePages
#define LIB_NVM_WRITE_TO_FLASH(addr, data, bytes) FLASH_writeHalfwords(addr, data, bytes / sizeof(storage_t))

typedef enum
{
NVM_ENTRYID_COUNT = 0U,
} lib_nvm_entryId_E;
7 changes: 7 additions & 0 deletions components/bms_worker/include/libcrc_componentSpecific.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* libcrc_componentSpecific.h
*
* Configuration for the libcrc module
*/

#define LIBCRC_CRC8_FAST
16 changes: 16 additions & 0 deletions components/bms_worker/src/LIB_nvm_componentSpecific.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file NVM.c
* @brief Source code for Non Volatile Memory Manager
*/

/******************************************************************************
* I N C L U D E S
******************************************************************************/

#include "LIB_nvm.h"

/******************************************************************************
* P U B L I C V A R S
******************************************************************************/

const lib_nvm_entry_S lib_nvm_entries[NVM_ENTRYID_COUNT];
3 changes: 3 additions & 0 deletions components/bms_worker/src/Module.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/**< Other Includes */
#include "Utility.h"
#include "FeatureDefines_generated.h"
#include "LIB_nvm.h"


/******************************************************************************
Expand Down Expand Up @@ -55,6 +56,7 @@ static Module_taskStats_S stats[MODULE_TASK_CNT] = { 0 };
*/
void Module_Init(void)
{
lib_nvm_init();
/**< Run each of the modules Init function in order */
for (uint8_t i = 0U; i < COUNTOF(modules); i++)
{
Expand Down Expand Up @@ -114,6 +116,7 @@ void Module_100Hz_TSK(void)
(*modules[i]->periodic100Hz_CLK)();
}
}
lib_nvm_run();

stats[MODULE_100Hz_TASK].total_percentage = (float32_t)ulTaskGetRunTimePercent(NULL);
}
Expand Down
Loading

0 comments on commit 2b92b1e

Please sign in to comment.