Skip to content

Commit

Permalink
コピー取るところまで一旦実装
Browse files Browse the repository at this point in the history
  • Loading branch information
chutaro committed Oct 25, 2023
1 parent 1751caf commit 435ed8d
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
106 changes: 106 additions & 0 deletions src/src_user/Applications/UserDefined/Cdh/non_volatile_bc_manager.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#pragma section REPRO
/**
* @file
* @brief BCT のコピーを FRAM にとって不揮発化する
*/

#include "non_volatile_bc_manager.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_;

static void APP_NVBC_MGR_init_(void);
static void APP_NVBC_MGR_exec_(void);


AppInfo APP_NVBC_MGR_create_app(void)
{
return AI_create_app_info("AOCS Data Recorder", APP_NVBC_MGR_init_, APP_NVBC_MGR_exec_);
}

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;

return;
}

static void APP_NVBC_MGR_exec_(void)
{
// 有効化するまではコピーしない
if (!nv_bc_manager_.is_active) return;

// データ書き込み
APP_NVBC_MGR_copy_bc_(nv_bc_manager_.bc_id_to_copy, nv_bc_manager_.bc_num_to_copy);

// 次にコピーする BC の ID を更新
if (nv_bc_manager_.bc_id_to_copy + nv_bc_manager_.bc_num_to_copy >= BCT_MAX_BLOCKS)
{
nv_bc_manager_.bc_id_to_copy = 0;
}
else
{
nv_bc_manager_.bc_id_to_copy += nv_bc_manager_.bc_num_to_copy;
}

return;
}

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;
APP_NVM_MANAGER_ERROR ret;

for (uint8_t i = 0; i < len; ++i)
{
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 が出力される関数を作る

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);
}
}

return;
}

static void APP_NVBC_MGR_recover_bc_from_nvm_()
{
// aaa
}

CCP_CmdRet Cmd_APP_NVBC_MGR_SET_ENABLE(const CommonCmdPacket* packet)
{
uint8_t flag = (TLM_CODE)CCP_get_param_from_packet(packet, 0, uint8_t);

if (flag > 0)
{
nv_bc_manager_.is_active = 1;
}
else
{
nv_bc_manager_.is_active = 0;
}

return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}

#pragma section
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @file
* @brief BCT のコピーを FRAM にとって不揮発化する
*/
#ifndef NON_VOLATILE_BC_MANAGER_H_
#define NON_VOLATILE_BC_MANAGER_H_

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

#include "non_volatile_memory_partition.h"

/**
* @struct
* @brief 不揮発BC管理アプリの構造体
*/
typedef struct
{
uint8_t is_active;
bct_id_t bc_id_to_copy; // 次にコピーする BC の ID
uint8_t bc_num_to_copy; // 一度に何個の BC をコピーするか
} 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);

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

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

0 comments on commit 435ed8d

Please sign in to comment.