53 lines
1.4 KiB
C
53 lines
1.4 KiB
C
//
|
|
// Created by cfif on 05.04.2024.
|
|
//
|
|
#include <SystemDelayInterface.h>
|
|
#include "CanSpamReceiver.h"
|
|
#include "CmsisRtosThreadUtils.h"
|
|
#include "CanPorts.h"
|
|
|
|
void CanSpamReceiver_Init(tCanSpamReceiver *env,
|
|
tSerialPortFrameIO *ioCanFrame) {
|
|
|
|
env->ioCanFrame = ioCanFrame;
|
|
|
|
env->access = osMutexNew(NULL);
|
|
|
|
InitThreadAtrStatic(&env->thread.attr, "CanSpamReceiver", env->thread.controlBlock, env->thread.stack,
|
|
osPriorityNormal);
|
|
}
|
|
|
|
static void ListenCanSpamReceiver(tCanSpamReceiver *env) {
|
|
|
|
uint16_t recv = env->ioCanFrame->receive(env->ioCanFrame->env, PROTOCOL_CAN_RAW, (uint8_t *) &env->canFrame, 1,
|
|
1000);
|
|
|
|
if (recv == 0)
|
|
return;
|
|
|
|
if (osMutexAcquire(env->access, 100) == osOK) {
|
|
|
|
uint32_t id = env->canFrame.standard_id;
|
|
|
|
if (env->canFrame.id_type == FLEXCAN_ID_EXT) {
|
|
id = env->canFrame.extended_id;
|
|
}
|
|
|
|
uint32_t result = ccu_candb_Receive(&ccu_candb_rx, env->canFrame.data, id, env->canFrame.dlc);
|
|
|
|
osMutexRelease(env->access);
|
|
}
|
|
|
|
}
|
|
|
|
static _Noreturn void CanSpamReceiver_Thread(tCanSpamReceiver *env) {
|
|
for (;;) {
|
|
ListenCanSpamReceiver(env);
|
|
}
|
|
}
|
|
|
|
void CanSpamReceiver_StartThread(tCanSpamReceiver *env) {
|
|
if (!env->thread.id) {
|
|
env->thread.id = osThreadNew((osThreadFunc_t) (CanSpamReceiver_Thread), (void *) (env), &env->thread.attr);
|
|
}
|
|
} |