Skip to content

Commit

Permalink
Merge pull request #444 from ut-issl/feature/fix_endian_conv
Browse files Browse the repository at this point in the history
Pre Release (v3.8.0-beta.1): エンディアン関連の関数の整理
  • Loading branch information
meltingrabbit authored Oct 1, 2022
2 parents 4af599d + a5f72f5 commit 8c53de2
Show file tree
Hide file tree
Showing 32 changed files with 407 additions and 419 deletions.
4 changes: 2 additions & 2 deletions Applications/anomaly_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "../Library/print.h"
#include <src_user/Library/vt100.h>
#include "../System/TimeManager/time_manager.h"
#include "../Library/endian_memcpy.h"
#include "../Library/endian.h"
#include "../TlmCmd/common_cmd_packet_util.h"
#include "timeline_command_dispatcher_id_define.h"
// #include "../anomaly_logger_group.h"
Expand Down Expand Up @@ -281,7 +281,7 @@ CCP_CmdRet Cmd_AH_REGISTER_RULE(const CommonCmdPacket* packet)
ahr.code.local = (uint32_t)param[LOCAL];
ahr.cond = (AH_CONDITION)param[COND];
ahr.threshold = (size_t)param[THRESHOLD];
endian_memcpy(&(ahr.bc_id), &(param[BC]), SIZE_OF_BCT_ID_T);
ENDIAN_memcpy(&(ahr.bc_id), &(param[BC]), SIZE_OF_BCT_ID_T);

AH_add_rule_((size_t)param[ID], &ahr);

Expand Down
16 changes: 8 additions & 8 deletions Applications/memory_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "../System/TimeManager/time_manager.h"
#include "../TlmCmd/packet_handler.h"
#include "../Library/endian_memcpy.h"
#include "../Library/endian.h"
#include "../TlmCmd/common_cmd_packet_util.h"

static MemoryDump memory_dump_;
Expand Down Expand Up @@ -65,8 +65,8 @@ CCP_CmdRet Cmd_MEM_SET_REGION(const CommonCmdPacket* packet)
uint32_t begin, end, span;

// パラメータを読み出し
endian_memcpy(&begin, param, 4);
endian_memcpy(&end, param + 4, 4);
ENDIAN_memcpy(&begin, param, 4);
ENDIAN_memcpy(&end, param + 4, 4);

if (begin > end)
{
Expand Down Expand Up @@ -135,7 +135,7 @@ CCP_CmdRet Cmd_MEM_DUMP_REGION_RND(const CommonCmdPacket* packet)
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_ILLEGAL_PARAMETER);
}

endian_memcpy(&adu_seq, param + 2, 2);
ENDIAN_memcpy(&adu_seq, param + 2, 2);

rp = memory_dump_.begin + (adu_seq * MEM_DUMP_WIDTH);

Expand Down Expand Up @@ -173,7 +173,7 @@ CCP_CmdRet Cmd_MEM_DUMP_SINGLE(const CommonCmdPacket* packet)
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_ILLEGAL_PARAMETER);
}

endian_memcpy(&start_addr, param + 2, 4);
ENDIAN_memcpy(&start_addr, param + 2, 4);

// 要検討: 指定アドレス値が異常な場合の処理をすべきか?
// Segmentation Faultとか起こる?
Expand Down Expand Up @@ -214,7 +214,7 @@ CCP_CmdRet Cmd_MEM_LOAD(const CommonCmdPacket* packet)
data_len = param_len - 4;

// 書き込みアドレス読み出し
endian_memcpy(&start_addr, param, 4);
ENDIAN_memcpy(&start_addr, param, 4);

// 指定した開始アドレスから始まる領域にデータを書き込み
memcpy((void*)start_addr, &(param[4]), data_len);
Expand All @@ -226,7 +226,7 @@ CCP_CmdRet Cmd_MEM_SET_DESTINATION(const CommonCmdPacket* packet)
const uint8_t* param = CCP_get_param_head(packet);
uint32_t dest;

endian_memcpy(&dest, param, 4);
ENDIAN_memcpy(&dest, param, 4);

if ((dest >= memory_dump_.begin) && (dest < memory_dump_.end))
{
Expand Down Expand Up @@ -254,7 +254,7 @@ CCP_CmdRet Cmd_MEM_COPY_REGION_SEQ(const CommonCmdPacket* packet)
}

// パラメータ読み出し。
endian_memcpy(&copy_width, param, 4);
ENDIAN_memcpy(&copy_width, param, 4);

