diff --git a/SDFTools/ARM.SDF.pdsc b/SDFTools/ARM.SDF.pdsc index 52b258ed..2e7cea50 100755 --- a/SDFTools/ARM.SDF.pdsc +++ b/SDFTools/ARM.SDF.pdsc @@ -8,6 +8,9 @@ http://www.keil.com/pack/ + + Refactor of the pack + Adding support for VHT platform @@ -27,56 +30,90 @@ - - - + + + + + + + + + + + + + + + + + - - SDFTools for CMSIS-DSP + + SDF core files for CMSIS-DSP - - - AudioSource for VHT + + Streaming nodes for SDF + + + + + + + + + + + + + + + + + Audio Source and Sink for VHT - + - + + + - + - - - - RingBuffer + + Video Source for VHT - - - + + + + + + + - - + \ No newline at end of file diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/Config/RingConfig.h b/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/Config/RingConfig.h deleted file mode 100755 index 5f77d6de..00000000 --- a/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/Config/RingConfig.h +++ /dev/null @@ -1,51 +0,0 @@ -#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 <256=> 256 <512=> 512 <1024=> 1024 <2048=> 2048 -// Must be consistent with the settings of the Audio source -#ifndef AUDIO_NBSAMPLES -#define AUDIO_NBSAMPLES 2048 -#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 - -// SDF_VHT_TX_RX_ORDERING: Force TX RX ordering -#define SDF_VHT_TX_RX_ORDERING 0 - -// - -// Ring Buffer Configuration -// Number of buffers <2=> 2 <4=> 4 <8=> 8 <16=> 16 <32=> 32 -#ifndef RING_NBBUFS -#define RING_NBBUFS 4 -#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/StreamingNodes/CMSIS_RTOS/RingPrivate.h similarity index 98% rename from SDFTools/sdf/nodes/cpp/RingBuffer/VHT/RingPrivate.h rename to SDFTools/sdf/nodes/cpp/StreamingNodes/CMSIS_RTOS/RingPrivate.h index c8b6b459..a9b2300c 100755 --- a/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/RingPrivate.h +++ b/SDFTools/sdf/nodes/cpp/StreamingNodes/CMSIS_RTOS/RingPrivate.h @@ -35,7 +35,6 @@ Implementation for RTX + Keil MDK Event logger */ #include -#include "audio_drv.h" #include "arm_vsi.h" #ifdef _RTE_ #include "RTE_Components.h" diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/SchedEvents.h b/SDFTools/sdf/nodes/cpp/StreamingNodes/CMSIS_RTOS/SchedEvents.h similarity index 100% rename from SDFTools/sdf/nodes/cpp/RingBuffer/VHT/SchedEvents.h rename to SDFTools/sdf/nodes/cpp/StreamingNodes/CMSIS_RTOS/SchedEvents.h diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/ring.scvd b/SDFTools/sdf/nodes/cpp/StreamingNodes/CMSIS_RTOS/ring.scvd similarity index 100% rename from SDFTools/sdf/nodes/cpp/RingBuffer/VHT/ring.scvd rename to SDFTools/sdf/nodes/cpp/StreamingNodes/CMSIS_RTOS/ring.scvd diff --git a/SDFTools/sdf/nodes/cpp/StreamingNodes/Config/AudioConfig.h b/SDFTools/sdf/nodes/cpp/StreamingNodes/Config/AudioConfig.h new file mode 100755 index 00000000..347c4df5 --- /dev/null +++ b/SDFTools/sdf/nodes/cpp/StreamingNodes/Config/AudioConfig.h @@ -0,0 +1,69 @@ +#ifndef _AUDIOCONFIG_H_ +#define _AUDIOCONFIG_H_ + +// <<< Use Configuration Wizard in Context Menu >>> + +// Audio Configuration for RX +#ifndef AUDIO_DRV_RX_ENABLED +#define AUDIO_DRV_RX_ENABLED 1 +#endif +// Sampling Frequency <8000=> 8000 kHz <16000=> 16000 kHz +// <44100=> 44100 kHz <48000=> 48000 kHz +#ifndef AUDIO_DRV_SAMPLINGFREQUENCY_RX +#define AUDIO_DRV_SAMPLINGFREQUENCY_RX 16000 +#endif + +// Number of samples <256=> 256 <512=> 512 <1024=> 1024 <2048=> 2048 +// Must be consistent with the settings of the Audio source +#ifndef AUDIO_DRV_NBSAMPLES_RX +#define AUDIO_DRV_NBSAMPLES_RX 2048 +#endif + +// Number of channels <1=> Mono <2=> Stereo +#ifndef AUDIO_DRV_NBCHANNELS_RX +#define AUDIO_DRV_NBCHANNELS_RX 1U +#endif + +// Channel encoding <2=> 16 Bits +#ifndef AUDIO_DRV_CHANNEL_ENCODING_RX +#define AUDIO_DRV_CHANNEL_ENCODING_RX 2U +#endif + +// + +// Audio Configuration for TX +#ifndef AUDIO_DRV_TX_ENABLED +#define AUDIO_DRV_TX_ENABLED 1 +#endif +// Sampling Frequency <8000=> 8000 kHz <16000=> 16000 kHz +// <44100=> 44100 kHz <48000=> 48000 kHz +#ifndef AUDIO_DRV_SAMPLINGFREQUENCY_TX +#define AUDIO_DRV_SAMPLINGFREQUENCY_TX 16000 +#endif + +// Number of samples <256=> 256 <512=> 512 <1024=> 1024 <2048=> 2048 +// Must be consistent with the settings of the Audio source +#ifndef AUDIO_DRV_NBSAMPLES_TX +#define AUDIO_DRV_NBSAMPLES_TX 2048 +#endif + +// Number of channels <1=> Mono <2=> Stereo +#ifndef AUDIO_DRV_NBCHANNELS_TX +#define AUDIO_DRV_NBCHANNELS_TX 1U +#endif + +// Channel encoding <2=> 16 Bits +#ifndef AUDIO_DRV_CHANNEL_ENCODING_TX +#define AUDIO_DRV_CHANNEL_ENCODING_TX 2U +#endif + +// + +// SDF_VHT_TX_RX_ORDERING: Force TX RX ordering +#define SDF_VHT_TX_RX_ORDERING 0 + +// <<< end of configuration section >>> + +#define SDF_AUDIO_CONFIG + +#endif diff --git a/SDFTools/sdf/nodes/cpp/StreamingNodes/Config/RingConfig.h b/SDFTools/sdf/nodes/cpp/StreamingNodes/Config/RingConfig.h new file mode 100755 index 00000000..33b346d1 --- /dev/null +++ b/SDFTools/sdf/nodes/cpp/StreamingNodes/Config/RingConfig.h @@ -0,0 +1,26 @@ +#ifndef _RINGCONFIG_H_ +#define _RINGCONFIG_H_ + +// <<< Use Configuration Wizard in Context Menu >>> + + +// Ring Buffer Configuration +// Number of buffers <2=> 2 <4=> 4 <8=> 8 <16=> 16 <32=> 32 +#ifndef RING_NBBUFS +#define RING_NBBUFS 4 +#endif +// + +// <<< end of configuration section >>> + +#if defined(SDF_AUDIO_CONFIG) +#define RING_BUFSIZE_RX (AUDIO_DRV_NBSAMPLES_RX * AUDIO_DRV_NBCHANNELS_RX * AUDIO_DRV_CHANNEL_ENCODING_RX) +#define RING_BUFSIZE_TX (AUDIO_DRV_NBSAMPLES_TX * AUDIO_DRV_NBCHANNELS_TX * AUDIO_DRV_CHANNEL_ENCODING_TX) +#endif + +#if defined(SDF_VIDEO_CONFIG) +#define RING_BUFSIZE_RX (VIDEO_DRV_WIDTH * VIDEO_DRV_HEIGHT * VIDEO_DRV_PIXEL_SIZE) +#define RING_BUFSIZE_TX 0 +#endif + +#endif diff --git a/SDFTools/sdf/nodes/cpp/StreamingNodes/Config/VideoConfig.h b/SDFTools/sdf/nodes/cpp/StreamingNodes/Config/VideoConfig.h new file mode 100755 index 00000000..f52d1898 --- /dev/null +++ b/SDFTools/sdf/nodes/cpp/StreamingNodes/Config/VideoConfig.h @@ -0,0 +1,35 @@ +#ifndef _VIDEOCONFIG_H_ +#define _VIDEOCONFIG_H_ + +// <<< Use Configuration Wizard in Context Menu >>> + +// Video Configuration +// Width in pixels <16-640> +#ifndef VIDEO_DRV_WIDTH +#define VIDEO_DRV_WIDTH 32 +#endif + +// Height in pixels <16-640> +#ifndef VIDEO_DRV_HEIGHT +#define VIDEO_DRV_HEIGHT 32 +#endif + +// Pixel size in bytes <1=> 1 <2=> 2 +#ifndef VIDEO_DRV_PIXEL_SIZE +#define VIDEO_DRV_PIXEL_SIZE 1 +#endif + +// Frame rate <10=> 10 <25=> 25 <30=> 30 <60=> 60 +#ifndef VIDEO_DRV_FRAME_RATE +#define VIDEO_DRV_FRAME_RATE 10 +#endif + +// + + + +// <<< end of configuration section >>> + +#define SDF_VIDEO_CONFIG + +#endif diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/README.md b/SDFTools/sdf/nodes/cpp/StreamingNodes/README.md similarity index 100% rename from SDFTools/sdf/nodes/cpp/RingBuffer/README.md rename to SDFTools/sdf/nodes/cpp/StreamingNodes/README.md diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/RingBuffer/RingBuffer.cpp b/SDFTools/sdf/nodes/cpp/StreamingNodes/RingBuffer/RingBuffer.cpp similarity index 100% rename from SDFTools/sdf/nodes/cpp/RingBuffer/RingBuffer/RingBuffer.cpp rename to SDFTools/sdf/nodes/cpp/StreamingNodes/RingBuffer/RingBuffer.cpp diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/RingBuffer/RingBuffer.h b/SDFTools/sdf/nodes/cpp/StreamingNodes/RingBuffer/RingBuffer.h similarity index 100% rename from SDFTools/sdf/nodes/cpp/RingBuffer/RingBuffer/RingBuffer.h rename to SDFTools/sdf/nodes/cpp/StreamingNodes/RingBuffer/RingBuffer.h diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/RingBuffer/RingInit.cpp b/SDFTools/sdf/nodes/cpp/StreamingNodes/RingBuffer/RingInit.cpp similarity index 80% rename from SDFTools/sdf/nodes/cpp/RingBuffer/RingBuffer/RingInit.cpp rename to SDFTools/sdf/nodes/cpp/StreamingNodes/RingBuffer/RingInit.cpp index 60fe22f1..f4853c9f 100755 --- a/SDFTools/sdf/nodes/cpp/RingBuffer/RingBuffer/RingInit.cpp +++ b/SDFTools/sdf/nodes/cpp/StreamingNodes/RingBuffer/RingInit.cpp @@ -33,28 +33,25 @@ -int initRingAndAudio(ring_config_t *ringConfigRX, +void initRing(ring_config_t *ringConfigRX, uint8_t *rxBuffer, + uint32_t bufSizeRX, int rxInterruptID, ring_config_t *ringConfigTX, uint8_t *txBuffer, + uint32_t bufSizeTX, int txInterruptID, int timeOut) { /* Initialization of the ring buffer data structure */ if (ringConfigRX != NULL) { - ringInit(ringConfigRX,RING_NBBUFS,RING_BUFSIZE,rxBuffer,rxInterruptID,timeOut); + ringInit(ringConfigRX,RING_NBBUFS,bufSizeRX,rxBuffer,rxInterruptID,timeOut); } if (ringConfigTX != NULL) { - ringInit(ringConfigTX,RING_NBBUFS,RING_BUFSIZE,txBuffer,txInterruptID,timeOut); + ringInit(ringConfigTX,RING_NBBUFS,bufSizeTX,txBuffer,txInterruptID,timeOut); } - /* Initialization of the audio HW and reservation of first buffer from the - ring buffer - */ - int err=AudioDrv_Setup(); - return(err); } \ No newline at end of file diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/RingBuffer/RingInit.h b/SDFTools/sdf/nodes/cpp/StreamingNodes/RingBuffer/RingInit.h similarity index 90% rename from SDFTools/sdf/nodes/cpp/RingBuffer/RingBuffer/RingInit.h rename to SDFTools/sdf/nodes/cpp/StreamingNodes/RingBuffer/RingInit.h index ff3ad7b4..9e4814df 100755 --- a/SDFTools/sdf/nodes/cpp/RingBuffer/RingBuffer/RingInit.h +++ b/SDFTools/sdf/nodes/cpp/StreamingNodes/RingBuffer/RingInit.h @@ -37,18 +37,16 @@ extern "C" { #endif -extern int32_t AudioDrv_Setup(void); extern ring_config_t ringConfigRX; extern ring_config_t ringConfigTX; -extern uint8_t* AudioRXBuffer(); -extern uint8_t* AudioTXBuffer(); - -int initRingAndAudio(ring_config_t *ringConfigRX, +void initRing(ring_config_t *ringConfigRX, uint8_t *rxBuffer, + uint32_t bufSizeRX, int rxInterruptID, ring_config_t *ringConfigTX, uint8_t *txBuffer, + uint32_t bufSizeTX, int txInterruptID, int timeOut); diff --git a/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/AudioInterrupt.cpp b/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/audio/AudioInterrupt.cpp similarity index 68% rename from SDFTools/sdf/nodes/cpp/RingBuffer/VHT/AudioInterrupt.cpp rename to SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/audio/AudioInterrupt.cpp index 4a3728af..d9716298 100755 --- a/SDFTools/sdf/nodes/cpp/RingBuffer/VHT/AudioInterrupt.cpp +++ b/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/audio/AudioInterrupt.cpp @@ -15,87 +15,96 @@ #include "arm_math.h" #include "SchedEvents.h" +#include "AudioConfig.h" #include "RingConfig.h" #include "RingInit.h" -extern osThreadId_t gAudioThreadID; +extern osThreadId_t gStreamingThreadID; // Number of bytes read by DMA -#define AUDIO_BLOCK_SIZE RING_BUFSIZE +#define AUDIO_BLOCK_SIZE_RX RING_BUFSIZE_RX +#define AUDIO_BLOCK_SIZE_TX RING_BUFSIZE_TX // Number of DMA blocks #define AUDIO_DMA_NB_BLOCKS RING_NBBUFS -extern int32_t AudioDrv_Setup(void); -#if RX_ENABLED +#if AUDIO_DRV_RX_ENABLED extern ring_config_t ringConfigRX; #ifdef __FVP_PY __attribute__((section(".ARM.__at_0x90000000"))) #endif #if SDF_VHT_TX_RX_ORDERING -__ALIGNED(16) static uint8_t dmaRX[AUDIO_BLOCK_SIZE]; +__ALIGNED(16) static uint8_t dmaRX[AUDIO_BLOCK_SIZE_RX]; int rxCount=0; #endif -__ALIGNED(16) static uint8_t audio_bufferRX[AUDIO_DMA_NB_BLOCKS*AUDIO_BLOCK_SIZE]; +__ALIGNED(16) static uint8_t audio_bufferRX[AUDIO_DMA_NB_BLOCKS*AUDIO_BLOCK_SIZE_RX]; static uint8_t *reservedBufRX=NULL; #endif -#if TX_ENABLED +#if AUDIO_DRV_TX_ENABLED extern ring_config_t ringConfigTX; #ifdef __FVP_PY __attribute__((section(".ARM.__at_0x9FFF0000"))) #endif #if SDF_VHT_TX_RX_ORDERING -__ALIGNED(16) static uint8_t dmaTX[AUDIO_BLOCK_SIZE]; +__ALIGNED(16) static uint8_t dmaTX[AUDIO_BLOCK_SIZE_TX]; int txCount=0; #endif -__ALIGNED(16) static uint8_t audio_bufferTX[AUDIO_DMA_NB_BLOCKS*AUDIO_BLOCK_SIZE]; +__ALIGNED(16) static uint8_t audio_bufferTX[AUDIO_DMA_NB_BLOCKS*AUDIO_BLOCK_SIZE_TX]; static uint8_t *reservedBufTX=NULL; #endif uint8_t* AudioRXBuffer() { +#if AUDIO_DRV_RX_ENABLED return(audio_bufferRX); +#else + return(NULL); +#endif } uint8_t* AudioTXBuffer() { - return(audio_bufferTX); +#if AUDIO_DRV_TX_ENABLED + return(audio_bufferTX); +#else + return(NULL); +#endif } static void AudioEvent (uint32_t event) { -#if RX_ENABLED +#if AUDIO_DRV_RX_ENABLED if (event & AUDIO_DRV_EVENT_RX_DATA) { #if SDF_VHT_TX_RX_ORDERING - memcpy(reservedBufRX,dmaRX,RING_BUFSIZE); + memcpy(reservedBufRX,dmaRX,RING_BUFSIZE_RX); (void)AudioDrv_Control(AUDIO_DRV_CONTROL_RX_DISABLE); (void)AudioDrv_Control(AUDIO_DRV_CONTROL_TX_ENABLE); #endif - ringInterruptReleaseBuffer(&ringConfigRX,(void *)gAudioThreadID); + ringInterruptReleaseBuffer(&ringConfigRX,(void *)gStreamingThreadID); int reservedRX=ringInterruptReserveBuffer(&ringConfigRX); reservedBufRX=ringGetBufferAddress(&ringConfigRX,reservedRX); } #endif -#if TX_ENABLED +#if AUDIO_DRV_TX_ENABLED if (event & AUDIO_DRV_EVENT_TX_DATA) { #if SDF_VHT_TX_RX_ORDERING - memcpy(dmaTX,reservedBufTX,RING_BUFSIZE); + memcpy(dmaTX,reservedBufTX,RING_BUFSIZE_TX); (void)AudioDrv_Control(AUDIO_DRV_CONTROL_TX_DISABLE); (void)AudioDrv_Control(AUDIO_DRV_CONTROL_RX_ENABLE); #endif - ringInterruptReleaseBuffer(&ringConfigTX,(void *)gAudioThreadID); + ringInterruptReleaseBuffer(&ringConfigTX,(void *)gStreamingThreadID); int reservedTX=ringInterruptReserveBuffer(&ringConfigTX); reservedBufTX=ringGetBufferAddress(&ringConfigTX,reservedTX); } @@ -110,12 +119,12 @@ int32_t AudioDrv_Setup(void) { return ret; } -#if RX_ENABLED +#if AUDIO_DRV_RX_ENABLED ret = AudioDrv_Configure(AUDIO_DRV_INTERFACE_RX, - AUDIO_NBCHANNELS, /* single channel */ - 8U * AUDIO_CHANNEL_ENCODING, /* 16 sample bits */ - static_cast(AUDIO_SAMPLINGFREQUENCY)); + AUDIO_DRV_NBCHANNELS_RX, /* single channel */ + 8U * AUDIO_DRV_CHANNEL_ENCODING_RX, /* 16 sample bits */ + static_cast(AUDIO_DRV_SAMPLINGFREQUENCY_RX)); if (ret != 0) { return ret; } @@ -128,10 +137,10 @@ int32_t AudioDrv_Setup(void) { #if SDF_VHT_TX_RX_ORDERING ret = AudioDrv_SetBuf(AUDIO_DRV_INTERFACE_RX, - dmaRX, 1,AUDIO_BLOCK_SIZE); + dmaRX, 1,AUDIO_BLOCK_SIZE_RX); #else ret = AudioDrv_SetBuf(AUDIO_DRV_INTERFACE_RX, - audio_bufferRX, AUDIO_DMA_NB_BLOCKS,AUDIO_BLOCK_SIZE); + audio_bufferRX, AUDIO_DMA_NB_BLOCKS,AUDIO_BLOCK_SIZE_RX); #endif if (ret != 0) { return ret; @@ -144,13 +153,13 @@ int32_t AudioDrv_Setup(void) { } #endif -#endif /* RX_ENABLED */ +#endif /* AUDIO_DRV_RX_ENABLED */ -#if TX_ENABLED +#if AUDIO_DRV_TX_ENABLED ret = AudioDrv_Configure(AUDIO_DRV_INTERFACE_TX, - AUDIO_NBCHANNELS, /* single channel */ - 8U * AUDIO_CHANNEL_ENCODING, /* 16 sample bits */ - static_cast(AUDIO_SAMPLINGFREQUENCY)); + AUDIO_DRV_NBCHANNELS_TX, /* single channel */ + 8U * AUDIO_DRV_CHANNEL_ENCODING_TX, /* 16 sample bits */ + static_cast(AUDIO_DRV_SAMPLINGFREQUENCY_TX)); if (ret != 0) { return ret; } @@ -170,10 +179,10 @@ int32_t AudioDrv_Setup(void) { #if SDF_VHT_TX_RX_ORDERING ret = AudioDrv_SetBuf(AUDIO_DRV_INTERFACE_TX, - dmaTX, 1 ,AUDIO_BLOCK_SIZE); + dmaTX, 1 ,AUDIO_BLOCK_SIZE_TX); #else ret = AudioDrv_SetBuf(AUDIO_DRV_INTERFACE_TX, - audio_bufferTX, AUDIO_DMA_NB_BLOCKS,AUDIO_BLOCK_SIZE); + audio_bufferTX, AUDIO_DMA_NB_BLOCKS,AUDIO_BLOCK_SIZE_TX); #endif if (ret != 0) { @@ -185,7 +194,7 @@ int32_t AudioDrv_Setup(void) { return ret; } -#endif /* TX_ENABLED */ +#endif /* AUDIO_DRV_TX_ENABLED */ return 0; diff --git a/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/audio/audio_drv.c b/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/audio/audio_drv.c new file mode 100755 index 00000000..d3703078 --- /dev/null +++ b/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/audio/audio_drv.c @@ -0,0 +1,292 @@ +/* + * Copyright (c) 2021 Arm Limited. All rights reserved. + */ + +#include +#include "audio_drv.h" +#include "arm_vsi.h" +#ifdef _RTE_ +#include "RTE_Components.h" +#endif +#include CMSIS_device_header + +/* Audio Peripheral definitions */ +#define AudioO ARM_VSI1 /* Audio Output access struct */ +#define AudioO_IRQn ARM_VSI1_IRQn /* Audio Output Interrupt number */ +#define AudioO_Handler ARM_VSI1_Handler /* Audio Output Interrupt handler */ +#define AudioI ARM_VSI0 /* Audio Input access struct */ +#define AudioI_IRQn ARM_VSI0_IRQn /* Audio Input Interrupt number */ +#define AudioI_Handler ARM_VSI0_Handler /* Audio Input Interrupt handler */ + +/* Audio Peripheral registers */ +#define CONTROL Regs[0] /* Control receiver */ +#define CHANNELS Regs[1] /* Number of channels */ +#define SAMPLE_BITS Regs[2] /* Sample number of bits (8..32) */ +#define SAMPLE_RATE Regs[3] /* Sample rate (samples per second) */ +#define STOP_SIMULATION Regs[4] /* Stop audio simulation */ + +/* Audio Control register definitions */ +#define CONTROL_ENABLE_Pos 0U /* CONTROL: ENABLE Position */ +#define CONTROL_ENABLE_Msk (1UL << CONTROL_ENABLE_Pos) /* CONTROL: ENABLE Mask */ + +/* Driver State */ +static uint8_t Initialized = 0U; + +/* Event Callback */ +static AudioDrv_Event_t CB_Event = NULL; + +/* Audio Output Interrupt Handler */ +void AudioO_Handler (void) { + + AudioO->IRQ.Clear = 0x00000001U; + __DSB(); + __ISB(); + if (CB_Event != NULL) { + CB_Event(AUDIO_DRV_EVENT_TX_DATA); + } +} + +/* Audio Input Interrupt Handler */ +void AudioI_Handler (void) { + + AudioI->IRQ.Clear = 0x00000001U; + __DSB(); + __ISB(); + if (CB_Event != NULL) { + CB_Event(AUDIO_DRV_EVENT_RX_DATA); + } +} + + + +/* Initialize Audio Interface */ +int32_t AudioDrv_Initialize (AudioDrv_Event_t cb_event) { + + CB_Event = cb_event; + + /* Initialize Audio Output peripheral */ + AudioO->Timer.Control = 0U; + AudioO->DMA.Control = 0U; + AudioO->IRQ.Clear = 0x00000001U; + AudioO->IRQ.Enable = 0x00000001U; + AudioO->CONTROL = 0U; + + /* Initialize Audio Input peripheral */ + AudioI->Timer.Control = 0U; + AudioI->DMA.Control = 0U; + AudioI->IRQ.Clear = 0x00000001U; + AudioI->IRQ.Enable = 0x00000001U; + AudioI->CONTROL = 0U; + + /* Enable peripheral interrupts */ +//NVIC_EnableIRQ(AudioO_IRQn); + NVIC->ISER[(((uint32_t)AudioO_IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)AudioO_IRQn) & 0x1FUL)); +//NVIC_EnableIRQ(AudioI_IRQn); + NVIC->ISER[(((uint32_t)AudioI_IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)AudioI_IRQn) & 0x1FUL)); + __DSB(); + __ISB(); + + Initialized = 1U; + + return AUDIO_DRV_OK; +} + +/* De-initialize Audio Interface */ +int32_t AudioDrv_Uninitialize (void) { + + /* Disable peripheral interrupts */ +//NVIC_DisableIRQ(AudioO_IRQn); + NVIC->ICER[(((uint32_t)AudioO_IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)AudioO_IRQn) & 0x1FUL)); +//NVIC_DisableIRQ(AudioI_IRQn); + NVIC->ICER[(((uint32_t)AudioI_IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)AudioI_IRQn) & 0x1FUL)); + __DSB(); + __ISB(); + + /* De-initialize Audio Output peripheral */ + AudioO->Timer.Control = 0U; + AudioO->DMA.Control = 0U; + AudioO->IRQ.Clear = 0x00000001U; + AudioO->IRQ.Enable = 0x00000000U; + AudioO->CONTROL = 0U; + + /* De-initialize Audio Input peripheral */ + AudioI->Timer.Control = 0U; + AudioI->DMA.Control = 0U; + AudioI->IRQ.Clear = 0x00000001U; + AudioI->IRQ.Enable = 0x00000000U; + AudioI->CONTROL = 0U; + + Initialized = 0U; + + return AUDIO_DRV_OK; +} + +/* Configure Audio Interface */ +int32_t AudioDrv_Configure (uint32_t interface, uint32_t channels, uint32_t sample_bits, uint32_t sample_rate) { + uint32_t format; + + if (Initialized == 0U) { + return AUDIO_DRV_ERROR; + } + + if ((channels < 1U) || + (channels > 32U) || + (sample_bits < 8U) || + (sample_bits > 32U) || + (sample_rate == 0U)) { + return AUDIO_DRV_ERROR_PARAMETER; + } + + switch (interface) { + case AUDIO_DRV_INTERFACE_TX: + if ((AudioO->CONTROL & CONTROL_ENABLE_Msk) != 0U) { + return AUDIO_DRV_ERROR; + } + AudioO->CHANNELS = channels; + AudioO->SAMPLE_BITS = sample_bits; + AudioO->SAMPLE_RATE = sample_rate; + break; + case AUDIO_DRV_INTERFACE_RX: + if ((AudioI->CONTROL & CONTROL_ENABLE_Msk) != 0U) { + return AUDIO_DRV_ERROR; + } + AudioI->CHANNELS = channels; + AudioI->SAMPLE_BITS = sample_bits; + AudioI->SAMPLE_RATE = sample_rate; + break; + default: + return AUDIO_DRV_ERROR_PARAMETER; + } + + return AUDIO_DRV_OK; +} + +/* Set Audio Interface buffer */ +int32_t AudioDrv_SetBuf (uint32_t interface, void *buf, uint32_t block_num, uint32_t block_size) { + + if (Initialized == 0U) { + return AUDIO_DRV_ERROR; + } + + switch (interface) { + case AUDIO_DRV_INTERFACE_TX: + if ((AudioO->DMA.Control & ARM_VSI_DMA_Enable_Msk) != 0U) { + return AUDIO_DRV_ERROR; + } + AudioO->DMA.Address = (uint32_t)buf; + AudioO->DMA.BlockNum = block_num; + AudioO->DMA.BlockSize = block_size; + break; + case AUDIO_DRV_INTERFACE_RX: + if ((AudioI->DMA.Control & ARM_VSI_DMA_Enable_Msk) != 0U) { + return AUDIO_DRV_ERROR; + } + AudioI->DMA.Address = (uint32_t)buf; + AudioI->DMA.BlockNum = block_num; + AudioI->DMA.BlockSize = block_size; + break; + default: + return AUDIO_DRV_ERROR_PARAMETER; + } + + return AUDIO_DRV_OK; +} + +/* Control Audio Interface */ +int32_t AudioDrv_Control (uint32_t control) { + uint32_t sample_size; + uint32_t sample_rate; + uint32_t block_size; + + if (Initialized == 0U) { + return AUDIO_DRV_ERROR; + } + + if ((control & AUDIO_DRV_CONTROL_TX_DISABLE) != 0U) { + AudioO->Timer.Control = 0U; + AudioO->DMA.Control = 0U; + AudioO->CONTROL = 0U; + } else if ((control & AUDIO_DRV_CONTROL_TX_ENABLE) != 0U) { + AudioO->CONTROL = CONTROL_ENABLE_Msk; + AudioO->DMA.Control = ARM_VSI_DMA_Direction_M2P | + ARM_VSI_DMA_Enable_Msk; + sample_size = AudioO->CHANNELS * ((AudioO->SAMPLE_BITS + 7U) / 8U); + sample_rate = AudioO->SAMPLE_RATE; + if ((sample_size == 0U) || (sample_rate == 0U)) { + AudioO->Timer.Interval = 0xFFFFFFFFU; + } else { + block_size = AudioO->DMA.BlockSize; + AudioO->Timer.Interval = (1000000U * (block_size / sample_size)) / sample_rate; + } + AudioO->Timer.Control = ARM_VSI_Timer_Trig_DMA_Msk | + ARM_VSI_Timer_Trig_IRQ_Msk | + ARM_VSI_Timer_Periodic_Msk | + ARM_VSI_Timer_Run_Msk; + } + + if ((control & AUDIO_DRV_CONTROL_RX_DISABLE) != 0U) { + AudioI->Timer.Control = 0U; + AudioI->DMA.Control = 0U; + AudioI->CONTROL = 0U; + } else if ((control & AUDIO_DRV_CONTROL_RX_ENABLE) != 0U) { + AudioI->CONTROL = CONTROL_ENABLE_Msk; + AudioI->DMA.Control = ARM_VSI_DMA_Direction_P2M | + ARM_VSI_DMA_Enable_Msk; + sample_size = AudioI->CHANNELS * ((AudioI->SAMPLE_BITS + 7U) / 8U); + sample_rate = AudioI->SAMPLE_RATE; + if ((sample_size == 0U) || (sample_rate == 0U)) { + AudioI->Timer.Interval = 0xFFFFFFFFU; + } else { + block_size = AudioI->DMA.BlockSize; + AudioI->Timer.Interval = (1000000U * (block_size / sample_size)) / sample_rate; + } + AudioI->Timer.Control = ARM_VSI_Timer_Trig_DMA_Msk | + ARM_VSI_Timer_Trig_IRQ_Msk | + ARM_VSI_Timer_Periodic_Msk | + ARM_VSI_Timer_Run_Msk; + } + + return AUDIO_DRV_OK; +} + +/* Get transmitted block count */ +uint32_t AudioDrv_GetTxCount (void) { + return (AudioO->Timer.Count); +} + +/* Get received block count */ +uint32_t AudioDrv_GetRxCount (void) { + return (AudioI->Timer.Count); +} + +/* Get Audio Interface status */ +AudioDrv_Status_t AudioDrv_GetStatus (void) { + AudioDrv_Status_t status; + uint32_t sr; + + if ((AudioO->CONTROL & CONTROL_ENABLE_Msk) != 0U) { + status.tx_active = 1U; + } else { + status.tx_active = 0U; + } + + if ((AudioI->CONTROL & CONTROL_ENABLE_Msk) != 0U) { + status.rx_active = 1U; + } else { + status.rx_active = 0U; + } + + return (status); +} + + +void AudioDrv_Stop (void) +{ + int32_t ret; + ret = AudioDrv_Control(AUDIO_DRV_CONTROL_TX_DISABLE); + ret = AudioDrv_Control(AUDIO_DRV_CONTROL_RX_DISABLE); + + AudioO->STOP_SIMULATION=1; + AudioI->STOP_SIMULATION=1; + +} \ No newline at end of file diff --git a/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/audio/audio_drv.h b/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/audio/audio_drv.h new file mode 100755 index 00000000..ed6a3b83 --- /dev/null +++ b/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/audio/audio_drv.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2021 Arm Limited. All rights reserved. + */ + +#ifndef __AUDIO_DRV_H +#define __AUDIO_DRV_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include + +/* Audio Interface */ +#define AUDIO_DRV_INTERFACE_TX (1U) ///< Transmitter +#define AUDIO_DRV_INTERFACE_RX (2U) ///< Receiver + +/* Audio Control */ +#define AUDIO_DRV_CONTROL_TX_ENABLE (1UL << 0) ///< Enable Transmitter +#define AUDIO_DRV_CONTROL_RX_ENABLE (1UL << 1) ///< Enable Receiver +#define AUDIO_DRV_CONTROL_TX_DISABLE (1UL << 2) ///< Disable Transmitter +#define AUDIO_DRV_CONTROL_RX_DISABLE (1UL << 3) ///< Disable Receiver + +/* Audio Event */ +#define AUDIO_DRV_EVENT_TX_DATA (1UL << 0) ///< Data block transmitted +#define AUDIO_DRV_EVENT_RX_DATA (1UL << 1) ///< Data block received + +/* Return code */ +#define AUDIO_DRV_OK (0) ///< Operation succeeded +#define AUDIO_DRV_ERROR (-1) ///< Unspecified error +#define AUDIO_DRV_ERROR_BUSY (-2) ///< Driver is busy +#define AUDIO_DRV_ERROR_TIMEOUT (-3) ///< Timeout occurred +#define AUDIO_DRV_ERROR_UNSUPPORTED (-4) ///< Operation not supported +#define AUDIO_DRV_ERROR_PARAMETER (-5) ///< Parameter error + +/** +\brief Audio Status +*/ +typedef struct { + uint32_t tx_active : 1; ///< Transmitter active + uint32_t rx_active : 1; ///< Receiver active + uint32_t reserved : 30; +} AudioDrv_Status_t; + +/** + \fn AudioDrv_Event_t + \brief Audio Events callback function type: void (*AudioDrv_Event_t) (uint32_t event + \param[in] event events notification mask + \return none +*/ +typedef void (*AudioDrv_Event_t) (uint32_t event); + +uint8_t* AudioRXBuffer(); +uint8_t* AudioTXBuffer(); +extern int32_t AudioDrv_Setup(void); + +/** + \fn int32_t AudioDrv_Initialize (AudioDrv_Event_t cb_event) + \brief Initialize Audio Interface. + \param[in] cb_event pointer to \ref AudioDrv_Event_t + \return return code +*/ +int32_t AudioDrv_Initialize (AudioDrv_Event_t cb_event); + +/** + \fn void AudioDrv_Stop (void); + \brief Stop audio simulation. + \return return code +*/ +void AudioDrv_Stop (void); + +/** + \fn int32_t AudioDrv_Uninitialize (void) + \brief De-initialize Audio Interface. + \return return code +*/ +int32_t AudioDrv_Uninitialize (void); + +/** + \fn int32_t AudioDrv_Configure (uint32_t interface, uint32_t channels, uint32_t sample_bits, uint32_t sample_rate) + \brief Configure Audio Interface. + \param[in] interface audio interface + \param[in] channels number of channels + \param[in] sample_bits sample number of bits (8..32) + \param[in] sample_rate sample rate (samples per second) + \return return code +*/ +int32_t AudioDrv_Configure (uint32_t interface, uint32_t channels, uint32_t sample_bits, uint32_t sample_rate); + +/** + \fn int32_t AudioDrv_SetBuf (uint32_t interface, void *buf, uint32_t block_num, uint32_t block_size) + \brief Set Audio Interface buffer. + \param[in] interface audio interface + \param[in] buf pointer to buffer for audio data + \param[in] block_num number of blocks in buffer (must be 2^n) + \param[in] block_size block size in number of samples + \return return code +*/ +int32_t AudioDrv_SetBuf (uint32_t interface, void *buf, uint32_t block_num, uint32_t block_size); + +/** + \fn int32_t AudioDrv_Control (uint32_t control) + \brief Control Audio Interface. + \param[in] control operation + \return return code +*/ +int32_t AudioDrv_Control (uint32_t control); + +/** + \fn uint32_t AudioDrv_GetTxCount (void) + \brief Get transmitted block count. + \return number of transmitted blocks +*/ +uint32_t AudioDrv_GetTxCount (void); + +/** + \fn uint32_t AudioDrv_GetRxCount (void) + \brief Get received block count. + \return number of received blocks +*/ +uint32_t AudioDrv_GetRxCount (void); + +/** + \fn AudioDrv_Status_t AudioDrv_GetStatus (void) + \brief Get Audio Interface status. + \return \ref AudioDrv_Status_t +*/ +AudioDrv_Status_t AudioDrv_GetStatus (void); + +#ifdef __cplusplus +} +#endif + +#endif /* __AUDIO_DRV_H */ diff --git a/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/video/VideoInterrupt.cpp b/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/video/VideoInterrupt.cpp new file mode 100755 index 00000000..d2017050 --- /dev/null +++ b/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/video/VideoInterrupt.cpp @@ -0,0 +1,101 @@ +#include +#include "video_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 "VideoConfig.h" +#include "RingConfig.h" + +#include "RingInit.h" + +extern osThreadId_t gStreamingThreadID; + +// Number of bytes read by DMA +#define VIDEO_BLOCK_SIZE RING_BUFSIZE_RX + +// Number of DMA blocks +#define VIDEO_DMA_NB_BLOCKS RING_NBBUFS + + +extern int32_t VideoDrv_Setup(void); + + +extern ring_config_t ringConfigRX; + +#ifdef __FVP_PY +__attribute__((section(".ARM.__at_0x90000000"))) +#endif +__ALIGNED(16) static uint8_t video_bufferRX[VIDEO_DMA_NB_BLOCKS*VIDEO_BLOCK_SIZE]; +static uint8_t *reservedBufRX=NULL; + + +uint8_t* VideoRXBuffer() +{ + return(video_bufferRX); +} + + +static void VideoEvent (uint32_t event) { + + if (event & VIDEO_DRV_EVENT_RX_DATA) + { + + + ringInterruptReleaseBuffer(&ringConfigRX,(void *)gStreamingThreadID); + int reservedRX=ringInterruptReserveBuffer(&ringConfigRX); + reservedBufRX=ringGetBufferAddress(&ringConfigRX,reservedRX); + + } + +} + +int32_t VideoDrv_Setup(void) { + int32_t ret; + + ret = VideoDrv_Initialize(VideoEvent); + if (ret != 0) { + return ret; + } + + + ret = VideoDrv_Configure(VIDEO_DRV_INTERFACE_RX, + 8U * VIDEO_DRV_PIXEL_SIZE, /* 16 sample bits */ + static_cast(VIDEO_DRV_FRAME_RATE*VIDEO_DRV_WIDTH*VIDEO_DRV_HEIGHT)); + if (ret != 0) { + return ret; + } + + /* Work because user process not started yet + */ + + int reservedRX=ringInterruptReserveBuffer(&ringConfigRX); + reservedBufRX=ringGetBufferAddress(&ringConfigRX,reservedRX); + + + ret = VideoDrv_SetBuf(VIDEO_DRV_INTERFACE_RX, + video_bufferRX, VIDEO_DMA_NB_BLOCKS,VIDEO_BLOCK_SIZE); + if (ret != 0) { + return ret; + } + + ret = VideoDrv_Control(VIDEO_DRV_CONTROL_RX_ENABLE); + if (ret != 0) { + return ret; + } + + + return 0; +} + diff --git a/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/video/video_drv.c b/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/video/video_drv.c new file mode 100755 index 00000000..1992e10e --- /dev/null +++ b/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/video/video_drv.c @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2021 Arm Limited. All rights reserved. + */ + +#include +#include "video_drv.h" +#include "arm_vsi.h" +#ifdef _RTE_ +#include "RTE_Components.h" +#endif +#include CMSIS_device_header + +/* Video Peripheral definitions */ +#define VideoO ARM_VSI1 /* Video Output access struct */ +#define VideoO_IRQn ARM_VSI1_IRQn /* Video Output Interrupt number */ +#define VideoO_Handler ARM_VSI1_Handler /* Video Output Interrupt handler */ +#define VideoI ARM_VSI0 /* Video Input access struct */ +#define VideoI_IRQn ARM_VSI0_IRQn /* Video Input Interrupt number */ +#define VideoI_Handler ARM_VSI0_Handler /* Video Input Interrupt handler */ + +/* Video Peripheral registers */ +#define CONTROL Regs[0] /* Control receiver */ +#define SAMPLE_BITS Regs[1] /* Sample number of bits (8..32) */ +#define SAMPLE_RATE Regs[2] /* Sample rate (frame per second) */ +#define STOP_SIMULATION Regs[4] /* Stop audio simulation */ + +/* Video Control register definitions */ +#define CONTROL_ENABLE_Pos 0U /* CONTROL: ENABLE Position */ +#define CONTROL_ENABLE_Msk (1UL << CONTROL_ENABLE_Pos) /* CONTROL: ENABLE Mask */ + +/* Driver State */ +static uint8_t Initialized = 0U; + +/* Event Callback */ +static VideoDrv_Event_t CB_Event = NULL; + + +/* Video Input Interrupt Handler */ +void VideoI_Handler (void) { + + VideoI->IRQ.Clear = 0x00000001U; + __DSB(); + __ISB(); + if (CB_Event != NULL) { + CB_Event(VIDEO_DRV_EVENT_RX_DATA); + } +} + + +void VideoO_Handler (void) { + + VideoO->IRQ.Clear = 0x00000001U; + __DSB(); + __ISB(); +} + + +/* Initialize Video Interface */ +int32_t VideoDrv_Initialize (VideoDrv_Event_t cb_event) { + + CB_Event = cb_event; + + /* Initialize Video Output peripheral */ + VideoO->Timer.Control = 0U; + VideoO->DMA.Control = 0U; + VideoO->IRQ.Clear = 0x00000001U; + VideoO->IRQ.Enable = 0x00000001U; + VideoO->CONTROL = 0U; + + /* Initialize Video Input peripheral */ + VideoI->Timer.Control = 0U; + VideoI->DMA.Control = 0U; + VideoI->IRQ.Clear = 0x00000001U; + VideoI->IRQ.Enable = 0x00000001U; + VideoI->CONTROL = 0U; + + /* Enable peripheral interrupts */ + NVIC->ISER[(((uint32_t)VideoI_IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)VideoI_IRQn) & 0x1FUL)); + __DSB(); + __ISB(); + + Initialized = 1U; + + return VIDEO_DRV_OK; +} + +/* De-initialize Video Interface */ +int32_t VideoDrv_Uninitialize (void) { + + /* Disable peripheral interrupts */ + NVIC->ICER[(((uint32_t)VideoI_IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)VideoI_IRQn) & 0x1FUL)); + __DSB(); + __ISB(); + + /* De-initialize Video Output peripheral */ + VideoO->Timer.Control = 0U; + VideoO->DMA.Control = 0U; + VideoO->IRQ.Clear = 0x00000001U; + VideoO->IRQ.Enable = 0x00000000U; + VideoO->CONTROL = 0U; + + /* De-initialize Video Input peripheral */ + VideoI->Timer.Control = 0U; + VideoI->DMA.Control = 0U; + VideoI->IRQ.Clear = 0x00000001U; + VideoI->IRQ.Enable = 0x00000000U; + VideoI->CONTROL = 0U; + + Initialized = 0U; + + return VIDEO_DRV_OK; +} + +/* Configure Video Interface */ +int32_t VideoDrv_Configure (uint32_t interface, uint32_t pixel_size, uint32_t samplerate) { + uint32_t format; + + if (Initialized == 0U) { + return VIDEO_DRV_ERROR; + } + + if ((pixel_size < 8*1U) || + (pixel_size > 8*2U)) { + return VIDEO_DRV_ERROR_PARAMETER; + } + + switch (interface) { + case VIDEO_DRV_INTERFACE_RX: + if ((VideoI->CONTROL & CONTROL_ENABLE_Msk) != 0U) { + return VIDEO_DRV_ERROR; + } + VideoI->SAMPLE_BITS = pixel_size; + VideoI->SAMPLE_RATE = samplerate; + break; + default: + return VIDEO_DRV_ERROR_PARAMETER; + } + + return VIDEO_DRV_OK; +} + +/* Set Video Interface buffer */ +int32_t VideoDrv_SetBuf (uint32_t interface, void *buf, uint32_t block_num, uint32_t block_size) { + + if (Initialized == 0U) { + return VIDEO_DRV_ERROR; + } + + switch (interface) { + case VIDEO_DRV_INTERFACE_RX: + if ((VideoI->DMA.Control & ARM_VSI_DMA_Enable_Msk) != 0U) { + return VIDEO_DRV_ERROR; + } + VideoI->DMA.Address = (uint32_t)buf; + VideoI->DMA.BlockNum = block_num; + VideoI->DMA.BlockSize = block_size; + break; + default: + return VIDEO_DRV_ERROR_PARAMETER; + } + + return VIDEO_DRV_OK; +} + +/* Control Video Interface */ +int32_t VideoDrv_Control (uint32_t control) { + uint32_t sample_size; + uint32_t sample_rate; + uint32_t block_size; + + if (Initialized == 0U) { + return VIDEO_DRV_ERROR; + } + + + + if ((control & VIDEO_DRV_CONTROL_RX_DISABLE) != 0U) { + VideoI->Timer.Control = 0U; + VideoI->DMA.Control = 0U; + VideoI->CONTROL = 0U; + } else if ((control & VIDEO_DRV_CONTROL_RX_ENABLE) != 0U) { + VideoI->CONTROL = CONTROL_ENABLE_Msk; + VideoI->DMA.Control = ARM_VSI_DMA_Direction_P2M | + ARM_VSI_DMA_Enable_Msk; + sample_size = ((VideoI->SAMPLE_BITS + 7U) / 8U); + sample_rate = VideoI->SAMPLE_RATE; + if ((sample_size == 0U) || (sample_rate == 0U)) { + VideoI->Timer.Interval = 0xFFFFFFFFU; + } else { + block_size = VideoI->DMA.BlockSize; + VideoI->Timer.Interval = (1000000U * (block_size / sample_size)) / sample_rate; + } + VideoI->Timer.Control = ARM_VSI_Timer_Trig_DMA_Msk | + ARM_VSI_Timer_Trig_IRQ_Msk | + ARM_VSI_Timer_Periodic_Msk | + ARM_VSI_Timer_Run_Msk; + } + + return VIDEO_DRV_OK; +} + +/* Get received block count */ +uint32_t VideoDrv_GetRxCount (void) { + return (VideoI->Timer.Count); +} + +/* Get Video Interface status */ +VideoDrv_Status_t VideoDrv_GetStatus (void) { + VideoDrv_Status_t status; + uint32_t sr; + + + if ((VideoI->CONTROL & CONTROL_ENABLE_Msk) != 0U) { + status.rx_active = 1U; + } else { + status.rx_active = 0U; + } + + return (status); +} + + +void VideoDrv_Stop (void) +{ + int32_t ret; + ret = VideoDrv_Control(VIDEO_DRV_CONTROL_RX_DISABLE); + + VideoI->STOP_SIMULATION=1; + +} + + diff --git a/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/video/video_drv.h b/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/video/video_drv.h new file mode 100755 index 00000000..01eef286 --- /dev/null +++ b/SDFTools/sdf/nodes/cpp/StreamingNodes/VHT/video/video_drv.h @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2021 Arm Limited. All rights reserved. + */ + +#ifndef __VIDEO_DRV_H +#define __VIDEO_DRV_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include + +/* Video Interface */ +#define VIDEO_DRV_INTERFACE_RX (2U) ///< Receiver + +/* Video Control */ +#define VIDEO_DRV_CONTROL_RX_ENABLE (1UL << 1) ///< Enable Receiver +#define VIDEO_DRV_CONTROL_RX_DISABLE (1UL << 3) ///< Disable Receiver + +/* Video Event */ +#define VIDEO_DRV_EVENT_RX_DATA (1UL << 1) ///< Data block received + +/* Return code */ +#define VIDEO_DRV_OK (0) ///< Operation succeeded +#define VIDEO_DRV_ERROR (-1) ///< Unspecified error +#define VIDEO_DRV_ERROR_BUSY (-2) ///< Driver is busy +#define VIDEO_DRV_ERROR_TIMEOUT (-3) ///< Timeout occurred +#define VIDEO_DRV_ERROR_UNSUPPORTED (-4) ///< Operation not supported +#define VIDEO_DRV_ERROR_PARAMETER (-5) ///< Parameter error + +/** +\brief Video Status +*/ +typedef struct { + uint32_t tx_active : 1; ///< Transmitter active + uint32_t rx_active : 1; ///< Receiver active + uint32_t reserved : 30; +} VideoDrv_Status_t; + +uint8_t* VideoRXBuffer(); +int32_t VideoDrv_Setup(void); + +/** + \fn VideoDrv_Event_t + \brief Video Events callback function type: void (*VideoDrv_Event_t) (uint32_t event + \param[in] event events notification mask + \return none +*/ +typedef void (*VideoDrv_Event_t) (uint32_t event); + +/** + \fn int32_t VideoDrv_Initialize (VideoDrv_Event_t cb_event) + \brief Initialize Video Interface. + \param[in] cb_event pointer to \ref VideoDrv_Event_t + \return return code +*/ +int32_t VideoDrv_Initialize (VideoDrv_Event_t cb_event); + +/** + \fn void VideoDrv_Stop (void); + \brief Stop audio simulation. + \return return code +*/ +void VideoDrv_Stop (void); + + +/** + \fn int32_t VideoDrv_Uninitialize (void) + \brief De-initialize Video Interface. + \return return code +*/ +int32_t VideoDrv_Uninitialize (void); + +/** + \fn int32_t VideoDrv_Configure (uint32_t interface, uint32_t channels, uint32_t sample_bits, uint32_t sample_rate) + \brief Configure Video Interface. + \param[in] interface audio interface + \param[in] pixel_size size in bytes + \param[in] samplerate samples per second + \return return code +*/ +int32_t VideoDrv_Configure (uint32_t interface, uint32_t pixel_size,uint32_t samplerate); + +/** + \fn int32_t VideoDrv_SetBuf (uint32_t interface, void *buf, uint32_t block_num, uint32_t block_size) + \brief Set Video Interface buffer. + \param[in] interface audio interface + \param[in] buf pointer to buffer for audio data + \param[in] block_num number of blocks in buffer (must be 2^n) + \param[in] block_size block size in number of samples + \return return code +*/ +int32_t VideoDrv_SetBuf (uint32_t interface, void *buf, uint32_t block_num, uint32_t block_size); + +/** + \fn int32_t VideoDrv_Control (uint32_t control) + \brief Control Video Interface. + \param[in] control operation + \return return code +*/ +int32_t VideoDrv_Control (uint32_t control); + + +/** + \fn uint32_t VideoDrv_GetRxCount (void) + \brief Get received block count. + \return number of received blocks +*/ +uint32_t VideoDrv_GetRxCount (void); + +/** + \fn VideoDrv_Status_t VideoDrv_GetStatus (void) + \brief Get Video Interface status. + \return \ref VideoDrv_Status_t +*/ +VideoDrv_Status_t VideoDrv_GetStatus (void); + +#ifdef __cplusplus +} +#endif + +#endif /* __VIDEO_DRV_H */ diff --git a/SDFTools/sdf/nodes/cpp/AudioSink.h b/SDFTools/sdf/nodes/cpp/StreamingSink.h similarity index 85% rename from SDFTools/sdf/nodes/cpp/AudioSink.h rename to SDFTools/sdf/nodes/cpp/StreamingSink.h index 4ed48cbc..7dca9701 100755 --- a/SDFTools/sdf/nodes/cpp/AudioSink.h +++ b/SDFTools/sdf/nodes/cpp/StreamingSink.h @@ -1,7 +1,7 @@ /* ---------------------------------------------------------------------- * Project: CMSIS DSP Library - * Title: AudioSink.h - * Description: Audio Sink working with the RingBuffer + * Title: StreamingSink.h + * Description: Streaming Sink working with the RingBuffer * * $Date: 30 July 2021 * $Revision: V1.10.0 @@ -25,17 +25,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef _AUDIO_SINK_H_ -#define _AUDIO_SINK_H_ +#ifndef _STREAMING_SINK_H_ +#define _STREAMING_SINK_H_ #include "RingBuffer.h" template -class AudioSink: public GenericSink +class StreamingSink: public GenericSink { public: - AudioSink(FIFOBase &src,ring_config_t *config): + StreamingSink(FIFOBase &src,ring_config_t *config): GenericSink(src),mConfig(config){}; int run() @@ -66,4 +66,4 @@ protected: ring_config_t *mConfig; }; -#endif \ No newline at end of file +#endif /* _STREAMING_SINK_H_ */ \ No newline at end of file diff --git a/SDFTools/sdf/nodes/cpp/AudioSource.h b/SDFTools/sdf/nodes/cpp/StreamingSource.h similarity index 86% rename from SDFTools/sdf/nodes/cpp/AudioSource.h rename to SDFTools/sdf/nodes/cpp/StreamingSource.h index 08b92284..d52b4b60 100755 --- a/SDFTools/sdf/nodes/cpp/AudioSource.h +++ b/SDFTools/sdf/nodes/cpp/StreamingSource.h @@ -1,7 +1,7 @@ /* ---------------------------------------------------------------------- * Project: CMSIS DSP Library - * Title: AudioSource.h - * Description: Audio source working with the Ring buffer + * Title: StreamingSource.h + * Description: Streaming source working with the Ring buffer * * $Date: 30 July 2021 * $Revision: V1.10.0 @@ -25,17 +25,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef _AUDIO_SOURCE_H_ -#define _AUDIO_SOURCE_H_ +#ifndef _STREAMING_SOURCE_H_ +#define _STREAMING_SOURCE_H_ #include "RingBuffer.h" template -class AudioSource: public GenericSource +class StreamingSource: public GenericSource { public: - AudioSource(FIFOBase &dst,ring_config_t *config): + StreamingSource(FIFOBase &dst,ring_config_t *config): GenericSource(dst),mConfig(config){}; int run(){ @@ -73,4 +73,4 @@ protected: }; -#endif \ No newline at end of file +#endif /* _STREAMING_SOURCE_H_ */ \ No newline at end of file diff --git a/Testing/Source/Benchmarks/BayesF16.cpp b/Testing/Source/Benchmarks/BayesF16.cpp index f3a24530..e9b5f317 100755 --- a/Testing/Source/Benchmarks/BayesF16.cpp +++ b/Testing/Source/Benchmarks/BayesF16.cpp @@ -7,9 +7,8 @@ void BayesF16::test_gaussian_naive_bayes_predict_f16() { - int16_t p; - p = arm_gaussian_naive_bayes_predict_f16(&bayes, + (void)arm_gaussian_naive_bayes_predict_f16(&bayes, inp, bufp,tempp); diff --git a/Testing/Source/Benchmarks/BayesF32.cpp b/Testing/Source/Benchmarks/BayesF32.cpp index 2f0753c4..259884aa 100755 --- a/Testing/Source/Benchmarks/BayesF32.cpp +++ b/Testing/Source/Benchmarks/BayesF32.cpp @@ -7,9 +7,8 @@ void BayesF32::test_gaussian_naive_bayes_predict_f32() { - int16_t p; - p = arm_gaussian_naive_bayes_predict_f32(&bayes, + (void)arm_gaussian_naive_bayes_predict_f32(&bayes, inp, bufp,tempp); diff --git a/Testing/Source/Benchmarks/DistanceF16.cpp b/Testing/Source/Benchmarks/DistanceF16.cpp index 6c6a2ed0..4511b435 100755 --- a/Testing/Source/Benchmarks/DistanceF16.cpp +++ b/Testing/Source/Benchmarks/DistanceF16.cpp @@ -7,79 +7,70 @@ void DistanceF16::test_braycurtis_distance_f16() { - float16_t outp; - outp = arm_braycurtis_distance_f16(inpA, inpB, this->vecDim); + (void)arm_braycurtis_distance_f16(inpA, inpB, this->vecDim); } void DistanceF16::test_canberra_distance_f16() { - float16_t outp; - outp = arm_canberra_distance_f16(inpA, inpB, this->vecDim); + (void)arm_canberra_distance_f16(inpA, inpB, this->vecDim); } void DistanceF16::test_chebyshev_distance_f16() { - float16_t outp; - outp = arm_chebyshev_distance_f16(inpA, inpB, this->vecDim); + (void)arm_chebyshev_distance_f16(inpA, inpB, this->vecDim); } void DistanceF16::test_cityblock_distance_f16() { - float16_t outp; - outp = arm_cityblock_distance_f16(inpA, inpB, this->vecDim); + (void)arm_cityblock_distance_f16(inpA, inpB, this->vecDim); } void DistanceF16::test_correlation_distance_f16() { - float16_t outp; memcpy(tmpAp, inpA, sizeof(float16_t) * this->vecDim); memcpy(tmpBp, inpB, sizeof(float16_t) * this->vecDim); - outp = arm_correlation_distance_f16(tmpAp, tmpBp, this->vecDim); + (void)arm_correlation_distance_f16(tmpAp, tmpBp, this->vecDim); } void DistanceF16::test_cosine_distance_f16() { - float16_t outp; - outp = arm_cosine_distance_f16(inpA, inpB, this->vecDim); + (void)arm_cosine_distance_f16(inpA, inpB, this->vecDim); } void DistanceF16::test_euclidean_distance_f16() { - float16_t outp; - outp = arm_euclidean_distance_f16(inpA, inpB, this->vecDim); + (void)arm_euclidean_distance_f16(inpA, inpB, this->vecDim); } void DistanceF16::test_jensenshannon_distance_f16() { - float16_t outp; - outp = arm_jensenshannon_distance_f16(inpA, inpB, this->vecDim); + (void)arm_jensenshannon_distance_f16(inpA, inpB, this->vecDim); } void DistanceF16::test_minkowski_distance_f16() { - float16_t outp; - outp = arm_minkowski_distance_f16(inpA, inpB, 2,this->vecDim); + (void)arm_minkowski_distance_f16(inpA, inpB, 2,this->vecDim); } diff --git a/Testing/Source/Benchmarks/DistanceF32.cpp b/Testing/Source/Benchmarks/DistanceF32.cpp index e76b1899..8a8e0dec 100755 --- a/Testing/Source/Benchmarks/DistanceF32.cpp +++ b/Testing/Source/Benchmarks/DistanceF32.cpp @@ -7,79 +7,70 @@ void DistanceF32::test_braycurtis_distance_f32() { - float32_t outp; - outp = arm_braycurtis_distance_f32(inpA, inpB, this->vecDim); + (void)arm_braycurtis_distance_f32(inpA, inpB, this->vecDim); } void DistanceF32::test_canberra_distance_f32() { - float32_t outp; - outp = arm_canberra_distance_f32(inpA, inpB, this->vecDim); + (void)arm_canberra_distance_f32(inpA, inpB, this->vecDim); } void DistanceF32::test_chebyshev_distance_f32() { - float32_t outp; - outp = arm_chebyshev_distance_f32(inpA, inpB, this->vecDim); + (void)arm_chebyshev_distance_f32(inpA, inpB, this->vecDim); } void DistanceF32::test_cityblock_distance_f32() { - float32_t outp; - outp = arm_cityblock_distance_f32(inpA, inpB, this->vecDim); + (void)arm_cityblock_distance_f32(inpA, inpB, this->vecDim); } void DistanceF32::test_correlation_distance_f32() { - float32_t outp; memcpy(tmpAp, inpA, sizeof(float32_t) * this->vecDim); memcpy(tmpBp, inpB, sizeof(float32_t) * this->vecDim); - outp = arm_correlation_distance_f32(tmpAp, tmpBp, this->vecDim); + (void)arm_correlation_distance_f32(tmpAp, tmpBp, this->vecDim); } void DistanceF32::test_cosine_distance_f32() { - float32_t outp; - outp = arm_cosine_distance_f32(inpA, inpB, this->vecDim); + (void)arm_cosine_distance_f32(inpA, inpB, this->vecDim); } void DistanceF32::test_euclidean_distance_f32() { - float32_t outp; - outp = arm_euclidean_distance_f32(inpA, inpB, this->vecDim); + (void)arm_euclidean_distance_f32(inpA, inpB, this->vecDim); } void DistanceF32::test_jensenshannon_distance_f32() { - float32_t outp; - outp = arm_jensenshannon_distance_f32(inpA, inpB, this->vecDim); + (void)arm_jensenshannon_distance_f32(inpA, inpB, this->vecDim); } void DistanceF32::test_minkowski_distance_f32() { - float32_t outp; - outp = arm_minkowski_distance_f32(inpA, inpB, 2,this->vecDim); + (void)arm_minkowski_distance_f32(inpA, inpB, 2,this->vecDim); } diff --git a/Testing/Source/Benchmarks/DistanceU32.cpp b/Testing/Source/Benchmarks/DistanceU32.cpp index 973369fa..422e2812 100755 --- a/Testing/Source/Benchmarks/DistanceU32.cpp +++ b/Testing/Source/Benchmarks/DistanceU32.cpp @@ -7,74 +7,64 @@ void DistanceU32::test_dice_distance_u32() { - uint32_t outp; - outp = arm_dice_distance(inpA, inpB,this->vecDim); + (void)arm_dice_distance(inpA, inpB,this->vecDim); } void DistanceU32::test_hamming_distance_u32() { - uint32_t outp; - outp = arm_hamming_distance(inpA, inpB,this->vecDim); + (void)arm_hamming_distance(inpA, inpB,this->vecDim); } void DistanceU32::test_jaccard_distance_u32() { - uint32_t outp; - outp = arm_jaccard_distance(inpA, inpB,this->vecDim); + (void)arm_jaccard_distance(inpA, inpB,this->vecDim); } void DistanceU32::test_kulsinski_distance_u32() { - uint32_t outp; - outp = arm_kulsinski_distance(inpA, inpB,this->vecDim); + (void)arm_kulsinski_distance(inpA, inpB,this->vecDim); } void DistanceU32::test_rogerstanimoto_distance_u32() - { - uint32_t outp; - - outp = arm_rogerstanimoto_distance(inpA, inpB,this->vecDim); + { + (void)arm_rogerstanimoto_distance(inpA, inpB,this->vecDim); } void DistanceU32::test_russellrao_distance_u32() { - uint32_t outp; - outp = arm_russellrao_distance(inpA, inpB,this->vecDim); + (void)arm_russellrao_distance(inpA, inpB,this->vecDim); } void DistanceU32::test_sokalmichener_distance_u32() { - uint32_t outp; - outp = arm_sokalmichener_distance(inpA, inpB,this->vecDim); + (void)arm_sokalmichener_distance(inpA, inpB,this->vecDim); } void DistanceU32::test_sokalsneath_distance_u32() { - uint32_t outp; - outp = arm_sokalsneath_distance(inpA, inpB,this->vecDim); + (void)arm_sokalsneath_distance(inpA, inpB,this->vecDim); } void DistanceU32::test_yule_distance_u32() { - uint32_t outp; - outp = arm_yule_distance(inpA, inpB,this->vecDim); + (void)arm_yule_distance(inpA, inpB,this->vecDim); } diff --git a/Testing/Source/Benchmarks/StatsF16.cpp b/Testing/Source/Benchmarks/StatsF16.cpp index 2a85b992..d6881b0c 100755 --- a/Testing/Source/Benchmarks/StatsF16.cpp +++ b/Testing/Source/Benchmarks/StatsF16.cpp @@ -146,17 +146,15 @@ void StatsF16::test_entropy_f16() { - float16_t out; - out = arm_entropy_f16(inap,this->nb); + (void)arm_entropy_f16(inap,this->nb); } void StatsF16::test_logsumexp_f16() { - float16_t out; - out = arm_logsumexp_f16(inap,this->nb); + (void)arm_logsumexp_f16(inap,this->nb); } @@ -164,17 +162,15 @@ void StatsF16::test_kullback_leibler_f16() { - float16_t out; - out = arm_kullback_leibler_f16(inap,inbp,this->nb); + (void)arm_kullback_leibler_f16(inap,inbp,this->nb); } void StatsF16::test_logsumexp_dot_prod_f16() { - float16_t out; - out = arm_logsumexp_dot_prod_f16(inap,inbp,this->nb,tmpp); + (void)arm_logsumexp_dot_prod_f16(inap,inbp,this->nb,tmpp); } diff --git a/Testing/Source/Benchmarks/StatsF32.cpp b/Testing/Source/Benchmarks/StatsF32.cpp index 3811ff4c..7b2e9f82 100755 --- a/Testing/Source/Benchmarks/StatsF32.cpp +++ b/Testing/Source/Benchmarks/StatsF32.cpp @@ -146,17 +146,15 @@ void StatsF32::test_entropy_f32() { - float32_t out; - out = arm_entropy_f32(inap,this->nb); + (void)arm_entropy_f32(inap,this->nb); } void StatsF32::test_logsumexp_f32() { - float32_t out; - out = arm_logsumexp_f32(inap,this->nb); + (void)arm_logsumexp_f32(inap,this->nb); } @@ -164,17 +162,15 @@ void StatsF32::test_kullback_leibler_f32() { - float32_t out; - out = arm_kullback_leibler_f32(inap,inbp,this->nb); + (void)arm_kullback_leibler_f32(inap,inbp,this->nb); } void StatsF32::test_logsumexp_dot_prod_f32() { - float32_t out; - out = arm_logsumexp_dot_prod_f32(inap,inbp,this->nb,tmpp); + (void)arm_logsumexp_dot_prod_f32(inap,inbp,this->nb,tmpp); } diff --git a/Testing/Source/Benchmarks/StatsF64.cpp b/Testing/Source/Benchmarks/StatsF64.cpp index b7edaba7..a5549e63 100755 --- a/Testing/Source/Benchmarks/StatsF64.cpp +++ b/Testing/Source/Benchmarks/StatsF64.cpp @@ -7,8 +7,7 @@ void StatsF64::test_entropy_f64() { - float64_t out; - out = arm_entropy_f64(inap,this->nb); + (void)arm_entropy_f64(inap,this->nb); } @@ -18,9 +17,8 @@ void StatsF64::test_kullback_leibler_f64() { - float64_t out; - out = arm_kullback_leibler_f64(inap,inbp,this->nb); + (void)arm_kullback_leibler_f64(inap,inbp,this->nb); }