make libCLS more independen of HW
goal is to reuse libCLS on an diffrent MCU
This commit is contained in:
@@ -30,8 +30,14 @@ add_library(PROTOS ${PROTO_SRCS} ${PROTO_HDRS})
|
||||
target_include_directories(PROTOS PUBLIC ${NANOPB_INCLUDE_DIRS} ${PROJECT_BINARY_DIR})
|
||||
include_directories(${PROJECT_BINARY_DIR})
|
||||
|
||||
|
||||
add_library(CLS_BSP mock_os/CLS_BSP.c)
|
||||
target_include_directories(CLS_BSP PUBLIC
|
||||
./
|
||||
../lib/Unity/src
|
||||
)
|
||||
|
||||
add_subdirectory(../../Application/Tasks Tasks)
|
||||
add_subdirectory(../../Application/CLS CLS)
|
||||
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC Tasks)
|
||||
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC Tasks CLS)
|
||||
@@ -202,6 +202,40 @@ void test_CanData_removeEvent() {
|
||||
}
|
||||
|
||||
|
||||
void test_CanData_regDataManualMsg(void) {
|
||||
CanDataHandler_init(); // Reset the state of the module
|
||||
|
||||
{
|
||||
CanDataId canids[] = {1, 2, 3};
|
||||
size_t id_count = sizeof(canids) / sizeof(canids[0]);
|
||||
CLS_BSP_CAN_UniversalFilter filter = {
|
||||
.filterDestination = CLS_CAN_FILTER_TO_RXFIFO0,
|
||||
.filterMode = 0xff,
|
||||
.id0 = 0x7ff,
|
||||
.id1 = 0x003,
|
||||
};
|
||||
|
||||
size_t result = CanData_regDataManualMsg(canids, id_count, &filter);
|
||||
TEST_ASSERT_EQUAL(id_count, result);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
CanDataId canids[] = {4, 5, 7};
|
||||
size_t id_count = sizeof(canids) / sizeof(canids[0]);
|
||||
CLS_BSP_CAN_UniversalFilter filter = {
|
||||
.filterDestination = CLS_CAN_FILTER_TO_RXFIFO0,
|
||||
.filterMode = 0xf8,
|
||||
.id0 = 0x777,
|
||||
.id1 = 0x073,
|
||||
};
|
||||
|
||||
size_t result = CanData_regDataManualMsg(canids, id_count, &filter);
|
||||
|
||||
TEST_ASSERT_EQUAL(id_count, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Create a test runner function
|
||||
@@ -217,4 +251,5 @@ void test_CanData(void) {
|
||||
RUN_TEST(test_CanData_canFifo0RxCallback_data_invalid);
|
||||
RUN_TEST(test_CanData_canFifo1RxCallback_data_valid);
|
||||
RUN_TEST(test_CanData_removeEvent);
|
||||
RUN_TEST(test_CanData_regDataManualMsg);
|
||||
}
|
||||
|
||||
10
tests/native/mock_os/CLS_BSP.c
Normal file
10
tests/native/mock_os/CLS_BSP.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "CLS_BSP.h"
|
||||
#include "stdio.h"
|
||||
|
||||
HAL_StatusTypeDef CLS_BSP_CAN_AddMessageToSend(CLS_BSP_TxHeaderType * header, uint8_t * data) {
|
||||
printf("CAN: %x : %x %x %x %x %x %x %x %x \n", header, data[0], data[1], data[2], data[3], data[4], data[5], data[6],data[7]);
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef CLS_BSP_CAN_SetUniversalFilter(const CLS_BSP_CAN_UniversalFilter * filter) {
|
||||
printf("FILTER: %x : %x %x : %x %x \n", filter->filterIndex, filter->filterDestination, filter->filterMode,filter->id0, filter->id1);
|
||||
}
|
||||
35
tests/native/mock_os/CLS_BSP.h
Normal file
35
tests/native/mock_os/CLS_BSP.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "stdint.h"
|
||||
|
||||
typedef uint16_t CLS_BSP_TxHeaderType;
|
||||
|
||||
typedef unsigned int HAL_StatusTypeDef;
|
||||
|
||||
typedef struct {
|
||||
uint32_t filterIndex;
|
||||
uint32_t filterDestination;
|
||||
uint32_t filterMode;
|
||||
uint16_t id0;
|
||||
uint16_t id1;
|
||||
} CLS_BSP_CAN_UniversalFilter;
|
||||
|
||||
#define CLS_BSP_DLC_BYTES_1 1
|
||||
#define CLS_BSP_DLC_BYTES_2 2
|
||||
#define CLS_BSP_DLC_BYTES_3 3
|
||||
#define CLS_BSP_DLC_BYTES_4 4
|
||||
#define CLS_BSP_DLC_BYTES_5 5
|
||||
#define CLS_BSP_DLC_BYTES_6 6
|
||||
#define CLS_BSP_DLC_BYTES_7 7
|
||||
#define CLS_BSP_DLC_BYTES_8 8
|
||||
|
||||
#define CLS_CAN_FILTER_DISABLE 0
|
||||
#define CLS_CAN_FILTER_TO_RXFIFO0 2
|
||||
#define CLS_CAN_FILTER_TO_RXFIFO1 3
|
||||
|
||||
#define CLS_BSP_CAN_FILTER_LIST 1
|
||||
|
||||
|
||||
#define CREATE_BSP_CAN_HEADER(identifier, datalength) 0
|
||||
|
||||
HAL_StatusTypeDef CLS_BSP_CAN_AddMessageToSend(CLS_BSP_TxHeaderType * header, uint8_t * data);
|
||||
|
||||
HAL_StatusTypeDef CLS_BSP_CAN_SetUniversalFilter(const CLS_BSP_CAN_UniversalFilter * filter);
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "stdint.h"
|
||||
|
||||
#include "stddef.h"
|
||||
#define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value.
|
||||
|
||||
/// Status code values returned by CMSIS-RTOS functions.
|
||||
@@ -96,15 +96,47 @@ typedef struct {
|
||||
} osMessageQueueAttr_t;
|
||||
|
||||
|
||||
/// Attributes structure for timer.
|
||||
typedef struct {
|
||||
const char *name; ///< name of the timer
|
||||
uint32_t attr_bits; ///< attribute bits
|
||||
void *cb_mem; ///< memory for control block
|
||||
uint32_t cb_size; ///< size of provided memory for control block
|
||||
} osTimerAttr_t;
|
||||
|
||||
|
||||
/// Timer callback function.
|
||||
typedef void (*osTimerFunc_t) (void *argument);
|
||||
|
||||
typedef void (*osThreadFunc_t) (void *argument);
|
||||
typedef void* osMessageQueueId_t;
|
||||
typedef void* osThreadId_t;
|
||||
typedef void* osTimerId_t;
|
||||
void Error_Handler();
|
||||
|
||||
|
||||
/// Timer type.
|
||||
typedef enum {
|
||||
osTimerOnce = 0, ///< One-shot timer.
|
||||
osTimerPeriodic = 1 ///< Repeating timer.
|
||||
} osTimerType_t;
|
||||
|
||||
// Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait).
|
||||
#define osFlagsWaitAny 0x00000000U ///< Wait for any flag (default).
|
||||
#define osFlagsWaitAll 0x00000001U ///< Wait for all flags.
|
||||
#define osFlagsNoClear 0x00000002U ///< Do not clear flags which have been specified to wait for.
|
||||
|
||||
|
||||
osThreadId_t osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr_t *attr);
|
||||
osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout);
|
||||
osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout);
|
||||
osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr) ;
|
||||
osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);
|
||||
osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks);
|
||||
|
||||
uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout);
|
||||
uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags);
|
||||
void osThreadExit (void);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1714,3 +1714,12 @@ do{ \
|
||||
|
||||
|
||||
HAL_StatusTypeDef HAL_FDCAN_ConfigFilter(FDCAN_HandleTypeDef *hfdcan, FDCAN_FilterTypeDef *sFilterConfig);
|
||||
uint32_t HAL_FDCAN_GetRxFifoFillLevel(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo);
|
||||
uint32_t HAL_FDCAN_GetTxFifoFreeLevel(FDCAN_HandleTypeDef *hfdcan);
|
||||
HAL_StatusTypeDef HAL_FDCAN_GetRxMessage(FDCAN_HandleTypeDef *hfdcan, uint32_t RxLocation, FDCAN_RxHeaderTypeDef *pRxHeader, uint8_t *pRxData);
|
||||
HAL_StatusTypeDef HAL_FDCAN_ConfigGlobalFilter(FDCAN_HandleTypeDef *hfdcan, uint32_t NonMatchingStd, uint32_t NonMatchingExt, uint32_t RejectRemoteStd, uint32_t RejectRemoteExt);
|
||||
HAL_StatusTypeDef HAL_FDCAN_Start(FDCAN_HandleTypeDef *hfdcan);
|
||||
|
||||
|
||||
#define HAL_OK 0
|
||||
#define HAL_ERROR 1
|
||||
|
||||
Reference in New Issue
Block a user