Skip to content

Commit

Permalink
Merge pull request #154 from arkedge/feature/rename-component-driver-…
Browse files Browse the repository at this point in the history
…prefix

Rename component driver prefix
  • Loading branch information
sksat authored Oct 24, 2023
2 parents 5a4fc67 + 0b8a423 commit b376eb2
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 201 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ set(C2A_CORE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

set(C2A_SRCS
c2a_core_main.c
component_driver/common_tlm_cmd_packet_for_driver_super.c
component_driver/eb90_frame_for_driver_super.c
component_driver/eb90_packet_for_driver_super.c
component_driver/cdrv_common_tlm_cmd_packet.c
component_driver/cdrv_eb90_frame.c
component_driver/cdrv_eb90_packet.c
component_driver/driver_super.c
hal/i2c_common.c
system/application_manager/app_info.c
Expand Down
4 changes: 2 additions & 2 deletions code-generator/my_mod/tlm_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs):
body_c += " {_obc_name_upper}_TLM_CODE tlm_id;\n"
body_c += " CDS_ERR_CODE ret;\n"
body_c += "\n"
body_c += " ret = CTP_get_ctp_from_cdssc(p_stream_config, &{_obc_name_upper}_ctp_);\n"
body_c += " ret = CDRV_CTP_get_ctp(p_stream_config, &{_obc_name_upper}_ctp_);\n"
body_c += " if (ret != CDS_ERR_CODE_OK) return ret;\n"
body_c += "\n"
body_c += " tlm_id = ({_obc_name_upper}_TLM_CODE)CTP_get_id(&{_obc_name_upper}_ctp_);\n"
Expand Down Expand Up @@ -368,7 +368,7 @@ def OutputTlmBufferC_(file_path, name, body, settings):
* @brief テレメトリバッファー(テレメ中継)
* @note このコードは自動生成されています!
*/
#include <src_core/component_driver/common_tlm_cmd_packet_for_driver_super.h>
#include <src_core/component_driver/cdrv_common_tlm_cmd_packet.h>
#include "./{_obc_name_lower}_telemetry_definitions.h"
#include "./{_obc_name_lower}_telemetry_buffer.h"
#include "./{_obc_name_lower}.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@
* @note データリンク層は CDS_StreamConfig.data_link_layer_ で規定する
* @note packet 構造 などは tlm_cmd/common_tlm_cmd_packet.h を参照のこと
*/
#include "common_tlm_cmd_packet_for_driver_super.h"
#include "eb90_frame_for_driver_super.h"
#include "cdrv_common_tlm_cmd_packet.h"
#include "cdrv_eb90_frame.h"
#include <string.h>

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

CDS_ERR_CODE CTCP_get_ctcp_from_cdssc(const CDS_StreamConfig* p_stream_config, CommonTlmCmdPacket* received_packet)
CDS_ERR_CODE CDRV_CTCP_get_ctcp(const CDS_StreamConfig* p_stream_config, CommonTlmCmdPacket* received_packet)
{
const uint16_t packet_len = EB90_FRAME_get_packet_length_from_cdssc(p_stream_config);
const uint16_t packet_len = CDRV_EB90_FRAME_get_packet_length(p_stream_config);

if (packet_len > CTCP_MAX_LEN) return CDS_ERR_CODE_ERR;

// まず, 受信データ長だけコピーしてしまってから,アサーションする(効率のため)
memcpy(&received_packet->packet, EB90_FRAME_get_packet_head_from_cdssc(p_stream_config), (size_t)packet_len);
memcpy(&received_packet->packet, CDRV_EB90_FRAME_get_packet_head(p_stream_config), (size_t)packet_len);
if (CTCP_get_packet_len(received_packet) != packet_len) return CDS_ERR_CODE_ERR;
if (!CTCP_is_valid_packet(received_packet)) return CDS_ERR_CODE_ERR;
return CDS_ERR_CODE_OK;
}


CDS_ERR_CODE CTP_get_ctp_from_cdssc(const CDS_StreamConfig* p_stream_config, CommonTlmPacket* received_packet)
CDS_ERR_CODE CDRV_CTP_get_ctp(const CDS_StreamConfig* p_stream_config, CommonTlmPacket* received_packet)
{
const uint16_t packet_len = EB90_FRAME_get_packet_length_from_cdssc(p_stream_config);
const uint16_t packet_len = CDRV_EB90_FRAME_get_packet_length(p_stream_config);

if (packet_len > CTP_MAX_LEN) return CDS_ERR_CODE_ERR;

// まず, 受信データ長だけコピーしてしまってから,アサーションする(効率のため)
memcpy(&received_packet->packet, EB90_FRAME_get_packet_head_from_cdssc(p_stream_config), (size_t)packet_len);
memcpy(&received_packet->packet, CDRV_EB90_FRAME_get_packet_head(p_stream_config), (size_t)packet_len);
if (CTP_get_packet_len(received_packet) != packet_len) return CDS_ERR_CODE_ERR;
if (!CTP_is_valid_packet(received_packet)) return CDS_ERR_CODE_ERR;

Expand All @@ -49,28 +49,28 @@ CDS_ERR_CODE CTP_get_ctp_from_cdssc(const CDS_StreamConfig* p_stream_config, Com
}


CDS_ERR_CODE CCP_get_ccp_from_cdssc(const CDS_StreamConfig* p_stream_config, CommonCmdPacket* received_packet)
CDS_ERR_CODE CDRV_CCP_get_ccp(const CDS_StreamConfig* p_stream_config, CommonCmdPacket* received_packet)
{
const uint16_t packet_len = EB90_FRAME_get_packet_length_from_cdssc(p_stream_config);
const uint16_t packet_len = CDRV_EB90_FRAME_get_packet_length(p_stream_config);

if (packet_len > CCP_MAX_LEN) return CDS_ERR_CODE_ERR;

// まず, 受信データ長だけコピーしてしまってから,アサーションする(効率のため)
memcpy(&received_packet->packet, EB90_FRAME_get_packet_head_from_cdssc(p_stream_config), (size_t)packet_len);
memcpy(&received_packet->packet, CDRV_EB90_FRAME_get_packet_head(p_stream_config), (size_t)packet_len);
if (CCP_get_packet_len(received_packet) != packet_len) return CDS_ERR_CODE_ERR;
if (!CCP_is_valid_packet(received_packet)) return CDS_ERR_CODE_ERR;
return CDS_ERR_CODE_OK;
}


CDS_ERR_CODE CTCP_init_cdssc(CDS_StreamConfig* p_stream_config,
uint8_t* tx_frame_buffer,
int16_t tx_frame_buffer_size,
CDS_ERR_CODE (*data_analyzer)(CDS_StreamConfig* p_stream_config, void* p_driver))
CDS_ERR_CODE CDRV_CTCP_init_stream_config(CDS_StreamConfig* p_stream_config,
uint8_t* tx_frame_buffer,
int16_t tx_frame_buffer_size,
CDS_ERR_CODE (*data_analyzer)(CDS_StreamConfig* p_stream_config, void* p_driver))
{
// MOBC か sub OBC かによって,送信側 (tx 側) が CTP になるか CCP になるかは不明なため,ひとまず CTCP に
// メモリが苦しい OBC もあるので,考えてもいいかも
const uint16_t max_frame_size = EB90_FRAME_HEADER_SIZE + CTCP_MAX_LEN + EB90_FRAME_FOOTER_SIZE;
const uint16_t max_frame_size = CDRV_EB90_FRAME_HEADER_SIZE + CTCP_MAX_LEN + CDRV_EB90_FRAME_FOOTER_SIZE;
if (tx_frame_buffer_size < max_frame_size)
{
return CDS_ERR_CODE_ERR;
Expand All @@ -82,14 +82,14 @@ CDS_ERR_CODE CTCP_init_cdssc(CDS_StreamConfig* p_stream_config,
CDSSC_set_tx_frame_size(p_stream_config, 0); // 送る直前に値をセットする

// 定期的な受信はする
CDSSC_set_rx_header(p_stream_config, EB90_FRAME_kStx, EB90_FRAME_STX_SIZE);
CDSSC_set_rx_footer(p_stream_config, EB90_FRAME_kEtx, EB90_FRAME_ETX_SIZE);
CDSSC_set_rx_header(p_stream_config, CDRV_EB90_FRAME_kStx, CDRV_EB90_FRAME_STX_SIZE);
CDSSC_set_rx_footer(p_stream_config, CDRV_EB90_FRAME_kEtx, CDRV_EB90_FRAME_ETX_SIZE);
CDSSC_set_rx_frame_size(p_stream_config, -1); // 可変
CDSSC_set_max_rx_frame_size(p_stream_config, max_frame_size);
CDSSC_set_rx_framelength_pos(p_stream_config, EB90_FRAME_STX_SIZE);
CDSSC_set_rx_framelength_pos(p_stream_config, CDRV_EB90_FRAME_STX_SIZE);
CDSSC_set_rx_framelength_type_size(p_stream_config, 2);
CDSSC_set_rx_framelength_offset(p_stream_config,
EB90_FRAME_HEADER_SIZE + EB90_FRAME_FOOTER_SIZE);
CDRV_EB90_FRAME_HEADER_SIZE + CDRV_EB90_FRAME_FOOTER_SIZE);
CDSSC_set_data_analyzer(p_stream_config, data_analyzer);

// 定期 TLM の監視機能の有効化はここではしないので, ComponentDriver 側でやる
Expand All @@ -99,58 +99,58 @@ CDS_ERR_CODE CTCP_init_cdssc(CDS_StreamConfig* p_stream_config,
}


CDS_ERR_CODE CTCP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config,
const CommonTlmCmdPacket* send_packet)
CDS_ERR_CODE CDRV_CTCP_set_tx_frame(CDS_StreamConfig* p_stream_config,
const CommonTlmCmdPacket* send_packet)
{
size_t pos;
size_t size;
uint16_t crc;
uint16_t packet_len = CTCP_get_packet_len(send_packet);
uint16_t frame_len = (uint16_t)(packet_len + EB90_FRAME_HEADER_SIZE + EB90_FRAME_FOOTER_SIZE);
uint16_t frame_len = (uint16_t)(packet_len + CDRV_EB90_FRAME_HEADER_SIZE + CDRV_EB90_FRAME_FOOTER_SIZE);
uint8_t* tx_frame = CDSSC_get_tx_frame_as_non_const_pointer(p_stream_config);

if (frame_len > CDSSC_get_tx_frame_buffer_size(p_stream_config)) return CDS_ERR_CODE_ERR;

CDSSC_set_tx_frame_size(p_stream_config, frame_len);

pos = 0;
size = EB90_FRAME_STX_SIZE;
memcpy(&(tx_frame[pos]), EB90_FRAME_kStx, size);
size = CDRV_EB90_FRAME_STX_SIZE;
memcpy(&(tx_frame[pos]), CDRV_EB90_FRAME_kStx, size);
pos += size;
size = EB90_FRAME_LEN_SIZE;
size = CDRV_EB90_FRAME_LEN_SIZE;
ENDIAN_memcpy(&(tx_frame[pos]), &packet_len, size); // ここはエンディアンを気にする!
pos += size;

size = (size_t)packet_len;
memcpy(&(tx_frame[pos]), send_packet->packet, size);
pos += size;

crc = EB90_FRAME_calc_crc(tx_frame + EB90_FRAME_HEADER_SIZE, pos - EB90_FRAME_HEADER_SIZE);
size = EB90_FRAME_CRC_SIZE;
crc = EB90_FRAME_calc_crc(tx_frame + CDRV_EB90_FRAME_HEADER_SIZE, pos - CDRV_EB90_FRAME_HEADER_SIZE);
size = CDRV_EB90_FRAME_CRC_SIZE;
ENDIAN_memcpy(&(tx_frame[pos]), &crc, size); // ここはエンディアンを気にする!
pos += size;
size = EB90_FRAME_ETX_SIZE;
memcpy(&(tx_frame[pos]), EB90_FRAME_kEtx, size);
size = CDRV_EB90_FRAME_ETX_SIZE;
memcpy(&(tx_frame[pos]), CDRV_EB90_FRAME_kEtx, size);

return CDS_ERR_CODE_OK;
}


CDS_ERR_CODE CTP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config,
const CommonTlmPacket* send_packet)
CDS_ERR_CODE CDRV_CTP_set_tx_frame(CDS_StreamConfig* p_stream_config,
const CommonTlmPacket* send_packet)
{
const CommonTlmCmdPacket* ctcp = CTCP_convert_from_ctp(send_packet);
if (ctcp == NULL) return CDS_ERR_CODE_ERR;
return CTCP_set_tx_frame_to_cdssc(p_stream_config, ctcp);
return CDRV_CTCP_set_tx_frame(p_stream_config, ctcp);
}


CDS_ERR_CODE CCP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config,
const CommonCmdPacket* send_packet)
CDS_ERR_CODE CDRV_CCP_set_tx_frame(CDS_StreamConfig* p_stream_config,
const CommonCmdPacket* send_packet)
{
const CommonTlmCmdPacket* ctcp = CTCP_convert_from_ccp(send_packet);
if (ctcp == NULL) return CDS_ERR_CODE_ERR;
return CTCP_set_tx_frame_to_cdssc(p_stream_config, ctcp);
return CDRV_CTCP_set_tx_frame(p_stream_config, ctcp);
}

#pragma section
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* @note データリンク層は CDS_StreamConfig.data_link_layer_ で規定する
* @note packet 構造 などは tlm_cmd/common_tlm_cmd_packet.h を参照のこと
*/
#ifndef COMMON_TLM_CMD_PACKET_FOR_DRIVER_SUPER_H_
#define COMMON_TLM_CMD_PACKET_FOR_DRIVER_SUPER_H_
#ifndef CDRV_COMMON_TLM_CMD_PACKET_H_
#define CDRV_COMMON_TLM_CMD_PACKET_H_

#include <stdint.h>
#include "driver_super.h"
Expand All @@ -20,7 +20,7 @@
* @retval CDS_ERR_CODE_OK: 正常終了
* @retval CDS_ERR_CODE_ERR: パケット長が異常など,エラーでコピーできない
*/
CDS_ERR_CODE CTCP_get_ctcp_from_cdssc(const CDS_StreamConfig* p_stream_config, CommonTlmCmdPacket* received_packet);
CDS_ERR_CODE CDRV_CTCP_get_ctcp(const CDS_StreamConfig* p_stream_config, CommonTlmCmdPacket* received_packet);

/**
* @brief CommonTlmPacket を受信データからコピーして取得する
Expand All @@ -30,7 +30,7 @@ CDS_ERR_CODE CTCP_get_ctcp_from_cdssc(const CDS_StreamConfig* p_stream_config, C
* @retval CDS_ERR_CODE_OK: 正常終了
* @retval CDS_ERR_CODE_ERR: パケット長が異常など,エラーでコピーできない
*/
CDS_ERR_CODE CTP_get_ctp_from_cdssc(const CDS_StreamConfig* p_stream_config, CommonTlmPacket* received_packet);
CDS_ERR_CODE CDRV_CTP_get_ctp(const CDS_StreamConfig* p_stream_config, CommonTlmPacket* received_packet);

/**
* @brief CommonCmdPacket を受信データからコピーして取得する
Expand All @@ -40,7 +40,7 @@ CDS_ERR_CODE CTP_get_ctp_from_cdssc(const CDS_StreamConfig* p_stream_config, Com
* @retval CDS_ERR_CODE_OK: 正常終了
* @retval CDS_ERR_CODE_ERR: パケット長が異常など,エラーでコピーできない
*/
CDS_ERR_CODE CCP_get_ccp_from_cdssc(const CDS_StreamConfig* p_stream_config, CommonCmdPacket* received_packet);
CDS_ERR_CODE CDRV_CCP_get_ccp(const CDS_StreamConfig* p_stream_config, CommonCmdPacket* received_packet);

/**
* @brief C2A 間通信など, CTCP をコンポ間通信に用いるとき,CDS_init で渡す初期化関数内部用の Init Util
Expand All @@ -54,10 +54,10 @@ CDS_ERR_CODE CCP_get_ccp_from_cdssc(const CDS_StreamConfig* p_stream_config, Com
* @retval CDS_ERR_CODE_OK: 正常終了
* @retval CDS_ERR_CODE_ERR: フレームバッファのサイズ不足などのエラー
*/
CDS_ERR_CODE CTCP_init_cdssc(CDS_StreamConfig* p_stream_config,
uint8_t* tx_frame_buffer,
int16_t tx_frame_buffer_size,
CDS_ERR_CODE (*data_analyzer)(CDS_StreamConfig* p_stream_config, void* p_driver));
CDS_ERR_CODE CDRV_CTCP_init_stream_config(CDS_StreamConfig* p_stream_config,
uint8_t* tx_frame_buffer,
int16_t tx_frame_buffer_size,
CDS_ERR_CODE (*data_analyzer)(CDS_StreamConfig* p_stream_config, void* p_driver));

/**
* @brief C2A 間通信など, CTCP をコンポ間通信に用いるときの tx_frame のセット
Expand All @@ -66,8 +66,8 @@ CDS_ERR_CODE CTCP_init_cdssc(CDS_StreamConfig* p_stream_config,
* @retval CDS_ERR_CODE_OK: 正常終了
* @retval CDS_ERR_CODE_ERR: DSSC 内部の設定不足などのエラー
*/
CDS_ERR_CODE CTCP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config,
const CommonTlmCmdPacket* send_packet);
CDS_ERR_CODE CDRV_CTCP_set_tx_frame(CDS_StreamConfig* p_stream_config,
const CommonTlmCmdPacket* send_packet);

