/*------------------------- GPIO -------------------------------------*/
/* from armadeus/target/packages/as_devices/c/as_gpio* */
# define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
//# define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/
int pin_file; /* pin file for 2.6.29 interface*/
struct gpio_device *RUN_LED_dev;
struct gpio_device *CAN0_EN_dev;
#endif /* CAN0_EN_GPIO_0_21 */
struct gpio_device *CAN1_EN_dev;
#endif /* CAN1_EN_GPIO_0_17 */
static int write_file_bool(int fd, int value)
ret = write(fd, value?"1":"0", 1);
if (lseek(fd, 0, SEEK_SET) < 0) {
static int gpio_set_pin_value(struct gpio_device *aDev, int aValue)
int pin_file = aDev->pin_file;
retval = write_file_bool(pin_file, aValue);
ERROR("Can't write value\n");
static struct gpio_device *gpio_open(int aGpioNum)
export_file = open("/sys/class/gpio/export", O_WRONLY);
ERROR("Can't open /sys/class/gpio/export\nBe sure that gpiolib is under your kernel\n");
snprintf(buf, BUFF_SIZE, "%%d", aGpioNum);
retval = write(export_file, buf, strlen(buf));
ERROR("/sys/class/gpio/export can't be written\n");
snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%%d/direction", aGpioNum);
gpio_dir_fd = open(buf, O_WRONLY);
ERROR("Can't open gpio%%d direction\n", aGpioNum);
ret = write(gpio_dir_fd, "out", 3);
ERROR("Error writing direction\n");
snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%%d/value", aGpioNum);
pin_file = open(buf, O_RDWR);
ERROR("Can't export gpio number %%d\n", aGpioNum);
dev = malloc(sizeof(struct gpio_device));
ERROR("Can't allocate gpio_device structure\n");
dev->port_num = aGpioNum;
dev->pin_file = pin_file;
gpio_set_pin_value(dev, 1);
static int gpio_close(struct gpio_device *aDev)
ERROR("device is NULL\n");
unexport_file = open("/sys/class/gpio/unexport", O_WRONLY);
ERROR("Can't open /sys/class/gpio/unexport\nBe sure that gpiolib is under your kernel\n");
snprintf(buf, BUFF_SIZE, "%%d", aDev->port_num);
retval = write(unexport_file, buf, strlen(buf));
ERROR("/sys/class/gpio/unexport can't be written\n");
/* TODO : DELETE !... but keep this until composer stops sending code snippets for mbrtu */
MB_PAR_ODD = 0, /**< ODD parity. */
MB_PAR_EVEN = 1, /**< Even parity. */
MB_PAR_NONE = 2 /**< No parity. */
unsigned long mbBaudRate = 115200; /**< Modbus baud-rate setting: 9600, 19200, 38400, 57600, 115200 */
eMBSerialParity mbParity = MB_PAR_NONE; /**< Modbus parity setting: odd, even, none */
#define MAX_ONBOARD_DEVICES 2
#define ONBOARD_READ_BUFSIZE 30
#define ONBOARD_WRITE_BUFSIZE 30
typedef char onBoardReadBuf_t[MAX_ONBOARD_DEVICES][ONBOARD_READ_BUFSIZE];
typedef char onBoardWriteBuf_t[MAX_ONBOARD_DEVICES][ONBOARD_WRITE_BUFSIZE];
typedef char onBoardDev_t[MAX_ONBOARD_DEVICES][2];
unsigned long long common_ticktime__;
#define RTIOC_TYPE_SMT_ONBOARD RTDM_CLASS_EXPERIMENTAL
#define RTSMT_ONBOARD_RTIOC_INIT _IOR(RTIOC_TYPE_SMT_ONBOARD, 0x00, onBoardBusInit_t)
#define RTSMT_ONBOARD_RTIOC_READ _IOR(RTIOC_TYPE_SMT_ONBOARD, 0x01, onBoardReadBuf_t)
#define RTSMT_ONBOARD_RTIOC_WRITE _IOR(RTIOC_TYPE_SMT_ONBOARD, 0x02, onBoardWriteBuf_t)
static onBoardReadBuf_t onBoardReadBuf;
static onBoardWriteBuf_t onBoardWriteBuf;
static onBoardBusInit_t onBoardBusInit;
static int onboardbusfd = -1;