if ((memory_dump_.rp + copy_width) > memory_dump_.end)
{
Expand Down
4 changes: 2 additions & 2 deletions Applications/telemetry_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "../TlmCmd/block_command_executor.h"
#include "../TlmCmd/command_analyze.h"
#include "../Library/print.h"
#include "../Library/endian_memcpy.h"
#include "../Library/endian.h"
#include "../System/WatchdogTimer/watchdog_timer.h"
#include <src_user/TlmCmd/block_command_definitions.h>
#include <src_user/TlmCmd/command_definitions.h>
Expand Down Expand Up @@ -557,7 +557,7 @@ CCP_CmdRet Cmd_TLM_MGR_START_TLM(const CommonCmdPacket* packet)

BCT_make_pos(&bc_register_pos, master_bc_id, bc_cmd_pos);
param[0] = TLCD_ID_DEPLOY_TLM;
endian_memcpy(&param[1], &master_bc_id, SIZE_OF_BCT_ID_T);
ENDIAN_memcpy(&param[1], &master_bc_id, SIZE_OF_BCT_ID_T);

CCP_form_tlc(&TLM_MGR_packet_,
TLM_MGR_USE_BC_NUM,
Expand Down
2 changes: 1 addition & 1 deletion Docs/General/coding_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ typedef enum
- ほとんどのパソコンがリトルエンディアンなのに対し,いくつかのマイコンはビッグエンディアンである.
- 当然バイトオーダーは異なるし,ビットフィールドの並びも異なる.
- ドライバなどで,バイト列を int や float に変換するところなどは要注意.
- エンディアンに依存しないコードを書くか,以下のような定義を適切に使うこと.また,`endian_memcpy` などといった共用関数を積極的に利用すること.
- エンディアンに依存しないコードを書くか,以下のような定義を適切に使うこと.また,`ENDIAN_memcpy` などといった共用関数を積極的に利用すること.
- `SILS_FW``IS_LITTLE_ENDIAN` を混同して使わないこと
```cpp
#ifndef SILS_FW
Expand Down
4 changes: 2 additions & 2 deletions Drivers/Protocol/common_tlm_cmd_packet_for_driver_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ DS_ERR_CODE CTCP_set_tx_frame_to_dssc(DS_StreamConfig* p_stream_config,
memcpy(&(tx_frame[pos]), EB90_FRAME_kStx, size);
pos += size;
size = EB90_FRAME_LEN_SIZE;
endian_memcpy(&(tx_frame[pos]), &packet_len, size); // ここはエンディアンを気にする!
ENDIAN_memcpy(&(tx_frame[pos]), &packet_len, size); // ここはエンディアンを気にする!
pos += size;

size = (size_t)packet_len;
Expand All @@ -114,7 +114,7 @@ DS_ERR_CODE CTCP_set_tx_frame_to_dssc(DS_StreamConfig* p_stream_config,

crc = EB90_FRAME_calc_crc(tx_frame + EB90_FRAME_HEADER_SIZE, pos - EB90_FRAME_HEADER_SIZE);
size = EB90_FRAME_CRC_SIZE;
endian_memcpy(&(tx_frame[pos]), &crc, size); // ここはエンディアンを気にする!
ENDIAN_memcpy(&(tx_frame[pos]), &crc, size); // ここはエンディアンを気にする!
pos += size;
size = EB90_FRAME_ETX_SIZE;
memcpy(&(tx_frame[pos]), EB90_FRAME_kEtx, size);
Expand Down
6 changes: 3 additions & 3 deletions Drivers/Protocol/eb90_frame_for_driver_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @brief コンポ間通信などで標準的に使う データリンク層 の EB90 Frame
*/
#include "eb90_frame_for_driver_super.h"
#include "../../Library/endian_memcpy.h"
#include "../../Library/endian.h"
#include "../../Library/crc.h"

const uint8_t EB90_FRAME_kStx[EB90_FRAME_STX_SIZE] = {EB90_FRAME_STX_1ST_BYTE, EB90_FRAME_STX_2ND_BYTE};
Expand All @@ -14,7 +14,7 @@ const uint8_t EB90_FRAME_kEtx[EB90_FRAME_ETX_SIZE] = {EB90_FRAME_ETX_1ST_BYTE, E
uint16_t EB90_FRAME_get_packet_length_from_dssc(const DS_StreamConfig* p_stream_config)
{
uint16_t length;
endian_memcpy(&length, &(DSSC_get_rx_frame(p_stream_config)[2]), EB90_FRAME_LEN_SIZE);
ENDIAN_memcpy(&length, &(DSSC_get_rx_frame(p_stream_config)[2]), EB90_FRAME_LEN_SIZE);
return length;
}

Expand All @@ -29,7 +29,7 @@ uint16_t EB90_FRAME_get_crc_from_dssc(const DS_StreamConfig* p_stream_config)
{
uint16_t crc;
uint16_t offset = EB90_FRAME_HEADER_SIZE + EB90_FRAME_get_packet_length_from_dssc(p_stream_config);
endian_memcpy(&crc, &(DSSC_get_rx_frame(p_stream_config)[offset]), EB90_FRAME_CRC_SIZE);
ENDIAN_memcpy(&crc, &(DSSC_get_rx_frame(p_stream_config)[offset]), EB90_FRAME_CRC_SIZE);
return crc;
}

Expand Down
4 changes: 2 additions & 2 deletions Drivers/Protocol/eb90_packet_for_driver_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
#include "eb90_packet_for_driver_super.h"
#include "eb90_frame_for_driver_super.h"
#include "../../Library/endian_memcpy.h"
#include "../../Library/endian.h"

// FIXME: DS_StreamConfig.data_link_layer_ をちゃんと見る!

Expand Down Expand Up @@ -41,7 +41,7 @@ uint32_t EB90_PACKET_get_id_from_dssc(const DS_StreamConfig* p_stream_config)
if (version == 1)
{
uint16_t id;
endian_memcpy(&id, &(EB90_FRAME_get_packet_head_from_dssc(p_stream_config)[2]), sizeof(uint16_t));
ENDIAN_memcpy(&id, &(EB90_FRAME_get_packet_head_from_dssc(p_stream_config)[2]), sizeof(uint16_t));
return (uint32_t)id;
}
else
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Super/driver_super.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <src_user/IfWrapper/if_list.h>
#include <src_user/Library/stdint.h>
#include "../../Library/endian_memcpy.h" // パスが不定な自動生成コード類で使えるように
#include "../../Library/endian.h" // パスが不定な自動生成コード類で使えるように
#include "../../System/TimeManager/time_manager.h"

#define DS_STREAM_MAX (3) /*!< DS_StreamConfigの最大数
Expand Down
1 change: 0 additions & 1 deletion Examples/2nd_obc_user/src/src_user/Drivers/Etc/mobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "./mobc.h"
#include <src_core/TlmCmd/common_tlm_cmd_packet.h>
#include <src_core/Library/endian_memcpy.h>
#include <src_core/Drivers/Protocol/eb90_frame_for_driver_super.h>
#include <src_core/Drivers/Protocol/common_tlm_cmd_packet_for_driver_super.h>
#include <string.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ CCP_CmdRet Cmd_DI_GS_DRIVER_RESET(const CommonCmdPacket* packet)
CCP_CmdRet Cmd_DI_GS_SET_MS_FLUSH_INTERVAL(const CommonCmdPacket* packet)
{
cycle_t flush_interval;
endian_memcpy(&flush_interval, CCP_get_param_head(packet), sizeof(cycle_t));
ENDIAN_memcpy(&flush_interval, CCP_get_param_head(packet), sizeof(cycle_t));

DI_GS_set_t2m_flush_interval_(flush_interval, &DI_GS_ms_tlm_packet_handler_);

Expand All @@ -152,7 +152,7 @@ CCP_CmdRet Cmd_DI_GS_SET_MS_FLUSH_INTERVAL(const CommonCmdPacket* packet)
CCP_CmdRet Cmd_DI_GS_SET_RP_FLUSH_INTERVAL(const CommonCmdPacket* packet)
{
cycle_t flush_interval;
endian_memcpy(&flush_interval, CCP_get_param_head(packet), sizeof(cycle_t));
ENDIAN_memcpy(&flush_interval, CCP_get_param_head(packet), sizeof(cycle_t));

DI_GS_set_t2m_flush_interval_(flush_interval, &DI_GS_rp_tlm_packet_handler_);

Expand Down
1 change: 0 additions & 1 deletion Examples/minimum_user/src/src_user/Drivers/Aocs/aobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "./aobc_telemetry_buffer.h"
#include <src_core/TlmCmd/common_tlm_cmd_packet.h>
#include <src_core/TlmCmd/common_cmd_packet.h>
#include <src_core/Library/endian_memcpy.h>
#include <src_core/Drivers/Protocol/eb90_frame_for_driver_super.h>
#include <src_core/Drivers/Protocol/common_tlm_cmd_packet_for_driver_super.h>
#include <string.h>
Expand Down
Loading

0 comments on commit 8c53de2

Please sign in to comment.