/**
* @brief C2A 間通信など, CTP をコンポ間通信に用いるときの tx_frame のセット
Expand All @@ -76,8 +76,8 @@ CDS_ERR_CODE CTCP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config,
* @retval CDS_ERR_CODE_OK: 正常終了
* @retval CDS_ERR_CODE_ERR: DSSC 内部の設定不足などのエラー
*/
CDS_ERR_CODE CTP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config,
const CommonTlmPacket* send_packet);
CDS_ERR_CODE CDRV_CTP_set_tx_frame(CDS_StreamConfig* p_stream_config,
const CommonTlmPacket* send_packet);

/**
* @brief C2A 間通信など, CCP をコンポ間通信に用いるときの tx_frame のセット
Expand All @@ -86,7 +86,7 @@ CDS_ERR_CODE CTP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config,
* @retval CDS_ERR_CODE_OK: 正常終了
* @retval CDS_ERR_CODE_ERR: DSSC 内部の設定不足などのエラー
*/
CDS_ERR_CODE CCP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config,
const CommonCmdPacket* send_packet);
CDS_ERR_CODE CDRV_CCP_set_tx_frame(CDS_StreamConfig* p_stream_config,
const CommonCmdPacket* send_packet);

#endif
52 changes: 52 additions & 0 deletions component_driver/cdrv_eb90_frame.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma section REPRO
/**
* @file
* @brief コンポ間通信などで標準的に使う データリンク層 の EB90 Frame
*/
#include "cdrv_eb90_frame.h"
#include "../library/endian.h"
#include "../library/crc.h"

