All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sos.c
Go to the documentation of this file.
#define _GNU_SOURCE 1
#include "stdio.h"
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include "../c_wrapper/pruio.h" /* include header */
int
isleep(unsigned int mseconds)
{
fd_set set;
struct timeval timeout;
/* Initialize the file descriptor set. */
FD_ZERO(&set);
FD_SET(STDIN_FILENO, &set);
/* Initialize the timeout data structure. */
timeout.tv_sec = 0;
timeout.tv_usec = mseconds * 1000;
/* select returns 0 if timeout, 1 if input available, -1 if error. */
return TEMP_FAILURE_RETRY(select(FD_SETSIZE,
&set, NULL, NULL,
&timeout));
}
#define PIN 24
#define OUT_K pruio_gpio_setValue(io, PIN, 128 + pinmode) ; isleep(150) ; pruio_gpio_setValue(io, PIN, pinmode) ; isleep(100) ;
#define OUT_L pruio_gpio_setValue(io, PIN, 128 + pinmode) ; isleep(350) ; pruio_gpio_setValue(io, PIN, pinmode) ; isleep(100) ;
#define OUT_S OUT_K ; OUT_K ; OUT_K ; isleep(150)
#define OUT_O OUT_L ; OUT_L ; OUT_L ; isleep(150)
int main(int argc, char **argv)
{
pruIo *io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1);
do { // pseudo loop to avoid goto
if (io->Errr) {
printf("initialisation failed (%s)\n", io->Errr); break;}
uint8 pinmode = io->BallConf[PIN];
if (pruio_config(io, 1, 0x1FE, 0, 4)) {
printf("config failed (%s)\n", io->Errr); break;}
printf("watch SOS code on user LED 3 (near ethernet connector)\n\n");
printf("execute the following command to get rid of mmc1 triggers\n");
printf(" sudo su && echo none > /sys/class/leds/beaglebone:green:usr3/trigger && exit\n\n");
printf("press any key to quit");
struct termios oldt, newt; /* make terminal non-blocking */
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
newt.c_cc[VMIN] = 0;
newt.c_cc[VTIME] = 1;
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
while(0 >= getchar()) { /* run loop until keystroke */
OUT_S;
OUT_O;
OUT_S;
isleep(1500);
}
tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); /* reset terminal */
pruio_gpio_setValue(io, PIN, pinmode); /* reset LED (cosmetic) */
} while (0);
printf("\n");
pruio_destroy(io); /* destroy driver structure */
return 0;
}
uint8
unsigned char uint8
8 bit unsigned integer data type
Definition: pruio.h:37
OUT_S
#define OUT_S
Output a 'S' (short - short - short).
Definition: sos.c:63
io
VAR io
create new driver UDT
Definition: 1.bas:21
main
int main(int argc, char **argv)
The main function.
Definition: sos.c:68
pruIo::BallConf
uint8 * BallConf
pointer to ball configuration (CPU pin muxing)
Definition: pruio.h:422
pruIo
Wrapper structure for PruIo.
Definition: pruio.h:403
pruio_new
pruIo * pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD)
Wrapper function for the constructor PruIo::PruIo().
pruIo::Errr
char * Errr
pointer for error messages
Definition: pruio.h:411
pruio_destroy
void pruio_destroy(pruIo *Io)
Wrapper function for the destructor PruIo::~PruIo.
PRUIO_DEF_ACTIVE
activate all devices
Definition: pruio.h:385
pinmode
VAR pinmode
The current pinmode.
Definition: sos.bas:43
isleep
int isleep(unsigned int mseconds)
Wait for keystroke or timeout.
Definition: sos.c:37
pruio_gpio_setValue
char * pruio_gpio_setValue(pruIo *Io, uint8 Ball, uint8 Modus)
Wrapper function for GpioUdt::config().
PIN
#define PIN
The CPU ball to control (user LED 3).
Definition: sos.c:57
OUT_O
#define OUT_O
Output an 'O' (long - long - long).
Definition: sos.c:65
pruio_config
char * pruio_config(pruIo *Io, uint32 Samp, uint32 Mask, uint32 Tmr, uint16 Mds)
Wrapper function for PruIo::config().