;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  HSHalTypes
;
;  This file has the type definitions for Handspring's HAL
;
;  Note: This relies on basic types defines in "SystemTypes"
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


typedef struct "HalOldCallsType"
>	VoidPtr			"cardInstalledIrqHandlerP"
>	VoidPtr			"lidOpenCloseIrqHandlerP"
typeend


typedef struct "HalCardInfoType"
>	Boolean			"skipReset"
>	Boolean			"hwInstalled"
>	UInt32			"installResetTicks"
>	Boolean			"debouncing"
>	UInt32			"installDebounceTicks"
>	UInt32			"installGiveUpTicks"
>	UInt32			"param"
>	VoidPtr			"intHandlerP"
>	VoidPtr			"pwrHandlerP"
>	Boolean			"recheckCardStatus"
>	Boolean			"swShutoffCard"
>	Boolean			"skippedCardWake"
>	Boolean			"cardInstallLock"
>	Boolean			"cardInstallRequest"
>	Boolean			"forcePeriodicCheck"
>	VoidPtr			"chargeStatusCallbackP"
typeend


typedef struct "HalchargeIndicatorType"
>	UInt16			"intervalRef"
>	UInt16			"indicatorIndex"
>	UInt8			"portDExtPowerBit"
>	UInt8			"_pad" \-
>	VoidPtr 		"seqLow"
>	VoidPtr 		"seqCharging"
>	VoidPtr 		"seqFull"
typeend


typedef struct "HalLibInterfacesType"
>	VoidPtr 		"phnHalControlInterfaceP"
>	VoidPtr 		"phnHalSystemInterfaceP"
>	VoidPtr 		"psaInterfaceP"
typeend

;;;;;;;;;;;;;;;;;
;; HalPeriodic ;;
;;;;;;;;;;;;;;;;;

typedef struct "HalPeriodicInfoType"
>	VoidPtr			"handlerP"
>	UInt32			"param"
>	Boolean			"alreadyCalled"
>	UInt8			"_filler0" \-
>	VoidPtr			"nextP"
typeend
typedef HalPeriodicInfoType @"HalPeriodicInfoPtr"


;;;;;;;;;;;;;;;;;;
;; HalIndicator ;;
;;;;;;;;;;;;;;;;;;

typedef struct "HalIndicatorSequence"
>	UInt16						"delay"
>	Uint16						"cap"
typeend

typedef struct "HalIndicatorGarbageType"
>	VoidPtr						"nextP"
>	HalIndicatorSequence@		"sequenceP"
typeend

typedef struct "HalIndicatorPurposeType"
>	HalIndicatorSequence@		"sequenceP"
>	UInt8						"repeat"
>	UInt8						"_filler0" \-
typeend

typedef struct "HalIndicatorCapDataType"
>	UInt8@						"portP"
>	UInt8						"mask"
>	UInt8						"load"
typeend

typedef struct "HalIndicatorInfoType"
>	UInt16@						"cap"
>	UInt16						"timer"
>	UInt16						"sequencePos"
>	HalIndicatorPurposeType		"purposeInfo"[5]
>	HalIndicatorCapDataType		"capData"[2]
typeend


typedef struct "HalIndicatorDataType"
>	UInt16						"indicatorCount"
>	UInt16						"nextTrigger"
>	Boolean						"shutdown"
>	UInt8						"_reserved" \-
>	UInt32						"disabledPurposeBits"
>	HalIndicatorGarbageType@	"garbageP"
>	HalIndicatorInfoType		"indicatorInfo"[2]
typeend
typedef HalIndicatorDataType @"HalIndicatorDataPtr"

;;;;;;;;;;;;;;;;;
;; HalInterval ;;
;;;;;;;;;;;;;;;;;

typedef struct "HalIntervalTimerType"
>	Int32			"cumulativeTime"
>	UInt16			"trigger"
>	UInt32			"userParam"
>	VoidPtr			"callbackP"
typeend
typedef HalIntervalTimerType  @"HalIntervalTimerPtr"


