StreamingSource.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /* This is deprecated. Don't use it */
  32. template<typename OUT,int outputSize>
  33. class StreamingSource: public GenericSource<OUT,outputSize>
  34. {
  35. public:
  36. StreamingSource(FIFOBase<OUT> &dst,ring_config_t *config):
  37. GenericSource<OUT,outputSize>(dst),mConfig(config){};
  38. int prepareForRunning() override
  39. {
  40. if (this->willUnderflow()
  41. )
  42. {
  43. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  44. }
  45. return(0);
  46. };
  47. int run() override
  48. {
  49. OUT *b=this->getWriteBuffer();
  50. /*
  51. Try to reserve a buffer. If no buffer is available, the task running
  52. this node will sleep.
  53. If there is a timeout (configured when the ring buffer was initialized)
  54. the function will return a NULL pointer.
  55. */
  56. int bufID=ringUserReserveBuffer(mConfig);
  57. uint8_t *buf=ringGetBufferAddress(mConfig,bufID);
  58. if (buf != NULL)
  59. {
  60. /* If a buffer is available we copy the data to the FIFO
  61. */
  62. memcpy((void*)b,buf,outputSize*sizeof(OUT));
  63. /* We release the buffer so than it can be used by the interrupt */
  64. ringUserReleaseBuffer(mConfig);
  65. return(0);
  66. }
  67. else
  68. {
  69. return(mConfig->error);
  70. }
  71. };
  72. protected:
  73. ring_config_t *mConfig;
  74. };
  75. #endif /* _STREAMING_SOURCE_H_ */