/*============================================================
File name: SetGpio.c

Originator: XXW THU

Description: define the functions related with SetGpio

Reference: none

============================================================
History:
------------------------------------------------------------
2017-07-20 Version 1.0
------------------------------------------------------------*/


#include "DSP28x_Project.h" 
#include "C28x_FPU_FastRTS.h"
#include <math.h>
#include "SetGpio.h"


//======== Definations for functions ===========================
//**********************************
/*
  @ Description:
  @ Param
  @ Return
*/
//**********************************
void gpioset(void)
{
	EALLOW;
	// 配置GPIO24、25、26、27分别为输入信号

    GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0;    // 使能GPIO24 引脚内部上拉
    GpioCtrlRegs.GPAPUD.bit.GPIO25 = 0;    // 使能GPIO25 引脚内部上拉
    GpioCtrlRegs.GPAPUD.bit.GPIO26 = 0;    // 使能GPIO26 引脚内部上拉
    GpioCtrlRegs.GPAPUD.bit.GPIO27 = 0;    // 使能GPIO27 引脚内部上拉

    /* 通过I/O功能选择寄存器配置通用I/O功能*/

    GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 0;   // 配置GPIO24为通用I/O口
    GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 0;   // 配置GPIO25为通用I/O口
    GpioCtrlRegs.GPAMUX2.bit.GPIO26 = 0;   // 配置GPIO26为通用I/O口
    GpioCtrlRegs.GPAMUX2.bit.GPIO27 = 0;   // 配置GPIO27为通用I/O口

    //设置I/O口为输入引脚
    GpioCtrlRegs.GPADIR.bit.GPIO24 = 0;   // 配置GPIO24为输入引脚
    GpioCtrlRegs.GPADIR.bit.GPIO25 = 0;   // 配置GPIO25为输入引脚
    GpioCtrlRegs.GPADIR.bit.GPIO26 = 0;   // 配置GPIO26为输入引脚
    GpioCtrlRegs.GPADIR.bit.GPIO27 = 0;   // 配置GPIO27为输入引脚

    //设置输入限定
    GpioCtrlRegs.GPAQSEL2.bit.GPIO24= 2;    // GPIO23与系统时钟SYSCLKOUT 同步，采用6次采样的采样窗
    GpioCtrlRegs.GPAQSEL2.bit.GPIO25= 2;    // GPIO24与系统时钟SYSCLKOUT 同步，采用6次采样的采样窗
    GpioCtrlRegs.GPAQSEL2.bit.GPIO26= 2;    // GPIO25与系统时钟SYSCLKOUT 同步，采用6次采样的采样窗
    GpioCtrlRegs.GPAQSEL2.bit.GPIO27= 2;    // GPIO26与系统时钟SYSCLKOUT 同步，采用6次采样的采样窗



//   // 配置外部中断引脚
//   GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 24;   // XINT1 is GPIO24
//   GpioIntRegs.GPIOXINT2SEL.bit.GPIOSEL = 25;   // XINT2 is GPIO25
//   GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 24;   // XINT1 is GPIO24
//   GpioIntRegs.GPIOXINT2SEL.bit.GPIOSEL = 25;   // XINT2 is GPIO25
//
//   XIntruptRegs.XINT1CR.bit.POLARITY = 1;      // Rising edge interrupt
//   XIntruptRegs.XINT1CR.bit.ENABLE = 1;        // Enable XINT2
//
//   XIntruptRegs.XINT2CR.bit.POLARITY = 1;      // Rising edge interrupt
//   XIntruptRegs.XINT2CR.bit.ENABLE = 1;        // Enable XINT2
//
//   XIntruptRegs.XINT1CR.bit.POLARITY = 1;      // Rising edge interrupt
//   XIntruptRegs.XINT1CR.bit.ENABLE = 1;        // Enable XINT2
//
//   XIntruptRegs.XINT1CR.bit.POLARITY = 1;      // Rising edge interrupt
//   XIntruptRegs.XINT1CR.bit.ENABLE = 1;        // Enable XINT2

   // 配置GPIO33、39为输出
   GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0;  // Enable pullup on GPIO33
   GpioDataRegs.GPBSET.bit.GPIO33= 1;  // Load output latch
   GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 0; // GPIO33 = GPIO33
   GpioCtrlRegs.GPBDIR.bit.GPIO33= 1;  // GPIO33 = output

   GpioDataRegs.GPBSET.bit.GPIO36= 1;  // Load output latch
   GpioCtrlRegs.GPBMUX1.bit.GPIO36 = 0; // GPIO36 = GPIO36
   GpioCtrlRegs.GPBDIR.bit.GPIO36= 1;  // GPIO36 = output

   GpioCtrlRegs.GPBPUD.bit.GPIO39 = 0;  // Enable pullup on GPIO39
   GpioDataRegs.GPBSET.bit.GPIO39= 1;  // Load output latch
   GpioCtrlRegs.GPBMUX1.bit.GPIO39 = 0; // GPIO39 = GPIO39
   GpioCtrlRegs.GPBDIR.bit.GPIO39= 1;  // GPIO39 = output

   EDIS;
}



//==============================================================
//End of file.
//==============================================================

