Intel 386 Computer Hardware User Manual


 
10-35
TIMER/COUNTER UNIT
Returns:Error Codes
E_INVALID_DEVICE -- Unit number specifies a non-existing device
E_OK -- Initialized OK, No error.
Assumptions:
REMAPCFG register has Expanded I/O space access enabled (ESE bit set);
This function also initializes the Timer-Counter Unit to be in the
Read/Write Format of least-significant byte first, then most-significant
byte
Syntax:
int error;
error = InitTimer (TMR_2,
TMR_SQWAVE | TMR_CLK_BIN,
TMR_CLK_INTRN,
TMR_OUT_ENABLE,
0xFFFF,
TMR_ENABLE );
Real/Protected Mode:
No changes required.
*****************************************************************************/
int InitTimer(int Unit, WORD Mode, BYTE Inputs, BYTE Output, WORD InitCount,
int Enable)
{
BYTE TmpByte;
WORD TmrCntPort;
if(Unit > 2)
return E_INVALID_DEVICE;
TmrCntPort = 0xf040 + Unit;// Set depending on which timer
/* Set Pin configuration */
if(Unit < 2)
{
TmpByte = _GetEXRegByte(P3CFG) | (Output << Unit); // Bit 0 or 1
_SetEXRegByte(P3CFG,TmpByte);
}
else
{
TmpByte = _GetEXRegByte(PINCFG) | (Output << 5); // Bit 5
_SetEXRegByte(PINCFG,TmpByte);
}
/* Set Timer Config */
TmpByte = _GetEXRegByte(TMRCFG); // All Timers share this register,
// Keep previous settings