Yet Another WebIOPi+
 All Classes Namespaces Files Functions Variables Macros Pages
Classes | Macros | Functions | Variables
gpio.c File Reference
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <time.h>
#include <pthread.h>
#include "gpio.h"
#include "cpuinfo.h"

Go to the source code of this file.

Classes

struct  tspair
 

Macros

#define BCM2708_PERI_BASE   0x20000000
 
#define BCM2708_GPIO_BASE   (BCM2708_PERI_BASE + 0x200000)
 
#define BCM2709_PERI_BASE   0x3F000000
 
#define BCM2709_GPIO_BASE   (BCM2709_PERI_BASE + 0x200000)
 
#define FSEL_OFFSET   0
 
#define SET_OFFSET   7
 
#define CLR_OFFSET   10
 
#define PINLEVEL_OFFSET   13
 
#define EVENT_DETECT_OFFSET   16
 
#define RISING_ED_OFFSET   19
 
#define FALLING_ED_OFFSET   22
 
#define HIGH_DETECT_OFFSET   25
 
#define LOW_DETECT_OFFSET   28
 
#define PULLUPDN_OFFSET   37
 
#define PULLUPDNCLK_OFFSET   38
 
#define PAGE_SIZE   (4*1024)
 
#define BLOCK_SIZE   (4*1024)
 

Functions

void short_wait (void)
 
int setup (void)
 
void set_pullupdn (int gpio, int pud)
 
void set_function (int gpio, int function, int pud)
 
int get_function (int gpio)
 
int input (int gpio)
 
void output (int gpio, int value)
 
void outputSequence (int gpio, int period, char *sequence)
 
void resetPWM (int gpio)
 
void pulseTS (int gpio, struct timespec *up, struct timespec *down)
 
void pulseOrSaveTS (int gpio, struct timespec *up, struct timespec *down)
 
void pulseMilli (int gpio, int up, int down)
 
void pulseMilliRatio (int gpio, int width, float ratio)
 
void pulseMicro (int gpio, int up, int down)
 
void pulseMicroRatio (int gpio, int width, float ratio)
 
void pulseAngle (int gpio, float angle)
 
void pulseRatio (int gpio, float ratio)
 
struct pulsegetPulse (int gpio)
 
void * pwmLoop (void *data)
 
void enablePWM (int gpio)
 
void disablePWM (int gpio)
 
int isPWMEnabled (int gpio)
 
void cleanup (void)
 
int number_of_cores (void)
 

Variables

static volatile uint32_t * gpio_map
 
static struct pulse gpio_pulses [GPIO_COUNT]
 
static struct tspair gpio_tspairs [GPIO_COUNT]
 
static pthread_t * gpio_threads [GPIO_COUNT]
 

Macro Definition Documentation

#define BCM2708_GPIO_BASE   (BCM2708_PERI_BASE + 0x200000)

Definition at line 35 of file gpio.c.

Referenced by setup().

#define BCM2708_PERI_BASE   0x20000000

Definition at line 34 of file gpio.c.

#define BCM2709_GPIO_BASE   (BCM2709_PERI_BASE + 0x200000)

Definition at line 37 of file gpio.c.

Referenced by setup().

#define BCM2709_PERI_BASE   0x3F000000

Definition at line 36 of file gpio.c.

#define BLOCK_SIZE   (4*1024)

Definition at line 51 of file gpio.c.

Referenced by cleanup(), and setup().

#define CLR_OFFSET   10

Definition at line 40 of file gpio.c.

Referenced by output().

#define EVENT_DETECT_OFFSET   16

Definition at line 42 of file gpio.c.

#define FALLING_ED_OFFSET   22

Definition at line 44 of file gpio.c.

#define FSEL_OFFSET   0

Definition at line 38 of file gpio.c.

Referenced by get_function(), and set_function().

#define HIGH_DETECT_OFFSET   25

Definition at line 45 of file gpio.c.

#define LOW_DETECT_OFFSET   28

Definition at line 46 of file gpio.c.

#define PAGE_SIZE   (4*1024)

Definition at line 50 of file gpio.c.

Referenced by setup().

#define PINLEVEL_OFFSET   13

Definition at line 41 of file gpio.c.

Referenced by input().

#define PULLUPDN_OFFSET   37

Definition at line 47 of file gpio.c.

Referenced by set_pullupdn().

#define PULLUPDNCLK_OFFSET   38

Definition at line 48 of file gpio.c.

Referenced by set_pullupdn().

#define RISING_ED_OFFSET   19

Definition at line 43 of file gpio.c.

#define SET_OFFSET   7

Definition at line 39 of file gpio.c.

Referenced by output().

Function Documentation

void cleanup ( void  )

Definition at line 332 of file gpio.c.

References BLOCK_SIZE, and gpio_map.

Referenced by initGPIO().

void disablePWM ( int  gpio)

Definition at line 314 of file gpio.c.

References webiopi-client::gpio, gpio_threads, output(), and resetPWM().

Referenced by py_disablePWM(), and set_function().

void enablePWM ( int  gpio)

Definition at line 300 of file gpio.c.