const uint8_t CDRV_EB90_FRAME_kStx[CDRV_EB90_FRAME_STX_SIZE] = {CDRV_EB90_FRAME_STX_1ST_BYTE, CDRV_EB90_FRAME_STX_2ND_BYTE};
const uint8_t CDRV_EB90_FRAME_kEtx[CDRV_EB90_FRAME_ETX_SIZE] = {CDRV_EB90_FRAME_ETX_1ST_BYTE, CDRV_EB90_FRAME_ETX_2ND_BYTE};


uint16_t CDRV_EB90_FRAME_get_packet_length(const CDS_StreamConfig* p_stream_config)
{
uint16_t length;
ENDIAN_memcpy(&length, &(CDSSC_get_rx_frame(p_stream_config)[2]), CDRV_EB90_FRAME_LEN_SIZE);
return length;
}


const uint8_t* CDRV_EB90_FRAME_get_packet_head(const CDS_StreamConfig* p_stream_config)
{
return &(CDSSC_get_rx_frame(p_stream_config)[CDRV_EB90_FRAME_HEADER_SIZE]);
}


uint16_t CDRV_EB90_FRAME_get_crc(const CDS_StreamConfig* p_stream_config)
{
uint16_t crc;
uint16_t offset = CDRV_EB90_FRAME_HEADER_SIZE + CDRV_EB90_FRAME_get_packet_length(p_stream_config);
ENDIAN_memcpy(&crc, &(CDSSC_get_rx_frame(p_stream_config)[offset]), CDRV_EB90_FRAME_CRC_SIZE);
return crc;
}


uint8_t CDRV_EB90_FRAME_is_valid_crc(const CDS_StreamConfig* p_stream_config)
{
uint16_t len = CDRV_EB90_FRAME_get_packet_length(p_stream_config);
const uint8_t* head = CDRV_EB90_FRAME_get_packet_head(p_stream_config);
return (EB90_FRAME_calc_crc(head, len + CDRV_EB90_FRAME_CRC_SIZE) == 0) ? 1 : 0;
}


uint16_t EB90_FRAME_calc_crc(const uint8_t* data, size_t len)
{
// CRC-16/CCITT-FALSE (CRC-16/AUTOSAR, CRC-16/IBM-3740 とも)
// https://reveng.sourceforge.io/crc-catalogue/16.htm
return CRC_calc_crc_16_ccitt_left(0xffff, data, len, 0);
}

#pragma section
Loading

0 comments on commit b376eb2

Please sign in to comment.