From b984d738f4453510a98e44320e807d67faabe22f Mon Sep 17 00:00:00 2001 From: Christophe Favergeon Date: Wed, 20 Oct 2021 15:27:56 +0200 Subject: [PATCH] CMSIS-DSP: Preliminary support for VHT in SDF. --- SDFTools/ARM.SDF.pdsc | 82 +++++++++ .../cpp/RingBuffer/VHT/AudioInterrupt.cpp | 159 ++++++++++++++++++ .../cpp/RingBuffer/VHT/Config/RingConfig.h | 48 ++++++ .../nodes/cpp/RingBuffer/VHT/RingPrivate.h | 80 +++++++++ .../nodes/cpp/RingBuffer/VHT/SchedEvents.h | 68 ++++++++ .../sdf/nodes/cpp/RingBuffer/VHT/ring.scvd | 66 ++++++++ SDFTools/sdf/src/GenericNodes.h | 3 +- 7 files changed, 505 insertions(+), 1 deletion(-) create mode 100755 SDFTools/ARM.SDF.pdsc create mode 100755 SDFTools/sdf/nodes/cpp/RingBuffer/VHT/AudioInterrupt.cpp create mode 100755 SDFTools/sdf/nodes/cpp/RingBuffer/VHT/Config/RingConfig.h create mode 100755 SDFTools/sdf/nodes/cpp/RingBuffer/VHT/RingPrivate.h create mode 100755 SDFTools/sdf/nodes/cpp/RingBuffer/VHT/SchedEvents.h create mode 100755 SDFTools/sdf/nodes/cpp/RingBuffer/VHT/ring.scvd diff --git a/SDFTools/ARM.SDF.pdsc b/SDFTools/ARM.SDF.pdsc new file mode 100755 index 00000000..52b258ed --- /dev/null +++ b/SDFTools/ARM.SDF.pdsc @@ -0,0 +1,82 @@ + + + + SDF + Synchronous Data Flow for CMSIS-DSP + ARM + + http://www.keil.com/pack/ + + + + Adding support for VHT platform + + + First version of Synchronous Data Flow + + + + + + + + + + + + + + + + + + + + + + + + + + SDFTools for CMSIS-DSP + + + + + + + + + + + AudioSource for VHT + + + + + + + + + + + + + + + + + RingBuffer + + + + + + + + + + + + + \ No newline at end of file diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/AudioInterrupt.cpp b/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/AudioInterrupt.cpp new file mode 100755 index 00000000..ba98bddd --- /dev/null +++ b/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/AudioInterrupt.cpp @@ -0,0 +1,159 @@ +#include +#include "audio_drv.h" +#include "arm_vsi.h" +#ifdef _RTE_ +#include "RTE_Components.h" +#endif +#include CMSIS_device_header + +#include "cmsis_os2.h" + + + +#include "RingBuffer.h" + +#include "arm_math.h" + +#include "SchedEvents.h" +#include "RingConfig.h" + +#include "RingInit.h" + +#define AudioIn_IRQn ((IRQn_Type)ARM_VSI0_IRQn) /* Audio Input Interrupt number */ + +extern osThreadId_t gAudioThreadID; + +// Number of bytes read by DMA +#define AUDIO_BLOCK_NUM (4) + +// Number of DMA blocks +#define AUDIO_DMA_NB_BLOCKS (RING_BUFSIZE >> 2) + + +extern int32_t AudioDrv_Setup(void); + + + +#if RX_ENABLED +extern ring_config_t ringConfigRX; + +#ifdef __FVP_PY +__attribute__((section(".ARM.__at_0x90000000"))) +#endif +__ALIGNED(16) static uint8_t audio_bufferRX[RING_BUFSIZE]; +static uint8_t *reservedBufRX=NULL; + +#endif + +#if TX_ENABLED +extern ring_config_t ringConfigTX; + +#ifdef __FVP_PY +__attribute__((section(".ARM.__at_0x9FFF0000"))) +#endif +__ALIGNED(16) static uint8_t audio_bufferTX[RING_BUFSIZE]; +static uint8_t *reservedBufTX=NULL; +#endif + +static void AudioEvent (uint32_t event) { + +#if RX_ENABLED + if (event & AUDIO_DRV_EVENT_RX_DATA) + { + if (reservedBufRX != NULL) + { + memcpy(reservedBufRX,audio_bufferRX,RING_BUFSIZE); + ringInterruptReleaseBuffer(&ringConfigRX,(void *)gAudioThreadID); + int reservedRX=ringInterruptReserveBuffer(&ringConfigRX); + reservedBufRX=ringGetBufferAddress(&ringConfigRX,reservedRX); + } + } +#endif + +#if TX_ENABLED + if (event & AUDIO_DRV_EVENT_TX_DATA) + { + if (reservedBufTX != NULL) + { + memcpy(audio_bufferTX,reservedBufTX,RING_BUFSIZE); + } + ringInterruptReleaseBuffer(&ringConfigTX,(void *)gAudioThreadID); + int reservedTX=ringInterruptReserveBuffer(&ringConfigTX); + reservedBufTX=ringGetBufferAddress(&ringConfigTX,reservedTX); + } +#endif +} + +int32_t AudioDrv_Setup(void) { + int32_t ret; + + ret = AudioDrv_Initialize(AudioEvent); + if (ret != 0) { + return ret; + } + +#if RX_ENABLED + + ret = AudioDrv_Configure(AUDIO_DRV_INTERFACE_RX, + AUDIO_NBCHANNELS, /* single channel */ + 8U * AUDIO_CHANNEL_ENCODING, /* 16 sample bits */ + static_cast(AUDIO_SAMPLINGFREQUENCY)); + if (ret != 0) { + return ret; + } + + /* Work because user process not started yet + */ + + int reservedRX=ringInterruptReserveBuffer(&ringConfigRX); + reservedBufRX=ringGetBufferAddress(&ringConfigRX,reservedRX); + + ret = AudioDrv_SetBuf(AUDIO_DRV_INTERFACE_RX, + audio_bufferRX, AUDIO_BLOCK_NUM, AUDIO_DMA_NB_BLOCKS); + if (ret != 0) { + return ret; + } + + ret = AudioDrv_Control(AUDIO_DRV_CONTROL_RX_ENABLE); + if (ret != 0) { + return ret; + } +#endif + +#if TX_ENABLED + ret = AudioDrv_Configure(AUDIO_DRV_INTERFACE_TX, + AUDIO_NBCHANNELS, /* single channel */ + 8U * AUDIO_CHANNEL_ENCODING, /* 16 sample bits */ + static_cast(AUDIO_SAMPLINGFREQUENCY)); + if (ret != 0) { + return ret; + } + + /* Work because user process not started yet + */ + + /* dataflow must be one packet ahead of the TX */ + ringUserReserveBuffer(&ringConfigTX); + ringUserReleaseBuffer(&ringConfigTX); + + int reservedTX=ringInterruptReserveBuffer(&ringConfigTX); + reservedBufTX=ringGetBufferAddress(&ringConfigTX,reservedTX); + + ret = AudioDrv_SetBuf(AUDIO_DRV_INTERFACE_TX, + audio_bufferTX, AUDIO_BLOCK_NUM, AUDIO_DMA_NB_BLOCKS); + if (ret != 0) { + return ret; + } + + ret = AudioDrv_Control(AUDIO_DRV_CONTROL_TX_ENABLE); + if (ret != 0) { + return ret; + } + +#endif + + + + return 0; +} + diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/Config/RingConfig.h b/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/Config/RingConfig.h new file mode 100755 index 00000000..0928651d --- /dev/null +++ b/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/Config/RingConfig.h @@ -0,0 +1,48 @@ +#ifndef _RINGCONFIG_H_ +#define _RINGCONFIG_H_ + +// <<< Use Configuration Wizard in Context Menu >>> + +// Audio Configuration +// Sampling Frequency <8000=> 8000 kHz <16000=> 16000 kHz +// <44100=> 44100 kHz <48000=> 48000 kHz +#ifndef AUDIO_SAMPLINGFREQUENCY +#define AUDIO_SAMPLINGFREQUENCY 16000 +#endif + +// Number of samples <100-3000> +// Must be consistent with the settings of the Audio source +#ifndef AUDIO_NBSAMPLES +#define AUDIO_NBSAMPLES 1600 +#endif + +// Number of channels <1=> Mono <2=> Stereo +#ifndef AUDIO_NBCHANNELS +#define AUDIO_NBCHANNELS 1U +#endif + +// Channel encoding <2=> 16 Bits +#ifndef AUDIO_CHANNEL_ENCODING +#define AUDIO_CHANNEL_ENCODING 2U +#endif + +// RX_ENABLED: Enable RX +#define RX_ENABLED 1 + +// TX_ENABLED: Enable TX +#define TX_ENABLED 1 + +// + +// Ring Buffer Configuration +// Number of buffers <2-32> +#ifndef RING_NBBUFS +#define RING_NBBUFS 2 +#endif +// + +// <<< end of configuration section >>> + +#define RING_BUFSIZE (AUDIO_NBSAMPLES * AUDIO_NBCHANNELS * AUDIO_CHANNEL_ENCODING) + +#endif diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/RingPrivate.h b/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/RingPrivate.h new file mode 100755 index 00000000..31ccdfb7 --- /dev/null +++ b/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/RingPrivate.h @@ -0,0 +1,80 @@ +/* ---------------------------------------------------------------------- + * Project: CMSIS DSP Library + * Title: RingPrivate.h + * Description: Implementation for RTX + Keil MDK + * + * $Date: 30 July 2021 + * $Revision: V1.10.0 + * + * Target Processor: Cortex-M and Cortex-A cores + * -------------------------------------------------------------------- */ +/* + * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _RINGPRIVATE_H_ +#define _RINGPRIVATE_H_ + +/* + +Implementation for RTX + Keil MDK Event logger + +*/ + +#include +#include "audio_drv.h" +#include "arm_vsi.h" +#ifdef _RTE_ +#include "RTE_Components.h" +#endif +#include CMSIS_device_header + +#include "cmsis_os2.h" + +#ifndef AudioIn_IRQn +#define AudioIn_IRQn ((IRQn_Type)0) /* Audio Input Interrupt number */ +#endif + +#include "SchedEvents.h" +/* + +RTX dependent definition + +*/ +#define RING_BEGINCRITICALSECTION() NVIC_DisableIRQ (AudioIn_IRQn) + +#define RING_ENDCRITICALSECTION() NVIC_EnableIRQ (AudioIn_IRQn) + +#define RING_WAIT_BUFFER(TIMEOUT) osThreadFlagsWait(1,osFlagsWaitAny,(TIMEOUT)) +#define RING_HASWAITERROR(F) (F < 0) + +#define RING_RELEASE_BUFFER(THREADID) osThreadFlagsSet((osThreadId_t)(THREADID),1) + +/* Debug trace using Event Recorder */ +#define RING_DBG_USER_RESERVE_BUFFER(ID) EventRecord2 (Evt_UsrReserve, (ID), 0) +#define RING_DBG_USER_RELEASE_BUFFER(ID) EventRecord2 (Evt_UsrRelease, (ID), 0) +#define RING_DBG_USER_WAIT_BUFFER(ID) EventRecord2 (Evt_UsrWait, (ID), 0) +#define RING_DBG_USER_BUFFER_RELEASED(ID) EventRecord2 (Evt_UsrFree, (ID), 0) +#define RING_DBG_USER_STATUS(SA,SB) EventRecord2 (Evt_UsrStatus, config->SA,config->SB) + +#define RING_DBG_INT_RESERVE_BUFFER(ID) EventRecord2 (Evt_IntReserve, (ID), 0) +#define RING_DBG_INT_RELEASE_BUFFER(ID) EventRecord2 (Evt_IntRelease, (ID), 0) +#define RING_DBG_INT_RELEASE_USER() EventRecord2 (Evt_IntReleaseUser, 0, 0) +#define RING_DBG_INT_STATUS(SA,SB) EventRecord2 (Evt_IntStatus, config->SA,config->SB) + +#define RING_DBG_ERROR(ERROR) EventRecord2 (Evt_Error, (ERROR), 0) + +#endif \ No newline at end of file diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/SchedEvents.h b/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/SchedEvents.h new file mode 100755 index 00000000..3c3ca1d7 --- /dev/null +++ b/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/SchedEvents.h @@ -0,0 +1,68 @@ +/* ---------------------------------------------------------------------- + * Project: CMSIS DSP Library + * Title: SchedEvents.h + * Description: Definition of the events for the Keil MDK Event logger + * + * $Date: 30 July 2021 + * $Revision: V1.10.0 + * + * Target Processor: Cortex-M and Cortex-A cores + * -------------------------------------------------------------------- */ +/* + * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _SCHEDEVT_H +#define _SCHEDEVT_H + +/* + +Definition of Event IDs for Keil MDK EventRecorder + +*/ +#include "EventRecorder.h" + +#define EvtNodes 0x00 +#define EvtRing_User 0x01 +#define EvtRing_Int 0x02 +#define EvtRing_All 0x03 + +/* Node events */ + +#define Evt_Sink EventID (EventLevelAPI, EvtNodes, 0x00) +#define Evt_Source EventID (EventLevelAPI, EvtNodes, 0x01) + +/* User Ring Events */ +#define Evt_UsrReserve EventID (EventLevelAPI, EvtRing_User, 0x00) +#define Evt_UsrRelease EventID (EventLevelAPI, EvtRing_User, 0x01) +#define Evt_UsrWait EventID (EventLevelAPI, EvtRing_User, 0x02) +#define Evt_UsrFree EventID (EventLevelAPI, EvtRing_User, 0x03) +#define Evt_UsrStatus EventID (EventLevelAPI, EvtRing_User, 0x04) + + +/* Interrupt Ring Events */ +#define Evt_IntReserve EventID (EventLevelAPI, EvtRing_Int, 0x00) +#define Evt_IntRelease EventID (EventLevelAPI, EvtRing_Int, 0x01) +#define Evt_IntReleaseUser EventID (EventLevelAPI, EvtRing_Int, 0x02) +#define Evt_IntStatus EventID (EventLevelAPI, EvtRing_Int, 0x03) + + +/* Other Ring Events */ +#define Evt_Error EventID (EventLevelError, EvtRing_All, 0x00) + + + +#endif \ No newline at end of file diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/ring.scvd b/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/ring.scvd new file mode 100755 index 00000000..b70cb854 --- /dev/null +++ b/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/ring.scvd @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SDFTools/sdf/src/GenericNodes.h b/SDFTools/sdf/src/GenericNodes.h index 886f9e43..70124be7 100755 --- a/SDFTools/sdf/src/GenericNodes.h +++ b/SDFTools/sdf/src/GenericNodes.h @@ -270,10 +270,11 @@ protected: }; - +#if !defined(CHECKERROR) #define CHECKERROR if (sdfError < 0) \ {\ break;\ } #endif +#endif