From 49a0e4abcda36876a9ba665b6cef1890e32d628f Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Mon, 22 Jan 2024 20:58:28 +0000 Subject: [PATCH] removing extern var --- src/gd/can2b/CAN.cpp | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/src/gd/can2b/CAN.cpp b/src/gd/can2b/CAN.cpp index 9edd16b..ab2ced1 100644 --- a/src/gd/can2b/CAN.cpp +++ b/src/gd/can2b/CAN.cpp @@ -14,14 +14,12 @@ uint16_t GD_CAN::pinRX_; uint16_t GD_CAN::pinTX_; uint16_t GD_CAN::pinSHDN_; -extern uint32_t txState; uint16_t can_prescaler; int can_bitrate; uint8_t can_tseg1; uint8_t can_tseg2; uint8_t can_sjw; - GD_CAN::GD_CAN(uint16_t pinRX, uint16_t pinTX, uint16_t pinSHDN) : filter_(CanFilter(FilterType::ACCEPT_ALL)), started_(false) { hcan_ = CAN0; @@ -39,13 +37,9 @@ GD_CAN::GD_CAN(uint16_t pinRX, uint16_t pinTX, uint16_t pinSHDN) : filter_(CanFi // gpio_init(GPIOB, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_8); // gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9); - // pin_function((PinName)GD_CAN::pinRX_, pinmap_function((PinName)GD_CAN::pinRX_, PinMap_CAN_RD)); // pin_function((PinName)GD_CAN::pinTX_, pinmap_function((PinName)GD_CAN::pinTX_, PinMap_CAN_TD)); - - - // // Clear bits 13 and 14 first // AFIO_PCF0 &= ~(AFIO_PCF0_CAN0_REMAP_BIT_13 | AFIO_PCF0_CAN0_REMAP_BIT_14); @@ -92,23 +86,22 @@ bool GD_CAN::begin(int bitrate) gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9); gpio_pin_remap_config(GPIO_CAN_PARTIAL_REMAP, ENABLE); - uint32_t clockFreq = rcu_clock_freq_get(CK_APB1); CanTiming timing = solveCanTiming(clockFreq, bitrate); // nvic_irq_enable(USBD_LP_CAN0_RX0_IRQn, 3, 0); can_struct_para_init(CAN_INIT_STRUCT, &can_parameter); - + // can_parameter.resync_jump_width=CAN_BT_SJW_1TQ; - can_parameter.time_segment_1=CAN_BT_BS1_14TQ; - can_parameter.time_segment_2=CAN_BT_BS2_1TQ; - can_parameter.prescaler=15; - - can_parameter.resync_jump_width = (uint8_t) timing.sjw - 1; - can_parameter.time_segment_1 = (uint8_t) (timing.tseg1 - 1); - can_parameter.time_segment_2 = (uint8_t) (timing.tseg2 - 1); - can_parameter.prescaler = (uint16_t) timing.prescaler; + can_parameter.time_segment_1 = CAN_BT_BS1_14TQ; + can_parameter.time_segment_2 = CAN_BT_BS2_1TQ; + can_parameter.prescaler = 15; + + can_parameter.resync_jump_width = (uint8_t)timing.sjw - 1; + can_parameter.time_segment_1 = (uint8_t)(timing.tseg1 - 1); + can_parameter.time_segment_2 = (uint8_t)(timing.tseg2 - 1); + can_parameter.prescaler = (uint16_t)timing.prescaler; // working_mode seems badly named, but it's the only way to set loopback mode can_parameter.working_mode = mode == CAN_LOOPBACK ? CAN_LOOPBACK_MODE : CAN_NORMAL_MODE; @@ -160,7 +153,6 @@ void GD_CAN::applyFilter() filterMaskHigh = filter_.getMask() << 5; filterIdLow = 0x0000; filterMaskLow = 0x0000; - } else if (filter_.getType() == FilterType::MASK_EXTENDED) { @@ -201,7 +193,6 @@ void GD_CAN::applyFilter() can_struct_para_init(CAN_FILTER_STRUCT, &can_filter); - can_filter.filter_number = (hcan_ == CAN0) ? 0 : 15; can_filter.filter_mode = CAN_FILTERMODE_MASK; can_filter.filter_bits = CAN_FILTERBITS_32BIT; @@ -216,10 +207,8 @@ void GD_CAN::applyFilter() // todo: support interrupt approach (alternative to polling) // can_interrupt_enable(hcan_, CAN_INT_RFNE0 | CAN_INT_TME); - } - int GD_CAN::write(CanMsg const &txMsg) { #ifdef CAN_DEBUG @@ -244,7 +233,6 @@ int GD_CAN::write(CanMsg const &txMsg) return logStatus('t', can_message_transmit(hcan_, &txHeader_)); - } CanMsg GD_CAN::read() @@ -254,7 +242,6 @@ CanMsg GD_CAN::read() can_message_receive(hcan_, CAN_FIFO0, &rxHeader_); can_error_enum err = can_error_get(hcan_); - txState = (uint32_t) can_transmit_states(hcan_, CAN_FIFO0); CanMsg const rxMsg( (rxHeader_.rx_ff == CAN_FF_EXTENDED) ? CanExtendedId(rxHeader_.rx_efid, rxHeader_.rx_ft == CAN_FT_REMOTE) : CanStandardId(rxHeader_.rx_sfid, rxHeader_.rx_ft == CAN_FT_REMOTE), @@ -279,7 +266,6 @@ void CAN0_RX0_IRQHandler(void) can_receive_message_struct receive_message; memset(&receive_message, 0, sizeof(receive_message)); can_message_receive(CAN0, CAN_FIFO0, &receive_message); - } CanStatus GD_CAN::logStatus(char op, uint32_t status)