StreamingSource.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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(){
  48. OUT *b=this->getWriteBuffer();
  49. /*
  50. Try to reserve a buffer. If no buffer is available, the task running
  51. this node will sleep.
  52. If there is a timeout (configured when the ring buffer was initialized)
  53. the function will return a NULL pointer.
  54. */
  55. int bufID=ringUserReserveBuffer(mConfig);
  56. uint8_t *buf=ringGetBufferAddress(mConfig,bufID);
  57. if (buf != NULL)
  58. {
  59. /* If a buffer is available we copy the data to the FIFO
  60. */
  61. memcpy((void*)b,buf,outputSize*sizeof(OUT));
  62. /* We release the buffer so than it can be used by the interrupt */
  63. ringUserReleaseBuffer(mConfig);
  64. return(0);
  65. }
  66. else
  67. {
  68. return(mConfig->error);
  69. }
  70. };
  71. protected:
  72. ring_config_t *mConfig;
  73. };
  74. #endif /* _STREAMING_SOURCE_H_ */