]> git.llucax.com Git - z.facultad/66.09/etherled.git/blobdiff - src/main.c
Faltó reemplazar un petherled por EPL =)
[z.facultad/66.09/etherled.git] / src / main.c
index 60ed5db0cec78cba5e4b71922ef001982b569842..f980df1fb630c10f9d10b7c4669bb80017a34f83 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "debug.h"
 #include "leds.h"
 
 #include "debug.h"
 #include "leds.h"
+#include "reg51.h"
 #include "netdev.h"
 #include "eth.h"
 #include "ip.h"
 #include "netdev.h"
 #include "eth.h"
 #include "ip.h"
 
 void main(void)
 {
 
 void main(void)
 {
-    // Apagamos todos los leds
-    leds(0);
+    // Inicializamos leds
+    leds_init();
+
+    // Hacemos prueba simple de los leds
+    leds_test();
 
     // Inicializamos dispositivo de red
     if (!netdev_init())
     {
 
     // Inicializamos dispositivo de red
     if (!netdev_init())
     {
-        leds(0xFFFF);
-        while(1); // Si falla init nos quedamos bobos
+        // Si hubo un error, quedan prendidos todos los leds
+        leds_write(0xFFFF);
+        return;
     }
 
     }
 
+    // Comienza a 'dibujar'
+    EA  = 1; // Habilita interrupciones globalmente
+    TR2 = 1; // Pone a correr el 'dibujado'
+
     // Inicializo IP
     ip_addr_local[0] = 10;
     ip_addr_local[1] = 10;
     // Inicializo IP
     ip_addr_local[0] = 10;
     ip_addr_local[1] = 10;
@@ -30,7 +39,6 @@ void main(void)
 
     while (1) // Forever
     {
 
     while (1) // Forever
     {
-        byte buf[64]; //XXX
         byte i; //XXX
         byte len;
 
         byte i; //XXX
         byte len;
 
@@ -76,8 +84,9 @@ void main(void)
                         // Nuestro protocolo, por ahora un simple echo!
                         len = udp_dgram_len - UDP_HEADER_SIZE;
                         netdev_read_start(len);
                         // Nuestro protocolo, por ahora un simple echo!
                         len = udp_dgram_len - UDP_HEADER_SIZE;
                         netdev_read_start(len);
+                        leds_matrix_len = len;
                         for (i = 0; i < len; ++i)
                         for (i = 0; i < len; ++i)
-                            buf[i] = udp_read_byte();
+                            leds_matrix[i] = udp_read_byte();
                         netdev_read_end();
                         if (!udp_checksum_ok())
                             goto drop;
                         netdev_read_end();
                         if (!udp_checksum_ok())
                             goto drop;
@@ -92,7 +101,7 @@ void main(void)
                         udp_write_dgram_header();
                         netdev_write_start(len);
                         for (i = 0; i < len; ++i)
                         udp_write_dgram_header();
                         netdev_write_start(len);
                         for (i = 0; i < len; ++i)
-                            udp_write_byte(buf[i]);
+                            udp_write_byte(leds_matrix[i]);
                         netdev_write_end();
                         udp_write_checksum(ETH_HEADER_SIZE+IP_HEADER_SIZE);
                         netdev_send_end(ETH_HEADER_SIZE+IP_HEADER_SIZE+udp_dgram_len);
                         netdev_write_end();
                         udp_write_checksum(ETH_HEADER_SIZE+IP_HEADER_SIZE);
                         netdev_send_end(ETH_HEADER_SIZE+IP_HEADER_SIZE+udp_dgram_len);