Project

General

Profile

RE: Need Help for Audio MityDSP-L138F. DSP Platforms. No ... » MityDSP_DSD1791_Init.c

riyanto fisika, 08/30/2016 02:29 AM

 
1
// L138_aic3106_init.c
2
//
3

    
4
#include "L138_aic3106_init.h"
5
#include "evmomapl138_spi.h"
6
#include "evmomapl138.h"
7

    
8

    
9
//#define PINMUX_GP08_REG_0          (0)
10
//#define PINMUX_GP08_MASK_0         (0xF0000000)
11
//#define PINMUX_GP08_VAL_0          (0x80000000)
12
//#define PINMUX_GP514_REG_0         (11)
13
//#define PINMUX_GP514_MASK_0        (0x000000F0)
14
//#define PINMUX_GP514_VAL_0         (0x80000080)
15

    
16

    
17
int16_t *pingIN, *pingOUT, *pongIN, *pongOUT;
18

    
19
AIC31_data_type AIC31_data;
20

    
21
typedef struct BITVAL    // used in function prbs()
22
{
23
 unsigned int b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1;
24
 unsigned int b7:1, b8:1, b9:1, b10:1, b11:1, b12:1,b13:1;
25
 unsigned int dweebie:2; //Fills the 2 bit hole - bits 14-15
26
} bitval;
27

    
28
typedef union SHIFT_REG
29
{
30
 unsigned int regval;
31
 bitval bt;
32
} shift_reg;
33
int fb = 1;                        // feedback variable
34
shift_reg sreg = {0xFFFF};         // shift register
35

    
36
uint32_t prand_seed = 1;       // used in function prand()
37

    
38
extern void vectors(void);
39

    
40
void output_sample(int32_t out_data)
41
{
42
  AIC31_data.uint = out_data;
43
  if (poll) while (!CHKBIT(MCASP->SRCTL15, XRDY));
44
  MCASP->XBUF0 = AIC31_data.uint;
45
}
46
   
