mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-06-12 01:25:59 +00:00
CAN implementation for standard CAN
This commit is contained in:
parent
f0176bb2ed
commit
7147d6de83
@ -78,9 +78,7 @@ namespace sta
|
|||||||
return thread_ptr;
|
return thread_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool queueCanBusMsg(const CanDataMsg & msg, uint32_t timeout);
|
bool queueCanBusMsg(CanSysMsg & msg, uint32_t timeout);
|
||||||
|
|
||||||
bool queueCanBusMsg(const CanSysMsg & msg, uint32_t timeout);
|
|
||||||
} // namespace tacos
|
} // namespace tacos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <sta/config.hpp>
|
#include <sta/config.hpp>
|
||||||
#include <sta/rtos/thread.hpp>
|
#include <sta/rtos/thread.hpp>
|
||||||
|
#include <sta/rtos/queue.hpp>
|
||||||
|
#include <sta/rtos/system/can_bus.hpp>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup tacos_thread TACOS Thread
|
* @defgroup tacos_thread TACOS Thread
|
||||||
@ -126,6 +128,24 @@ namespace sta
|
|||||||
*/
|
*/
|
||||||
void sleep(uint32_t ticks);
|
void sleep(uint32_t ticks);
|
||||||
|
|
||||||
|
#ifdef STA_CAN_BUS_ENABLE
|
||||||
|
/**
|
||||||
|
* @brief Set the ID of the CAN bus this thread is associated with.
|
||||||
|
*
|
||||||
|
* @param canID
|
||||||
|
*/
|
||||||
|
void setCanID(uint32_t canID);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the ID of the CAN bus this thread is associated with.
|
||||||
|
*
|
||||||
|
* @return can ID
|
||||||
|
*/
|
||||||
|
uint32_t getCanID();
|
||||||
|
|
||||||
|
sta::RtosQueue<CanSysMsg> CAN_queue_;
|
||||||
|
#endif // STA_CAN_BUS_ENABLE
|
||||||
|
|
||||||
#ifdef STA_TACOS_WATCHDOG_ENABLED
|
#ifdef STA_TACOS_WATCHDOG_ENABLED
|
||||||
/**
|
/**
|
||||||
* @brief This macro wraps a given statement into waiting() and heartbeat() to make the code more readable.
|
* @brief This macro wraps a given statement into waiting() and heartbeat() to make the code more readable.
|
||||||
@ -191,6 +211,9 @@ namespace sta
|
|||||||
bool running_;
|
bool running_;
|
||||||
#ifdef STA_TACOS_WATCHDOG_ENABLED
|
#ifdef STA_TACOS_WATCHDOG_ENABLED
|
||||||
ThreadStatus status_;
|
ThreadStatus status_;
|
||||||
|
#endif // STA_TACOS_WATCHDOG_ENABLED
|
||||||
|
#ifdef STA_CAN_BUS_ENABLE
|
||||||
|
uint32_t canID_;
|
||||||
#endif // STA_TACOS_WATCHDOG_ENABLED
|
#endif // STA_TACOS_WATCHDOG_ENABLED
|
||||||
bool terminate_;
|
bool terminate_;
|
||||||
};
|
};
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <sta/tacos/can_bus.hpp>
|
#include <sta/tacos/can_bus.hpp>
|
||||||
#include <sta/debug/assert.hpp>
|
#include <sta/debug/assert.hpp>
|
||||||
|
#include <sta/tacos/manager.hpp>
|
||||||
|
|
||||||
// TODO fix this shit
|
// TODO fix this shit
|
||||||
extern CAN_HandleTypeDef hcan1;
|
extern CAN_HandleTypeDef hcan1;
|
||||||
namespace sta
|
namespace sta
|
||||||
@ -43,18 +45,6 @@ namespace sta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & STA_RTOS_CAN_FLAG_DATA_QUEUED)
|
|
||||||
{
|
|
||||||
// Take messages from queue until empty
|
|
||||||
CanDataMsg msg;
|
|
||||||
while (CanBus::_instance->getCanBusMsg(&msg, 0))
|
|
||||||
{
|
|
||||||
canBus_.send(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
//canBus_.tx_.processFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & STA_RTOS_CAN_FLAG_MSG_AVAIL)
|
if (flags & STA_RTOS_CAN_FLAG_MSG_AVAIL)
|
||||||
{
|
{
|
||||||
STA_DEBUG_PRINTLN("[event] CAN INT");
|
STA_DEBUG_PRINTLN("[event] CAN INT");
|
||||||
@ -68,11 +58,25 @@ namespace sta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synchronus message check
|
CanRxHeader rxHeader; //CAN Bus Receive Header
|
||||||
canBus_.processRx();
|
uint8_t canRX[8] = {0,0,0,0,0,0,0,0}; //CAN Bus Receive Buffer
|
||||||
|
|
||||||
|
canBusController_->receiveFrame(CAN_RX_FIFO0, &rxHeader, canRX);
|
||||||
|
|
||||||
|
// Create a CANSysMsg from the received data
|
||||||
|
CanSysMsg sysMsg;
|
||||||
|
sysMsg.header.sid = rxHeader.id.sid;
|
||||||
|
sysMsg.header.payloadLength = rxHeader.payloadLength;
|
||||||
|
std::memcpy(sysMsg.payload, canRX, rxHeader.payloadLength);
|
||||||
|
|
||||||
|
// Append to the correct thread's queue
|
||||||
|
for (std::shared_ptr<TacosThread> thread : Manager::instance()->getActiveThreads()){
|
||||||
|
if (thread->getCanID() == rxHeader.id.sid){
|
||||||
|
thread->CAN_queue_.put(sysMsg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Process ISOTP transmissions
|
|
||||||
canBus_.processTx();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CanBus::queueCanBusMsg(const CanDataMsg& msg, uint32_t timeout)
|
bool CanBus::queueCanBusMsg(const CanDataMsg& msg, uint32_t timeout)
|
||||||
|
@ -25,12 +25,8 @@ namespace sta
|
|||||||
{
|
{
|
||||||
Statemachine::instance()->requestTimedStateTransition(from, to, millis, lockout);
|
Statemachine::instance()->requestTimedStateTransition(from, to, millis, lockout);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool queueCanBusMsg(const CanDataMsg & msg, uint32_t timeout){
|
|
||||||
return CanBus::instance()->queueCanBusMsg(msg, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool queueCanBusMsg(const CanSysMsg & msg, uint32_t timeout){
|
bool queueCanBusMsg(CanSysMsg & msg, uint32_t timeout){
|
||||||
return CanBus::instance()->queueCanBusMsg(msg, timeout);
|
return CanBus::instance()->queueCanBusMsg(msg, timeout);
|
||||||
}
|
}
|
||||||
} // namespace tacos
|
} // namespace tacos
|
||||||
|
@ -27,6 +27,10 @@ namespace sta
|
|||||||
#ifdef STA_TACOS_WATCHDOG_ENABLED
|
#ifdef STA_TACOS_WATCHDOG_ENABLED
|
||||||
status_{ThreadStatus::STOPPED},
|
status_{ThreadStatus::STOPPED},
|
||||||
#endif // STA_TACOS_WATCHDOG_ENABLED
|
#endif // STA_TACOS_WATCHDOG_ENABLED
|
||||||
|
#ifdef STA_CAN_BUS_ENABLE
|
||||||
|
canID_{0},
|
||||||
|
CAN_queue_{STA_RTOS_CAN_BUS_QUEUE_LENGTH},
|
||||||
|
#endif // STA_CAN_BUS_ENABLE
|
||||||
terminate_{false}
|
terminate_{false}
|
||||||
{
|
{
|
||||||
STA_ASSERT(stack_size >= 0);
|
STA_ASSERT(stack_size >= 0);
|
||||||
@ -165,6 +169,16 @@ namespace sta
|
|||||||
|
|
||||||
TacosThread::~TacosThread(){}
|
TacosThread::~TacosThread(){}
|
||||||
|
|
||||||
|
#ifdef STA_CAN_BUS_ENABLE
|
||||||
|
void TacosThread::setCanID(uint32_t canID){
|
||||||
|
canID_ = canID;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t TacosThread::getCanID(){
|
||||||
|
return canID_;
|
||||||
|
}
|
||||||
|
#endif // STA_CAN_BUS_ENABLE
|
||||||
|
|
||||||
} // namespace tacos
|
} // namespace tacos
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user