/*---------------------------------------------------------------------------*
  Project:  NitroSDK - WM - demos - wireless_shared
  File:     wc.h

  Copyright 2003,2004 Nintendo.  All rights reserved.

  These coded instructions, statements, and computer programs contain
  proprietary information of Nintendo of America Inc. and/or Nintendo
  Company Ltd., and are protected by Federal copyright law.  They may
  not be disclosed to third parties or copied or duplicated in any form,
  in whole or in part, without the prior written consent of Nintendo.

  $Log: wc.h,v $
  Revision 1.3  2004/10/29 01:54:47  terui
  Made revisions so that the channel used when scanning the child device is the channel to which WcInit was passed

  Revision 1.2  2004/10/28 11:20:16  yosizaki
  merge with wbt-1.

  Revision 1.1  2004/10/22 11:04:14  terui
  Cut out the wc module in the shared region

  $NoKeywords: $
 *---------------------------------------------------------------------------*/

#ifndef DEMOS_WIRELESS_SHARED_WC_H_
#define DEMOS_WIRELESS_SHARED_WC_H_

#ifdef  __cplusplus
extern "C" {
#endif

/*===========================================================================*/

#include    <nitro/types.h>
#include    <nitro/wm.h>


/*---------------------------------------------------------------------------*
    Definition of constants
 *---------------------------------------------------------------------------*/
#define     WC_DMA_NO                   2   // Make sure that there is no overlap with the DMA numbers for GX, etc.
#define     WC_DEFAULT_PORT             4   // The port number  (4 - 7)
#define     WC_DEFAULT_PORT_PRIO        2   // The port priority ( 0 - 3 )
#define     WC_DS_PORT_NUMBER           12  // Port number for data sharing ( 12 - 15 )


/*---------------------------------------------------------------------------*
    Definition of macros
 *---------------------------------------------------------------------------*/
// For 32-byte alignment
#define     WC_ROUNDUP_32B( x ) ( ( x + 31 ) & 0xffffffe0 )


/*---------------------------------------------------------------------------*
    Definition of structures
 *---------------------------------------------------------------------------*/
typedef enum WCStatus
{
    WC_STATUS_READY = 0 ,   // Initialization state
    WC_STATUS_ERROR ,       // Unrecoverable error state
    WC_STATUS_BUSY ,        // Busy state when in the middle of a state transition
    WC_STATUS_PARENT ,      // Connection completed state as parent device
    WC_STATUS_CHILD ,       // Connection completed state as child device
    WC_STATUS_MAX
    
} WCStatus;

// Definition of the callback function type for single device MP mode
typedef void (*WCCallbackFunc)( u16 aid , u16* data , u16 length );

// Definition of the callback function type for block transmission mode
// The WMCallback pointer is currently passed at the following points in time:
// - At WM_StartMP completion
// - At WcSetParentData and WcSetChildData completion
// - At WM_Reset completion
typedef void (*WCBlockTransferCallbackFunc)( WMCallback *arg );


/*---------------------------------------------------------------------------*
    Definition of functions
 *---------------------------------------------------------------------------*/
void        WcInit( const WMParentParam* pp , BOOL dsFlag , BOOL btFlag , u16 framePeriod );  // Each type of initialization. Mainly memory allocation.
void        WcStartParent( void );      // Starts the connection as the parent device
void        WcStartChild( void );       // Starts the connection as the child device
void        WcEnd( void );              // Starts the transition to the initialized state
WCStatus    WcGetStatus( void );        // Gets the internal state of the WCStatus type
u16         WcGetAid( void );           // Gets the AID

// Configure the callback called when MO communications data is received.
void        WcSetMpReceiveCallback( WCCallbackFunc cb );
// Configure the callback called when configuring block transmission mode
void        WcSetBlockTransferCallback( WCBlockTransferCallbackFunc cb );
// Set send data as the parent device
void        WcSetParentData( const void* buf , u16 size );
// Set send data as the child device
void        WcSetChildData( const void* buf , u16 size );

// After the connection is complete, proceed to data-sharing communications. Call once per game frame.
BOOL        WcStepDataSharing( const void* send , u16* bitmap );
// Gets the pointer to the terminal data from the reception data
u8*         WcGetSharedDataAddress( u16 aid );


/*===========================================================================*/

#ifdef  __cplusplus
}       /* extern "C" */
#endif

#endif  /* DEMOS_WIRELESS_SHARED_WC_H_ */

/*---------------------------------------------------------------------------*
  End of file
 *---------------------------------------------------------------------------*/
