This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM5708: 关于DSP核的CCS RTOS开发按键检测配置问题

Part Number: AM5708

我想在AM5708 DSP核 实现按键的轮训和按键中断功能,参考SDK的代码配置,但是功能没法实现,不清楚是不是驱动没配置好。

如下代码现象:LED输出翻转正常,两个按键检测都不工作。

/**
 *  \file    tl-led-flash.c
 *
 *  \brief   Example application main file. This application will toggle the led.
 *           The led toggling will be done inside an callback function, which
 *           will be called by Interrupt Service Routine. Interrupts are
 *           triggered manually and no external source is used to trigger
 *           interrupts.
 *
 *  \version 1.0
 */

/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>


/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>

#include <stdio.h>
#include <string.h>

/* TI-RTOS Header files */
#include <ti/drv/gpio/GPIO.h>
#include <ti/drv/gpio/soc/GPIO_soc.h>

/* UART Header files */
#include <ti/drv/uart/UART.h>
#include <ti/drv/uart/UART_stdio.h>

#include <ti/drv/uart/test/src/UART_board.h>

#include <ti/board/board.h>
#include <ti/csl/soc.h>
#include <ti/csl/soc/am572x/src/cslr_control_core_pad_io.h>
#include <ti/board/src/evmAM572x/include/evmam572x_pinmux.h>

/**********************************************************************
 ************************** Macros ************************************
 **********************************************************************/

#define GPIO_PIN_VAL_LOW          (0U)
#define GPIO_PIN_VAL_HIGH         (1U)

#define GPIO_USER0_LED_PIN_NUM    (0x04U)
#define GPIO_USER0_LED_PORT_NUM   (0x04)    /* user-led0, gpio4_4 */
#define GPIO_USER1_LED_PIN_NUM    (0x04U)
#define GPIO_USER1_LED_PORT_NUM   (0x05)    /* user-led1, gpio5_4 */
#define GPIO_USER2_LED_PIN_NUM    (0x05U)
#define GPIO_USER2_LED_PORT_NUM   (0x05)    /* user-led2, gpio5_5 */

#define GPIO_USER_KEY3_PIN_NUM     5
#define GPIO_USER_KEY3_PORT_NUM    4       //GPIO4_5
#define GPIO_USER_KEY4_PIN_NUM     20
#define GPIO_USER_KEY4_PORT_NUM    6       //GPIO6_20

/**********************************************************************
 ************************** Internal functions ************************
 **********************************************************************/
/* GPIO Driver board specific pin configuration structure */
GPIO_PinConfig gpioPinConfigs[] = {
	GPIO_DEVICE_CONFIG(GPIO_USER0_LED_PORT_NUM, GPIO_USER0_LED_PIN_NUM) | GPIO_CFG_OUTPUT,
	GPIO_DEVICE_CONFIG(GPIO_USER1_LED_PORT_NUM, GPIO_USER1_LED_PIN_NUM) | GPIO_CFG_OUTPUT,
    GPIO_DEVICE_CONFIG(GPIO_USER2_LED_PORT_NUM, GPIO_USER2_LED_PIN_NUM) | GPIO_CFG_OUTPUT,

    GPIO_DEVICE_CONFIG(GPIO_USER_KEY3_PORT_NUM, GPIO_USER_KEY3_PIN_NUM) | GPIO_CFG_INPUT,
    GPIO_DEVICE_CONFIG(GPIO_USER_KEY4_PORT_NUM, GPIO_USER_KEY4_PIN_NUM) | GPIO_CFG_IN_INT_RISING | GPIO_CFG_INPUT
};

/* GPIO Driver call back functions */
GPIO_CallbackFxn gpioCallbackFunctions[] = {
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
};

/* GPIO Driver configuration structure */
GPIO_v1_Config GPIO_v1_config = {
    .pinConfigs = gpioPinConfigs,
    .callbacks  = gpioCallbackFunctions,
    .numberOfPinConfigs = sizeof(gpioPinConfigs) / sizeof(GPIO_PinConfig),
    .numberOfCallbacks  = sizeof(gpioCallbackFunctions) / sizeof(GPIO_CallbackFxn),
    .intPriority = 20,
};

/* ON Board LED pins which are connected to GPIO pins. */
typedef enum GPIO_LED {
    USER_LED0 = 0,
    USER_LED1,
    USER_LED2,
	END
}GPIO_LED;

typedef enum GPIO_INPUT {
    USER_KEY3 = 3,
    USER_KEY4 = 4
}GPIO_INPUT;


void print_debug(char *str)
{
    UART_puts(str,strlen(str));
}

void user_key3_cb(void)
{
    print_debug("\n user_key3_cb \n");
}

void user_key4_cb(void)
{
    print_debug("\n user_key4_cb \n");
}

