StreamingSink.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: StreamingSink.h
  4. * Description: Streaming Sink working with the RingBuffer
  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_SINK_H_
  29. #define _STREAMING_SINK_H_
  30. #include "RingBuffer.h"
  31. /* This is deprecated. Don't use it */
  32. template<typename IN, int inputSize>
  33. class StreamingSink: public GenericSink<IN, inputSize>
  34. {
  35. public:
  36. StreamingSink(FIFOBase<IN> &src,ring_config_t *config):
  37. GenericSink<IN,inputSize>(src),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. {
  49. IN *b=this->getReadBuffer();
  50. int bufID=ringUserReserveBuffer(mConfig);
  51. uint8_t *buf=ringGetBufferAddress(mConfig,bufID);
  52. if (buf != NULL)
  53. {
  54. /* If a buffer is available we copy the data to the FIFO
  55. */
  56. memcpy(buf,(void*)b,inputSize*sizeof(IN));
  57. /* We release the buffer so than it can be used by the interrupt */
  58. ringUserReleaseBuffer(mConfig);
  59. return(0);
  60. }
  61. else
  62. {
  63. return(mConfig->error);
  64. }
  65. return(0);
  66. }
  67. protected:
  68. ring_config_t *mConfig;
  69. };
  70. #endif /* _STREAMING_SINK_H_ */