References webiopi-client::gpio, gpio_threads, pwmLoop(), and resetPWM().

Referenced by py_enablePWM(), and set_function().

int get_function ( int  gpio)
struct pulse* getPulse ( int  gpio)

Definition at line 286 of file gpio.c.

References webiopi-client::gpio, and gpio_pulses.

Referenced by py_getPulse().

int input ( int  gpio)

Definition at line 153 of file gpio.c.

References gpio_map, PINLEVEL_OFFSET, and webiopi-client::value.

Referenced by py_input().

int isPWMEnabled ( int  gpio)

Definition at line 327 of file gpio.c.

References webiopi-client::gpio, and gpio_threads.

Referenced by get_function(), and py_isPWMEnabled().

int number_of_cores ( void  )

Definition at line 338 of file gpio.c.

Referenced by setup().

void output ( int  gpio,
int  value 
)

Definition at line 163 of file gpio.c.

References CLR_OFFSET, gpio_map, and SET_OFFSET.

Referenced by disablePWM(), outputSequence(), pulseTS(), and py_output().

void outputSequence ( int  gpio,
int  period,
char *  sequence 
)

Definition at line 178 of file gpio.c.

References output(), and webiopi-client::value.

Referenced by py_output_sequence().

void pulseAngle ( int  gpio,
float  angle 
)

Definition at line 269 of file gpio.c.

References ANGLE, webiopi-client::gpio, gpio_pulses, pulseMicro(), pulse::type, and pulse::value.

Referenced by py_pulseAngle().

void pulseMicro ( int  gpio,
int  up,
int  down 
)

Definition at line 250 of file gpio.c.

References pulseOrSaveTS().

Referenced by pulseAngle(), pulseMicroRatio(), pulseRatio(), and py_pulseMicro().

void pulseMicroRatio ( int  gpio,
int  width,
float  ratio 
)

Definition at line 262 of file gpio.c.

References pulseMicro().

Referenced by py_pulseMicroRatio().

void pulseMilli ( int  gpio,
int  up,
int  down 
)

Definition at line 231 of file gpio.c.

References pulseOrSaveTS().

Referenced by pulseMilliRatio(), and py_pulseMilli().

void pulseMilliRatio ( int  gpio,
int  width,
float  ratio 
)

Definition at line 243 of file gpio.c.

References pulseMilli().

Referenced by py_pulseMilliRatio().

void pulseOrSaveTS ( int  gpio,
struct timespec *  up,
struct timespec *  down 
)

Definition at line 220 of file gpio.c.

References gpio_threads, gpio_tspairs, and pulseTS().

Referenced by pulseMicro(), and pulseMilli().

void pulseRatio ( int  gpio,
float  ratio 
)

Definition at line 278 of file gpio.c.

References webiopi-client::gpio, gpio_pulses, pulseMicro(), RATIO, pulse::type, and pulse::value.

Referenced by py_pulse(), and py_pulseRatio().

void pulseTS ( int  gpio,
struct timespec *  up,
struct timespec *  down 
)

Definition at line 207 of file gpio.c.

References output().

Referenced by pulseOrSaveTS(), and pwmLoop().

void* pwmLoop ( void *  data)

Definition at line 291 of file gpio.c.

References webiopi-client::gpio, gpio_tspairs, and pulseTS().

Referenced by enablePWM().

void resetPWM ( int  gpio)

Definition at line 196 of file gpio.c.

References tspair::down, webiopi-client::gpio, gpio_pulses, gpio_tspairs, pulse::type, tspair::up, and pulse::value.

Referenced by disablePWM(), and enablePWM().

void set_function ( int  gpio,
int  function,
int  pud 
)

Definition at line 121 of file gpio.c.

References disablePWM(), enablePWM(), FSEL_OFFSET, gpio_map, OUT, PWM, and set_pullupdn().

Referenced by py_set_function().

void set_pullupdn ( int  gpio,
int  pud 
)

Definition at line 101 of file gpio.c.

References gpio_map, PUD_DOWN, PUD_UP, PULLUPDN_OFFSET, PULLUPDNCLK_OFFSET, and short_wait().

Referenced by set_function().

int setup ( void  )
void short_wait ( void  )

Definition at line 64 of file gpio.c.

Referenced by set_pullupdn().

Variable Documentation

volatile uint32_t* gpio_map
static

Definition at line 53 of file gpio.c.

Referenced by cleanup(), get_function(), input(), output(), set_function(), set_pullupdn(), and setup().

struct pulse gpio_pulses[GPIO_COUNT]
static

Definition at line 60 of file gpio.c.

Referenced by getPulse(), pulseAngle(), pulseRatio(), and resetPWM().

pthread_t* gpio_threads[GPIO_COUNT]
static

Definition at line 62 of file gpio.c.

Referenced by disablePWM(), enablePWM(), isPWMEnabled(), and pulseOrSaveTS().

struct tspair gpio_tspairs[GPIO_COUNT]
static

Definition at line 61 of file gpio.c.

Referenced by pulseOrSaveTS(), pwmLoop(), and resetPWM().