AM273x MCU+ SDK  08.02.00
mcasp/v0/mcasp.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * 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
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
50 #ifndef MCASP_H_
51 #define MCASP_H_
52 
53 /* ========================================================================== */
54 /* Include Files */
55 /* ========================================================================== */
56 
57 #include <drivers/mcasp.h>
58 #include <stdint.h>
59 #include <stdbool.h>
60 #include <kernel/dpl/HwiP.h>
61 #include <kernel/dpl/SemaphoreP.h>
62 #include <drivers/hw_include/cslr_mcasp.h>
63 #include <drivers/edma.h>
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 /* ========================================================================== */
70 /* Macros & Typedefs */
71 /* ========================================================================== */
72 
74 typedef void *MCASP_Handle;
75 
80 #define MCASP_GBLCTL_TIMEOUT (30000U)
81 
83 #define MCASP_RESET ((uint32_t) 0x00U)
84 #define MCASP_ENABLE ((uint32_t) 0x01U)
85 #define MCASP_DISABLE ((uint32_t) 0x00U)
86 
87 /*
88 ** McASP Register Offset
89 */
90 #define MCASP_REG_OFFSET ((uint32_t)0x4U)
91 
101 #define MCASP_TRANSFER_STATUS_COMPLETED (0U)
102 
103 #define MCASP_TRANSFER_STATUS_STARTED (1U)
104 
105 #define MCASP_TRANSFER_STATUS_CANCELLED (2U)
106 
107 #define MCASP_TRANSFER_STATUS_FAILED (3U)
108 
109 #define MCASP_TRANSFER_STATUS_TIMEOUT (4U)
110 
122 #define MCASP_DRIVER_MODE_POLLING (0U)
123 
127 #define MCASP_DRIVER_MODE_INTERRUPT (1U)
128 
132 #define MCASP_DRIVER_MODE_DMA (2U)
133 
144 #define MCASP_OPMODE_MASTER (0U)
145 
146 #define MCASP_OPMODE_SLAVE (1U)
147 
158 #define MCASP_CHANNEL_INPUT (0x0001U)
159 
160 #define MCASP_CHANNEL_OUTPUT (0x0002U)
161 
162 #define MCASP_CHANNEL_INOUT (MCASP_CHANNEL_INPUT | MCASP_CHANNEL_OUTPUT)
163 
173 #define MCASP_DRIVER_STATE_DELETED (0U)
174 #define MCASP_DRIVER_STATE_CREATED (1U)
175 #define MCASP_DRIVER_STATE_INITIALIZED (2U)
176 #define MCASP_DRIVER_STATE_OPENED (3U)
177 #define MCASP_DRIVER_STATE_CLOSED (4U)
178 #define MCASP_DRIVER_STATE_DEINITIALIZED (5U)
179 #define MCASP_DRIVER_STATE_POWERED_DOWN (6U)
180 #define MCASP_DRIVER_STATE_PWRM_SUSPEND (7U)
181 
191 #define MCASP_SERIALIZER_STATUS_FREE (0U)
192 #define MCASP_SERIALIZER_STATUS_XMT (1U)
193 #define MCASP_SERIALIZER_STATUS_RCV (2U)
194 
204 #define MCASP_CHANNEL_MODE_FREE (0U)
205 #define MCASP_CHANNEL_MODE_XMT_DIT (1U)
206 #define MCASP_CHANNEL_MODE_XMT_TDM (2U)
207 #define MCASP_CHANNEL_MODE_RCV (3U)
208 
218 #define MCASP_WORD_SELECT_LSW (0U)
219 #define MCASP_WORD_SELECT_MSW (1U)
220 
230 #define MCASP_TRANSMIT_STATE_TX_RESET (0U)
231 #define MCASP_TRANSMIT_STATE_TX_FLUSH (1U)
232 #define MCASP_TRANSMIT_STATE_LOAD_INIT_BUFFER (2U)
233 #define MCASP_TRANSMIT_STATE_RELEASE_FROM_RESET (3U)
234 #define MCASP_TRANSMIT_STATE_WAIT_EVENT (4U)
235 #define MCASP_TRANSMIT_STATE_PROCESS_EVENT (5U)
236 #define MCASP_TRANSMIT_STATE_LOAD_ACTIVE_BUFFER (6U)
237 #define MCASP_TRANSMIT_STATE_DONE (7U)
238 #define MCASP_TRANSMIT_STATE_SPIN_IDLE (8U)
239 #define MCASP_TRANSMIT_STATE_ERROR (9U)
240 #define MCASP_TRANSMIT_STATE_EXIT (10U)
241 
251 #define MCASP_RECEIVE_STATE_RX_RESET (0U)
252 #define MCASP_RECEIVE_STATE_RX_FLUSH (1U)
253 #define MCASP_RECEIVE_STATE_RELEASE_FROM_RESET (2U)
254 #define MCASP_RECEIVE_STATE_WAIT_EVENT (3U)
255 #define MCASP_RECEIVE_STATE_PROCESS_EVENT (4U)
256 #define MCASP_RECEIVE_STATE_DONE (5U)
257 #define MCASP_RECEIVE_STATE_SPIN_IDLE (6U)
258 #define MCASP_RECEIVE_STATE_ERROR (7U)
259 #define MCASP_RECEIVE_STATE_EXIT (8U)
260 
262 /* ========================================================================== */
263 /* Structure Definitions */
264 /* ========================================================================== */
265 
270 typedef struct
271 {
272  void *txBuf;
275  void *rxBuf;
278  uint32_t count;
282  uint32_t timeout;
284  int32_t status;
286  void *args;
289 
297 typedef void (*MCASP_CallbackFxn) (MCASP_Handle handle,
298  MCASP_Transaction *transaction);
299 
303 typedef struct
304 {
305  uint32_t aClk;
307  uint32_t hiClk;
309  uint32_t clkChk;
312 
316 typedef struct
317 {
318  uint32_t pfunc;
320  uint32_t pdir;
322  uint32_t gblCtl;
324  uint32_t ditCtl;
326  uint32_t dlbCtl;
328  uint32_t amute;
330  uint32_t serSetup[16u];
333 
337 typedef struct
338 {
339  uint32_t fifoCtl;
341  uint32_t fifoStatus;
344 
348 typedef struct
349 {
350  uint32_t mask;
352  uint32_t fmt;
354  uint32_t frSyncCtl;
356  uint32_t tdm;
358  uint32_t intCtl;
360  uint32_t stat;
362  uint32_t evtCtl;
369 
373 typedef struct
374 {
382 
393 typedef struct
394 {
395  uint32_t edmaInst;
398 
402 typedef struct
403 {
404  uint32_t intrNum;
406  uint8_t intrPriority;
409 
414 typedef struct
415 {
416  uint32_t inProgress;
418  uint32_t state;
420  int32_t status;
422  uint32_t count;
427 
428 
441 typedef struct
442 {
443  uint32_t drvState;
445  uint32_t mode;
447  void *devHandle;
449  uint32_t frSyncCtl;
451  uint32_t fmt;
453  uint32_t noOfChannels;
455  uint32_t indexOfSersRequested[16];
457  uint32_t channelMode;
459  uint32_t wordBitsSelect;
465  uint16_t noOfSlots;
468 
472 typedef struct
473 {
474  /*
475  * User params
476  */
479  uint16_t instNum;
481  uint32_t drvState;
483  uint32_t transferMode;
490  /*
491  * State variables
492  */
493  uint32_t isOpen;
503 } MCASP_Object;
504 
506 typedef struct
507 {
508  /*
509  * SOC configuration
510  */
511  uintptr_t baseAddr;
515  uint16_t serStatus[16];
519  uint32_t intrEnable;
525  uint32_t dmaEnable;
527 } MCASP_Attrs;
528 
529 typedef struct
530 {
535 } MCASP_Config;
536 
538 extern MCASP_Config gMcaspConfig[];
540 extern uint32_t gMcaspConfigNum;
541 
542 
543 /* ========================================================================== */
544 /* Function Declarations */
545 /* ========================================================================== */
546 
550 void MCASP_init(void);
551 
555 void MCASP_deinit(void);
556 
563 static inline void MCASP_openParamsInit(MCASP_OpenParams *openPrms);
564 
579 MCASP_Handle MCASP_open(uint32_t index, const MCASP_OpenParams *openParams);
580 
591 
606 
617 
618 /* ========================================================================== */
619 /* Static Function Definitions */
620 /* ========================================================================== */
621 
622 static inline void MCASP_openParamsInit(MCASP_OpenParams *openPrms)
623 {
624  if (openPrms != NULL)
625  {
626  // Set Default values
627  }
628 }
629 
630 #ifdef __cplusplus
631 }
632 #endif
633 
634 #endif /* #ifndef MCASP_H_ */
635 
MCASP_GlobalConfig::amute
uint32_t amute
Definition: mcasp/v0/mcasp.h:328
MCASP_Config::attrs
const MCASP_Attrs * attrs
Definition: mcasp/v0/mcasp.h:531
MCASP_ChannelObj::channelMode
uint32_t channelMode
Definition: mcasp/v0/mcasp.h:457
MCASP_Transaction::args
void * args
Definition: mcasp/v0/mcasp.h:286
MCASP_ClockConfig::aClk
uint32_t aClk
Definition: mcasp/v0/mcasp.h:305
MCASP_Object
MCASP driver object.
Definition: mcasp/v0/mcasp.h:473
MCASP_ChannelObj::frSyncCtl
uint32_t frSyncCtl
Definition: mcasp/v0/mcasp.h:449
MCASP_close
void MCASP_close(MCASP_Handle handle)
Function to close a MCASP peripheral specified by the MCASP handle.
MCASP_DataConfig::tdm
uint32_t tdm
Definition: mcasp/v0/mcasp.h:356
MCASP_GlobalConfig::pfunc
uint32_t pfunc
Definition: mcasp/v0/mcasp.h:318
MCASP_Object::handle
MCASP_Handle handle
Definition: mcasp/v0/mcasp.h:477
gMcaspConfig
MCASP_Config gMcaspConfig[]
Externally defined driver configuration array.
MCASP_Attrs::dmaEnable
uint32_t dmaEnable
Definition: mcasp/v0/mcasp.h:525
MCASP_TransferObj::status
int32_t status
Definition: mcasp/v0/mcasp.h:420
MCASP_CallbackFxn
void(* MCASP_CallbackFxn)(MCASP_Handle handle, MCASP_Transaction *transaction)
The definition of a callback function used by the MCASP driver when used in Callback Mode.
Definition: mcasp/v0/mcasp.h:297
MCASP_Object::hwiObjTx
HwiP_Object hwiObjTx
Definition: mcasp/v0/mcasp.h:499
MCASP_Transaction::rxBuf
void * rxBuf
Definition: mcasp/v0/mcasp.h:275
MCASP_Object::transferSemObj
SemaphoreP_Object transferSemObj
Definition: mcasp/v0/mcasp.h:497
MCASP_Object::lockObj
SemaphoreP_Object lockObj
Definition: mcasp/v0/mcasp.h:495
MCASP_TransferObj::state
uint32_t state
Definition: mcasp/v0/mcasp.h:418
MCASP_FifoConfig
Hardware fifo setup structure.
Definition: mcasp/v0/mcasp.h:338
MCASP_DataConfig::clk
MCASP_ClockConfig clk
Definition: mcasp/v0/mcasp.h:364
MCASP_Transaction::txBuf
void * txBuf
Definition: mcasp/v0/mcasp.h:272
MCASP_open
MCASP_Handle MCASP_open(uint32_t index, const MCASP_OpenParams *openParams)
This function opens a given MCASP peripheral.
MCASP_Attrs::numOfSerializers
uint16_t numOfSerializers
Definition: mcasp/v0/mcasp.h:513
MCASP_transfer
int32_t MCASP_transfer(MCASP_Handle handle, MCASP_Transaction *txn)
Generic transfer function using McASP.
MCASP_ChannelObj::drvState
uint32_t drvState
Definition: mcasp/v0/mcasp.h:443
MCASP_ChannelObj::fmt
uint32_t fmt
Definition: mcasp/v0/mcasp.h:451
MCASP_Attrs::hwCfg
MCASP_HwConfig hwCfg
Definition: mcasp/v0/mcasp.h:517
MCASP_FifoConfig::fifoStatus
uint32_t fifoStatus
Definition: mcasp/v0/mcasp.h:341
SemaphoreP.h
MCASP_GlobalConfig::dlbCtl
uint32_t dlbCtl
Definition: mcasp/v0/mcasp.h:326
MCASP_DataConfig
Hardware setup data structure.
Definition: mcasp/v0/mcasp.h:349
MCASP_ChannelObj::noOfSerAllocated
uint16_t noOfSerAllocated
Definition: mcasp/v0/mcasp.h:463
edma.h
MCASP_Transaction
Data structure used with transfer call.
Definition: mcasp/v0/mcasp.h:271
MCASP_ChannelObj::wordBitsSelect
uint32_t wordBitsSelect
Definition: mcasp/v0/mcasp.h:459
MCASP_OpenParams
MCASP Parameters.
Definition: mcasp/v0/mcasp.h:394
MCASP_Object::XmtObj
MCASP_TransferObj XmtObj
Definition: mcasp/v0/mcasp.h:485
MCASP_Attrs
MCASP instance attributes - used during init time.
Definition: mcasp/v0/mcasp.h:507
MCASP_Transaction::count
uint32_t count
Definition: mcasp/v0/mcasp.h:278
MCASP_GlobalConfig
Hardware setup global structure.
Definition: mcasp/v0/mcasp.h:317
MCASP_HwIntConfig::intrPriority
uint8_t intrPriority
Definition: mcasp/v0/mcasp.h:406
MCASP_HwConfig::tx
MCASP_DataConfig tx
Definition: mcasp/v0/mcasp.h:379
MCASP_Config
Definition: mcasp/v0/mcasp.h:530
MCASP_deinit
void MCASP_deinit(void)
This function de-initializes the MCASP module.
HwiP.h
MCASP_TransferObj::transaction
MCASP_Transaction * transaction
Definition: mcasp/v0/mcasp.h:424
MCASP_ChannelObj::noOfSlots
uint16_t noOfSlots
Definition: mcasp/v0/mcasp.h:465
gMcaspConfigNum
uint32_t gMcaspConfigNum
Externally defined driver configuration array size.
MCASP_TransferObj::count
uint32_t count
Definition: mcasp/v0/mcasp.h:422
MCASP_GlobalConfig::ditCtl
uint32_t ditCtl
Definition: mcasp/v0/mcasp.h:324
MCASP_DataConfig::evtCtl
uint32_t evtCtl
Definition: mcasp/v0/mcasp.h:362
MCASP_ChannelObj
McASP Channel Object.
Definition: mcasp/v0/mcasp.h:442
MCASP_Object::RcvObj
MCASP_TransferObj RcvObj
Definition: mcasp/v0/mcasp.h:487
MCASP_HwConfig::rx
MCASP_DataConfig rx
Definition: mcasp/v0/mcasp.h:377
MCASP_ClockConfig::hiClk
uint32_t hiClk
Definition: mcasp/v0/mcasp.h:307
mcasp.h
MCASP_Attrs::baseAddr
uintptr_t baseAddr
Definition: mcasp/v0/mcasp.h:511
MCASP_Transaction::status
int32_t status
Definition: mcasp/v0/mcasp.h:284
MCASP_OpenParams::edmaInst
uint32_t edmaInst
Definition: mcasp/v0/mcasp.h:395
MCASP_ClockConfig
Hardware setup data clock structure.
Definition: mcasp/v0/mcasp.h:304
MCASP_TransferObj::inProgress
uint32_t inProgress
Definition: mcasp/v0/mcasp.h:416
MCASP_GlobalConfig::gblCtl
uint32_t gblCtl
Definition: mcasp/v0/mcasp.h:322
MCASP_DataConfig::frSyncCtl
uint32_t frSyncCtl
Definition: mcasp/v0/mcasp.h:354
MCASP_Object::isOpen
uint32_t isOpen
Definition: mcasp/v0/mcasp.h:493
MCASP_DataConfig::intCtl
uint32_t intCtl
Definition: mcasp/v0/mcasp.h:358
MCASP_ChannelObj::noOfChannels
uint32_t noOfChannels
Definition: mcasp/v0/mcasp.h:453
MCASP_DataConfig::stat
uint32_t stat
Definition: mcasp/v0/mcasp.h:360
MCASP_openParamsInit
static void MCASP_openParamsInit(MCASP_OpenParams *openPrms)
Function to initialize the MCASP_OpenParams struct to its defaults.
Definition: mcasp/v0/mcasp.h:622
MCASP_HwConfig::gbl
MCASP_GlobalConfig gbl
Definition: mcasp/v0/mcasp.h:375
MCASP_Handle
void * MCASP_Handle
A handle that is returned from a MCASP_open() call.
Definition: mcasp/v0/mcasp.h:74
MCASP_GlobalConfig::pdir
uint32_t pdir
Definition: mcasp/v0/mcasp.h:320
HwiP_Object
Opaque Hwi object used with the Hwi APIs.
Definition: HwiP.h:91
MCASP_Object::transferMode
uint32_t transferMode
Definition: mcasp/v0/mcasp.h:483
MCASP_HwIntConfig::intrNum
uint32_t intrNum
Definition: mcasp/v0/mcasp.h:404
MCASP_HwIntConfig
McASP Interrupt structures.
Definition: mcasp/v0/mcasp.h:403
MCASP_DataConfig::fmt
uint32_t fmt
Definition: mcasp/v0/mcasp.h:352
MCASP_TransferObj
McASP Transfer Data structure stored in driver object.
Definition: mcasp/v0/mcasp.h:415
MCASP_Attrs::intCfgRx
MCASP_HwIntConfig intCfgRx
Definition: mcasp/v0/mcasp.h:523
SemaphoreP_Object
Opaque semaphore object used with the semaphore APIs.
Definition: SemaphoreP.h:59
MCASP_ClockConfig::clkChk
uint32_t clkChk
Definition: mcasp/v0/mcasp.h:309
MCASP_Attrs::intCfgTx
MCASP_HwIntConfig intCfgTx
Definition: mcasp/v0/mcasp.h:521
MCASP_getHandle
MCASP_Handle MCASP_getHandle(uint32_t index)
This function returns the handle of an open MCASP Instance from the instance index.
MCASP_Transaction::timeout
uint32_t timeout
Definition: mcasp/v0/mcasp.h:282
MCASP_DataConfig::fifoCfg
MCASP_FifoConfig fifoCfg
Definition: mcasp/v0/mcasp.h:366
MCASP_Attrs::intrEnable
uint32_t intrEnable
Definition: mcasp/v0/mcasp.h:519
MCASP_Object::instNum
uint16_t instNum
Definition: mcasp/v0/mcasp.h:479
MCASP_ChannelObj::mode
uint32_t mode
Definition: mcasp/v0/mcasp.h:445
MCASP_Object::hwiObjRx
HwiP_Object hwiObjRx
Definition: mcasp/v0/mcasp.h:501
MCASP_ChannelObj::devHandle
void * devHandle
Definition: mcasp/v0/mcasp.h:447
MCASP_Config::object
MCASP_Object * object
Definition: mcasp/v0/mcasp.h:533
MCASP_init
void MCASP_init(void)
This function initializes the MCASP module.
MCASP_FifoConfig::fifoCtl
uint32_t fifoCtl
Definition: mcasp/v0/mcasp.h:339
MCASP_HwConfig
Hardware setup structure.
Definition: mcasp/v0/mcasp.h:374
MCASP_DataConfig::mask
uint32_t mask
Definition: mcasp/v0/mcasp.h:350
MCASP_Object::drvState
uint32_t drvState
Definition: mcasp/v0/mcasp.h:481