kb_gpio.c File Reference

This module provides useful basic facilities to use the KoreBot GPIO and configure them. More...

Include dependency graph for kb_gpio.c:

Go to the source code of this file.

Defines

#define MAP_SIZE   4096UL
#define MAP_MASK   (MAP_SIZE - 1)
#define MEMDEV   "/dev/mem"
#define MAXIO   84
#define MAXPWM   2
#define reg_val(reg)   *((unsigned long *)reg)

Functions

static void bit_set (unsigned long addr, unsigned gpio)
static void bit_clear (unsigned long addr, unsigned gpio)
static int bit_test (unsigned long addr, unsigned gpio)
static void reg_set (unsigned long addr, unsigned long value)
static long int get_reg (unsigned long addr)
int kb_gpio_init ()
int kb_gpio_cleanup ()
int kb_gpio_mode ()
void kb_gpio_function (unsigned gpio, unsigned function)
void kb_gpio_dir (unsigned gpio, unsigned dir)
void kb_gpio_set (unsigned gpio)
void kb_gpio_clear (unsigned gpio)
int kb_gpio_get (unsigned gpio)

Variables

static void * map_base
static int fd


Detailed Description

This module provides useful basic facilities to use the KoreBot GPIO and configure them.

Support for KoreBot General Purpose IO.

Author:
Pierre Bureau (K-Team SA)
Note:
Copyright (C) 2004 K-TEAM SA
Bug:
none discovered.
Todo:
nothing.

Definition in file kb_gpio.c.


Define Documentation

#define MAP_MASK   (MAP_SIZE - 1)

#define MAP_SIZE   4096UL

#define MAXIO   84

Definition at line 33 of file kb_gpio.c.

Referenced by kb_gpio_clear(), kb_gpio_dir(), kb_gpio_function(), kb_gpio_get(), and kb_gpio_set().

#define MAXPWM   2

#define MEMDEV   "/dev/mem"

Definition at line 32 of file kb_gpio.c.

Referenced by kb_clk_init(), kb_gpio_init(), kb_pwm0_init(), and kb_pwm1_init().

#define reg_val ( reg   )     *((unsigned long *)reg)


Function Documentation

static void bit_clear ( unsigned long  addr,
unsigned  gpio 
) [static]

Definition at line 53 of file kb_gpio.c.

References map_base, MAP_MASK, and reg_val.

Referenced by kb_gpio_dir(), and kb_gpio_function().

static void bit_set ( unsigned long  addr,
unsigned  gpio 
) [static]

Definition at line 41 of file kb_gpio.c.

References map_base, MAP_MASK, and reg_val.

Referenced by kb_gpio_clear(), kb_gpio_dir(), kb_gpio_function(), and kb_gpio_set().

static int bit_test ( unsigned long  addr,
unsigned  gpio 
) [static]

Definition at line 64 of file kb_gpio.c.

References map_base, MAP_MASK, and reg_val.

Referenced by kb_gpio_get().

static long int get_reg ( unsigned long  addr  )  [static]

Definition at line 87 of file kb_gpio.c.

References map_base, MAP_MASK, and reg_val.

int kb_gpio_cleanup (  ) 

Cleanup the GPIO module. Must be called to free the module ressources.

Definition at line 128 of file kb_gpio.c.

References fd, KB_ERROR, KB_ERROR_MMAP, map_base, and MAP_SIZE.

void kb_gpio_clear ( unsigned  gpio  ) 

Clear a given GPIO. The GPIO must be first configured to ouput mode. If the GPIO is configured as input, it will be cleared when configured as ouput.

Parameters:
gpio A gpio number between 0 and 84

Definition at line 204 of file kb_gpio.c.

References bit_set(), GPCR, KB_ERROR, KB_ERROR_INVALID, and MAXIO.

Referenced by kb_lrf_pwrOff(), main(), and resetio().

Here is the call graph for this function:

void kb_gpio_dir ( unsigned  gpio,
unsigned  dir 
)

Configure the given GPIO as input or output. The GPIO function must be configured as well to use the pin as an IO.

Parameters:
gpio A gpio number between 0 and 84
dir The direction 0:output 1:input

Definition at line 171 of file kb_gpio.c.

References bit_clear(), bit_set(), GPDR, KB_ERROR, KB_ERROR_INVALID, and MAXIO.

Referenced by configio(), gpioinit(), kb_lrf_Init(), kb_pwm_activate(), kh3_init(), and main().

Here is the call graph for this function:

void kb_gpio_function ( unsigned  gpio,
unsigned  function 
)

Configure the given GPIO pin function. Check first if the pin is freely available on the KoreBot.

Parameters:
gpio A gpio number between 0 and 84
function 0:IO mode 1:Alternate function 1 2:Alternate function 2 3:Alternate function 3

Definition at line 148 of file kb_gpio.c.

References bit_clear(), bit_set(), GAFR, KB_ERROR, KB_ERROR_INVALID, and MAXIO.

Referenced by configio(), gpioinit(), kb_lrf_Init(), kb_pwm_activate(), kh3_init(), and main().

Here is the call graph for this function:

int kb_gpio_get ( unsigned  gpio  ) 

Get the current level for a given GPIO. It can be used regardless of the current GPIO configuration.

Parameters:
gpio A gpio number between 0 and 84
Returns:
  • 1 if the GPIO is set
  • 0 if the GPIO is cleared
  • an error code if the GPIO is invalid

Definition at line 223 of file kb_gpio.c.

References bit_test(), GPLR, KB_ERROR, KB_ERROR_INVALID, and MAXIO.

Referenced by braitenbergAvoidance(), kh3_ambiant_ir(), kh3_battery_voltage(), kh3_configure_os(), kh3_measure_us(), kh3_proximity_ir(), kh3_reset_tstamp(), kh3_revision(), readio(), and thread().

Here is the call graph for this function:

int kb_gpio_init (  ) 

Initialize the GPIO module. This function must be called before any other call the gpio functions.

Returns:
  • 0 on success
  • a negative error code on failure

Definition at line 104 of file kb_gpio.c.

References fd, GPIO_BASE, KB_ERROR, KB_ERROR_FILEOPEN, KB_ERROR_MMAP, map_base, MAP_MASK, MAP_SIZE, and MEMDEV.

Referenced by gpioinit(), kb_lrf_Init(), kb_pwm_init(), kh3_init(), and main().

int kb_gpio_mode (  ) 

Definition at line 134 of file kb_gpio.c.

void kb_gpio_set ( unsigned  gpio  ) 

Set a given GPIO. The GPIO must be first configured to ouput mode. If the GPIO is configured as input, it will be set when configured as ouput.

Parameters:
gpio A gpio number between 0 and 84

Definition at line 189 of file kb_gpio.c.

References bit_set(), GPSR, KB_ERROR, KB_ERROR_INVALID, and MAXIO.

Referenced by kb_lrf_pwrOn(), main(), and setio().

Here is the call graph for this function:

static void reg_set ( unsigned long  addr,
unsigned long  value 
) [static]

Definition at line 78 of file kb_gpio.c.

References map_base, MAP_MASK, and reg_val.


Variable Documentation

int fd [static]

void* map_base [static]

Definition at line 38 of file kb_gpio.c.

Referenced by bit_clear(), bit_set(), bit_test(), get_reg(), kb_gpio_cleanup(), kb_gpio_init(), and reg_set().


Generated on Wed Dec 15 11:49:28 2010 for KoreBot Library by  doxygen 1.5.5