typedef struct "HalIntervalDataType"
>	VoidPtr			"oldHwrDisplayAttributesP"
>	UInt16			"savedTimer2Control"
>	UInt16			"savedTimer2Counter"
>	UInt16			"allocBits"
>	UInt16			"callbackSetTime"
>	HalIntervalTimerType	"timerInfo"[$10];
>	UInt32			"stackGuard"
>	UInt8			"stack"[$400] \-
typeend
typedef HalIntervalDataType @"HalIntervalDataPtr"


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;          HalGlobals           ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

typedef struct "HalGlobalsType"
>	Boolean			"lastDockInputState"
>	UInt8	  		"portDExtPowerBit"
>	UInt16	  		"lcdRefreshRateAdj"
>	UInt8	  		"cardRuntimeIntEnable"
>	UInt8	  		"filler_1" \-
>	HalOldCallsType 	"oldCalls"
>	HalCardInfoType		"cardInfo"
>	HalLibInterfacesType	"libInterfaces"
>	UInt32 			"ser2ISPData"
>	VoidPtr			"systemTickAuxHandlerP"
>	HalPeriodicInfoPtr	"periodicInfos"[8]
>	HalPeriodicInfoPtr	"periodicFreeListP"
>	UInt16			"periodicIntBits"
>	HalIndicatorDataPtr	"indicatorDataP"
>	HalIntervalDataPtr	"intervalDataP"
>	UInt16			"lidClosedAutoOffSecs"
>	VoidPtr			"irq4StackP"
>	Boolean 		"usingIrq7Stack"
>	Boolean			"dontUnmaskLowbat"
>	VoidPtr			"irq7StackP"
>	Boolean 		"sleepLock"
>	Boolean			"sleepRequest"
>	Boolean			"sleepEmergency"
>	Boolean			"sleepUntilReset"
>	VoidPtr			"kbdLayoutDB"
>	UInt16			"muteSounds"
>	UInt16			"prevTimerTickMuteSounds"
typeend

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;          BatGlobals           ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


typedef struct "HwrBatGlobalsLevelHistoryArray"
	> UInt32 "ticks"
	> UInt16 "abs"
	typeend

