Hi all,

I'm a college student working on a project and I'm trying to use the
GPIO pins on the DC7 expansion connector.  I wrote a software program
that calls the EVMDM355_GPIO_init() function from the development
environment found at: http://c6000.spectrumdigital.com/evmdm355/revd/
under DM355 EVM Target Content.  The program looks like this:

/* Main.c is a test of the basic GPIO functions
 * Written by Charlie Reitsma
 ************************************************/
#include <stdio.h>
/* Include the header files for the dm355 interface */
#include "evmdm355.h"
#include "evmdm355_i2c.h"
#include "evmdm355_gpio.h"

int main(void)
{
        printf("I ran, I'm running");

        EVMDM355_init( );

//        EVMDM355_GPIO_getInput( 31 );

        return 0;

}


I compile it using "make" and the following Makefile:

ROOTDIR = ./

include $(ROOTDIR)/Rules.make

RELTARGET = release/$(TARGET)

# The prefix to be added before the GNU compiler tools (optionally including
# path), i.e. "arm_v5t_le-" or "/opt/bin/arm_v5t_le-".
MVTOOL_DIR=/opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le
MVTOOL_PREFIX=$(MVTOOL_DIR)/bin/arm_v5t_le-

all:  evmdm355.o evmdm355_gpio.o evmdm355_i2c.o main.o
        @echo Linking $@ from $^..
        $(MVTOOL_PREFIX)gcc -o GPIO_test main.o evmdm355.o evmdm355_gpio.o
evmdm355_i2c.o

main.o: evmdm355_gpio.h evmdm355_gpio.c evmdm355.h evmdm355.c
evmdm355_i2c.h evmdm355_i2c.c main.c
        @echo ======== Building $(TARGET) ========
        @echo Configuring application using
        $(MVTOOL_PREFIX)gcc -Wall -DDM355
-Dti_sdo_ce_osal_Memory_USEDEPRECATEDAPIS=1
-I$(LINUXKERNEL_INSTALL_DIR)/include -c main.c

evmdm355.o: evmdm355.h evmdm355.c
        @echo ======== Building $(TARGET) ========
        @echo Configuring application using $<
        $(MVTOOL_PREFIX)gcc -Wall -DDM355
-Dti_sdo_ce_osal_Memory_USEDEPRECATEDAPIS=1
-I$(LINUXKERNEL_INSTALL_DIR)/include -c evmdm355.c

evmdm355_i2c.o: evmdm355.h evmdm355.c evmdm355_i2c.c evmdm355_i2c.h
        @echo ======== Building $(TARGET) ========
        @echo Configuring application using $<
        $(MVTOOL_PREFIX)gcc -Wall -DDM355
-Dti_sdo_ce_osal_Memory_USEDEPRECATEDAPIS=1
-I$(LINUXKERNEL_INSTALL_DIR)/include -c evmdm355_i2c.c

evmdm355_gpio.o: evmdm355_gpio.h evmdm355_gpio.c evmdm355.h evmdm355.c
evmdm355_i2c.h evmdm355_i2c.c
        @echo ======== Building $(TARGET) ========
        @echo Configuring application using $<
        $(MVTOOL_PREFIX)gcc -Wall -DDM355
-Dti_sdo_ce_osal_Memory_USEDEPRECATEDAPIS=1
-I$(LINUXKERNEL_INSTALL_DIR)/include -c evmdm355_gpio.c

install:
        @echo
        @echo Installing $(TARGET) target files to $(EXEC_DIR)..
        $(VERBOSE) install -d $(EXEC_DIR)
        $(VERBOSE) install $(RELTARGET) $(EXEC_DIR)
        $(VERBOSE) install -m 444 $(TARGET).txt $(EXEC_DIR)
        
clean:
        @echo Removing generated files..
        \rm *.o *~ GPIO_test


When the EVMDM355_init( ); is called, the program gives me a segfault.
 Is there something else I need to do in order to read these GPIOs?
Thanks for any help you can give.  It's sincerely appreciated.

Charlie Reitsma

P.S.  Here are the files used in the program:

evmdm355_gpio.c:

/*
 *  Copyright 2005 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 */

/*
 *  GPIO implementation
 *
 */

