📄 gpio_example.c
字号:
/* ============================================================================
* Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005, 2006, 2007
*
* Use of this software is controlled by the terms and conditions found
* in the license agreement under which this software has been supplied.
* ============================================================================
*/
/** ============================================================================
*
* @file Gpio_example.c
*
* @path (CSL_EXAMPLE_PATH)\example\dm648\gpio\src
*
* @desc example for GPIO Register layer usage.
*
* =============================================================================
* @n Target Platform: EVM
* ============================================================================
* @n <b> Example Description </b>
* @verbatim
This Example,
1. Write 1 (high) to GPIO pin 8 and then read it back to verify
2. Write 0 (low) to GPIO pin 8 and then read it back to verify
*
* =============================================================================
*
* <b> Procedure to run the example </b>
* @verbatim
* 1. Configure the CCS setup to work with the emulator being used
* 2. Please refer CCS manual for setup configuration and loading
* proper GEL file
* 3. Launch CCS window
* 4. Open project GPIO_example.pjt
* 5. Build the project and load the .out file of the project.
*
* @endverbatim
*
*/
/* =============================================================================
* Revision History
* ===============
*
* 22-March-2007 File Created.
*
* =============================================================================
*/
#include <tistdtypes.h>
#include <soc.h>
#include <cslr_sys.h>
#include <cslr_psc.h>
#include <cslr_gpio.h>
#include <stdio.h>
/*
* =============================================================================
* @func sw_wait
*
* @desc
* This is the delay routine.
*
* =============================================================================
*/
void sw_wait (int delay)
{
volatile int i;
for( i = 0; i < delay; i++ ) {
}
}
/*
* =============================================================================
* @func test_GPIO
*
* @desc
* This is the example code for GPIO register layer macro usage.
*
* =============================================================================
*/
void test_GPIO (void)
{
/* Pointer to register overlay structure for PSC */
CSL_PscRegsOvly pscRegs = (CSL_PscRegsOvly)CSL_PSC_0_REGS;
/* Pointer to register overlay structure for GPIO */
CSL_GpioRegsOvly gpioRegs = (CSL_GpioRegsOvly)CSL_GPIO_0_REGS;
/* enable GPIO LPSC*/
pscRegs->MDCTL[CSL_PSC_GPIO] = CSL_FMKT(PSC_MDCTL_NEXT, ENABLE) |
CSL_FMKT(PSC_MDCTL_LRST, DEASSERT);
pscRegs->PTCMD = CSL_FMKT(PSC_PTCMD_GO0, SET);
while (CSL_FEXT(pscRegs->MDSTAT[CSL_PSC_GPIO], PSC_MDSTAT_STATE)
!= CSL_PSC_MDSTAT_STATE_ENABLE);
/* Configure pin 8 as an output, then set the data High (Low->High).*/
CSL_FINS(gpioRegs->DIR01, GPIO_DIR01_DIR8, CSL_GPIO_DIR01_DIR8_OUT);
/* Set Data high in SET_DATA register*/
gpioRegs->SET_DATA01 =
CSL_FMK(GPIO_SET_DATA01_SET8, CSL_GPIO_SET_DATA01_SET8_SET);
sw_wait(10);
/* read IN_DATA*/
if (CSL_FEXT(gpioRegs->IN_DATA01, GPIO_IN_DATA01_IN8)
!= CSL_GPIO_IN_DATA01_IN8_HIGH) {
printf("Driving GPIO8 high failed!\n" );
return;
}
sw_wait(10);
/* Set Data low in CLR_DATA register*/
gpioRegs->CLR_DATA01 =
CSL_FMK(GPIO_CLR_DATA01_CLR8, CSL_GPIO_CLR_DATA01_CLR8_CLEAR);
sw_wait(10);
/* read IN_DATA*/
if (CSL_FEXT( gpioRegs->IN_DATA01, GPIO_IN_DATA01_IN8) !=
CSL_GPIO_IN_DATA01_IN8_LOW) {
printf("Driving GPIO8 low failed!\n" );
return;
}
printf( "Test of GPIO8 is successful!\n" );
}
/*
* =============================================================================
* @func main
*
* @desc
* This is the main routine for the file.
*
* =============================================================================
*/
void main (void)
{
test_GPIO( );
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -