Skip to content

Commit

Permalink
Updates regarding Arduino
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed May 13, 2024
1 parent 8d971c3 commit d7f4914
Show file tree
Hide file tree
Showing 26 changed files with 7,357 additions and 280 deletions.
22 changes: 10 additions & 12 deletions examples/xcpsim/xcp_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
#define XCP_DAQ_ENABLE_ADDR_EXT XCP_OFF
#define XCP_DAQ_ENABLE_BIT_OFFSET XCP_OFF
#define XCP_DAQ_ENABLE_PRIORITIZATION XCP_OFF
#define XCP_DAQ_ENABLE_QUEUING XCP_ON
#define XCP_DAQ_ENABLE_ALTERNATING XCP_OFF
#define XCP_DAQ_ENABLE_CLOCK_ACCESS_ALWAYS XCP_ON
#define XCP_DAQ_ENABLE_WRITE_THROUGH XCP_OFF
Expand All @@ -105,17 +104,16 @@
/*
** Optional Services.
*/
#define XCP_ENABLE_GET_COMM_MODE_INFO XCP_ON
#define XCP_ENABLE_GET_ID XCP_ON
#define XCP_ENABLE_SET_REQUEST XCP_OFF
#define XCP_ENABLE_GET_SEED XCP_OFF
#define XCP_ENABLE_UNLOCK XCP_OFF
#define XCP_ENABLE_SET_MTA XCP_ON
#define XCP_ENABLE_UPLOAD XCP_ON
#define XCP_ENABLE_SHORT_UPLOAD XCP_ON
#define XCP_ENABLE_BUILD_CHECKSUM XCP_ON
#define XCP_ENABLE_TRANSPORT_LAYER_CMD XCP_OFF /* TODO: TL dependend include file! */
#define XCP_ENABLE_USER_CMD XCP_OFF
#define XCP_ENABLE_GET_COMM_MODE_INFO XCP_ON
#define XCP_ENABLE_GET_ID XCP_ON
#define XCP_ENABLE_SET_REQUEST XCP_OFF
#define XCP_ENABLE_GET_SEED XCP_OFF
#define XCP_ENABLE_UNLOCK XCP_OFF
#define XCP_ENABLE_SET_MTA XCP_ON
#define XCP_ENABLE_UPLOAD XCP_ON
#define XCP_ENABLE_SHORT_UPLOAD XCP_ON
#define XCP_ENABLE_BUILD_CHECKSUM XCP_ON
#define XCP_ENABLE_USER_CMD XCP_OFF

#define XCP_ENABLE_CAL_COMMANDS XCP_ON

Expand Down
118 changes: 118 additions & 0 deletions inc/queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

#ifndef CXCP_QUEUE_HPP
#define CXCP_QUEUE_HPP

template<typename T>
class Queue {
public:

explicit Queue(size_t size) {
arr = new T[size];
m_capacity = size;
m_front = 0;
m_rear = -1;
m_count = 0;
}

Queue() = delete;

~Queue() {
delete[] arr;
}

T pop() {
if (isEmpty()) {
exit(EXIT_FAILURE);
}
T x = arr[m_front];

m_front = (m_front + 1) % m_capacity;
m_count--;

return x;
}

void push(const T &item) {
if (isFull()) {
exit(EXIT_FAILURE);
}

m_rear = (m_rear + 1) % m_capacity;
arr[m_rear] = item;
m_count++;
}
#if 0
T peek() {
if (isEmpty()) {
exit(EXIT_FAILURE);
}
return arr[m_front];
}
#endif
size_t size() {
return m_count;
}

bool isEmpty() {
return (size() == 0);
}

bool isFull() {
return (size() == m_capacity);
}

private:

T *arr;
size_t m_capacity;
int m_front;
int m_rear;
size_t m_count;
};

