⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 davincievm_gpio.c

📁 TI的DM6446的硬件平台搭建的相关例子
💻 C
字号:
/*
 *  Copyright 2005 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 *
 *  Not for distribution.
 */

/*
 *  GPIO implementation
 *
 */

#include "davincievm_gpio.h"

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_GPIO_init( )                                                 *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_GPIO_init()
{
    GPIO_PCR = 1;   // Free GPIO from emulation
    return 0;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_GPIO_setDirection( number, direction )                       *
 *                                                                          *
 *      number    <- GPIO# [0:7]                                            *
 *      direction <- 0:OUT 1:IN                                             *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_GPIO_setDirection( Uint16 number, Uint8 direction )
{
    Uint16 group_id   = number >> 5;
    Uint16 group_item = number & 0x1F;

    Uint32* gpio_dir = ( Uint32* )( GPIO_DIR_BASE + ( group_id * GPIO_BASE_OFFSET ) );

    direction &= 1;

    if ( direction == 0 )
        *gpio_dir &= ~( 1 << group_item );  // Set GPIO to OUT
    else
        *gpio_dir |= ( 1 << group_item );   // Set GPIO to IN

    return 0;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_GPIO_setOutput( number, value )                              *
 *                                                                          *
 *      number   <- GPIO# [0:7]                                             *
 *      value    <- 0:LOW 1:HIGH                                            *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_GPIO_setOutput( Uint16 number, Uint8 value )
{
    Uint16 group_id   = number >> 5;
    Uint16 group_item = number & 0x1F;

    Uint32* gpio_out = ( Uint32* )( GPIO_OUT_DATA_BASE + ( group_id * GPIO_BASE_OFFSET ) );

    value &= 1;

    if ( value == 0 )
        *gpio_out &= ~( 1 << group_item );  // Set GPIO to LOW
    else
        *gpio_out |= ( 1 << group_item );   // Set GPIO to HIGH

    return 0;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_GPIO_getInput( number )                                      *
 *                                                                          *
 *      number   <- GPIO# [0:7]                                             *
 *      value    <- 0:LOW 1:HIGH                                            *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_GPIO_getInput( Uint16 number )
{
   // Uint16 value;
    Uint32 value;
    Uint16 group_id   = number >> 5;
    Uint16 group_item = number & 0x1F;

    Uint32* gpio_in = ( Uint32* )( GPIO_IN_DATA_BASE + ( group_id * GPIO_BASE_OFFSET ) );

    value = *gpio_in;
    value = value >> group_item;

    return value & 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -