#include <nitro/spi.h>
u32 PM_SetAmpGain( PMAmpGain val );
u32 PM_SetAmpGainAsync( PMAmpGain val, PMCallback callback, void* arg );
| val | Setting value that determines the amp gain. |
| callback | Callback that is called when the command finishes. |
| arg | Argument that is used when calling the callback. |
If PM_RESULT_SUCCESS, the command execution has succeeded (for synchronous functions), or the command was successfully sent to the ARM7 processor (for asynchronous functions).
If PM_RESULT_BUSY, the SPI was occupied by other processing and unable to process this function.
Sets the programmable amp gain.
The val argument is a PMAmpGain enumerator type value that can contain either one of the following values:
| val | Gain to Set |
|---|---|
PM_AMPGAIN_20 |
26.0 dB (20x) |
PM_AMPGAIN_40, PM_AMPGAIN_DEFAULT |
32.0 dB (40x) |
PM_AMPGAIN_80 |
38.0 dB (80x) |
PM_AMPGAIN_160 |
44.0 dB (160x) |
Before you use this function, initialize the PM library with the PM_Init function. (The PM_Init function has to be called only once. Also, when you call the OS_Init function, there is no need to call the PM_Init function separately because it is called from inside OS_Init.)
This function can be used from an interrupt handler. This function cannot be used in interrupt-prohibited states other than interrupt handlers.
Asynchronous Functions
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 "Async" appended to the function name.)
When an asynchronous function is called, the specified callback is called when processing on the ARM7 side finishes. The callback type PMCallback is defined by:
typedef void ( *PMCallback )( u32 result, void* arg );
This callback is called from within the PXI interrupt handler.
The callback's first argument, result, indicates the result of the command. This is either PM_RESULT_SUCCESS or PM_RESULT_BUSY. The second argument in the callback returns the value arg.
About PM_RESULT_BUSY
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 PM_RESULT_BUSY 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 PM_RESULT_BUSY. (In this case, the determination is made before notification is sent to the ARM7.)
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.)
Example
while( PM_SetAmpGain( ... ) != PM_RESULT_SUCCESS )
{
}
When using the Async version of this function, you could do this with code similar to the following.
Example
void setResult( u32 result, void* arg )
{
if ( arg )
{
*(u32*)arg = result;
}
}
while(1)
{
volatile u32 result = PM_RESULT_NONE; //A value that will not be returned
while ( PM_SetAmpGainAsync(..., setResult, (void*)&result ) != PM_RESULT_SUCCESS )
{
}
// Some other process
otherProcess();
// Wait for completion
while( result == PM_RESULT_NONE )
{
}
// Exit the loop on success
if ( result == PM_RESULT_SUCCESS )
{
break;
}
}
About PM_AMPGAIN_DEFAULT
The PM_AMPGAIN_DEFAULT setting of 40x is the default value configured by the hardware when the PM_SetAmpGain* functions have not been used; it is not necessarily the recommended setting.
Differences Between the PM_SetAmpGain* and PM_SetAmpGainLevel* Functions
In TWL mode, the codec can set the amp gain precisely to one of 120 levels, instead of 4 levels. See the PM_SetAmpGainLevel function for more information.
On NITRO hardware, this function manipulates the PMIC register PGA_GAIN. On TWL hardware it manipulates the codec.
PM_Init
PM_SetAmp*
PM_SetAmpGainLevel*
PM_GetAmpGain
2008/08/23 Stopped using PM_RESULT_ERROR and elaborated on PM_RESULT_BUSY.
2008/05/01 Added information about PM_SetAmpGainLevel*.
2006/01/25 Added the setting value PM_AMPGAIN_DEFAULT.
2005/07/07 Elaborated on the return value PM_RESULT_ERROR.
2005/06/02 Clarified the origin of the call to the callback.
2004/07/31 Initial version.
CONFIDENTIAL