blob: f2f644f53ef5cba50a058e47431f435213338d72 [file] [log] [blame]
/******************************************************************************
* @file app_gpio_irq.c
*
* @brief for TLSR chips
*
* @author public@telink-semi.com;
* @date Sep. 30, 2010
*
* @attention
*
* Copyright (C) 2019-2020 Telink Semiconductor (Shanghai) Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*****************************************************************************/
/*
* app_gpio_irq.c
*
* Created on: 2017-8-25
* Author: Administrator
*/
#include "tl_common.h"
#include "drivers.h"
#if (DRIVER_TEST_MODE == TEST_GPIO_IRQ)
//you can change IO here
#define GPIO_LED1_PIN GPIO_PA0
#define GPIO_LED2_PIN GPIO_PA1
#define GPIO_LED3_PIN GPIO_PA2
#define LED_INIT_LEVEL 0
#define GPIO_TEST_PIN1 GPIO_PD0
#define GPIO_TEST_PIN2 GPIO_PD1
#define GPIO_TEST_PIN3 GPIO_PD2
unsigned char gpio_irq_test_mode = 0;
void app_gpio_irq_test_init(void)
{
//demo1: IRQ_GPIO, TEST_PIN1, falling edge triggers
/***step1. set pin as gpio and enable input********/
gpio_set_func(GPIO_TEST_PIN1, AS_GPIO); //enable GPIO func
gpio_set_input_en(GPIO_TEST_PIN1, 1); //enable input
gpio_set_output_en(GPIO_TEST_PIN1, 0); //disable output
/***step2. set the polarity and open pullup ***/
gpio_setup_up_down_resistor(GPIO_TEST_PIN1, PM_PIN_PULLUP_10K); //open pull up resistor
gpio_set_interrupt_pol(GPIO_TEST_PIN1, pol_falling); //falling edge
/***step3. set irq enable ***/
reg_irq_src = FLD_IRQ_GPIO_EN; //clean irq status
reg_irq_mask |= FLD_IRQ_GPIO_EN;
gpio_en_interrupt(GPIO_TEST_PIN1, 1);
//demo2: IRQ_GPIO_RISC0, TEST_PIN2, falling edge triggers
/***step1. set pin as gpio and enable input********/
gpio_set_func(GPIO_TEST_PIN2, AS_GPIO); //enable GPIO func
gpio_set_input_en(GPIO_TEST_PIN2, 1); //enable input
gpio_set_output_en(GPIO_TEST_PIN2, 0); //disable output
/***step2. set the polarity and open pullup ***/
gpio_setup_up_down_resistor(GPIO_TEST_PIN2, PM_PIN_PULLUP_10K); //open pull up resistor
gpio_set_interrupt_pol(GPIO_TEST_PIN2, pol_falling); //falling edge
/***step3. set irq enable ***/
reg_irq_src = FLD_IRQ_GPIO_RISC0_EN; //clean irq status
reg_irq_mask |= FLD_IRQ_GPIO_RISC0_EN;
gpio_en_interrupt_risc0(GPIO_TEST_PIN2, 1);
//demo3: IRQ_GPIO_RISC1, TEST_PIN3, rising edge triggers
/***step1. set pin as gpio and enable input********/
gpio_set_func(GPIO_TEST_PIN3, AS_GPIO); //enable GPIO func
gpio_set_input_en(GPIO_TEST_PIN3, 1); //enable input
gpio_set_output_en(GPIO_TEST_PIN3, 0); //disable output
/***step2. set the polarity and open pullup ***/
gpio_setup_up_down_resistor(GPIO_TEST_PIN3, PM_PIN_PULLDOWN_100K); //open pull down resistor
gpio_set_interrupt_pol(GPIO_TEST_PIN3, pol_rising); //rising edge
/***step3. set irq enable ***/
reg_irq_src = FLD_IRQ_GPIO_RISC1_EN; //clean irq status
reg_irq_mask |= FLD_IRQ_GPIO_RISC1_EN;
gpio_en_interrupt_risc1(GPIO_TEST_PIN3, 1);
irq_enable(); //must
}
//init the LED pin,for indication
void app_led_init(void)
{
gpio_set_func(GPIO_LED1_PIN, AS_GPIO);
gpio_set_output_en(GPIO_LED1_PIN, 1);//enable output
gpio_set_input_en(GPIO_LED1_PIN, 0); //disable input
gpio_write(GPIO_LED1_PIN, LED_INIT_LEVEL);
gpio_set_func(GPIO_LED2_PIN, AS_GPIO);
gpio_set_output_en(GPIO_LED2_PIN, 1);//enable output
gpio_set_input_en(GPIO_LED2_PIN, 0); //disable input
gpio_write(GPIO_LED2_PIN, LED_INIT_LEVEL);
gpio_set_func(GPIO_LED3_PIN, AS_GPIO);
gpio_set_output_en(GPIO_LED3_PIN, 1);//enable output
gpio_set_input_en(GPIO_LED3_PIN, 0); //disable input
gpio_write(GPIO_LED3_PIN, LED_INIT_LEVEL);
}
int gpio_all_irq_cnt;
int gpio_irq_cnt;
int gpio_irq_risr0_cnt;
int gpio_irq_risr1_cnt;
_attribute_ram_code_ void app_gpio_irq_test_proc(void)
{
gpio_all_irq_cnt ++;
/************ gpio irq ***************/
if(reg_irq_src & FLD_IRQ_GPIO_EN){
reg_irq_src = FLD_IRQ_GPIO_EN; // clear irq_gpio irq flag
gpio_irq_cnt ++;
DBG_CHN0_TOGGLE;
gpio_toggle(GPIO_LED1_PIN);
}
/************* gpio irq risc0 *************/
if(reg_irq_src & FLD_IRQ_GPIO_RISC0_EN){
reg_irq_src = FLD_IRQ_GPIO_RISC0_EN; // clear irq_gpio irq flag
gpio_irq_risr0_cnt ++;
DBG_CHN1_TOGGLE;
gpio_toggle(GPIO_LED2_PIN);
}
/************* gpio irq risc1 *************/
if(reg_irq_src & FLD_IRQ_GPIO_RISC1_EN){
reg_irq_src = FLD_IRQ_GPIO_RISC1_EN; // clear irq_gpio irq flag
gpio_irq_risr1_cnt ++;
DBG_CHN2_TOGGLE;
gpio_toggle(GPIO_LED3_PIN);
}
}
#endif