Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/common_drivers/dac_buffer/dac_buffer.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file dac_buffer.c
3 * @brief Implementation of DAC LUT driver.
4 * @author Istvan Csomortani ([email protected])
5 ********************************************************************************
6 * Copyright 2014-2016(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *******************************************************************************/
39 #include "dac_buffer.h"
40
41 /******************************************************************************/
42 /******************************* Constant definitions *************************/
43 /******************************************************************************/
44
45 /* Sine Look Up Tables */
46 const uint16_t sine_lut_1[128] = {
47 0x0000, 0x0640, 0x0C80, 0x12C0, 0x18F0, 0x1F10, 0x2520, 0x2B10,
48 0x30F0, 0x36B0, 0x3C50, 0x41C0, 0x4710, 0x4C30, 0x5120, 0x55F0,
49 0x5A70, 0x5ED0, 0x62E0, 0x66C0, 0x6A60, 0x6DC0, 0x70D0, 0x73A0,
50 0x7630, 0x7870, 0x7A70, 0x7C20, 0x7D80, 0x7E90, 0x7F50, 0x7FD0,
51 0x7FF0, 0x7FD0, 0x7F50, 0x7E90, 0x7D80, 0x7C20, 0x7A70, 0x7870,
52 0x7630, 0x73A0, 0x70D0, 0x6DC0, 0x6A60, 0x66C0, 0x62E0, 0x5ED0,
53 0x5A70, 0x55F0, 0x5120, 0x4C30, 0x4710, 0x41C0, 0x3C50, 0x36B0,
54 0x30F0, 0x2B10, 0x2520, 0x1F10, 0x18F0, 0x12C0, 0x0C80, 0x0640,
55 0x0000, 0xF9B0, 0xF370, 0xED30, 0xE700, 0xE0E0, 0xDAD0, 0xD4E0,
56 0xCF00, 0xC940, 0xC3A0, 0xBE30, 0xB8E0, 0xB3C0, 0xAED0, 0xAA00,
57 0xA580, 0xA120, 0x9D10, 0x9930, 0x9590, 0x9230, 0x8F20, 0x8C50,
58 0x89C0, 0x8780, 0x8580, 0x83D0, 0x8270, 0x8160, 0x80A0, 0x8020,
59 0x8000, 0x8020, 0x80A0, 0x8160, 0x8270, 0x83D0, 0x8580, 0x8780,
60 0x89C0, 0x8C50, 0x8F20, 0x9230, 0x9590, 0x9930, 0x9D10, 0xA120,
61 0xA580, 0xAA00, 0xAED0, 0xB3C0, 0xB8E0, 0xBE30, 0xC3A0, 0xC940,
62 0xCF00, 0xD4E0, 0xDAD0, 0xE0E0, 0xE700, 0xED30, 0xF370, 0xF9B0
63 };
64
65 /* 90 degree offset from sine_lut_1 */
66 const uint16_t sine_lut_2[128] = {
67 0x7FF0, 0x7FD0, 0x7F50, 0x7E90, 0x7D80, 0x7C20, 0x7A70, 0x7870,
68 0x7630, 0x73A0, 0x70D0, 0x6DC0, 0x6A60, 0x66C0, 0x62E0, 0x5ED0,
69 0x5A70, 0x55F0, 0x5120, 0x4C30, 0x4710, 0x41C0, 0x3C50, 0x36B0,
70 0x30F0, 0x2B10, 0x2520, 0x1F10, 0x18F0, 0x12C0, 0x0C80, 0x0640,
71 0x0000, 0xF9B0, 0xF370, 0xED30, 0xE700, 0xE0E0, 0xDAD0, 0xD4E0,
72 0xCF00, 0xC940, 0xC3A0, 0xBE30, 0xB8E0, 0xB3C0, 0xAED0, 0xAA00,
73 0xA580, 0xA120, 0x9D10, 0x9930, 0x9590, 0x9230, 0x8F20, 0x8C50,
74 0x89C0, 0x8780, 0x8580, 0x83D0, 0x8270, 0x8160, 0x80A0, 0x8020,
75 0x8000, 0x8020, 0x80A0, 0x8160, 0x8270, 0x83D0, 0x8580, 0x8780,
76 0x89C0, 0x8C50, 0x8F20, 0x9230, 0x9590, 0x9930, 0x9D10, 0xA120,
77 0xA580, 0xAA00, 0xAED0, 0xB3C0, 0xB8E0, 0xBE30, 0xC3A0, 0xC940,
78 0xCF00, 0xD4E0, 0xDAD0, 0xE0E0, 0xE700, 0xED30, 0xF370, 0xF9B0,
79 0x0000, 0x0640, 0x0C80, 0x12C0, 0x18F0, 0x1F10, 0x2520, 0x2B10,
80 0x30F0, 0x36B0, 0x3C50, 0x41C0, 0x4710, 0x4C30, 0x5120, 0x55F0,
81 0x5A70, 0x5ED0, 0x62E0, 0x66C0, 0x6A60, 0x6DC0, 0x70D0, 0x73A0,
82 0x7630, 0x7870, 0x7A70, 0x7C20, 0x7D80, 0x7E90, 0x7F50, 0x7FD0
83 };
84
85 /******************************************************************************/
86 /************************ Functions Definitions *******************************/
87 /******************************************************************************/
88
89 uint32_t dac_buffer_load(dac_core core, uint32_t start_address) {
90
91 uint32_t no_of_samples;
92 uint32_t index;
93 uint32_t index_mem = 0;
94
95 no_of_samples = sizeof(sine_lut_1) / sizeof(typeof(sine_lut_1[0]));
96
97 for (index = 0; index < no_of_samples; index ++) {
98 switch (core.no_of_channels) {
99 case 1:
100 ad_reg_write_16(start_address + index_mem * 2, sine_lut_1[index]);
101 index_mem += 1;
102 break;
103 case 2:
104 ad_reg_write_16(start_address + (index_mem + 0) * 2, sine_lut_1[index]);
105 ad_reg_write_16(start_address + (index_mem + 1) * 2, sine_lut_2[index]);
106 index_mem += 2;
107 break;
108 case 4:
109 ad_reg_write_16(start_address + (index_mem + 0) * 2, sine_lut_1[index]);
110 ad_reg_write_16(start_address + (index_mem + 1) * 2, sine_lut_2[index]);
111 ad_reg_write_16(start_address + (index_mem + 2) * 2, sine_lut_1[index]);
112 ad_reg_write_16(start_address + (index_mem + 3) * 2, sine_lut_2[index]);
113 index_mem += 4;
114 break;
115 default:
116 ad_printf("Unsupported mode.\n\r");
117 return -1;
118 }
119 }
120
121 ad_dcache_flush();
122
123 return no_of_samples;
124 }
125