■ SCREENSHOT 1. Setting up the Vinculum-II's I/O
subsystem is as easy as pointing and clicking. Note that
we could have assigned pins 39 and 40 to any of the
Vinculum-II's GPIO ports and a select list of peripheral devices.
(GPIO_PORT_A). We do that by filling in our gpioCtxA
context’s port_identifier variable with the Vinculum-II
GPIO port we wish to associate with our GPIO code. In
that we defined the LED I/O pins as belonging to
Vinculum-II’s GPIO_PORT_A, our gpioCtxA port_identifier
entry looks like this:
// initialize device driver
gpioCtxA.port_identifier = GPIO_PORT_A;
In the Vinculum-II programming world, control blocks
are used to hold command codes, variables, and
identifiers that are used by VOS (Vinculum Operating
System) commands. With that thought in mind, let’s create
yet another structure instance based on this IOC TL (I/O
Control) template found in GPIO.h:
// GPIO control block for use with GPIO
//IOCTL function
typedef struct _gpio_ioctl_cb_t {
unsigned char ioctl_code;
unsigned char value;
} gpio_ioctl_cb_t;
In traditional C manner, we’ll create an instance of the
structure gpio_ioctl_cb_t called gpio_iocbA:
//spawn an I/O control block called gpio_iocbA
gpio_ioctl_cb_t gpio_iocbA;
70 September 2011
Our new gpio_iocbA structure will allow us to initiate
VOS GPIO commands. However, we have one more GPIO
task to complete before we can issue commands via our
brand new gpio_iocbA structure. We need to open the GPIOA
I/O port which is viewed as a device by the Vinculum-II:
//***********************************************
//* VOS DEVICES
//***********************************************
#define VOS_NUMBER_DEVICES 4
#define VOS_DEV_USBHOST_2 0
#define VOS_DEV_USBHOST_FT232 1
#define VOS_DEV_GPIOA 2
#define VOS_DEV_GPIOC 3
//***********************************************
//* VOS HANDLES
//***********************************************
VOS_HANDLE hUSBHOST_2; // USB Host Port 2
VOS_HANDLE hUSBHOST_FT232;
// Connects to FT232 devices using the USB Host
Interface
VOS_HANDLE hGPIOA; //Vinculum-II GPIO_PORT_A
VOS_HANDLE hGPIOC; //Vinculum-II GPIO_PORT_C
//***********************************************
//* GLOBAL DEFINITIONS
//***********************************************
#define LED1 0x01
#define LED2 0x02
//open the I/O port device
hGPIOA = vos_dev_open(VOS_DEV_GPIOA);
Keep reading and you’ll get the scoop on all of the
VOS devices and VOS handles in the open device code
snippet that we have yet to discuss. For now, concentrate on
all things GPIOA. With the issuance of the vos_dev_open
command, we have just associated the Vinculum-II’s
GPIO_PORT_A device with a handle we defined as hGPIOA.
The hGPIOA and hGPIOC I/O port handles will be used
in VOS IOCTL commands to identify the I/O port that the
command and data in the control block should act upon.
For instance, let’s write some code to set the LED1 and
LED2 positions of GPIO_PORT_A as outputs. We’ll stuff
our PORTA IOCTL control block instance (gpio_iocbA)
with the command code (ioctl_code) and variable (value)
necessary to set the LED1 and LED2 port pin directions:
//set lower 2 bits of GPIO_PORT_A (A0 and A1)
//as outputs
gpio_iocbA.ioctl_code = VOS_IOCTL_GPIO_SET_MASK;
gpio_iocbA.value = 0x03; // set lower 2 bits
as outputs
vos_dev_ioctl(hGPIOA, &gpio_iocbA);
The function vos_dev_ioctl uses the handle we
obtained when we opened the GPIOA device (hGPIOA)
to direct the contents of I/O control block gpio_iocbA to
the IOCTL subsystem of GPIO_PORT_A.
At this point, we have everything in place that will
allow us to control the state of LED1 and LED2. So, let’s
assemble some Vinculum-II code to illuminate LED1:
uint8 ledmask;
#define LED1 0x01
ledmask &= (~LED1); //0b11111110
vos_dev_write(hGPIOA,&ledmask,1,NULL);
//write 1 byte to GPIO_PORT_A
Again, we used the device handle (hGPIOA) to tell the
VOS device write function where to send the single byte