This repository has been archived on 2024-10-30. You can view files and clone it, but cannot push or open issues or pull requests.
PTR-Events/main.c

136 lines
3.9 KiB
C
Raw Permalink Normal View History

/*----------------------------------------------------------------------------
* CMSIS-RTOS 'main' function template
*---------------------------------------------------------------------------*/
#include "stm32f7xx_hal.h"
#include "stm32f7xx_hal_conf.h"
#include "RTE_Components.h"
#include CMSIS_device_header
#include "cmsis_os2.h"
#include "string.h"
#include <stdlib.h>
#include "ext_uart.h"
#include "ext_buttons.h"
#include "ext_26pin.h"
#ifdef RTE_Compiler_EventRecorder
#include "EventRecorder.h"
#endif
GPIO_InitTypeDef GPIO_InitStruct;
osThreadId_t idTask1;
osEventFlagsId_t evt_id;
const osThreadAttr_t AttrTask1 = {
.stack_size = 512, // Create the thread stack size
.priority = osPriorityNormal, //Set initial thread priority to high
.name = "Task 1"
};
void init_button(void)
{
/* Configure GPIO pin: PI2 (BTN_0) as interrupt */
__HAL_RCC_GPIOI_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI2_IRQn,5,5);
HAL_NVIC_EnableIRQ(EXTI2_IRQn);
}
void EXTI2_IRQHandler(void)
{
EventRecord2(0x000,0,0);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);
EventRecord2(0x100,0,0);
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_PIN)
{
//button interrupt
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, 1);
osEventFlagsSet(evt_id, 0x1U);
}
/*----------------------------------------------------------------------------
* Thread 1
*---------------------------------------------------------------------------*/
__NO_RETURN static void taskCounter(void *argument) {
for (;;) {
osEventFlagsWait(evt_id, 0x1U, osFlagsWaitAny, osWaitForever);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, 0);
}
}
//------------------------------------------------------------------------------
// Setup system clock to 216MHz
//------------------------------------------------------------------------------
void SystemClock_Config (void) {
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
/* Enable HSE Oscillator and activate PLL with HSE as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25;
RCC_OscInitStruct.PLL.PLLN = 432;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 9;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
/* Activate the OverDrive to reach the 216 MHz Frequency */
HAL_PWREx_EnableOverDrive();
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7);
}
int main (void) {
// System Initialization
SystemCoreClockUpdate();
SystemClock_Config();
Ext_Debug_Init();//initialize pin pf9 as output
init_button();
#ifdef RTE_Compiler_EventRecorder
// Initialize and start Event Recorder
// Ext_UART_Init(9600);
EventRecorderInitialize(EventRecordAll, 1U);
#endif
osKernelInitialize(); // Initialize CMSIS-RTOS
idTask1 = osThreadNew(taskCounter, NULL, &AttrTask1);
//events
evt_id = osEventFlagsNew(NULL);
//----------------------------------------------------------------------------------------------
// get names are placed for TraceAlyzer visualisation
//----------------------------------------------------------------------------------------------
osThreadGetName(idTask1);
osKernelStart();
// Start thread execution
for (;;) {
}
}