Rleg  2
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Macros | Functions
gpio_functions.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
Include dependency graph for gpio_functions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SUCCESS   1
 
#define FAILURE   -1
 

Functions

int gpio_read (uint8_t gpio)
 
int gpio_write (uint8_t gpio, uint8_t value)
 
int gpio_f_write (uint8_t gpio, uint8_t value)
 

Macro Definition Documentation

#define FAILURE   -1

Definition at line 18 of file gpio_functions.h.

#define SUCCESS   1

Definition at line 17 of file gpio_functions.h.

Function Documentation

int gpio_f_write ( uint8_t  gpio,
uint8_t  value 
)

Definition at line 61 of file gpio_functions.c.

References SUCCESS.

62 {
63  FILE *fp_gpio;
64  char path[30];
65  char fp_value;
66 
67  sprintf(path,"/sys/class/gpio/gpio%d/value",gpio);
68  fp_gpio=fopen(path,"w");
69  rewind(fp_gpio);
70  fp_value=0x30+value;
71  fwrite(&fp_value, sizeof(char), 1, fp_gpio);
72  fclose(fp_gpio);
73  return SUCCESS;
74 }
#define SUCCESS
Definition: calibration.h:6
int gpio_read ( uint8_t  gpio)

Definition at line 3 of file gpio_functions.c.

References FAILURE.

Referenced by dac_shut_down().

4 {
5  FILE *fp_gpio=NULL;
6  char path[30];
7  char fp_value;
8 
9  sprintf(path,"/sys/class/gpio/gpio%d/value",gpio);
10  if( (fp_gpio=fopen(path,"rb+")) == NULL )
11  {
12  //printf("Open %s failed\n",path);
13  return FAILURE;
14  }
15  rewind(fp_gpio);
16  fread(&fp_value, 1, sizeof(char), fp_gpio);
17  fclose(fp_gpio);
18  return (uint8_t)fp_value-0x30;
19 }
#define FAILURE
Definition: calibration.h:7

Here is the caller graph for this function:

int gpio_write ( uint8_t  gpio,
uint8_t  value 
)

Definition at line 21 of file gpio_functions.c.

References FAILURE, and SUCCESS.

Referenced by actuate(), dac_shut_down(), and read_all_data().

22 {
23  FILE *fp_gpio;
24  char path[30];
25  char fp_read[4];
26  char s_out[]="out";
27  char fp_write;
28 
29 // Verifying if GPIO is set as Output
30  sprintf(path,"/sys/class/gpio/gpio%d/direction",gpio);
31 
32  if( (fp_gpio=fopen(path,"r")) == NULL )
33  {
34  //printf("Open %s failed\n",path);
35  return -1;
36  }
37  rewind(fp_gpio);
38  fread(fp_read, 3, sizeof(char), fp_gpio);
39  if( strncmp(fp_read,s_out,3 ) )
40  {
41  //printf("Gpio%d is set as Input. Impossible to write.",gpio);
42  return FAILURE;
43  }
44  fclose(fp_gpio);
45 
46 // Writing
47  sprintf(path,"/sys/class/gpio/gpio%d/value",gpio);
48 
49  if( (fp_gpio=fopen(path,"w")) == NULL )
50  {
51  //printf("Open %s failed\n",path);
52  return FAILURE;
53  }
54  rewind(fp_gpio);
55  fp_write=0x30+value;
56  fwrite(&fp_write, sizeof(char), 1, fp_gpio);
57  fclose(fp_gpio);
58  return SUCCESS;
59 }
#define FAILURE
Definition: calibration.h:7
#define SUCCESS
Definition: calibration.h:6

Here is the caller graph for this function: