1 /*
2  * Copyright 2024 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 #ifndef _FSL_DSP_H_
8 #define _FSL_DSP_H_
9 
10 #include <stdint.h>
11 #include "fsl_device_registers.h"
12 
13 /*!
14  * @addtogroup dsp
15  * @{
16  */
17 
18 /*******************************************************************************
19  * Definitions
20  ******************************************************************************/
21 
22 /*! @name Driver version */
23 /*@{*/
24 /*! @brief DSP driver version 2.0.0. */
25 #define FSL_DSP_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
26 /*@}*/
27 
28 #if defined(SYSCON0)
29 #define SYSCON SYSCON0
30 #elif defined(SYSCON1)
31 #define SYSCON SYSCON1
32 #endif
33 /*!
34  * @brief Structure for DSP copy image to destination address
35  *
36  * Defines start and destination address for copying image with given size.
37  */
38 typedef struct _dsp_copy_image
39 {
40     uint32_t *srcAddr;
41     uint32_t *destAddr;
42     uint32_t size;
43 } dsp_copy_image_t;
44 
45 /*!
46  * @brief Fusion DSP vector table select
47  */
48 typedef enum _dsp_static_vec_sel
49 {
50     kDSP_StatVecSel0 = 0U, /* Vector base 0058_0000h for HiFi1. Primary vector (2402_0000h) for HiFi4. */
51     kDSP_StatVecSel1 = 1U, /* Vector base 0060_0000h.  Alternate vector (2010_0000h) for HiFi4. */
52 } dsp_static_vec_sel_t;
53 
54 /*******************************************************************************
55  * API
56  ******************************************************************************/
57 #if defined(__cplusplus)
58 extern "C" {
59 #endif
60 
61 /*!
62  * @brief Initializing DSP core.
63  *
64  * Power up DSP TCM
65  * Enable DSP clock
66  * Reset DSP peripheral
67  */
68 void DSP_Init(void);
69 /*!
70  * @brief Deinit DSP core.
71  *
72  * Power down DSP TCM
73  * Disable DSP clock
74  * Set DSP peripheral reset
75  */
76 void DSP_Deinit(void);
77 
78 /*!
79  * @brief Copy DSP image to destination address.
80  *
81  * Copy DSP image from source address to destination address with given size.
82  *
83  * @param dspCopyImage Structure contains information for DSP copy image to destination address.
84  */
85 void DSP_CopyImage(dsp_copy_image_t *dspCopyImage);
86 
87 /*!
88  * @brief Start DSP core.
89  */
DSP_Start(void)90 static inline void DSP_Start(void)
91 {
92     SYSCON->DSPSTALL = 0x0;
93 }
94 
95 /*!
96  * @brief Stop DSP core.
97  */
DSP_Stop(void)98 static inline void DSP_Stop(void)
99 {
100     SYSCON->DSPSTALL = 0x1;
101 }
102 
103 /*!
104  * @brief Set DSP static vector table remap.
105  *
106  * @param statVecSel static vector base address selection
107  * @param remap static vector remap, For HiFi1 when statVecSel = 0, the valid range is 0~0x3FF, when statVecSel=1, the
108  * valid range is 0~0x7FF. For HiFi4, the bits value will remap ARADDR[22:10] when [STATVECSELECT] is high and ARADDR
109  * hits 1 KB from 2010_0000h.
110  */
DSP_SetVecRemap(dsp_static_vec_sel_t statVecSel,uint32_t remap)111 static inline void DSP_SetVecRemap(dsp_static_vec_sel_t statVecSel, uint32_t remap)
112 {
113 #if defined(SYSCON1)
114     SYSCON1->DSP_VECT_REMAP =
115         SYSCON1_DSP_VECT_REMAP_STATVECSELECT(statVecSel) | SYSCON1_DSP_VECT_REMAP_DSP_VECT_REMAP(remap);
116 #else
117     SYSCON0->DSP_VECT_REMAP =
118         SYSCON0_DSP_VECT_REMAP_STATVECSELECT(statVecSel) | SYSCON0_DSP_VECT_REMAP_DSP_VECT_REMAP(remap);
119 #endif
120 }
121 
122 #if defined(__cplusplus)
123 }
124 #endif
125 
126 /*! @} */
127 
128 #endif /* _FSL_RESET_H_ */
129