main_fifo.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include <cstdio>
  2. #include <cstdint>
  3. #if defined(COMMAND_LINE)
  4. #include <cstdlib>
  5. #endif
  6. #include <cassert>
  7. #include "RTE_Components.h"
  8. #include CMSIS_device_header
  9. #include "arm_math_types.h"
  10. #include "GenericNodes.h"
  11. #define BUFSIZE 100
  12. #define FIFOSIZE0 100
  13. float32_t buf1[BUFSIZE]={0};
  14. template<typename T, int length>
  15. class FIFOPublicSync : public FIFO<T,length,0,0>
  16. {
  17. public:
  18. FIFOPublicSync(T *buffer,int delay=0):FIFO<T,length,0,0>(buffer,delay){};
  19. int getReadPos() const{return(this->readPos);};
  20. int getWritePos() const{return(this->writePos);};
  21. };
  22. template<typename T, int length>
  23. class FIFOPublicAsync : public FIFO<T,length,0,1>
  24. {
  25. public:
  26. FIFOPublicAsync(T *buffer,int delay=0):FIFO<T,length,0,1>(buffer,delay){};
  27. int getReadPos() const{return(this->readPos);};
  28. int getWritePos() const{return(this->writePos);};
  29. };
  30. int main(void)
  31. {
  32. float32_t *in,*out;
  33. // System Initialization
  34. SystemCoreClockUpdate();
  35. (void)in;
  36. (void)out;
  37. FIFOPublicSync<float32_t,FIFOSIZE0> fifo_sync(buf1);
  38. printf("SYNC\r\n");
  39. memset(buf1,0,sizeof(float32_t)*BUFSIZE);
  40. printf("r=%d, w=%d\n\r",fifo_sync.getReadPos(),fifo_sync.getWritePos());
  41. assert(fifo_sync.getWritePos() + 50 <= FIFOSIZE0);
  42. out = fifo_sync.getWriteBuffer(50);
  43. printf("r=%d, w=%d\n\r",fifo_sync.getReadPos(),fifo_sync.getWritePos());
  44. assert(fifo_sync.getWritePos() + 50 <= FIFOSIZE0);
  45. out = fifo_sync.getWriteBuffer(30);
  46. printf("r=%d, w=%d\n\r",fifo_sync.getReadPos(),fifo_sync.getWritePos());
  47. in = fifo_sync.getReadBuffer(20);
  48. printf("r=%d, w=%d\n\r",fifo_sync.getReadPos(),fifo_sync.getWritePos());
  49. in = fifo_sync.getReadBuffer(20);
  50. printf("r=%d, w=%d\n\r",fifo_sync.getReadPos(),fifo_sync.getWritePos());
  51. assert(fifo_sync.getWritePos() + 50 > FIFOSIZE0);
  52. out = fifo_sync.getWriteBuffer(30);
  53. assert(fifo_sync.getWritePos() <= FIFOSIZE0);
  54. printf("r=%d, w=%d\n\r",fifo_sync.getReadPos(),fifo_sync.getWritePos());
  55. FIFOPublicAsync<float32_t,FIFOSIZE0> fifo_async(buf1);
  56. printf("\r\nASYNC\r\n");
  57. memset(buf1,0,sizeof(float32_t)*BUFSIZE);
  58. printf("r=%d, w=%d\n\r",fifo_async.getReadPos(),fifo_async.getWritePos());
  59. assert(fifo_async.getWritePos() + 50 <= FIFOSIZE0);
  60. out = fifo_async.getWriteBuffer(50);
  61. printf("r=%d, w=%d\n\r",fifo_async.getReadPos(),fifo_async.getWritePos());
  62. assert(fifo_async.getWritePos() + 50 <= FIFOSIZE0);
  63. out = fifo_async.getWriteBuffer(30);
  64. printf("r=%d, w=%d\n\r",fifo_async.getReadPos(),fifo_async.getWritePos());
  65. in = fifo_async.getReadBuffer(20);
  66. printf("r=%d, w=%d\n\r",fifo_async.getReadPos(),fifo_async.getWritePos());
  67. in = fifo_async.getReadBuffer(20);
  68. printf("r=%d, w=%d\n\r",fifo_async.getReadPos(),fifo_async.getWritePos());
  69. assert(fifo_async.getWritePos() + 50 > FIFOSIZE0);
  70. out = fifo_async.getWriteBuffer(30);
  71. assert(fifo_async.getWritePos() <= FIFOSIZE0);
  72. printf("r=%d, w=%d\n\r",fifo_async.getReadPos(),fifo_async.getWritePos());
  73. }