-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Simulation infra and can stuff * bootloader and simulation
- Loading branch information
Showing
115 changed files
with
8,983 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
145 changes: 145 additions & 0 deletions
145
autogen/templates/simulation_app/inc/can_scheduler.h.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#pragma once | ||
|
||
/************************************************************************************************ | ||
* @file can_scheduler.h | ||
* | ||
* @brief Header file defining the CanScheduler class | ||
* | ||
* @date 2025-01-04 | ||
* @author Aryan Kashem | ||
************************************************************************************************/ | ||
|
||
/** @warning This file is autogenerated */ | ||
|
||
/* Standard library Headers */ | ||
#include <atomic> | ||
#include <string> | ||
|
||
/* Inter-component Headers */ | ||
#include <arpa/inet.h> | ||
#include <fcntl.h> | ||
#include <linux/can.h> | ||
#include <linux/can/bcm.h> | ||
#include <net/if.h> | ||
#include <sys/ioctl.h> | ||
#include <sys/socket.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
|
||
/* Intra-component Headers */ | ||
|
||
/** | ||
* @defgroup CanScheduler | ||
* @brief SocketCAN Broadcast Manager abstraction class | ||
* @{ | ||
*/ | ||
{% set messages = messages | list %} | ||
/** | ||
* @class CanScheduler | ||
* @brief Class that handles message scheduling over a SocketCAN interface | ||
* @details This class is responsible scheduling CAN messages based on their cycle speed | ||
* Only 3 cycle speeds are supported, Fast (1kHz), medium (10Hz) and slow (1Hz) | ||
* The class shall support message updating during run-time for further bus simulation | ||
*/ | ||
class CanScheduler { | ||
private: | ||
const std::string CAN_INTERFACE_NAME = "vcan0"; /**< SocketCAN interface name */ | ||
|
||
static const constexpr unsigned int FAST_CYCLE_SPEED_MS = 1U; /**< CAN fast cycle period in milliseconds */ | ||
static const constexpr unsigned int MEDIUM_CYCLE_SPEED_MS = 100U; /**< CAN medium cycle period in milliseconds */ | ||
static const constexpr unsigned int SLOW_CYCLE_SPEED_MS = 1000U; /**< CAN slow cycle period in milliseconds */ | ||
|
||
static const constexpr unsigned int SLOW_CYCLE_BCM_ID = 0U; /**< Linux Broadcast Manager Id for tracking fast cycle messages */ | ||
static const constexpr unsigned int MEDIUM_CYCLE_BCM_ID = 1U; /**< Linux Broadcast Manager Id for tracking medium cycle messages */ | ||
static const constexpr unsigned int FAST_CYCLE_BCM_ID = 2U; /**< Linux Broadcast Manager Id for tracking slow cycle messages */ | ||
|
||
static const constexpr unsigned int NUM_FAST_CYCLE_MESSAGES = {{ message_count.fast_cycle }}U; /**< Number of fast cycle messages */ | ||
static const constexpr unsigned int NUM_MEDIUM_CYCLE_MESSAGES = {{ message_count.medium_cycle }}U; /**< Number of medium cycle messages */ | ||
static const constexpr unsigned int NUM_SLOW_CYCLE_MESSAGES = {{ message_count.slow_cycle }}U; /**< Number of slow cycle messages */ | ||
static const constexpr unsigned int NUM_TOTAL_MESSAGES = {{ message_count.total }}U; /**< Total number of messages */ | ||
static const constexpr unsigned int MAX_MESSAGE_LENGTH = 8U; /**< Max message length in bytes */ | ||
|
||
{% set fast_message = namespace(count = 0) %} | ||
{%- for message in messages %} | ||
{%- if message.cycle == "fast" %} | ||
static const constexpr unsigned int FAST_{{ message.sender | upper }}_{{ message.name | upper }}_FRAME_INDEX = {{ fast_message.count }}U; /**< Broadcast Manager {{ message.name | lower }} to Frame index mapping */ | ||
{%- set fast_message.count = fast_message.count + 1 %} | ||
{%- endif %} | ||
{%- endfor %} | ||
|
||
{% set medium_message = namespace(count = 0) %} | ||
{%- for message in messages %} | ||
{%- if message.cycle == "medium" %} | ||
static const constexpr unsigned int MEDIUM_{{ message.sender | upper }}_{{ message.name | upper }}_FRAME_INDEX = {{ medium_message.count }}U; /**< Broadcast Manager {{ message.name | lower }} to Frame index mapping */ | ||
{%- set medium_message.count = medium_message.count + 1 %} | ||
{%- endif %} | ||
{%- endfor %} | ||
|
||
{% set slow_message = namespace(count = 0) %} | ||
{%- for message in messages %} | ||
{%- if message.cycle == "slow" %} | ||
static const constexpr unsigned int SLOW_{{ message.sender | upper }}_{{ message.name | upper }}_FRAME_INDEX = {{ slow_message.count }}U; /**< Broadcast Manager {{ message.name | lower }} to Frame index mapping */ | ||
{%- set slow_message.count = slow_message.count + 1 %} | ||
{%- endif %} | ||
{%- endfor %} | ||
|
||
/** | ||
* @brief Fast cycle Broadcast Manager message for the Linux Kernel | ||
*/ | ||
struct { | ||
struct bcm_msg_head msg_head; /**< Broadcast Manager message head containing metadata */ | ||
struct can_frame frame[NUM_FAST_CYCLE_MESSAGES]; /**< CAN message frames that shall be scheduled for fast cycle */ | ||
} canFastCycleBCM; | ||
|
||
/** | ||
* @brief Medium cycle Broadcast Manager message for the Linux Kernel | ||
*/ | ||
struct { | ||
struct bcm_msg_head msg_head; /**< Broadcast Manager message head containing metadata */ | ||
struct can_frame frame[NUM_MEDIUM_CYCLE_MESSAGES]; /**< CAN message frames that shall be scheduled for medium cycle */ | ||
} canMediumCycleBCM; | ||
|
||
/** | ||
* @brief Slow cycle Broadcast Manager message for the Linux Kernel | ||
*/ | ||
struct { | ||
struct bcm_msg_head msg_head; /**< Broadcast Manager message head containing metadata */ | ||
struct can_frame frame[NUM_SLOW_CYCLE_MESSAGES]; /**< CAN message frames that shall be scheduled for slow cycle */ | ||
} canSlowCycleBCM; | ||
|
||
int m_bcmCanSocket; /**< The CAN schedulers Broadcast Manager socket FD */ | ||
std::atomic<bool> m_isConnected; /**< Boolean flag to track the CAN schedulers connection status */ | ||
|
||
/** | ||
* @brief Schedules all CAN data by updating the Broacast Manager socket | ||
* @details This function is called by startCanScheduler | ||
* This function shall initialize all CAN message values to 0 | ||
*/ | ||
void scheduleCanMessages(); | ||
|
||
public: | ||
/** | ||
* @brief Constructs a CanScheduler object | ||
* @details Initializes the CanScheduler. The constructor sets up internal variables | ||
*/ | ||
CanScheduler(); | ||
|
||
/** | ||
* @brief Starts the CAN scheduler and sets all messages to 0. Must only be called once | ||
* @details This function will connect to the Linux Broadcast Manager | ||
* This function must only be called once, and it will set all messages to 0 | ||
*/ | ||
void startCanScheduler(); | ||
|
||
{%- for message in messages %} | ||
{%- for signal in message.signals %} | ||
/** | ||
* @brief Update the CAN value for {{ message.name | lower }} {{ signal.name | lower }} | ||
* @param {{ signal.name | lower }}_value New value for the signal | ||
*/ | ||
void update_{{ message.name | lower }}_{{ signal.name | lower }}(uint{{ signal.length }}_t {{ signal.name | lower }}_value); | ||
{%- endfor %} | ||
{%- endfor %} | ||
}; | ||
|
||
/** @} */ |
Oops, something went wrong.