Skip to content

Commit

Permalink
Fix some code smells.
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Sep 4, 2022
1 parent 8516d44 commit 8365b2b
Show file tree
Hide file tree
Showing 16 changed files with 870 additions and 710 deletions.
4 changes: 2 additions & 2 deletions examples/xcpsim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ IF(CMAKE_C_COMPILER_ID STREQUAL "GNU")
ELSEIF(CMAKE_C_COMPILER_ID MATCHES "Clang")
SET(CMAKE_C_STANDARD 11)
ELSE()
message(WARNING "C standard could not be set because compiler is not GNU or Clang.")
#message(WARNING "C standard could not be set because compiler is not GNU or Clang.")
ENDIF()

option(DISABLE_SOCKET "Disable SocketCAN build" OFF)
Expand Down Expand Up @@ -86,7 +86,7 @@ else()
endif()
endif()
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG -O3 -flto ")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG -Og -UNDEBUG")
endif()
endif(MSVC)

Expand Down
2 changes: 1 addition & 1 deletion flsemu/flsemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ typedef struct tagFlsEmu_SegmentType {
uint16_t sectorSize;
uint32_t pageSize;
uint8_t blockCount;
uint32_t baseAddress;
Xcp_PointerSizeType baseAddress;
FlsEmu_PersistentArrayType *persistentArray;
uint8_t currentPage;
uint32_t alloctedPageSize;
Expand Down
6 changes: 3 additions & 3 deletions inc/xcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,15 +714,15 @@ typedef enum tagXcp_ReturnType {

typedef struct tagXcp_MtaType {
uint8_t ext;
uint32_t address;
Xcp_PointerSizeType address;
} Xcp_MtaType;

#if XCP_ENABLE_DAQ_COMMANDS == XCP_ON
typedef struct tagXcpDaq_MtaType {
#if XCP_DAQ_ENABLE_ADDR_EXT == XCP_ON
uint8_t ext;
#endif /* XCP_DAQ_ENABLE_ADDR_EXT */
uint32_t address;
Xcp_PointerSizeType address;
} XcpDaq_MtaType;

typedef enum tagXcpDaq_ProcessorStateType {
Expand Down Expand Up @@ -991,7 +991,7 @@ bool XcpDaq_ValidateOdtEntry(XcpDaq_ListIntegerType daqListNumber,
XcpDaq_ODTEntryIntegerType odtEntry);
void XcpDaq_AddEventChannel(XcpDaq_ListIntegerType daqListNumber,
uint16_t eventChannelNumber);
void XcpDaq_CopyMemory(void *dst, void *src, uint32_t len);
void XcpDaq_CopyMemory(void *dst, void const *src, uint32_t len);
XcpDaq_EventType const *
XcpDaq_GetEventConfiguration(uint16_t eventChannelNumber);
void XcpDaq_TriggerEvent(uint8_t eventChannelNumber);
Expand Down
6 changes: 5 additions & 1 deletion inc/xcp_macros.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* BlueParrot XCP
*
* (C) 2007-2021 by Christoph Schueler <github.com/Christoph2,
* (C) 2007-2022 by Christoph Schueler <github.com/Christoph2,
* cpu12.gems@googlemail.com>
*
* All Rights Reserved
Expand Down Expand Up @@ -41,6 +41,8 @@ extern "C" {
#endif /* __cplusplus */
#endif /* XCP_EXTERN_C_GUARDS */

#include <assert.h>

#define XCP_DEBUG_BUILD (1)
#define XCP_RELEASE_BUILD (2)

Expand Down Expand Up @@ -185,4 +187,6 @@ extern "C" {
#endif /* __cplusplus */
#endif /* XCP_EXTERN_C_GUARDS */

#define XCP_ASSERT(x) assert(x)

#endif /* __XCP_MACROS_H */
3 changes: 2 additions & 1 deletion inc/xcp_terminal.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* BlueParrot XCP
*
* (C) 2021 by Christoph Schueler <github.com/Christoph2,
* (C) 2022 by Christoph Schueler <github.com/Christoph2,
* cpu12.gems@googlemail.com>
*
* All Rights Reserved
Expand All @@ -28,6 +28,7 @@

/*!!! START-INCLUDE-SECTION !!!*/
#include "xcp.h"
#include "xcp_threads.h"
/*!!! END-INCLUDE-SECTION !!!*/

#endif /* __TERMINAL_H */
23 changes: 18 additions & 5 deletions inc/xcp_types.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* BlueParrot XCP
*
* (C) 2007-2019 by Christoph Schueler <github.com/Christoph2,
* (C) 2007-2022 by Christoph Schueler <github.com/Christoph2,
* cpu12.gems@googlemail.com>
*
* All Rights Reserved
Expand All @@ -26,6 +26,8 @@
#if !defined(__XCP_TYPES_H)
#define __XCP_TYPES_H

#include <limits.h>

#if XCP_ENABLE_EXTERN_C_GUARDS == XCP_ON
#if defined(__cplusplus)
extern "C" {
Expand Down Expand Up @@ -59,15 +61,26 @@ typedef unsigned short uint16_t;
typedef signed long int32_t;
typedef unsigned long uint32_t;

#if 0
typedef signed long long int64_t;
typedef unsigned long long uint64_t;
#endif
typedef signed long long int64_t;
typedef unsigned long long uint64_t;

#else

#include <stdbool.h>
#include <stdint.h>

/* 64-bit */
#if UINTPTR_MAX == 0xffffffffffffffff
#define ENV64BIT
typedef uint64_t Xcp_PointerSizeType;
#elif UINTPTR_MAX == 0xffffffff
typedef uint32_t Xcp_PointerSizeType;
#define ENV32BIT
#else
#define ENV16BIT
typedef uint32_t Xcp_PointerSizeType;
#endif

#endif

#define UINT8(x) ((uint8_t)(x))
Expand Down
16 changes: 9 additions & 7 deletions src/hw/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
#if defined(_WIN32)
#include <windows.h>
#else
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include <termios.h>
Expand All @@ -67,7 +67,9 @@ void XcpDaq_Info(void);
#if defined(_WIN32)
void *XcpTerm_Thread(void *param) {
HANDLE hStdin;
DWORD cNumRead, fdwMode, idx;
DWORD cNumRead;
DWORD fdwMode;
DWORD idx;
INPUT_RECORD irInBuf[128];
KEY_EVENT_RECORD key;

Expand Down Expand Up @@ -103,7 +105,7 @@ void *XcpTerm_Thread(void *param) {
}
switch (tolower(key.uChar.AsciiChar)) {
case 'q':
XcpThrd_Exit(NULL);
XcpThrd_Exit();
case 'h':
DisplayHelp();
break;
Expand All @@ -113,6 +115,8 @@ void *XcpTerm_Thread(void *param) {
case 'd':
XcpDaq_PrintDAQDetails();
break;
default:
break;
}
}
break;
Expand Down Expand Up @@ -206,7 +210,7 @@ void *XcpTerm_Thread(void *param) {

static void SystemInformation(void) {
#if XCP_ENABLE_STATISTICS == XCP_ON
Xcp_StateType *state;
Xcp_StateType const *state = Xcp_GetState();
#endif /* XCP_ENABLE_STATISTICS */

printf("\n\rSystem-Information\n\r");
Expand Down Expand Up @@ -252,7 +256,6 @@ static void SystemInformation(void) {
FlsEmu_Info();
}
#if XCP_ENABLE_STATISTICS == XCP_ON
state = Xcp_GetState();
printf("\n\rStatistics\n\r");
printf("----------\n\r");
printf("CTOs rec'd : %d\n\r", state->statistics.ctosReceived);
Expand All @@ -268,7 +271,6 @@ static void DisplayHelp(void) {
printf("<ESC> or q\texit\n\r");
printf("i\t\tsystem information\n\r");
printf("d\t\tDAQ configuration\n\r");
/* printf("d\t\tReset connection\n"); */
}

void FlsEmu_Info(void) {
Expand Down Expand Up @@ -303,7 +305,7 @@ void XcpDaq_PrintDAQDetails(void) {
XcpDaq_ListConfigurationType const *listConf;
XcpDaq_ListStateType *listState;
XcpDaq_ODTType const *odt;
XcpDaq_ODTEntryType *entry;
XcpDaq_ODTEntryType const *entry;
uint8_t mode;
uint32_t total;
XcpDaq_ODTIntegerType firstPid;
Expand Down
6 changes: 3 additions & 3 deletions src/hw/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ static void XcpThrd_CreateThread(XcpThrd_ThreadType *thrd,
void XcpThrd_RunThreads(void) {
atexit(bye);

XcpThrd_CreateThread(&threads[UI_THREAD], XcpTerm_Thread);
XcpThrd_CreateThread(&threads[TL_THREAD], XcpTl_Thread);
XcpThrd_CreateThread(&threads[XCP_THREAD], Xcp_Thread);
XcpThrd_CreateThread(&threads[UI_THREAD], &XcpTerm_Thread);
XcpThrd_CreateThread(&threads[TL_THREAD], &XcpTl_Thread);
XcpThrd_CreateThread(&threads[XCP_THREAD], &Xcp_Thread);
#if defined(_WIN32)
WaitForSingleObject(threads[UI_THREAD], INFINITE);
XcpThrd_ShutDown();
Expand Down

0 comments on commit 8365b2b

Please sign in to comment.