Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 2, 2024
1 parent 3932ff5 commit c78f66e
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 188 deletions.
2 changes: 1 addition & 1 deletion checker/cl-tidy/xcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ void Xcp_SendPdu(void) {
Xcp_PduOut.data[XCP_TRANSPORT_LAYER_LENGTH_SIZE] = XCP_LOBYTE(Xcp_State.counter);
Xcp_State.counter++;
#elif XCP_TRANSPORT_LAYER_COUNTER_SIZE == 2
Xcp_PduOut.data[XCP_TRANSPORT_LAYER_LENGTH_SIZE] = XCP_LOBYTE(Xcp_State.counter);
Xcp_PduOut.data[XCP_TRANSPORT_LAYER_LENGTH_SIZE] = XCP_LOBYTE(Xcp_State.counter);
Xcp_PduOut.data[XCP_TRANSPORT_LAYER_LENGTH_SIZE + 1] = XCP_HIBYTE(Xcp_State.counter);
Xcp_State.counter++;
#endif /* XCP_TRANSPORT_LAYER_COUNTER_SIZE */
Expand Down
229 changes: 114 additions & 115 deletions flsemu/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ void FlsEmu_OpenCreate(uint8_t segmentIdx) {
length = strlen(segment->name);
#if defined(_MSC_VER)
strncpy_s((char *)rom, 1024, (char *)segment->name, length);
rom[length] = '\x00';
strcat_s((char *)rom, 1024, ".rom");
rom[length] = '\x00';
strcat_s((char *)rom, 1024, ".rom");
#else
strncpy((char *)rom, (char *)segment->name, length);
rom[length] = '\x00';
strcat((char *)rom, ".rom");
rom[length] = '\x00';
strcat((char *)rom, ".rom");
#endif /* _MSC_VER */
numPages = FlsEmu_NumPages(segmentIdx);
result = FlsEmu_OpenCreatePersitentArray(rom, pageSize * numPages, segment->persistentArray);
Expand All @@ -139,148 +139,147 @@ void FlsEmu_OpenCreate(uint8_t segmentIdx) {
for (pageIdx = 0U; pageIdx < numPages; ++pageIdx) {
// FIXME!!!
offset = ((Xcp_PointerSizeType)segment->persistentArray->mappingAddress) + (pageIdx * pageSize);
XcpUtl_MemSet((void*)offset, FLSEMU_ERASED_VALUE, segment->pageSize);
XcpUtl_MemSet((void *)offset, FLSEMU_ERASED_VALUE, segment->pageSize);
if (fillerSize > 0) {
XcpUtl_MemSet((void*)(offset + segment->pageSize), FLSEMU_FILLER_VALUE, fillerSize);
XcpUtl_MemSet((void *)(offset + segment->pageSize), FLSEMU_FILLER_VALUE, fillerSize);
}
}
}
}
}

void *FlsEmu_BasePointer(uint8_t segmentIdx) {
/// TODO: getSegment()
FlsEmu_SegmentType const *segment = XCP_NULL;
FLSEMU_ASSERT_INITIALIZED();
void *FlsEmu_BasePointer(uint8_t segmentIdx) {
/// TODO: getSegment()
FlsEmu_SegmentType const *segment = XCP_NULL;
FLSEMU_ASSERT_INITIALIZED();

if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
return XCP_NULL;
}
segment = FlsEmu_GetConfig()->segments[segmentIdx];
return segment->persistentArray->mappingAddress;
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
return XCP_NULL;
}
segment = FlsEmu_GetConfig()->segments[segmentIdx];
return segment->persistentArray->mappingAddress;
}

uint32_t FlsEmu_NumPages(uint8_t segmentIdx) {
FlsEmu_SegmentType const *segment = XCP_NULL;
FLSEMU_ASSERT_INITIALIZED();
uint32_t FlsEmu_NumPages(uint8_t segmentIdx) {
FlsEmu_SegmentType const *segment = XCP_NULL;
FLSEMU_ASSERT_INITIALIZED();

if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
return UINT32(0);
}
segment = FlsEmu_GetConfig()->segments[segmentIdx];
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
return UINT32(0);
}
segment = FlsEmu_GetConfig()->segments[segmentIdx];

