Difference between revisions of "Example egpc"

From wiki.emacinc.com
Jump to: navigation, search
(Using egpc)
 
(23 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{todo|InProgress(11.13.13-14:31->JG+)|Jgreene|project=oe 4,oe 5,jg,md,InProgress}}
+
{{todo|SEOKWREV - revise for 5.00 (12.27.13-14:22->JG+);(12.30.13-17:20->MD+);(01.02.14-11:20->KY+);(03.27.14-16:45->BS+);(04.10.14-12:20->BS+)|Jgreene|project=oe 4,oe 5,jg,md,bs,SEOKWREV}}
 +
 
 +
 
 +
{{#seo:
 +
|title=Example egpc
 +
|titlemode=append
 +
|keywords=Port Configuration,Port Data,Port Index,GPIO
 +
|description=This is a guide to the egpc C example project included in the EMAC OE SDK.
 +
}}
 
This is a guide to the <code>egpc</code> C example project included in the EMAC OE SDK.
 
This is a guide to the <code>egpc</code> C example project included in the EMAC OE SDK.
  
<code>egpc</code> is an application for reading/writing/configuring gpio character devices. Specifically, we read/write/configure the 3 ports (ports A, B and C) on the GPIO header.
+
<code>egpc</code> is an application for reading/writing/configuring gpio character devices. Specifically, it will read/write/configure the 3 ports (ports '''A''', '''B''' and '''C''') on the GPIO header.
  
 
The <code>egpc</code> project builds one executable: <code>egpc</code>.
 
The <code>egpc</code> project builds one executable: <code>egpc</code>.
Line 8: Line 16:
 
== Opening, Building and Uploading the Project Files ==
 
== Opening, Building and Uploading the Project Files ==
  
<big>1. Open the C/C++ editing perspective.</big>
+
For information on opening the project from within Eclipse, please see [[Importing the EMAC OE SDK Projects with Eclipse]].  Then, follow [[Using the EMAC OE SDK Projects with Eclipse]] for information on how to build, upload and execute the example.
 +
 
 +
Alternatively, the <code>Makefile</code> can be used with the <code>make</code> command from the commandline to build and upload the example.  For more information on this method, please see [[Using EMAC OE SDK Example Projects]].
 +
 
 +
==Usage and Behavior==
 +
 
 +
<code>egpc</code> reads/writes/configures the GPIO ports.
 +
 
 +
===Hardware Requirements===
 +
 
 +
The <code>egpc</code> C example project will run on any EMAC carrier board which has one or more GPIO.
  
stub
+
===Using <code>egpc</code>===
  
<big>2. Open the project files.</big>
+
./egpc ''device'' ''[d/c/i]'' ''arg''
  
stub
+
''device'' is <code>/dev/porta</code>, <code>/dev/portb</code> or <code>/dev/portc</code><br />
 +
''d/c/i'' specifies the port command : <code>d</code> (data), <code>c</code> (configure) or <code>i</code> (index)<br />
 +
''arg'' is either a port index or a bitmask. The bitmask is in hex format, range <code>[0x00,0xff]</code>.
  
<big>3. Build the project.</big>
+
===Usage Example. Port Configuration===
  
stub
+
./egpc ''device'' c ''[mask]''
  
<big>4. Upload the executables to the target system.</big>
+
If a mask is specified, it configures the pins for input/output.<br />
 +
If no mask is specified, it returns the current configuration.<br /> 
 +
''mask'' is an input/output bitmask. <code>1</code>=output and <code>0</code>=input.<br />                    
 +
For example, this sets every other pin on '''Port A''' to be an output.
 +
                                       
 +
./egpc /dev/porta c 0xaa
  
stub
+
...and this reads the current pin configuration state of '''Port A'''.
  
==Usage and Behavior==
+
./egpc /dev/porta c   
 +
0xaa
 +
 
 +
===Usage Example: Port Data===
 +
 
 +
./egpc device d ''[mask]''
  
<code>egpc</code> reads/writes/configures the GPIO ports. 
+
If a mask is specified then it sets each bit's corresponding pin output latch to high/low accordingly.<br />
 +
If a mask is not specified then the current pin state is retrieved.<br />
  
===Hardware Requirements===
+
For example, this writes pin output latches on '''Port C''' to alternating high and low.
  
The <code>egpc</code> C example project will run on any EMAC carrier board.
+
./egpc /dev/portc d 0x55
  
===Using <code>egpc</code>===
+
This flips the pins, writing all the pins that were set low in the previous command to high, and vice-versa:
  
  ./egpc device d/c/i (mask)
+
  ./egpc /dev/portc d 0xaa
  
'''device''' is /dev/porta, /dev/portb or /dev/portc<br />
+
This reads the current pin data state of '''Port C'''.
'''d/c/i''' specifies the port command : d(data), c(configure) or i(index)<br />
 
'''mask''' is a bitmask in hex format in range [0x0,0xff].  
 
  
Our three commands work like this:
+
./egps /dev/portc d
  