template<typename T>
class Observers {
public:

explicit Observers(size_t size) {
arr = new T[size];
m_capacity = size;
m_count = 0;
}

Observers() = delete;

~Observers() {
delete[] arr;
}

void append(const T &item) {
if (isFull()) {
exit(EXIT_FAILURE);
}
arr[m_count++] = item;
}

bool isFull() {
return (size() == m_capacity);
}

size_t size() {
return m_count;
}

template<typename V>
void notify(const V &value) {
for (size_t i = 0; i < m_capacity; ++i) {
arr[i]->update(value);
}
}

private:

T *arr;
size_t m_capacity;
size_t m_count;
};

#endif // CXCP_QUEUE_HPP
50 changes: 35 additions & 15 deletions inc/xcp.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* BlueParrot XCP
*
* (C) 2007-2022 by Christoph Schueler <github.com/Christoph2,
* (C) 2007-2024 by Christoph Schueler <github.com/Christoph2,
* cpu12.gems@googlemail.com>
*
* All Rights Reserved
Expand All @@ -28,7 +28,7 @@

#include <assert.h>

/*!!! START-INCLUDE-SECTION !!!*/
/*!!! START-INCLUDE-SECTION !!!*/
#include "xcp_macros.h"
#include "xcp_types.h"
#include "xcp_util.h"
Expand Down Expand Up @@ -102,8 +102,15 @@ extern "C" {
#error XCP_MAX_CTO must be <= 255
#endif

#define XCP_DAQ_ENABLE_QUEUING (XCP_ON) /* Private setting for now. */

#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))
#define XCP_ENABLE_TRANSPORT_LAYER_CMD (XCP_ON)
#endif

#if (!defined(XCP_ENABLE_CAN_FD)) || (XCP_ENABLE_CAN_FD == XCP_OFF)
#ifdef XCP_MAX_CTO
#undef XCP_MAX_CTO
Expand Down Expand Up @@ -263,7 +270,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 @@ -454,6 +461,12 @@ extern "C" {
#define XCP_DAQ_DEFINE_EVENT(name, 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 \
} \
; \
const uint16_t Xcp_DaqIDCount = XCP_ARRAY_SIZE(Xcp_DaqIDs);

/*
* PAG Processor Properties.
*/
Expand Down Expand Up @@ -484,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 Expand Up @@ -642,11 +655,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 +674,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 All @@ -674,6 +687,13 @@ extern "C" {
ERR_SUCCESS = UINT8(0xff)
} Xcp_ReturnType;

/*
** Transport Layer Commands / XcpOnCAN
*/
#define XCP_GET_SLAVE_ID (0xFF)
#define XCP_GET_DAQ_ID (0xFE)
#define XCP_SET_DAQ_ID (0xFD)

typedef struct tagXcp_MtaType {
uint8_t ext;
Xcp_PointerSizeType address;
Expand Down Expand Up @@ -1039,7 +1059,7 @@ extern "C" {

#endif // XCP_BUILD_TYPE

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

/*
** PGM Functions.
Expand Down Expand Up @@ -1186,7 +1206,7 @@ extern "C" {

void XcpHw_ReleaseLock(uint8_t lockIdx);

void XcpHw_TransmitDtos(void);
void XcpDaq_TransmitDtos(void);

extern Xcp_PduType Xcp_CtoIn;
extern Xcp_PduType Xcp_CtoOut;
Expand Down Expand Up @@ -1222,4 +1242,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
2 changes: 1 addition & 1 deletion inc/xcp_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern "C" {
#endif
#endif

#if defined(__CSMC__) || !defined(C99_COMPILER) || !defined(C11_COMPILER)
#if (defined(__CSMC__) || !defined(C99_COMPILER) || !defined(C11_COMPILER)) && !defined(__cplusplus)

#if defined(_MSC_VER)

Expand Down
14 changes: 3 additions & 11 deletions src/hw/arduino/hw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ void XcpHw_ReleaseLock(uint8_t lockIdx) {
}
}

#include <vector>

class Timer {
public:

Timer();

private:

std::vector<int> m_timers;
};
void XcpHw_Sleep(uint64_t usec) {
delayMicroseconds(usec);
}
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 d7f4914

Please sign in to comment.