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 Apr 8, 2024
1 parent dc16438 commit 6fef372
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 223 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;
}
24 changes: 12 additions & 12 deletions inc/xcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,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 @@ -484,7 +484,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 Expand Up @@ -642,11 +642,11 @@ extern "C" {
} Xcp_CommandType;

typedef enum tagXcp_ReturnType {
ERR_CMD_SYNCH = UINT8(0x00), /* Command processor synchronization. S0 */
ERR_CMD_SYNCH = UINT8(0x00), /* Command processor synchronization. S0 */

ERR_CMD_BUSY = UINT8(0x10), /* Command was not executed. S2 */
ERR_DAQ_ACTIVE = UINT8(0x11), /* Command rejected because DAQ is running. S2 */
ERR_PGM_ACTIVE = UINT8(0x12), /* Command rejected because PGM is running. S2 */
ERR_CMD_BUSY = UINT8(0x10), /* Command was not executed. S2 */
ERR_DAQ_ACTIVE = UINT8(0x11), /* Command rejected because DAQ is running. S2 */
ERR_PGM_ACTIVE = UINT8(0x12), /* Command rejected because PGM is running. S2 */

ERR_CMD_UNKNOWN = UINT8(0x20), /* Unknown command or not implemented optional command. S2 */
ERR_CMD_SYNTAX = UINT8(0x21), /* Command syntax invalid S2 */
Expand All @@ -661,10 +661,10 @@ extern "C" {
ERR_SEQUENCE = UINT8(0x29), /* Sequence error S2 */
ERR_DAQ_CONFIG = UINT8(0x2A), /* DAQ configuration not valid S2 */

ERR_MEMORY_OVERFLOW = UINT8(0x30), /* Memory overflow error S2 */
ERR_GENERIC = UINT8(0x31), /* Generic error. S2 */
ERR_VERIFY = UINT8(0x32), /* The slave internal program verify routine detects
an error. S3 */
ERR_MEMORY_OVERFLOW = UINT8(0x30), /* Memory overflow error S2 */
ERR_GENERIC = UINT8(0x31), /* Generic error. S2 */
ERR_VERIFY = UINT8(0x32), /* The slave internal program verify routine detects
an error. S3 */

/* NEW IN 1.1 */
ERR_RESOURCE_TEMPORARY_NOT_ACCESSIBLE = UINT8(0x33), /* Access to the requested resource is temporary not
Expand Down Expand Up @@ -1039,7 +1039,7 @@ extern "C" {

#endif // XCP_BUILD_TYPE

#endif /* XCP_ENABLE_DAQ_COMMANDS */
#endif /* XCP_ENABLE_DAQ_COMMANDS */

/*
** PGM Functions.
Expand Down Expand Up @@ -1222,4 +1222,4 @@ typedef uint32_t Xcp_ChecksumType;
#endif /* __cplusplus */
#endif /* XCP_EXTERN_C_GUARDS */

#endif /* __CXCP_H */
#endif /* __CXCP_H */
2 changes: 1 addition & 1 deletion inc/xcp_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ extern "C" {
#define DBG_TRACE4(a, b, c, d)
#define DBG_TRACE5(a, b, c, d, e)
#define DBG_TRACE6(a, b, c, d, e, f)
#endif /* XCP_BUILD_TYPE == XCP_DEBUG_BUILD */
#endif /* XCP_BUILD_TYPE == XCP_DEBUG_BUILD */

#define XCP_ARRAY_SIZE(arr) (sizeof((arr)) / sizeof((arr)[0])) /**< Calculates the number of elements of \a arr */

Expand Down
9 changes: 4 additions & 5 deletions src/hw/linux/hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,13 @@ static void DeinitTUI(void);

void exitFunc(void);


/*
** Local Variables.
*/
static HwStateType HwState = { 0 };
static struct timespec XcpHw_TimerResolution = { 0 };
static timer_t XcpHw_AppMsTimer;
static unsigned long long XcpHw_FreeRunningCounter = 0ULL;
static HwStateType HwState = { 0 };
static struct timespec XcpHw_TimerResolution = { 0 };
static timer_t XcpHw_AppMsTimer;
static unsigned long long XcpHw_FreeRunningCounter = 0ULL;

/*
** Global Functions.
Expand Down
Loading

0 comments on commit 6fef372

Please sign in to comment.