47
void output_left_sample(int16_t out_data)
48
{
49
  AIC31_data.uint = 0;
50
  AIC31_data.channel[LEFT]=out_data;
51
  if (poll) while (!CHKBIT(MCASP->SRCTL15, XRDY));
52
  MCASP->XBUF0 = AIC31_data.uint;
53
}
54

    
55

    
56
void L138_init_mcasp_poll()
57
{
58

    
59
	// globally reset McASP0
60
		MCASP->GBLCTL  = 0;
61

    
62
//		   // configure McASP0 receive registers
63
		MCASP->RMASK      = 0xFFFFFFFF;
64
		MCASP->RFMT       = 0x000080F8;
65
		MCASP->AFSRCTL    = 0x00000000;
66
		MCASP->ACLKRCTL   = 0x00000000;
67
		MCASP->AHCLKRCTL  = 0x00000000;
68
		MCASP->RTDM       = 0x00000001; // TDM timeslot 0
69
		MCASP->RINTCTL    = 0x00000000;
70
		MCASP->RCLKCHK    = 0x00000000;
71

    
72
		   // configure McASP0 transmit registers
73
	    MCASP->XMASK      = 0xFFFFFFFF;
74
//		MCASP->XFMT       = 0x000080F8;
75
		MCASP->XFMT       = 0x00018070;
76
//		MCASP->AFSXCTL    = 0x00000002;
77
		MCASP->AFSXCTL    = 0x00000112;
78
	//	MCASP->AFSXCTL    = 0x00000000;
79
//		MCASP->ACLKXCTL   = 0x00000000;
80
		MCASP->ACLKXCTL   = 0x000000A3;
81
//		MCASP->AHCLKXCTL  = 0x00000000;
82
		MCASP->AHCLKXCTL  = 0x00008004;
83
		MCASP->XTDM       = 0x00000003; // TDM timeslot 0
84
		MCASP->XINTCTL    = 0x00000000; // interrupt on transmit
85
		MCASP->XCLKCHK    = 0x00000000;
86

    
87

    
88
		   // config pin function and direction.
89
		MCASP->PFUNC      = 0;
90
	//	MCASP->PDIR       = 0x00020000;
91
		MCASP->PDIR       = 0X14008000;
92
//		MCASP->PDIR       = 0x00008000;
93

    
94

    
95
		   //
96
		MCASP->XEVTCTL    = 0x00000000;
97
		MCASP->DITCTL     = 0x00000000;
98
		MCASP->DLBCTL     = 0x00000000;
99
		MCASP->AMUTE      = 0x00000000;
100

    
101

    
102
		   // Transmitter
103
		SETBIT(MCASP->XGBLCTL, XHCLKRST);
104
		while (!CHKBIT(MCASP->XGBLCTL, XHCLKRST)) {}
105
		SETBIT(MCASP->XGBLCTL, XCLKRST);
106
	    while (!CHKBIT(MCASP->XGBLCTL, XCLKRST)) {}
107
		SETBIT(MCASP->XGBLCTL, XSRCLR); //TXSERCLRS
108
		while (!CHKBIT(MCASP->XGBLCTL, XSRCLR)) {}
109
		MCASP->XBUF0 = 0;
110

    
111
		SETBIT(MCASP->XGBLCTL, XSMRST);
112
		while (!CHKBIT(MCASP->XGBLCTL, XSMRST)) {}
113
		SETBIT(MCASP->XGBLCTL, XFRST);
114
		while (!CHKBIT(MCASP->XGBLCTL, XFRST)) {}
115
		MCASP->XBUF0 = 0;
116

    
117
		   // configure serialisers (15 for xmit, 12 for rcv)
118
	    MCASP->SRCTL15    = 0x000D;
119
		MCASP->SRCTL12    = 0x000E;
120

    
121
		MCASP->XSTAT = 0xFFFFFFFF;        // Clear all
122

    
123
	    while(!CHKBIT(MCASP->SRCTL15, XRDY)) {}
124
	    MCASP->XBUF0 = 0;
125

    
126

    
127
		   //Receiver
128
//		SETBIT(MCASP->RGBLCTL, RHCLKRST);
129
//		while (!CHKBIT(MCASP->RGBLCTL, RHCLKRST)) {}
130
//		SETBIT(MCASP->RGBLCTL, RSRCLR);
131
//		while (!CHKBIT(MCASP->RGBLCTL, RSRCLR)) {}
132
//		SETBIT(MCASP->RGBLCTL, RSMRST);
133
//		while (!CHKBIT(MCASP->RGBLCTL, RSMRST)) {}
134
//		SETBIT(MCASP->RGBLCTL, RFRST);
135
//		while (!CHKBIT(MCASP->RGBLCTL, RFRST)) {}
136
//
137
//		MCASP->RSTAT = 0x0000FFFF;        // Clear all
138
//
139
//		   // Write zero to serialiser buffers so that no underrun occurs after releasing the state machine
140
//
141
//		MCASP->RBUF12 = 0;
142

    
143
	   // wait for transmit ready and send a dummy byte.
144
}
145

    
146

    
147

    
148
void L138_initialise_poll()
149
{
150
  
151
  poll = 1;     // used in input_sample() and output_sample() functions
152

    
153
//  spi_config_t spi_config;
154

    
155

    
156
//   bsl initialisation functions
157
//  EVMOMAPL138_init();
158
//  EVMOMAPL138_initRAM();
159
//  USTIMER_init();
160

    
161
  EVMOMAPL138_lpscTransition(PSC1, DOMAIN0, LPSC_MCASP0, PSC_ENABLE);
162
  EVMOMAPL138_lpscTransition(PSC1, DOMAIN0, LPSC_GPIO, PSC_ENABLE);
163
  EVMOMAPL138_pinmuxConfig(PINMUX_MCASP_REG_0, PINMUX_MCASP_MASK_0, PINMUX_MCASP_VAL_0);
164
  EVMOMAPL138_pinmuxConfig(PINMUX_MCASP_REG_1, PINMUX_MCASP_MASK_1, PINMUX_MCASP_VAL_1);
165

    
166

    
167
  CSR = 0x0000; // disable interrupts globally while initialising
168

    
169
  L138_init_mcasp_poll();
170

    
171
  ICR = 0xFFF0; 
172
}
173

    
174
int prbs(void) 			       //gen pseudo-random sequence {-1,1}
175
{
176
  int prnseq;			 
177
  if(sreg.bt.b0)
178
	prnseq = -NOISELEVEL;		           //scaled negative noise level
179
  else
180
	prnseq = NOISELEVEL;		           //scaled positive noise level
181
  fb =(sreg.bt.b0)^(sreg.bt.b1);   //XOR bits 0,1
182
  fb^=(sreg.bt.b11)^(sreg.bt.b13); //with bits 11,13 -> fb
183
  sreg.regval<<=1;
184
  sreg.bt.b0=fb;			       //close feedback path
185
  return prnseq;			       //return noise sequence value 
186
}
187

    
188

    
189

    
190
uint32_t rand31_next()
191
{
192
  uint32_t hi, lo;
193

    
194
  lo = 16807 * (prand_seed & 0xFFFF);
195
  hi = 16807 * (prand_seed >> 16);
196

    
197
  lo += (hi & 0x7FFF) << 16;
198
  lo += hi >> 15;
199

    
200
  if (lo > 0x7FFFFFFF) lo -= 0x7FFFFFFF;
201

    
202
  return(prand_seed = (uint32_t)lo);
203
}
204

    
205
int16_t prand()
206
{
207
return ((int16_t)(rand31_next()>>18)-4096);
208
}
(1-1/2) Go to top
Add picture from clipboard (Maximum size: 1 GB)