fixed and adaptions
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
#include "fdcan.h"
|
||||
#include "CanDataHandler.h"
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
#include "CLSAddress.h"
|
||||
#include "firmware.pb.h"
|
||||
|
||||
// Define thread flags
|
||||
#define FLAG_FDCAN_RX_FIFO0 (1<<0)
|
||||
@@ -58,15 +59,6 @@ void CanDataTask_start() {
|
||||
|
||||
static FDCAN_RxHeaderTypeDef RxHeader;
|
||||
static uint8_t RxData[8];
|
||||
void CanDataTask_HandleFifo(uint32_t fifo) {
|
||||
while (HAL_FDCAN_GetRxFifoFillLevel(&hfdcan1, FDCAN_RX_FIFO0) > 0 ) {
|
||||
if (HAL_FDCAN_GetRxMessage(&hfdcan1, fifo, &RxHeader, RxData) != HAL_OK) {
|
||||
Error_Handler();
|
||||
} else {
|
||||
CanData_canFifo0RxCallback(RxHeader.Identifier,RxData, dlcDecode(RxHeader.DataLength));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Function for the task
|
||||
void CanDataTask_func(void *argument) {
|
||||
@@ -82,13 +74,37 @@ void CanDataTask_func(void *argument) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
if(HAL_FDCAN_ActivateNotification(&hfdcan1,FDCAN_IT_RX_FIFO0_NEW_MESSAGE | FDCAN_IT_RX_FIFO1_NEW_MESSAGE, 0) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
|
||||
// setup listening for heartbeats
|
||||
for (size_t i = 0; i < 16; i++)
|
||||
{
|
||||
CanData_regDataMsg(GENERATE_CLS_ADDRESS(CLS_CODE_STATUS, i, CLS_CH_STA_HEATBEAT));
|
||||
}
|
||||
|
||||
|
||||
|
||||
for(;;) {
|
||||
// wait for interrupt event on any fifo
|
||||
osThreadFlagsWait(FLAG_FDCAN_RX_FIFO0 | FLAG_FDCAN_RX_FIFO1, osFlagsWaitAny, osWaitForever);
|
||||
// check the fifos for data and handle it if nessessay
|
||||
CanDataTask_HandleFifo(FDCAN_RX_FIFO0);
|
||||
CanDataTask_HandleFifo(FDCAN_RX_FIFO1);
|
||||
while (HAL_FDCAN_GetRxFifoFillLevel(&hfdcan1, FDCAN_RX_FIFO0) > 0 ) {
|
||||
if (HAL_FDCAN_GetRxMessage(&hfdcan1, FDCAN_RX_FIFO0, &RxHeader, RxData) != HAL_OK) {
|
||||
Error_Handler();
|
||||
} else {
|
||||
CanData_canFifo0RxCallback(RxHeader.Identifier,RxData, dlcDecode(RxHeader.DataLength));
|
||||
}
|
||||
}
|
||||
while (HAL_FDCAN_GetRxFifoFillLevel(&hfdcan1, FDCAN_RX_FIFO1) > 0 ) {
|
||||
if (HAL_FDCAN_GetRxMessage(&hfdcan1, FDCAN_RX_FIFO1, &RxHeader, RxData) != HAL_OK) {
|
||||
Error_Handler();
|
||||
} else {
|
||||
CanData_canFifo1RxCallback(RxHeader.Identifier,RxData, dlcDecode(RxHeader.DataLength));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,4 +117,41 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
|
||||
void HAL_FDCAN_RxFifo1Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo1ITs) {
|
||||
// Notify the thread
|
||||
osThreadFlagsSet(CanDataTask_id, FLAG_FDCAN_RX_FIFO1);
|
||||
}
|
||||
|
||||
|
||||
void DataClbk_ResponseDeviceList(void* msg, uint32_t length) {
|
||||
// igored
|
||||
}
|
||||
|
||||
|
||||
#include "UsbDataHandler.h"
|
||||
ResponseDeviceList list;
|
||||
extern uint8_t gCLS_DEVICE_ADDRESS;
|
||||
void DataClbk_RequestDeviceList(void* msg, uint32_t length) {
|
||||
|
||||
// add yourself
|
||||
list.devices[list.devices_count].available = true;
|
||||
list.devices[list.devices_count].canid = GENERATE_CLS_ADDRESS(CLS_CODE_STATUS, gCLS_DEVICE_ADDRESS, CLS_CH_STA_HEATBEAT);
|
||||
list.devices[list.devices_count].device = gCLS_DEVICE_ADDRESS;
|
||||
list.devices[list.devices_count].counter = (osKernelGetTickCount()/500)%256;
|
||||
list.devices_count++;
|
||||
|
||||
for (size_t i = 0; i < 16; i++)
|
||||
{
|
||||
uint16_t canid = (GENERATE_CLS_ADDRESS(CLS_CODE_STATUS, i, CLS_CH_STA_HEATBEAT));
|
||||
const CanDataMessage * msg =CanData_getDataMessage(canid);
|
||||
if(msg) {
|
||||
if(msg->data_length > 0) {
|
||||
list.devices[list.devices_count].available = true;
|
||||
list.devices[list.devices_count].canid = canid;
|
||||
list.devices[list.devices_count].device = i;
|
||||
list.devices[list.devices_count].counter = msg->data[0];
|
||||
list.devices_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
USBDataResonse(&list, ResponseDeviceList_fields, UsbPackageType_RESPONSE_DEVICE_LIST);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user