StreamingSource.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: StreamingSource.h
  4. * Description: Streaming source working with the Ring buffer
  5. *
  6. * $Date: 30 July 2021
  7. * $Revision: V1.10.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #ifndef _STREAMING_SOURCE_H_
  29. #define _STREAMING_SOURCE_H_
  30. #include "RingBuffer.h"
  31. template<typename OUT,int outputSize>
  32. class StreamingSource: public GenericSource<OUT,outputSize>
  33. {
  34. public:
  35. StreamingSource(FIFOBase<OUT> &dst,ring_config_t *config):
  36. GenericSource<OUT,outputSize>(dst),mConfig(config){};
  37. int run(){
  38. OUT *b=this->getWriteBuffer();
  39. /*
  40. Try to reserve a buffer. If no buffer is available, the task running
  41. this node will sleep.
  42. If there is a timeout (configured when the ring buffer was initialized)
  43. the function will return a NULL pointer.
  44. */
  45. int bufID=ringUserReserveBuffer(mConfig);
  46. uint8_t *buf=ringGetBufferAddress(mConfig,bufID);
  47. if (buf != NULL)
  48. {
  49. /* If a buffer is available we copy the data to the FIFO
  50. */
  51. memcpy((void*)b,buf,outputSize*sizeof(OUT));
  52. /* We release the buffer so than it can be used by the interrupt */
  53. ringUserReleaseBuffer(mConfig);
  54. return(0);
  55. }
  56. else
  57. {
  58. return(mConfig->error);
  59. }
  60. };
  61. protected:
  62. ring_config_t *mConfig;
  63. };
  64. #endif /* _STREAMING_SOURCE_H_ */