return segment->memSize / segment->pageSize;
}

void FlsEmu_EraseSector(uint8_t segmentIdx, uint32_t address) {
uint32_t mask = 0UL;
uint16_t *ptr = XCP_NULL;
FlsEmu_SegmentType const *segment = XCP_NULL;

return segment->memSize / segment->pageSize;
FLSEMU_ASSERT_INITIALIZED();
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
return;
}
segment = FlsEmu_GetConfig()->segments[segmentIdx];
mask = (uint32_t)segment->sectorSize - 1UL;
ptr = (uint16_t *)segment->persistentArray->mappingAddress;
if ((address & mask) != 0UL) {
// TODO: warn misalignment.
// ("address (%#X) should be aligned to %u-byte sector boundary.", address,
// segment->sectorSize)
}
XcpUtl_MemSet(ptr + (address & ~mask), FLSEMU_ERASED_VALUE, segment->sectorSize);
}

void FlsEmu_EraseSector(uint8_t segmentIdx, uint32_t address) {
uint32_t mask = 0UL;
uint16_t *ptr = XCP_NULL;
FlsEmu_SegmentType const *segment = XCP_NULL;
void FlsEmu_ErasePage(uint8_t segmentIdx, uint8_t page) {
uint8_t *ptr = (uint8_t *)FlsEmu_BasePointer(segmentIdx);
FlsEmu_SegmentType *segment = XCP_NULL;

FLSEMU_ASSERT_INITIALIZED();
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
return;
}
segment = FlsEmu_GetConfig()->segments[segmentIdx];
mask = (uint32_t)segment->sectorSize - 1UL;
ptr = (uint16_t *)segment->persistentArray->mappingAddress;
if ((address & mask) != 0UL) {
// TODO: warn misalignment.
// ("address (%#X) should be aligned to %u-byte sector boundary.", address,
// segment->sectorSize)
}
XcpUtl_MemSet(ptr + (address & ~mask), FLSEMU_ERASED_VALUE, segment->sectorSize);
FLSEMU_ASSERT_INITIALIZED();
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
return;
}
segment = FlsEmu_GetConfig()->segments[segmentIdx];
XcpUtl_MemSet(ptr + (segment->pageSize * page), FLSEMU_ERASED_VALUE, segment->pageSize);
segment->currentPage = page;
}

void FlsEmu_ErasePage(uint8_t segmentIdx, uint8_t page) {
uint8_t *ptr = (uint8_t *)FlsEmu_BasePointer(segmentIdx);
FlsEmu_SegmentType *segment = XCP_NULL;
void FlsEmu_EraseBlock(uint8_t segmentIdx, uint16_t block) {
/* TODO: Nur den entsprechenden Block mappen!!! */
uint8_t *ptr = XCP_NULL;
uint32_t offset = 0UL;
uint32_t blockSize = 0UL;
FlsEmu_SegmentType const *segment = XCP_NULL;

FLSEMU_ASSERT_INITIALIZED();
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
return;
}
segment = FlsEmu_GetConfig()->segments[segmentIdx];
XcpUtl_MemSet(ptr + (segment->pageSize * page), FLSEMU_ERASED_VALUE, segment->pageSize);
segment->currentPage = page;
FLSEMU_ASSERT_INITIALIZED();
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
return;
}
segment = FlsEmu_GetConfig()->segments[segmentIdx];
assert(block < (segment->blockCount));

void FlsEmu_EraseBlock(uint8_t segmentIdx, uint16_t block) {
/* TODO: Nur den entsprechenden Block mappen!!! */
uint8_t *ptr = XCP_NULL;
uint32_t offset = 0UL;
uint32_t blockSize = 0UL;
FlsEmu_SegmentType const *segment = XCP_NULL;
blockSize = (segment->memSize / segment->blockCount);
offset = (blockSize * block);

FLSEMU_ASSERT_INITIALIZED();
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
return;
}
segment = FlsEmu_GetConfig()->segments[segmentIdx];
assert(block < (segment->blockCount));
ptr = (uint8_t *)FlsEmu_BasePointer(segmentIdx) + offset;
XcpUtl_MemSet(ptr, FLSEMU_ERASED_VALUE, blockSize);
}

