mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/CAN-Demo.git
synced 2025-06-10 02:55:59 +00:00
Addapted to reduced CAN task
This commit is contained in:
parent
29c12b00cd
commit
7732fa2823
@ -5,7 +5,7 @@
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1080687771005896909" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-614993993494983921" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
@ -16,7 +16,7 @@
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1080687771005896909" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-614993993494983921" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
|
@ -1,5 +1,5 @@
|
||||
635E684B79701B039C64EA45C3F84D30=44DBEC1DE4EBA9B0485911FBE58BFC80
|
||||
66BE74F758C12D739921AEA421D593D3=3
|
||||
8DF89ED150041C4CBC7CB9A9CAA90856=84EF3C290D485BA5E95DA5C0811FD966
|
||||
DC22A860405A8BF2F2C095E5B6529F12=84EF3C290D485BA5E95DA5C0811FD966
|
||||
8DF89ED150041C4CBC7CB9A9CAA90856=7B5B92F1162457C6ECACD202698061B0
|
||||
DC22A860405A8BF2F2C095E5B6529F12=3C8525AE6BF206AA629BF4979058680C
|
||||
eclipse.preferences.version=1
|
||||
|
55
.vscode/settings.json
vendored
Normal file
55
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"algorithm": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"cctype": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"exception": "cpp",
|
||||
"functional": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"ios": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"iterator": "cpp",
|
||||
"limits": "cpp",
|
||||
"list": "cpp",
|
||||
"memory": "cpp",
|
||||
"new": "cpp",
|
||||
"ostream": "cpp",
|
||||
"set": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"utility": "cpp",
|
||||
"vector": "cpp",
|
||||
"xfacet": "cpp",
|
||||
"xhash": "cpp",
|
||||
"xiosbase": "cpp",
|
||||
"xlocale": "cpp",
|
||||
"xlocinfo": "cpp",
|
||||
"xlocnum": "cpp",
|
||||
"xmemory": "cpp",
|
||||
"xstddef": "cpp",
|
||||
"xstring": "cpp",
|
||||
"xtr1common": "cpp",
|
||||
"xtree": "cpp",
|
||||
"xutility": "cpp"
|
||||
}
|
||||
}
|
@ -29,7 +29,7 @@
|
||||
#define STA_RTOS_SYSTEM_EVENTS_ENABLE
|
||||
// #define STA_RTOS_SYSTEM_WATCHDOG_ENABLE
|
||||
// #define STA_RTOS_WATCHDOG_ENABLE
|
||||
// #define STA_CAN_BUS_ENABLE
|
||||
#define STA_CAN_BUS_ENABLE
|
||||
|
||||
// Uses the default configuration for TACOS.
|
||||
#include<sta/tacos/configs/default.hpp>
|
||||
|
@ -15,18 +15,12 @@ namespace demo
|
||||
{
|
||||
class CanTask : public sta::tacos::TacosThread {
|
||||
public:
|
||||
CanTask(const char* name, CAN_HandleTypeDef * handle);
|
||||
CanTask(const char* name, uint32_t canID);
|
||||
|
||||
void init() override;
|
||||
|
||||
void func() override;
|
||||
|
||||
void unpackValues(uint8_t packedByte, uint8_t* type_id, uint8_t* sensor_ID, uint8_t* value, uint8_t* include);
|
||||
private:
|
||||
|
||||
uint8_t payload[8];
|
||||
sta::STM32CanController canController;
|
||||
sta::CanTxHeader txHeader;
|
||||
};
|
||||
} // namespace demo
|
||||
|
||||
|
@ -10,6 +10,9 @@
|
||||
|
||||
#include <sta/tacos/thread.hpp>
|
||||
#include <sta/devices/stm32/can.hpp>
|
||||
#include <sta/rtos/mutex.hpp>
|
||||
#include <sta/MAX31855.hpp>
|
||||
#include <sta/devices/stm32/bus/spi.hpp>
|
||||
#include <gpio.h>
|
||||
#include <spi.h>
|
||||
|
||||
@ -30,7 +33,7 @@ namespace demo
|
||||
sta::STM32SPI* spi2;
|
||||
sta::STM32SPIDevice* device_;
|
||||
|
||||
sta::MAX31855 tc*;
|
||||
sta::MAX31855* tc;
|
||||
|
||||
};
|
||||
} // namespace demo
|
||||
|
@ -8,11 +8,11 @@
|
||||
#include <sta/debug/debug.hpp>
|
||||
#include <tasks/can_task.hpp>
|
||||
#include <tasks/thermo.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 <sta/tacos.hpp>
|
||||
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -32,8 +32,7 @@ namespace sta
|
||||
// ###### 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});
|
||||
Manager::instance()->registerThread(std::make_shared<demo::ThermoTask>(), {0});
|
||||
Manager::instance()->registerThread(std::make_shared<demo::CanTask>("CAN test", 0x22), {ALL_STATES});
|
||||
|
||||
STA_DEBUG_PRINTF("The answer to everything is %d", 42);
|
||||
|
||||
|
@ -9,102 +9,36 @@
|
||||
#include <sta/debug/debug.hpp>
|
||||
#include <sta/rtos/debug/heap_stats.hpp>
|
||||
#include "can.h"
|
||||
#include <sta/tacos.hpp>
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
namespace demo
|
||||
{
|
||||
CanTask::CanTask(const char* name, CAN_HandleTypeDef * handle)
|
||||
: TacosThread(name, osPriorityNormal), canController(handle)
|
||||
CanTask::CanTask(const char* name, uint32_t canID)
|
||||
: TacosThread(name, osPriorityNormal)
|
||||
{
|
||||
|
||||
setCanID(canID);
|
||||
}
|
||||
|
||||
void CanTask::init()
|
||||
{
|
||||
|
||||
canController.start();
|
||||
|
||||
txHeader.id.format = sta::CanIdFormat::STD; // Set to EXT for extended ID
|
||||
txHeader.id.sid = 0x040; // 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()
|
||||
{
|
||||
//STA_DEBUG_HEAP_STATS();
|
||||
canController.sendFrame(txHeader, payload);
|
||||
//STA_DEBUG_HEAP_STATS();
|
||||
STA_DEBUG_PRINTLN("Can Task awaiting message");
|
||||
if (CAN_queue_.available() > 0)
|
||||
{
|
||||
// Receiving message
|
||||
CanSysMsg msg;
|
||||
CAN_queue_.get(&msg);
|
||||
STA_DEBUG_PRINTLN("Can Task received message");
|
||||
|
||||
CAN_RxHeaderTypeDef rxHeader; //CAN Bus Receive Header
|
||||
uint8_t canRX[8] = {0,0,0,0,0,0,0,0}; //CAN Bus Receive Buffer
|
||||
|
||||
STA_DEBUG_PRINTLN("WAITING");
|
||||
HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &rxHeader, canRX);
|
||||
|
||||
uint8_t type_id, sensor_ID, value, include;
|
||||
|
||||
unpackValues(canRX[0], &type_id, &sensor_ID, &value, &include);
|
||||
|
||||
if (type_id == 0){
|
||||
if (sensor_ID == 1){
|
||||
|
||||
STA_DEBUG_PRINTLN("Relay 1 triggered");
|
||||
if(value == 1){
|
||||
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2, GPIO_PIN_SET);
|
||||
} else if(value == 0){
|
||||
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2, GPIO_PIN_RESET);
|
||||
// Sending it back
|
||||
sta::tacos::queueCanBusMsg(msg, 0);
|
||||
STA_DEBUG_PRINTLN("Can Task sent message");
|
||||
}
|
||||
|
||||
}else if (sensor_ID == 2){
|
||||
|
||||
STA_DEBUG_PRINTLN("Relay 2 triggered");
|
||||
if(value == 1){
|
||||
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1, GPIO_PIN_SET);
|
||||
} else if(value == 0){
|
||||
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1, GPIO_PIN_RESET);
|
||||
}
|
||||
}else if (sensor_ID == 3){
|
||||
|
||||
STA_DEBUG_PRINTLN("Relay 3 triggered");
|
||||
if(value == 1){
|
||||
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_0, GPIO_PIN_SET);
|
||||
} else if(value == 0){
|
||||
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_0, GPIO_PIN_RESET);
|
||||
}
|
||||
}else if (sensor_ID == 4){
|
||||
|
||||
STA_DEBUG_PRINTLN("Relay 4 triggered");
|
||||
if(value == 1){
|
||||
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3, GPIO_PIN_SET);
|
||||
} else if(value == 0){
|
||||
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3, GPIO_PIN_RESET);
|
||||
}
|
||||
}else if (sensor_ID == 5){
|
||||
|
||||
STA_DEBUG_PRINTLN("Relay 5 triggered");
|
||||
if(value == 1){
|
||||
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_6, GPIO_PIN_SET);
|
||||
} else if(value == 0){
|
||||
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_6, GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
HAL_Delay(1000);
|
||||
}
|
||||
|
||||
void CanTask::unpackValues(uint8_t packedByte, uint8_t* type_id, uint8_t* sensor_ID, uint8_t* value, uint8_t* include) {
|
||||
*type_id = (packedByte >> 6) & 0x03; // Extracting two bits for type_id
|
||||
*sensor_ID = (packedByte >> 3) & 0x07; // Extracting three bits for sensorID
|
||||
*include = (packedByte >> 2) & 0x01; // Extracting the flag for included value
|
||||
*value = (packedByte >> 1) & 0x01; // Extracting one bit for value
|
||||
}
|
||||
} // namespace demo
|
||||
|
||||
|
@ -28,10 +28,10 @@ namespace demo
|
||||
void ThermoTask::init()
|
||||
{
|
||||
mutex = new sta::RtosMutex("spi2");
|
||||
spi2 = new sta::STM32SPI(&hspi2, 16000000, &mutex);
|
||||
spi2 = new sta::STM32SPI(&hspi2, 16000000, mutex);
|
||||
device_ = new sta::STM32SPIDevice(spi2, &cs_pin);
|
||||
|
||||
tc = new sta::MAX31855(&device_); //create driver object
|
||||
tc = new sta::MAX31855(device_); //create driver object
|
||||
}
|
||||
|
||||
void ThermoTask::func()
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 16b2ed5a20df1c04b9bbcf5e12101d5e822e45d2
|
||||
Subproject commit 7147d6de8308110eace178b11ab88548ca29177a
|
Loading…
x
Reference in New Issue
Block a user