You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

61 lines
1.5 KiB

/*
* Created on: Aug 5, 2019
* Author: Cristian Fatu
* This project implements a basic UART communication over UART on
* Petalinux, unsing Uart Lite linux driver. The hardware platform implements an
* UART Lite IP core and the device tree (in pl.dtsi) sets the appropriate
* parameters. After booting linux, the "/dev/ttyUL1" must be present.
*/
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include "uart.h"
#define MAX_RECV_SIZE 235
void openuart(struct UartDevice *device, char *devname, int rate) {
device->name = devname;
device->rate = rate;
printf("UART open %s\n", device->name);
int rc = uartStart(device, 0);
if (rc) {
printf("uartStart %s fail\n", device->name);
exit(-1);
}
}
int main(int argc, char *argv[]) {
struct UartDevice dev = {0};
// struct UartDevice dev2 = {0};
if (argc != 2) {
printf("Usage:%s dev1\n", argv[0]);
// printf("Demo:%s /dev/ttyUSB0 /dev/ttyUSB1\n", argv[0]);
exit(-1);
}
openuart(&dev, argv[1], B9600);
// openuart(&dev2, argv[2], B9600);
char buf[1024] = {0x55};
memset(buf, 0x55, 1024);
for (size_t i = 0;; i++) {
int ret1, ret2;
ret1 = uartSend(&dev, buf, 1); // send the received text over UART
// ret2 = uartSend(&dev2, buf, 1); // send the received text over UART
printf("send %d %d characters %d\n", ret1, ret2, i);
usleep(1*1000);
}
while (1) {
sleep(1);
}
return 0;
}