Working CAN sending on TACOS via user space

This commit is contained in:
CarlWachter
2023-12-10 14:59:05 +01:00
parent 98ecffac48
commit af703eaea3
168 changed files with 45744 additions and 485 deletions

BIN
App/.DS_Store vendored Normal file

Binary file not shown.

BIN
App/Inc/.DS_Store vendored Normal file

Binary file not shown.

41
App/Inc/sta/config.hpp Normal file
View File

@@ -0,0 +1,41 @@
/*
* Configuration file for STA-Core.
*
* Created on: Aug 30, 2023
* Author: Dario
*/
#ifndef INC_STA_CONFIG_HPP_
#define INC_STA_CONFIG_HPP_
#include <sta/devices/stm32/mcu/common.hpp>
// Doesn't really do too much right now. Has to be added for successful compilation.
#define STA_PRINTF_USE_STDLIB
#define STA_MCU_LITTLE_ENDIAN
#define STA_PLATFORM_STM32
// Enable debug serial output and assertions.
#define STA_ASSERT_FORCE
#define STA_DEBUGGING_ENABLED
// Activate the timer for microsecond delays.
// #define STA_STM32_DELAY_ENABLE
// #define STA_STM32_DELAY_US_TIM htim1
// Settings for the rtos-utils
#define STA_RTOS_SYSTEM_EVENTS_ENABLE
// #define STA_RTOS_SYSTEM_WATCHDOG_ENABLE
// #define STA_RTOS_WATCHDOG_ENABLE
// Settings for TACOS
#define STA_TACOS_MANAGER_PRIORITY osPriorityNormal
#define STA_TACOS_STATEMACHINE_PRIORITY osPriorityNormal
// Statemachine settings. Here, we only have a single state which is also the initial state.
#define STA_TACOS_NUM_STATES 3
#define STA_TACOS_INITIAL_STATE 0
#endif /* INC_STA_CONFIG_HPP_ */

View File

@@ -0,0 +1,32 @@
/*
* can_task.hpp
*
* Created on: 10 Dec 2023
* Author: Carl
*/
#ifndef INC_TASKS_CANTASK_HPP_
#define INC_TASKS_CANTASK_HPP_
#include <sta/tacos/thread.hpp>
#include <sta/devices/stm32/can.hpp>
namespace demo
{
class CanTask : public sta::tacos::TacosThread {
public:
CanTask(const char* name, CAN_HandleTypeDef * handle);
void init() override;
void func() override;
private:
uint8_t payload[8];
sta::STM32CanController canController;
sta::CanTxHeader txHeader;
};
} // namespace demo
#endif /* INC_TASKS_CANTASK_HPP_ */

43
App/Src/startup.cpp Normal file
View File

@@ -0,0 +1,43 @@
/*
* printable.cpp
*
* Created on: Aug 30, 2023
* Author: Dario
*/
#include <sta/tacos/startup.hpp>
#include <sta/debug/debug.hpp>
#include <tasks/can_task.hpp>
#include <sta/tacos/manager.hpp>
#include <sta/tacos/statemachine.hpp>
#include <sta/devices/stm32/gpio_pin.hpp>
#include <sta/rtos/debug/heap_stats.hpp>
#include <memory>
extern CAN_HandleTypeDef hcan1;
namespace sta
{
namespace tacos
{
void onStatemachineInit()
{
}
void onManagerInit()
{
// ###### Register different threads for different states here. ######
// The dummy task runs for state 0.
Manager::instance()->registerThread(std::make_shared<demo::CanTask>("CAN SPAM", &hcan1), {0});
STA_DEBUG_PRINTF("The answer to everything is %d", 42);
STA_DEBUG_HEAP_STATS();
}
} // namespace tacos
} // namespace sta

View File

@@ -0,0 +1,42 @@
/*
* can_task.cpp
*
* Created on: 10 Dec 2023
* Author: Carl
*/
#include <tasks/can_task.hpp>
#include <sta/debug/debug.hpp>
#include <cmsis_os2.h>
namespace demo
{
CanTask::CanTask(const char* name, CAN_HandleTypeDef * handle)
: TacosThread(name, osPriorityNormal), canController(handle)
{
}
void CanTask::init()
{
canController.start();
txHeader.id.format = sta::CanIdFormat::STD; // Set to EXT for extended ID
txHeader.id.sid = 0x30; // Set the standard ID or extended ID
txHeader.payloadLength = 8; // Set the payload length (max 8 bytes)
// Create your message payload
for (int i = 0; i < 8; ++i) {
payload[i] = i + 1;
}
}
void CanTask::func()
{
canController.sendFrame(txHeader, payload);
HAL_Delay(1000);
}
} // namespace demo