mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/CAN-Demo.git
synced 2025-09-29 00:37:33 +00:00
Working CAN sending on TACOS via user space
This commit is contained in:
43
App/Src/startup.cpp
Normal file
43
App/Src/startup.cpp
Normal 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
|
||||
|
42
App/Src/tasks/can_task.cpp
Normal file
42
App/Src/tasks/can_task.cpp
Normal 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
|
||||
|
Reference in New Issue
Block a user