# PM_ForceToPowerOff*

## Syntax

      #include <nitro/spi.h>

      u32 PM_ForceToPowerOff( void );

      u32 PM_ForceToPowerOffAsync( PMCallback callback, void* arg );

## Arguments

`PM_ForceToPowerOff`
No arguments.

`PM_ForceToPowerOffAsync`

callback | Callback that is called when the command finishes.
arg | Argument that is used when calling the callback.

## Return Values

`PM_ForceToPowerOff`
For compatibility with past versions, this function has a `u32`-type return value. However, because this function internally retries until it succeeds and then enters a loop, control does not actually return from this function. Accordingly, there is no meaning in getting or comparing its return value with anything.

`PM_ForceToPowerOffAsync`
In asynchronous versions, this function returns `PM_RESULT_SUCCESS` to indicate that it successfully sent the command to the ARM7. However, because the power turns OFF, you cannot actually do anything with the `PM_RESULT_SUCCESS` return value after it is returned.

A return value of `PM_RESULT_BUSY` indicates that the SPI was occupied by other processing and unable to process this function.

## Description

Forces the power OFF.

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.)

The synchronous version of this function continues to retry internally until it succeeds. Once it has succeeded, it immediately enters a loop, so control does not return from the function. Even though it does not return, this function has a `u32`-type return value. This is only for compatibility with past versions; the value itself has no meaning, and because this function does not return, it cannot actually be obtained.

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 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.

However, when processes with the power OFF in the ARM7 succeed, processes after that cannot be carried out. The callback function is executed only when the process fails.

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 called from an interrupt handler. It can also be called from interrupt-prohibited states other than interrupt handlers.

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.)

The synchronous version of this function takes this into account by retrying internally until it succeeds, but the asynchronous version returns `PM_RESULT_BUSY`. Accordingly, if you want to make certain that the asynchronous version of this function succeeds, make it retry when it returns BUSY.

## Internal Operation

Operates the `PMIC_CTL` value of the PMIC register.

## See Also

`PM_Init`

## Revision History

2008/08/23 Elaborated on `PM_RESULT_BUSY`.
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