recv.c 564 B

123456789101112131415161718192021222324252627282930313233
  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 0
  8. #define PIN_CLK 1
  9. #define PIN_ACK 2
  10. int main()
  11. {
  12. bus_t bus;
  13. pthread_t thread;
  14. FILE* file = NULL;
  15. init_read_pin(PIN_DATA, PIN_CLK, PIN_ACK);
  16. bus_init_recv(&bus, PIN_DATA, PIN_CLK, PIN_ACK);
  17. pthread_create(&thread, NULL, bus_recv_thread, &bus);
  18. while(1)
  19. {
  20. uint32_t c;
  21. bus_read(&bus, &c, 4);
  22. file=fopen("data", "r+");
  23. fprintf(file,"%u\n", c);
  24. fclose(file);
  25. }
  26. free_fifo(PIN_DATA, PIN_CLK, PIN_ACK);
  27. }
  28. #endif