Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C2A 初期化時に実行環境のエンディアンが設定と正しいかチェックする #260

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [#268](https://github.com/arkedge/c2a-core/pull/268): GS と FSW 側での同期のために,BCT, TL のダイジェスト (CRC) を下ろせるようにする App の追加
- [#237](https://github.com/arkedge/c2a-core/pull/237): 任意の Component Driver に対して,任意バイト列の送受信と HAL init, reopen Cmd を提供する
- [#274](https://github.com/arkedge/c2a-core/pull/274): `TMGR_get_master_mode_cycle_in_msec` などの in_sec 版を実装
- [#260](https://github.com/arkedge/c2a-core/pull/260): C2A 初期化時に実行環境のエンディアンが設定と正しいかチェックする

### Breaking Changes

Expand Down
17 changes: 17 additions & 0 deletions c2a_core_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "./library/git_revision.h"
#include "./library/print.h"
#include "./library/endian.h"
#include "./system/task_manager/task_dispatcher.h"
#include "./system/application_manager/app_manager.h"
#include "./system/event_manager/event_manager.h"
Expand All @@ -15,6 +16,7 @@
#include "./tlm_cmd/telemetry_frame.h"

#include <src_user/applications/app_registry.h>
#include <src_user/settings/build_settings.h>
meltingrabbit marked this conversation as resolved.
Show resolved Hide resolved

// git revisionをコードに埋め込む
const char GIT_REV_CORE[41] = GIT_REVISION_C2A_CORE;
Expand All @@ -24,6 +26,21 @@ const uint32_t GIT_REV_USER_SHORT = GIT_REVISION_C2A_USER_SHORT;

void C2A_core_init(void)
{
// エンディアンの設定が正しいかの確認
#ifdef IS_LITTLE_ENDIAN
if (ENDIAN_detect_system_endian() != ENDIAN_TYPE_LITTLE)
#else
if (ENDIAN_detect_system_endian() != ENDIAN_TYPE_BIG)
#endif
{
Printf("WARNING: ENDIAN MISMATCH BETWEEN BUILD SETTINGS AND RUNTIME!\n");
}
else
{
Printf("C2A_init: Endian OK.\n");
}

// C2A の初期化
CA_initialize(); // Cmd Analyze
Printf("C2A_init: CA_initialize done.\n");
TF_initialize(); // TLM frame
Expand Down
19 changes: 19 additions & 0 deletions library/endian.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,23 @@ void ENDIAN_conv(void* after, const void* before, size_t size)
return;
}

ENDIAN_TYPE ENDIAN_detect_system_endian(void)
{
uint32_t test = 0x12345678;
uint8_t* p = (uint8_t*)&test;

if (*p == 0x12)
{
return ENDIAN_TYPE_BIG;
}
else if (*p == 0x78)
sksat marked this conversation as resolved.
Show resolved Hide resolved
{
return ENDIAN_TYPE_LITTLE;
}
else
{
return ENDIAN_TYPE_UNKNOWN;
meltingrabbit marked this conversation as resolved.
Show resolved Hide resolved
}
}

#pragma section
7 changes: 7 additions & 0 deletions library/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ void* ENDIAN_memcpy(void* dest, const void* src, size_t size);
*/
void ENDIAN_conv(void* after, const void* before, size_t size);

/**
* @brief 実行環境のエンディアンを判定する
* @param void
* @return ENDIAN_TYPE
*/
ENDIAN_TYPE ENDIAN_detect_system_endian(void);

#endif
Loading