First Version (beta test) raw ethernet

Dependencies:   EthernetNetIf mbed

Files at this revision

API Documentation at this revision

Comitter:
ficofer
Date:
Mon Jul 09 22:31:28 2012 +0000
Commit message:

Changed in this revision

EthernetNetIf.lib Show annotated file Show diff for this revision Revisions of this file
defines.h Show annotated file Show diff for this revision Revisions of this file
eth3.c Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
utils.c Show annotated file Show diff for this revision Revisions of this file
utils.h Show annotated file Show diff for this revision Revisions of this file
variables.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Mon Jul 09 22:31:28 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/sherckuith/code/EthernetNetIf/#479ce5546098
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/defines.h	Mon Jul 09 22:31:28 2012 +0000
@@ -0,0 +1,15 @@
+/*
+*
+*		Defines necesaries
+*
+*/
+
+
+#define forever for(;;)
+#define ETH_BUFF_SIZE		1536
+#define PAYLOAD_OFF			14
+#define NUM_PAYLOAD			100
+#define SEC					1000
+#define ETHER_TYPE			0x0801
+#define MAC_ADD_NUM			6
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eth3.c	Mon Jul 09 22:31:28 2012 +0000
@@ -0,0 +1,56 @@
+/*
+ *     eth2.c
+ *         Send ethernet frames
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inet.h>
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "defines.h"
+#include "utils.h"
+#include "variables.h"
+
+
+
+/*
+ *     Public functions
+ *         main: here starts ball rolling forever !!!
+ */
+    
+int
+main( void )
+{
+    int i;
+
+    set_to_mac( eth_txs_buffer, broadcast );
+
+    printf("Sending data to\n");
+    for(i=0; i<6; i++)
+        printf("%02X ", broadcast[i]);
+    printf("\n");
+    
+    mbed_mac_address(my_mac);
+    
+    set_from_mac( eth_txs_buffer, my_mac );
+    
+    printf("Sending data from\n");
+    for(i=0; i<6; i++)
+        printf("%02X ", my_mac[i]);
+    printf("\n");
+    
+    set_ether_type( eth_txs_buffer, ETHER_TYPE );
+
+    memset( eth_txs_buffer + PAYLOAD_OFF, 'Z', NUM_PAYLOAD );
+
+    printf("Flooding Data...\n");
+    forever
+    {
+        eth.write( eth_txs_buffer, PAYLOAD_OFF + NUM_PAYLOAD );
+        eth.send();
+        wait_ms(1*SEC);
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jul 09 22:31:28 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/utils.c	Mon Jul 09 22:31:28 2012 +0000
@@ -0,0 +1,44 @@
+/*
+*
+*        utils.c functions to work with ethernet frames
+*
+*
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inet.h>
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "defines.h"
+#include "utils.h"
+#include "variables.h"
+
+extern "C" void 
+mbed_mac_address(char *mac);
+
+static
+void
+set_to_mac( char *peth, char const *pmac )
+{
+    memcpy( peth, pmac, MAC_ADD_NUM );
+}
+
+static
+void
+set_from_mac( char *peth, char const *pmac )
+{
+    memcpy( peth + MAC_ADD_NUM, pmac, MAC_ADD_NUM );
+}
+
+static
+void
+set_ether_type( char *peth, unsigned ether_type )
+{
+    unsigned short etype;
+
+    etype = ether_type;
+    etype = htons(etype);
+    memcpy( peth + 2*MAC_ADD_NUM, &etype, sizeof(unsigned short) );
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/utils.h	Mon Jul 09 22:31:28 2012 +0000
@@ -0,0 +1,12 @@
+/*
+*
+*        utils.h functions to work with ethernet frames
+*
+*
+*/
+
+
+extern "C" void mbed_mac_address(char *mac);
+static void set_to_mac(char *peth, char const *pmac);
+static void set_from_mac(char *peth, char const *pmac);
+static void set_ether_type(char *peth, unsigned ether_type);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/variables.h	Mon Jul 09 22:31:28 2012 +0000
@@ -0,0 +1,29 @@
+/*
+*
+*
+*        Variables needed in the program
+*
+*
+*/
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "defines.h"
+
+/*Statics and uninitialiazed*/
+
+Ethernet eth;  /*Starts ethernet interface for mbed*/
+static char eth_txs_buffer[ETH_BUFF_SIZE];
+
+
+/*Statics and initialiazed*/
+
+static const char broadcast[MAC_ADD_NUM] =
+{
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+};
+
+static char my_mac[MAC_ADD_NUM] =
+{
+    0x11, 0x11, 0x11, 0x11, 0x11, 0x11
+};
+