'''c''' (mask)<br />           
+
The pin values for '''Port C''' are displayed on the board's strip of 8 LEDs. Observe that the LEDs change state when a new value is written to '''Port C'''. This only works for '''Port C''', however. '''Ports A''' and '''B''' must be read with an oscilloscope, multimeter, logic analyzer or similar device.
Configures the pins for input/output if a mask is specified.<br />
 
Returns the current configuration if no mask is specified.<br /> 
 
'''mask''' is an input/output bitmask. 1=output and 0=input.<br />                   
 
For example, this sets every other pin on PortA to be an output.<br />
 
                                       
 
./egpc /dev/porta c 0xaa
 
                   
 
...and this reads the current pin configuration state of PortA.
 
  
./egpc /dev/porta c
+
===Usage Example. Port Index===
  
'''d''' (mask)<br />           
+
./egpc device i (index)
If '''mask''' is specified then it sets each bit's corresponding pin output latch to high/low accordingly.
 
If '''mask''' is not specified then the current pin state is retrieved.
 
        "ex:                                          \n"
 
        "egp /dev/egpio1  d 0xff                      \n"
 
        "writes the ouput latch all high              \n"
 
        "egp /dev/egpio1  d                            \n"
 
        "reads the current pin state
 
  
===Usage Example. Writing to Port C===
+
If an index is specified then it sets the port's index<br />
 +
If an index is not specified then the port's current index is retrieved.<br />
  
We write a data bitmask to Port C. The values are rendered in our LED strip. (note that only PortC is displayed in the LED strip. Ports A or B would require kind of device to read them; a multimeter or oscilloscope or something like that.)
+
For example, this sets the index of '''Port A''' to 1
  
  ./egpc /dev/portc d 0x55
+
  ./egpc /dev/porta i 1
  
LEDs 1-8 are lit: 10101010
+
...and this reads the current index of '''Port A'''
  
'''MIKE I was thinking that maybe we could have some kind of general purpose "know your board" images (I have created a few) or wiki pages. They would point out things like the GPIO header and the LED strip.'''
+
./egpc /dev/porta i
  
./egpc /dev/portc d 0xaa
+
==Summary==
  
LEDs 1-8 are lit: 01010101
+
<code>egpc</code> is an application which demonstrates reading, writing and configuring the GPIO ports.

Latest revision as of 11:19, 10 April 2014

TODO: {{#todo:SEOKWREV - revise for 5.00 (12.27.13-14:22->JG+);(12.30.13-17:20->MD+);(01.02.14-11:20->KY+);(03.27.14-16:45->BS+);(04.10.14-12:20->BS+)|Jgreene|oe 4,oe 5,jg,md,bs,SEOKWREV}}


This is a guide to the egpc C example project included in the EMAC OE SDK.

egpc is an application for reading/writing/configuring gpio character devices. Specifically, it will read/write/configure the 3 ports (ports A, B and C) on the GPIO header.

The egpc project builds one executable: egpc.

Opening, Building and Uploading the Project Files

For information on opening the project from within Eclipse, please see Importing the EMAC OE SDK Projects with Eclipse. Then, follow Using the EMAC OE SDK Projects with Eclipse for information on how to build, upload and execute the example.

Alternatively, the Makefile can be used with the make command from the commandline to build and upload the example. For more information on this method, please see Using EMAC OE SDK Example Projects.

Usage and Behavior

egpc reads/writes/configures the GPIO ports.

Hardware Requirements

The egpc C example project will run on any EMAC carrier board which has one or more GPIO.

Using egpc

./egpc device [d/c/i] arg

device is /dev/porta, /dev/portb or /dev/portc
d/c/i specifies the port command : d (data), c (configure) or i (index)
arg is either a port index or a bitmask. The bitmask is in hex format, range [0x00,0xff].

Usage Example. Port Configuration

./egpc device c [mask]

If a mask is specified, it configures the pins for input/output.
If no mask is specified, it returns the current configuration.
mask is an input/output bitmask. 1=output and 0=input.
For example, this sets every other pin on Port A to be an output.

./egpc /dev/porta c 0xaa

...and this reads the current pin configuration state of Port A.

./egpc /dev/porta c     
0xaa

Usage Example: Port Data

./egpc device d [mask]

If a mask is specified then it sets each bit's corresponding pin output latch to high/low accordingly.
If a mask is not specified then the current pin state is retrieved.

For example, this writes pin output latches on Port C to alternating high and low.

./egpc /dev/portc d 0x55

This flips the pins, writing all the pins that were set low in the previous command to high, and vice-versa:

./egpc /dev/portc d 0xaa

This reads the current pin data state of Port C.

./egps /dev/portc d

The pin values for Port C are displayed on the board's strip of 8 LEDs. Observe that the LEDs change state when a new value is written to Port C. This only works for Port C, however. Ports A and B must be read with an oscilloscope, multimeter, logic analyzer or similar device.

Usage Example. Port Index

./egpc device i (index)

If an index is specified then it sets the port's index
If an index is not specified then the port's current index is retrieved.

For example, this sets the index of Port A to 1

./egpc /dev/porta i 1

...and this reads the current index of Port A

./egpc /dev/porta i

Summary

egpc is an application which demonstrates reading, writing and configuring the GPIO ports.