[MCU framework][bsp layer][cx32l003][bsp_exti] EXTI configuration and use

Publisher:shmilydeLatest update time:2022-09-22 Source: csdn Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Different Subjects

Internal interrupt: An interrupt is an algorithm instruction, which is initiated by a soft interrupt instruction.


External interrupt: It is an internal mechanism for the microcontroller to process external events in real time.


2. Different mechanisms

Internal interrupt: When executing a division instruction, if the divisor is 0 or the quotient exceeds the range that the register can express, an internal interrupt of type 0 is generated. It is the internal interrupt with the highest priority.


External interrupt: When some external event occurs, the interrupt system of the microcontroller will force the CPU to suspend the program being executed and turn to handle the interrupt event; after the interrupt is handled, it returns to the interrupted program and continues to execute.


/********************************************************************************

* @file bsp_exti.c

* @author jianqiang.xue

* @version V1.0.0

* @date    2021-04-09

* @brief   NULL

********************************************************************************/

/* Includes ------------------------------------------------------------------*/

#include

#include

#include


#include "RTE_Components.h"

#include CMSIS_device_header


#include "cx32l003_hal_def.h"

#include "cx32l003_hal_conf.h"


#include "sys_api.h"

/* Private Includes ----------------------------------------------------------*/


/* Private Define ------------------------------------------------------------*/

/* Private Variables ---------------------------------------------------------*/

bool bsp_exti_init = false;


typedef void(*bsp_gpio_exti_callback)(void *gpiox, uint16_t gpio_pin);

static bsp_gpio_exti_callback g_irq_callback;

/* Public Function Prototypes ------------------------------------------------*/


void HAL_GPIO_EXTI_Callback(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)

{

    if (g_irq_callback)

    {

        g_irq_callback(GPIOx, GPIO_Pin);

    }

}


/**

 * @brief Set external interrupt NVIC

 * @note   NULL

 * @param irqn: interrupt number (in typedef enum IRQn, for example: USART1_IRQn)

 * @param priority: interrupt priority

 * @retval None

 */

void bsp_exit_set(uint8_t irqn, uint32_t priority)

{

    bsp_exit_init = true;

    HAL_NVIC_SetPriority((IRQn_Type)(irqn), priority);

    HAL_NVIC_EnableIRQ((IRQn_Type)(irqn));

}


/**

 * @brief Clear external interrupt settings

 * @note   NULL

 * @param irqn: interrupt number (in typedef enum IRQn, for example: USART1_IRQn)

 * @retval None

 */

void bsp_exit_clear_set(uint8_t irqn)

{

    HAL_NVIC_DisableIRQ((IRQn_Type)(irqn));

}


/**

 * @brief Clear external interrupt flag

 * @note   NULL

 * @param *gpiox: reserved

 * @param pin: pin number

 * @retval None

 */

void bsp_exit_clear_flag(void *gpiox, uint8_t pin)

{

    GPIO_TypeDef *gpiox_t = gpiox;


    __HAL_GPIO_EXTI_CLEAR_FLAG(gpiox_t, pin);

}


/**

 * @brief Register external event callback function

 * @note   NULL

 * @param *event: event function

 * @retval None

 */

bool bsp_gpio_exit_irq_register_callback(void *event)

{

    if (g_irq_callback != NULL)

    {

        return false;

    }

    else

    {

        g_irq_callback = (bsp_gpio_exti_callback)event;

    }

    return true;

}


/********************************************************************************

* @file bsp_exti.h

* @author jianqiang.xue

* @version V1.0.0

* @date    2021-04-09

* @brief   NULL

********************************************************************************/


#ifndef __BSP_EXTI_H

#define __BSP_EXTI_H


/* Includes ------------------------------------------------------------------*/

#include


/* Public Function Prototypes ------------------------------------------------*/


void bsp_exit_set(uint8_t irqn, uint32_t priority);

void bsp_exit_clear_set(uint8_t irqn);

void bsp_exit_clear_flag(void *gpiox, uint8_t pin);


//Pin external interrupt callback


bool bsp_gpio_exit_irq_register_callback(void *event);


#endif

Reference address:[MCU framework][bsp layer][cx32l003][bsp_exti] EXTI configuration and use

Previous article:[MCU framework][bsp layer][cx32l003][bsp_flash] FLASH configuration and use
Next article:[MCU framework][bsp layer][cx32l003][bsp_gpio] GPIO configuration and use

Recommended ReadingLatest update time:2024-11-16 22:38

[BSP layer] [nrf52832] [nrf52840] [nrf52810] [nrf52820] [bsp_exti] exti/gpioe configuration and use
GPIOTE—GPIO tasks and events The GPIO Tasks and Events (GPIOTE) module provides the ability to access GPIO pins using tasks and events. Each GPIOTE channel can be assigned to a pin. The GPIOTE block enables GPIOs to generate events on pin state changes, which can be used to perform tasks through the PPI system. You
[Microcontroller]
[BSP layer] [nrf52832] [nrf52840] [nrf52810] [nrf52820] [bsp_exti] exti/gpioe configuration and use
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号