gbpakpower.c 1.63 KB
/*---------------------------------------------------------------------
        Copyright (C) 1997, Nintendo.
        
        File            gbpakpower.c
        Coded    by     Koji Mitsunari. Oct  2, 1997.
        Modified by     Koji Mitsunari. Apr 16, 1998.
        Comments        64GB-PAK Power ON/OFF
   
        $Id: 
   ---------------------------------------------------------------------*/

/**************************************************************************
 *
 *  $Revision: 1.2 $
 *  $Date: 2003/03/25 20:42:32 $
 *  $Source: 
 *
 **************************************************************************/

#include "osint.h"
#include "controller.h"

#define	GBPAK_POWER_WAIT		120000	/* micro sec. */

#ifndef BBPLAYER
extern OSTimer		__osGbpakTimer;
extern OSMesgQueue	__osGbpakTimerQ;
extern OSMesg		__osGbpakTimerMsg;
#endif

s32
osGbpakPower(OSPfs *pfs, s32 flag) /* flag OS_GBPAK_ON or OS_GBPAK_OFF */
{
#ifdef BBPLAYER
    return PFS_ERR_DEVICE;
#else
  s32	i, ret;
  u8	temp[BLOCKSIZE];

  for ( i = 0 ; i < BLOCKSIZE ; temp[i++] = (u8)flag);
  ret =  __osContRamWrite(pfs->queue, pfs->channel, GB_POWER_ADDR, temp, 0);
  if (ret == PFS_ERR_NEW_PACK) {
    ret = osGbpakInit(pfs->queue, pfs, pfs->channel);
    if (ret == 0) {
      ret =  __osContRamWrite(pfs->queue, pfs->channel, GB_POWER_ADDR, temp, 0);
      if (ret == PFS_ERR_NEW_PACK) {
	ret = PFS_ERR_CONTRFAIL;
      }
    }
  }
  if (flag != OS_GBPAK_POWER_OFF) {
    osSetTimer(&__osGbpakTimer, OS_USEC_TO_CYCLES(GBPAK_POWER_WAIT), 0, 
	       &__osGbpakTimerQ, &__osGbpakTimerMsg);
    (void)osRecvMesg(&__osGbpakTimerQ, NULL, OS_MESG_BLOCK);
  }

  return(ret);
#endif
}