Skip to content

Commit

Permalink
restore bc の暫定版を実装
Browse files Browse the repository at this point in the history
  • Loading branch information
chutaro committed Dec 15, 2023
1 parent 5ddba0c commit 0e78d12
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
*/

#include "non_volatile_bc_manager.h"
#include "non_volatile_memory_partition.h"

#include <string.h>
#include <src_core/TlmCmd/common_cmd_packet_util.h>
#include <src_core/TlmCmd/block_command_table.h>
#include <src_core/Library/print.h>
#include <src_core/System/EventManager/event_logger.h>
#include <src_user/TlmCmd/block_command_user_settings.h>

static NonVolatileBCManager nv_bc_manager_;
const NonVolatileBCManager* const nv_bc_manager = &nv_bc_manager_;
Expand All @@ -30,6 +28,7 @@ static void APP_NVBC_MGR_init_(void)
nv_bc_manager_.is_active = 0; // 起動直後は無効化しておく
nv_bc_manager_.bc_id_to_copy = 0;
nv_bc_manager_.bc_num_to_copy = 10;
nv_bc_manager_.start_address = non_volatile_memory_partition->elements[APP_NVM_PARTITION_ID_BCT].start_address;

return;
}
Expand All @@ -39,7 +38,7 @@ static void APP_NVBC_MGR_exec_(void)
// 有効化するまではコピーしない
if (!nv_bc_manager_.is_active) return;

// データ書き込み
// FRAM に BCT をコピー
APP_NVBC_MGR_copy_bc_(nv_bc_manager_.bc_id_to_copy, nv_bc_manager_.bc_num_to_copy);

// 次にコピーする BC の ID を更新
Expand All @@ -57,7 +56,6 @@ static void APP_NVBC_MGR_exec_(void)

static void APP_NVBC_MGR_copy_bc_(bct_id_t begin_bc_id, uint8_t len)
{
uint32_t start_address = non_volatile_memory_partition->elements[APP_NVM_PARTITION_ID_BCT].start_address;
uint32_t write_address;
bct_id_t bc_id;
BCT_Table block;
Expand All @@ -67,24 +65,53 @@ static void APP_NVBC_MGR_copy_bc_(bct_id_t begin_bc_id, uint8_t len)
{
bc_id = begin_bc_id + i;
block = *block_command_table->blocks[bc_id]; // TODO: アサーション入れる
write_address = start_address + sizeof(BCT_Table) * i; // TODO: bc_id を入力すると address が出力される関数を作る
write_address = APP_NVBC_MGR_get_address_from_bc_id_(bc_id);

ret = APP_NVM_PARTITION_write_bytes(APP_NVM_PARTITION_ID_BCT,
write_address,
sizeof(BCT_Table),
&block);
if (ret != APP_NVM_MANAGER_ERROR_OK)
{
EL_record_event(EL_GROUP_NVBC_WRITE, (uint32_t)ret, EL_ERROR_LEVEL_LOW, bc_id);
EL_record_event(EL_GROUP_NV_BC_MGR, (uint32_t)ret, EL_ERROR_LEVEL_LOW, bc_id);
}
}

return;
}

static void APP_NVBC_MGR_recover_bc_from_nvm_()
static void APP_NVBC_MGR_restore_bc_from_nvm_(bct_id_t bc_id)
{
// aaa
BCT_Table block;
APP_NVM_MANAGER_ERROR ret;
uint32_t read_address = APP_NVBC_MGR_get_address_from_bc_id_(bc_id);

ret = APP_NVM_PARTITION_read_bytes(&block,
APP_NVM_PARTITION_ID_BCT,
read_address,
sizeof(BCT_Table));
if (ret != APP_NVM_MANAGER_ERROR_OK)
{
EL_record_event(EL_GROUP_NV_BC_MGR, (uint32_t)ret, EL_ERROR_LEVEL_HIGH, bc_id);
}

memcpy(block_command_table->blocks[bc_id], &block, sizeof(BCT_Table)); // FIXME: BCT は static const 確保されているので無理な気がする

return;
}

static uint32_t APP_NVBC_MGR_get_address_from_bc_id_(bct_id_t bc_id)
{
uint32_t write_address;

if (bc_id >= BCT_MAX_BLOCKS)
{
return nv_bc_manager_.start_address;
}

write_address = nv_bc_manager_.start_address + sizeof(BCT_Table) * bc_id;

return write_address;
}

CCP_CmdRet Cmd_APP_NVBC_MGR_SET_ENABLE(const CommonCmdPacket* packet)
Expand All @@ -103,4 +130,13 @@ CCP_CmdRet Cmd_APP_NVBC_MGR_SET_ENABLE(const CommonCmdPacket* packet)
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}

CCP_CmdRet Cmd_APP_NVBC_MGR_RESTORE_BC_FROM_NVM(const CommonCmdPacket* packet)
{
bct_id_t bc_id = CCP_get_param_from_packet(packet, 0, bct_id_t);

APP_NVBC_MGR_restore_bc_from_nvm_(bc_id);

return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}

#pragma section
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#define NON_VOLATILE_BC_MANAGER_H_

#include <src_core/System/ApplicationManager/app_info.h>

#include "non_volatile_memory_partition.h"
#include <src_core/TlmCmd/block_command_table.h>

/**
* @struct
Expand All @@ -18,13 +17,14 @@ typedef struct
uint8_t is_active;
bct_id_t bc_id_to_copy; // 次にコピーする BC の ID
uint8_t bc_num_to_copy; // 一度に何個の BC をコピーするか
uint32_t start_address; // BCT 保存用の partition の開始アドレス
} NonVolatileBCManager;

extern const NonVolatileBCManager* const nv_bc_manager;

AppInfo APP_NVBC_MGR_create_app(void);

CCP_CmdRet Cmd_APP_NVBC_MGR_SET_ENABLE(const CommonCmdPacket* packet);
CCP_CmdRet Cmd_APP_NVBC_MGR_RESTORE_FROM_NVM(const CommonCmdPacket* packet);
CCP_CmdRet Cmd_APP_NVBC_MGR_RESTORE_BC_FROM_NVM(const CommonCmdPacket* packet);

#endif
2 changes: 1 addition & 1 deletion src/src_user/Settings/System/event_logger_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef enum
// その他: 120-127
EL_GROUP_DR_WRITE = 120, //!< DR書き込みエラー
EL_GROUP_DR_READ, //!< DR読み出しエラー
EL_GROUP_NVBC_WRITE, //!< 不揮発BCコピー時のエラー
EL_GROUP_NV_BC_MGR, //!< 不揮発BC操作時のエラー
EL_GROUP_NVM_TRIPLE_REDUNDANT, //!< 不揮発メモリ三重冗長エラー

// とりあえず最大値は0x7f(127)に!
Expand Down

0 comments on commit 0e78d12

Please sign in to comment.