/* ============================================================================ * Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005, 2008 * * 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_Input_Pin_Example.c * * @brief Test code to verify the input functionality of GPIO module * * \page page3 GPIO EXAMPLE DOCUMENTATION * * \section GPIO2 GPIO EXAMPLE2 - INPUT PIN TEST * * \subsection GPIO2x TEST DESCRIPTION: * This example code tests the GPIO(General Purpose Input Output) pin * functionality as input pin. * C5505 DSP is having 32 GPIO pins which can be configured as input or output. * GPIO pin 11 is configured as input pin by this test code. For verifying the * input functionality, a source is required which sends data to the GPIO pin * configured as input pin. GPIO pin 4 is configured as output pin and is used * as data source for pin 11. These two pins should be connected with a jumper * on the EVM to facilitate the data loop back. Interrupts are enabled for the * GPIO input pin to indicate the high signal on the input pin.A data value 1 * is written to the GPIO pin4 which is loop backed to the pin11 and is read in * the ISR. Test will be successful when the GPIO interrupt for pin11 is * generated. Value read from the pin11 is also compared with the value * written to the pin4 to announce the success of the test. * * NOTE: PIN 1(GPIO_4) AND 2(GPIO_11) OF J22 ON C5505 EVM SHOULD BE CONNECTED * WITH JUMPER BEFORE RUNNING THIS TEST CODE. * * \subsection GPIO2y TEST PROCEDURE: * @li Open the CCS and connect the target (C5505 EVM) * @li Open the project "CSL_GPIO_InputPinExample.pjt" and build it * @li Load the program on to the target * @li Set the PLL frequency to 12.288MHz * @li Run the program and observe the test result * @li Repeat the test at PLL frequencies 40, 60, 75 and 100MHz * @li Repeat the test in Release mode * * \subsection GPIO2z TEST RESULT: * @li All the CSL APIs should return success * @li An Interrupt should be generated for GPIO Pin11 * @li Value read from the GPIO pin 11 should match with the value written to * GPIO pin 4. * * */ /* ============================================================================ * Revision History * ================ * 26-Sep-2008 - Created * 28-Jun-2009 - Added Documentation * ============================================================================ */ #include "csl_gpio.h" #include "csl_intc.h" #include "csl_gpt.h" #include #define CSL_TEST_FAILED (1u) #define CSL_TEST_PASSED (0) #define CSL_PLL_DIV_000 (0) #define CSL_PLL_DIV_001 (1u) #define CSL_PLL_DIV_002 (2u) #define CSL_PLL_DIV_003 (3u) #define CSL_PLL_DIV_004 (4u) #define CSL_PLL_DIV_005 (5u) #define CSL_PLL_DIV_006 (6u) #define CSL_PLL_DIV_007 (7u) #define CSL_PLL_CLOCKIN (32768u) extern void VECSTART(void); /* Global Structure Declaration */ CSL_GpioObj GpioObj; CSL_GpioObj *hGpio; CSL_TimRegsOvly regPtr; ioport volatile Uint16 *iafrReg; int i = 0; Uint16 readVal = 0; int writeVal=0; /* Reference the start of the interrupt vector table */ /* This symbol is defined in file vectors.asm */ extern void VECSTART(void); int gpio_input_int_test(void); Int16 CSL_gptCountinterrupt(void); interrupt void gpt0Isr(void); void main(void) { int result; printf("CSL GPIO Input Pin Test!\n\n"); /* To test GPIO channel (pin) as an input channel in interrupt mode */ result = gpio_input_int_test(); if(CSL_TEST_PASSED == result) { printf("\nCSL GPIO Input Pin Test Passed!!\n"); } else { printf("\nCSL GPIO Input Pin Test Failed!!\n"); } result = CSL_gptCountinterrupt(); if(CSL_TEST_FAILED == result) { printf("TIMER COUNT READ TEST FAILED!!\n"); } else { printf("TIMER COUNT READ TEST PASSED!!\n"); } } int gpio_input_int_test(void) { CSL_Status status; CSL_GpioPinConfig config; CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_SP1MODE, MODE2); hGpio = GPIO_open(&GpioObj,&status); if((NULL == hGpio) || (CSL_SOK != status)) { printf("GPIO_open failed\n"); return(CSL_TEST_FAILED); } else { printf("GPIO_open Successful\n"); } /* Reset the GPIO module */ GPIO_reset(hGpio); config.pinNum = CSL_GPIO_PIN11; config.direction = CSL_GPIO_DIR_OUTPUT; config.trigger = CSL_GPIO_TRIG_CLEAR_EDGE; status = GPIO_configBit(hGpio,&config); if(CSL_SOK != status) { printf("test failed - GPIO_configBit\n"); return(CSL_TEST_FAILED); } else { printf("GPIO PIN11 is configured as Output Pin\n"); } return (CSL_TEST_PASSED); } Int16 CSL_gptCountinterrupt(void) { CSL_Handle hGpt; CSL_Status status; CSL_Config hwConfig; CSL_GptObj gptObj; status = 0; /* Open the CSL GPT_0 module */ hGpt = GPT_open (GPT_0, &gptObj, &status); if((NULL == hGpt) || (CSL_SOK != status)) { printf("GPT Open Failed\n"); return (CSL_TEST_FAILED); } else { printf("GPT Open Successful\n"); } /* Reset the GPT module */ status = GPT_reset(hGpt); if(CSL_SOK != status) { printf("GPT Reset Failed\n"); return (CSL_TEST_FAILED); } else { printf("GPT Reset Successful\n"); } /* Clear any pending interrupts */ IRQ_clearAll(); /* Disable all the interrupts */ IRQ_disableAll(); IRQ_setVecs((Uint32)(&VECSTART)); IRQ_plug(TINT_EVENT, &gpt0Isr); IRQ_enable(TINT_EVENT); hwConfig.autoLoad = GPT_AUTO_ENABLE; hwConfig.ctrlTim = GPT_TIMER_ENABLE; hwConfig.preScaleDiv = GPT_PRE_SC_DIV_1; hwConfig.prdLow = 0x7840; hwConfig.prdHigh = 0x017D; /* Configure the GPT module */ status = GPT_config(hGpt, &hwConfig); if(CSL_SOK != status) { printf("GPT Config Failed\n"); return (CSL_TEST_FAILED); } else { printf("GPT Config Successful\n"); } /* Enable CPU Interrupts */ IRQ_globalEnable(); /* Start the Timer */ status = GPT_start(hGpt); if(CSL_SOK != status) { printf("GPT Start Failed\n"); return (CSL_TEST_FAILED); } for (i=1;i<10000;); { printf("i= %d \n", i); } /* Disable the CPU interrupts */ IRQ_globalDisable(); /* Clear any pending interrupts */ IRQ_clearAll(); /* Disable all the interrupts */ IRQ_disableAll(); /* Stop the Timer */ status = GPT_stop(hGpt); if(CSL_SOK != status) { printf("GPT Stop Failed \n"); return (CSL_TEST_FAILED); } else { printf("GPT Stop Successful\n"); } status = GPT_reset(hGpt); /* Close The GPT Module */ status = GPT_close(hGpt); if(CSL_SOK != status) { printf("GPT Close Failed\n"); return (CSL_TEST_FAILED); } return (CSL_TEST_PASSED); } interrupt void gpt0Isr(void) { { if (writeVal==0) /* (hGpio->baseAddr->IOOUTDATA1==0x0800) */ { writeVal=1; CSL_FINSR (hGpio->baseAddr->IOOUTDATA1,CSL_GPIO_PIN11,CSL_GPIO_PIN11,1); printf("writeVal= %d \n", writeVal); } else { writeVal=0; CSL_FINSR (hGpio->baseAddr->IOOUTDATA1,CSL_GPIO_PIN11,CSL_GPIO_PIN11,0); printf("writeVal= %d \n", writeVal); } printf("GPT pulse successfully\n"); i++; IRQ_clear(TINT_EVENT); } }