博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[TMS320C674x] 一、GPIO认识
阅读量:5038 次
发布时间:2019-06-12

本文共 7037 字,大约阅读时间需要 23 分钟。

前几日购买了一款ARM+DSP+FPGA的开发板,由于之前一直做FPGA方向,对ARM也有研究。虽然找的工作是数字IC设计,纯Verilog硬件语言,也不想固步自封,把自己死掉在数字IC中,所以继续往DSP方向钻。(暂时DSP不会淘汰吧)

言归正传吧~~~DSP小白,有些地方不对,望指正!

一、外设初始化

由于硬件的时钟、DDR2的初始化都已经在GEL文件中设定,程序中不比继续做时钟等硬件的初始化,只需要对相关模块使能即可。

PSC是C6748内部的电源管理模块,通过PSCInit()函数可以完成相应功能使能; 

void PSCInit(void){  // 使能 GPIO 模块  // 对相应外设模块的使能也可以在 BootLoader 中完成  PSCModuleControl(SOC_PSC_1_REGS,HW_PSC_GPIO,PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);}

SOC_PSC_1_REGS是PSC1的寄存器地址、HW_PSC_GPIO是GPIO使能的偏移。

二、管脚复用配置

void GPIOBank0Pin0PinMuxSetup(void){     unsigned int savePinmux = 0;     savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(1)) & ~(SYSCFG_PINMUX1_PINMUX1_31_28));     HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(1)) = (PINMUX1_GPIO0_0_ENABLE | savePinmux);}

HWREG是读取寄存器宏定义;SYSCFG0_PINMUX(x) 是选择复用寄存器x;

 

分析:savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(1)) & ~(SYSCFG_PINMUX1_PINMUX1_31_28));      

    是对31~28位清零;

 

分析:HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(1)) = (PINMUX1_GPIO0_0_ENABLE | savePinmux);

 

    #define PINMUX1_GPIO0_0_ENABLE (SYSCFG_PINMUX1_PINMUX1_31_28_GPIO0_0 << SYSCFG_PINMUX1_PINMUX1_31_28_SHIFT)

 

    #define SYSCFG_PINMUX1_PINMUX1_31_28_GPIO0_0 (0x00000008u)

 

    #define SYSCFG_PINMUX1_PINMUX1_31_28_SHIFT (0x0000001Cu)

 

   是对31~28位置8h;

   

三、GPIO管脚初始化

