[En-Nut-Discussion] Interfacing a memory mapped (Oxford Quad UART) device to an EtherNut
Pearless
Douglas.Pearless at pearless.co.nz
Wed Sep 17 01:46:00 CEST 2003
Hi People,
I'd appreciate some comments.
I have an Oxford quad UART mapped into 0xFF00 to 0xFFFF
I cannot seem to be able to read or write to it.
I have checked the hardware carefully (famous last words...) and neither the
RD\ nor WR\ lines seem to change, or at least may be they are changing too
fast for my logic probe.
Does this code cover what it needs to in order to be able to access the
Oxford chip (note that I am using UART0 on the Ethernut for comms and
debug!)
Cheers Douglas
#define UARTQUAD_BASE 0xFF00
#define UARTQUAD_DLL 0x008
#define uartquad_read(reg) *(base + (reg))
#define uartquad_write(reg, data) *(base + (reg)) = data
#include <string.h>
#include <stdio.h>
#include <io.h>
#include <dev/uartavr.h>
#include <sys/timer.h>
static char *banner = "\nNut/OXFORD UART Sample\n";
static char inbuf[128];
int main(void)
{
int got;
int i,j,k;
char *cp;
u_long baud = 115200;
FILE *uart;
float dval = 0.0;
u_long TWI_speed;
volatile u_char *base = (u_char *) UARTQUAD_BASE;
/*
* Enable external data and address
* bus.
*/
outp(BV(SRE) | BV(SRW), MCUCR);
NutRegisterDevice(&devUart0, 0, 0);
uart = fopen("uart0", "r+");
_ioctl(_fileno(uart), UART_SETSPEED, &baud);
NutSleep(200);
_write(_fileno(uart), banner, strlen(banner));
_write(_fileno(uart), 0, 0);
for(i = 0;; i++) {
fputs("\nPress Enter", uart);
fflush(uart);
fgets(inbuf, sizeof(inbuf), uart);
j = uartquad_read(UARTQUAD_DLL);
fprintf(uart, "\ni = %x : READ UARTQUAD_DLL = %x\n", i,j);
fflush(uart);
/* set it to 0x20 */
j = 0x20;
uartquad_write(UARTQUAD_DLL,j);
/* did it work ?*/
k = uartquad_read(UARTQUAD_DLL);
fprintf(uart, "\n UARTQUAD_DLL = %x\n", k);
fflush(uart);
}
}
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.518 / Virus Database: 316 - Release Date: 11/09/2003
More information about the En-Nut-Discussion
mailing list