From fd442639a2d4cce31f6a795794ca43d21055e6e0 Mon Sep 17 00:00:00 2001 From: "Io. D" Date: Tue, 18 Jan 2022 09:11:24 +0100 Subject: [PATCH 1/3] fx as submodule --- exm/ISO15765Development.c | 7 ++- src/iqueue.c | 123 -------------------------------------- src/iqueue.h | 57 ------------------ src/iso15765_2.h | 2 +- 4 files changed, 6 insertions(+), 183 deletions(-) delete mode 100644 src/iqueue.c delete mode 100644 src/iqueue.h diff --git a/exm/ISO15765Development.c b/exm/ISO15765Development.c index c5b8b94..7e026dd 100644 --- a/exm/ISO15765Development.c +++ b/exm/ISO15765Development.c @@ -1,4 +1,7 @@ -#include +//#define ISO16765Example +#ifdef ISO16765Example + +#include #include #include "iso15765_2.h" #include @@ -227,4 +230,4 @@ int main() } return 0; } - +#endif diff --git a/src/iqueue.c b/src/iqueue.c deleted file mode 100644 index 4ba624e..0000000 --- a/src/iqueue.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * iqueue.c - * - * Created on: 31 Jul 2018 - * Author: ioadel - */ - - - /****************************************************************************** - * SOF - Source | By: Io.D - ******************************************************************************/ - - /****************************************************************************** - * Includes - ******************************************************************************/ - -#include "iqueue.h" - - /****************************************************************************** - * Declarations - ******************************************************************************/ - - /****************************************************************************** - * Public functions - ******************************************************************************/ - -I_Status_Queue iqueue_init(iqueue_t* _queue, int _max_elements, size_t _element_size, void* _storage) -{ - I_Status_Queue result = I_ERROR; - if (_queue != NULL) - { - memset(_storage, 0x00, _element_size * _max_elements); - _queue->element_size = _element_size; - _queue->max_elements = _max_elements; - _queue->first = (void*)0; - _queue->next = _queue->storage = _storage; - result = I_OK; - } - return result; -} - - -volatile void* iqueue_get_next_enqueue(iqueue_t* _queue) -{ - return _queue->next; -} - -I_Status_Queue iqueue_advance_next(iqueue_t* _queue) -{ - I_Status_Queue result = I_FULL; - if (_queue->first != _queue->next) - { - _queue->first = _queue->first == (void*)0 ? _queue->next : _queue->first; - _queue->next = (uint8_t*)_queue->next + _queue->element_size == (uint8_t*)_queue->storage + (_queue->element_size * _queue->max_elements) - ? _queue->storage : (uint8_t*)_queue->next + _queue->element_size; - result = I_OK; - } - return result; -} - -I_Status_Queue iqueue_enqueue(iqueue_t* _queue, void* _element) -{ - I_Status_Queue result = I_FULL; - - if (_queue->first != _queue->next) - { - memmove((void*)_queue->next, (void*)_element, _queue->element_size); - _queue->first = _queue->first == (void*)0 ? _queue->next : _queue->first; - _queue->next = (uint8_t*)_queue->next + _queue->element_size == (uint8_t*)_queue->storage + (_queue->element_size * _queue->max_elements) - ? _queue->storage : (uint8_t*)_queue->next + _queue->element_size; - result = I_OK; - } - return result; -} - -I_Status_Queue iqueue_dequeue(iqueue_t* _queue, void* _element) -{ - I_Status_Queue result = I_EMPTY; - - if (_queue->first != (void*)0) - { - memmove((void*)_element, (void*)_queue->first, _queue->element_size); - _queue->first = (uint8_t*)_queue->first + _queue->element_size == (uint8_t*)_queue->storage + (_queue->element_size * _queue->max_elements) - ? _queue->storage : (uint8_t*)_queue->first + _queue->element_size; - _queue->first = _queue->first == _queue->next ? (void*)0 : _queue->first; - result = I_OK; - } - return result; -} - -volatile void* iqueue_dequeue_fast(iqueue_t* _queue) -{ - void* result = _queue->first; - - if (result != (void*)0) - { - _queue->first = (uint8_t*)_queue->first + _queue->element_size == (uint8_t*)_queue->storage + (_queue->element_size * _queue->max_elements) - ? _queue->storage : (uint8_t*)_queue->first + _queue->element_size; - _queue->first = _queue->first == _queue->next ? (void*)0 : _queue->first; - } - - return result; -} - - -I_Status_Queue iqueue_size(iqueue_t* _queue, uint32_t* _size) -{ - *_size = _queue->first == (void*)0 - ? 0 - : _queue->first < _queue->next - ? ((uintptr_t)_queue->next - (uintptr_t)_queue->first) / _queue->element_size - : _queue->max_elements - (((uintptr_t)_queue->first - (uintptr_t)_queue->next) / _queue->element_size); - - return I_OK; -} - -/****************************************************************************** -* Static functions -******************************************************************************/ - -/****************************************************************************** -* EOF - Source -******************************************************************************/ \ No newline at end of file diff --git a/src/iqueue.h b/src/iqueue.h deleted file mode 100644 index 9838199..0000000 --- a/src/iqueue.h +++ /dev/null @@ -1,57 +0,0 @@ -/****************************************************************************** -* SOF - Header | By: Io.D -******************************************************************************/ - -#ifndef LIBRARIES_IQUEUE_H_ - -/****************************************************************************** -* Definitions -******************************************************************************/ - -#define LIBRARIES_IQUEUE_H_ - -/****************************************************************************** -* Includes -******************************************************************************/ - -#include -#include - -/****************************************************************************** -* Enumerations, structures & External Variables -******************************************************************************/ - -typedef enum -{ - I_OK = 0x00, - I_ERROR = 0x01, - I_FULL = 0x60, - I_EMPTY = 0x61 -}I_Status_Queue; - -typedef struct -{ - volatile void* storage; - volatile void* first; - volatile void* next; - volatile size_t element_size; - volatile uint32_t max_elements; -} -iqueue_t; - -/****************************************************************************** -* Public Functions (API) -******************************************************************************/ - -I_Status_Queue iqueue_init(iqueue_t* _queue, int _max_elements, size_t _element_size, void* _storage); -I_Status_Queue iqueue_enqueue(iqueue_t* _queue, void* _element); -I_Status_Queue iqueue_dequeue(iqueue_t* _queue, void* _element); -I_Status_Queue iqueue_size(iqueue_t* _queue, uint32_t* _size); -volatile void* iqueue_get_next_enqueue(iqueue_t* _queue); -volatile void* iqueue_dequeue_fast(iqueue_t* _queue); -I_Status_Queue iqueue_advance_next(iqueue_t* _queue); -/****************************************************************************** -* EOF - Header -******************************************************************************/ - -#endif \ No newline at end of file diff --git a/src/iso15765_2.h b/src/iso15765_2.h index 732f9cc..479050e 100644 --- a/src/iso15765_2.h +++ b/src/iso15765_2.h @@ -57,7 +57,7 @@ SOFTWARE. #include #include -#include "iqueue.h" +#include "lib_iqueue.h" /****************************************************************************** * Enumerations, structures & Variables From 379b2ccd1d04666151c996c7fdd601f0b35a4674 Mon Sep 17 00:00:00 2001 From: "Io. D" Date: Tue, 18 Jan 2022 09:35:42 +0100 Subject: [PATCH 2/3] update header --- src/iso15765_2.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/iso15765_2.h b/src/iso15765_2.h index 479050e..0d2f8b6 100644 --- a/src/iso15765_2.h +++ b/src/iso15765_2.h @@ -65,7 +65,8 @@ SOFTWARE. /* --- CANTP Mode - Frame Type (ref: ) ----------------- */ -#ifndef cbus_fr_format +#ifndef CBUS_FR_FORMAT +#define CBUS_FR_FORMAT typedef enum { CBUS_FR_FRM_STD = 0x01, /* Standard CANBUS */ @@ -75,7 +76,8 @@ typedef enum /* --- CANBus Mode [ID Type] (ref: iso15765-2 p.8) -------==---------------- */ -#ifndef cbus_id_type +#ifndef CBUS_ID_TYPE +#define CBUS_ID_TYPE typedef enum { CBUS_ID_T_STANDARD = 0x04U, /* 11bits CAN Identifier */ @@ -86,6 +88,7 @@ typedef enum /* --- CANBus Frame (ref: iso15765-2 p.) ----------------------------------- */ #ifndef CANBUS_FRAME +#define CANBUS_FRAME typedef struct { uint32_t id; /* CAN Frame Id */ From c95bc0f6858c9e1bd2e644e2f6b7b46855b28ce4 Mon Sep 17 00:00:00 2001 From: "Io. D" Date: Tue, 18 Jan 2022 11:10:46 +0100 Subject: [PATCH 3/3] fx as module --- exm/ISO15765Development.c | 2 +- src/{iso15765_2.c => lib_iso15765.c} | 2 +- src/{iso15765_2.h => lib_iso15765.h} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/{iso15765_2.c => lib_iso15765.c} (99%) rename src/{iso15765_2.h => lib_iso15765.h} (100%) diff --git a/exm/ISO15765Development.c b/exm/ISO15765Development.c index 7e026dd..f5ba231 100644 --- a/exm/ISO15765Development.c +++ b/exm/ISO15765Development.c @@ -3,7 +3,7 @@ #include #include -#include "iso15765_2.h" +#include "lib_iso15765.h" #include #include #include diff --git a/src/iso15765_2.c b/src/lib_iso15765.c similarity index 99% rename from src/iso15765_2.c rename to src/lib_iso15765.c index b2a4449..bedc333 100644 --- a/src/iso15765_2.c +++ b/src/lib_iso15765.c @@ -33,7 +33,7 @@ SOFTWARE. * Includes ******************************************************************************/ -#include "iso15765_2.h" +#include "lib_iso15765.h" /****************************************************************************** * Enumerations, structures & Variables diff --git a/src/iso15765_2.h b/src/lib_iso15765.h similarity index 100% rename from src/iso15765_2.h rename to src/lib_iso15765.h