typedef struct "HwrBatGlobalsLevelHistoryType"
	> UInt8					"cursor"
	> UInt8					"lastResult"
	> UInt16				"lastFullAbs"
	> HwrBatGlobalsLevelHistoryArray	"arr"[#4]
	typeend

typedef struct "HwrBatGlobalsAnalogHistoryType"
	> UInt16				"len"
	> UInt8					"arr"[#4]
	> UInt16				"union_fill"[#11] \-
	typeend


typedef struct "HwrBatGlobalsChargeIndicatorType"
	> UInt16  "intervalRef"
	> UInt16  "indicatorIndex"
	> UInt16  "flags"
	> UInt16  "extPwrTimer"
	> UInt16  "extPwrDelay"
	> MemPtr  "seqLow"
	> MemPtr  "seqCharging"
	> MemPtr  "seqFull"
	typeend

typedef struct "HwrBatGlobalsHeadType"
	> UInt32					"mVoltsFullScale"
	> Int16						"powerLoad"
	> UInt16					"loadDeviceBits"
	> UInt16					"loadTable"[#16]
	> UInt16					"batteryMVolts"
	> Boolean					"jamAverages"
	> Boolean					"debugPrint"
	> Boolean					"historyValid"
	> Boolean					"filler"
	typeend

typedef struct "HwrBatGlobalsTailType"
	> UInt16					"resetAvgSteps"
	> UInt32					"shutdownTicks"
	> UInt16					"battCheckTimer"
	> HwrBatGlobalsChargeIndicatorType 		"chargeIndicator"
	typeend

;; This type shows 'analog' of the chargeHistory union
typedef struct "HwrBatGlobalsAnalogType"
	> HwrBatGlobalsHeadType			"Head"	
	> HwrBatGlobalsAnalogHistoryType	"chargeHistory"
	> HwrBatGlobalsTailType			"Tail"
	typeend
typedef HwrBatGlobalsAnalogType	@"HwrBatGlobalsAnalogPtr"

;; This type shows 'level' of the chargeHistory union
typedef struct "HwrBatGlobalsLevelType"
	> HwrBatGlobalsHeadType			"Head"	
	> HwrBatGlobalsLevelHistoryType		"chargeHistory"
	> HwrBatGlobalsTailType			"Tail"
	typeend
typedef HwrBatGlobalsLevelType	@"HwrBatGlobalsLevelPtr"

;; Set the default part of the union to be displayed as the "Analog" version
typedef HwrBatGlobalsAnalogType	"HwrBatGlobalsType"

typedef HwrBatGlobalsType	@"HwrBatGlobalsPtr"

typedef struct "SysBatteryDataType"
	> UInt16          "sysBattDataStructVersion"
	> UInt16          "_sysBattMildWrngVoltageV1"
	> UInt16          "_sysBattSevereWrngVoltageV1"
	> UInt16          "_sysBattMildWrngPercentV1"
	> UInt16          "_sysBattSevereWrngPercentV1"
	> UInt16          "sysBattShutdownEnVoltage"
	> UInt16          "sysBattShutdownDisVoltage"
	> UInt16          "sysBattTableFlags"
	> UInt32          "_sysBattMildWrngTimeoutV2"
	> UInt32          "_sysBattSevereWrngTimeoutV2"
	> UInt16          "sysBattCritWarnOffDays"
	> UInt32          "sysBattCritWarnOnTicks"
	> UInt16          "sysBattStepsPerVolt"
	> Int16           "sysBattVoltageStepOffset"
	> UInt32          "sysBattCapacity"
	> UInt32          "sysBattReserved2"
	> UInt16          "sysBattVoltageCurve"[#11]
	typeend
typedef SysBatteryDataType @"SysBatteryDataPtr"


;;;;;;;;;;;;;;;;;;;;;;;;;;
;; HS Serial Extensions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;

typedef VoidPtr "HsSendWakeupHandlerFnPtr"
typedef VoidPtr "HsSrmSetSendWakeupHandlerFnPtr"
typedef VoidPtr "HsSrmSendNonblockingFnPtr"

typedef struct "HsSrmSendExtensionsAPIType"
	> VoidPtr "drvrDataP";

	> HsSrmSetSendWakeupHandlerFnPtr		"hsSrmSetSendWakeupHandler";
	> HsSrmSendNonblockingFnPtr				"hsSrmSendNonblocking";
	typeend

;;;;;;;;;;;;;;;;;;;;;;;
;; Serial on 3.5CDMA ;;
;;;;;;;;;;;;;;;;;;;;;;;

typedef VoidPtr "SerFifoGetFnPtr"

typedef struct "CircBufferType_68Z328_CDMA"
	> UInt8			"buf"[#512] \-
	> UInt16			"head";
	> UInt16			"tail";
	typeend

typedef struct "Sdrv328GlobalsType_CDMA"
	> VoidPtr           "portP";					
											
	> VoidPtr           "oldIntHandler";			
	> UInt32			"oldIntData";				
											
	> UInt32			"curBaudRate";			
	> UInt32			"curSysClockFreq";		
											
	> UInt8				"hwHShake";				
											
	> UInt8				"irDriverOn";				
											
	> UInt8				"oldRtsBits";				

	> Boolean			"rtsOffForQueueFull";		
											

	> UInt16			"ctsTimeout";
	> UInt32			"settingsFlags";
	> DrvrHWRcvQPtr		"receiveQ";

	> UInt8				"sendLock";				
											
	> UInt8				"_filler1" \-

	> HsSendWakeupHandlerFnPtr  "sendWakeupHandlerFnP";	
													
	> UInt32			"sendWakeupRef";			
	> Int32			"sendWakeupIdealBytesAvail";

	> SerFifoGetFnPtr	"FifoGetFnP";			  
	> VoidPtr			"FifoGetUserP";		  

	> CircBufferType_68Z328_CDMA	"writeBuffer";		

	> UInt16			"phoneLibRefNum";		
	
	> VoidPtr			"debugData";				
	typeend


typedef UInt8	"ISRStateEnum"
typedef UInt8	"DMStateEnum"

typedef struct "CircBufferType_SPI_CDMA"
	> UInt8			"buf"[#8192]  \-
	> UInt16			"head";					  
	> UInt16			"tail";					  
	typeend


typedef struct "SdrvSPI1GlobalsType_CDMA"
	> VoidPtr           "portP";					
											
	> VoidPtr           "oldIntHandler";			
	> UInt32			"oldIntData";				

											
	> UInt32			"curBaudRate";			
	> UInt32			"curSysClockFreq";		
											
											
	> UInt8				"hwHShake";				
											
	> UInt8				"irDriverOn";				
											

											
											
	> UInt8				"oldRtsBits";				

	> Boolean			"rtsOffForQueueFull";		
											

	> UInt16			"ctsTimeout";
	> UInt32			"settingsFlags";
	> DrvrHWRcvQPtr		"receiveQ";

	> UInt8				"sendLock";				
											
	> UInt8				"_filler1"  \-

	> HsSendWakeupHandlerFnPtr  "sendWakeupHandlerFnP";	
													
	> UInt32			"sendWakeupRef";			

	> SerFifoGetFnPtr	"FifoGetFnP";				
	> VoidPtr			"FifoGetUserP";			

	> ISRStateEnum		"ISRState";				
	> UInt8				"_filler2"  \-

    > HsSrmSendExtensionsAPIType "DMPortSendAPI"; 
	> Boolean			"DMpassthruMode";			
	> DMStateEnum		"DMState";				
	> Boolean			"DMPacketReady";			
	> UInt8				"_filler3"  \-
	> UInt16			"DMPortid";				
	> CircBufferType_SPI_CDMA	"DMReadBuf";				
	> CircBufferType_SPI_CDMA	"DMWriteBuf";				
	> CircBufferType_SPI_CDMA	"WriteBuf";				
;	> UInt8	  		"DebugBuf"[#1024] \-
;	> UInt16			"dbi";
	> Boolean			"WriteDataReady";			
	> UInt8				"_filler4"  \-

	> VoidPtr			"debugData";				
	typeend


; Theoretically, this should go somewhere else.  For now, it will
; go here.

typedef struct  "NewSerialManagerMsgLibDataType"
  > UInt16    "portId";
  > VoidPtr	  "readBufferEndP";
  > VoidPtr   "readLocation";
  > Boolean   "inWakeupHandler";
  > UInt8     "lastCharacterIn";

  > UInt8     "readBuffer"[#4096] \-
  > UInt16    "readLocationHead";
  > UInt16    "readLocationTail";
  > UInt16    "msgLen";
  > UInt16    "NumMsgTail";
  > UInt16    "NumMsgHead";
  > UInt16    "msgEndLocation"[20] \-
  > VoidPtr	  "cardGP";
typeend


;################################################################
; Macros
;##############################################################
alias "HalGlobals"			"dm @.l($000000F8) HalGlobalsType"
alias "HalIndicatorGlobals"	"dm @.l(@.l($000000F8)+$6A) HalIndicatorDataType"
alias "HalIntervalGlobals"	"dm @.l(@.l($000000F8)+$6E) HalIntervalDataType"

alias "BatGlobalsAnalog"	"dm @.l($000002F6) HwrBatGlobalsAnalogType"
alias "BatGlobalsLevel"		"dm @.l($000002F6) HwrBatGlobalsLevelType"
alias "BatGlobals"			"dm @.l($000002F6) HwrBatGlobalsType"

alias "BatData"				"dm @.l($000002C2) SysBatteryDataType"

