Added print on interrupt via task flag
This commit is contained in:
@@ -59,10 +59,10 @@ void Error_Handler(void);
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define LED_RED_Pin GPIO_PIN_12
|
||||
#define LED_RED_GPIO_Port GPIOI
|
||||
#define TIM2_CRANK_Pin GPIO_PIN_0
|
||||
#define TIM2_CRANK_GPIO_Port GPIOA
|
||||
#define TIM2_CAM_Pin GPIO_PIN_1
|
||||
#define TIM2_CAM_GPIO_Port GPIOA
|
||||
#define TIM2_CRANK_Pin GPIO_PIN_0
|
||||
#define TIM2_CRANK_GPIO_Port GPIOA
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
#include "main.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "stm32h7xx_hal_tim.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "global_state.h"
|
||||
#include "ring_buffer.h"
|
||||
#ifdef DEBUG
|
||||
#include "SEGGER_RTT.h"
|
||||
#endif
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -80,8 +82,7 @@ const osThreadAttr_t camTask_attributes = {
|
||||
.priority = (osPriority_t)osPriorityRealtime7,
|
||||
};
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
global_state_t state_g ={0};
|
||||
static volatile global_state_t state_g = {0};
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@@ -104,12 +105,14 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) {
|
||||
switch (htim->Channel) {
|
||||
// HAL_TIM_ACTIVE_CHANNEL_2 is the channel used for cam interupts
|
||||
case HAL_TIM_ACTIVE_CHANNEL_2:
|
||||
ringBufferPush(&state_g.cam_RB,HAL_TIM_ReadCapturedValue(htim,HAL_TIM_ACTIVE_CHANNEL_2));
|
||||
ringBufferPush(&state_g.cam_RB,
|
||||
HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2));
|
||||
osThreadFlagsSet(camTaskHandle, 0x01);
|
||||
break;
|
||||
// HAL_TIM_ACTIVE_CHANNEL_1 is the channel used for crank interupts
|
||||
case HAL_TIM_ACTIVE_CHANNEL_1:
|
||||
ringBufferPush(&state_g.crank_RB,HAL_TIM_ReadCapturedValue(htim,HAL_TIM_ACTIVE_CHANNEL_1));
|
||||
ringBufferPush(&state_g.crank_RB,
|
||||
HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1));
|
||||
osThreadFlagsSet(crankTaskHandle, 0x01);
|
||||
break;
|
||||
default:
|
||||
@@ -190,6 +193,12 @@ int main(void) {
|
||||
MX_TIM2_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
#ifdef DEBUG
|
||||
void SEGGER_RTT_Init(void);
|
||||
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0,
|
||||
SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
|
||||
#endif
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Init scheduler */
|
||||
@@ -340,18 +349,20 @@ static void MX_TIM2_Init(void) {
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
|
||||
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
|
||||
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
|
||||
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
|
||||
sConfigIC.ICFilter = 0;
|
||||
if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
|
||||
if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_2) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM2_Init 2 */
|
||||
|
||||
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1);
|
||||
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2);
|
||||
/* USER CODE END TIM2_Init 2 */
|
||||
}
|
||||
|
||||
@@ -400,7 +411,7 @@ void StartDefaultTask(void *argument) {
|
||||
/* USER CODE BEGIN 5 */
|
||||
/* Infinite loop */
|
||||
for (;;) {
|
||||
osDelay(1);
|
||||
osDelay(1000);
|
||||
}
|
||||
/* USER CODE END 5 */
|
||||
}
|
||||
@@ -417,9 +428,12 @@ void crankHandler(void *argument) {
|
||||
/* Infinite loop */
|
||||
for (;;) {
|
||||
osThreadFlagsWait(0x01, osFlagsWaitAny, osWaitForever);
|
||||
#ifdef DEBUG
|
||||
SEGGER_RTT_printf(0, "Crank pulse detected at: %lu\n\r",
|
||||
ringBufferRead(&state_g.crank_RB, 0));
|
||||
#endif /* ifdef DEBUG */
|
||||
if (state_g.sync == SYNC_OK) {
|
||||
// TODO complete algorithm for scheduling spark
|
||||
|
||||
}
|
||||
}
|
||||
/* USER CODE END crankHandler */
|
||||
@@ -437,9 +451,12 @@ void camHandler(void *argument) {
|
||||
/* Infinite loop */
|
||||
for (;;) {
|
||||
osThreadFlagsWait(0x01, osFlagsWaitAny, osWaitForever);
|
||||
#ifdef DEBUG
|
||||
SEGGER_RTT_printf(0, "Cam pulse detected at: %lu\n\r",
|
||||
ringBufferRead(&state_g.cam_RB, 0));
|
||||
#endif /* ifdef DEBUG */
|
||||
if (state_g.sync == SYNC_OK) {
|
||||
// TODO complete algorithm for scheduling spark
|
||||
|
||||
}
|
||||
}
|
||||
/* USER CODE END camHandler */
|
||||
|
||||
@@ -96,10 +96,10 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**TIM2 GPIO Configuration
|
||||
PA1 ------> TIM2_CH2
|
||||
PA0 ------> TIM2_CH1
|
||||
PA1_C ------> TIM2_CH2
|
||||
*/
|
||||
GPIO_InitStruct.Pin = TIM2_CRANK_Pin|TIM2_CAM_Pin;
|
||||
GPIO_InitStruct.Pin = TIM2_CAM_Pin|TIM2_CRANK_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
@@ -134,10 +134,10 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
|
||||
__HAL_RCC_TIM2_CLK_DISABLE();
|
||||
|
||||
/**TIM2 GPIO Configuration
|
||||
PA1 ------> TIM2_CH2
|
||||
PA0 ------> TIM2_CH1
|
||||
PA1_C ------> TIM2_CH2
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, TIM2_CRANK_Pin|TIM2_CAM_Pin);
|
||||
HAL_GPIO_DeInit(GPIOA, TIM2_CAM_Pin|TIM2_CRANK_Pin);
|
||||
|
||||
/* TIM2 interrupt DeInit */
|
||||
HAL_NVIC_DisableIRQ(TIM2_IRQn);
|
||||
|
||||
@@ -41,8 +41,8 @@ Mcu.Pin3=PA13 (JTMS/SWDIO)
|
||||
Mcu.Pin4=PI12
|
||||
Mcu.Pin5=PH1-OSC_OUT (PH1)
|
||||
Mcu.Pin6=PH0-OSC_IN (PH0)
|
||||
Mcu.Pin7=PA0
|
||||
Mcu.Pin8=PA1_C
|
||||
Mcu.Pin7=PA1
|
||||
Mcu.Pin8=PA0
|
||||
Mcu.Pin9=VP_FREERTOS_M7_VS_CMSIS_V2
|
||||
Mcu.PinsNb=13
|
||||
Mcu.ThirdPartyNb=0
|
||||
@@ -81,6 +81,11 @@ PA0.GPIO_Label=TIM2_CRANK
|
||||
PA0.Locked=true
|
||||
PA0.PinAttribute=CortexM7
|
||||
PA0.Signal=S_TIM2_CH1_ETR
|
||||
PA1.GPIOParameters=GPIO_Label,PinAttribute
|
||||
PA1.GPIO_Label=TIM2_CAM
|
||||
PA1.Locked=true
|
||||
PA1.PinAttribute=CortexM7
|
||||
PA1.Signal=S_TIM2_CH2
|
||||
PA13\ (JTMS/SWDIO).GPIOParameters=PinAttribute
|
||||
PA13\ (JTMS/SWDIO).Locked=true
|
||||
PA13\ (JTMS/SWDIO).PinAttribute=CortexM7
|
||||
@@ -89,11 +94,6 @@ PA14\ (JTCK/SWCLK).GPIOParameters=PinAttribute
|
||||
PA14\ (JTCK/SWCLK).Locked=true
|
||||
PA14\ (JTCK/SWCLK).PinAttribute=CortexM7
|
||||
PA14\ (JTCK/SWCLK).Signal=DEBUG_JTCK-SWCLK
|
||||
PA1_C.GPIOParameters=GPIO_Label,PinAttribute
|
||||
PA1_C.GPIO_Label=TIM2_CAM
|
||||
PA1_C.Locked=true
|
||||
PA1_C.PinAttribute=CortexM7
|
||||
PA1_C.Signal=S_TIM2_CH2
|
||||
PC14-OSC32_IN\ (OSC32_IN).GPIOParameters=PinAttribute
|
||||
PC14-OSC32_IN\ (OSC32_IN).Locked=true
|
||||
PC14-OSC32_IN\ (OSC32_IN).Mode=LSE-External-Oscillator
|
||||
@@ -249,7 +249,8 @@ SYS.userName=SYS_M7
|
||||
TIM2.Channel-Input_Capture1_from_TI1=TIM_CHANNEL_1
|
||||
TIM2.Channel-Input_Capture2_from_TI2=TIM_CHANNEL_2
|
||||
TIM2.ClockDivision=TIM_CLOCKDIVISION_DIV4
|
||||
TIM2.IPParameters=ClockDivision,Prescaler,Channel-Input_Capture1_from_TI1,Channel-Input_Capture2_from_TI2
|
||||
TIM2.ICPolarity_CH1=TIM_INPUTCHANNELPOLARITY_FALLING
|
||||
TIM2.IPParameters=ClockDivision,Prescaler,Channel-Input_Capture1_from_TI1,ICPolarity_CH1,Channel-Input_Capture2_from_TI2
|
||||
TIM2.Prescaler=0
|
||||
VP_FREERTOS_M7_VS_CMSIS_V2.Mode=CMSIS_V2
|
||||
VP_FREERTOS_M7_VS_CMSIS_V2.Signal=FREERTOS_M7_VS_CMSIS_V2
|
||||
@@ -260,3 +261,4 @@ VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
||||
VP_TIM2_VS_ClockSourceINT.Mode=Internal
|
||||
VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT
|
||||
board=custom
|
||||
rtos.0.ip=FREERTOS_M7
|
||||
|
||||
Reference in New Issue
Block a user