--- /dev/null
+
+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
// 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] =
{
IOW = 1;
NICE = 1;
- // Set register data port as input again.
- ETH_DATA_PORT = ETH_DATA_PORT_MASK;
-
return;
}
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;
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;
// 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);
#ifndef ETHERDEV_H
#define ETHERDEV_H
-#include "REG51.h"
+#include "reg51.h"
extern unsigned char uip_buf[80];
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
#define RXSDEF 0x80 /* deferring */
-bit etherdev_init(void);
+bool etherdev_init(void);
void etherdev_send(void);
unsigned int etherdev_read(void);
// 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)
{
len = etherdev_read();
if (len)
{
- //leds1 = ~0x55;
- //leds2 = ~len;
- //sleep(0);
+ leds1 = ~0x55;
+ leds2 = ~len;
+ sleep(0);
/*
for (len = 0; len < uip_len; ++len)
{
--- /dev/null
+#ifndef _REG51_H_
+#define _REG51_H_
+
+#ifdef SDCC
+# include "reg51sdcc.h"
+#else
+# include "reg51keil.h"
+#endif
+
+#endif /* _REG51_H_ */
-/*--------------------------------------------------------------------------
-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;
sbit TI = 0x99;
sbit RI = 0x98;
-#endif /* REG51_H */
+#endif /* _REG51KEIL_H_ */
--- /dev/null
+#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_ */
--- /dev/null
+#ifndef _TYPES_H_
+#define _TYPES_H_
+
+#if 0 /* i386 */
+#include <stdint.h>
+
+/** 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_ */