# PM_AppendPreSleepCallback

## C Specification

      #include <nitro/spi.h>

      void PM_AppendPreSleepCallback( PMSleepCallbackInfo* info );

## Description

Registers callback when switching to sleep mode. Registered at top of the callback list.

Each callback can register multiple. Callback is defined by the void type function that gets one void* type argument as

    typedef void (*PMSleepCallback)( void* );

When registering, specify the pointer to callback and argument information (as well as the structure that includes information for constructing the list). This structure is defined as follows.

    typedef struct PMiSleepCallbackInfo PMSleepCallbackInfo;
    struct PMiSleepCallbackInfo
    {
        PMSleepCallback callback;
        void* arg;
        PMSleepCallbackInfo* next;
    };

The `PM_SetSleepCallback()` function for registering callback to callback information is also provided.

Callbacks are executed in order from the top of the list.

In callback registration when switching to sleep mode, `PM_AppendPreSleepCallback()` is registered at the top of the list and `PM_PrependPreSleepCallback()` is registered at the end of the list.

In callback registration when returning from sleep mode, `PM_AppendPostSleepCallback()` is registered at the top of the list and `PM_PrependPostSleepCallback()` is registered at the end of the list.

(Example)

    //---- sleep callback info
    PMSleepCallbackinfo c1info;
    PMSleepCallbackinfo c2info;

    //---- Callback before sleep mode
    void myCallback1( void* )
    {
        OS_Printf( "go to sleep mode.\n" );
    }

    //---- Callback after sleep mode
    void myCallback2( void* )
    {
        OS_Printf( "now return from sleep mode.\n" );
    }

    //---- Main
    void NitroMain( void )
    {
        :
        //---- set callback to callback info
        PM_SetSleepCallback( &c1info, myCallback1, NULL );
        PM_SetSleepCallback( &c2info, myCallback2, NULL );

        //---- set pre-callback for sleep mode
        PM_AppendPreSleepCallback( &c1info );

        //---- set post-callback for sleep mode
        PM_AppendPostSleepCallback( &c2info );

        //---- go to sleep mode
        PM_GoSleepMode(...);
        :
    }

## See Also

`PM_Init`, `PM_GoSleepMode`, `PM_AppendPreSleepCallback`, `PM_PrependPreSleepCallback`, `PM_AppendPostSleepCallback`, `PM_PrependPostSleepCallback`, `PM_DeletePreSleepCallback`, `PM_DeletePostSleepCallback`, `PM_SetSleepCallback`

## Revision History

10/06/2004 Initial version