blockSize = (segment->memSize / segment->blockCount);
offset = (blockSize * block);
Xcp_MemoryMappingResultType FlsEmu_MemoryMapper(Xcp_MtaType *dst, Xcp_MtaType const *src) {
uint8_t idx = 0;
uint8_t *ptr = XCP_NULL;
FlsEmu_SegmentType const *segment = XCP_NULL;

ptr = (uint8_t *)FlsEmu_BasePointer(segmentIdx) + offset;
XcpUtl_MemSet(ptr, FLSEMU_ERASED_VALUE, blockSize);
}
/* printf("addr: %x ext: %d\n", src->address, src->ext); */

Xcp_MemoryMappingResultType FlsEmu_MemoryMapper(Xcp_MtaType * dst, Xcp_MtaType const *src) {
uint8_t idx = 0;
uint8_t *ptr = XCP_NULL;
FlsEmu_SegmentType const *segment = XCP_NULL;

/* printf("addr: %x ext: %d\n", src->address, src->ext); */

for (idx = 0; idx < FlsEmu_GetConfig()->numSegments; ++idx) {
ptr = FlsEmu_BasePointer(idx);
segment = FlsEmu_GetConfig()->segments[idx];
if ((src->address >= segment->baseAddress) && (src->address < (segment->baseAddress + segment->pageSize))) {
if (src->ext >= FlsEmu_NumPages(idx)) {
return XCP_MEMORY_ADDRESS_INVALID;
} else {
FlsEmu_SelectPage(idx, src->ext);
}
dst->address = ((Xcp_PointerSizeType)ptr - segment->baseAddress) + src->address;
dst->ext = src->ext;
/* printf("MAPPED: addr: %x ext: %d TO: %x:%d\n", src->address, src->ext,
* dst->address, dst->ext); */
return XCP_MEMORY_MAPPED;
for (idx = 0; idx < FlsEmu_GetConfig()->numSegments; ++idx) {
ptr = FlsEmu_BasePointer(idx);
segment = FlsEmu_GetConfig()->segments[idx];
if ((src->address >= segment->baseAddress) && (src->address < (segment->baseAddress + segment->pageSize))) {
if (src->ext >= FlsEmu_NumPages(idx)) {
return XCP_MEMORY_ADDRESS_INVALID;
} else {
FlsEmu_SelectPage(idx, src->ext);
}
dst->address = ((Xcp_PointerSizeType)ptr - segment->baseAddress) + src->address;
dst->ext = src->ext;
/* printf("MAPPED: addr: %x ext: %d TO: %x:%d\n", src->address, src->ext,
* dst->address, dst->ext); */
return XCP_MEMORY_MAPPED;
}
return XCP_MEMORY_NOT_MAPPED;
}
return XCP_MEMORY_NOT_MAPPED;
}

/*!
* Align emulated page-size to OS allocation granularity.
*/
uint32_t FlsEmu_AllocatedSize(uint8_t segmentIdx) {
FlsEmu_SegmentType const *segment = XCP_NULL;
FLSEMU_ASSERT_INITIALIZED();

if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
return (uint32_t)0;
}
segment = FlsEmu_GetConfig()->segments[segmentIdx];
/*!
* Align emulated page-size to OS allocation granularity.
*/
uint32_t FlsEmu_AllocatedSize(uint8_t segmentIdx) {
FlsEmu_SegmentType const *segment = XCP_NULL;
FLSEMU_ASSERT_INITIALIZED();

return FlsEmu_SystemMemory.AllocationGranularity *
(((segment->pageSize / FlsEmu_SystemMemory.AllocationGranularity) +
((segment->pageSize % FlsEmu_SystemMemory.AllocationGranularity) != 0)) ?
1 :
0);
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
return (uint32_t)0;
}
segment = FlsEmu_GetConfig()->segments[segmentIdx];

FlsEmu_ConfigType const *FlsEmu_GetConfig(void) {
return FlsEmu_Config;
}
return FlsEmu_SystemMemory.AllocationGranularity * (((segment->pageSize / FlsEmu_SystemMemory.AllocationGranularity) +
((segment->pageSize % FlsEmu_SystemMemory.AllocationGranularity) != 0)) ?
1 :
0);
}

FlsEmu_ModuleStateType *FlsEmu_GetModuleState(void) {
return &FlsEmu_ModuleState;
}
FlsEmu_ConfigType const *FlsEmu_GetConfig(void) {
return FlsEmu_Config;
}

bool FlsEmu_Initialized(void) {
FlsEmu_ModuleStateType const *state = FlsEmu_GetModuleState();
FlsEmu_ModuleStateType *FlsEmu_GetModuleState(void) {
return &FlsEmu_ModuleState;
}

return *state == FLSEMU_INIT;
}
bool FlsEmu_Initialized(void) {
FlsEmu_ModuleStateType const *state = FlsEmu_GetModuleState();

return *state == FLSEMU_INIT;
}
17 changes: 9 additions & 8 deletions inc/xcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ extern "C" {

#if XCP_TRANSPORT_LAYER == XCP_ON_CAN

#if ((XCP_ENABLE_CAN_GET_SLAVE_ID == XCP_ON) || (XCP_ENABLE_CAN_GET_DAQ_ID == XCP_ON) || (XCP_ENABLE_CAN_SET_DAQ_ID == XCP_ON))
#if ((XCP_ENABLE_CAN_GET_SLAVE_ID == XCP_ON) || (XCP_ENABLE_CAN_GET_DAQ_ID == XCP_ON) || \
(XCP_ENABLE_CAN_SET_DAQ_ID == XCP_ON))
#define XCP_ENABLE_TRANSPORT_LAYER_CMD (XCP_ON)
#endif

Expand Down Expand Up @@ -250,8 +251,7 @@ extern "C" {
#define XCP_DAQ_ENTITY_TYPE uint32_t
#endif

#define XCP_SET_ID(name) \
{ UINT16(sizeof((name)) - UINT16(1)), (uint8_t const *)(name) }
#define XCP_SET_ID(name) { UINT16(sizeof((name)) - UINT16(1)), (uint8_t const *)(name) }

#if !defined(XCP_MAX_BS)
#define XCP_MAX_BS (0)
Expand All @@ -269,7 +269,7 @@ extern "C" {
#define XCP_MIN_ST_PGM (0)
#endif /* XCP_MIN_ST_PGM */

#define XCP_DOWNLOAD_PAYLOAD_LENGTH ((XCP_MAX_CTO)-2)
#define XCP_DOWNLOAD_PAYLOAD_LENGTH ((XCP_MAX_CTO) - 2)

/*
* Packet Identifiers.
Expand Down Expand Up @@ -449,16 +449,17 @@ extern "C" {
#define XCP_DAQ_PREDEFINDED_LIST_COUNT (sizeof(XcpDaq_PredefinedLists) / sizeof(XcpDaq_PredefinedLists[0]))

/* DAQ Implementation Macros */
#define XCP_DAQ_DEFINE_ODT_ENTRY(meas) \
{ { /*(uint32_t)*/ &(meas) }, sizeof((meas)) }
#define XCP_DAQ_DEFINE_ODT_ENTRY(meas) { { /*(uint32_t)*/ &(meas) }, sizeof((meas)) }

/* DAQ Event Implementation Macros */
#define XCP_DAQ_BEGIN_EVENTS const XcpDaq_EventType XcpDaq_Events[XCP_DAQ_MAX_EVENT_CHANNEL] = {
#define XCP_DAQ_END_EVENTS \
} \
;
#define XCP_DAQ_DEFINE_EVENT(name, props, timebase, cycle) \
{ (uint8_t const * const)(name), sizeof((name)) - 1, (props), (timebase), (cycle), }
{ \
(uint8_t const * const)(name), sizeof((name)) - 1, (props), (timebase), (cycle), \
}

#define XCP_DAQ_BEGIN_ID_LIST const uint32_t Xcp_DaqIDs[] = {
#define XCP_DAQ_END_ID_LIST \
Expand Down Expand Up @@ -496,7 +497,7 @@ extern "C" {
/*
** XCPonCAN specific function-like macros.
*/
#define XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(i) (((i)&XCP_ON_CAN_EXT_IDENTIFIER) == XCP_ON_CAN_EXT_IDENTIFIER)
#define XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(i) (((i) & XCP_ON_CAN_EXT_IDENTIFIER) == XCP_ON_CAN_EXT_IDENTIFIER)
#define XCP_ON_CAN_STRIP_IDENTIFIER(i) ((i) & (~XCP_ON_CAN_EXT_IDENTIFIER))

/*
Expand Down
2 changes: 1 addition & 1 deletion src/tl/can/arduino_can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static void on_receive() {
#else
static void on_receive(int packetSize) {
uint_least8_t idx = 0;
XcpTl_Dlc = packetSize;
XcpTl_Dlc = packetSize;
#endif

#if (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_SHIELD) || (XCP_CAN_INTERFACE == XCP_CAN_IF_SEED_STUDIO_CAN_FD_SHIELD)
Expand Down
25 changes: 12 additions & 13 deletions src/xcp_daq.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ bool XcpDaq_QueueEnqueue(uint16_t len, uint8_t const *data);
*/
#if XCP_DAQ_ENABLE_DYNAMIC_LISTS == XCP_ON
XCP_STATIC const uint8_t XcpDaq_AllocTransitionTable[5][4] = {
/* FREE_DAQ ALLOC_DAQ ALLOC_ODT ALLOC_ODT_ENTRY */
/* ALLOC_IDLE*/ {UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR)},
/* AFTER_FREE_DAQ */
{ UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR)},
/* AFTER_ALLOC_DAQ */
{ UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR)},
/* AFTER_ALLOC_ODT */
{ UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK) },
/* AFTER_ALLOC_ODT_ENTRY */
{ UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_OK) },
/* FREE_DAQ ALLOC_DAQ ALLOC_ODT ALLOC_ODT_ENTRY */
/* ALLOC_IDLE*/ { UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR) },
/* AFTER_FREE_DAQ */
{ UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR) },
/* AFTER_ALLOC_DAQ */
{ UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR) },
/* AFTER_ALLOC_ODT */
{ UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_OK) },
/* AFTER_ALLOC_ODT_ENTRY */
{ UINT8(DAQ_ALLOC_OK), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_ERR), UINT8(DAQ_ALLOC_OK) },
};
#endif /* XCP_DAQ_ENABLE_DYNAMIC_LISTS */

