TI-RTOS Drivers  tidrivers_cc13xx_cc26xx_2_16_00_08
PDMCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
237 #ifndef ti_drivers_pdm_PDMCC26XX__include
238 #define ti_drivers_pdm_PDMCC26XX__include
239 
240 #ifdef __cplusplus
241 extern "C" {
242 #endif
243 
248 #define ti_sysbios_family_arm_m3_Hwi__nolocalnames
249 
250 #include <ti/sysbios/knl/Semaphore.h>
251 #include <ti/drivers/PIN.h>
252 #include <ti/sysbios/family/arm/m3/Hwi.h>
253 #include <ti/drivers/Power.h>
255 
256 /*********************************************************************
257  * CONSTANTS
258  */
260 #define PDM_TASK_STACK_SIZE 400
261 
264 #define PDM_NUM_OF_CHANNELS 2
265 
269 #define PDM_BLOCK_SIZE_IN_SAMPLES 64
270 
273 #define PDM_BUFFER_SIZE_IN_BLOCKS 3
274 
276 #define PCM_COMPRESSION_RATE 4
277 
282 #define PCM_METADATA_SIZE 4
283 
287 #define PDM_SAMPLE_SIZE 16 // 24
288 
289 #define PCM_SAMPLE_SIZE 16 // Only 16 bits supported for now
290 
293 #define PDM_NUMBER_OF_PINS 1 // Only one pin to control microphone power
294 
295 /* Events */
298 #define PDM_EVT_BLK_RDY Event_Id_00
299 
301 #define PDM_EVT_START Event_Id_01
302 
304 #define PDM_EVT_BLK_ERROR Event_Id_02
305 
307 #define PDM_EVT_CLOSE Event_Id_03
308 
313 #define PDM_DECIMATION_STARTUP_DELAY_IN_SAMPLES 32
314 
315 /* PDM rollback vector bit masks. Each bit mask corresponds to an action that PDMCC26XX_rollbackDriverInitialisation() commits */
317 #define PDM_ROLLBACK_OPEN 1 << 0
318 
319 #define PDM_ROLLBACK_ACTIVE_PCM_BUFFER 1 << 1
320 
321 #define PDM_ROLLBACK_I2S_DRIVER 1 << 2
322 
323 #define PDM_ROLLBACK_PIN 1 << 3
324 
325 
326 
328 #define PDMCC26XX_COMPR_ITER_OUTPUT_SIZE 16
329 
330 #define PDMCC26XX_CPY_ITER_OUTPUT_SIZE 64
331 /*********************************************************************
332  * MACROS
333  */
334 
335 /*********************************************************************
336  * TYPEDEFS
337 */
340 #if (defined PDM_SAMPLE_SIZE) && (PDM_SAMPLE_SIZE == 24)
341 typedef __packed struct {
342  uint8_t pdmSampleLsb;
343  uint16_t pdmSampleMsb;
344 } pdmSample_t;
345 #elif (defined PDM_SAMPLE_SIZE) && (PDM_SAMPLE_SIZE == 16)
346 typedef uint16_t pdmSample_t;
347 #else
348 #error Unsupported PDM samples size (16 or 24)
349 #endif
350 
351 #if (defined PCM_SAMPLE_SIZE) && (PCM_SAMPLE_SIZE == 16)
352 typedef int16_t pcmSample_t;
353 #else
354 #error Unsupported PCM samples size (16)
355 #endif
356 
358 typedef struct {
359  uint8_t seqNum;
360  int8_t si;
361  int16_t pv;
363 
365 typedef struct {
367  uint8_t pBuffer[];
369 
375 typedef void *(*PDMCC26XX_MallocFxn)(size_t memSize);
376 
383 typedef void (*PDMCC26XX_FreeFxn)(void *ptr, size_t memSize);
384 
390 typedef struct PDMCC26XX_Config {
392  void *object;
393 
395  void const *hwAttrs;
397 
399 extern const PDMCC26XX_Config PDMCC26XX_config[];
400 
407 typedef struct PDMCC26XX_HWAttrs {
413 
418 
422 typedef enum PDMCC26XX_Status {
435 
448 typedef enum PDMCC26XX_Gain {
456 
463  void *arg;
466 
472 typedef void (*PDMCC26XX_CallbackFxn) (PDMCC26XX_Handle handle, PDMCC26XX_StreamNotification *streamNotification);
473 
489 typedef struct PDMCC26XX_BufferRequest {
495 
503 typedef struct PDMCC26XX_Params {
504  /* PDM control variables */
509  int32_t *decimationFilter;
519  uint16_t retBufSizeInBytes;
524  uintptr_t custom;
527 
533 typedef struct PDMCC26XX_Object {
534  /* PDM control variables */
539  int32_t *decimationFilter;
549  uint16_t retBufSizeInBytes;
557  /* PDM SYS/BIOS objects */
558  ti_sysbios_family_arm_m3_Hwi_Struct hwi;
559  Semaphore_Struct blockComplete;
561  /* PIN driver state object and handle */
565  bool isOpen;
567 
572 extern void PDMCC26XX_init(PDMCC26XX_Handle handle);
573 
591 extern PDMCC26XX_Handle PDMCC26XX_open(PDMCC26XX_Params *params);
592 
608 extern void PDMCC26XX_close(PDMCC26XX_Handle handle);
609 
626 extern bool PDMCC26XX_startStream(PDMCC26XX_Handle handle);
627 
644 extern bool PDMCC26XX_stopStream(PDMCC26XX_Handle handle);
645 
664 extern bool PDMCC26XX_requestBuffer(PDMCC26XX_Handle handle, PDMCC26XX_BufferRequest *bufferRequest);
665 
666 
667 /* Do not interfere with the app if they include the family Hwi module */
668 #undef ti_sysbios_family_arm_m3_Hwi__nolocalnames
669 
670 #ifdef __cplusplus
671 }
672 #endif
673 
674 #endif /* ti_drivers_pdm_PDMCC26XX__include */
uint8_t PIN_Id
Pin identifier data type.
Definition: PIN.h:557
void PDMCC26XX_close(PDMCC26XX_Handle handle)
Function to close a given CC26XX PDM peripheral specified by the PDM handle.
PDMCC26XX_Gain
Predefined gain settings.
Definition: PDMCC26XX.h:448
PDMCC26XX_Gain micGain
Definition: PDMCC26XX.h:542
PDMCC26XX_pcmBuffer * buffer
Definition: PDMCC26XX.h:490
int16_t pv
Definition: PDMCC26XX.h:361
bool useDefaultFilter
Definition: PDMCC26XX.h:506
PDMCC26XX_Handle PDMCC26XX_open(PDMCC26XX_Params *params)
Function to initialize the CC26XX PDM peripheral specified by the particular handle. The parameter specifies which mode the PDM will operate.
struct PDMCC26XX_Config PDMCC26XX_Config
The PDMCC26XX_Config structure contains a set of pointers used to characterize the PDMCC26XX driver i...
bool PDMCC26XX_startStream(PDMCC26XX_Handle handle)
Function to start streaming PDM data.
A PDMCC26XX_StreamNotification data structure is used with PDMCC26XX_CallbackFxn(). Provides notification about available buffers and potential errors.
Definition: PDMCC26XX.h:462
void * arg
Definition: PDMCC26XX.h:463
void *(* PDMCC26XX_MallocFxn)(size_t memSize)
PDMCC26XX_MallocFxn is a function pointer for the malloc function to be used by the driver...
Definition: PDMCC26XX.h:375
Definition: PDMCC26XX.h:432
struct PDMCC26XX_StreamNotification PDMCC26XX_StreamNotification
A PDMCC26XX_StreamNotification data structure is used with PDMCC26XX_CallbackFxn(). Provides notification about available buffers and potential errors.
Power manager interface.
bool applyCompression
Definition: PDMCC26XX.h:544
int16_t pcmSample_t
Definition: PDMCC26XX.h:352
Power manager interface for CC26XX.
struct PDMCC26XX_Object PDMCC26XX_Object
PDMCC26XX Object.
PDMCC26XX_MallocFxn mallocFxn
Definition: PDMCC26XX.h:550
Metadata associated with an array of PCM data.
Definition: PDMCC26XX.h:358
PIN_Handle pinHandle
Definition: PDMCC26XX.h:563
bool PDMCC26XX_stopStream(PDMCC26XX_Handle handle)
Function to stop streaming PDM data.
int taskPriority
Definition: PDMCC26XX.h:411
const PDMCC26XX_Config PDMCC26XX_config[]
PDMCC26XX_CallbackFxn callbackFxn
Definition: PDMCC26XX.h:535
PCM buffer pointed to in a PDMCC26XX_BufferRequest.
Definition: PDMCC26XX.h:365
struct PDMCC26XX_HWAttrs PDMCC26XX_HWAttrs
PDMCC26XX Hardware attributes.
struct PDMCC26XX_Params PDMCC26XX_Params
PDMCC26XX Parameters are used to with the PDMCC26XX_open() call. Default values for these parameters ...
Definition: PDMCC26XX.h:424
bool PDMCC26XX_requestBuffer(PDMCC26XX_Handle handle, PDMCC26XX_BufferRequest *bufferRequest)
Function for requesting buffer.
Semaphore_Struct blockComplete
Definition: PDMCC26XX.h:559
Definition: PDMCC26XX.h:452
void PDMCC26XX_init(PDMCC26XX_Handle handle)
PDM CC26XX initialization.
int32_t * decimationFilter
Definition: PDMCC26XX.h:509
struct PDMCC26XX_Config * PDMCC26XX_Handle
A handle that is returned from a PDMCC26XX_open() call.
Definition: PDMCC26XX.h:417
Definition: PDMCC26XX.h:430
PDMCC26XX_metaData metaData
Definition: PDMCC26XX.h:366
PDMCC26XX_StreamNotification * streamNotification
Definition: PDMCC26XX.h:554
void const * hwAttrs
Definition: PDMCC26XX.h:395
bool micPowerActiveHigh
Definition: PDMCC26XX.h:543
Definition: PDMCC26XX.h:454
uint16_t pdmSample_t
Definition: PDMCC26XX.h:346
bool micPowerActiveHigh
Definition: PDMCC26XX.h:513
A PDMCC26XX_BufferRequest data structure is used with PDMCC26XX_requestBuffer().
Definition: PDMCC26XX.h:489
PDMCC26XX Parameters are used to with the PDMCC26XX_open() call. Default values for these parameters ...
Definition: PDMCC26XX.h:503
uint16_t retBufSizeInBytes
Definition: PDMCC26XX.h:519
uint32_t startupDelayWithClockInSamples
Definition: PDMCC26XX.h:546
Definition: PDMCC26XX.h:451
Definition: PDMCC26XX.h:450
uint32_t startupDelayWithClockInSamples
Definition: PDMCC26XX.h:516
The PDMCC26XX_Config structure contains a set of pointers used to characterize the PDMCC26XX driver i...
Definition: PDMCC26XX.h:390
uint16_t retBufSizeInBytes
Definition: PDMCC26XX.h:549
Definition: PDMCC26XX.h:449
Definition: PDMCC26XX.h:433
void * object
Definition: PDMCC26XX.h:392
underlying data structure for type PIN_State
Definition: PIN.h:687
void(* PDMCC26XX_CallbackFxn)(PDMCC26XX_Handle handle, PDMCC26XX_StreamNotification *streamNotification)
The definition of a callback function used when buffers are ready.
Definition: PDMCC26XX.h:472
Definition: PDMCC26XX.h:423
uint8_t seqNum
Definition: PDMCC26XX.h:359
PDMCC26XX_Status status
Definition: PDMCC26XX.h:493
PDMCC26XX_MallocFxn mallocFxn
Definition: PDMCC26XX.h:522
int8_t si
Definition: PDMCC26XX.h:360
PIN_Id micPower
Definition: PDMCC26XX.h:409
PDMCC26XX_Status status
Definition: PDMCC26XX.h:464
bool useDefaultFilter
Definition: PDMCC26XX.h:536
bool isOpen
Definition: PDMCC26XX.h:565
PDMCC26XX_FreeFxn freeFxn
Definition: PDMCC26XX.h:523
PDMCC26XX Object.
Definition: PDMCC26XX.h:533
PDMCC26XX_Status
Status codes that are set by the PDM driver.
Definition: PDMCC26XX.h:422
int32_t * decimationFilter
Definition: PDMCC26XX.h:539
struct PDMCC26XX_BufferRequest PDMCC26XX_BufferRequest
A PDMCC26XX_BufferRequest data structure is used with PDMCC26XX_requestBuffer().
Definition: PDMCC26XX.h:453
PIN_State pinState
Definition: PDMCC26XX.h:562
bool applyCompression
Definition: PDMCC26XX.h:514
PDMCC26XX_FreeFxn freeFxn
Definition: PDMCC26XX.h:551
uintptr_t custom
Definition: PDMCC26XX.h:524
Generic PIN & GPIO driver.
void(* PDMCC26XX_FreeFxn)(void *ptr, size_t memSize)
PDMCC26XX_FreeFxn is a function pointer for the free function to be used by the driver. This is needed for memory clean up, if something goes wrong.
Definition: PDMCC26XX.h:383
PDMCC26XX Hardware attributes.
Definition: PDMCC26XX.h:407
PDMCC26XX_Gain micGain
Definition: PDMCC26XX.h:512
ti_sysbios_family_arm_m3_Hwi_Struct hwi
Definition: PDMCC26XX.h:558
Definition: PDMCC26XX.h:429
bool bStreamStarted
Definition: PDMCC26XX.h:555
PDMCC26XX_CallbackFxn callbackFxn
Definition: PDMCC26XX.h:505
Copyright 2016, Texas Instruments Incorporated