void GPIO_PIN_MUX(void)
{
    uint32_t regVal = 0;

    /* GPIO pinmux configuration */
    CSL_FINS(regVal, CONTROL_CORE_PAD_IO_PAD_VIN2A_D3_VIN2A_D3_MUXMODE, 0xEU);
    ((CSL_padRegsOvly) CSL_MPU_CORE_PAD_IO_REGISTERS_REGS)->PAD_VIN2A_D3 = regVal;      /* vin2a_d3.gpio4_4(user_led0) */
    CSL_FINS(regVal, CONTROL_CORE_PAD_IO_PAD_MCASP1_AXR2_MCASP1_AXR2_MUXMODE, 0xEU);
    ((CSL_padRegsOvly) CSL_MPU_CORE_PAD_IO_REGISTERS_REGS)->PAD_MCASP1_AXR2 = regVal;   /* mcasp1_axr2.gpio5_4(user_led1) */
    CSL_FINS(regVal, CONTROL_CORE_PAD_IO_PAD_MCASP1_AXR3_MCASP1_AXR3_MUXMODE, 0xEU);
    ((CSL_padRegsOvly) CSL_MPU_CORE_PAD_IO_REGISTERS_REGS)->PAD_MCASP1_AXR3 = regVal;   /* mcasp1_axr3.gpio5_5(user_led2) */

    CSL_FINS(regVal, CONTROL_CORE_PAD_IO_PAD_VIN2A_D4_VIN2A_D4_MUXMODE, 0xEU);
    ((CSL_padRegsOvly) CSL_MPU_CORE_PAD_IO_REGISTERS_REGS)->PAD_VIN2A_D4 = regVal;   /* VIN2A_D4.gpio4_5(user_key3) */
    CSL_FINS(regVal, CONTROL_CORE_PAD_IO_PAD_XREF_CLK3_XREF_CLK3_MUXMODE, 0xEU);
    ((CSL_padRegsOvly) CSL_MPU_CORE_PAD_IO_REGISTERS_REGS)->PAD_XREF_CLK3 = regVal;   /* XREF_CLK3.gpio6_20(user_key4) */

    /* GPIO4 Clock Enable */
    *(unsigned int*)0x4A009770 = (unsigned int)(0x00000102);

    /* GPIO6 Clock Enable */
    *(unsigned int*)0x4A009780 = (unsigned int)(0x00000102);

//    /* Set the callback function */
//    GPIO_setCallback(USER_KEY3, user_key3_cb);
//    /* Enable GPIO interrupt on the specific gpio pin */
//    GPIO_enableInt(USER_KEY3);

    /* Set the callback function */
    GPIO_setCallback(USER_KEY4, user_key4_cb);
    /* Enable GPIO interrupt on the specific gpio pin */
    GPIO_enableInt(USER_KEY4);
}


/*
 *  ======== Board_initGPIO ========
 */
static void Board_initGPIO(void)
{
    Board_initCfg boardCfg;

    boardCfg = BOARD_INIT_MODULE_CLOCK | BOARD_INIT_UART_STDIO;
    Board_init(boardCfg);
}

/**********************************************************************
 ************************** Global Variables **************************
 **********************************************************************/
/*
 *  ======== task function ========
 */
void tl_led_flash(UArg arg0, UArg arg1)
{
    uint8_t i = 0;

    /* GPIO initialization */
    GPIO_init();

    GPIO_PIN_MUX();

    print_debug("\n GPIO Led Blink Application \n");

    while(1)
    {
		/* Turn on LEDs */
		for ( i = 0; i < END; i++ ){
			GPIO_write(i,GPIO_PIN_VAL_HIGH);
		}
		
		/* Keep the LEDs on for 500 ms */
		Task_sleep(500);
		
		/* Turn off LEDs */
		for ( i = 0; i < END; i++ ){
			GPIO_write(i,GPIO_PIN_VAL_LOW);
		}
		
		/* Keep the LEDs off for 500 ms */
		Task_sleep(500);


		if(GPIO_read(USER_KEY3) == 1)
		{
		    print_debug("key3 is press\n");
		}

        if(GPIO_read(USER_KEY4) == 0)
        {
            print_debug("key4 is press\n");
        }
    }
    Task_exit();
}

/*
 *  ======== main ========
 */
int main(void)
{
    Task_Handle task;
    Error_Block eb;

    Error_init(&eb);

    /* Call board_init functions */
    Board_initGPIO();
	
	/* create a Task, which is tl_led_flash */
    task = Task_create(tl_led_flash, NULL, &eb);
        if (task == NULL) {
            System_printf("Task_create() failed!\n");
            BIOS_exit(0);
        }

    /* Start BIOS */
    BIOS_start();

    return (0);
}