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

4 years ago
  1. /*
  2. * Created on: Aug 5, 2019
  3. * Author: Cristian Fatu
  4. * This project implements a basic UART communication over UART on
  5. * Petalinux, unsing Uart Lite linux driver. The hardware platform implements an
  6. * UART Lite IP core and the device tree (in pl.dtsi) sets the appropriate
  7. * parameters. After booting linux, the "/dev/ttyUL1" must be present.
  8. */
  9. #include <fcntl.h>
  10. #include <stdint.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <termios.h>
  15. #include <unistd.h>
  16. #include "uart.h"
  17. #define MAX_RECV_SIZE 235
  18. void openuart(struct UartDevice *device, char *devname, int rate) {
  19. device->name = devname;
  20. device->rate = rate;
  21. printf("UART open %s\n", device->name);
  22. int rc = uartStart(device, 0);
  23. if (rc) {
  24. printf("uartStart %s fail\n", device->name);
  25. exit(-1);
  26. }
  27. }
  28. int main(int argc, char *argv[]) {
  29. struct UartDevice dev = {0};
  30. // struct UartDevice dev2 = {0};
  31. if (argc != 2) {
  32. printf("Usage:%s dev1\n", argv[0]);
  33. // printf("Demo:%s /dev/ttyUSB0 /dev/ttyUSB1\n", argv[0]);
  34. exit(-1);
  35. }
  36. openuart(&dev, argv[1], B9600);
  37. // openuart(&dev2, argv[2], B9600);
  38. char buf[1024] = {0x55};
  39. memset(buf, 0x55, 1024);
  40. for (size_t i = 0;; i++) {
  41. int ret1, ret2;
  42. ret1 = uartSend(&dev, buf, 1); // send the received text over UART
  43. // ret2 = uartSend(&dev2, buf, 1); // send the received text over UART
  44. printf("send %d %d characters %d\n", ret1, ret2, i);
  45. usleep(1*1000);
  46. }
  47. while (1) {
  48. sleep(1);
  49. }
  50. return 0;
  51. }