void gpioInit() { //--------------NOTE------------------ // FOR GPIOs TO WORK ON C6713 DSK SPECTRUM DIGITAL BOARD // SWITCH 4 OF THE DIPSWITCH SW3 (NOT SW1!!!) HAS TO BE ON-CLOSED //--------------NOTE------------------ GPIO_Config gpio_config = { 0x00000000, /* gpgc */ 0x0000FFFF, /* gpen --*/ 0x00000000, /* gdir -*/ 0x00000000, /* gpval */ 0x00000000, /* gphm all interrupts disabled for io pins */ 0x00000000, /* gplm all interrupts to cpu or edma disabled */ 0x00000000 /* gppol -- default state */ }; hGpio = GPIO_open( GPIO_DEV0, GPIO_OPEN_RESET ); GPIO_config(hGpio , &gpio_config ); /* Enables pins */ GPIO_pinEnable (hGpio, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN13);//enable here or in MyConfig GPIO_pinDirection(hGpio,GPIO_PIN0, GPIO_OUTPUT); // CS GPIO_pinDirection(hGpio,GPIO_PIN1, GPIO_OUTPUT); GPIO_pinDirection(hGpio,GPIO_PIN2, GPIO_OUTPUT); GPIO_pinDirection(hGpio,GPIO_PIN3, GPIO_OUTPUT); // MOSI GPIO_pinDirection(hGpio,GPIO_PIN13, GPIO_OUTPUT); // SCK GPIO_pinDirection(hGpio,GPIO_PIN8, GPIO_INPUT); // MISO GPIO_pinDirection(hGpio,GPIO_PIN9, GPIO_INPUT); // GDO0 }
/* * ======== SENSORTAG_CC2650_initGPIO ======== */ Void SENSORTAG_CC2650_initGPIO(Void) { Bits32 pin; /* Power up the GPIO module. */ GPIO_open(); /* Setup the LED1 (red) GPIO pin. */ pin = gpioHWAttrs[SENSORTAG_CC2650_LED1].pin; IOCPortConfigureSet(PIN2IOID(pin), IOC_PORT_GPIO, IOC_STD_OUTPUT); GPIODirModeSet(pin, GPIO_DIR_MODE_OUT); /* Setup the LED2 (green) GPIO pin. */ pin = gpioHWAttrs[SENSORTAG_CC2650_LED2].pin; IOCPortConfigureSet(PIN2IOID(pin), IOC_PORT_GPIO, IOC_STD_OUTPUT); GPIODirModeSet(pin, GPIO_DIR_MODE_OUT); /* Setup the Button1 GPIO pin. */ pin = gpioHWAttrs[SENSORTAG_CC2650_BUTTON1].pin; IOCPortConfigureSet(PIN2IOID(pin), IOC_PORT_GPIO, IOC_STD_INPUT); GPIODirModeSet(pin, GPIO_DIR_MODE_IN); IOCIOPortPullSet(PIN2IOID(pin), IOC_IOPULL_UP); /* Setup the Button2 GPIO pin. */ pin = gpioHWAttrs[SENSORTAG_CC2650_BUTTON2].pin; IOCPortConfigureSet(PIN2IOID(pin), IOC_PORT_GPIO, IOC_STD_INPUT); GPIODirModeSet(pin, GPIO_DIR_MODE_IN); IOCIOPortPullSet(PIN2IOID(pin), IOC_IOPULL_UP); /* Setup the Reed relay GPIO pin. */ pin = gpioHWAttrs[SENSORTAG_CC2650_REED_INT].pin; IOCPortConfigureSet(PIN2IOID(pin), IOC_PORT_GPIO, IOC_STD_INPUT); GPIODirModeSet(pin, GPIO_DIR_MODE_IN); IOCIOPortPullSet(PIN2IOID(pin), IOC_IOPULL_DOWN); /* Setup the FLASH_CS pin. */ pin = gpioHWAttrs[SENSORTAG_CC2650_FLASH_CS].pin; IOCPortConfigureSet(PIN2IOID(pin), IOC_PORT_GPIO, IOC_STD_OUTPUT); GPIODirModeSet(pin, GPIO_DIR_MODE_OUT); IOCIOPortPullSet(PIN2IOID(pin), IOC_NO_IOPULL); /* Setup the BUZZER_EN pin. */ pin = gpioHWAttrs[SENSORTAG_CC2650_BUZZER_EN].pin; IOCPortConfigureSet(PIN2IOID(pin), IOC_PORT_GPIO, IOC_STD_OUTPUT); GPIODirModeSet(pin, GPIO_DIR_MODE_OUT); /* Setup the MPU_POWER GPIO pin. */ pin = gpioHWAttrs[SENSORTAG_CC2650_MPU_POWER].pin; IOCPortConfigureSet(PIN2IOID(pin), IOC_PORT_GPIO, IOC_STD_OUTPUT); GPIODirModeSet(pin, GPIO_DIR_MODE_OUT); /* Setup the MPU_INT GPIO pin. */ pin = gpioHWAttrs[SENSORTAG_CC2650_MPU_INT].pin; IOCPortConfigureSet(PIN2IOID(pin), IOC_PORT_GPIO, IOC_STD_INPUT); GPIODirModeSet(pin, GPIO_DIR_MODE_IN); IOCIOPortPullSet(PIN2IOID(pin), IOC_IOPULL_DOWN); /* Setup the TMP_RDY GPIO pin. */ pin = gpioHWAttrs[SENSORTAG_CC2650_TMP_RDY].pin; IOCPortConfigureSet(PIN2IOID(pin), IOC_PORT_GPIO, IOC_STD_INPUT); GPIODirModeSet(pin, GPIO_DIR_MODE_IN); /* Once GPIO_init is called, GPIO_config cannot be changed */ GPIO_init(); /* Set some of the IO pins */ GPIO_write(SENSORTAG_CC2650_LED1, SENSORTAG_CC2650_LED_OFF); GPIO_write(SENSORTAG_CC2650_LED2, SENSORTAG_CC2650_LED_OFF); GPIO_write(SENSORTAG_CC2650_MPU_POWER, SENSORTAG_CC2650_MPU_POWER_ON); GPIO_write(SENSORTAG_CC2650_MIC_POWER, SENSORTAG_CC2650_MIC_POWER_OFF); GPIO_write(SENSORTAG_CC2650_FLASH_CS, SENSORTAG_CC2650_FLASH_CS_OFF); }
/* * * USBSTK5505_GPIO_init( ) * * Description * Initialize GPIO Mudule. * */ Int16 USBSTK5505_GPIO_init() { CSL_Status status; hGpio = GPIO_open(&GpioObj,&status); return 0; }
int main(int argc, char *const *argv) { int r = 0; int s = 0; int opts_index = 0; int lcd_off = 0; int verbose = 0; char *colour_string = 0; char *cursor_string = 0; char *short_opts = "hc:u:v"; struct option long_opts[] = { {"off", no_argument, &lcd_off, 1}, {"verbose", no_argument, &verbose, 1}, {"help", no_argument, NULL, 'h'}, {"colour", required_argument, NULL, 'c'}, {"cursor", required_argument, NULL, 'u'}, {0, 0, 0, 0} }; GPIO_open(); LCD_init(0); while ((s = getopt_long(argc, argv, short_opts, long_opts, &opts_index)) != -1) { switch (s) { case 'h': print_help(); break; case 'c': r += set_colour(optarg); colour_string = optarg; break; case 'u': cursor_string = optarg; r += set_cursor(optarg); break; case 'v': verbose = 1; case '?': break; } }; /* printing off the remaining arguments */ int optind_old = optind; int n = 0; if (optind < argc) { while (optind < argc) { n += LCD_wrap_printf("%s ", argv[optind++]); } LCD_cursor_move(-1); optind = optind_old; } else if (!lcd_off) { int c; int n = 0; while ((c = getchar()) != EOF) { if (n == LCD_LENGTH) { LCD_putchar('\n'); n = 0; } LCD_putchar(c); n++; } } else { LCD_off(); } /* verbose flag print off more messages */ if (verbose) { if (colour_string) { printf("Setting LCD colour to: %s\n", colour_string); } if (cursor_string) { printf("Setting cursor to: %s\n", cursor_string); } printf("Printed %d characters: \n", n); while (optind < argc) { printf("%s ", argv[optind++]); } printf("\n"); if (lcd_off) { printf("Turning off LCD\n"); } } return r; }
/** * \brief Tests the configuration of the CSL GPIO module * * This function configures the CSL GPIO module using GPIO_config API. * Configured values are verified by reading back using the CSL function * GPIO_getConfig. * * \param none * * \return Test result */ int gpio_pin_config_test(void) { CSL_Status status; CSL_GpioConfig config; CSL_GpioConfig getConfig; /* Pin Muxing for GPIO Pins * Make Serial port 0 and 1 parallel port 8 pin * and A15 to A20 pin as GPIO */ CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_SP0MODE, MODE2); CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_SP1MODE, MODE2); CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_PPMODE, MODE1); CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_A20_MODE, MODE1); CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_A19_MODE, MODE1); CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_A18_MODE, MODE1); CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_A17_MODE, MODE1); CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_A16_MODE, MODE1); CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_A15_MODE, MODE1); /* Open GPIO module */ 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 all the pins */ GPIO_reset(hGpio); /* Configure the GPIO module */ config.GPIODIRL = 0xffff; config.GPIODIRH = 0x07e3; config.GPIOINTENAL = 0x0000; config.GPIOINTENAH = 0x0000; config.GPIOINTTRIGL = 0x0000; config.GPIOINTTRIGH = 0x0000; status = GPIO_config(hGpio, &config); if(CSL_SOK != status) { printf("GPIO_config failed\n"); return(CSL_TEST_FAILED); } else { printf("GPIO_config Successful\n"); } /* Read the configured values */ status = GPIO_getConfig(hGpio, &getConfig); if(CSL_SOK != status) { printf("GPIO_getConfig failed\n"); return CSL_TEST_FAILED; } else { printf("GPIO_getConfig Successful\n"); } /* Compare the configuration values */ if((getConfig.GPIODIRL != config.GPIODIRL) || (getConfig.GPIODIRH != config.GPIODIRH) || (getConfig.GPIOINTENAL != config.GPIOINTENAL) || (getConfig.GPIOINTENAH != config.GPIOINTENAH) || (getConfig.GPIOINTTRIGL != config.GPIOINTTRIGL) || (getConfig.GPIOINTTRIGH != config.GPIOINTTRIGH)) { printf("Configuration Comparison Failed\n"); /////INSTRUMENTATION FOR BATCH TESTING -- Part 2 -- ///// Reseting PaSs_StAtE to 0 if error detected here. PaSs_StAtE = 0x0000; // Was intialized to 1 at declaration. ///// } else { printf("Configuration Comparison Successful\n"); } /* Close the GPIO module */ status = GPIO_close(hGpio); if(CSL_SOK != status) { printf("GPIO_close failed\n"); return(CSL_TEST_FAILED); } return(CSL_TEST_PASSED); }
/** * \brief Function to test the functionality of GPIO as output pin * * This function configures GPIO pin 0 as output pin and writes a value. * Written value is verified and result is returned to the main function * * \param none * * \return Test result */ int gpio_output_pin_test(void) { CSL_Status status; CSL_GpioPinConfig config; Uint16 writeVal; Uint16 readVal; writeVal = 0; /* Pin Muxing gor GPIO Pins - * Make Serial port 0 and 1, parallel port's 8 pin and * A15 to A20 pin as GPIO */ CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_SP0MODE, MODE2); /* Open GPIO module */ 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 all the pins */ GPIO_reset(hGpio); /* Configure GPIO pin 0 as output pin */ config.pinNum = CSL_GPIO_PIN0; config.direction = CSL_GPIO_DIR_OUTPUT; config.trigger = CSL_GPIO_TRIG_CLEAR_EDGE; status = GPIO_configBit(hGpio, &config); if(CSL_SOK != status) { printf("GPIO_configBit failed\n"); return(CSL_TEST_FAILED); } /* Write 1 to output pin */ status = GPIO_write(hGpio, CSL_GPIO_PIN0, writeVal); if(CSL_SOK != status) { printf("GPIO_write Failed\n"); return(CSL_TEST_FAILED); } else { printf("GPIO_write Successful\n"); } /* Read pin No 0 - to check data written is equal to data read */ status = GPIO_read(hGpio, CSL_GPIO_PIN0, &readVal); if(CSL_SOK != status) { printf("GPIO_read failed\n"); return(CSL_TEST_FAILED); } else { printf("GPIO_read Successful\n"); } /* Compare the value read and value written */ if(writeVal == readVal) { printf("Data read is same as data written\n"); } else { printf("Data read is not same as data written \n"); return(CSL_TEST_FAILED); } /* Close the GPIO module */ status = GPIO_close(hGpio); if(CSL_SOK != status) { printf("GPIO_close failed\n"); return(CSL_TEST_FAILED); } return(CSL_TEST_PASSED); }