TI-RTOS Drivers  tidrivers_full_2_20_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  */
249 #ifndef ti_drivers_pdm_PDMCC26XX__include
250 #define ti_drivers_pdm_PDMCC26XX__include
251 
252 #ifdef __cplusplus
253 extern "C" {
254 #endif
255 
260 #define ti_sysbios_family_arm_m3_Hwi__nolocalnames
261 
262 #include <ti/sysbios/knl/Semaphore.h>
263 #include <ti/drivers/PIN.h>
264 #include <ti/sysbios/family/arm/m3/Hwi.h>
265 #include <ti/drivers/Power.h>
267 
268 /*********************************************************************
269  * CONSTANTS
270  */
272 #define PDM_TASK_STACK_SIZE 500
273 
276 #define PDM_NUM_OF_CHANNELS 2
277 
281 #define PDM_BLOCK_SIZE_IN_SAMPLES 64
282 
285 #define PDM_BUFFER_SIZE_IN_BLOCKS 3
286 
288 #define PCM_COMPRESSION_RATE 4
289 
294 #define PCM_METADATA_SIZE 4
295 
299 #define PDM_SAMPLE_SIZE 16 // 24
300 
301 #define PCM_SAMPLE_SIZE 16 // Only 16 bits supported for now
302 
305 #define PDM_NUMBER_OF_PINS 1 // Only one pin to control microphone power
306 
307 /* Events */
310 #define PDM_EVT_BLK_RDY Event_Id_00
311 
313 #define PDM_EVT_START Event_Id_01
314 
316 #define PDM_EVT_BLK_ERROR Event_Id_02
317 
319 #define PDM_EVT_CLOSE Event_Id_03
320 
325 #define PDM_DECIMATION_STARTUP_DELAY_IN_SAMPLES 32
326 
327 /* PDM rollback vector bit masks. Each bit mask corresponds to an action that PDMCC26XX_rollbackDriverInitialisation() commits */
329 #define PDM_ROLLBACK_OPEN 1 << 0
330 
331 #define PDM_ROLLBACK_ACTIVE_PCM_BUFFER 1 << 1
332 
333 #define PDM_ROLLBACK_I2S_DRIVER 1 << 2
334 
335 #define PDM_ROLLBACK_PIN 1 << 3
336 
337 
338 
340 #define PDMCC26XX_COMPR_ITER_OUTPUT_SIZE 16
341 
342 #define PDMCC26XX_CPY_ITER_OUTPUT_SIZE 64
343 /*********************************************************************
344  * MACROS
345  */
346 
347 /*********************************************************************
348  * TYPEDEFS
349 */
352 #if (defined PDM_SAMPLE_SIZE) && (PDM_SAMPLE_SIZE == 24)
353 typedef __packed struct {
354  uint8_t pdmSampleLsb;
355  uint16_t pdmSampleMsb;
356 } pdmSample_t;
357 #elif (defined PDM_SAMPLE_SIZE) && (PDM_SAMPLE_SIZE == 16)
358 typedef uint16_t pdmSample_t;
359 #else
360 #error Unsupported PDM samples size (16 or 24)
361 #endif
362 
363 #if (defined PCM_SAMPLE_SIZE) && (PCM_SAMPLE_SIZE == 16)
364 typedef int16_t pcmSample_t;
365 #else
366 #error Unsupported PCM samples size (16)
367 #endif
368 
370 typedef struct {
371  uint8_t seqNum;
372  int8_t si;
373  int16_t pv;
375 
377 typedef struct {
379  uint8_t pBuffer[];
381 
387 typedef void *(*PDMCC26XX_MallocFxn)(size_t memSize);
388 
395 typedef void (*PDMCC26XX_FreeFxn)(void *ptr, size_t memSize);
396 
402 typedef struct PDMCC26XX_Config {
404  void *object;
405 
407  void const *hwAttrs;
409 
411 extern const PDMCC26XX_Config PDMCC26XX_config[];
412 
419 typedef struct PDMCC26XX_HWAttrs {
425 
430 
434 typedef enum PDMCC26XX_Status {
447 
460 typedef enum PDMCC26XX_Gain {
468 
475  void *arg;
478 
484 typedef void (*PDMCC26XX_CallbackFxn) (PDMCC26XX_Handle handle, PDMCC26XX_StreamNotification *streamNotification);
485 
501 typedef struct PDMCC26XX_BufferRequest {
507 
515 typedef struct PDMCC26XX_Params {
516  /* PDM control variables */
521  int32_t *decimationFilter;
531  uint16_t retBufSizeInBytes;
536  uintptr_t custom;
539 
545 typedef struct PDMCC26XX_Object {
546  /* PDM control variables */
551  int32_t *decimationFilter;
561  uint16_t retBufSizeInBytes;
569  /* PDM SYS/BIOS objects */
570  ti_sysbios_family_arm_m3_Hwi_Struct hwi;
571  Semaphore_Struct blockComplete;
573  /* PIN driver state object and handle */
577  bool isOpen;
579 
584 extern void PDMCC26XX_init(PDMCC26XX_Handle handle);
585 
603 extern PDMCC26XX_Handle PDMCC26XX_open(PDMCC26XX_Params *params);
604 
620 extern void PDMCC26XX_close(PDMCC26XX_Handle handle);
621 
638 extern bool PDMCC26XX_startStream(PDMCC26XX_Handle handle);
639 
656 extern bool PDMCC26XX_stopStream(PDMCC26XX_Handle handle);
657 
676 extern bool PDMCC26XX_requestBuffer(PDMCC26XX_Handle handle, PDMCC26XX_BufferRequest *bufferRequest);
677 
678 
679 /* Do not interfere with the app if they include the family Hwi module */
680 #undef ti_sysbios_family_arm_m3_Hwi__nolocalnames
681 
682 #ifdef __cplusplus
683 }
684 #endif
685 
686 #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:460
PDMCC26XX_Gain micGain
Definition: PDMCC26XX.h:554
PDMCC26XX_pcmBuffer * buffer
Definition: PDMCC26XX.h:502
int16_t pv
Definition: PDMCC26XX.h:373
bool useDefaultFilter
Definition: PDMCC26XX.h:518
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:474
void * arg
Definition: PDMCC26XX.h:475
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:387
Definition: PDMCC26XX.h:444
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:556
int16_t pcmSample_t
Definition: PDMCC26XX.h:364
Power manager interface for CC26XX.
struct PDMCC26XX_Object PDMCC26XX_Object
PDMCC26XX Object.
PDMCC26XX_MallocFxn mallocFxn
Definition: PDMCC26XX.h:562
Metadata associated with an array of PCM data.
Definition: PDMCC26XX.h:370
PIN_Handle pinHandle
Definition: PDMCC26XX.h:575
bool PDMCC26XX_stopStream(PDMCC26XX_Handle handle)
Function to stop streaming PDM data.
int taskPriority
Definition: PDMCC26XX.h:423
const PDMCC26XX_Config PDMCC26XX_config[]
PDMCC26XX_CallbackFxn callbackFxn
Definition: PDMCC26XX.h:547
PCM buffer pointed to in a PDMCC26XX_BufferRequest.
Definition: PDMCC26XX.h:377
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:436
bool PDMCC26XX_requestBuffer(PDMCC26XX_Handle handle, PDMCC26XX_BufferRequest *bufferRequest)
Function for requesting buffer.
Semaphore_Struct blockComplete
Definition: PDMCC26XX.h:571
Definition: PDMCC26XX.h:464
void PDMCC26XX_init(PDMCC26XX_Handle handle)
PDM CC26XX initialization.
int32_t * decimationFilter
Definition: PDMCC26XX.h:521
struct PDMCC26XX_Config * PDMCC26XX_Handle
A handle that is returned from a PDMCC26XX_open() call.
Definition: PDMCC26XX.h:429
Definition: PDMCC26XX.h:442
PDMCC26XX_metaData metaData
Definition: PDMCC26XX.h:378
PDMCC26XX_StreamNotification * streamNotification
Definition: PDMCC26XX.h:566
void const * hwAttrs
Definition: PDMCC26XX.h:407
bool micPowerActiveHigh
Definition: PDMCC26XX.h:555
Definition: PDMCC26XX.h:466
uint16_t pdmSample_t
Definition: PDMCC26XX.h:358
bool micPowerActiveHigh
Definition: PDMCC26XX.h:525
A PDMCC26XX_BufferRequest data structure is used with PDMCC26XX_requestBuffer().
Definition: PDMCC26XX.h:501
PDMCC26XX Parameters are used to with the PDMCC26XX_open() call. Default values for these parameters ...
Definition: PDMCC26XX.h:515
uint16_t retBufSizeInBytes
Definition: PDMCC26XX.h:531
uint32_t startupDelayWithClockInSamples
Definition: PDMCC26XX.h:558
Definition: PDMCC26XX.h:463
Definition: PDMCC26XX.h:462
uint32_t startupDelayWithClockInSamples
Definition: PDMCC26XX.h:528
The PDMCC26XX_Config structure contains a set of pointers used to characterize the PDMCC26XX driver i...
Definition: PDMCC26XX.h:402
uint16_t retBufSizeInBytes
Definition: PDMCC26XX.h:561
Definition: PDMCC26XX.h:461
Definition: PDMCC26XX.h:445
void * object
Definition: PDMCC26XX.h:404
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:484
Definition: PDMCC26XX.h:435
uint8_t seqNum
Definition: PDMCC26XX.h:371
PDMCC26XX_Status status
Definition: PDMCC26XX.h:505
PDMCC26XX_MallocFxn mallocFxn
Definition: PDMCC26XX.h:534
int8_t si
Definition: PDMCC26XX.h:372
PIN_Id micPower
Definition: PDMCC26XX.h:421
PDMCC26XX_Status status
Definition: PDMCC26XX.h:476
bool useDefaultFilter
Definition: PDMCC26XX.h:548
bool isOpen
Definition: PDMCC26XX.h:577
PDMCC26XX_FreeFxn freeFxn
Definition: PDMCC26XX.h:535
PDMCC26XX Object.
Definition: PDMCC26XX.h:545
PDMCC26XX_Status
Status codes that are set by the PDM driver.
Definition: PDMCC26XX.h:434
int32_t * decimationFilter
Definition: PDMCC26XX.h:551
struct PDMCC26XX_BufferRequest PDMCC26XX_BufferRequest
A PDMCC26XX_BufferRequest data structure is used with PDMCC26XX_requestBuffer().
Definition: PDMCC26XX.h:465
PIN_State pinState
Definition: PDMCC26XX.h:574
bool applyCompression
Definition: PDMCC26XX.h:526
PDMCC26XX_FreeFxn freeFxn
Definition: PDMCC26XX.h:563
uintptr_t custom
Definition: PDMCC26XX.h:536
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:395
PDMCC26XX Hardware attributes.
Definition: PDMCC26XX.h:419
PDMCC26XX_Gain micGain
Definition: PDMCC26XX.h:524
ti_sysbios_family_arm_m3_Hwi_Struct hwi
Definition: PDMCC26XX.h:570
Definition: PDMCC26XX.h:441
bool bStreamStarted
Definition: PDMCC26XX.h:567
PDMCC26XX_CallbackFxn callbackFxn
Definition: PDMCC26XX.h:517
Copyright 2016, Texas Instruments Incorporated