1 /*
2 * Copyright (c) 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 *
32 */
33 \r
34 /*=================================================================\r
35 * sysasnr.c: ASNR creation routines.\r
36 *=================================================================*/\r
37 \r
38 #include <xdc/std.h>\r
39 #include <ti/sysbios/BIOS.h>\r
40 #include <xdc/runtime/System.h>\r
41 \r
42 #include <types.h>\r
43 #include <ti/mas/util/ecomem.h>\r
44 #include <ti/mas/vpe/asnr.h>\r
45 \r
46 #include "sys.h"\r
47 \r
48 asnrSizeConfig_t asnrSizeConfig = {\r
49 asnr_SRATE_16K /* 16kHz sampling rate */\r
50 };\r
51 \r
52 asnrOpenConfig_t asnrOpenConfig = {\r
53 asnr_SRATE_16K /* use 16kHz sampling rate */\r
54 };\r
55 \r
56 /*=================================================================\r
57 * void sysAsnrCreate(void) Create ASNR's within virtual mics\r
58 *=================================================================*/\r
59 void sysAsnrCreate(void)\r
60 {\r
61 int k, err;\r
62 tint nbufs;\r
63 const ecomemBuffer_t *bufs;\r
64 asnrNewConfig_t asnrNewConfig;\r
65 asnrControl_t asnrCtl;\r
66 \r
67 System_printf("...Initializing ASNR's\n");\r
68 System_flush();\r
69 \r
70 /* Configure ASNR's (use same configuration for all) */\r
71 err = asnrGetSizes(&nbufs, &bufs, &asnrSizeConfig);\r
72 if (err != asnr_NOERR) {\r
73 System_printf("*** ASNR's getsizes error: %d\n", err);\r
74 BIOS_exit(0);\r
75 }\r
76 /* Allocate memory for ASNR's */\r
77 if (nbufs > SYS_COMP_MAXBUFS) {\r
78 System_printf("*** not enough buffer descriptors");\r
79 BIOS_exit(0);\r
80 }\r
81 \r
82 asnrNewConfig.sizeCfg = asnrSizeConfig; /* Use same configuration for all */\r
83 for (k = 0; k < sysContext.nvmics; k++) {\r
84 err = sysHeapAllocAll(nbufs, sysCompBufs, (const void*)bufs);\r
85 SYS_CHECK_ERROR(err);\r
86 \r
87 /* Give memory to ASNR #k */\r
88 asnrNewConfig.handle = (void*)k; /* Indicate ASNR instance #k */\r
89 sysContext.asnrInst_p[k] = NULL;\r
90 err = asnrNew(&sysContext.asnrInst_p[k], nbufs, sysCompBufs, &asnrNewConfig);\r
91 if (err != asnr_NOERR) {\r
92 System_printf("*** ASNR #%d new error: %d\n", k, err);\r
93 BIOS_exit(0);\r
94 }\r
95 }\r
96 \r
97 /* Open ASNR for business */\r
98 for (k = 0; k < sysContext.nvmics; k++) {\r
99 err = asnrOpen(sysContext.asnrInst_p[k],&asnrOpenConfig);\r
100 if (err != asnr_NOERR) {\r
101 System_printf("*** ASNR #%d open error: %d\n", k, err);\r
102 BIOS_exit(0);\r
103 }\r
104 }\r
105 /* At this point ASNR's are open, but may need additional configuration */\r
106 \r
107 /* Here we reconfigure the ASNR */\r
108 asnrCtl.valid_bitfield = (asnr_CTL_VALID_BAND1_MAX_ATTEN |\r
109 asnr_CTL_VALID_BAND2_MAX_ATTEN |\r
110 asnr_CTL_VALID_BAND3_MAX_ATTEN);\r
111 asnrCtl.band1_max_atten = 12;\r
112 asnrCtl.band2_max_atten = 9;\r
113 asnrCtl.band3_max_atten = 6;\r
114 for (k = 0; k < sysContext.nvmics; k++) {\r
115 err = asnrControl (sysContext.asnrInst_p[k], &asnrCtl);\r
116 if (err != asnr_NOERR) {\r
117 System_printf("*** ASNR #%d control error: %d\n", k, err);\r
118 BIOS_exit(0);\r
119 }\r
120 }\r
121 \r
122 System_printf("Done with ASNR's\n");\r
123 System_flush();\r
124 \r
125 } /* sysAsnrCreate */\r
126 \r
127 /* nothing past this point */\r
128 \r