From 6d1b8171a0f0c1ae99836c41bdfffa49e6dcfe61 Mon Sep 17 00:00:00 2001 From: JorgePerC Date: Wed, 29 Jan 2025 02:27:56 +0000 Subject: [PATCH] deleted can files --- inc/ControllerCAN.hpp | 116 ---------------------------------------- inc/ControllerFDCAN.hpp | 108 ------------------------------------- src/ControllerFDCAN.cpp | 109 ------------------------------------- 3 files changed, 333 deletions(-) delete mode 100644 inc/ControllerCAN.hpp delete mode 100644 inc/ControllerFDCAN.hpp delete mode 100644 src/ControllerFDCAN.cpp diff --git a/inc/ControllerCAN.hpp b/inc/ControllerCAN.hpp deleted file mode 100644 index 6f15780..0000000 --- a/inc/ControllerCAN.hpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * ControllerCAN.hpp - * - * Created on: April 12, 2024 - * Author: @JorgePerC - * - * For mor information about how to use this driver: - * um2217-description-of-stm32h7-hal-and-lowlayer-drivers-stmicroelectronics-1 - */ - -#ifndef ControllerCAN_HPP -#define ControllerCAN_HPP - -// ===== Includes ===== -#include "stm32f4xx_hal.h" - -// ===== Constants ===== - //TODO: CHECK SYNTAX FOR WRITING VALUES -#define CAN_ID_1 0x1U -#define CAN_ID_2 0x2U -#define CAN_ID_3 0x3U -#define CAN_ID_4 0x4U -#define CAN_ID_5 0x5U -#define CAN_ID_6 0x6U -#define CAN_ID_7 0x7U -#define CAN_ID_8 0x8U - -// Read information from a given motor - // The MSG is defined by - // FEEDBACK_ID + MotorID -#define FEEDBACK_ID 0x204 -#define FEEDBACK_ID_ALT 0x200 - -// Sent control output to motors -#define CONTROL_ID_1FF 0x1FF -#define CONTROL_ID_2FF 0x2FF -#define CONTROL_ID_200 0x200 - -// Read motor status -#define CONTROL_ANGLE_BEND 0x0 -#define CONTROL_ANGLE_LEND 0x1 - -#define CONTROL_SPEED_BEND 0x2 -#define CONTROL_SPEED_LEND 0x3 - -//TODO: SET AS TORQUE? -#define READ_CURRENT_BEND 0x4 -#define READ_CURRENT_LEND 0x5 - -#define READ_TEMP 0x6 -// Data Length Code 8 BYTES -#define RM_DLC 0x8 - -// ===== Structs for message ===== - -class ControllerFDCAN { -private: - -HAL_FDCAN_IsRxBufferMessageAvailable -HAL_FDCAN_IsTxBufferMessagePending -HAL_FDCAN_GetRxFifoFillLevel -HAL_FDCAN_GetTxFifoFreeLevel - - CAN_HandleTypeDef* hcan; - - CAN_RxHeaderTypeDef* RxHeader; - CAN_TxHeaderTypeDef* TxHeader; - - // Array buffer 8 bytes - uint8_t RxData[RM_DLC]; - //TODO: Define weather this is going to be done - // I chose this function will be a static parameter of each motor - uint8_t TxData[RM_DLC]; - - void readMessagePolling (); - void setChannelFilter(); - -public: - ControllerCAN(FDCAN_HandleTypeDef* handler); - - static void updateMessage(uint8_t* bufferArr, uint8_t motorId, uint16_t value); - - void getMotorInfo(uint8_t feedbackID, uint8_t motorId); - void getMotorStatus(); - void sendMessage (FDCAN_TxHeaderTypeDef* TxHeader, uint8_t* TxData); - - ~ControllerCAN(); -}; - -#endif /* ControllerCAN */ - -// ================== -/* -file:///Users/jperezch/Downloads/um2217-description-of-stm32h7-hal-and-lowlayer-drivers-stmicroelectronics.pdf - - - ============================================================================== - ##### Control functions ##### - ============================================================================== - [..] This section provides functions allowing to: - (+) HAL_CAN_Start : Start the CAN module - (+) HAL_CAN_Stop : Stop the CAN module - (+) HAL_CAN_RequestSleep : Request sleep mode entry. - (+) HAL_CAN_WakeUp : Wake up from sleep mode. - (+) HAL_CAN_IsSleepActive : Check is sleep mode is active. - (+) HAL_CAN_AddTxMessage : Add a message to the Tx mailboxes - and activate the corresponding - transmission request - (+) HAL_CAN_AbortTxRequest : Abort transmission request - (+) HAL_CAN_GetTxMailboxesFreeLevel : Return Tx mailboxes free level - (+) HAL_CAN_IsTxMessagePending : Check if a transmission request is - pending on the selected Tx mailbox - (+) HAL_CAN_GetRxMessage : Get a CAN frame from the Rx FIFO - (+) HAL_CAN_GetRxFifoFillLevel : Return Rx FIFO fill level - -*/ \ No newline at end of file diff --git a/inc/ControllerFDCAN.hpp b/inc/ControllerFDCAN.hpp deleted file mode 100644 index 02cb38d..0000000 --- a/inc/ControllerFDCAN.hpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * ControllerCAN.hpp - * - * Created on: April 12, 2024 - * Author: @JorgePerC - */ - -#ifndef ControllerCAN_HPP -#define ControllerCAN_HPP - -// ===== Includes ===== -#include "stm32f4xx_hal.h" - -// ===== Constants ===== - //TODO: CHECK SYNTAX FOR WRITING VALUES -#define CAN_ID_1 0x1U -#define CAN_ID_2 0x2U -#define CAN_ID_3 0x3U -#define CAN_ID_4 0x4U -#define CAN_ID_5 0x5U -#define CAN_ID_6 0x6U -#define CAN_ID_7 0x7U -#define CAN_ID_8 0x8U - -// Read information from a given motor - // The MSG is defined by - // FEEDBACK_ID + MotorID -#define FEEDBACK_ID 0x204 -#define FEEDBACK_ID_ALT 0x200 - -// Sent control output to motors -#define CONTROL_ID_1FF 0x1FF -#define CONTROL_ID_2FF 0x2FF -#define CONTROL_ID_200 0x200 - -// Read motor status -#define CONTROL_ANGLE_BEND 0x0 -#define CONTROL_ANGLE_LEND 0x1 - -#define CONTROL_SPEED_BEND 0x2 -#define CONTROL_SPEED_LEND 0x3 - -//TODO: SET AS TORQUE? -#define READ_CURRENT_BEND 0x4 -#define READ_CURRENT_LEND 0x5 - -#define READ_TEMP 0x6 -// Data Length Code 8 BYTES -#define RM_DLC 0x8 - -// ===== Structs for message ===== - -class ControllerCAN { -private: - - CAN_HandleTypeDef* hcan; - - CAN_RxHeaderTypeDef* RxHeader; - CAN_TxHeaderTypeDef* TxHeader; - - // Array buffer 8 bytes - uint8_t RxData[RM_DLC]; - //TODO: Define weather this is going to be done - // I chose this function will be a static parameter of each motor - uint8_t TxData[RM_DLC]; - - void readMessagePolling (); - void setChannelFilter(); - -public: - ControllerCAN(CAN_HandleTypeDef* handler); - - static void updateMessage(uint8_t* bufferArr, uint8_t motorId, uint16_t value); - - void getMotorInfo(uint8_t feedbackID, uint8_t motorId); - void getMotorStatus(); - void sendMessage (CAN_TxHeaderTypeDef* TxHeader, uint8_t* TxData); - - ~ControllerCAN(); -}; - -#endif /* ControllerCAN */ - -// ================== -/* -file:///Users/jperezch/Downloads/um2217-description-of-stm32h7-hal-and-lowlayer-drivers-stmicroelectronics.pdf - - - ============================================================================== - ##### Control functions ##### - ============================================================================== - [..] This section provides functions allowing to: - (+) HAL_CAN_Start : Start the CAN module - (+) HAL_CAN_Stop : Stop the CAN module - (+) HAL_CAN_RequestSleep : Request sleep mode entry. - (+) HAL_CAN_WakeUp : Wake up from sleep mode. - (+) HAL_CAN_IsSleepActive : Check is sleep mode is active. - (+) HAL_CAN_AddTxMessage : Add a message to the Tx mailboxes - and activate the corresponding - transmission request - (+) HAL_CAN_AbortTxRequest : Abort transmission request - (+) HAL_CAN_GetTxMailboxesFreeLevel : Return Tx mailboxes free level - (+) HAL_CAN_IsTxMessagePending : Check if a transmission request is - pending on the selected Tx mailbox - (+) HAL_CAN_GetRxMessage : Get a CAN frame from the Rx FIFO - (+) HAL_CAN_GetRxFifoFillLevel : Return Rx FIFO fill level - -*/ \ No newline at end of file diff --git a/src/ControllerFDCAN.cpp b/src/ControllerFDCAN.cpp deleted file mode 100644 index 4ff85e4..0000000 --- a/src/ControllerFDCAN.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * ControllerCAN.cpp - * - * Created on: April 12, 2024 - * Author: @JorgePerC - */ -#include "ControllerFDCAN.hpp" - -// Remember MSB: Most significant bit - -// This is a function that will be called in case something failed -// TODO: make it global but put it somewhere usefull -static void Error_Handler(void) { - while (1) { - // comment - for (int i = 0; i < 10; i++) { - i *= 1; - } - } -} - -ControllerCAN::ControllerCAN(FDCAN* handler) { - // Check there are no duplicate IDs - hcan = handler; - // Turn off interruption mode - // HAL_NVIC_DisableIRQ(CAN2_RX0_IRQn); - // HAL_NVIC_DisableIRQ(CAN1_RX0_IRQn); - - // HAL_CAN_DeactivateNotification(hcan, ); - // Check that the handler has been initialized - if (!HAL_CAN_GetState(hcan) != CAN_INITSTATUS_SUCCESS) { - Error_Handler(); - } -} - -void ControllerCAN::updateMessage(uint8_t* bufferArr, uint8_t motorId, uint16_t value) { - // This should only be updated from the same type of motor. - // Also, if the IDs are in the ranges 1-4 || 5-7 - // TODO: limit the resource to comply - // UPDT: That's why i'm passing as an argument the pointer to the buffer - // see if we can return it, instead of passing it as a reference. - - // Set postion to be written - uint8_t writePos = motorId == CAN_ID_4 ? 6 : (motorId % 4 - 1) * 2; - - bufferArr[writePos] = value; -} - -void ControllerCAN::sendMessage(CAN_TxHeaderTypeDef* TxHeader, uint8_t* TxData) { - // The example never actually sets a value to the mailbox - // if (HAL_CAN_AddTxMessage(&CanHandle, &TxHeader, TxData, &TxMailbox) != HAL_OK) - // Prior to sending the message, we must - // check that all prev messages have been sent - // we do so wit the tx boxes - uint32_t selectedMailBox = NULL; - // Monitor the Tx mailboxes availability until at least one Tx mailbox is free - if ((hcan->Instance->TSR & CAN_TSR_TME0) != 0U) { - selectedMailBox = CAN_TX_MAILBOX0; - } else if ((hcan->Instance->TSR & CAN_TSR_TME1) != 0U) { - selectedMailBox = CAN_TX_MAILBOX1; - } else if ((hcan->Instance->TSR & CAN_TSR_TME2) != 0U) { - selectedMailBox = CAN_TX_MAILBOX2; - } - if (selectedMailBox != NULL) { - if (HAL_CAN_AddTxMessage(hcan, TxHeader, TxData, &selectedMailBox) != HAL_OK) { - // uart_buf_len = sprintf(uart_buf, "Error"); - // HAL_UART_Transmit(&huart3, (uint8_t *)uart_buf, uart_buf_len, HAL_MAX_DELAY); - Error_Handler(); - } - } - // Timeout so that is has time to send the data - // HAL_Delay(10); -} - -/* This method is configured to read messages through polling. -Note that the implementation is rather different from using interrupts -Since these functions NEED TO BE CONSTANTLY CALLED. -On one side, this is easier, since will be using RTOS later -*/ -void ControllerCAN::readMessagePolling() { - // TODO: How to pass it to the motors? - - // Check there's a message on the fifo - if (HAL_CAN_GetRxFifoFillLevel(hcan, CAN_FILTER_FIFO0) > 1) { - /* Get RX message */ - if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, RxHeader, RxData) != HAL_OK) { - /* Reception Error */ - Error_Handler(); - } - } - // Timeout so that is has time to read the data - - // HAL_Delay(10); -} - -// TODO: Complete -void ControllerCAN::getMotorInfo(uint8_t feedbackID, uint8_t motorId) { - // Decode message - RxHeader->StdId = FEEDBACK_ID + motorId; -} - -void ControllerCAN::setChannelFilter() { - // TODO: FIGURE OUT HOW THIS WORKS - // Use interrtuptions or no - // HAL_CAN_ActivateNotification() - - // // Filter messages and freq - // HAL_CAN_ConfigFilter(); -}