Expand Down Expand Up @@ -390,9 +390,8 @@ void XcpDaq_SetPointer(
bool XcpDaq_ValidateConfiguration(void) {
#if (XCP_DAQ_ENABLE_DYNAMIC_LISTS == XCP_ON) && (XCP_DAQ_ENABLE_PREDEFINED_LISTS == XCP_OFF)
/* Dynamic DAQs only */
return (bool
)((XcpDaq_EntityCount > (XCP_DAQ_ENTITY_TYPE)0) && (XcpDaq_ListCount > (XCP_DAQ_ENTITY_TYPE)0) &&
(XcpDaq_OdtCount > (XCP_DAQ_ENTITY_TYPE)0));
return (bool)((XcpDaq_EntityCount > (XCP_DAQ_ENTITY_TYPE)0) && (XcpDaq_ListCount > (XCP_DAQ_ENTITY_TYPE)0) &&
(XcpDaq_OdtCount > (XCP_DAQ_ENTITY_TYPE)0));
#elif (XCP_DAQ_ENABLE_DYNAMIC_LISTS == XCP_OFF) && (XCP_DAQ_ENABLE_PREDEFINED_LISTS == XCP_ON)
/* Predefined DAQs only */
return (bool)XCP_TRUE;
Expand Down
Loading

0 comments on commit c78f66e

Please sign in to comment.