From: Leandro Lucarella Date: Wed, 7 Dec 2005 03:22:22 +0000 (+0000) Subject: Adapto ejemplo básico que andaba a SDCC y funciona correctamente. X-Git-Tag: 0.1-recibe-matriz-raw-por-udp~24 X-Git-Url: https://git.llucax.com/z.facultad/66.09/etherled.git/commitdiff_plain/c0e5d185c08cc8c099e9a3a93e62d422ca0e7ebf Adapto ejemplo básico que andaba a SDCC y funciona correctamente. --- diff --git a/pruebas/keil/red_test_anda/Makefile b/pruebas/keil/red_test_anda/Makefile new file mode 100644 index 0000000..ad2923d --- /dev/null +++ b/pruebas/keil/red_test_anda/Makefile @@ -0,0 +1,26 @@ + +CC=sdcc +LD=sdcc +#CFLAGS=-DDEBUG + +all: red.hex + +reg51.h: reg51sdcc.h + +netdev.h: types.h + +etherdev.h: types.h reg51.h netdev.h + +etherdev.rel: etherdev.c etherdev.h + $(CC) $(CFLAGS) -c etherdev.c + +main.rel: main.c etherdev.h + $(CC) $(CFLAGS) -c main.c + +red.hex: main.rel etherdev.rel + $(LD) $(LDFLAGS) -o red.hex main.rel etherdev.rel + +clean: + @rm -vf red.hex *.rel *.asm *.lst *.map *.lnk *.mem *.sym + +.PHONY: clean diff --git a/pruebas/keil/red_test_anda/etherdev.c b/pruebas/keil/red_test_anda/etherdev.c index d07bf98..93abcbf 100644 --- a/pruebas/keil/red_test_anda/etherdev.c +++ b/pruebas/keil/red_test_anda/etherdev.c @@ -1,11 +1,17 @@ // vim: set et sw=4 sts=4 : +#include "types.h" #include "etherdev.h" void sleep(unsigned char); -static xdata leds1 _at_ 0x0080; -static xdata leds2 _at_ 0x00c0; +#ifdef SDCC +static xdata at 0x0080 byte leds1; +static xdata at 0x00c0 byte leds2; +#else +static byte xdata leds1 _at_ 0x0080; +static byte xdata leds2 _at_ 0x00c0; +#endif unsigned char uip_buf[80] = { @@ -56,9 +62,6 @@ static void etherdev_reg_write(unsigned char reg, unsigned char wr_data) IOW = 1; NICE = 1; - // Set register data port as input again. - ETH_DATA_PORT = ETH_DATA_PORT_MASK; - return; } @@ -71,6 +74,9 @@ static unsigned char etherdev_reg_read(unsigned char reg) ETH_ADDR_PORT &= ~ETH_ADDR_PORT_MASK; ETH_ADDR_PORT |= reg; + // Set register data port as input. + ETH_DATA_PORT = ETH_DATA_PORT_MASK; + // Enable register data output from RTL8019AS. NICE = 0; IOR = 0; @@ -94,7 +100,7 @@ static unsigned char etherdev_reg_read(unsigned char reg) Refer to National Semiconductor DP8390 App Note 874, July 1993. */ -bit etherdev_init(void) +bool etherdev_init(void) { // Set IOR & IOW as they're active low. IOR = 1; @@ -141,7 +147,7 @@ bit etherdev_init(void) // Mask all interrupts in mask register. etherdev_reg_write(IMR, 0x00); - + // Obtengo MAC de la placa etherdev_reg_write(RBCR0, 0x0c); // Vamos a leer 12 bytes (2 x 6) etherdev_reg_write(RBCR1, 0x00); diff --git a/pruebas/keil/red_test_anda/etherdev.h b/pruebas/keil/red_test_anda/etherdev.h index f683064..32dbb57 100644 --- a/pruebas/keil/red_test_anda/etherdev.h +++ b/pruebas/keil/red_test_anda/etherdev.h @@ -3,7 +3,7 @@ #ifndef ETHERDEV_H #define ETHERDEV_H -#include "REG51.h" +#include "reg51.h" extern unsigned char uip_buf[80]; extern unsigned int uip_len; @@ -11,10 +11,16 @@ extern unsigned int uip_len; #define ETH_DATA_PORT P2 // Adjust this to suit hardware. #define ETH_ADDR_PORT P1 // Adjust this to suit hardware. -#define ETH_CTRL_PORT P3 // Adjust this to suit hardware. -sbit IOW = ETH_CTRL_PORT^4; // ISA slot pin B13, RTL8019AS pin 30, active low -sbit IOR = ETH_CTRL_PORT^5; // ISA slot pin B14, RTL8019AS pin 29, active low -sbit NICE = ETH_CTRL_PORT^2; // A7, usado para activar placa de red +#ifdef SDCC +sbit at 0xB4 IOW; // ISA slot pin B13, RTL8019AS pin 30, active low +sbit at 0xB5 IOR; // ISA slot pin B14, RTL8019AS pin 29, active low +sbit at 0xB2 NICE; // A7, usado para activar placa de red +#else +#define CTRL_PORT P3 // Adjust this to suit hardware. +sbit IOW = CTRL_PORT^4; // ISA slot pin B13, RTL8019AS pin 30, active low +sbit IOR = CTRL_PORT^5; // ISA slot pin B14, RTL8019AS pin 29, active low +sbit NICE = CTRL_PORT^2; // A7, usado para activar placa de red +#endif // Register base address @@ -211,7 +217,7 @@ sbit NICE = ETH_CTRL_PORT^2; // A7, usado para activar placa de red #define RXSDEF 0x80 /* deferring */ -bit etherdev_init(void); +bool etherdev_init(void); void etherdev_send(void); unsigned int etherdev_read(void); diff --git a/pruebas/keil/red_test_anda/main.c b/pruebas/keil/red_test_anda/main.c index f2ef8f7..d6583d0 100644 --- a/pruebas/keil/red_test_anda/main.c +++ b/pruebas/keil/red_test_anda/main.c @@ -1,9 +1,15 @@ // vim: set et sw=4 sts=4 : +#include "types.h" #include "main.h" -static xdata leds1 _at_ 0x0080; -static xdata leds2 _at_ 0x00c0; +#ifdef SDCC +static byte xdata at 0x0080 leds1; +static byte xdata at 0x00c0 leds2; +#else +static byte xdata leds1 _at_ 0x0080; +static byte xdata leds2 _at_ 0x00c0; +#endif void sleep(unsigned char times) { @@ -36,9 +42,9 @@ void main(void) len = etherdev_read(); if (len) { - //leds1 = ~0x55; - //leds2 = ~len; - //sleep(0); + leds1 = ~0x55; + leds2 = ~len; + sleep(0); /* for (len = 0; len < uip_len; ++len) { diff --git a/pruebas/keil/red_test_anda/reg51.h b/pruebas/keil/red_test_anda/reg51.h new file mode 100644 index 0000000..9f08bd6 --- /dev/null +++ b/pruebas/keil/red_test_anda/reg51.h @@ -0,0 +1,10 @@ +#ifndef _REG51_H_ +#define _REG51_H_ + +#ifdef SDCC +# include "reg51sdcc.h" +#else +# include "reg51keil.h" +#endif + +#endif /* _REG51_H_ */ diff --git a/pruebas/keil/red_test_anda/REG51.H b/pruebas/keil/red_test_anda/reg51keil.h similarity index 81% rename from pruebas/keil/red_test_anda/REG51.H rename to pruebas/keil/red_test_anda/reg51keil.h index 77548c4..ed182bf 100644 --- a/pruebas/keil/red_test_anda/REG51.H +++ b/pruebas/keil/red_test_anda/reg51keil.h @@ -1,11 +1,5 @@ -/*-------------------------------------------------------------------------- -REG51.H - - Header file for generic 80C51 and 80C31 microcontroller. - ---------------------------------------------------------------------------*/ -#ifndef REG51_H -#define REG51_H +#ifndef _REG51KEIL_H_ +#define _REG51KEIL_H_ /* BYTE Register */ sfr P0 = 0x80; @@ -85,4 +79,4 @@ sbit RB8 = 0x9A; sbit TI = 0x99; sbit RI = 0x98; -#endif /* REG51_H */ +#endif /* _REG51KEIL_H_ */ diff --git a/pruebas/keil/red_test_anda/reg51sdcc.h b/pruebas/keil/red_test_anda/reg51sdcc.h new file mode 100644 index 0000000..ca1bbaf --- /dev/null +++ b/pruebas/keil/red_test_anda/reg51sdcc.h @@ -0,0 +1,82 @@ +#ifndef _REG51SDCC_H_ +#define _REG51SDCC_H_ + +/* BYTE Register */ +sfr at 0x80 P0; +sfr at 0x90 P1; +sfr at 0xA0 P2; +sfr at 0xB0 P3; +sfr at 0xD0 PSW; +sfr at 0xE0 ACC; +sfr at 0xF0 B; +sfr at 0x81 SP; +sfr at 0x82 DPL; +sfr at 0x83 DPH; +sfr at 0x87 PCON; +sfr at 0x88 TCON; +sfr at 0x89 TMOD; +sfr at 0x8A TL0; +sfr at 0x8B TL1; +sfr at 0x8C TH0; +sfr at 0x8D TH1; +sfr at 0xA8 IE; +sfr at 0xB8 IP; +sfr at 0x98 SCON; +sfr at 0x99 SBUF; + +/* BIT Register */ +/* PSW */ +sbit at 0xD7 CY; +sbit at 0xD6 AC; +sbit at 0xD5 F0; +sbit at 0xD4 RS1; +sbit at 0xD3 RS0; +sbit at 0xD2 OV; +sbit at 0xD0 P; + +/* TCON */ +sbit at 0x8F TF1; +sbit at 0x8E TR1; +sbit at 0x8D TF0; +sbit at 0x8C TR0; +sbit at 0x8B IE1; +sbit at 0x8A IT1; +sbit at 0x89 IE0; +sbit at 0x88 IT0; + +/* IE */ +sbit at 0xAF EA; +sbit at 0xAC ES; +sbit at 0xAB ET1; +sbit at 0xAA EX1; +sbit at 0xA9 ET0; +sbit at 0xA8 EX0; + +/* IP */ +sbit at 0xBC PS; +sbit at 0xBB PT1; +sbit at 0xBA PX1; +sbit at 0xB9 PT0; +sbit at 0xB8 PX0; + +/* P3 */ +sbit at 0xB7 RD; +sbit at 0xB6 WR; +sbit at 0xB5 T1; +sbit at 0xB4 T0; +sbit at 0xB3 INT1; +sbit at 0xB2 INT0; +sbit at 0xB1 TXD; +sbit at 0xB0 RXD; + +/* SCON */ +sbit at 0x9F SM0; +sbit at 0x9E SM1; +sbit at 0x9D SM2; +sbit at 0x9C REN; +sbit at 0x9B TB8; +sbit at 0x9A RB8; +sbit at 0x99 TI; +sbit at 0x98 RI; + +#endif /* _REG51SDCC_H_ */ diff --git a/pruebas/keil/red_test_anda/types.h b/pruebas/keil/red_test_anda/types.h new file mode 100644 index 0000000..3bd0dc6 --- /dev/null +++ b/pruebas/keil/red_test_anda/types.h @@ -0,0 +1,52 @@ +#ifndef _TYPES_H_ +#define _TYPES_H_ + +#if 0 /* i386 */ +#include + +/** booleano */ +typedef unsigned char bool; + +/** entero sin signo de 8 bits */ +typedef uint8_t byte; + +/** entero sin signo de 16 bits */ +typedef uint16_t uint16; + +#endif + +#if 1 /* 8051 */ + +/** entero sin signo de 8 bits */ +typedef unsigned char byte; + +/** entero sin signo de 16 bits */ +typedef unsigned int uint16; + +#ifdef SDCC +/** booleano */ +typedef byte bool; +#else +/** booleano */ +typedef bit bool; +#endif + +#endif + +/** valores posibles de un booleano */ +enum { false = 0, true = 1 }; + +/** convierte 2 bytes (high, low) en un word */ +#define WORD(high, low) ((uint16)((uint16)(high << 8) + (uint16)low)) + +/** convierte un word en 2 bytes */ +#define UNPACK(word, high, low) (high = (byte)(word >> 8), \ + low = (byte)word & 0xFF) + +/** obtiene parte alta de un word */ +#define HIGH(word) ((byte)(word >> 8)) + +/** obtiene parte baja de un word */ +#define LOW(word) ((byte)(word & 0xFF)) + +#endif /* _TYPES_H_ */