#include "evmdm355_gpio.h"

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  _GPIO_init( )                                                           *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 EVMDM355_GPIO_init()
{
    /* Free GPIO from emulation */
    GPIO_PCR = 1;
    return 0;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  _GPIO_setDirection( number, direction )                                 *
 *                                                                          *
 *      number    <- GPIO#                                                  *
 *      direction <- 0:OUT 1:IN                                             *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 EVMDM355_GPIO_setDirection( Uint16 number, Uint8 direction )
{
    Uint32 bank_id = ( number >> 5 );
    Uint32 pin_id  = ( 1 << ( number & 0x1F ) );
    Uint32* gpio_dir = ( Uint32* )( GPIO_BASE + GPIO_DIR_BASE + (
bank_id * GPIO_BASE_OFFSET ) );

    if ( ( direction & 1 ) == GPIO_OUT )
        *gpio_dir &= ~( pin_id );  // Set to OUTPUT
    else
        *gpio_dir |= ( pin_id );   // Set to INPUT

    return 0;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  _GPIO_setOutput( number, output )                                       *
 *                                                                          *
 *      number   <- GPIO#                                                   *
 *      value    <- 0:LOW 1:HIGH                                            *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 EVMDM355_GPIO_setOutput( Uint16 number, Uint8 output )
{
    Uint32 bank_id = ( number >> 5 );
    Uint32 pin_id  = ( 1 << ( number & 0x1F ) );
    Uint32* gpio_out = ( Uint32* )( GPIO_BASE + GPIO_OUT_DATA_BASE + (
bank_id * GPIO_BASE_OFFSET ) );

    if ( ( output & 1 )  == 0 )
        *gpio_out &= ~( pin_id );  // Set to LOW
    else
        *gpio_out |= ( pin_id );   // Set to HIGH

    return 0;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  _GPIO_getInput( number )                                                *
 *                                                                          *
 *      number   <- GPIO#                                                   *
 *                                                                          *
 *      Returns:    0:LOW                                                   *
 *                  1:HIGH                                                  *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 EVMDM355_GPIO_getInput( Uint16 number )
{
    Uint32 input;
    Uint32 bank_id = ( number >> 5 );
    Uint32 pin_id  = ( number & 0x1F );
    Uint32* gpio_in = ( Uint32* )( GPIO_BASE + GPIO_IN_DATA_BASE + (
bank_id * GPIO_BASE_OFFSET ) );

    input = *gpio_in;
    input = ( input >> pin_id ) & 1;

    return input;
}




evmdm355_gpio.h:

/*
 *  Copyright 2005 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 */

/*
 *  GPIO header file
 *
 */

#ifndef GPIO_
#define GPIO_

#include "evmdm355.h"

#define GPIO_IN                 1
#define GPIO_OUT                0

#define GPIO0                   0x00
#define GPIO1                   0x01
#define GPIO2                   0x02
#define GPIO3                   0x03
#define GPIO4                   0x04
#define GPIO5                   0x05
#define GPIO6                   0x06
#define GPIO7                   0x07
#define GPIO8                   0x08
#define GPIO9                   0x09

#define GPIO10                  0x0A
#define GPIO11                  0x0B
#define GPIO12                  0x0C
#define GPIO13                  0x0D
#define GPIO14                  0x0E
#define GPIO15                  0x0F
#define GPIO16                  0x10
#define GPIO17                  0x11
#define GPIO18                  0x12
#define GPIO19                  0x13

#define GPIO20                  0x14
#define GPIO21                  0x15
#define GPIO22                  0x16
#define GPIO23                  0x17
#define GPIO24                  0x18
#define GPIO25                  0x19
#define GPIO26                  0x1A
#define GPIO27                  0x1B
#define GPIO28                  0x1C
#define GPIO29                  0x1D

#define GPIO30                  0x1E
#define GPIO31                  0x1F
#define GPIO32                  0x20
#define GPIO33                  0x21
#define GPIO34                  0x22
#define GPIO35                  0x23
#define GPIO36                  0x24
#define GPIO37                  0x25
#define GPIO38                  0x26
#define GPIO39                  0x27

#define GPIO40                  0x28
#define GPIO41                  0x29
#define GPIO42                  0x2A
#define GPIO43                  0x2B
#define GPIO44                  0x2C
#define GPIO45                  0x2D
#define GPIO46                  0x2E
#define GPIO47                  0x2F
#define GPIO48                  0x30
#define GPIO49                  0x31

#define GPIO50                  0x32
#define GPIO51                  0x33
#define GPIO52                  0x34
#define GPIO53                  0x35

#define GPIO3V3_0               0x36
#define GPIO3V3_1               0x37
#define GPIO3V3_2               0x38
#define GPIO3V3_3               0x39
#define GPIO3V3_4               0x3A
#define GPIO3V3_5               0x3B
#define GPIO3V3_6               0x3C
#define GPIO3V3_7               0x3D
#define GPIO3V3_8               0x3E
#define GPIO3V3_9               0x3F

#define GPIO3V3_10              0x40
#define GPIO3V3_11              0x41
#define GPIO3V3_12              0x42
#define GPIO3V3_13              0x43
#define GPIO3V3_14              0x44
#define GPIO3V3_15              0x45

/* ------------------------------------------------------------------------ *
 *  Prototypes                                                              *
 * ------------------------------------------------------------------------ */
Int16 EVMDM355_GPIO_init         ( );
Int16 EVMDM355_GPIO_setDirection ( Uint16 number, Uint8 direction );
Int16 EVMDM355_GPIO_setOutput    ( Uint16 number, Uint8 output );
Int16 EVMDM355_GPIO_getInput     ( Uint16 number );

#endif
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to