2024-02-06 03:26:10 +01:00
2024-02-05 19:49:37 +01:00
2024-05-28 04:15:52 +02:00
2024-05-28 04:15:52 +02:00
2024-05-29 03:48:06 +02:00
2024-02-06 03:26:10 +01:00

libCLS

libCLS is the core library for the CanLightSystem (CLS). It serves as the starting point for interacting with the CLS-Can-bus network. The library is designed to run on a STM32 MCU with FreeRTOS/CMSISv2.

Features

  • CanDataHandler: This is the core part of the libCLS. It is the common point where all CLS CAN Messages are processed. You can register message CAN ID. If a CAN message is received that is registered, it will be stored, and the latest value can always be accessed from anywhere in the code. You can also register an event CAN ID along with a callback. This callback is then called when a message with this ID is received. Additionally, the CanDataHandler also provides a way to set up the STM32 Can Hardware Filters to receive these CAN IDs.

  • CanID Generator: This feature allows you to generate CAN StdIDs (11bit), based on the CLS address layout (Type, Device, Channel).

  • Heartbeat Sender: Currently, the libCLS also contains a Heartbeat sender that sends a Heartbeat message to the CLS Can Bus.

Requirements

STM32 MCU with FreeRTOS/CMSISv2.

Usage

When using libCLS, the project must contain a libCLS_BSP that needs to be implemented by the project. This must provide hardware-specific functions, like the interaction with the Can Controller Hardware.

CanDataHandler

The CanDataHandler module is primarily responsible for managing CAN data messages and event messages. It provides functionalities to register CAN IDs for data and event messages, handle the reception of these messages from FIFO buffers, insert data messages into an array, and retrieve stored data messages based on their CAN ID.

Usage

When using the CanDataHandler you must define MAX_FILTER_SLOTS accroding to you hardware setup. MAX_FILTER_SLOTS is the number of Hardware CAN filters you have for the CLS Can Bus.

Also you may define MAX_DATA_STORAGE or MAX_DATA_STORAGE they define the number of data messages or event messages you could handle. if not defined they will default to 100

The CanDataHandler will automatcly setup Hardware filters for each canid that gets registerd. To work with your hardware you need to implemetn the following function and types in your libCLS_BST:

typedef struct  {
    uint32_t filterIndex;
    uint32_t filterDestination;
    uint32_t filterMode;
    uint16_t id0;
    uint16_t id1;
} CLS_BSP_CAN_UniversalFilter;

HAL_StatusTypeDef CLS_BSP_CAN_SetUniversalFilter(const CLS_BSP_CAN_UniversalFilter * filter);

if you need deeper access to the filter generation you could overwrite these functions:

__weak void setup_StmCanFilter(const CanDataFilterSlot* filterSetting );
__weak void setup_StmCanFilterManual(const CanDataFilterSlot* filterSetting, CLS_BSP_CAN_UniversalFilter * filter );

API

The main components of the CanDataHandler module are:

  1. CanData_regDataMsg: This function registers a CAN ID for data messages. If a CAN ID is already registered, it will return true and do nothing.

  2. CanData_regDataManualMsg: This function registers a set of IDs for data messages using a manual filter. This is useful for implementing a filter mask that matches multiple CAN IDs and saves filter slots in the hardware.

  3. CanData_regEventMsg: This function registers a CAN ID for event messages and associates it with a callback function. Only a single callback is currently supported for each CAN ID.

  4. CanData_removeEvent: This function removes a CAN ID from the event messages register.

  5. CanData_canFifo0RxCallback: This function handles the reception of data messages from FIFO0 and needs to be called when CAN messages arrive on FIFO0.

  6. CanData_canFifo1RxCallback: This function handles the reception of event messages from FIFO1 and needs to be called when CAN messages arrive on FIFO1.

  7. CanData_getDataMessage: This function retrieves a stored data message based on the CAN ID. If not found, it returns NULL.

The module maintains an internal structure for data and event message slots, each associated with a filter reference that points to a filter slot. A filter slot stores the CAN IDs and indicates the type of FIFO buffer and the number of free IDs in the slot. For event messages, a callback function can be registered to handle specific events associated with a CAN ID.

Description
No description provided
Readme 49 KiB
Languages
C 97.7%
CMake 2.3%