diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index ee8c24e..b6fd953 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -77,8 +77,12 @@ void can1_callback(CAN_HandleTypeDef *hcan) new_msg.len = rx_header.DLC; new_msg.id = rx_header.StdId; - queue_and_set_flag(can_inbound_queue, &new_msg, can_receive_thread, - NEW_CAN_MSG_FLAG); + //queue_and_set_flag(can_inbound_queue, &new_msg, can_receive_thread, + // NEW_CAN_MSG_FLAG); + + /* Print Callback Messages */ + if (new_msg.id == 2) + printf("Callback: %s", new_msg.data); } int8_t queue_can_msg(can_msg_t msg) @@ -102,32 +106,35 @@ void vCanDispatch(void *pv_params) fault_data_t fault_data = { .id = CAN_DISPATCH_FAULT, .severity = DEFCON1 }; - can_msg_t msg_from_queue; - HAL_StatusTypeDef msg_status; + can_msg_t msg_from_queue = { + .id = 0x002, + .len = 4, + .data = { 69 } + }; + HAL_StatusTypeDef msg_status; CAN_HandleTypeDef *hcan = (CAN_HandleTypeDef *)pv_params; for (;;) { - osThreadFlagsWait(CAN_DISPATCH_FLAG, osFlagsWaitAny, - osWaitForever); - /* Send CAN message */ - while (osMessageQueueGet(can_outbound_queue, &msg_from_queue, - NULL, 0U) == osOK) { - /* Wait if CAN outbound queue is full */ - while (HAL_CAN_GetTxMailboxesFreeLevel(hcan) == 0) { - osDelay(1); - } - - msg_status = can_send_msg(can1, &msg_from_queue); - - if (msg_status == HAL_ERROR) { - fault_data.diag = "Failed to send CAN message"; - queue_fault(&fault_data); - } else if (msg_status == HAL_BUSY) { - fault_data.diag = "Outbound mailbox full!"; - queue_fault(&fault_data); - } + osDelay(500); + + /* Wait if CAN outbound queue is full */ + while (HAL_CAN_GetTxMailboxesFreeLevel(hcan) == 0) { + osDelay(1); } + + msg_status = can_send_msg(can1, &msg_from_queue); + + if (msg_status == HAL_ERROR) { + fault_data.diag = "Failed to send CAN message"; + queue_fault(&fault_data); + } else if (msg_status == HAL_BUSY) { + fault_data.diag = "Outbound mailbox full!"; + queue_fault(&fault_data); + } + + /* Print Dispatch Messages */ + printf("Dispatch: %s", msg_from_queue.data); } } @@ -140,26 +147,15 @@ const osThreadAttr_t can_receive_attributes = { void vCanReceive(void *pv_params) { - dti_t *mc = (dti_t *)pv_params; + //dti_t *mc = (dti_t *)pv_params; can_msg_t msg; for (;;) { - osThreadFlagsWait(NEW_CAN_MSG_FLAG, osFlagsWaitAny, - osWaitForever); - while (osOK == - osMessageQueueGet(can_inbound_queue, &msg, 0U, 0U)) { - switch (msg.id) { - /* Messages Relevant to Motor Controller */ - case DTI_CANID_ERPM: - dti_record_rpm(mc, msg); - break; - case BMS_DCL_MSG: - handle_dcl_msg(); - break; - default: - break; - } + osThreadFlagsWait(NEW_CAN_MSG_FLAG, osFlagsWaitAny, osWaitForever); + while (osOK == osMessageQueueGet(can_inbound_queue, &msg, 0U, 0U)) { + /* Print Receive Messages */ + printf("Recieve: %s", msg.data); } } } \ No newline at end of file diff --git a/Core/Src/main.c b/Core/Src/main.c index 9ddd550..ffea953 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -86,15 +86,15 @@ osMessageQueueId_t imu_queue; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); -static void MX_GPIO_Init(void); -static void MX_DMA_Init(void); +/*static void MX_GPIO_Init(void); +static void MX_DMA_Init(void);*/ static void MX_CAN1_Init(void); -static void MX_I2C1_Init(void); +/*static void MX_I2C1_Init(void); static void MX_I2C2_Init(void); -static void MX_ADC1_Init(void); +static void MX_ADC1_Init(void);*/ static void MX_USART3_UART_Init(void); -static void MX_ADC3_Init(void); -static void MX_IWDG_Init(void); +/*static void MX_ADC3_Init(void); +static void MX_IWDG_Init(void);*/ void StartDefaultTask(void *argument); /* USER CODE BEGIN PFP */ @@ -139,44 +139,44 @@ int main(void) /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + //HAL_Init(); /* USER CODE BEGIN Init */ - HAL_Delay(500); + //HAL_Delay(500); /* USER CODE END Init */ /* Configure the system clock */ - SystemClock_Config(); + //SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); + /*MX_GPIO_Init(); + MX_DMA_Init();*/ MX_CAN1_Init(); - MX_I2C1_Init(); + /*MX_I2C1_Init(); MX_I2C2_Init(); - MX_ADC1_Init(); + MX_ADC1_Init();*/ MX_USART3_UART_Init(); - MX_ADC3_Init(); + /*MX_ADC3_Init(); MX_IWDG_Init(); - /* USER CODE BEGIN 2 */ + USER CODE BEGIN 2 - /* Create Interfaces to Represent Relevant Hardware */ - mpu_t *mpu = init_mpu(&hi2c1, &hadc3, &hadc1, GPIOC, GPIOB); + Create Interfaces to Represent Relevant Hardware */ + /*mpu_t *mpu = init_mpu(&hi2c1, &hadc3, &hadc1, GPIOC, GPIOB); assert(mpu); pdu_t *pdu = init_pdu(&hi2c2); - assert(pdu); + assert(pdu);*/ dti_t *mc = dti_init(); assert(mc); - steeringio_t *wheel = steeringio_init(); - assert(wheel); + /*steeringio_t *wheel = steeringio_init(); + assert(wheel);8*/ init_can1(&hcan1); - bms_init(); + //bms_init(); printf("\r\n\n\nInit Success...\r\n\n\n"); @@ -207,7 +207,7 @@ int main(void) /* USER CODE BEGIN RTOS_THREADS */ /* Monitors */ - non_func_data_args_t *nfd_args = malloc(sizeof(non_func_data_args_t)); + /*non_func_data_args_t *nfd_args = malloc(sizeof(non_func_data_args_t)); nfd_args->mpu = mpu; nfd_args->pdu = pdu; non_functional_data_thead = osThreadNew(vNonFunctionalDataCollection, nfd_args, &non_functional_data_attributes); @@ -225,7 +225,7 @@ int main(void) // shutdown_monitor_handle = osThreadNew(vShutdownMonitor, pdu, &shutdown_monitor_attributes); // assert(shutdown_monitor_handle); - /* Messaging */ + Messaging */ can_dispatch_handle = osThreadNew(vCanDispatch, &hcan1, &can_dispatch_attributes); assert(can_dispatch_handle); can_receive_thread = osThreadNew(vCanReceive, mc, &can_receive_attributes); @@ -234,7 +234,7 @@ int main(void) assert(serial_monitor_handle); /* Control Logic */ - fault_handle = osThreadNew(vFaultHandler, NULL, &fault_handle_attributes); + /*fault_handle = osThreadNew(vFaultHandler, NULL, &fault_handle_attributes); assert(fault_handle); rtds_thread = osThreadNew(vRTDS, pdu, &rtds_attributes); @@ -252,7 +252,7 @@ int main(void) sm_args->mc = mc; sm_director_handle = osThreadNew(vStateMachineDirector, sm_args, &sm_director_attributes); assert(sm_director_handle); - /* USER CODE END RTOS_THREADS */ + USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ /* add events, ... */ @@ -320,14 +320,14 @@ void SystemClock_Config(void) * @param None * @retval None */ -static void MX_ADC1_Init(void) -{ +/*static void MX_ADC1_Init(void) +{*/ /* USER CODE BEGIN ADC1_Init 0 */ /* USER CODE END ADC1_Init 0 */ - ADC_ChannelConfTypeDef sConfig = {0}; + //ADC_ChannelConfTypeDef sConfig = {0}; /* USER CODE BEGIN ADC1_Init 1 */ @@ -335,7 +335,7 @@ static void MX_ADC1_Init(void) /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ - hadc1.Instance = ADC1; + /*hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV6; hadc1.Init.Resolution = ADC_RESOLUTION_12B; hadc1.Init.ScanConvMode = ENABLE; @@ -350,36 +350,36 @@ static void MX_ADC1_Init(void) if (HAL_ADC_Init(&hadc1) != HAL_OK) { Error_Handler(); - } + }*/ /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ - sConfig.Channel = ADC_CHANNEL_8; + /*sConfig.Channel = ADC_CHANNEL_8; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); - } + }*/ /* USER CODE BEGIN ADC1_Init 2 */ /* USER CODE END ADC1_Init 2 */ -} +//} /** * @brief ADC3 Initialization Function * @param None * @retval None */ -static void MX_ADC3_Init(void) -{ +/*static void MX_ADC3_Init(void) +{*/ /* USER CODE BEGIN ADC3_Init 0 */ /* USER CODE END ADC3_Init 0 */ - ADC_ChannelConfTypeDef sConfig = {0}; + //ADC_ChannelConfTypeDef sConfig = {0}; /* USER CODE BEGIN ADC3_Init 1 */ @@ -387,7 +387,7 @@ static void MX_ADC3_Init(void) /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ - hadc3.Instance = ADC3; + /*hadc3.Instance = ADC3; hadc3.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV6; hadc3.Init.Resolution = ADC_RESOLUTION_12B; hadc3.Init.ScanConvMode = ENABLE; @@ -402,49 +402,49 @@ static void MX_ADC3_Init(void) if (HAL_ADC_Init(&hadc3) != HAL_OK) { Error_Handler(); - } + }*/ /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ - sConfig.Channel = ADC_CHANNEL_2; + /*sConfig.Channel = ADC_CHANNEL_2; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK) { Error_Handler(); - } + }*/ /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ - sConfig.Channel = ADC_CHANNEL_3; + /*sConfig.Channel = ADC_CHANNEL_3; sConfig.Rank = 2; if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK) { Error_Handler(); - } + }*/ /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ - sConfig.Channel = ADC_CHANNEL_0; + /*sConfig.Channel = ADC_CHANNEL_0; sConfig.Rank = 3; if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK) { Error_Handler(); - } + }*/ /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ - sConfig.Channel = ADC_CHANNEL_1; + /*sConfig.Channel = ADC_CHANNEL_1; sConfig.Rank = 4; if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK) { Error_Handler(); - } + }*/ /* USER CODE BEGIN ADC3_Init 2 */ /* USER CODE END ADC3_Init 2 */ -} +//} /** * @brief CAN1 Initialization Function @@ -488,8 +488,8 @@ static void MX_CAN1_Init(void) * @param None * @retval None */ -static void MX_I2C1_Init(void) -{ +/*static void MX_I2C1_Init(void) +{*/ /* USER CODE BEGIN I2C1_Init 0 */ @@ -498,7 +498,7 @@ static void MX_I2C1_Init(void) /* USER CODE BEGIN I2C1_Init 1 */ /* USER CODE END I2C1_Init 1 */ - hi2c1.Instance = I2C1; + /*hi2c1.Instance = I2C1; hi2c1.Init.ClockSpeed = 100000; hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; hi2c1.Init.OwnAddress1 = 0; @@ -510,20 +510,20 @@ static void MX_I2C1_Init(void) if (HAL_I2C_Init(&hi2c1) != HAL_OK) { Error_Handler(); - } + }*/ /* USER CODE BEGIN I2C1_Init 2 */ /* USER CODE END I2C1_Init 2 */ -} +//} /** * @brief I2C2 Initialization Function * @param None * @retval None */ -static void MX_I2C2_Init(void) -{ +/*static void MX_I2C2_Init(void) +{*/ /* USER CODE BEGIN I2C2_Init 0 */ @@ -532,7 +532,7 @@ static void MX_I2C2_Init(void) /* USER CODE BEGIN I2C2_Init 1 */ /* USER CODE END I2C2_Init 1 */ - hi2c2.Instance = I2C2; + /*hi2c2.Instance = I2C2; hi2c2.Init.ClockSpeed = 100000; hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2; hi2c2.Init.OwnAddress1 = 0; @@ -544,20 +544,20 @@ static void MX_I2C2_Init(void) if (HAL_I2C_Init(&hi2c2) != HAL_OK) { Error_Handler(); - } + }*/ /* USER CODE BEGIN I2C2_Init 2 */ /* USER CODE END I2C2_Init 2 */ -} +//} /** * @brief IWDG Initialization Function * @param None * @retval None */ -static void MX_IWDG_Init(void) -{ +/*static void MX_IWDG_Init(void) +{*/ /* USER CODE BEGIN IWDG_Init 0 */ @@ -566,18 +566,18 @@ static void MX_IWDG_Init(void) /* USER CODE BEGIN IWDG_Init 1 */ /* USER CODE END IWDG_Init 1 */ - hiwdg.Instance = IWDG; + /*hiwdg.Instance = IWDG; hiwdg.Init.Prescaler = IWDG_PRESCALER_32; hiwdg.Init.Reload = 4095; if (HAL_IWDG_Init(&hiwdg) != HAL_OK) { Error_Handler(); - } + }*/ /* USER CODE BEGIN IWDG_Init 2 */ /* USER CODE END IWDG_Init 2 */ -} +//} /** * @brief USART3 Initialization Function @@ -615,84 +615,84 @@ static void MX_USART3_UART_Init(void) /** * Enable DMA controller clock */ -static void MX_DMA_Init(void) -{ +/*static void MX_DMA_Init(void) +{*/ /* DMA controller clock enable */ - __HAL_RCC_DMA2_CLK_ENABLE(); + /*__HAL_RCC_DMA2_CLK_ENABLE(); -} +}*/ /** * @brief GPIO Initialization Function * @param None * @retval None */ -static void MX_GPIO_Init(void) +/*static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; -/* USER CODE BEGIN MX_GPIO_Init_1 */ + USER CODE BEGIN MX_GPIO_Init_1 */ /* USER CODE END MX_GPIO_Init_1 */ /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOH_CLK_ENABLE(); + /*__HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE();*/ /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3|GPIO_PIN_8|GPIO_PIN_9, GPIO_PIN_RESET); + //HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3|GPIO_PIN_8|GPIO_PIN_9, GPIO_PIN_RESET); /*Configure GPIO pins : PC3 PC8 PC9 */ - GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_8|GPIO_PIN_9; + /*GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_8|GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);*/ /*Configure GPIO pins : PA4 PA5 PA6 PA7 */ - GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; + /*GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);*/ /*Configure GPIO pin : PC4 */ - GPIO_InitStruct.Pin = GPIO_PIN_4; + /*GPIO_InitStruct.Pin = GPIO_PIN_4; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);*/ /*Configure GPIO pin : PB1 */ - GPIO_InitStruct.Pin = GPIO_PIN_1; + /*GPIO_InitStruct.Pin = GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);*/ /*Configure GPIO pin : PB2 */ - GPIO_InitStruct.Pin = GPIO_PIN_2; + /*GPIO_InitStruct.Pin = GPIO_PIN_2; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF15_EVENTOUT; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);*/ /*Configure GPIO pin : PA9 */ - GPIO_InitStruct.Pin = GPIO_PIN_9; + /*GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);*/ /*Configure GPIO pins : PA11 PA12 */ - GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; + /*GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);*/ /* USER CODE BEGIN MX_GPIO_Init_2 */ /* USER CODE END MX_GPIO_Init_2 */ -} +//} /* USER CODE BEGIN 4 */