# PM_GetAmpGainLevel

## Syntax

      #include <twl/spi.h>

      u32 PM_GetAmpGainLevel( u8* levelBuf );

## Arguments

levelBuf | Buffer to store the obtained results for settings values that determine the amp gain.

## Return Values

If `PM_RESULT_SUCCESS`, the command was run successfully.

If `PM_RESULT_BUSY`, the SPI was occupied by other processing and unable to process this function.

## Description

Gets the current setting for the programmable amp gain.

It saves a `u8` value in levelBuf. The values it can obtain are in the range of 0 to 119 (120 levels).

Value Stored in levelBuf | Gain
--- | ---
0 | 10.5 dB
1 | 11.0 dB
2 | 11.5 dB
: | :
n | 10.5 + (n x 0.5) dB
: | :
119 | 70.0 dB

This function uses PXI to send a command to execute the operation in question on the ARM7 processor. Once it receives that command, the ARM7 executes it by manipulating the PMIC.

Note

Before you use this function, use the `PM_Init` function to initialize the PM library. (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`.)

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_GetAmpGainLevel( ... ) != PM_RESULT_SUCCESS )
> {
> }`

Differences Between the `PM_GetAmpGain` and `PM_GetAmpGainLevel` Functions

There are two types of functions to get the gain settings: `PM_GetAmpGain` and `PM_GetAmpGainLevel` (this function). The former has existed since the old Nintendo DS and can get four gain levels. (Four gain levels can be set, as well.) The latter is explained in this reference page; it is new, has been added for the TWL system, and can get 120 gain levels.

The `PM_GetAmpGain` function can get four levels and is usable in any mode.

The `PM_GetAmpGainLevel` function can get 120 levels and is usable only in TWL HYBRID and TWL LIMITED mode. The CODEC mode decides whether 120 levels are actually configured internally. The codec will be configured with 120 levels when it is running in TWL mode (this should always be TWL mode).

If 4 levels have been configured internally, this function will obtain a setting value that corresponds to 120 levels. On the other hand, if 120 levels have been configured internally and the `PM_GetAmpGain` function attempts to get a 4-level value, the 120 levels will be divided into 4 sections, from which an approximate 4-level value will be returned.

The following table shows the 120-level values obtained from the `PM_GetAmpGainLevel` function when 4 levels are configured internally.

Configured Value | Gain (120 Levels)
--- | ---
`PM_AMPGAIN_20` | 31 (26.0 dB)
`PM_AMPGAIN_40` | 43 (32.0 dB)
`PM_AMPGAIN_80` | 55 (38.0 dB)
`PM_AMPGAIN_160` | 67 (44.0 dB)

The values 31, 43, 55, and 67 are given the constant definitions `PM_AMPGAIN_LEVEL_DS0`, `PM_AMPGAIN_LEVEL_DS1`, `PM_AMPGAIN_LEVEL_DS2`, and `PM_AMPGAIN_LEVEL_DS3`, respectively.

## Internal Operation

On NITRO hardware, reads the value of the PMIC register PGA_GAIN. On TWL hardware, reads the codec value.

## See Also

`PM_Init`
`PM_SetAmpGainLevel*`
`PM_GetAmpGain`

## Revision History

2008/08/23 Elaborated on `PM_RESULT_BUSY`.
2008/05/01 Branched from `PM_GetAmpGain`.

CONFIDENTIAL