1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<HTML>
3<HEAD>
4<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
5<META name="GENERATOR" content="IBM WebSphere Studio Homepage Builder Version 7.0.1.0 for Windows">
6<META http-equiv="Content-Style-Type" content="text/css">
7<TITLE>PM_SetAmpGainLevel*</TITLE>
8<LINK rel="stylesheet" href="../../css/nitro.css" type="text/css">
9</HEAD>
10<BODY>
11<H1 align="left">PM_SetAmpGainLevel* <IMG src="../../image/TWL.gif" width="24" height="12" border="0" align="middle"></H1>
12<H2>Syntax</H2>
13<DL>
14  <DD>
15  <PRE><CODE>#include &lt;twl/spi.h&gt;</CODE></PRE>
16  <PRE><CODE>u32 PM_SetAmpGainLevel( u8 level );
17
18u32 PM_SetAmpGainLevelAsync( u8 level, PMCallback callback, void* arg );
19  </CODE></PRE>
20</DL>
21<H2>Arguments</H2>
22<TABLE border="1" width="100%">
23  <TBODY>
24    <TR>
25<TD width="13%"><SPAN class="argument">level</SPAN></TD>
26<TD width="87%">Setting value that determines the amp gain.</TD>
27    </TR>
28    <TR>
29<TD><SPAN class="argument">callback</SPAN></TD>
30<TD>Callback that is called when the command finishes.</TD>
31    </TR>
32    <TR>
33<TD><SPAN class="argument">arg</SPAN></TD>
34<TD>Argument that is used when calling the callback.</TD>
35    </TR>
36  </TBODY>
37</TABLE>
38<H2>Return Values</H2>
39<P>If <CODE>PM_RESULT_SUCCESS</CODE>, the command execution has succeeded (for synchronous functions), or the command was successfully sent to the ARM7 processor (for asynchronous functions).</P>
40<P>If <CODE>PM_RESULT_BUSY</CODE>, the SPI was occupied by other processing and unable to process this function.</P>
41<H2>Description</H2>
42<P>Sets the gain of the programmable amp gain. This function can only be used when the operating mode is TWL mode.</P>
43<P>The <SPAN class="argument">level</SPAN> argument is a <CODE>u8</CODE> value; specify a value in the range of 0 to 119.</P>
44<P>Before you use this function, initialize the PM library with the <A href="PM_Init.html"><CODE>PM_Init</CODE></A> function. (The <code>PM_Init</code> function has to be called only once. Also, when you call the <a href="../../os/init/OS_Init.html"><code>OS_Init</code></a> function, there is no need to call the <a href="PM_Init.html"><code>PM_Init</code></a> function separately because it is called from inside <code>OS_Init</code>.)
45<P><B>Differences Between the <A href="PM_SetAmpGain.html"><CODE>PM_SetAmpGain*</CODE></A> and <CODE>PM_SetAmpGainLevel*</CODE> Functions</B>
46
47<P>There are two types of setter functions: <A href="PM_SetAmpGain.html"><CODE>PM_SetAmpGain*</CODE></A> and <CODE>PM_SetAmpGainLevel*</CODE>. The former has existed since the old Nintendo DS and can specify four gain levels. The latter is explained in this reference page; it is new, has been added for the TWL system, and can set 120 gain levels.
48<P>The <CODE><A href="PM_SetAmpGain.html">PM_SetAmpGain*</A></CODE> functions can specify four levels and are usable in any mode. The specified value will always be set unchanged.
49
50<P>The <CODE>PM_SetAmpGainLevel*</CODE> functions can specify 120 levels and are usable only in TWL HYBRID and TWL LIMITED mode. The CODEC mode decides whether the value is actually configured as one of 120 levels, as specified. A 120-level setting will be applied as specified when the CODEC is running in TWL mode (in this case the operation mode should always be TWL mode). However, at all other times, values specified for 120 levels will be averaged to 4 levels. These four levels conform to the four levels set with the <CODE><A href="PM_SetAmpGain.html">PM_SetAmpGain</A></CODE> function.
51
52<P><B>Value of <SPAN class="argument">level</SPAN> and the Gain to Set</B>
53
54<P>The value of the <SPAN class="argument">level</SPAN> argument and the actual amp gain that is set are shown below.
55
56<BLOCKQUOTE>
57<P>When the codec is in TWL mode:</P>
58<TABLE border="1">
59  <TBODY>
60    <TR>
61<TH width="254"><SPAN class="argument">level</SPAN></TH>
62<TH width="725">Gain to Set</TH>
63    </TR>
64    <TR>
65      <TD width="254"> 0</TD>
66<TD width="725"> 10.5 dB</TD>
67    </TR>
68    <TR>
69      <TD width="254"> 1</TD>
70<TD width="725"> 11.0 dB</TD>
71    </TR>
72    <TR>
73      <TD width="254"> 2</TD>
74<TD width="725"> 11.5 dB</TD>
75    </TR>
76    <TR>
77      <TD width="254"> :</TD>
78      <TD width="725"> :</TD>
79    </TR>
80    <TR>
81<TD> n</TD>
82<TD>10.5 + (<I>n</I> x 0.5) dB</TD>
83    </TR>
84    <TR>
85      <TD> :</TD>
86      <TD> :</TD>
87    </TR>
88    <TR>
89      <TD width="254"> 119</TD>
90<TD width="725"> 70.0 dB</TD>
91    </TR>
92  </TBODY>
93</TABLE>
94</BLOCKQUOTE>
95<BLOCKQUOTE>
96<P>When the codec is in DS mode:</P>
97<TABLE border="1">
98  <TBODY>
99    <TR>
100<TH width="249"><SPAN class="argument">level</SPAN></TH>
101<TH width="730">Gain to Set</TH>
102    </TR>
103    <TR>
104      <TD width="249"> 0 ~ 36</TD>
105<TD width="730"> 26.0 dB (equivalent to 31 in the 120-level notation)</TD>
106    </TR>
107    <TR>
108      <TD width="249"> 37 ~ 48</TD>
109<TD width="730"> 32.0 dB (equivalent to 43 in the 120-level notation)</TD>
110    </TR>
111    <TR>
112      <TD width="249"> 49 ~ 60</TD>
113<TD width="730"> 38.0 dB (equivalent to 55 in the 120-level notation)</TD>
114    </TR>
115    <TR>
116      <TD width="249"> 61 ~ 119</TD>
117<TD width="730"> 44.0 dB (equivalent to 67 in the 120-level notation)</TD>
118    </TR>
119  </TBODY>
120</TABLE>
121</BLOCKQUOTE>
122<P> <B>Asynchronous Functions</B></P>
123<P>This function uses PXI to send the command that performs the corresponding operation in the ARM7 processor. The ARM7 side that receives that command is executed by operating the PMIC. Therefore, this function may not operate instantly after you call it. A synchronous function that waits for the operation to finish, as well as an asynchronous function that only sends commands to the ARM7, are provided. Use either of the functions depending on your operational requirements. (The asynchronous function has &quot;Async&quot; appended to the function name.))</P>
124<P>When an asynchronous function is called, the specified <SPAN class="argument">callback</SPAN> is called when processing on the ARM7 side finishes. The callback type <CODE>PMCallback</CODE> is defined by: </P>
125<BLOCKQUOTE> <CODE><code>typedef void ( *PMCallback )( u32 result, void* arg )</code>;</CODE></BLOCKQUOTE>
126<P> This callback is called from within the PXI interrupt handler.</P>
127<P>The callback's first argument, <SPAN class="argument">result</SPAN>, indicates the result of the command. This is either <code>PM_RESULT_SUCCESS</code> or <code>PM_RESULT_BUSY</code>. The second argument in the callback returns the value <SPAN class="argument">arg</SPAN>.</P>
128<P> <B>About <CODE>PM_RESULT_BUSY</CODE></B></P>
129<P>The SPI is used for various other processes besides power management. If you call this function while another process is using it, this function sends a command to the ARM7; there, the SPI is determined to be BUSY, and <CODE>PM_RESULT_BUSY</CODE> is notified to the ARM9 without actually processing this function. Likewise, if you call this function while another PM process is running, that fact is determined on the ARM9 side and this function returns <CODE>PM_RESULT_BUSY</CODE>. (In this case, the determination is made before notification is sent to the ARM7.)</P>
130<P>Accordingly, if you want to make certain that this function will succeed, make it loop until it succeeds as shown below. (This example does not take into account mistakes such as wrong arguments.)</P>
131<BLOCKQUOTE style="background-color:#ffffcc"><B>Example</B><BR> <CODE>while( PM_SetAmpGainLevel( ... ) != PM_RESULT_SUCCESS )<BR> {<BR> }</CODE></BLOCKQUOTE>
132<P>When using the <CODE>Async</CODE> version of this function, you could do this with code similar to the following.</P>
133<BLOCKQUOTE style="background-color:#ffffcc"><B>Example:</B><BR>
134<PRE>
135void setResult( u32 result, void* arg )
136{
137  if ( arg )
138  {
139    *(u32*)arg = result;
140  }
141}
142
143while(1)
144{
145  volatile u32 result = PM_RESULT_NONE; //A value that will not be returned
146
147  while ( PM_SetAmpGainLevelAsync(..., setResult, (void*)&amp;result ) != PM_RESULT_SUCCESS )
148  {
149  }
150
151  // Some other process
152  otherProcess();
153
154  // Wait for completion
155  while( result == PM_RESULT_NONE )
156  {
157  }
158
159  // Exit the loop on success
160  if ( result == PM_RESULT_SUCCESS )
161  {
162    break;
163  }
164}</PRE></BLOCKQUOTE>
165<H2>Internal Operation</H2>
166<P>On NITRO hardware, this function manipulates the PMIC register PGA_GAIN. On TWL hardware it manipulates the codec.</P>
167<H2>See Also</H2>
168<P><A href="PM_Init.html"><CODE>PM_Init</CODE></A><BR> <A href="PM_SetAmp.html"><CODE>PM_SetAmp*</CODE></A><BR> <A href="PM_SetAmpGain.html"><CODE>PM_SetAmpGain*</CODE></A><BR> <A href="PM_GetAmpGainLevel.html"><CODE>PM_GetAmpGainLevel</CODE></A></P>
169<H2>Revision History</H2>
170<P>2008/05/01 Initial version. Branched off from the <CODE>PM_SetAmpGain*</CODE> functions.</P>
171<hr><p>CONFIDENTIAL</p></body>
172</HTML>