This commit is contained in:
2024-09-26 22:32:20 +08:00
commit 097089ef4e
323 changed files with 135661 additions and 0 deletions
+171
View File
@@ -0,0 +1,171 @@
/*
* GPIO_EXTI.c
*
* Created on: Jun 30, 2020
* Author: matth
*/
#include "GPIO_EXTI.h"
#include "main.h"
#include "FreeRTOS.h"
#include "task.h"
static GPIO_EXIT_t *gpio_extis[16]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
int GPIO_EXIT_open(GPIO_EXIT_t *exti, uint16_t pin)
{
exti->task = NULL;
exti->cnt = 0;
exti->total_cnt = 0;
exti->last_cnt = 0;
exti->pps = 0;
switch (pin)
{
case GPIO_PIN_0:
gpio_extis[0] = exti;
break;
case GPIO_PIN_1:
gpio_extis[1] = exti;
break;
case GPIO_PIN_2:
gpio_extis[2] = exti;
break;
case GPIO_PIN_3:
gpio_extis[3] = exti;
break;
case GPIO_PIN_4:
gpio_extis[4] = exti;
break;
case GPIO_PIN_5:
gpio_extis[5] = exti;
break;
case GPIO_PIN_6:
gpio_extis[6] = exti;
break;
case GPIO_PIN_7:
gpio_extis[7] = exti;
break;
case GPIO_PIN_8:
gpio_extis[8] = exti;
break;
case GPIO_PIN_9:
gpio_extis[9] = exti;
break;
case GPIO_PIN_10:
gpio_extis[10] = exti;
break;
case GPIO_PIN_11:
gpio_extis[11] = exti;
break;
case GPIO_PIN_12:
gpio_extis[12] = exti;
break;
case GPIO_PIN_13:
gpio_extis[13] = exti;
break;
case GPIO_PIN_14:
gpio_extis[14] = exti;
break;
case GPIO_PIN_15:
gpio_extis[15] = exti;
break;
default:
return -1;
}
return 0;
}
int GPIO_EXIT_take(GPIO_EXIT_t *e, uint32_t millisec)
{
e->task = xTaskGetCurrentTaskHandle();
return ulTaskNotifyTake( pdTRUE, millisec);
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
GPIO_EXIT_t *exti = NULL;
switch (GPIO_Pin)
{
case GPIO_PIN_0:
exti = gpio_extis[0];
break;
case GPIO_PIN_1:
exti = gpio_extis[1];
break;
case GPIO_PIN_2:
exti = gpio_extis[2];
break;
case GPIO_PIN_3:
exti = gpio_extis[3];
break;
case GPIO_PIN_4:
exti = gpio_extis[4];
break;
case GPIO_PIN_5:
exti = gpio_extis[5];
break;
case GPIO_PIN_6:
exti = gpio_extis[6];
break;
case GPIO_PIN_7:
exti = gpio_extis[7];
break;
case GPIO_PIN_8:
exti = gpio_extis[8];
break;
case GPIO_PIN_9:
exti = gpio_extis[9];
break;
case GPIO_PIN_10:
exti = gpio_extis[10];
break;
case GPIO_PIN_11:
exti = gpio_extis[11];
break;
case GPIO_PIN_12:
exti = gpio_extis[12];
break;
case GPIO_PIN_13:
exti = gpio_extis[13];
break;
case GPIO_PIN_14:
exti = gpio_extis[14];
break;
case GPIO_PIN_15:
exti = gpio_extis[15];
break;
}
if (exti)
{
exti->total_cnt++;
exti->cnt++;
if (exti->task)
{
vTaskNotifyGiveFromISR( exti->task, &xHigherPriorityTaskWoken );
exti->task = NULL;
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
}
}
void GPIO_EXIT_stats(void)
{
GPIO_EXIT_t * exti;
for (int i=0;i<16;++i)
{
exti = gpio_extis[i];
if (exti)
{
exti->pps = exti->total_cnt - exti->last_cnt;
exti->last_cnt = exti->total_cnt;
}
}
}