void GPIOBankPinInit(void)        {        // 配置 LED 对应管脚为输出管脚        // OMAPL138 及 DSP C6748 共有 144 个 GPIO    	// 以下为各组 GPIO BANK 起始管脚对应值        // 范围 1-144    	// GPIO0[0] 1        // GPIO1[0] 17    	// GPIO2[0] 33        // GPIO3[0] 49    	// GPIO4[0] 65        // GPIO5[0] 81    	// GPIO6[0] 97    	// GPIO7[0] 113    	// GPIO8[0] 129	// 核心板 LED        GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT);  // GPIO6[12]        GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT);  // GPIO6[13]            // 底板 LED        GPIODirModeSet(SOC_GPIO_0_REGS, 1, GPIO_DIR_OUTPUT);    // D7  GPIO0[0]        GPIODirModeSet(SOC_GPIO_0_REGS, 2, GPIO_DIR_OUTPUT);    // D9  GPIO0[1]        GPIODirModeSet(SOC_GPIO_0_REGS, 3, GPIO_DIR_OUTPUT);    // D10 GPIO0[2]        GPIODirModeSet(SOC_GPIO_0_REGS, 6, GPIO_DIR_OUTPUT);    // D6  GPIO0[5]    }

GPIODirModeSet的原型gpio.c文件里面定义,相关输入参数如下

void GPIOBankPinInit(void)        {        // 配置 LED 对应管脚为输出管脚        // OMAPL138 及 DSP C6748 共有 144 个 GPIO    	// 以下为各组 GPIO BANK 起始管脚对应值        // 范围 1-144    	// GPIO0[0] 1        // GPIO1[0] 17    	// GPIO2[0] 33        // GPIO3[0] 49    	// GPIO4[0] 65        // GPIO5[0] 81    	// GPIO6[0] 97    	// GPIO7[0] 113    	// GPIO8[0] 129	// 核心板 LED        GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT);  // GPIO6[12]        GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT);  // GPIO6[13]            // 底板 LED        GPIODirModeSet(SOC_GPIO_0_REGS, 1, GPIO_DIR_OUTPUT);    // D7  GPIO0[0]        GPIODirModeSet(SOC_GPIO_0_REGS, 2, GPIO_DIR_OUTPUT);    // D9  GPIO0[1]        GPIODirModeSet(SOC_GPIO_0_REGS, 3, GPIO_DIR_OUTPUT);    // D10 GPIO0[2]        GPIODirModeSet(SOC_GPIO_0_REGS, 6, GPIO_DIR_OUTPUT);    // D6  GPIO0[5]    }

 

GPIODirModeSet的原型gpio.c文件里面定义,相关输入参数如下

/**         * \brief    This function configures the direction of a pin as input or output.     *     * \param    baseAdd     The memory address of the GPIO instance being used.     * \param    pinNumber   The serial number of the GPIO pin.  The 144 GPIO pins have serial numbers from 1 to 144            * \param    pinDir      The direction to be set for the pin.  This can take the values:     *                       1> GPIO_DIR_INPUT, for configuring the pin as input.     *                       2> GPIO_DIR_OUTPUT, for configuring the pin as output.     *      * \return   None.     *     * \note     Here we write to the DIRn register. Writing a logic 1 configures      *           the pin as input and writing logic 0 as output. By default, all     *           the pins are set as input pins.     */    void GPIODirModeSet(unsigned int baseAdd, unsigned int pinNumber, unsigned int pinDir)    {        unsigned int regNumber = 0;        unsigned int pinOffset = 0;            /*        ** Each register contains settings for each pin of two banks. The 32 bits        ** represent 16 pins each from the banks. Thus the register number must be        ** calculated based on 32 pins boundary.        */        regNumber = (pinNumber - 1)/32;             /*        ** In every register the least significant bits starts with a GPIO number on        ** a boundary of 32. Thus the pin offset must be calculated based on 32        ** pins boundary. Ex: 'pinNumber' of 1 corresponds to bit 0 in         ** 'register_name01'.        */        pinOffset = (pinNumber - 1) % 32;            if(GPIO_DIR_OUTPUT == pinDir)        {            HWREG(baseAdd + GPIO_DIR(regNumber)) &= ~(1 << pinOffset);        }        else        {            HWREG(baseAdd + GPIO_DIR(regNumber)) |= (1 << pinOffset);        }    }

四、GPIO操作

作为通用的GPIO既可以输出高电平也可以输出低电平。由TL6748底板的原理图可知若想点亮LED需要将控制引脚置高,熄灭LED需要将控     制引脚置低。DSP的GPIO输出的高低电平可以由不同的寄存器控制,也可以使用同一个寄存器来实现。例程中使用了同一个寄存器来控制G   PIO输出的状态即:OUT_DATAn寄存器。GP0[0]的输出状态对应OUT_DATA01寄存器的第0位,对该位置1则可以在该管脚上输出高电平,反之清零该位即可在该脚上输出低电平。

GPIOPinWrite(SOC_GPIO_0_REGS, 1, GPIO_PIN_HIGH);   // D7  亮 GPIO0[0]Delay(0x00FFFFFF);GPIOPinWrite(SOC_GPIO_0_REGS, 1, GPIO_PIN_LOW);    // D7  灭 GPIO0[0]

GPIOPinWrite原型在gpio.c文件定义:

* \brief   This function writes a logic 1 or a logic 0 to the specified pin. * * \param   baseAdd    The memory address of the GPIO instance being used. * \param   pinNumber  The serial number of the GPIO pin. *                     The 144 GPIO pins have serial numbers from 1 to 144.  * * \param   bitValue   This signifies whether to write a logic 0 or logic 1  *                     to the specified pin.This variable can take any of the  *                     following two values: *                     1> GPIO_PIN_LOW, which indicates to clear(logic 0) the bit. *                     2> GPIO_PIN_HIGH, which indicates to set(logic 1) the bit. * * \return  None. * * \note    The pre-requisite to write to any pin is that the pin has to *          be configured as an output pin. */void GPIOPinWrite(unsigned int baseAdd, unsigned int pinNumber,                   unsigned int bitValue){    unsigned int regNumber = 0;    unsigned int pinOffset = 0;        /*    ** Each register contains settings for each pin of two banks. The 32 bits    ** represent 16 pins each from the banks. Thus the register number must be    ** calculated based on 32 pins boundary.    */     regNumber = (pinNumber - 1)/32;    /*    ** In every register the least significant bits starts with a GPIO number on    ** a boundary of 32. Thus the pin offset must be calculated based on 32    ** pins boundary. Ex: 'pinNumber' of 1 corresponds to bit 0 in     ** 'register_name01'.    */       pinOffset = (pinNumber - 1) % 32;    if(GPIO_PIN_LOW == bitValue)    {        HWREG(baseAdd + GPIO_CLR_DATA(regNumber)) = (1 << pinOffset);    }    else if(GPIO_PIN_HIGH == bitValue)    {        HWREG(baseAdd + GPIO_SET_DATA(regNumber)) = (1 << pinOffset);    }}

  

 

转载于:https://www.cnblogs.com/fengwantgb/p/4946238.html

你可能感兴趣的文章
apache服务器中设置目录不可访问
查看>>
嵌入式Linux驱动学习之路(十)字符设备驱动-my_led
查看>>
【NOIP模拟】密码
查看>>
java容器---------手工实现Linkedlist 链表
查看>>
three.js 性能优化的几种方法
查看>>
《梦断代码》读书笔记(三)
查看>>
FreeMarker解析json数据
查看>>
Java8 Lambda表达应用 -- 单线程游戏server+异步数据库操作
查看>>
次序+“选择不重复的记录”(3)——最大记录
查看>>
Codeforces 450 C. Jzzhu and Chocolate
查看>>
[Unity3D]Unity3D游戏开发MatchTarget的作用攀登效果实现
查看>>
ACdream 1115 Salmon And Cat (找规律&amp;&amp;打表)
查看>>
JSON、JSONP、Ajax的区别
查看>>
AngularJS学习篇(一)
查看>>
【转载】 IP实时传输协议RTP/RTCP详解
查看>>
关于Xshell无法连接centos6.4的问题
查看>>
Linux系统的数据写入机制--延迟写入
查看>>
css3动画——基本准则
查看>>
SQLite详解,案例,手册
查看>>
创建自己的内容提供器
查看>>