recv.c 596 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include "bus.h"
  6. #ifdef __linux__
  7. #define PIN_DATA 2
  8. #define PIN_CLK 3
  9. #define PIN_ACK 4
  10. int data[3]={0};
  11. #include "io.h"
  12. int main()
  13. {
  14. bus_t bus;
  15. pthread_t thread;
  16. FILE* file = NULL;
  17. setup_io();
  18. bus_init_recv(&bus, PIN_DATA, PIN_CLK, PIN_ACK);
  19. init_read_pin(PIN_DATA, PIN_CLK, PIN_ACK);
  20. pthread_create(&thread, NULL, bus_recv_thread, &bus);
  21. while(1)
  22. {
  23. uint32_t c;
  24. char buffer[16];
  25. bus_read(&bus, &c, 4);
  26. printf("%ld' s %ld ms %'d us \n", c/1000000, c%1000000/1000, c%1000);
  27. }
  28. }
  29. #endif