KT24-1110_65E-HA-651B/cpu/br25/port_wkup.c

84 lines
2.5 KiB
C
Raw Permalink Normal View History

2024-11-10 10:44:17 +00:00
#include "typedef.h"
#include "irq.h"
#include "asm/gpio.h"
/**
* JL_WAKEUP PMU管理的唤醒使
*/
static void (*port_wkup_irq_cbfun)(void) = NULL;
static u32 user_port = -1;;
/**
* @brief
*/
___interrupt
void port_wkup_irq_fun(void)
{
if (JL_WAKEUP->CON3 & BIT(0)) {
JL_WAKEUP->CON2 |= BIT(0);
if (port_wkup_irq_cbfun) {
port_wkup_irq_cbfun();
}
}
}
/**
* @brief
* @param port IO_PORTA_00......
* @param trigger_edge 沿 0沿 1沿
* @param cbfun
*/
void port_wkup_interrupt_init(u32 port, u8 trigger_edge, void (*cbfun)(void))
{
JL_WAKEUP->CON0 &= ~BIT(0);
gpio_set_die(port, 1);
gpio_set_direction(port, 1);
if (trigger_edge == 0) {
JL_WAKEUP->CON1 &= ~BIT(0);
gpio_set_pull_up(port, 0);
gpio_set_pull_down(port, 1);
} else {
JL_WAKEUP->CON1 |= BIT(0);
gpio_set_pull_up(port, 1);
gpio_set_pull_down(port, 0);
}
user_port = port;
if (cbfun) {
port_wkup_irq_cbfun = cbfun;
}
request_irq(IRQ_PORT_IDX, 3, port_wkup_irq_fun, 0); //注册中断函数
JL_IOMAP->CON2 &= ~(0b111111 << 0); //使用inputchannel 0
JL_IOMAP->CON2 |= (port << 0);
JL_WAKEUP->CON2 |= BIT(0); //清一次pnd
JL_WAKEUP->CON0 |= BIT(0); //引脚中断使能
}
/**
* @brief
* @param port IO_PORTA_00......
*/
void port_wkup_interrupt_close(u32 port)
{
JL_WAKEUP->CON0 &= ~BIT(0);
if (port == user_port) {
gpio_set_die(port, 0);
gpio_set_direction(port, 1);
gpio_set_pull_up(port, 0);
gpio_set_pull_down(port, 0);
}
}
/*********************************************************************************************************
* ****************************** 使 ***************************************
* ******************************************************************************************************/
void port_irq_cbfun(void)
{
printf("Hello world !\n");
}
void my_port_wkup_test()
{
port_wkup_interrupt_init(IO_PORTA_03, 0, port_irq_cbfun);//上升沿触发
/* port_wkup_interrupt_init(IO_PORT_DP, 1, port_irq_cbfun);//下降沿触发 */
while (1);
}