libpruio  0.2
Input/Output driver for digital/analog lines on Beagleboard hardware
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sos.c
Go to the documentation of this file.
1 
18 #define _GNU_SOURCE 1
20 #include "stdio.h"
21 #include <termios.h>
22 #include <unistd.h>
23 #include <errno.h>
24 #include <sys/types.h>
25 #include <sys/time.h>
26 #include "../c_wrapper/pruio.h" /* include header */
27 
28 
36 int
37 isleep(unsigned int mseconds)
38 {
39  fd_set set;
40  struct timeval timeout;
41 
42  /* Initialize the file descriptor set. */
43  FD_ZERO(&set);
44  FD_SET(STDIN_FILENO, &set);
45 
46  /* Initialize the timeout data structure. */
47  timeout.tv_sec = 0;
48  timeout.tv_usec = mseconds * 1000;
49 
50  /* select returns 0 if timeout, 1 if input available, -1 if error. */
51  return TEMP_FAILURE_RETRY(select(FD_SETSIZE,
52  &set, NULL, NULL,
53  &timeout));
54 }
55 
57 #define PIN 24
58 #define OUT_K pruio_gpio_setValue(io, PIN, 128 + pinmode) ; isleep(150) ; pruio_gpio_setValue(io, PIN, pinmode) ; isleep(100) ;
60 #define OUT_L pruio_gpio_setValue(io, PIN, 128 + pinmode) ; isleep(350) ; pruio_gpio_setValue(io, PIN, pinmode) ; isleep(100) ;
62 #define OUT_S OUT_K ; OUT_K ; OUT_K ; isleep(150)
64 #define OUT_O OUT_L ; OUT_L ; OUT_L ; isleep(150)
66 
68 int main(int argc, char **argv)
69 {
70  pruIo *io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1);
71  do { // pseudo loop to avoid goto
72  if (io->Errr) {
73  printf("initialisation failed (%s)\n", io->Errr); break;}
74 
75  uint8 pinmode = io->BallConf[PIN];
76 
77  if (pruio_config(io, 1, 0x1FE, 0, 4)) {
78  printf("config failed (%s)\n", io->Errr); break;}
79 
80  printf("watch SOS code on user LED 3 (near ethernet connector)\n\n");
81  printf("execute the following command to get rid of mmc1 triggers\n");
82  printf(" sudo su && echo none > /sys/class/leds/beaglebone:green:usr3/trigger && exit\n\n");
83  printf("press any key to quit");
84 
85  struct termios oldt, newt; /* make terminal non-blocking */
86  tcgetattr( STDIN_FILENO, &oldt );
87  newt = oldt;
88  newt.c_lflag &= ~( ICANON | ECHO );
89  newt.c_cc[VMIN] = 0;
90  newt.c_cc[VTIME] = 1;
91  tcsetattr( STDIN_FILENO, TCSANOW, &newt );
92 
93  while(0 >= getchar()) { /* run loop until keystroke */
94  OUT_S;
95  OUT_O;
96  OUT_S;
97  isleep(1500);
98  }
99 
100  tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); /* reset terminal */
101 
102  pruio_gpio_setValue(io, PIN, pinmode); /* reset LED (cosmetic) */
103  } while (0);
104  printf("\n");
105 
106  pruio_destroy(io); /* destroy driver structure */
107  return 0;
108 }
unsigned char uint8
8 bit unsigned integer data type
Definition: pruio.h:37
#define OUT_S
Output a 'S' (short - short - short).
Definition: sos.c:63
VAR io
create new driver UDT
Definition: 1.bas:21
int main(int argc, char **argv)
The main function.
Definition: sos.c:68
uint8 * BallConf
pointer to ball configuration (CPU pin muxing)
Definition: pruio.h:422
Wrapper structure for PruIo.
Definition: pruio.h:403
pruIo * pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD)
Wrapper function for the constructor PruIo::PruIo().
char * Errr
pointer for error messages
Definition: pruio.h:411
void pruio_destroy(pruIo *Io)
Wrapper function for the destructor PruIo::~PruIo.
activate all devices
Definition: pruio.h:385
VAR pinmode
The current pinmode.
Definition: sos.bas:43
int isleep(unsigned int mseconds)
Wait for keystroke or timeout.
Definition: sos.c:37
char * pruio_gpio_setValue(pruIo *Io, uint8 Ball, uint8 Modus)
Wrapper function for GpioUdt::config().
#define PIN
The CPU ball to control (user LED 3).
Definition: sos.c:57
#define OUT_O
Output an 'O' (long - long - long).
Definition: sos.c:65
char * pruio_config(pruIo *Io, uint32 Samp, uint32 Mask, uint32 Tmr, uint16 Mds)
Wrapper function for PruIo::config().