flashinit.c 2.04 KB
/*---------------------------------------------------------------------
        Copyright (C) 1998 Nintendo.
        
        File            flash.c
        Coded    by     Atushi Watanabe. Dec  1, 1998.
        Modified by     Atushi Watanabe. Apr 4, 2000.
        Comments        1M Flash ROM access functions(Ver.7.6)
   
 	$Id: flashinit.c,v 1.1.1.1 2002/10/29 08:06:43 blythe Exp $
   ---------------------------------------------------------------------*/
/**************************************************************************
 *
 *  $Revision: 1.1.1.1 $
 *  $Date: 2002/10/29 08:06:43 $
 *  $Source: 
 *
 **************************************************************************/

#include	<ultra64.h>
#include        "osint_flash.h"

u32 __osFlashID[4];

OSIoMesg	__osFlashMsg;
OSMesgQueue	__osFlashMessageQ;
OSPiHandle      __osFlashHandler;
OSMesg		__osFlashMsgBuf;
u32		__osFlashVersion;

OSPiHandle *
osFlashInit(void)
{
  u32 flash_type,flash_maker;

  osCreateMesgQueue(&__osFlashMessageQ, &__osFlashMsgBuf, 1);

  if (__osFlashHandler.baseAddress == PHYS_TO_K1(FLASH_START_ADDR))
    return(&__osFlashHandler);
  
  /* Fill basic information */
  __osFlashHandler.type = DEVICE_TYPE_FLASH;
  __osFlashHandler.baseAddress = PHYS_TO_K1(FLASH_START_ADDR);
  
  /* Get Domain parameters */
  __osFlashHandler.latency = (u8)FLASH_LATENCY;
  __osFlashHandler.pulse = (u8)FLASH_PULSE;
  __osFlashHandler.pageSize = (u8)FLASH_PAGE_SIZE;
  __osFlashHandler.relDuration = (u8)FLASH_REL_DURATION;
  __osFlashHandler.domain = PI_DOMAIN2;

  /* Fill speed and transferInfo to zero */
  __osFlashHandler.speed = 0;
  bzero((void *)&(__osFlashHandler.transferInfo),
	sizeof(__osFlashHandler.transferInfo));
	
  /* Put the __osFlashHandler onto PiTable*/
  osEPiLinkHandle(&__osFlashHandler);

  /* get flash ID */
  osFlashReadId(&flash_type, &flash_maker);
  if ((flash_maker == 0x00c2001e)||(flash_maker == 0x00c20001)
      ||(flash_maker == 0x00c20000))
    __osFlashVersion = OLD_FLASH;
  else
    __osFlashVersion = NEW_FLASH;

  return(&__osFlashHandler);

}  /* FlashInit */