silentlights wrote:
Hi Thomas,
That was a brilliant idea. Could you please explain me a little bit more..
I want to understand in detail so I can implement this idea in all other
get() and put() functions.
#define TX_REG_OFFSET 0
#define RX_REG_OFFSET 4
#define STATUS_REG_OFFSET 8
#define CTRL_REG_OFFSET 12
How do I calculate the offset ?
The offsets are calculated by subtracting the address of a given
register from the base or first register. This just happens
to be an example I made up. I used this method on a tape
drive project.
unsigned char Read_Serial_Port(unsigned char * base_ptr)
{
unsigned char byte = 0;
if (*((unsigned int *)(base_ptr + CTRL_REG_OFFSET))
& RX_RDY)
What is RX_RDY ?, If I want to check for a flag in register how can I do
that..?
Thanks in advance
Densil
RX_RDY happens to be a bit in the status register that
indicates a character is in the receive register of the
UART.
To check flags (bits) in a register, read the register
then use the bit operators: &, |, ! or ^. Generally,
the bitwise-AND is used to mask out unwanted bits.
On the current platform that I am working on, the
designers use this paradigm:
#define UART_BASE 0x40000
#define UART0_RECV_REG (volatile char *)(UART_BASE + 4)
#define UART0_XMIT_REG (volatile char *)(UART_BASE + 8)
Since the processor is 32-bit, the hardware designers
have placed the registers on 32-bit boundaries to make
accessing easier on the processor.
The above paradigm is used in case the H/W folk decide
to change where the UART is located in the address space.
Thus only one value would have to change.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library