?? hal_indirect16.c
字號:
//===========================================================================
// HAL_INDIRECT.C
//
// The routines in this file comprise the register and access methods for
// the S1D13716.
//
// The 13716 supports two indirect access modes (and no direct methods).
// The modes have been labeled "Serial Indirect" and "Parallel Indirect".
// The following text describes the access modes, from a programming
// point of view as they pertain to accessing the 13716 mounted on a
// S5U13716B00? evaluation board.
//
// Regardless of the access mode the 13716 interprets the current access
// cycle according to the state of the RS control line. On 13716 eval
// boards the RS line is connected to Address 1. Writing to odd addresses
// result in the RS line being pulled ???? and writing to even addresses
// result in the RS line being pulled ????.
//
// Parallel Indirect
// This mode consists of two distinct cycles, address and data. When the
// RS line is low an address cycle is performed. When the RS line is high
// the 13716 interprets this to be a data cycle.
//
// A typical Parallel Indirect sequence to access a control register
// will resemble the following:
// With RS low
// - Write the register LSB
// - Write the register MSB // this step can be skipped if the
// // MSB was previousley set
// With RS high
// - Read/Write the register data
//
// Serial Indirect
// This mode uses three types of cycles. A command cycle, when RS is low
// (valid commands consist of SER_SET_ADDR, WRITE and READ) and address or
// data cycles when the RS line is high.
//
// A typical Serial Indirect sequence to access a control register
// will resemble the following:
// With RS low
// - SER_SET_ADDR
// With RS high
// - Write the Addr LSB // Write the address
// - Write the Addr MSB // this step can be skipped if the
// // MSB was previously set
// With RS low
// - WRITE // Inform the system we want to write data
// With RS high
// - Read/Write register data
//---------------------------------------------------------------------------
// Copyright (c) 2003 Epson Research and Development, Inc.
// All Rights Reserved.
//===========================================================================
// (Tabs set to every 4)
#include "hal.h"
#include "hal_platform.h"
#include "hal_private.h"
#include "hal_indirect.h"
HALIND_STRUCT HalIndInfo; // HAL indirect pointers structure.
UInt16 tmp;
UInt16 swap16addr( in UInt16 Value )
{
return (UInt16)( ((Value>>8)&0x00FF) | ((Value&0x00FF)<<8) );
}
//---------------------------------------------------------------------------
// INDIRECT FUNCTION: halpIndirectInit() - Initialize HAL to communicate using indirect interface
//---------------------------------------------------------------------------
void halpIndirectInit( UInt32 RegAddr )
{
HalIndInfo.pIndex8 = (pvUInt8)(RegAddr + 0);
HalIndInfo.pData8 = (pvUInt8)(RegAddr + 2);
HalIndInfo.pIndex16 = (pvUInt16)(RegAddr + 0);
HalIndInfo.pData16 = (pvUInt16)(RegAddr + 2);
}
//---------------------------------------------------------------------------
// FUNCTION: halpParWriteReg8()
//
// DESCRIPTION:
// Writes one eight bit control register with the specified data
// using indirect parallel I/O.
//
// PARAMETERS:
// index - Register offset to write the value to
// value - The eight bit value to write to the register
//---------------------------------------------------------------------------
void halpParWriteReg8( UInt32 index, UInt8 value )
{
halSetProcessExclusivity( TRUE );
// Setup the address
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
// Write the value
*HalIndInfo.pData8 = value;
halSetProcessExclusivity( FALSE );
}
//---------------------------------------------------------------------------
// FUNCTION: halpParWriteReg16()
//
// DESCRIPTION:
// Writes two consective eight bit control registers with
// one sixteen bit value using parallel indirect I/O.
//
// PARAMETERS:
// index - Register offset to the LSB register
// The MSB of value will be written to index + 1
// value - The sixteen bit value to write to the registers
//---------------------------------------------------------------------------
void halpParWriteReg16( UInt32 index, UInt16 value )
{
halSetProcessExclusivity( TRUE );
// Read first 8-bit value.
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
*HalIndInfo.pData8 = LOBYTE(value);
// Read second 8-bit value.
index++;
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
*HalIndInfo.pData8 = HIBYTE(value);
halSetProcessExclusivity( FALSE );
}
//---------------------------------------------------------------------------
// FUNCTION: halpParWriteReg32()
//
// DESCRIPTION:
// Writes four consective eight bit control registers with
// one thirty-two bit value using parallel indirect I/O.
//
// PARAMETERS:
// index - Register offset to the LSB register
// The MSB of value will be written to index + 1 ...
// value - The thirty-two bit value to write to the registers
//---------------------------------------------------------------------------
void halpParWriteReg32( UInt32 index, UInt32 value )
{
halSetProcessExclusivity( TRUE );
// Read first 8-bit value.
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
*HalIndInfo.pData8 = LOBYTE(LOWORD(value));
// Read second 8-bit value.
index++;
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
*HalIndInfo.pData8 = HIBYTE(LOWORD(value));
// Read third 8-bit value.
index++;
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
*HalIndInfo.pData8 = LOBYTE(HIWORD(value));
// Read fourth 8-bit value.
index++;
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
*HalIndInfo.pData8 = HIBYTE(HIWORD(value));
halSetProcessExclusivity( FALSE );
}
//---------------------------------------------------------------------------
// FUNCTION: halpParReadReg8()
//
// DESCRIPTION:
// Reads one eight bit register and returns the value to the caller
// using parallel indirect I/O.
//
// PARAMETERS:
// index - The register offset to read data from
//
// RETURNS:
// The eight bit value read from the register.
//---------------------------------------------------------------------------
UInt8 halpParReadReg8( UInt32 index )
{
UInt8 val = 0;
halSetProcessExclusivity( TRUE );
// Setup the register address
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
val = *HalIndInfo.pData8;
halSetProcessExclusivity( FALSE );
return val;
}
//---------------------------------------------------------------------------
// FUNCTION: halpParReadReg16()
//
// DESCRIPTION:
// Reads two consective eight bit control registers and returns the
// resulting sixteen bit value using parallel indirect I/O.
//
// PARAMETERS:
// index - Register offset to the LSB register
// The MSB value will be read from index + 1
//
// RETURNS:
// The sixteen bit value read from the registers.
//---------------------------------------------------------------------------
UInt16 halpParReadReg16( UInt32 index )
{
UInt16 val;
halSetProcessExclusivity( TRUE );
// Read first 8-bit value.
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
val = *HalIndInfo.pData8;
// Read second 8-bit value.
index++;
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
val |= (UInt16)(*HalIndInfo.pData8<<8);
halSetProcessExclusivity( FALSE );
return val;
}
//---------------------------------------------------------------------------
// FUNCTION: halpParReadReg32()
//
// DESCRIPTION:
// Reads four consective eight bit control registers and returns the
// resulting thirty-two bit value using parallel indirect I/O.
//
// PARAMETERS:
// index - Register offset to the LSB register
//
// RETURNS:
// The thirty-two bit value read from the registers.
//---------------------------------------------------------------------------
UInt32 halpParReadReg32( UInt32 index )
{
UInt16 loword, hiword;
halSetProcessExclusivity( TRUE );
// Read first 8-bit value.
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
loword = *HalIndInfo.pData8;
// Read second 8-bit value.
index++;
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
loword |= (UInt16)(*HalIndInfo.pData8<<8);
// Read third 8-bit value.
index++;
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
hiword = *HalIndInfo.pData8;
// Read fourth 8-bit value.
index++;
if (HalInfo.dwFlags & fINDIRECT_ADDR16)
*HalIndInfo.pIndex16 = LOWORD(index);
else
{
*HalIndInfo.pIndex8 = LOBYTE(index);
*HalIndInfo.pIndex8 = HIBYTE(index);
}
hiword |= (UInt16)(*HalIndInfo.pData8<<8);
halSetProcessExclusivity( FALSE );
return MAKELONG(loword, hiword);
}
//---------------------------------------------------------------------------
// FUNCTION: halpParWriteDisplay8()
//
// DESCRIPTION:
// This routine writes one eight bit value to the specified display
// memory offset using parallel indirect I/O.
//
// PARAMETERS:
// addr - The offset in display memory to write the value to.
// data - The eight bit value to be written to display memory.
//---------------------------------------------------------------------------
void halpParWriteDisplay8( UInt32 addr, UInt8 data, UInt32 count )
{
UInt32 loop;
halSetProcessExclusivity( TRUE );
SetDisplayAddrParallel(addr);
for ( loop=0; loop<count; loop++ )
*HalIndInfo.pData8 = data;
halSetProcessExclusivity( FALSE );
}
//---------------------------------------------------------------------------
// FUNCTION: halpParWriteDisplay16()
//
// DESCRIPTION:
// This routine writes one sixteen bit value to two consective
// display memory addresses using parallel indirect I/O.
//
// PARAMETERS:
// addr - The offset in display memory to write the LSB of value to
// The MSB will be wrtten to addr + 1
// data - The 16-bit value to be written to display memory.
//---------------------------------------------------------------------------
void halpParWriteDisplay16( UInt32 addr, UInt16 data, UInt32 count )
{
UInt32 loop;
halSetProcessExclusivity( TRUE );
SetDisplayAddrParallel(addr);
// Write the data
for ( loop=0; loop<count; loop++ )
{
if (HalInfo.dwFlags & fINDIRECT_DATA16)
*HalIndInfo.pData16 = data;
else
{
*HalIndInfo.pData8 = LOBYTE(data);
*HalIndInfo.pData8 = HIBYTE(data);
}
}
halSetProcessExclusivity( FALSE );
}
//---------------------------------------------------------------------------
// FUNCTION: halpParWriteDisplay32()
//
// DESCRIPTION:
// This routine writes four consective eight bit display memory addresses
// with the thirty-two bits of data using parallel indirect I/O.
//
// PARAMETERS:
// addr - Specifies the offset to the LSB of the data to be written
// data - The 32-bit data to be written to the specified address
//---------------------------------------------------------------------------
void halpParWriteDisplay32( UInt32 addr, UInt32 data, UInt32 count )
{
UInt32 loop;
halSetProcessExclusivity( TRUE );
SetDisplayAddrParallel(addr);
// Write the data
for ( loop=0; loop<count; loop++ )
{
if (HalInfo.dwFlags & fINDIRECT_DATA16)
{
*HalIndInfo.pData16 = LOWORD(data);
*HalIndInfo.pData16 = HIWORD(data);
}
else
{
*HalIndInfo.pData8 = LOBYTE(LOWORD(data));
*HalIndInfo.pData8 = HIBYTE(LOWORD(data));
*HalIndInfo.pData8 = LOBYTE(HIWORD(data));
*HalIndInfo.pData8 = HIBYTE(HIWORD(data));
}
}
halSetProcessExclusivity( FALSE );
}
//---------------------------------------------------------------------------
// FUNCTION: halpParReadDisplay8()
//
// DESCRIPTION:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -