From ea812b14c037816196adf2443815ca4a149f38d6 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 27 Mar 2017 09:37:28 +1100 Subject: [PATCH 001/169] Update version number --- ZodiacFX/src/config/config_zodiac.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/config/config_zodiac.h b/ZodiacFX/src/config/config_zodiac.h index 6698768..89eaab6 100644 --- a/ZodiacFX/src/config/config_zodiac.h +++ b/ZodiacFX/src/config/config_zodiac.h @@ -31,7 +31,7 @@ #define CONFIG_ZODIAC_H_ -#define VERSION "0.80" // Firmware version number +#define VERSION "0.81" // Firmware version number #define MAX_OFP_VERSION 0x04 From 844ef102ed485c225de22a4d901b2c0d0b9fa757 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 27 Mar 2017 09:37:45 +1100 Subject: [PATCH 002/169] Update CLI command 'help' list --- ZodiacFX/src/command.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index 864f33d..c1bd78a 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -24,6 +24,7 @@ * along with this program. If not, see . * * Author: Paul Zanna + * & Kristopher Chen * */ @@ -1670,10 +1671,12 @@ void printhelp(void) printf(" config\r\n"); printf(" openflow\r\n"); printf(" debug\r\n"); - printf(" show ports\r\n"); + printf(" update\r\n"); printf(" show status\r\n"); printf(" show version\r\n"); + printf(" show ports\r\n"); printf(" restart\r\n"); + printf(" help\r\n"); printf("\r\n"); printf("Config:\r\n"); printf(" save\r\n"); @@ -1693,13 +1696,14 @@ void printhelp(void) printf(" set vlan-type \r\n"); printf(" add vlan-port \r\n"); printf(" delete vlan-port \r\n"); - printf(" factory reset\r\n"); printf(" set of-version \r\n"); printf(" set ethertype-filter \r\n"); + printf(" factory reset\r\n"); printf(" exit\r\n"); printf("\r\n"); printf("OpenFlow:\r\n"); printf(" show status\r\n"); + printf(" show tables\r\n"); printf(" show flows\r\n"); printf(" show meters\r\n"); printf(" enable\r\n"); From 02cb45ffb395a85e41bbbb161110d3c3c06e99b2 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 27 Mar 2017 10:11:52 +1100 Subject: [PATCH 003/169] Improve web interface flow output - Display style matched with the meter display page - Flow count, and current display range is now shown --- ZodiacFX/src/http.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index fca726f..3534e26 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -2980,6 +2980,16 @@ static uint8_t interfaceCreate_Display_OpenFlow(void) */ static uint8_t interfaceCreate_Display_Flows(void) { + int i; + uint8_t flowEnd = flowBase + FLOW_DISPLAY_LIMIT; + struct ofp_action_header * act_hdr; + + // Ensure page correctly displays end of flows + if(iLastFlow < flowEnd) + { + flowEnd = iLastFlow; + } + sprintf(shared_buffer, http_header); snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ @@ -2996,22 +3006,22 @@ static uint8_t interfaceCreate_Display_Flows(void) ""\ "

"\ "

Flows

"\ + "%d flows installed
"\ + , iLastFlow); + + if(iLastFlow != 0) + { + snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + "Showing flows %d - %d
"\ + , flowBase+1, flowEnd); + } + + snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ "

"\ "
"\
 			);
 
 // Begin Flow formatting
-
-int i;
-uint8_t flowEnd = flowBase + FLOW_DISPLAY_LIMIT;
-struct ofp_action_header * act_hdr;
-
-// Ensure page correctly displays end of flows
-if(iLastFlow < flowEnd)
-{
-	flowEnd = iLastFlow;
-}
-
 if (iLastFlow > 0)
 {
 	// OpenFlow v1.0 (0x01) Flow Table
@@ -3414,8 +3424,6 @@ if (iLastFlow > 0)
 		}
 		snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),"_______\r\n\n");
 	}
-	} else {
-	snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),"No Flows installed\r\n");
 	}
 	
 // End Flow formatting

From 7bfb0b559682b3e90567ab531a878cb14ae92c0e Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 27 Mar 2017 10:22:27 +1100
Subject: [PATCH 004/169] Move software reset into function

- All restart calls moved into software_reset function
---
 ZodiacFX/src/command.c | 27 +++++++++++++++------------
 ZodiacFX/src/command.h |  1 +
 ZodiacFX/src/flash.c   |  4 +---
 ZodiacFX/src/http.c    | 10 +---------
 4 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c
index c1bd78a..2df0d2f 100644
--- a/ZodiacFX/src/command.c
+++ b/ZodiacFX/src/command.c
@@ -125,6 +125,18 @@ void saveConfig(void)
 	return;
 }
 
+/*
+*	Restart Zodiac FX
+*
+*/
+void software_reset(void)
+{
+	for(int x = 0;x<100000;x++);	// Let the above message get sent to the terminal before detaching
+	udc_detach();	// Detach the USB device before restart
+	rstc_start_software_reset(RSTC);	// Software reset
+	while (1);
+}
+
 /*
 *	Main command line loop
 *
@@ -143,10 +155,7 @@ void task_command(char *str, char *str_last)
 	if(restart_required_outer == true)
 	{
 		printf("Restarting the Zodiac FX, please reopen your terminal application.\r\n");
-		for(int x = 0;x<100000;x++);	// Let the above message get sent to the terminal before detaching
-		udc_detach();	// Detach the USB device before restart
-		rstc_start_software_reset(RSTC);	// Software reset
-		while (1);		
+		software_reset();
 	}
 
 	while(udi_cdc_is_rx_ready()){
@@ -448,10 +457,7 @@ void command_root(char *command, char *param1, char *param2, char *param3)
 	if (strcmp(command, "restart")==0)
 	{
 		printf("Restarting the Zodiac FX, please reopen your terminal application.\r\n");
-		for(int x = 0;x<100000;x++);	// Let the above message get sent to the terminal before detaching
-		udc_detach();	// Detach the USB device before restart
-		rstc_start_software_reset(RSTC);	// Software reset
-		while (1);
+		software_reset();
 	}
 
 	// Get CRC
@@ -507,10 +513,7 @@ void command_config(char *command, char *param1, char *param2, char *param3)
 	if (strcmp(command, "restart")==0)
 	{
 		printf("Restarting the Zodiac FX, please reopen your terminal application.\r\n");
-		for(int x = 0;x<100000;x++);	// Let the above message get send to the terminal before detaching
-		udc_detach();	// Detach the USB device before restart
-		rstc_start_software_reset(RSTC);	// Software reset
-		while (1);
+		software_reset();
 	}
 	
 	// Display Config
diff --git a/ZodiacFX/src/command.h b/ZodiacFX/src/command.h
index b2d0f36..bee2417 100644
--- a/ZodiacFX/src/command.h
+++ b/ZodiacFX/src/command.h
@@ -93,5 +93,6 @@ typedef struct arp_header {
 
 void task_command(char *str, char * str_last);
 void loadConfig(void);
+void software_reset(void);
 
 #endif /* COMMANDS_H_ */
diff --git a/ZodiacFX/src/flash.c b/ZodiacFX/src/flash.c
index 25ac197..065a6be 100644
--- a/ZodiacFX/src/flash.c
+++ b/ZodiacFX/src/flash.c
@@ -152,9 +152,7 @@ void cli_update(void)
 	if(verification_check() == SUCCESS)
 	{
 		printf("Firmware upload complete - Restarting the Zodiac FX.\r\n");
-		for(int x = 0;x<100000;x++);	// Let the above message get send to the terminal before detaching
-		udc_detach();	// Detach the USB device before restart
-		rstc_start_software_reset(RSTC);	// Software reset
+		software_reset();
 	}
 	else
 	{
diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index 3534e26..8270342 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -212,11 +212,6 @@ static err_t http_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len)
 	if(restart_required == true)
 	{
 		restart_required_outer = true;
-		//TRACE("http.c: restarting the Zodiac FX. Please reconnect.");
-		//for(int x = 0;x<100000;x++);	// Let the above message get sent to the terminal before detaching
-		//udc_detach();	// Detach the USB device before restart
-		//rstc_start_software_reset(RSTC);	// Software reset
-		//while (1);
 	}
 	
 	return ERR_OK;
@@ -722,10 +717,7 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err
 					eeprom_write();
 				
 					TRACE("http.c: restarting the Zodiac FX. Please reconnect.");
-					for(int x = 0;x<100000;x++);	// Let the above message get sent to the terminal before detaching
-					udc_detach();	// Detach the USB device before restart
-					rstc_start_software_reset(RSTC);	// Software reset
-					while (1);
+					software_reset();
 				}
 				else if(strcmp(post_msg,"save_ports") == 0)
 				{

From 80569e87d6619a404136d3dd48e4c1631828b542 Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 27 Mar 2017 11:10:42 +1100
Subject: [PATCH 005/169] Clean up return values

---
 ZodiacFX/src/http.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index 8270342..9e85d21 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -1876,7 +1876,7 @@ static uint8_t Config_Network(char *payload, int len)
 			if (strlen(http_msg) != 27 )	// Accounting for ":" as "%3A"
 			{
 				TRACE("http.c: incorrect MAC address format");
-				return;
+				return FAILURE;
 			}
 			
 			// Decode http string
@@ -1934,7 +1934,7 @@ static uint8_t Config_Network(char *payload, int len)
 			if (strlen(http_msg) > 15 )
 			{
 				TRACE("http.c: incorrect IP format");
-				return;
+				return FAILURE;
 			}
 			sscanf(http_msg, "%d.%d.%d.%d", &ip1, &ip2,&ip3,&ip4);
 			Zodiac_Config.IP_address[0] = ip1;
@@ -1973,7 +1973,7 @@ static uint8_t Config_Network(char *payload, int len)
 			if (strlen(http_msg) > 15 )
 			{
 				TRACE("http.c: incorrect netmask format");
-				return;
+				return FAILURE;
 			}
 			sscanf(http_msg, "%d.%d.%d.%d", &nm1, &nm2,&nm3,&nm4);
 			Zodiac_Config.netmask[0] = nm1;
@@ -2013,7 +2013,7 @@ static uint8_t Config_Network(char *payload, int len)
 		if (strlen(http_msg) > 15 )
 		{
 			TRACE("http.c: incorrect gateway format");
-			return;
+			return FAILURE;
 		}
 		sscanf(http_msg, "%d.%d.%d.%d", &gw1, &gw2,&gw3,&gw4);
 		Zodiac_Config.gateway_address[0] = gw1;
@@ -2669,7 +2669,7 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step)
 		}
 				
 		if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\
-					""\		
+					""\
 				) < SHARED_BUFFER_LEN)
 		{
 			TRACE("http.c: html (1/2) written to buffer");
@@ -2845,6 +2845,7 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step)
 	else
 	{
 		TRACE:("http.c: Display: Ports step error");
+		return 0;
 	}
 }
 

From d76fd5d21418ea6e55f9c9a339c5bbf47ecd4243 Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 27 Mar 2017 11:11:02 +1100
Subject: [PATCH 006/169] Remove unnecessary externs

---
 ZodiacFX/src/http.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index 9e85d21..3dd847a 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -70,9 +70,6 @@ extern struct ofp10_port_stats phys10_port_stats[4];
 extern struct ofp13_port_stats phys13_port_stats[4];
 extern struct table_counter table_counters[MAX_TABLES];
 
-extern int firmware_update_init(void);
-extern int flash_write_page(uint8_t *flash_page);
-
 // Local Variables
 struct tcp_pcb *http_pcb;
 static char http_msg[64];			// Buffer for HTTP message filtering

From 8611fbd1d85378eeb8b8fb113deca422f0dc0077 Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 27 Mar 2017 11:11:19 +1100
Subject: [PATCH 007/169] Add notes to restart flagging

---
 ZodiacFX/src/http.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index 3dd847a..0e5d04d 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -208,6 +208,8 @@ static err_t http_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len)
 	}
 	if(restart_required == true)
 	{
+		// Indicates to task_command() that a restart is required on the next loop
+		// This allows the 'Restarting...' page to display before the restart occurs
 		restart_required_outer = true;
 	}
 	

From 235291e56e7b60660a03ab64dfb882195aade2ae Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 27 Mar 2017 11:20:06 +1100
Subject: [PATCH 008/169] Clean up network config error messages

- 'return;' removed
---
 ZodiacFX/src/http.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index 0e5d04d..06e38c3 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -1147,20 +1147,22 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err
 						if(pdat[i+1] == 'w')
 						{
 							int oc1,oc2,oc3,oc4;
-							if (strlen(http_msg) > 15 )
+							if (strlen(http_msg) <= 15 )
 							{
-								TRACE("http.c: incorrect IP format");
-								return;
-							}
-							sscanf(http_msg, "%d.%d.%d.%d", &oc1,&oc2,&oc3,&oc4);
-							Zodiac_Config.OFIP_address[0] = oc1;
-							Zodiac_Config.OFIP_address[1] = oc2;
-							Zodiac_Config.OFIP_address[2] = oc3;
-							Zodiac_Config.OFIP_address[3] = oc4;
-							TRACE("http.c: openflow server address set to %d.%d.%d.%d" ,\
+								sscanf(http_msg, "%d.%d.%d.%d", &oc1,&oc2,&oc3,&oc4);
+								Zodiac_Config.OFIP_address[0] = oc1;
+								Zodiac_Config.OFIP_address[1] = oc2;
+								Zodiac_Config.OFIP_address[2] = oc3;
+								Zodiac_Config.OFIP_address[3] = oc4;
+								TRACE("http.c: openflow server address set to %d.%d.%d.%d" ,\
 								Zodiac_Config.OFIP_address[0], Zodiac_Config.OFIP_address[1],\
 								Zodiac_Config.OFIP_address[2], Zodiac_Config.OFIP_address[3]\
-									);
+								);
+							}
+							else
+							{
+								TRACE("http.c: incorrect IP format");
+							}
 						}
 						else
 						{
@@ -2843,7 +2845,7 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step)
 	}
 	else
 	{
-		TRACE:("http.c: Display: Ports step error");
+		TRACE("http.c: Display: Ports step error");
 		return 0;
 	}
 }

From fa2b1c56fb03d8144929f4a9bad33ee83ce1a06d Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 27 Mar 2017 11:52:31 +1100
Subject: [PATCH 009/169] Update web interface style consolidation

---
 ZodiacFX/src/http.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index 06e38c3..1a2cf34 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -2332,18 +2332,14 @@ static uint8_t interfaceCreate_Upload_Status(uint8_t sel)
 {
 	if(sel == 1)
 	{	
-		if( snprintf(shared_buffer, SHARED_BUFFER_LEN,\
+		snprintf(shared_buffer, SHARED_BUFFER_LEN,\
 			""\
 				""\
 					""\
 						""\
 					""\
 					""\

From a051664ed81bcc85c81d152c0b77b3229391c4ac Mon Sep 17 00:00:00 2001
From: Paul Zanna 
Date: Sun, 2 Apr 2017 13:20:33 +1000
Subject: [PATCH 010/169] Moved stacking functions to stacking.c

---
 ZodiacFX/ZodiacFX.cproj |  10 +-
 ZodiacFX/src/main.c     |   8 +-
 ZodiacFX/src/stacking.c | 377 ++++++++++++++++++++++++++++++++++++++++
 ZodiacFX/src/stacking.h |  20 +++
 ZodiacFX/src/switch.c   | 340 +-----------------------------------
 5 files changed, 408 insertions(+), 347 deletions(-)
 create mode 100644 ZodiacFX/src/stacking.c
 create mode 100644 ZodiacFX/src/stacking.h

diff --git a/ZodiacFX/ZodiacFX.cproj b/ZodiacFX/ZodiacFX.cproj
index e3e4036..c3965ce 100644
--- a/ZodiacFX/ZodiacFX.cproj
+++ b/ZodiacFX/ZodiacFX.cproj
@@ -274,11 +274,11 @@
         JTAG
       
       com.atmel.avrdbg.tool.atmelice
-      J41800058832
+      J41800009874
       Atmel-ICE
     
     JTAG
-    J41800058832
+    J41800009874
     0xA3CC0CE0
     7500000
   
@@ -720,6 +720,12 @@
     
       compile
     
+    
+      compile
+    
+    
+      compile
+    
     
       compile
     
diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c
index 95494ae..58bbec2 100644
--- a/ZodiacFX/src/main.c
+++ b/ZodiacFX/src/main.c
@@ -42,6 +42,7 @@
 #include "command.h"
 #include "eeprom.h"
 #include "switch.h"
+#include "stacking.h"
 #include "http.h"
 #include "flash.h"
 #include "openflow/openflow.h"
@@ -137,13 +138,6 @@ int main (void)
 	masterselect = ioport_get_pin_level(MASTER_SEL);	// true = slave
 	stacking_init(masterselect);	// Initialise the stacking connector as either master or slave
 
-	// Set the IRQ line as either master or slave
-	if(masterselect) {
-		ioport_set_pin_dir(SPI_IRQ1, IOPORT_DIR_OUTPUT);
-	} else {
-		ioport_set_pin_dir(SPI_IRQ1, IOPORT_DIR_INPUT);
-	}
-
 	irq_initialize_vectors(); // Initialize interrupt vector table support.
 
 	cpu_irq_enable(); // Enable interrupts
diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c
new file mode 100644
index 0000000..2e650ef
--- /dev/null
+++ b/ZodiacFX/src/stacking.c
@@ -0,0 +1,377 @@
+/**
+ * @file
+ * stacking.c
+ *
+ * This file contains the stacking functions
+ *
+ */
+
+/*
+ * This file is part of the Zodiac FX firmware.
+ * Copyright (c) 2017 Northbound Networks.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ *
+ * Author: Paul Zanna 
+ *
+ */ 
+
+#include 
+#include 
+#include "stacking.h"
+#include "trace.h"
+#include "switch.h"
+#include "lwip/def.h"
+
+/* SPI clock setting (Hz). */
+static uint32_t gs_ul_spi_clock = 500000;
+
+/* Chip select. */
+#define SPI_CHIP_SEL 0
+#define SPI_CHIP_PCS spi_get_pcs(SPI_CHIP_SEL)
+/* Clock polarity. */
+#define SPI_CLK_POLARITY 0
+/* Clock phase. */
+#define SPI_CLK_PHASE 0
+/* Delay before SPCK. */
+#define SPI_DLYBS 0x40
+/* Delay between consecutive transfers. */
+#define SPI_DLYBCT 0x10
+
+#define SPI_SLAVE_PREAMBLE		0xAAAAAAAB
+#define SPI_MASTER_PREAMBLE		0xBBBBBBBC
+#define SPI_STATE_PREAMBLE	0
+#define SPI_STATE_COMMAND	1
+#define SPI_STATE_DATA		3
+
+uint32_t *spi_cmd_buffer;
+uint32_t spi_slv_preamble;
+uint8_t spi_state = 0;
+uint16_t spi_data_count = 0;
+uint16_t spi_command, spi_command_size;
+bool spi_slave_send;
+uint16_t spi_slave_send_size;
+uint8_t spibuffer[1];
+
+void spi_master_initialize(void);
+void spi_slave_initialize(void);
+void stack_mst_write(uint8_t *rx_data, uint16_t ul_size);
+
+/*
+*	Initialize the SPI interface to MASTER or SLAVE based on the stacking jumper
+*
+*/
+void stacking_init(bool master)
+{
+	if (master)
+	{
+		spi_slave_initialize();
+		ioport_set_pin_dir(SPI_IRQ1, IOPORT_DIR_OUTPUT);
+		} else {
+		spi_master_initialize();
+		ioport_set_pin_dir(SPI_IRQ1, IOPORT_DIR_INPUT);
+	}
+	return;
+}
+
+/*
+*	Initialize the SPI interface as a SLAVE
+*
+*/
+void spi_slave_initialize(void)
+{
+	NVIC_DisableIRQ(SPI_IRQn);
+	NVIC_ClearPendingIRQ(SPI_IRQn);
+	NVIC_SetPriority(SPI_IRQn, 0);
+	NVIC_EnableIRQ(SPI_IRQn);
+
+	/* Configure an SPI peripheral. */
+	spi_enable_clock(SPI_SLAVE_BASE);
+	spi_disable(SPI_SLAVE_BASE);
+	spi_reset(SPI_SLAVE_BASE);
+	spi_set_slave_mode(SPI_SLAVE_BASE);
+	spi_disable_mode_fault_detect(SPI_SLAVE_BASE);
+	spi_set_peripheral_chip_select_value(SPI_SLAVE_BASE, SPI_CHIP_SEL);
+	spi_set_clock_polarity(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY);
+	spi_set_clock_phase(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE);
+	spi_set_bits_per_transfer(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT);
+	spi_enable_interrupt(SPI_SLAVE_BASE, SPI_IER_RDRF);
+	spi_enable(SPI_SLAVE_BASE);
+	ioport_set_pin_level(SPI_IRQ1, false);
+}
+
+/*
+*	Initialize the SPI interface as a MASTER
+*
+*/
+void spi_master_initialize(void)
+{
+	/* Configure an SPI peripheral. */
+	spi_enable_clock(SPI_MASTER_BASE);
+	spi_disable(SPI_MASTER_BASE);
+	spi_reset(SPI_MASTER_BASE);
+	spi_set_lastxfer(SPI_MASTER_BASE);
+	spi_set_master_mode(SPI_MASTER_BASE);
+	spi_disable_mode_fault_detect(SPI_MASTER_BASE);
+	spi_disable_loopback(SPI_MASTER_BASE);
+	spi_set_peripheral_chip_select_value(SPI_MASTER_BASE, SPI_CHIP_SEL);
+	//spi_set_fixed_peripheral_select(SPI_MASTER_BASE);
+	//spi_disable_peripheral_select_decode(SPI_MASTER_BASE);
+	spi_set_transfer_delay(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_DLYBS, SPI_DLYBCT);
+	spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT);
+	spi_set_baudrate_div(SPI_MASTER_BASE, SPI_CHIP_SEL, (sysclk_get_cpu_hz() / gs_ul_spi_clock));
+	//spi_configure_cs_behavior(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CS_KEEP_LOW);
+	spi_set_clock_polarity(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY);
+	spi_set_clock_phase(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE);
+
+	spi_enable(SPI_MASTER_BASE);
+}
+
+
+void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size)
+{
+	uint32_t cmd_buffer;
+	
+	// Send the preamble mark the beginning of a transfer
+	cmd_buffer = ntohl(SPI_SLAVE_PREAMBLE);
+	stack_mst_write(&cmd_buffer, sizeof(cmd_buffer));
+	
+	// Send a 2 byte command code and 2 byte data code
+	cmd_buffer = ntohl(ul_size);
+	stack_mst_write(&cmd_buffer, sizeof(cmd_buffer));
+	
+	// Send packet
+	stack_mst_write(p_uc_data, ul_size);
+	return;
+}
+
+void MasterStackRcv(void)
+{
+	uint32_t cmd_buffer;
+	
+	TRACE("switch.c: Master received slave IRQ!");
+	// Send the preamble mark the beginning of a transfer
+	cmd_buffer = ntohl(SPI_MASTER_PREAMBLE);
+	stack_mst_write(&cmd_buffer, sizeof(cmd_buffer));
+
+	// Send 4 bytes to receive slave packet size
+	cmd_buffer = 0xFFFFFFFF;
+	stack_mst_write(&cmd_buffer, sizeof(cmd_buffer));
+	TRACE("switch.c: Rcv Size = %04X", cmd_buffer);
+	while(ioport_get_pin_level(SPI_IRQ1));
+}
+
+/*
+*	Write to the SPI stacking interface
+*
+*/
+void stack_mst_write(uint8_t *rx_data, uint16_t ul_size)
+{
+	uint8_t uc_pcs;
+	static uint16_t data;
+	uint8_t *p_buffer;
+	
+	p_buffer = rx_data;
+	
+	for (int i = 0; i < ul_size; i++) {
+		for(int x = 0;x<10000;x++);
+		spi_write(SPI_MASTER_BASE, p_buffer[i], 0, 0);
+		TRACE("switch.c: SPI Write - %d , %02X", i, p_buffer[i]);
+		/* Wait transfer done. */
+		while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0);
+		//spi_read(SPI_MASTER_BASE, p_buffer[i], &uc_pcs);
+		TRACE("switch.c: SPI Read - %d , %02X", i, data);
+	}
+	return;
+}
+	
+
+
+
+/*
+*	SPI interface IRQ handler
+*	Used to receive data from the stacking interface
+*
+*/
+void SPI_Handler(void)
+{
+	static uint16_t data;
+	uint8_t uc_pcs;
+
+	if (spi_slave_send == false)
+	{
+		if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF)
+		{
+			spi_read(SPI_SLAVE_BASE, &data, &uc_pcs);
+			//TRACE("%d - %02X", spi_data_count, data);
+
+			if (spi_state == SPI_STATE_DATA)
+			{
+				spibuffer[spi_data_count] = data;
+				spi_data_count++;
+				if (spi_data_count == spi_command_size)
+				{
+					TRACE("switch.c: %d bytes of Data received", spi_data_count);
+					uint8_t* tail_tag = (uint8_t*)(spibuffer + (int)(spi_command_size)-1);
+					uint8_t tag = *tail_tag + 1;
+					TRACE("switch.c: Tag = %d", tag);
+					gmac_write(spibuffer, spi_data_count-1, tag);
+					spi_data_count = 0;
+					spi_state = SPI_STATE_PREAMBLE;
+					return;
+				}
+			}
+
+			//	Start of Preamble
+			if (spi_state == SPI_STATE_PREAMBLE && data == 0xAA)
+			{
+				switch (spi_data_count)
+				{
+					case 0:
+					spi_data_count = 1;
+					break;
+					
+					case 1:
+					spi_data_count = 2;
+					break;
+					
+					case 2:
+					spi_data_count = 3;
+					break;
+				}
+			}
+			
+			//	End of Preamble
+			if (spi_state == SPI_STATE_PREAMBLE && data == 0xAB && spi_data_count == 3)
+			{
+				spi_state = SPI_STATE_COMMAND;
+				spi_data_count = 0;
+				TRACE("switch.c: Master send preamble received!");
+				return;
+			}
+			// Command bytes
+			if (spi_state == SPI_STATE_COMMAND)
+			{
+				switch(spi_data_count)
+				{
+					case 0:
+					spi_command = data;
+					spi_data_count++;
+					break;
+					
+					case 1:
+					spi_command = data<<8;
+					spi_data_count++;
+					break;
+					
+					case 2:
+					spi_command_size = data<<8;
+					spi_data_count++;
+					break;
+					case 3:
+					spi_command_size += data;
+					spi_state = SPI_STATE_DATA;
+					spi_data_count = 0;
+					TRACE("switch.c: Command received! %d - %d", spi_command, spi_command_size);
+					break;
+				}
+			}
+			
+		}
+		return;
+		
+	} else
+	{
+		if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF)
+		{
+			spi_read(SPI_SLAVE_BASE, &data, &uc_pcs);
+			TRACE("switch.c: %d - %02X (%d)", spi_data_count, data, spi_state);
+
+			//	Start of Preamble
+			if (spi_state == SPI_STATE_PREAMBLE && data == 0xBB)
+			{
+				switch (spi_data_count)
+				{
+					case 0:
+					spi_data_count = 1;
+					spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
+					break;
+					
+					case 1:
+					spi_data_count = 2;
+					spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
+					break;
+					
+					case 2:
+					spi_data_count = 3;
+					spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
+					break;
+				}
+				return;
+			}
+			
+			//	End of Preamble
+			if (spi_state == SPI_STATE_PREAMBLE && data == 0xBC && spi_data_count == 3)
+			{
+				spi_state = SPI_STATE_COMMAND;
+				spi_write(SPI_SLAVE_BASE, data, 0, 0);
+				spi_data_count = 0;
+				TRACE("switch.c: Slave send reamble received!");
+				return;
+			}
+			// Command bytes
+			if (spi_state == SPI_STATE_COMMAND)
+			{
+				switch(spi_data_count)
+				{
+					case 0:
+					spi_command = data;
+					spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
+					spi_data_count++;
+					break;
+					
+					case 1:
+					spi_command = data<<8;
+					spi_write(SPI_SLAVE_BASE, spi_slave_send_size >> 8, 0, 0); // Size
+					spi_data_count++;
+					break;
+					
+					case 2:
+					spi_command_size = data<<8;
+					spi_write(SPI_SLAVE_BASE, spi_slave_send_size, 0, 0); // Size
+					spi_data_count++;
+					break;
+					case 3:
+					spi_command_size += data;
+					spi_state = SPI_STATE_DATA;
+					spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
+					spi_data_count = 0;
+					//TRACE("Master fill received! %d - %d", spi_command, spi_command_size);
+					TRACE("switch.c: Packet Size = 0x%X (%d)", spi_slave_send_size, spi_slave_send_size);
+					break;
+				}
+			}
+			
+			if (spi_state == SPI_STATE_DATA)
+			{
+				ioport_set_pin_level(SPI_IRQ1, false);
+				spi_slave_send = false;
+				TRACE("switch.c: Set Slave to false!");
+				spi_state = SPI_STATE_PREAMBLE;
+				return;
+			}
+		}
+		return;
+	}
+}
\ No newline at end of file
diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h
new file mode 100644
index 0000000..a0a4f53
--- /dev/null
+++ b/ZodiacFX/src/stacking.h
@@ -0,0 +1,20 @@
+/*
+ * stacking.h
+ *
+ * Created: 1/04/2017 5:30:12 PM
+ *  Author: paul
+ */ 
+
+
+#ifndef STACKING_H_
+#define STACKING_H_
+
+#define SPI_Handler     SPI_Handler
+#define SPI_IRQn        SPI_IRQn
+
+void stacking_init(bool master);
+void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size);
+void MasterStackRcv(void);
+
+
+#endif /* STACKING_H_ */
\ No newline at end of file
diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c
index 00f9c42..d7d8689 100644
--- a/ZodiacFX/src/switch.c
+++ b/ZodiacFX/src/switch.c
@@ -33,6 +33,7 @@
 #include "trace.h"
 #include "openflow/openflow.h"
 #include "switch.h"
+#include "stacking.h"
 #include "conf_eth.h"
 #include "command.h"
 
@@ -45,7 +46,6 @@ extern struct tcp_conn tcp_conn;
 extern struct zodiac_config Zodiac_Config;
 extern int OF_Version;
 uint8_t gmacbuffer[GMAC_FRAME_LENTGH_MAX];
-uint8_t spibuffer[1];
 struct ofp10_port_stats phys10_port_stats[4];
 struct ofp13_port_stats phys13_port_stats[4];
 uint8_t port_status[4];
@@ -56,9 +56,6 @@ extern bool stackenabled;
 /** Buffer for ethernet packets */
 static volatile uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX];
 
-/* SPI clock setting (Hz). */
-static uint32_t gs_ul_spi_clock = 500000;
-
 /* GMAC HW configurations */
 #define BOARD_GMAC_PHY_ADDR 0
 /** First Status Command Register - Second Dummy Data */
@@ -66,43 +63,14 @@ static uint32_t gs_ul_spi_clock = 500000;
 #define USART_SPI_DEVICE_ID         1
 #define USART_SPI_BAUDRATE          1000000
 
-/* Chip select. */
-#define SPI_CHIP_SEL 0
-#define SPI_CHIP_PCS spi_get_pcs(SPI_CHIP_SEL)
-/* Clock polarity. */
-#define SPI_CLK_POLARITY 0
-/* Clock phase. */
-#define SPI_CLK_PHASE 0
-/* Delay before SPCK. */
-#define SPI_DLYBS 0x40
-/* Delay between consecutive transfers. */
-#define SPI_DLYBCT 0x10
-
-#define SPI_SLAVE_PREAMBLE		0xAAAAAAAB
-#define SPI_MASTER_PREAMBLE		0xBBBBBBBC
-#define SPI_STATE_PREAMBLE	0
-#define SPI_STATE_COMMAND	1
-#define SPI_STATE_DATA		3
-
 uint8_t stats_rr = 0;
 
-uint32_t *spi_cmd_buffer;
-uint32_t spi_slv_preamble;
-uint8_t spi_state = 0;
-uint16_t spi_data_count = 0;
-uint16_t spi_command, spi_command_size;
-bool spi_slave_send; 
-uint16_t spi_slave_send_size;
-
 // Internal functions
 int readtxbytes(int port);
 int readrxbytes(int port);
 int readtxdrop(int port);
 int readrxdrop(int port);
 int readrxcrcerr(int port);
-void spi_master_initialize(void);
-void spi_slave_initialize(void);
-void stack_mst_write(uint8_t *rx_data, uint16_t ul_size);
 
 
 struct usart_spi_device USART_SPI_DEVICE = {
@@ -122,308 +90,6 @@ void spi_init(void)
 	usart_spi_enable(USART_SPI);
 }
 
-
-void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size)
-{
-	uint32_t cmd_buffer;
-	
-	// Send the preamble mark the beginning of a transfer
-	cmd_buffer = ntohl(SPI_SLAVE_PREAMBLE);
-	stack_mst_write(&cmd_buffer, sizeof(cmd_buffer));
-	
-	// Send a 2 byte command code and 2 byte data code
-	cmd_buffer = ntohl(ul_size);
-	stack_mst_write(&cmd_buffer, sizeof(cmd_buffer));
-	
-	// Send packet
-	stack_mst_write(p_uc_data, ul_size);
-	return;
-}
-
-void MasterStackRcv(void)
-{
-	uint32_t cmd_buffer;
-	
-	TRACE("switch.c: Master received slave IRQ!");
-	// Send the preamble mark the beginning of a transfer
-	cmd_buffer = ntohl(SPI_MASTER_PREAMBLE);
-	stack_mst_write(&cmd_buffer, sizeof(cmd_buffer));
-
-	// Send 4 bytes to receive slave packet size
-	cmd_buffer = 0xFFFFFFFF;
-	stack_mst_write(&cmd_buffer, sizeof(cmd_buffer));
-	TRACE("switch.c: Rcv Size = %04X", cmd_buffer);
-	while(ioport_get_pin_level(SPI_IRQ1));
-}
-
-/*
-*	Write to the SPI stacking interface
-*
-*/
-void stack_mst_write(uint8_t *rx_data, uint16_t ul_size)
-{
-	uint8_t uc_pcs;
-	static uint16_t data;
-	uint8_t *p_buffer;
-	
-	p_buffer = rx_data;
-		
-	for (int i = 0; i < ul_size; i++) {
-		for(int x = 0;x<10000;x++);
-		spi_write(SPI_MASTER_BASE, p_buffer[i], 0, 0);
-		TRACE("switch.c: SPI Write - %d , %02X", i, p_buffer[i]);
-		/* Wait transfer done. */
-		while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0);
-		//spi_read(SPI_MASTER_BASE, p_buffer[i], &uc_pcs);
-		TRACE("switch.c: SPI Read - %d , %02X", i, data);
-	}
-	return;
-}
-
-/*
-*	Initialize the SPI interface to MASTER or SLAVE based on the stacking jumper
-*
-*/
-void stacking_init(bool master)
-{
-	if (master){
-		spi_slave_initialize();
-	} else {
-		spi_master_initialize();
-	}
-	return;
-}
-
-/*
-*	Initialize the SPI interface as a SLAVE
-*
-*/
-void spi_slave_initialize(void)
-{
-	NVIC_DisableIRQ(SPI_IRQn);
-	NVIC_ClearPendingIRQ(SPI_IRQn);
-	NVIC_SetPriority(SPI_IRQn, 0);
-	NVIC_EnableIRQ(SPI_IRQn);
-
-	/* Configure an SPI peripheral. */
-	spi_enable_clock(SPI_SLAVE_BASE);
-	spi_disable(SPI_SLAVE_BASE);
-	spi_reset(SPI_SLAVE_BASE);
-	spi_set_slave_mode(SPI_SLAVE_BASE);
-	spi_disable_mode_fault_detect(SPI_SLAVE_BASE);
-	spi_set_peripheral_chip_select_value(SPI_SLAVE_BASE, SPI_CHIP_SEL);
-	spi_set_clock_polarity(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY);
-	spi_set_clock_phase(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE);
-	spi_set_bits_per_transfer(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT);
-	spi_enable_interrupt(SPI_SLAVE_BASE, SPI_IER_RDRF);
-	spi_enable(SPI_SLAVE_BASE);
-	ioport_set_pin_level(SPI_IRQ1, false);
-}
-
-/*
-*	Initialize the SPI interface as a MASTER
-*
-*/
-void spi_master_initialize(void)
-{
-	/* Configure an SPI peripheral. */
-	spi_enable_clock(SPI_MASTER_BASE);
-	spi_disable(SPI_MASTER_BASE);
-	spi_reset(SPI_MASTER_BASE);
-	spi_set_lastxfer(SPI_MASTER_BASE);
-	spi_set_master_mode(SPI_MASTER_BASE);
-	spi_disable_mode_fault_detect(SPI_MASTER_BASE);
-	spi_disable_loopback(SPI_MASTER_BASE);
-	spi_set_peripheral_chip_select_value(SPI_MASTER_BASE, SPI_CHIP_SEL);
-	//spi_set_fixed_peripheral_select(SPI_MASTER_BASE);
-	//spi_disable_peripheral_select_decode(SPI_MASTER_BASE);
-	spi_set_transfer_delay(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_DLYBS, SPI_DLYBCT);
-	spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT);
-	spi_set_baudrate_div(SPI_MASTER_BASE, SPI_CHIP_SEL, (sysclk_get_cpu_hz() / gs_ul_spi_clock));
-	//spi_configure_cs_behavior(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CS_KEEP_LOW);
-	spi_set_clock_polarity(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY);
-	spi_set_clock_phase(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE);
-
-	spi_enable(SPI_MASTER_BASE);
-}
-
-/*
-*	SPI interface IRQ handler
-*	Used to receive data from the stacking interface
-*
-*/
-void SPI_Handler(void)
-{
-	static uint16_t data;
-	uint8_t uc_pcs;
-
-	if (spi_slave_send == false)
-	{
-		if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF)
-		{
-			spi_read(SPI_SLAVE_BASE, &data, &uc_pcs);
-			//TRACE("%d - %02X", spi_data_count, data);
-
-			if (spi_state == SPI_STATE_DATA)
-			{
-				spibuffer[spi_data_count] = data;
-				spi_data_count++;
-				if (spi_data_count == spi_command_size)
-				{
-					TRACE("switch.c: %d bytes of Data received", spi_data_count);
-					uint8_t* tail_tag = (uint8_t*)(spibuffer + (int)(spi_command_size)-1);
-					uint8_t tag = *tail_tag + 1;
-					TRACE("switch.c: Tag = %d", tag);
-					gmac_write(spibuffer, spi_data_count-1, tag);
-					spi_data_count = 0;
-					spi_state = SPI_STATE_PREAMBLE;
-					return;
-				}
-			}
-
-			//	Start of Preamble
-			if (spi_state == SPI_STATE_PREAMBLE && data == 0xAA)
-			{ 
-				switch (spi_data_count)
-				{
-				case 0:
-					spi_data_count = 1;
-					break;
-				
-				case 1:
-					spi_data_count = 2;
-					break;
-			
-				case 2:
-					spi_data_count = 3;
-					break;
-				}
-			}
-		
-			//	End of Preamble
-			if (spi_state == SPI_STATE_PREAMBLE && data == 0xAB && spi_data_count == 3)
-			{
-				spi_state = SPI_STATE_COMMAND;
-				spi_data_count = 0;
-				TRACE("switch.c: Master send preamble received!");
-				return;
-			}
-			// Command bytes
-			if (spi_state == SPI_STATE_COMMAND)
-			{
-				switch(spi_data_count)
-				{
-					case 0:
-						spi_command = data;
-						spi_data_count++;
-						break;
-					
-					case 1:
-						spi_command = data<<8;
-						spi_data_count++;
-						break;
-					
-					case 2:
-						spi_command_size = data<<8;
-						spi_data_count++;
-						break;
-					case 3:
-						spi_command_size += data;
-						spi_state = SPI_STATE_DATA;
-						spi_data_count = 0;
-						TRACE("switch.c: Command received! %d - %d", spi_command, spi_command_size);
-						break;
-				}
-			}
-		
-		}	
-	return;
-	
-	} else
-	{
-		if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF)
-		{
-			spi_read(SPI_SLAVE_BASE, &data, &uc_pcs);
-			TRACE("switch.c: %d - %02X (%d)", spi_data_count, data, spi_state);
-
-			//	Start of Preamble
-			if (spi_state == SPI_STATE_PREAMBLE && data == 0xBB)
-			{
-				switch (spi_data_count)
-				{
-					case 0:
-					spi_data_count = 1;
-					spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
-					break;
-					
-					case 1:
-					spi_data_count = 2;
-					spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
-					break;
-					
-					case 2:
-					spi_data_count = 3;
-					spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
-					break;
-				}
-				return;
-			}
-			
-			//	End of Preamble
-			if (spi_state == SPI_STATE_PREAMBLE && data == 0xBC && spi_data_count == 3)
-			{
-				spi_state = SPI_STATE_COMMAND;
-				spi_write(SPI_SLAVE_BASE, data, 0, 0);
-				spi_data_count = 0;
-				TRACE("switch.c: Slave send reamble received!");
-				return;
-			}
-			// Command bytes
-			if (spi_state == SPI_STATE_COMMAND)
-			{
-				switch(spi_data_count)
-				{
-					case 0:
-						spi_command = data;
-						spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
-						spi_data_count++;
-						break;
-					
-					case 1:
-						spi_command = data<<8;
-						spi_write(SPI_SLAVE_BASE, spi_slave_send_size >> 8, 0, 0); // Size
-						spi_data_count++;
-						break;
-					
-					case 2:
-						spi_command_size = data<<8;
-						spi_write(SPI_SLAVE_BASE, spi_slave_send_size, 0, 0); // Size
-						spi_data_count++;
-						break;
-					case 3:
-						spi_command_size += data;
-						spi_state = SPI_STATE_DATA;
-						spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
-						spi_data_count = 0;
-						//TRACE("Master fill received! %d - %d", spi_command, spi_command_size);
-						TRACE("switch.c: Packet Size = 0x%X (%d)", spi_slave_send_size, spi_slave_send_size);
-						break;
-				}
-			}
-			
-			if (spi_state == SPI_STATE_DATA)
-			{
-				ioport_set_pin_level(SPI_IRQ1, false);
-				spi_slave_send = false;
-				TRACE("switch.c: Set Slave to false!");
-				spi_state = SPI_STATE_PREAMBLE;
-				return;
-			}
-		}
-	return;		
-	}
-}
-
 /*
 *	Read from the switch registers
 *
@@ -857,9 +523,7 @@ void task_switch(struct netif *netif)
 		} else
 		{
 			TRACE("switch.c: Set Slave to true!");
-			spi_slave_send = true;
-			spi_slave_send_size = ul_rcv_size;
-			ioport_set_pin_level(SPI_IRQ1, true);
+
 			return;
 		}
 	}

From 88c6f9f9a9628b1c2c6f9f470632ae183903c2eb Mon Sep 17 00:00:00 2001
From: Paul Zanna 
Date: Sun, 2 Apr 2017 21:19:04 +1000
Subject: [PATCH 011/169] Fixd port CRC stats

---
 ZodiacFX/src/openflow_spec/openflow_spec10.h | 77 --------------------
 ZodiacFX/src/switch.c                        | 14 +---
 2 files changed, 4 insertions(+), 87 deletions(-)

diff --git a/ZodiacFX/src/openflow_spec/openflow_spec10.h b/ZodiacFX/src/openflow_spec/openflow_spec10.h
index eed501a..0443d05 100644
--- a/ZodiacFX/src/openflow_spec/openflow_spec10.h
+++ b/ZodiacFX/src/openflow_spec/openflow_spec10.h
@@ -827,81 +827,4 @@ struct ofp_vendor_header {
     /* Vendor-defined arbitrary additional data. */
 };
 
-/* All ones is used to indicate all queues in a port (for stats retrieval). */
-#define OFPQ_ALL      0xffffffff
-
-/* Min rate > 1000 means not configured. */
-#define OFPQ_MIN_RATE_UNCFG      0xffff
-
-enum ofp_queue_properties {
-    OFPQT_NONE = 0,       /* No property defined for queue (default). */
-    OFPQT_MIN_RATE,       /* Minimum datarate guaranteed. */
-                          /* Other types should be added here
-                           * (i.e. max rate, precedence, etc). */
-};
-
-/* Common description for a queue. */
-struct ofp_queue_prop_header {
-    uint16_t property;    /* One of OFPQT_. */
-    uint16_t len;         /* Length of property, including this header. */
-    uint8_t pad[4];       /* 64-bit alignemnt. */
-};
-
-/* Min-Rate queue property description. */
-struct ofp_queue_prop_min_rate {
-    struct ofp_queue_prop_header prop_header; /* prop: OFPQT_MIN, len: 16. */
-    uint16_t rate;        /* In 1/10 of a percent; >1000 -> disabled. */
-    uint8_t pad[6];       /* 64-bit alignment */
-};
-
-/* Full description for a queue. */
-struct ofp_packet_queue {
-    uint32_t queue_id;     /* id for the specific queue. */
-    uint16_t len;          /* Length in bytes of this queue desc. */
-    uint8_t pad[2];        /* 64-bit alignment. */
-    struct ofp_queue_prop_header properties[0]; /* List of properties. */
-};
-
-/* Query for port queue configuration. */
-struct ofp_queue_get_config_request {
-    struct ofp_header header;
-    uint16_t port;         /* Port to be queried. Should refer
-                              to a valid physical port (i.e. < OFPP_MAX) */
-    uint8_t pad[2];        /* 32-bit alignment. */
-};
-
-/* Queue configuration for a given port. */
-struct ofp_queue_get_config_reply {
-    struct ofp_header header;
-    uint16_t port;
-    uint8_t pad[6];
-    struct ofp_packet_queue queues[0]; /* List of configured queues. */
-};
-
-/* OFPAT_ENQUEUE action struct: send packets to given queue on port. */
-struct ofp_action_enqueue {
-    uint16_t type;            /* OFPAT_ENQUEUE. */
-    uint16_t len;             /* Len is 16. */
-    uint16_t port;            /* Port that queue belongs. Should
-                                 refer to a valid physical port
-                                 (i.e. < OFPP_MAX) or OFPP_IN_PORT. */
-    uint8_t pad[6];           /* Pad for 64-bit alignment. */
-    uint32_t queue_id;        /* Where to enqueue the packets. */
-};
-
-struct ofp_queue_stats_request {
-    uint16_t port_no;        /* All ports if OFPT_ALL. */
-    uint8_t pad[2];          /* Align to 32-bits. */
-    uint32_t queue_id;       /* All queues if OFPQ_ALL. */
-};
-
-struct ofp_queue_stats {
-    uint16_t port_no;
-    uint8_t pad[2];          /* Align to 32-bits. */
-    uint32_t queue_id;       /* Queue i.d */
-    uint64_t tx_bytes;       /* Number of transmitted bytes. */
-    uint64_t tx_packets;     /* Number of transmitted packets. */
-    uint64_t tx_errors;      /* Number of packets dropped due to overrun. */
-};
-
 #endif /* OPENFLOW_10_H_ */
diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c
index d7d8689..dc9e121 100644
--- a/ZodiacFX/src/switch.c
+++ b/ZodiacFX/src/switch.c
@@ -162,7 +162,6 @@ void disableOF(void)
 	switch_write(53,0);
 	switch_write(69,0);
 	clear_flows();
-
 }
 
 /*
@@ -191,7 +190,7 @@ void update_port_stats(void)
 		phys10_port_stats[stats_rr].rx_bytes += readrxbytes(stats_rr+1);
 		phys10_port_stats[stats_rr].tx_dropped += readtxdrop(stats_rr+1);
 		phys10_port_stats[stats_rr].rx_dropped += readrxdrop(stats_rr+1);
-		phys10_port_stats[stats_rr].rx_crc_err += readrxdrop(stats_rr+1);
+		phys10_port_stats[stats_rr].rx_crc_err += readrxcrcerr(stats_rr+1);
 	}
 
 	if (OF_Version == 4)
@@ -200,7 +199,7 @@ void update_port_stats(void)
 		phys13_port_stats[stats_rr].rx_bytes += readrxbytes(stats_rr+1);
 		phys13_port_stats[stats_rr].tx_dropped += readtxdrop(stats_rr+1);
 		phys13_port_stats[stats_rr].rx_dropped += readrxdrop(stats_rr+1);
-		phys13_port_stats[stats_rr].rx_crc_err += readrxdrop(stats_rr+1);
+		phys13_port_stats[stats_rr].rx_crc_err += readrxcrcerr(stats_rr+1);
 	}
 	stats_rr++;
 	if (stats_rr == 4) stats_rr = 0;
@@ -301,7 +300,7 @@ void update_port_status(void)
 	last_port_status[0] = port_status[0];
 	last_port_status[1] = port_status[1];
 	last_port_status[2] = port_status[2];
-	last_port_status[3] = port_status[2];
+	last_port_status[3] = port_status[3];
 	// Update port status
 	port_status[0] = (switch_read(30) & 32) >> 5;
 	port_status[1] = (switch_read(46) & 32) >> 5;
@@ -381,12 +380,7 @@ void switch_init(void)
 		/* Fill in GMAC options */
 		gmac_option.uc_copy_all_frame = 1;
 		gmac_option.uc_no_boardcast = 0;
-		gmac_option.uc_mac_addr[0] = Zodiac_Config.MAC_address[0];
-		gmac_option.uc_mac_addr[1] = Zodiac_Config.MAC_address[1];
-		gmac_option.uc_mac_addr[2] = Zodiac_Config.MAC_address[2];
-		gmac_option.uc_mac_addr[3] = Zodiac_Config.MAC_address[3];
-		gmac_option.uc_mac_addr[4] = Zodiac_Config.MAC_address[4];
-		gmac_option.uc_mac_addr[5] = Zodiac_Config.MAC_address[5];
+		memcpy(gmac_option.uc_mac_addr, Zodiac_Config.MAC_address, 6);
 		gs_gmac_dev.p_hw = GMAC;
 
 		/* Init KSZ8795 registers */

From e3bdf4e0c08abadd77b605cb169efafe28ff7fdb Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 3 Apr 2017 14:07:40 +1000
Subject: [PATCH 012/169] Change firmware offset

---
 ZodiacFX/ZodiacFX.cproj | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ZodiacFX/ZodiacFX.cproj b/ZodiacFX/ZodiacFX.cproj
index c3965ce..ab4e3bd 100644
--- a/ZodiacFX/ZodiacFX.cproj
+++ b/ZodiacFX/ZodiacFX.cproj
@@ -368,7 +368,7 @@
   
   True
   
-  -Wl,--defsym,__stack_size__=0x1400 -Wl,--entry=Reset_Handler -Wl,-section-start=.text=0x00420000 -Wl,--cref -mthumb -T../src/ASF/sam/utils/linker_scripts/sam4e/sam4e8/gcc/flash.ld
+  -Wl,--defsym,__stack_size__=0x1400 -Wl,--entry=Reset_Handler -Wl,-section-start=.text=0x00410000 -Wl,--cref -mthumb -T../src/ASF/sam/utils/linker_scripts/sam4e/sam4e8/gcc/flash.ld
   
     
       ../src/ASF/sam/drivers/efc

From 13db3c18070aea7c606d5cb9eb40f7669044f612 Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 3 Apr 2017 14:13:56 +1000
Subject: [PATCH 013/169] Update update buffer start region

Moved from 0x00450000 to 0x00448000 (region expanded by 32k)
---
 ZodiacFX/src/flash.c | 2 +-
 ZodiacFX/src/flash.h | 4 +---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/ZodiacFX/src/flash.c b/ZodiacFX/src/flash.c
index 065a6be..91055a8 100644
--- a/ZodiacFX/src/flash.c
+++ b/ZodiacFX/src/flash.c
@@ -67,7 +67,7 @@ void get_serial(uint32_t *uid_buf)
 */
 int firmware_update_init(void)
 {	
-	flash_page_addr = NEW_FW_BASE;
+	flash_page_addr = FLASH_BUFFER;
 	
 	/* Initialize flash: 6 wait states for flash writing. */
 	ul_rc = flash_init(FLASH_ACCESS_MODE_128, 6);
diff --git a/ZodiacFX/src/flash.h b/ZodiacFX/src/flash.h
index 7c25a9e..8d8969e 100644
--- a/ZodiacFX/src/flash.h
+++ b/ZodiacFX/src/flash.h
@@ -53,10 +53,8 @@ struct verification_data
 #define X_NAK 0x15
 
 #define ERASE_SECTOR_SIZE	8192
-#define NEW_FW_BASE			(IFLASH_ADDR + (5*IFLASH_NB_OF_PAGES/8)*IFLASH_PAGE_SIZE)
-#define NEW_FW_MAX_SIZE		196608
 
-#define FLASH_BUFFER 0x450000
+#define FLASH_BUFFER 0x448000
 #define FLASH_BUFFER_END 0x480000
 
 #define NN_VERIFICATION_LEN	8

From ab2dae5d23dcb1dbc17c42b277a1c3bc78b3c52d Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 3 Apr 2017 14:17:55 +1000
Subject: [PATCH 014/169] Change flash erase method

---
 ZodiacFX/src/flash.c | 9 ++++-----
 ZodiacFX/src/flash.h | 2 --
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/ZodiacFX/src/flash.c b/ZodiacFX/src/flash.c
index 91055a8..5be14fe 100644
--- a/ZodiacFX/src/flash.c
+++ b/ZodiacFX/src/flash.c
@@ -92,19 +92,18 @@ int firmware_update_init(void)
 		unlock_address += IFLASH_LOCK_REGION_SIZE;
 	}
 
-	// Erase 192k
+	// Erase 32 pages at a time
 	uint32_t erase_address = flash_page_addr;
-	while(erase_address < IFLASH_ADDR + IFLASH_SIZE - (ERASE_SECTOR_SIZE - 1))
+	while(erase_address < FLASH_BUFFER_END)
 	{
-		//printf("-I- Erasing sector with address: 0x%08x\r\n", erase_address);
-		ul_rc = flash_erase_sector(erase_address);
+		ul_rc = flash_erase_page(erase_address, IFLASH_ERASE_PAGES_32);
 		if (ul_rc != FLASH_RC_OK)
 		{
 			//printf("-F- Flash programming error %lu\n\r", (unsigned long)ul_rc);
 			return 0;
 		}
 		
-		erase_address += ERASE_SECTOR_SIZE;
+		erase_address += ((uint8_t)32*IFLASH_PAGE_SIZE);
 	}
 	
 	return 1;
diff --git a/ZodiacFX/src/flash.h b/ZodiacFX/src/flash.h
index 8d8969e..f08c547 100644
--- a/ZodiacFX/src/flash.h
+++ b/ZodiacFX/src/flash.h
@@ -52,8 +52,6 @@ struct verification_data
 #define X_ACK 0x06
 #define X_NAK 0x15
 
-#define ERASE_SECTOR_SIZE	8192
-
 #define FLASH_BUFFER 0x448000
 #define FLASH_BUFFER_END 0x480000
 

From 296a37791a9ec73faf6f5872b4851a750edf98bb Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 3 Apr 2017 14:20:58 +1000
Subject: [PATCH 015/169] Cleanup flash.c

---
 ZodiacFX/src/flash.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/ZodiacFX/src/flash.c b/ZodiacFX/src/flash.c
index 5be14fe..0b3ae5c 100644
--- a/ZodiacFX/src/flash.c
+++ b/ZodiacFX/src/flash.c
@@ -47,8 +47,6 @@ static uint32_t page_addr;
 
 static	uint32_t flash_page_addr;
 static	uint32_t ul_rc;
-static	uint32_t ul_idx;
-static	uint32_t ul_page_buffer[IFLASH_PAGE_SIZE / sizeof(uint32_t)];
 
 
 /*
@@ -340,7 +338,7 @@ int xmodem_xfer(void)
 *	Remove XMODEM 0x1A padding at end of data
 *
 */
-xmodem_clear_padding(uint8_t *buff)
+void xmodem_clear_padding(uint8_t *buff)
 {
 	int len = IFLASH_PAGE_SIZE;
 	

From 5f51fbccce327e844c1a79696ae38c923257ec23 Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 3 Apr 2017 16:49:37 +1000
Subject: [PATCH 016/169] Add error-check for boundary read

---
 ZodiacFX/src/http.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index 1a2cf34..eaf58a7 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -1557,7 +1557,7 @@ static uint8_t upload_handler(char *payload, int len)
 			// Store the discovered boundary
 			char tmpID[BOUNDARY_MAX_LEN] = {0};
 			int z = 0;
-			while(z < BOUNDARY_MAX_LEN && *(py+z) != '\x2d' && *(py+z) != '\x0d' && *(py+z) != '\x0a')
+			while(z < BOUNDARY_MAX_LEN && *(py+z) != '\x2d' && *(py+z) != '\x0d' && *(py+z) != '\x0a' && (py+z) < payload+len)
 			{
 				tmpID[z] = *(py+z);
 				z++;

From 2160fd23e62306e49a3da496372fcc3d33625319 Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 3 Apr 2017 16:52:28 +1000
Subject: [PATCH 017/169] Add Content-Length check for file upload

Use Content-Length if only partial boundary is found
---
 ZodiacFX/src/http.c | 46 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)

diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index eaf58a7..4d18301 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -81,6 +81,7 @@ static uint8_t meterBase = 0;		// Current set of meters to display
 static struct tcp_pcb * upload_pcb;	// Firmware upload connection check (pcb pointer)
 static int upload_port = 0;
 static int upload_timer = 0;		// Timer for firmware upload timeout
+static uint32_t bin_content_length = 0;				// HTTP Content-Length of upload binary
 static struct http_conns http_conn[MAX_CONN];	// http connection status
 
 // Flag variables
@@ -625,6 +626,28 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err
 					// Initialize timeout value
 					upload_timer = sys_get_ms();
 					
+					// Get content-length
+					if(strstr(http_payload, "Content-Length: ") != NULL)
+					{
+						char *ptmp = NULL;
+						ptmp = strstr(http_payload, "Content-Length: ");
+						ptmp += (strlen("Content-Length: "));
+				
+						char tmpbuff[8] = {'\0'};
+						i = 0;
+						while(i < 7 && *ptmp != '\x2d' && *ptmp != '\x0d' && *ptmp != '\x0a')
+						{
+							tmpbuff[i] = *ptmp;
+					
+							ptmp++;
+							i++;
+						}
+				
+						bin_content_length = atoi(tmpbuff);
+				
+						TRACE("http.c: Content-Length: %d", bin_content_length);
+					}
+					
 					upload_handler(http_payload, len);
 				}
 				else if(strcmp(post_msg,"save_config") == 0)
@@ -1422,6 +1445,7 @@ static uint8_t upload_handler(char *payload, int len)
 		upload_pcb = NULL;								// Clear pcb connection pointer
 		upload_timer = 0;								// Clear upload timeout
 		total_handled_bytes = 0;
+		bin_content_length = 0;
 		return 1;
 	}
 	
@@ -1581,9 +1605,25 @@ static uint8_t upload_handler(char *payload, int len)
 			}
 			else
 			{
-				TRACE("http.c: boundary IDs do not match");
-				i = 1;
-				// 'i' will be decremented to 0 if this line is run
+				// Check if we've handled near the specified bytes
+				if(bin_content_length && total_handled_bytes + len + saved_bytes >= bin_content_length)
+				{
+					// Move end pointer back before the boundary (valid data)
+					while(*(py-1) == '\x0d' || *(py-1) == '\x0a' || *(py-1) == '\x2d')
+					{
+						py--;
+					}
+				
+					TRACE("http.c: Content-Length match");
+						
+					i = 0;	// Signal completion
+				}
+				else
+				{
+					TRACE("http.c: boundary IDs do not match");
+					i = 1;
+					// 'i' will be decremented to 0 if this line is run
+				}
 			}
 		}
 		i--;

From ea44c8095049fb79afdc046f7ffed675aa223256 Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Tue, 4 Apr 2017 14:11:39 +1000
Subject: [PATCH 018/169] Rename DSCP remark struct name

Adjusted to fit with naming scheme of v1.3
---
 ZodiacFX/src/openflow_spec/openflow_spec13.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ZodiacFX/src/openflow_spec/openflow_spec13.h b/ZodiacFX/src/openflow_spec/openflow_spec13.h
index 7905b94..df6d5e1 100644
--- a/ZodiacFX/src/openflow_spec/openflow_spec13.h
+++ b/ZodiacFX/src/openflow_spec/openflow_spec13.h
@@ -840,7 +840,7 @@ struct ofp13_meter_band_drop {
 };
 
 /* OFPMBT_DSCP_REMARK band - Remark DSCP in the IP header */
-struct ofp_meter_band_dscp_remark {
+struct ofp13_meter_band_dscp_remark {
     uint16_t        type;    /* OFPMBT_DSCP_REMARK. */
     uint16_t        len;     /* Length in bytes of this band. */
     uint32_t        rate;    /* Rate for remarking packets. */

From fc2127041b85619fab532c8ae20c3fd9047260f8 Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Tue, 4 Apr 2017 15:39:03 +1000
Subject: [PATCH 019/169] Add DSCP meter band precedence support

---
 ZodiacFX/src/openflow/openflow_13.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c
index 7de7391..a41bf80 100644
--- a/ZodiacFX/src/openflow/openflow_13.c
+++ b/ZodiacFX/src/openflow/openflow_13.c
@@ -2093,6 +2093,12 @@ void meter_add13(struct ofp_header *msg)
 			ptr_band->rate			= ntohl(ptr_rxband->rate);
 			ptr_band->burst_size	= ntohl(ptr_rxband->burst_size);
 			
+			// Copy DSCP precedence level
+			if(ptr_band->type == OFPMBT13_DSCP_REMARK)
+			{
+				((struct ofp13_meter_band_dscp_remark*)ptr_band)->prec_level = ((struct ofp13_meter_band_dscp_remark*)ptr_rxband)->prec_level;
+			}
+			
 			ptr_band++;		// Move to next band storage location
 			ptr_rxband++;	// Move to next received band
 			bands_processed++;
@@ -2210,6 +2216,12 @@ void meter_modify13(struct ofp_header *msg)
 			ptr_band->rate			= ntohl(ptr_rxband->rate);
 			ptr_band->burst_size	= ntohl(ptr_rxband->burst_size);
 			
+			// Copy DSCP precedence level
+			if(ptr_band->type == OFPMBT13_DSCP_REMARK)
+			{
+				((struct ofp13_meter_band_dscp_remark*)ptr_band)->prec_level = ((struct ofp13_meter_band_dscp_remark*)ptr_rxband)->prec_level;
+			}
+			
 			// ***** TODO : add error checking for band processing
 			TRACE("openflow_13.c: %d of %d bands processed", bands_processed, bands_received);
 			

From eee8468d52c68b34b7f3398fc2e167dc5e4d33cc Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Tue, 4 Apr 2017 16:16:19 +1000
Subject: [PATCH 020/169] Display DSCP remark in CLI & web interface

---
 ZodiacFX/src/command.c | 7 ++++++-
 ZodiacFX/src/http.c    | 9 +++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c
index 2df0d2f..d8e1152 100644
--- a/ZodiacFX/src/command.c
+++ b/ZodiacFX/src/command.c
@@ -1544,7 +1544,7 @@ void command_openflow(char *command, char *param1, char *param2, char *param3)
 						}
 						else if(ptr_band->type == OFPMBT13_DSCP_REMARK)
 						{
-							printf("DSCP REMARK (unsupported)\r\n");
+							printf("DSCP REMARK\r\n");
 						}
 						else
 						{
@@ -1553,6 +1553,11 @@ void command_openflow(char *command, char *param1, char *param2, char *param3)
 						printf("\t\t  Rate:\t\t%d\t\r\n", ptr_band->rate);
 						printf("\t\t  Burst Size:\t%d\t\r\n", ptr_band->burst_size);
 						
+						if(ptr_band->type == OFPMBT13_DSCP_REMARK)
+						{
+							printf("\t\t  Precedence:\t+%d\t\r\n", ((struct ofp13_meter_band_dscp_remark*)ptr_band)->prec_level);
+						}
+						
 						// Find band index
 						int band_index = ((uint8_t*)ptr_band - (uint8_t*)&(meter_entry[meter_index]->bands)) / sizeof(struct ofp13_meter_band_drop);
 						
diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index 1a2cf34..772ef27 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -3585,7 +3585,7 @@ static uint8_t interfaceCreate_Display_Meters(void)
 				}
 				else if(ptr_band->type == OFPMBT13_DSCP_REMARK)
 				{
-					snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),"DSCP REMARK (unsupported)\r\n");
+					snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),"DSCP REMARK\r\n");
 				}
 				else
 				{
@@ -3593,7 +3593,12 @@ static uint8_t interfaceCreate_Display_Meters(void)
 				}
 				snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),"\t\t  Rate:\t\t%d\t\r\n", ptr_band->rate);
 				snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),"\t\t  Burst Size:\t%d\t\r\n", ptr_band->burst_size);
-					
+				
+				if(ptr_band->type == OFPMBT13_DSCP_REMARK)
+				{
+					snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),"\t\t  Precedence:\t+%d\t\r\n", ((struct ofp13_meter_band_dscp_remark*)ptr_band)->prec_level);
+				}
+				
 				// Find band index
 				int band_index = ((uint8_t*)ptr_band - (uint8_t*)&(meter_entry[meter_index]->bands)) / sizeof(struct ofp13_meter_band_drop);
 					

From 507c387a3f90a7281b6d2a39572086e2425d42da Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Tue, 4 Apr 2017 18:31:37 +1000
Subject: [PATCH 021/169] Add DSCP support (WIP)

---
 ZodiacFX/src/openflow/of_helper.c   | 35 ++++++++++++++++++++---------
 ZodiacFX/src/openflow/openflow.h    |  4 ++++
 ZodiacFX/src/openflow/openflow_13.c | 32 +++++++++++++++++++++++++-
 3 files changed, 60 insertions(+), 11 deletions(-)

diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c
index db2f6b2..d90384f 100644
--- a/ZodiacFX/src/openflow/of_helper.c
+++ b/ZodiacFX/src/openflow/of_helper.c
@@ -1273,8 +1273,9 @@ int flow_stats_msg13(char *buffer, int first, int last)
 *	@param	id		- meter ID to process
 *	@param	bytes	- packet size (for throughput calculations)
 *
-*	@ret	SUCCESS	- packet does not need to be dropped
-*	@ret	FAILURE	- packet needs to be dropped
+*	@ret	METER_NOACT	- no action needs to be taken
+*	@ret	METER_DROP	- packet needs to be dropped
+*	@ret	val			- increase encoded drop precedence by val (DSCP remark)
 *
 */
 int	meter_handler(uint32_t id, uint16_t bytes)
@@ -1296,7 +1297,7 @@ int	meter_handler(uint32_t id, uint16_t bytes)
 	if(meter_entry[meter_index] == NULL || meter_index == MAX_METER_13)
 	{
 		TRACE("of_helper.c: meter entry not found - packet not dropped");
-		return SUCCESS;
+		return METER_NOACT;
 	}
 	// meter_index now holds the meter bound to the current flow
 	
@@ -1311,7 +1312,7 @@ int	meter_handler(uint32_t id, uint16_t bytes)
 		meter_entry[meter_index]->last_packet_in = sys_get_ms();
 		
 		TRACE("of_helper.c: first hit of meter - packet not dropped");
-		return SUCCESS;
+		return METER_NOACT;
 	}
 	
 	// Find time delta
@@ -1335,7 +1336,7 @@ int	meter_handler(uint32_t id, uint16_t bytes)
 	else
 	{
 		TRACE("of_helper.c: unsupported meter configuration - packet not dropped");
-		return SUCCESS;
+		return METER_NOACT;
 	}
 	
 	// Check each band
@@ -1363,14 +1364,14 @@ int	meter_handler(uint32_t id, uint16_t bytes)
 	if(highest_rate == 0 || ptr_highest_band == NULL)
 	{
 		TRACE("of_helper.c: no bands triggered - packet not dropped");
-		return SUCCESS;
+		return METER_NOACT;
 	}
 	
 	// Check band type
-	if(ptr_highest_band->type != OFPMBT13_DROP)
+	if(ptr_highest_band->type != OFPMBT13_DROP && ptr_highest_band->type != OFPMBT13_DSCP_REMARK)
 	{
 		TRACE("of_helper.c: unsupported band type - not dropping packet");
-		return SUCCESS;
+		return METER_NOACT;
 	}
 	
 	TRACE("of_helper.c: highest triggered band rate:%d", highest_rate);
@@ -1383,8 +1384,22 @@ int	meter_handler(uint32_t id, uint16_t bytes)
 	band_stats_array[meter_index].band_stats[band_index].byte_band_count += bytes;
 	band_stats_array[meter_index].band_stats[band_index].packet_band_count++;
 
-	TRACE("of_helper.c: packet needs to be dropped");	
-	return FAILURE;
+	if(ptr_highest_band->type == OFPMBT13_DROP)
+	{
+		TRACE("of_helper.c: packet dropped");
+		return METER_DROP;
+	}
+	else if(ptr_highest_band->type == OFPMBT13_DSCP_REMARK)
+	{
+		struct ofp13_meter_band_dscp_remark * ptr_dscp_band = ptr_highest_band;
+		int prec_increase = (int)(ptr_dscp_band->prec_level);
+		
+		TRACE("of_helper.c: DSCP drop precedence needs to be increased by %d", prec_increase);
+		return prec_increase;
+	}
+	
+	TRACE("of_helper.c: ERROR - unknown band type");
+	return METER_NOACT;
 }
 
 /*
diff --git a/ZodiacFX/src/openflow/openflow.h b/ZodiacFX/src/openflow/openflow.h
index ad8e60f..87b2f72 100644
--- a/ZodiacFX/src/openflow/openflow.h
+++ b/ZodiacFX/src/openflow/openflow.h
@@ -130,4 +130,8 @@ void port_status_message13(uint8_t port);
 #define SUCCESS		0
 #define FAILURE		1
 
+// Meter processing defines
+#define METER_DROP	-1	// drop packet
+#define METER_NOACT	0	// no action
+
 #endif /* OPENFLOW_H_ */
diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c
index a41bf80..8b16985 100644
--- a/ZodiacFX/src/openflow/openflow_13.c
+++ b/ZodiacFX/src/openflow/openflow_13.c
@@ -146,11 +146,41 @@ void nnOF13_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port)
 		if(insts[OFPIT13_METER] != NULL)
 		{
 			struct ofp13_instruction_meter *inst_meter = insts[OFPIT13_METER];
-			if(meter_handler(ntohl(inst_meter->meter_id), packet_size) == FAILURE)	// Process meter id (provide byte count for counters)
+			int meter_ret = meter_handler(ntohl(inst_meter->meter_id), packet_size);
+			if(meter_ret == METER_DROP)	// Process meter id (provide byte count for counters)
 			{
 				// Packet must be dropped
+				TRACE("openflow_13.c: dropping packet");
 				return;
 			}
+			else if(meter_ret == METER_NOACT)
+			{
+				TRACE("openflow_13.c: no action taken");
+			}
+			else
+			{
+				if(meter_ret > 0)
+				{
+					int prec_increase = meter_ret;
+					
+					if (fields.eth_prot == htons(0x0800))
+					{
+						TRACE("openflow_13.c: increasing encoded drop precedence by %d", prec_increase);
+
+						// Copy set field value to oxm
+						struct ip_hdr *hdr = fields.payload;
+						uint8_t prec_level = IPH_TOS(hdr);
+						TRACE("openflow_13.c: header current TOS field - %d", (int)prec_level);
+						//IPH_TOS_SET(hdr, (oxm_value[0]<<2)|(IPH_TOS(hdr)&0x3));
+						// Recalculate IP checksum
+						//set_ip_checksum(p_uc_data, packet_size, fields.payload + 14);
+					}
+				}
+				else
+				{
+					TRACE("openflow_13.c: ERROR - unhandled meter_handler return value");
+				}
+			}
 		}
 			
 		if(insts[OFPIT13_APPLY_ACTIONS] != NULL)

From fdeeaeef7c6fa28b5a1a0f0dded03c6b10619e44 Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Wed, 5 Apr 2017 10:41:08 +1000
Subject: [PATCH 022/169] Add support for DSCP remark (metering)

---
 ZodiacFX/src/openflow/openflow_13.c | 30 +++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c
index 8b16985..2c50fd6 100644
--- a/ZodiacFX/src/openflow/openflow_13.c
+++ b/ZodiacFX/src/openflow/openflow_13.c
@@ -167,13 +167,35 @@ void nnOF13_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port)
 					{
 						TRACE("openflow_13.c: increasing encoded drop precedence by %d", prec_increase);
 
-						// Copy set field value to oxm
+						// Retrieve TOS field
 						struct ip_hdr *hdr = fields.payload;
 						uint8_t prec_level = IPH_TOS(hdr);
 						TRACE("openflow_13.c: header current TOS field - %d", (int)prec_level);
-						//IPH_TOS_SET(hdr, (oxm_value[0]<<2)|(IPH_TOS(hdr)&0x3));
-						// Recalculate IP checksum
-						//set_ip_checksum(p_uc_data, packet_size, fields.payload + 14);
+						// Isolate the drop precedence value (3 bits)
+						prec_level = (prec_level & 0x1C) >> 2;
+						// Check that value is valid ( 2 || 4 || 6 )
+						if( prec_level == 2 || prec_level == 4 || prec_level == 6)
+						{
+							// Increase drop precedence level by specified value
+							TRACE("openflow_13.c: increasing drop precedence level by %d", prec_increase);
+							prec_level = 2*(prec_level/2 + prec_increase);
+							// Ensure drop precedence value is valid
+							if(prec_level > 6)
+							{
+								prec_level = 6;
+							}
+							// Write new precedence to TOS field
+							TRACE("openflow_13.c: header new TOS field - %d", (prec_level<<2)|(IPH_TOS(hdr)&0xE3))
+							IPH_TOS_SET(hdr, (prec_level<<2)|(IPH_TOS(hdr)&0xE3));
+													
+							// Recalculate IP checksum
+							set_ip_checksum(p_uc_data, packet_size, fields.payload + 14);
+						}
+						else
+						{
+							TRACE("openflow_13.c: invalid drop precedence value - no adjustments made");
+						}
+
 					}
 				}
 				else

From 2df3e418a7dee94d2c0938064dece118eb60b53e Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Wed, 5 Apr 2017 11:36:37 +1000
Subject: [PATCH 023/169] Update meter features reply

---
 ZodiacFX/src/openflow/openflow_13.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c
index 2c50fd6..72a3c83 100644
--- a/ZodiacFX/src/openflow/openflow_13.c
+++ b/ZodiacFX/src/openflow/openflow_13.c
@@ -1539,7 +1539,7 @@ int multi_meter_features_reply13(uint8_t *buffer, struct ofp13_multipart_request
 	
 	// Format reply with meter features
 	meter_features.max_meter	= htonl(MAX_METER_13);
-	meter_features.band_types	= htonl(2);		// Only OFPMBT_DROP supported
+	meter_features.band_types	= htonl(OFPMBT13_DSCP_REMARK | OFPMBT13_DROP);		// Only OFPMBT_DROP supported
 	meter_features.capabilities	= htonl(OFPMF13_KBPS | OFPMF13_PKTPS);
 	meter_features.max_bands	= MAX_METER_BANDS_13;
 	meter_features.max_color	= 0;

From 929c2df7e3b9a8f8a45778e7be1695ae7c220594 Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Wed, 5 Apr 2017 11:38:23 +1000
Subject: [PATCH 024/169] Revert "Add Content-Length check for file upload"

This reverts commit 2160fd23e62306e49a3da496372fcc3d33625319.
---
 ZodiacFX/src/http.c | 46 +++------------------------------------------
 1 file changed, 3 insertions(+), 43 deletions(-)

diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index 4d18301..eaf58a7 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -81,7 +81,6 @@ static uint8_t meterBase = 0;		// Current set of meters to display
 static struct tcp_pcb * upload_pcb;	// Firmware upload connection check (pcb pointer)
 static int upload_port = 0;
 static int upload_timer = 0;		// Timer for firmware upload timeout
-static uint32_t bin_content_length = 0;				// HTTP Content-Length of upload binary
 static struct http_conns http_conn[MAX_CONN];	// http connection status
 
 // Flag variables
@@ -626,28 +625,6 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err
 					// Initialize timeout value
 					upload_timer = sys_get_ms();
 					
-					// Get content-length
-					if(strstr(http_payload, "Content-Length: ") != NULL)
-					{
-						char *ptmp = NULL;
-						ptmp = strstr(http_payload, "Content-Length: ");
-						ptmp += (strlen("Content-Length: "));
-				
-						char tmpbuff[8] = {'\0'};
-						i = 0;
-						while(i < 7 && *ptmp != '\x2d' && *ptmp != '\x0d' && *ptmp != '\x0a')
-						{
-							tmpbuff[i] = *ptmp;
-					
-							ptmp++;
-							i++;
-						}
-				
-						bin_content_length = atoi(tmpbuff);
-				
-						TRACE("http.c: Content-Length: %d", bin_content_length);
-					}
-					
 					upload_handler(http_payload, len);
 				}
 				else if(strcmp(post_msg,"save_config") == 0)
@@ -1445,7 +1422,6 @@ static uint8_t upload_handler(char *payload, int len)
 		upload_pcb = NULL;								// Clear pcb connection pointer
 		upload_timer = 0;								// Clear upload timeout
 		total_handled_bytes = 0;
-		bin_content_length = 0;
 		return 1;
 	}
 	
@@ -1605,25 +1581,9 @@ static uint8_t upload_handler(char *payload, int len)
 			}
 			else
 			{
-				// Check if we've handled near the specified bytes
-				if(bin_content_length && total_handled_bytes + len + saved_bytes >= bin_content_length)
-				{
-					// Move end pointer back before the boundary (valid data)
-					while(*(py-1) == '\x0d' || *(py-1) == '\x0a' || *(py-1) == '\x2d')
-					{
-						py--;
-					}
-				
-					TRACE("http.c: Content-Length match");
-						
-					i = 0;	// Signal completion
-				}
-				else
-				{
-					TRACE("http.c: boundary IDs do not match");
-					i = 1;
-					// 'i' will be decremented to 0 if this line is run
-				}
+				TRACE("http.c: boundary IDs do not match");
+				i = 1;
+				// 'i' will be decremented to 0 if this line is run
 			}
 		}
 		i--;

From 9899fef89995ff5bda4b5424ad5cf9ab0d0cdcc5 Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Wed, 5 Apr 2017 13:40:59 +1000
Subject: [PATCH 025/169] Add edge-case handling for upload boundary detection

---
 ZodiacFX/src/flash.c |   3 +-
 ZodiacFX/src/http.c  | 278 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 279 insertions(+), 2 deletions(-)

diff --git a/ZodiacFX/src/flash.c b/ZodiacFX/src/flash.c
index 0b3ae5c..9e28d16 100644
--- a/ZodiacFX/src/flash.c
+++ b/ZodiacFX/src/flash.c
@@ -40,12 +40,12 @@
 // Global variables
 extern uint8_t shared_buffer[SHARED_BUFFER_LEN];
 struct verification_data verify;
+uint32_t flash_page_addr;
 
 // Static variables
 static uint32_t page_addr;
 //static uint32_t ul_rc;
 
-static	uint32_t flash_page_addr;
 static	uint32_t ul_rc;
 
 
@@ -367,4 +367,3 @@ void xmodem_clear_padding(uint8_t *buff)
 	
 	return;	// Padding characters removed
 }
-
diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index eaf58a7..e068ae3 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -54,6 +54,7 @@ extern struct tcp_pcb *tcp_pcb;
 extern int OF_Version;
 extern uint8_t shared_buffer[SHARED_BUFFER_LEN];	// SHARED_BUFFER_LEN must never be reduced below 2048
 extern int tcp_con_state;	// Check connection state
+extern uint32_t flash_page_addr;
 
 extern struct ofp_flow_mod *flow_match10[MAX_FLOWS_10];
 extern struct ofp13_flow_mod *flow_match13[MAX_FLOWS_13];
@@ -1669,6 +1670,145 @@ static uint8_t upload_handler(char *payload, int len)
 			TRACE("http.c: %d bytes saved", saved_bytes);
 			
 			total_handled_bytes += handled_bytes;
+			
+			/* Handle partial boundary scenarios */
+			uint32_t curr_addr = flash_page_addr - IFLASH_PAGE_SIZE;	// Get start address of previously-written page
+			if(curr_addr > FLASH_BUFFER && curr_addr < FLASH_BUFFER_END)
+			{
+				memset(&shared_buffer, 0, SHARED_BUFFER_LEN);	// Clear shared_buffer
+				uint8_t * p_addr = curr_addr;					// Create a working pointer at flash page start
+				uint16_t ct = 0;								// shared buffer index
+				// Copy page into shared buffer
+				for(ct;ct<512;ct++)
+				{
+					shared_buffer[ct] = *p_addr;
+					p_addr++;
+				}
+				// Copy any saved bytes into the shared buffer
+				if(saved_bytes)
+				{
+					// Current page needs to be appended to the previously-written page
+					uint16_t ind = 0;
+					for(ind;ind0)
+				{
+					wind--;
+					// Latch onto '----' ("----[boundary ID]")
+					if(shared_buffer[wind-1] == '\x2d' && shared_buffer[wind-2] == '\x2d' && shared_buffer[wind-3] == '\x2d' && shared_buffer[wind-4] == '\x2d')
+					{
+						// Store the discovered boundary
+						char tmpID[BOUNDARY_MAX_LEN] = {0};
+						int z = 0;
+						while(z < BOUNDARY_MAX_LEN && shared_buffer[wind+z] != '\x2d' && shared_buffer[wind+z] != '\x0d' && shared_buffer[wind+z] != '\x0a' && (wind+z) < ct)
+						{
+							tmpID[z] = shared_buffer[wind+z];
+							z++;
+						}
+			
+						TRACE("http.c: discovered boundary ID : %s (shared buffer check)", tmpID);
+			
+						// Match the boundary ID with stored ID
+						if(strcmp(tmpID, boundary_ID) == 0)
+						{
+							TRACE("http.c: boundary IDs match");
+							TRACE("http.c: moving data end pointer");
+							// Traverse through the preceding newline characters
+							while(shared_buffer[wind-1] == '\x0d' || shared_buffer[wind-1] == '\x0a' || shared_buffer[wind-1] == '\x2d')
+							{
+								wind--;
+							}
+					
+							// Overwrite previous page
+							flash_page_addr = curr_addr;	// Move page write address to overwrite previous page
+							// Fill 512-byte array
+							int j = 0;
+							while(j < IFLASH_PAGE_SIZE)
+							{
+								if(j < wind)
+								{
+									// Write data
+									page[j] = shared_buffer[j];
+									//handled_bytes++;
+								}
+								else
+								{
+									// Append 0xFF
+									page[j] = 0xFF;
+								}
+
+								j++;
+							}
+								
+							// Write to page
+							if(flash_write_page(&page))
+							{
+								TRACE("http.c: page written successfully");
+								page_ctr++;
+							}
+							else
+							{
+								TRACE("http.c: page write FAILED");
+							}
+							
+							if(j= FLASH_BUFFER_END)
+			{
+				TRACE("http.c: ERROR - flash upper limit reached");
+			}
+			
 			return 1;
 		}
 		else
@@ -1807,6 +1947,144 @@ static uint8_t upload_handler(char *payload, int len)
 	total_handled_bytes += handled_bytes;
 	TRACE("http.c: total_handled_bytes: %d", total_handled_bytes);
 	
+	/* Handle partial boundary scenarios */
+	uint32_t curr_addr = flash_page_addr - IFLASH_PAGE_SIZE;	// Get start address of previously-written page
+	if(curr_addr > FLASH_BUFFER && curr_addr < FLASH_BUFFER_END)
+	{
+		memset(&shared_buffer, 0, SHARED_BUFFER_LEN);	// Clear shared_buffer
+		uint8_t * p_addr = curr_addr;					// Create a working pointer at flash page start
+		uint16_t ct = 0;								// shared buffer index
+		// Copy page into shared buffer
+		for(ct;ct<512;ct++)
+		{
+			shared_buffer[ct] = *p_addr;
+			p_addr++;
+		}
+		// Copy any saved bytes into the shared buffer
+		if(saved_bytes)
+		{
+			// Current page needs to be appended to the previously-written page
+			uint16_t ind = 0;
+			for(ind;ind0)
+		{
+			wind--;
+			// Latch onto '----' ("----[boundary ID]")
+			if(shared_buffer[wind-1] == '\x2d' && shared_buffer[wind-2] == '\x2d' && shared_buffer[wind-3] == '\x2d' && shared_buffer[wind-4] == '\x2d')
+			{
+				// Store the discovered boundary
+				char tmpID[BOUNDARY_MAX_LEN] = {0};
+				int z = 0;
+				while(z < BOUNDARY_MAX_LEN && shared_buffer[wind+z] != '\x2d' && shared_buffer[wind+z] != '\x0d' && shared_buffer[wind+z] != '\x0a' && (wind+z) < ct)
+				{
+					tmpID[z] = shared_buffer[wind+z];
+					z++;
+				}
+			
+				TRACE("http.c: discovered boundary ID : %s (shared buffer check)", tmpID);
+			
+				// Match the boundary ID with stored ID
+				if(strcmp(tmpID, boundary_ID) == 0)
+				{
+					TRACE("http.c: boundary IDs match");
+					TRACE("http.c: moving data end pointer");
+					// Traverse through the preceding newline characters
+					while(shared_buffer[wind-1] == '\x0d' || shared_buffer[wind-1] == '\x0a' || shared_buffer[wind-1] == '\x2d')
+					{
+						wind--;
+					}
+					
+					// Overwrite previous page
+					flash_page_addr = curr_addr;	// Move page write address to overwrite previous page
+					// Fill 512-byte array
+					int j = 0;
+					while(j < IFLASH_PAGE_SIZE)
+					{
+						if(j < wind)
+						{
+							// Write data
+							page[j] = shared_buffer[j];
+							//handled_bytes++;
+						}
+						else
+						{
+							// Append 0xFF
+							page[j] = 0xFF;
+						}
+
+						j++;
+					}
+								
+					// Write to page
+					if(flash_write_page(&page))
+					{
+						TRACE("http.c: page written successfully");
+						page_ctr++;
+					}
+					else
+					{
+						TRACE("http.c: page write FAILED");
+					}
+					
+					if(j= FLASH_BUFFER_END)
+	{
+		TRACE("http.c: ERROR - flash upper limit reached");
+	}
+
 	if(final)
 	{		
 		return 2;

From cfe3c21d1f35e896e5ac0bfea307d4b3401bc277 Mon Sep 17 00:00:00 2001
From: Paul Zanna 
Date: Wed, 5 Apr 2017 18:15:44 +1000
Subject: [PATCH 026/169] Stacking setup

---
 ZodiacFX/ZodiacFX.cproj |  4 ++--
 ZodiacFX/src/command.c  |  2 +-
 ZodiacFX/src/main.c     |  2 +-
 ZodiacFX/src/stacking.c | 20 ++++++++++++++++++++
 ZodiacFX/src/stacking.h |  2 +-
 ZodiacFX/src/switch.c   | 22 ++++++++++++++++++----
 6 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/ZodiacFX/ZodiacFX.cproj b/ZodiacFX/ZodiacFX.cproj
index ab4e3bd..dbed849 100644
--- a/ZodiacFX/ZodiacFX.cproj
+++ b/ZodiacFX/ZodiacFX.cproj
@@ -274,11 +274,11 @@
         JTAG
       
       com.atmel.avrdbg.tool.atmelice
-      J41800009874
+      J41800076758
       Atmel-ICE
     
     JTAG
-    J41800009874
+    J41800076758
     0xA3CC0CE0
     7500000
   
diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c
index d8e1152..1e4c2d6 100644
--- a/ZodiacFX/src/command.c
+++ b/ZodiacFX/src/command.c
@@ -541,7 +541,7 @@ void command_config(char *command, char *param1, char *param2, char *param3)
 		if (masterselect == true) printf(" Stacking Select: SLAVE\r\n");
 		if (masterselect == false) printf(" Stacking Select: MASTER\r\n");
 		if (stackenabled == true) printf(" Stacking Status: Enabled\r\n");
-		if (stackenabled == false) printf(" Stacking Select: Disabled\r\n");
+		if (stackenabled == false) printf(" Stacking Status: Disabled\r\n");
 		if (Zodiac_Config.ethtype_filter == 1) printf(" EtherType Filtering: Enabled\r\n");
 		if (Zodiac_Config.ethtype_filter != 1) printf(" EtherType Filtering: Disabled\r\n");
 		printf("\r\n-------------------------------------------------------------------------\r\n\n");
diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c
index 58bbec2..6beb3bf 100644
--- a/ZodiacFX/src/main.c
+++ b/ZodiacFX/src/main.c
@@ -202,10 +202,10 @@ int main (void)
 	while(1)
 	{
 		task_switch(&gs_net_if);
-		task_command(cCommand, cCommand_last);
 		// Only run the following tasks if set to Master
 		if(masterselect == false)
 		{
+			task_command(cCommand, cCommand_last);
 			sys_check_timeouts();
 			task_openflow();	
 		} 
diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c
index 2e650ef..edb913a 100644
--- a/ZodiacFX/src/stacking.c
+++ b/ZodiacFX/src/stacking.c
@@ -55,6 +55,11 @@ static uint32_t gs_ul_spi_clock = 500000;
 #define SPI_STATE_COMMAND	1
 #define SPI_STATE_DATA		3
 
+// Global variables
+extern uint8_t last_port_status[4];
+extern uint8_t port_status[4];
+
+// Local variables
 uint32_t *spi_cmd_buffer;
 uint32_t spi_slv_preamble;
 uint8_t spi_state = 0;
@@ -63,6 +68,7 @@ uint16_t spi_command, spi_command_size;
 bool spi_slave_send;
 uint16_t spi_slave_send_size;
 uint8_t spibuffer[1];
+uint8_t timer_alt;
 
 void spi_master_initialize(void);
 void spi_slave_initialize(void);
@@ -138,6 +144,20 @@ void spi_master_initialize(void)
 	spi_enable(SPI_MASTER_BASE);
 }
 
+void Slave_timer(void)
+{
+	if (timer_alt == 0)
+	{
+		update_port_stats();
+		timer_alt = 1;
+		return;
+	} else if (timer_alt == 1)
+	{
+		update_port_status();
+		timer_alt = 0;
+		return;
+	}
+}
 
 void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size)
 {
diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h
index a0a4f53..2abebe4 100644
--- a/ZodiacFX/src/stacking.h
+++ b/ZodiacFX/src/stacking.h
@@ -15,6 +15,6 @@
 void stacking_init(bool master);
 void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size);
 void MasterStackRcv(void);
-
+void Slave_timer(void);
 
 #endif /* STACKING_H_ */
\ No newline at end of file
diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c
index dc9e121..22ac1c7 100644
--- a/ZodiacFX/src/switch.c
+++ b/ZodiacFX/src/switch.c
@@ -36,6 +36,7 @@
 #include "stacking.h"
 #include "conf_eth.h"
 #include "command.h"
+#include "timers.h"
 
 #include "ksz8795clx/ethernet_phy.h"
 #include "netif/etharp.h"
@@ -53,6 +54,7 @@ uint8_t last_port_status[4];
 extern uint8_t NativePortMatrix;
 extern bool masterselect;
 extern bool stackenabled;
+int slave_timer = 0;
 /** Buffer for ethernet packets */
 static volatile uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX];
 
@@ -467,10 +469,24 @@ void task_switch(struct netif *netif)
 	uint32_t ul_rcv_size = 0;
 	uint8_t tag = 0;
 	int8_t in_port = 0;
-			
+					
+	// Check if the slave device is connected and enable stacking
+	if(masterselect == false && !ioport_get_pin_level(SPI_IRQ1) && stackenabled == false) stackenabled = true;
+
 	// Check if the slave device has a packet to send us
 	if(masterselect == false && ioport_get_pin_level(SPI_IRQ1) && stackenabled == true) MasterStackRcv();
+	
+	// Slave house keeping
+	if(masterselect == true) 
+	{
+		if((sys_get_ms() - slave_timer) > 500)	// every 500 ms (0.5 secs)
+		{
+			slave_timer = sys_get_ms();	
+			Slave_timer(); // Slave timer
+		}
+	}
 
+	
 	/* Main packet processing loop */
 	uint32_t dev_read = gmac_dev_read(&gs_gmac_dev, (uint8_t *) gs_uc_eth_buffer, sizeof(gs_uc_eth_buffer), &ul_rcv_size);
 	if (dev_read == GMAC_OK)
@@ -496,7 +512,6 @@ void task_switch(struct netif *netif)
 				uint8_t tag = *tail_tag + 1;
 				if (Zodiac_Config.OFEnabled == OF_ENABLED && Zodiac_Config.of_port[tag-1] == 1)
 				{
-					//MasterStackSend((uint8_t *) gs_uc_eth_buffer, ul_rcv_size);
 					phys10_port_stats[tag-1].rx_packets++;
 					phys13_port_stats[tag-1].rx_packets++;
 					ul_rcv_size--; // remove the tail first
@@ -516,8 +531,7 @@ void task_switch(struct netif *netif)
 			}
 		} else
 		{
-			TRACE("switch.c: Set Slave to true!");
-
+			// TODO: Send packet to master
 			return;
 		}
 	}

From 3e08ca31d9515178c29e9948f197c0facab66105 Mon Sep 17 00:00:00 2001
From: Paul Zanna 
Date: Wed, 5 Apr 2017 20:03:22 +1000
Subject: [PATCH 027/169] Stacking Master Init

---
 ZodiacFX/ZodiacFX.cproj | 562 ++++++++++++++++++++--------------------
 ZodiacFX/src/stacking.c | 254 +++---------------
 ZodiacFX/src/stacking.h |  38 ++-
 ZodiacFX/src/switch.c   |   7 +-
 4 files changed, 355 insertions(+), 506 deletions(-)

diff --git a/ZodiacFX/ZodiacFX.cproj b/ZodiacFX/ZodiacFX.cproj
index dbed849..1d5afa1 100644
--- a/ZodiacFX/ZodiacFX.cproj
+++ b/ZodiacFX/ZodiacFX.cproj
@@ -274,301 +274,301 @@
         JTAG
       
       com.atmel.avrdbg.tool.atmelice
-      J41800076758
+      J41800009874
       Atmel-ICE
     
     JTAG
-    J41800076758
+    J41800009874
     0xA3CC0CE0
     7500000
   
   
     
       
-  True
-  True
-  True
-  True
-  True
-  
-    
-      NDEBUG
-      scanf=iscanf
-      BOARD=USER_BOARD
-      ARM_MATH_CM4=true
-      printf=iprintf
-      UDD_ENABLE
-    
-  
-  False
-  
-    
-      ../common/applications/user_application/user_board/config
-      ../src/config
-      ../src/ASF/thirdparty/CMSIS/Lib/GCC
-      ../src/ASF/common/utils
-      ../src
-      ../src/ASF/sam/utils/fpu
-      ../src/ASF/sam/utils
-      ../src/ASF/sam/utils/preprocessor
-      ../src/ASF/sam/utils/cmsis/sam4e/include
-      ../src/ASF/common/boards
-      ../src/ASF/sam/utils/header_files
-      ../src/ASF/common/boards/user_board
-      ../src/ASF/thirdparty/CMSIS/Include
-      ../src/ASF/sam/utils/cmsis/sam4e/source/templates
-      ../src/ASF/sam/drivers/pmc
-      ../src/ASF/common/services/clock
-      ../src/ASF/common/services/ioport
-      ../src/ASF/common/services/spi/sam_usart_spi
-      ../src/ASF/common/services/spi
-      ../src/ASF/common/services/twi
-      ../src/ASF/sam/drivers/twi
-      ../src/ASF/sam/drivers/usart
-      ../src/ASF/sam/drivers/gmac
-      ../src/ASF/sam/drivers/matrix
-      ../src/ASF/sam/drivers/pio
-      ../src/ASF/sam/drivers/rtc
-      ../src/ASF/common/services/sleepmgr
-      ../src/ASF/common/services/usb
-      ../src/ASF/common/services/usb/class/cdc
-      ../src/ASF/common/services/usb/class/cdc/device
-      ../src/ASF/common/services/usb/udc
-      ../src/ASF/common/utils/stdio/stdio_usb
-      ../src/ASF/sam/drivers/udp
-      ../src/ASF/sam/drivers/tc
-      ../src/ASF/common/services/spi/sam_spi
-      ../src/ASF/sam/drivers/spi
-      ../src/ASF/sam/drivers/rstc
-      ../src/lwip/include
-      ../src/lwip
-      ../src/lwip/include/ipv4
-      ../src/ASF/sam/drivers/afec
-      ../src/ASF/common/utils/membag
-      ../src/ASF/sam/drivers/efc
-      ../src/ASF/sam/services/flash_efc
-    
-  
-  Optimize (-O1)
-  -fdata-sections
-  True
-  True
-  -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -mfloat-abi=softfp -mfpu=fpv4-sp-d16
-  
-    
-      libarm_cortexM4lf_math_softfp
-      libm
-    
-  
-  
-    
-      ../cmsis/linkerScripts
-      ../src/ASF/thirdparty/CMSIS/Lib/GCC
-    
-  
-  True
-  
-  -Wl,--defsym,__stack_size__=0x1400 -Wl,--entry=Reset_Handler -Wl,-section-start=.text=0x00410000 -Wl,--cref -mthumb -T../src/ASF/sam/utils/linker_scripts/sam4e/sam4e8/gcc/flash.ld
-  
-    
-      ../src/ASF/sam/drivers/efc
-      ../src/ASF/sam/services/flash_efc
-    
-  
-  -DARM_MATH_CM4=true -DBOARD=USER_BOARD -Dprintf=iprintf -Dscanf=iscanf -DUDD_ENABLE
-  False
-  
-    
-      ../common/applications/user_application/user_board/config
-      ../src/config
-      ../src/ASF/thirdparty/CMSIS/Lib/GCC
-      ../src/ASF/common/utils
-      ../src
-      ../src/ASF/sam/utils/fpu
-      ../src/ASF/sam/utils
-      ../src/ASF/sam/utils/preprocessor
-      ../src/ASF/sam/utils/cmsis/sam4e/include
-      ../src/ASF/common/boards
-      ../src/ASF/sam/utils/header_files
-      ../src/ASF/common/boards/user_board
-      ../src/ASF/thirdparty/CMSIS/Include
-      ../src/ASF/sam/utils/cmsis/sam4e/source/templates
-      ../src/ASF/sam/drivers/pmc
-      ../src/ASF/common/services/clock
-      ../src/ASF/common/services/ioport
-      ../src/ASF/common/services/spi/sam_usart_spi
-      ../src/ASF/common/services/spi
-      ../src/ASF/common/services/twi
-      ../src/ASF/sam/drivers/twi
-      ../src/ASF/sam/drivers/usart
-      ../src/ASF/sam/drivers/gmac
-      ../src/ASF/sam/drivers/matrix
-      ../src/ASF/sam/drivers/pio
-      ../src/ASF/sam/drivers/rtc
-      ../src/ASF/common/services/sleepmgr
-      ../src/ASF/common/services/usb
-      ../src/ASF/common/services/usb/class/cdc
-      ../src/ASF/common/services/usb/class/cdc/device
-      ../src/ASF/common/services/usb/udc
-      ../src/ASF/common/utils/stdio/stdio_usb
-      ../src/ASF/sam/drivers/udp
-      ../src/ASF/sam/drivers/tc
-      ../src/ASF/common/services/spi/sam_spi
-      ../src/ASF/sam/drivers/spi
-      ../src/ASF/sam/drivers/rstc
-      ../src/ASF/sam/drivers/afec
-      ../src/ASF/common/utils/membag
-      ../src/ASF/sam/drivers/efc
-      ../src/ASF/sam/services/flash_efc
-    
-  
-
+        True
+        True
+        True
+        True
+        True
+        
+          
+            NDEBUG
+            scanf=iscanf
+            BOARD=USER_BOARD
+            ARM_MATH_CM4=true
+            printf=iprintf
+            UDD_ENABLE
+          
+        
+        False
+        
+          
+            ../common/applications/user_application/user_board/config
+            ../src/config
+            ../src/ASF/thirdparty/CMSIS/Lib/GCC
+            ../src/ASF/common/utils
+            ../src
+            ../src/ASF/sam/utils/fpu
+            ../src/ASF/sam/utils
+            ../src/ASF/sam/utils/preprocessor
+            ../src/ASF/sam/utils/cmsis/sam4e/include
+            ../src/ASF/common/boards
+            ../src/ASF/sam/utils/header_files
+            ../src/ASF/common/boards/user_board
+            ../src/ASF/thirdparty/CMSIS/Include
+            ../src/ASF/sam/utils/cmsis/sam4e/source/templates
+            ../src/ASF/sam/drivers/pmc
+            ../src/ASF/common/services/clock
+            ../src/ASF/common/services/ioport
+            ../src/ASF/common/services/spi/sam_usart_spi
+            ../src/ASF/common/services/spi
+            ../src/ASF/common/services/twi
+            ../src/ASF/sam/drivers/twi
+            ../src/ASF/sam/drivers/usart
+            ../src/ASF/sam/drivers/gmac
+            ../src/ASF/sam/drivers/matrix
+            ../src/ASF/sam/drivers/pio
+            ../src/ASF/sam/drivers/rtc
+            ../src/ASF/common/services/sleepmgr
+            ../src/ASF/common/services/usb
+            ../src/ASF/common/services/usb/class/cdc
+            ../src/ASF/common/services/usb/class/cdc/device
+            ../src/ASF/common/services/usb/udc
+            ../src/ASF/common/utils/stdio/stdio_usb
+            ../src/ASF/sam/drivers/udp
+            ../src/ASF/sam/drivers/tc
+            ../src/ASF/common/services/spi/sam_spi
+            ../src/ASF/sam/drivers/spi
+            ../src/ASF/sam/drivers/rstc
+            ../src/lwip/include
+            ../src/lwip
+            ../src/lwip/include/ipv4
+            ../src/ASF/sam/drivers/afec
+            ../src/ASF/common/utils/membag
+            ../src/ASF/sam/drivers/efc
+            ../src/ASF/sam/services/flash_efc
+          
+        
+        Optimize (-O1)
+        -fdata-sections
+        True
+        True
+        -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -mfloat-abi=softfp -mfpu=fpv4-sp-d16
+        
+          
+            libarm_cortexM4lf_math_softfp
+            libm
+          
+        
+        
+          
+            ../cmsis/linkerScripts
+            ../src/ASF/thirdparty/CMSIS/Lib/GCC
+          
+        
+        True
+        
+        -Wl,--defsym,__stack_size__=0x1400 -Wl,--entry=Reset_Handler -Wl,-section-start=.text=0x00410000 -Wl,--cref -mthumb -T../src/ASF/sam/utils/linker_scripts/sam4e/sam4e8/gcc/flash.ld
+        
+          
+            ../src/ASF/sam/drivers/efc
+            ../src/ASF/sam/services/flash_efc
+          
+        
+        -DARM_MATH_CM4=true -DBOARD=USER_BOARD -Dprintf=iprintf -Dscanf=iscanf -DUDD_ENABLE
+        False
+        
+          
+            ../common/applications/user_application/user_board/config
+            ../src/config
+            ../src/ASF/thirdparty/CMSIS/Lib/GCC
+            ../src/ASF/common/utils
+            ../src
+            ../src/ASF/sam/utils/fpu
+            ../src/ASF/sam/utils
+            ../src/ASF/sam/utils/preprocessor
+            ../src/ASF/sam/utils/cmsis/sam4e/include
+            ../src/ASF/common/boards
+            ../src/ASF/sam/utils/header_files
+            ../src/ASF/common/boards/user_board
+            ../src/ASF/thirdparty/CMSIS/Include
+            ../src/ASF/sam/utils/cmsis/sam4e/source/templates
+            ../src/ASF/sam/drivers/pmc
+            ../src/ASF/common/services/clock
+            ../src/ASF/common/services/ioport
+            ../src/ASF/common/services/spi/sam_usart_spi
+            ../src/ASF/common/services/spi
+            ../src/ASF/common/services/twi
+            ../src/ASF/sam/drivers/twi
+            ../src/ASF/sam/drivers/usart
+            ../src/ASF/sam/drivers/gmac
+            ../src/ASF/sam/drivers/matrix
+            ../src/ASF/sam/drivers/pio
+            ../src/ASF/sam/drivers/rtc
+            ../src/ASF/common/services/sleepmgr
+            ../src/ASF/common/services/usb
+            ../src/ASF/common/services/usb/class/cdc
+            ../src/ASF/common/services/usb/class/cdc/device
+            ../src/ASF/common/services/usb/udc
+            ../src/ASF/common/utils/stdio/stdio_usb
+            ../src/ASF/sam/drivers/udp
+            ../src/ASF/sam/drivers/tc
+            ../src/ASF/common/services/spi/sam_spi
+            ../src/ASF/sam/drivers/spi
+            ../src/ASF/sam/drivers/rstc
+            ../src/ASF/sam/drivers/afec
+            ../src/ASF/common/utils/membag
+            ../src/ASF/sam/drivers/efc
+            ../src/ASF/sam/services/flash_efc
+          
+        
+      
     
   
   
     
       
-  True
-  True
-  True
-  True
-  True
-  
-    
-      DEBUG
-      scanf=iscanf
-      BOARD=USER_BOARD
-      ARM_MATH_CM4=true
-      printf=iprintf
-      UDD_ENABLE
-    
-  
-  False
-  
-    
-      ../common/applications/user_application/user_board/config
-      ../src/config
-      ../src/ASF/thirdparty/CMSIS/Lib/GCC
-      ../src/ASF/common/utils
-      ../src
-      ../src/ASF/sam/utils/fpu
-      ../src/ASF/sam/utils
-      ../src/ASF/sam/utils/preprocessor
-      ../src/ASF/sam/utils/cmsis/sam4e/include
-      ../src/ASF/common/boards
-      ../src/ASF/sam/utils/header_files
-      ../src/ASF/common/boards/user_board
-      ../src/ASF/thirdparty/CMSIS/Include
-      ../src/ASF/sam/utils/cmsis/sam4e/source/templates
-      ../src/ASF/sam/drivers/pmc
-      ../src/ASF/common/services/clock
-      ../src/ASF/common/services/ioport
-      ../src/ASF/common/services/spi/sam_usart_spi
-      ../src/ASF/common/services/spi
-      ../src/ASF/common/services/twi
-      ../src/ASF/sam/drivers/twi
-      ../src/ASF/sam/drivers/usart
-      ../src/ASF/sam/drivers/gmac
-      ../src/ASF/sam/drivers/matrix
-      ../src/ASF/sam/drivers/pio
-      ../src/ASF/sam/drivers/rtc
-      ../src/ASF/common/services/sleepmgr
-      ../src/ASF/common/services/usb
-      ../src/ASF/common/services/usb/class/cdc
-      ../src/ASF/common/services/usb/class/cdc/device
-      ../src/ASF/common/services/usb/udc
-      ../src/ASF/common/utils/stdio/stdio_usb
-      ../src/ASF/sam/drivers/udp
-      ../src/lwip
-      ../src/lwip/include
-      ../src/lwip/include/ipv4
-      ../src/ASF/sam/drivers/tc
-      ../src/ASF/common/services/spi/sam_spi
-      ../src/ASF/sam/drivers/spi
-      ../src/ASF/sam/drivers/rstc
-      ../src/ASF/sam/drivers/afec
-      ../src/ASF/common/utils/membag
-      ../src/ASF/sam/drivers/efc
-      ../src/ASF/sam/services/flash_efc
-    
-  
-  -fdata-sections
-  True
-  Maximum (-g3)
-  True
-  -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -mfloat-abi=softfp -mfpu=fpv4-sp-d16
-  True
-  
-    
-      libarm_cortexM4lf_math_softfp
-      libm
-    
-  
-  
-    
-      ../cmsis/linkerScripts
-      ../src/ASF/thirdparty/CMSIS/Lib/GCC
-    
-  
-  True
-  
-  -Wl,--defsym,__stack_size__=0x1400 -Wl,--entry=Reset_Handler -Wl,--cref -mthumb -T../src/ASF/sam/utils/linker_scripts/sam4e/sam4e8/gcc/flash.ld
-  
-    
-      ../src/ASF/sam/drivers/efc
-      ../src/ASF/sam/services/flash_efc
-    
-  
-  Default (-g)
-  -DARM_MATH_CM4=true -DBOARD=USER_BOARD -Dprintf=iprintf -Dscanf=iscanf -DUDD_ENABLE
-  False
-  
-    
-      ../common/applications/user_application/user_board/config
-      ../src/config
-      ../src/ASF/thirdparty/CMSIS/Lib/GCC
-      ../src/ASF/common/utils
-      ../src
-      ../src/ASF/sam/utils/fpu
-      ../src/ASF/sam/utils
-      ../src/ASF/sam/utils/preprocessor
-      ../src/ASF/sam/utils/cmsis/sam4e/include
-      ../src/ASF/common/boards
-      ../src/ASF/sam/utils/header_files
-      ../src/ASF/common/boards/user_board
-      ../src/ASF/thirdparty/CMSIS/Include
-      ../src/ASF/sam/utils/cmsis/sam4e/source/templates
-      ../src/ASF/sam/drivers/pmc
-      ../src/ASF/common/services/clock
-      ../src/ASF/common/services/ioport
-      ../src/ASF/common/services/spi/sam_usart_spi
-      ../src/ASF/common/services/spi
-      ../src/ASF/common/services/twi
-      ../src/ASF/sam/drivers/twi
-      ../src/ASF/sam/drivers/usart
-      ../src/ASF/sam/drivers/gmac
-      ../src/ASF/sam/drivers/matrix
-      ../src/ASF/sam/drivers/pio
-      ../src/ASF/sam/drivers/rtc
-      ../src/ASF/common/services/sleepmgr
-      ../src/ASF/common/services/usb
-      ../src/ASF/common/services/usb/class/cdc
-      ../src/ASF/common/services/usb/class/cdc/device
-      ../src/ASF/common/services/usb/udc
-      ../src/ASF/common/utils/stdio/stdio_usb
-      ../src/ASF/sam/drivers/udp
-      ../src/ASF/sam/drivers/tc
-      ../src/ASF/common/services/spi/sam_spi
-      ../src/ASF/sam/drivers/spi
-      ../src/ASF/sam/drivers/rstc
-      ../src/ASF/sam/drivers/afec
-      ../src/ASF/common/utils/membag
-      ../src/ASF/sam/drivers/efc
-      ../src/ASF/sam/services/flash_efc
-    
-  
-  Default (-Wa,-g)
-
+        True
+        True
+        True
+        True
+        True
+        
+          
+            DEBUG
+            scanf=iscanf
+            BOARD=USER_BOARD
+            ARM_MATH_CM4=true
+            printf=iprintf
+            UDD_ENABLE
+          
+        
+        False
+        
+          
+            ../common/applications/user_application/user_board/config
+            ../src/config
+            ../src/ASF/thirdparty/CMSIS/Lib/GCC
+            ../src/ASF/common/utils
+            ../src
+            ../src/ASF/sam/utils/fpu
+            ../src/ASF/sam/utils
+            ../src/ASF/sam/utils/preprocessor
+            ../src/ASF/sam/utils/cmsis/sam4e/include
+            ../src/ASF/common/boards
+            ../src/ASF/sam/utils/header_files
+            ../src/ASF/common/boards/user_board
+            ../src/ASF/thirdparty/CMSIS/Include
+            ../src/ASF/sam/utils/cmsis/sam4e/source/templates
+            ../src/ASF/sam/drivers/pmc
+            ../src/ASF/common/services/clock
+            ../src/ASF/common/services/ioport
+            ../src/ASF/common/services/spi/sam_usart_spi
+            ../src/ASF/common/services/spi
+            ../src/ASF/common/services/twi
+            ../src/ASF/sam/drivers/twi
+            ../src/ASF/sam/drivers/usart
+            ../src/ASF/sam/drivers/gmac
+            ../src/ASF/sam/drivers/matrix
+            ../src/ASF/sam/drivers/pio
+            ../src/ASF/sam/drivers/rtc
+            ../src/ASF/common/services/sleepmgr
+            ../src/ASF/common/services/usb
+            ../src/ASF/common/services/usb/class/cdc
+            ../src/ASF/common/services/usb/class/cdc/device
+            ../src/ASF/common/services/usb/udc
+            ../src/ASF/common/utils/stdio/stdio_usb
+            ../src/ASF/sam/drivers/udp
+            ../src/lwip
+            ../src/lwip/include
+            ../src/lwip/include/ipv4
+            ../src/ASF/sam/drivers/tc
+            ../src/ASF/common/services/spi/sam_spi
+            ../src/ASF/sam/drivers/spi
+            ../src/ASF/sam/drivers/rstc
+            ../src/ASF/sam/drivers/afec
+            ../src/ASF/common/utils/membag
+            ../src/ASF/sam/drivers/efc
+            ../src/ASF/sam/services/flash_efc
+          
+        
+        -fdata-sections
+        True
+        Maximum (-g3)
+        True
+        -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -mfloat-abi=softfp -mfpu=fpv4-sp-d16
+        True
+        
+          
+            libarm_cortexM4lf_math_softfp
+            libm
+          
+        
+        
+          
+            ../cmsis/linkerScripts
+            ../src/ASF/thirdparty/CMSIS/Lib/GCC
+          
+        
+        True
+        
+        -Wl,--defsym,__stack_size__=0x1400 -Wl,--entry=Reset_Handler -Wl,--cref -mthumb -T../src/ASF/sam/utils/linker_scripts/sam4e/sam4e8/gcc/flash.ld
+        
+          
+            ../src/ASF/sam/drivers/efc
+            ../src/ASF/sam/services/flash_efc
+          
+        
+        Default (-g)
+        -DARM_MATH_CM4=true -DBOARD=USER_BOARD -Dprintf=iprintf -Dscanf=iscanf -DUDD_ENABLE
+        False
+        
+          
+            ../common/applications/user_application/user_board/config
+            ../src/config
+            ../src/ASF/thirdparty/CMSIS/Lib/GCC
+            ../src/ASF/common/utils
+            ../src
+            ../src/ASF/sam/utils/fpu
+            ../src/ASF/sam/utils
+            ../src/ASF/sam/utils/preprocessor
+            ../src/ASF/sam/utils/cmsis/sam4e/include
+            ../src/ASF/common/boards
+            ../src/ASF/sam/utils/header_files
+            ../src/ASF/common/boards/user_board
+            ../src/ASF/thirdparty/CMSIS/Include
+            ../src/ASF/sam/utils/cmsis/sam4e/source/templates
+            ../src/ASF/sam/drivers/pmc
+            ../src/ASF/common/services/clock
+            ../src/ASF/common/services/ioport
+            ../src/ASF/common/services/spi/sam_usart_spi
+            ../src/ASF/common/services/spi
+            ../src/ASF/common/services/twi
+            ../src/ASF/sam/drivers/twi
+            ../src/ASF/sam/drivers/usart
+            ../src/ASF/sam/drivers/gmac
+            ../src/ASF/sam/drivers/matrix
+            ../src/ASF/sam/drivers/pio
+            ../src/ASF/sam/drivers/rtc
+            ../src/ASF/common/services/sleepmgr
+            ../src/ASF/common/services/usb
+            ../src/ASF/common/services/usb/class/cdc
+            ../src/ASF/common/services/usb/class/cdc/device
+            ../src/ASF/common/services/usb/udc
+            ../src/ASF/common/utils/stdio/stdio_usb
+            ../src/ASF/sam/drivers/udp
+            ../src/ASF/sam/drivers/tc
+            ../src/ASF/common/services/spi/sam_spi
+            ../src/ASF/sam/drivers/spi
+            ../src/ASF/sam/drivers/rstc
+            ../src/ASF/sam/drivers/afec
+            ../src/ASF/common/utils/membag
+            ../src/ASF/sam/drivers/efc
+            ../src/ASF/sam/services/flash_efc
+          
+        
+        Default (-Wa,-g)
+      
     
     "$(ToolchainDir)\arm-none-eabi-size.exe" $(OutputFileName)$(OutputFileExtension)
   
diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c
index edb913a..3fe50c5 100644
--- a/ZodiacFX/src/stacking.c
+++ b/ZodiacFX/src/stacking.c
@@ -49,12 +49,6 @@ static uint32_t gs_ul_spi_clock = 500000;
 /* Delay between consecutive transfers. */
 #define SPI_DLYBCT 0x10
 
-#define SPI_SLAVE_PREAMBLE		0xAAAAAAAB
-#define SPI_MASTER_PREAMBLE		0xBBBBBBBC
-#define SPI_STATE_PREAMBLE	0
-#define SPI_STATE_COMMAND	1
-#define SPI_STATE_DATA		3
-
 // Global variables
 extern uint8_t last_port_status[4];
 extern uint8_t port_status[4];
@@ -65,14 +59,14 @@ uint32_t spi_slv_preamble;
 uint8_t spi_state = 0;
 uint16_t spi_data_count = 0;
 uint16_t spi_command, spi_command_size;
-bool spi_slave_send;
+//bool spi_slave_send;
 uint16_t spi_slave_send_size;
-uint8_t spibuffer[1];
 uint8_t timer_alt;
+uint8_t pending_spi_command = SPI_SEND_CLEAR;
+bool master_ready;
 
 void spi_master_initialize(void);
 void spi_slave_initialize(void);
-void stack_mst_write(uint8_t *rx_data, uint16_t ul_size);
 
 /*
 *	Initialize the SPI interface to MASTER or SLAVE based on the stacking jumper
@@ -132,12 +126,9 @@ void spi_master_initialize(void)
 	spi_disable_mode_fault_detect(SPI_MASTER_BASE);
 	spi_disable_loopback(SPI_MASTER_BASE);
 	spi_set_peripheral_chip_select_value(SPI_MASTER_BASE, SPI_CHIP_SEL);
-	//spi_set_fixed_peripheral_select(SPI_MASTER_BASE);
-	//spi_disable_peripheral_select_decode(SPI_MASTER_BASE);
 	spi_set_transfer_delay(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_DLYBS, SPI_DLYBCT);
 	spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT);
 	spi_set_baudrate_div(SPI_MASTER_BASE, SPI_CHIP_SEL, (sysclk_get_cpu_hz() / gs_ul_spi_clock));
-	//spi_configure_cs_behavior(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CS_KEEP_LOW);
 	spi_set_clock_polarity(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY);
 	spi_set_clock_phase(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE);
 
@@ -154,71 +145,54 @@ void Slave_timer(void)
 	} else if (timer_alt == 1)
 	{
 		update_port_status();
+		timer_alt = 2;
+		return;
+	} else if (timer_alt == 2)
+	{
+		if(master_ready == false) return;		// Wait until the master acknowledges us before sending anything
+		ioport_set_pin_level(SPI_IRQ1, true);	// Set the IRQ to signal the slave wants to send something
+		pending_spi_command = SPI_SEND_STATS;	// We are waiting to send port stats
 		timer_alt = 0;
 		return;
 	}
 }
 
-void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size)
+/*
+*	Master ready function
+*
+*/
+void MasterReady(void)
 {
-	uint32_t cmd_buffer;
-	
-	// Send the preamble mark the beginning of a transfer
-	cmd_buffer = ntohl(SPI_SLAVE_PREAMBLE);
-	stack_mst_write(&cmd_buffer, sizeof(cmd_buffer));
-	
-	// Send a 2 byte command code and 2 byte data code
-	cmd_buffer = ntohl(ul_size);
-	stack_mst_write(&cmd_buffer, sizeof(cmd_buffer));
-	
-	// Send packet
-	stack_mst_write(p_uc_data, ul_size);
+	spi_write(SPI_MASTER_BASE, 0xaa, 0, 0);
+	master_ready = true;
 	return;
 }
 
-void MasterStackRcv(void)
+/*
+*	Master send function
+*
+*/
+void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size)
 {
-	uint32_t cmd_buffer;
-	
-	TRACE("switch.c: Master received slave IRQ!");
-	// Send the preamble mark the beginning of a transfer
-	cmd_buffer = ntohl(SPI_MASTER_PREAMBLE);
-	stack_mst_write(&cmd_buffer, sizeof(cmd_buffer));
 
-	// Send 4 bytes to receive slave packet size
-	cmd_buffer = 0xFFFFFFFF;
-	stack_mst_write(&cmd_buffer, sizeof(cmd_buffer));
-	TRACE("switch.c: Rcv Size = %04X", cmd_buffer);
-	while(ioport_get_pin_level(SPI_IRQ1));
+	return;
 }
 
 /*
-*	Write to the SPI stacking interface
+*	Master receive function
 *
 */
-void stack_mst_write(uint8_t *rx_data, uint16_t ul_size)
+void MasterStackRcv(void)
 {
-	uint8_t uc_pcs;
-	static uint16_t data;
-	uint8_t *p_buffer;
-	
-	p_buffer = rx_data;
-	
-	for (int i = 0; i < ul_size; i++) {
+	while(ioport_get_pin_level(SPI_IRQ1))
+	{
 		for(int x = 0;x<10000;x++);
-		spi_write(SPI_MASTER_BASE, p_buffer[i], 0, 0);
-		TRACE("switch.c: SPI Write - %d , %02X", i, p_buffer[i]);
-		/* Wait transfer done. */
+		spi_write(SPI_MASTER_BASE, 0xaa, 0, 0);
 		while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0);
-		//spi_read(SPI_MASTER_BASE, p_buffer[i], &uc_pcs);
-		TRACE("switch.c: SPI Read - %d , %02X", i, data);
 	}
 	return;
 }
 	
-
-
-
 /*
 *	SPI interface IRQ handler
 *	Used to receive data from the stacking interface
@@ -226,172 +200,12 @@ void stack_mst_write(uint8_t *rx_data, uint16_t ul_size)
 */
 void SPI_Handler(void)
 {
-	static uint16_t data;
-	uint8_t uc_pcs;
-
-	if (spi_slave_send == false)
-	{
-		if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF)
-		{
-			spi_read(SPI_SLAVE_BASE, &data, &uc_pcs);
-			//TRACE("%d - %02X", spi_data_count, data);
-
-			if (spi_state == SPI_STATE_DATA)
-			{
-				spibuffer[spi_data_count] = data;
-				spi_data_count++;
-				if (spi_data_count == spi_command_size)
-				{
-					TRACE("switch.c: %d bytes of Data received", spi_data_count);
-					uint8_t* tail_tag = (uint8_t*)(spibuffer + (int)(spi_command_size)-1);
-					uint8_t tag = *tail_tag + 1;
-					TRACE("switch.c: Tag = %d", tag);
-					gmac_write(spibuffer, spi_data_count-1, tag);
-					spi_data_count = 0;
-					spi_state = SPI_STATE_PREAMBLE;
-					return;
-				}
-			}
-
-			//	Start of Preamble
-			if (spi_state == SPI_STATE_PREAMBLE && data == 0xAA)
-			{
-				switch (spi_data_count)
-				{
-					case 0:
-					spi_data_count = 1;
-					break;
-					
-					case 1:
-					spi_data_count = 2;
-					break;
-					
-					case 2:
-					spi_data_count = 3;
-					break;
-				}
-			}
-			
-			//	End of Preamble
-			if (spi_state == SPI_STATE_PREAMBLE && data == 0xAB && spi_data_count == 3)
-			{
-				spi_state = SPI_STATE_COMMAND;
-				spi_data_count = 0;
-				TRACE("switch.c: Master send preamble received!");
-				return;
-			}
-			// Command bytes
-			if (spi_state == SPI_STATE_COMMAND)
-			{
-				switch(spi_data_count)
-				{
-					case 0:
-					spi_command = data;
-					spi_data_count++;
-					break;
-					
-					case 1:
-					spi_command = data<<8;
-					spi_data_count++;
-					break;
-					
-					case 2:
-					spi_command_size = data<<8;
-					spi_data_count++;
-					break;
-					case 3:
-					spi_command_size += data;
-					spi_state = SPI_STATE_DATA;
-					spi_data_count = 0;
-					TRACE("switch.c: Command received! %d - %d", spi_command, spi_command_size);
-					break;
-				}
-			}
-			
-		}
-		return;
-		
-	} else
+	master_ready = true;
+	
+	if(pending_spi_command == SPI_SEND_STATS)	// We send the master our port stats
 	{
-		if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF)
-		{
-			spi_read(SPI_SLAVE_BASE, &data, &uc_pcs);
-			TRACE("switch.c: %d - %02X (%d)", spi_data_count, data, spi_state);
-
-			//	Start of Preamble
-			if (spi_state == SPI_STATE_PREAMBLE && data == 0xBB)
-			{
-				switch (spi_data_count)
-				{
-					case 0:
-					spi_data_count = 1;
-					spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
-					break;
-					
-					case 1:
-					spi_data_count = 2;
-					spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
-					break;
-					
-					case 2:
-					spi_data_count = 3;
-					spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
-					break;
-				}
-				return;
-			}
-			
-			//	End of Preamble
-			if (spi_state == SPI_STATE_PREAMBLE && data == 0xBC && spi_data_count == 3)
-			{
-				spi_state = SPI_STATE_COMMAND;
-				spi_write(SPI_SLAVE_BASE, data, 0, 0);
-				spi_data_count = 0;
-				TRACE("switch.c: Slave send reamble received!");
-				return;
-			}
-			// Command bytes
-			if (spi_state == SPI_STATE_COMMAND)
-			{
-				switch(spi_data_count)
-				{
-					case 0:
-					spi_command = data;
-					spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
-					spi_data_count++;
-					break;
-					
-					case 1:
-					spi_command = data<<8;
-					spi_write(SPI_SLAVE_BASE, spi_slave_send_size >> 8, 0, 0); // Size
-					spi_data_count++;
-					break;
-					
-					case 2:
-					spi_command_size = data<<8;
-					spi_write(SPI_SLAVE_BASE, spi_slave_send_size, 0, 0); // Size
-					spi_data_count++;
-					break;
-					case 3:
-					spi_command_size += data;
-					spi_state = SPI_STATE_DATA;
-					spi_write(SPI_SLAVE_BASE, 0xFF, 0, 0);
-					spi_data_count = 0;
-					//TRACE("Master fill received! %d - %d", spi_command, spi_command_size);
-					TRACE("switch.c: Packet Size = 0x%X (%d)", spi_slave_send_size, spi_slave_send_size);
-					break;
-				}
-			}
-			
-			if (spi_state == SPI_STATE_DATA)
-			{
-				ioport_set_pin_level(SPI_IRQ1, false);
-				spi_slave_send = false;
-				TRACE("switch.c: Set Slave to false!");
-				spi_state = SPI_STATE_PREAMBLE;
-				return;
-			}
-		}
-		return;
+		pending_spi_command = SPI_SEND_CLEAR;	// Clear the pending command
+		ioport_set_pin_level(SPI_IRQ1, false);	// turn off the IRQ because we are done
+		return;	
 	}
 }
\ No newline at end of file
diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h
index 2abebe4..1881fcc 100644
--- a/ZodiacFX/src/stacking.h
+++ b/ZodiacFX/src/stacking.h
@@ -1,9 +1,32 @@
+/**
+ * @file
+ * command.c
+ *
+ * This file contains the command line functions
+ *
+ */
+
 /*
- * stacking.h
+ * This file is part of the Zodiac FX firmware.
+ * Copyright (c) 2016 Northbound Networks.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * Created: 1/04/2017 5:30:12 PM
- *  Author: paul
- */ 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ *
+ * Author: Paul Zanna 
+ *
+ *
+ */
 
 
 #ifndef STACKING_H_
@@ -12,7 +35,14 @@
 #define SPI_Handler     SPI_Handler
 #define SPI_IRQn        SPI_IRQn
 
+#define SPI_SEND_CLEAR	0
+#define SPI_SEND_STATS	1
+#define SPI_SEND_PKT	2
+#define SPI_SLAVE_PREAMBLE		0xAAAAAAAB
+#define SPI_MASTER_PREAMBLE		0xBBBBBBBC
+
 void stacking_init(bool master);
+void MasterReady(void);
 void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size);
 void MasterStackRcv(void);
 void Slave_timer(void);
diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c
index 22ac1c7..accfc8f 100644
--- a/ZodiacFX/src/switch.c
+++ b/ZodiacFX/src/switch.c
@@ -471,7 +471,11 @@ void task_switch(struct netif *netif)
 	int8_t in_port = 0;
 					
 	// Check if the slave device is connected and enable stacking
-	if(masterselect == false && !ioport_get_pin_level(SPI_IRQ1) && stackenabled == false) stackenabled = true;
+	if(masterselect == false && !ioport_get_pin_level(SPI_IRQ1) && stackenabled == false) 
+	{
+		MasterReady();
+		stackenabled = true;
+	}
 
 	// Check if the slave device has a packet to send us
 	if(masterselect == false && ioport_get_pin_level(SPI_IRQ1) && stackenabled == true) MasterStackRcv();
@@ -484,6 +488,7 @@ void task_switch(struct netif *netif)
 			slave_timer = sys_get_ms();	
 			Slave_timer(); // Slave timer
 		}
+		
 	}
 
 	

From 60f4a1132bd98a3dd854e54ec0670041dad38494 Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 10 Apr 2017 11:02:33 +1000
Subject: [PATCH 028/169] Rewrite upload handler

---
 ZodiacFX/src/command.c |  13 +
 ZodiacFX/src/http.c    | 668 ++++++++---------------------------------
 ZodiacFX/src/http.h    |   1 +
 3 files changed, 147 insertions(+), 535 deletions(-)

diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c
index 2df0d2f..062f596 100644
--- a/ZodiacFX/src/command.c
+++ b/ZodiacFX/src/command.c
@@ -468,6 +468,19 @@ void command_root(char *command, char *param1, char *param2, char *param3)
 		printf("Append [%08x 00000000] to the binary\r\n", ntohl(verify.calculated));
 		return;
 	}
+	
+	if (strcmp(command, "dump")==0 && strcmp(param1, "flash")==0)
+	{
+		uint8_t* buffer_pmem = FLASH_BUFFER;
+		while(buffer_pmem < FLASH_BUFFER_END)
+		{
+			printf("%02x", *buffer_pmem);
+			buffer_pmem++;
+		}
+		printf("\n");
+		
+		return;
+	}
 
 	// Unknown Command
 	printf("Unknown command\r\n");
diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index e068ae3..a8629e3 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -96,7 +96,9 @@ void http_send(char *buffer, struct tcp_pcb *pcb, bool out);
 static err_t http_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len);
 void http_close(struct tcp_pcb *pcb);
 
-static uint8_t upload_handler(char *payload, int len);
+static uint8_t	upload_handler(char *payload, int len);
+static uint8_t	process_pagebuff(uint8_t * buff_addr, uint16_t buff_index, uint8_t * match_addr);
+static uint16_t	send_pagebuff(uint8_t * buff_addr, uint16_t buff_index);
 
 // HTML resources
 static uint8_t interfaceCreate_Frames(void);
@@ -1406,23 +1408,24 @@ void http_close(struct tcp_pcb *pcb)
 */
 static uint8_t upload_handler(char *payload, int len)
 {
-	static char page[IFLASH_PAGE_SIZE] = {0};			// Storage for each page of data
-	static uint16_t saved_bytes = 0;					// Persistent counter of unwritten data
-	uint16_t handled_bytes = 0;							// Counter of handled data
-	static uint32_t total_handled_bytes = 0;			// Counter of total handled data
-	static char boundary_ID[BOUNDARY_MAX_LEN] = {0};	// Storage for boundary ID
+	// Persistent local variables
+	static uint8_t pagebuff[PAGEBUFF_SIZE] = {0};			// Storage for each page of data
+	static uint8_t boundary_ID[BOUNDARY_MAX_LEN] = {0};	// Storage for boundary ID
+	static uint16_t pagebuff_index = 0;
+	
+	// Local variables
+	uint16_t	payload_index = 0;
+	uint8_t		boundary_ret = 0;
 
 	if(payload == NULL || len == 0)
 	{
 		// Clean up upload handler (on interrupted/failed upload)
-		memset(&page, 0, IFLASH_PAGE_SIZE);				// Clear page storage
+		memset(&pagebuff, 0, PAGEBUFF_SIZE);				// Clear page storage
 		memset(&boundary_ID, 0, BOUNDARY_MAX_LEN);		// Clear boundary storage
-		saved_bytes = 0;								// Clear saved byte counter
 		file_upload = false;							// Clear file upload flag
 		boundary_start = 1;								// Set starting boundary required flag
 		upload_pcb = NULL;								// Clear pcb connection pointer
 		upload_timer = 0;								// Clear upload timeout
-		total_handled_bytes = 0;
 		return 1;
 	}
 	
@@ -1536,7 +1539,7 @@ static uint8_t upload_handler(char *payload, int len)
 			boundary_start = 0;
 			
 			// Clear page array before use
-			memset(&page, 0, IFLASH_PAGE_SIZE);	// Clear shared_buffer
+			memset(&pagebuff, 0, PAGEBUFF_SIZE);	// Clear shared_buffer
 		}
 	}
 	else
@@ -1545,554 +1548,62 @@ static uint8_t upload_handler(char *payload, int len)
 		px = payload;
 	}
 	
-	// Search for ending boundary
-	py = payload + len;
-	
-	i = 128;
-	while(i>0)
+	// Fix alignment after boundary detection
+	if(px > payload)
 	{
-		py--;
-		// Latch onto '----' ("----[boundary ID]")
-		if((*(py-1)) == '\x2d' && (*(py-2)) == '\x2d' && (*(py-3)) == '\x2d' && (*(py-4)) == '\x2d')
-		{
-			// Store the discovered boundary
-			char tmpID[BOUNDARY_MAX_LEN] = {0};
-			int z = 0;
-			while(z < BOUNDARY_MAX_LEN && *(py+z) != '\x2d' && *(py+z) != '\x0d' && *(py+z) != '\x0a' && (py+z) < payload+len)
-			{
-				tmpID[z] = *(py+z);
-				z++;
-			}
-			
-			TRACE("http.c: discovered boundary ID : %s", tmpID);
-			
-			// Match the boundary ID with stored ID
-			if(strcmp(tmpID, boundary_ID) == 0)
-			{
-				TRACE("http.c: boundary IDs match");
-				TRACE("http.c: moving data end pointer");
-				// Traverse through the preceding newline characters
-				while(*(py-1) == '\x0d' || *(py-1) == '\x0a' || *(py-1) == '\x2d')
-				{
-					py--;
-				}
-				
-				i = 0;
-				// 'i' will be decremented to -1 if this line is run
-			}
-			else
-			{
-				TRACE("http.c: boundary IDs do not match");
-				i = 1;
-				// 'i' will be decremented to 0 if this line is run
-			}
-		}
-		i--;
+		len = len - (px - payload);
+		payload = px;
 	}
 
-	
-	if(i == 0)
-	{
-		TRACE("http.c: ending boundary not found - ending data is valid");
-		
-		// Return ending pointer to the end
-		py = payload + len;
-	}
-	else
-	{
-		TRACE("http.c: ending boundary found");
-		final = 1;
-	}
-	
-	// Get length of uploaded part
-	data_len = py - px;
-	
-	// Check if any existing data needs to be handled
-	if(saved_bytes)
+	while(payload_index < len)
 	{
-		TRACE("http.c: %d saved bytes need to be cleared", saved_bytes);
-		
-		if(final)
+		if(pagebuff_index < PAGEBUFF_SIZE)
 		{
-			/* Final page needs to be written */
-			
-			// Fill 512-byte array
-			while(saved_bytes < IFLASH_PAGE_SIZE)
-			{
-				if(px < py)
-				{
-					// Write data
-					page[saved_bytes] = *px;
-					px++;
-					handled_bytes++;
-				}
-				else
-				{
-					// Append 0xFF
-					page[saved_bytes] = 0xFF;
-				}
-
-				saved_bytes++;
-			}
-			
-			// Write data to page
-			if(flash_write_page(&page))
-			{
-				TRACE("http.c: final firmware page written successfully");
-				page_ctr++;
-			}
-			else
-			{
-				TRACE("http.c: final firmware page write FAILED");
-			}
-		}
-		else if(saved_bytes + len < IFLASH_PAGE_SIZE)
-		{
-			int max_len = saved_bytes + len;
-			// Fill existing partially-complete page with new data
-			while(saved_bytes < max_len && handled_bytes < len)
-			{
-				page[saved_bytes] = *px;
-				if(px < py)
-				{
-					px++;
-				}
-				else
-				{
-					TRACE("http.c: ERROR - multi-part start pointer has passed the end pointer");
-				}
-				saved_bytes++;
-				handled_bytes++;
-			}
-			
-			// Handle edge-case
-			TRACE("http.c: unable to fill a complete page - skipping page write");
-			TRACE("http.c: %d bytes saved", saved_bytes);
-			
-			total_handled_bytes += handled_bytes;
-			
-			/* Handle partial boundary scenarios */
-			uint32_t curr_addr = flash_page_addr - IFLASH_PAGE_SIZE;	// Get start address of previously-written page
-			if(curr_addr > FLASH_BUFFER && curr_addr < FLASH_BUFFER_END)
-			{
-				memset(&shared_buffer, 0, SHARED_BUFFER_LEN);	// Clear shared_buffer
-				uint8_t * p_addr = curr_addr;					// Create a working pointer at flash page start
-				uint16_t ct = 0;								// shared buffer index
-				// Copy page into shared buffer
-				for(ct;ct<512;ct++)
-				{
-					shared_buffer[ct] = *p_addr;
-					p_addr++;
-				}
-				// Copy any saved bytes into the shared buffer
-				if(saved_bytes)
-				{
-					// Current page needs to be appended to the previously-written page
-					uint16_t ind = 0;
-					for(ind;ind0)
-				{
-					wind--;
-					// Latch onto '----' ("----[boundary ID]")
-					if(shared_buffer[wind-1] == '\x2d' && shared_buffer[wind-2] == '\x2d' && shared_buffer[wind-3] == '\x2d' && shared_buffer[wind-4] == '\x2d')
-					{
-						// Store the discovered boundary
-						char tmpID[BOUNDARY_MAX_LEN] = {0};
-						int z = 0;
-						while(z < BOUNDARY_MAX_LEN && shared_buffer[wind+z] != '\x2d' && shared_buffer[wind+z] != '\x0d' && shared_buffer[wind+z] != '\x0a' && (wind+z) < ct)
-						{
-							tmpID[z] = shared_buffer[wind+z];
-							z++;
-						}
-			
-						TRACE("http.c: discovered boundary ID : %s (shared buffer check)", tmpID);
-			
-						// Match the boundary ID with stored ID
-						if(strcmp(tmpID, boundary_ID) == 0)
-						{
-							TRACE("http.c: boundary IDs match");
-							TRACE("http.c: moving data end pointer");
-							// Traverse through the preceding newline characters
-							while(shared_buffer[wind-1] == '\x0d' || shared_buffer[wind-1] == '\x0a' || shared_buffer[wind-1] == '\x2d')
-							{
-								wind--;
-							}
-					
-							// Overwrite previous page
-							flash_page_addr = curr_addr;	// Move page write address to overwrite previous page
-							// Fill 512-byte array
-							int j = 0;
-							while(j < IFLASH_PAGE_SIZE)
-							{
-								if(j < wind)
-								{
-									// Write data
-									page[j] = shared_buffer[j];
-									//handled_bytes++;
-								}
-								else
-								{
-									// Append 0xFF
-									page[j] = 0xFF;
-								}
-
-								j++;
-							}
-								
-							// Write to page
-							if(flash_write_page(&page))
-							{
-								TRACE("http.c: page written successfully");
-								page_ctr++;
-							}
-							else
-							{
-								TRACE("http.c: page write FAILED");
-							}
-							
-							if(j= FLASH_BUFFER_END)
-			{
-				TRACE("http.c: ERROR - flash upper limit reached");
-			}
-			
-			return 1;
+			pagebuff[pagebuff_index] = payload[payload_index];
+			pagebuff_index++;
 		}
-		else
+		
+		if(pagebuff_index >= PAGEBUFF_SIZE)
 		{
-			// Fill existing partially-complete page with new data
-			while(saved_bytes < IFLASH_PAGE_SIZE && handled_bytes < len)
-			{
-				page[saved_bytes] = *px;
-				if(px < py)
-				{
-					px++;
-				}
-				else
-				{
-					TRACE("http.c: ERROR - multi-part start pointer has passed the end pointer");
-				}
-				saved_bytes++;
-				handled_bytes++;
-			}
+			boundary_ret = process_pagebuff(pagebuff, pagebuff_index, boundary_ID);
+			if(boundary_ret == 1)	break;
 			
-			// Write data to page
-			if(flash_write_page(&page))
-			{
-				TRACE("http.c: firmware page written successfully");
-				page_ctr++;
-			}
-			else
-			{
-				TRACE("http.c: firmware page write FAILED");
-			}
+			pagebuff_index = send_pagebuff(pagebuff, pagebuff_index);
 		}
-				
-		// Saved bytes have been handled - clear the counter
-		saved_bytes = 0;
 		
-		TRACE("http.c: saved bytes have been cleared");		
-		TRACE("http.c: handled_bytes: %04d, data_len: %04d", handled_bytes, data_len);
+		payload_index++;
 	}
-
-	while(handled_bytes < data_len)
-	{
-		if(data_len - handled_bytes >= IFLASH_PAGE_SIZE)
-		{
-			// Fill 512-byte array
-			int j = 0;
-			while(j < IFLASH_PAGE_SIZE)
-			{
-				page[j] = *px;
-				if(px < py)
-				{
-					px++;	
-				}
-				else
-				{
-					TRACE("http.c: ERROR - multi-part start pointer has passed the end pointer");
-				}
-				j++;
-				handled_bytes++;
-			}
-			
-			// Write to page
-			if(flash_write_page(&page))
-			{
-				TRACE("http.c: firmware page written successfully");
-				page_ctr++;
-			}
-			else
-			{
-				TRACE("http.c: firmware page write FAILED");
-			}
-		}
-		else if(!final)
-		{
-			/* Data needs to be saved */
-			TRACE("http.c: data needs to be saved");
-			
-			// Save leftover into page array for next run-through
-			int j = 0;
-			while(handled_bytes < data_len)
-			{
-				page[j] = *px;
-				if(px < py)
-				{
-					px++;
-				}
-				else
-				{
-					TRACE("http.c: ERROR - multi-part start pointer has passed the end pointer");
-				}
-				j++;
-				handled_bytes++;
-				saved_bytes++;
-			}
-			
-			TRACE("http.c: %d bytes saved", saved_bytes);
-		}
-		else
-		{
-			/* Final page needs to be written */
-			
-			// Fill 512-byte array
-			int j = 0;
-			while(j < IFLASH_PAGE_SIZE)
-			{
-				if(px < py)
-				{
-					// Write data
-					page[j] = *px;
-					px++;
-					handled_bytes++;
-				}
-				else
-				{
-					// Append 0xFF
-					page[j] = 0xFF;
-				}
-
-				j++;
-			}
-			
-			// Write to page
-			if(flash_write_page(&page))
-			{
-				TRACE("http.c: final page written successfully");
-				page_ctr++;
-			}
-			else
-			{
-				TRACE("http.c: final page write FAILED");
-			}
-		}
-	
-		TRACE("http.c: handled_bytes: %04d, data_len: %04d", handled_bytes, data_len);
-	}	
 	
-	total_handled_bytes += handled_bytes;
-	TRACE("http.c: total_handled_bytes: %d", total_handled_bytes);
+	if(boundary_ret == 0)
+	{
+		boundary_ret = process_pagebuff(pagebuff, pagebuff_index, boundary_ID);
+	}
 	
-	/* Handle partial boundary scenarios */
-	uint32_t curr_addr = flash_page_addr - IFLASH_PAGE_SIZE;	// Get start address of previously-written page
-	if(curr_addr > FLASH_BUFFER && curr_addr < FLASH_BUFFER_END)
+	if(boundary_ret == 1)
 	{
-		memset(&shared_buffer, 0, SHARED_BUFFER_LEN);	// Clear shared_buffer
-		uint8_t * p_addr = curr_addr;					// Create a working pointer at flash page start
-		uint16_t ct = 0;								// shared buffer index
-		// Copy page into shared buffer
-		for(ct;ct<512;ct++)
-		{
-			shared_buffer[ct] = *p_addr;
-			p_addr++;
-		}
-		// Copy any saved bytes into the shared buffer
-		if(saved_bytes)
+		if(pagebuff_index >= 512)
 		{
-			// Current page needs to be appended to the previously-written page
-			uint16_t ind = 0;
-			for(ind;ind0)
+		else
 		{
-			wind--;
-			// Latch onto '----' ("----[boundary ID]")
-			if(shared_buffer[wind-1] == '\x2d' && shared_buffer[wind-2] == '\x2d' && shared_buffer[wind-3] == '\x2d' && shared_buffer[wind-4] == '\x2d')
-			{
-				// Store the discovered boundary
-				char tmpID[BOUNDARY_MAX_LEN] = {0};
-				int z = 0;
-				while(z < BOUNDARY_MAX_LEN && shared_buffer[wind+z] != '\x2d' && shared_buffer[wind+z] != '\x0d' && shared_buffer[wind+z] != '\x0a' && (wind+z) < ct)
-				{
-					tmpID[z] = shared_buffer[wind+z];
-					z++;
-				}
-			
-				TRACE("http.c: discovered boundary ID : %s (shared buffer check)", tmpID);
-			
-				// Match the boundary ID with stored ID
-				if(strcmp(tmpID, boundary_ID) == 0)
-				{
-					TRACE("http.c: boundary IDs match");
-					TRACE("http.c: moving data end pointer");
-					// Traverse through the preceding newline characters
-					while(shared_buffer[wind-1] == '\x0d' || shared_buffer[wind-1] == '\x0a' || shared_buffer[wind-1] == '\x2d')
-					{
-						wind--;
-					}
-					
-					// Overwrite previous page
-					flash_page_addr = curr_addr;	// Move page write address to overwrite previous page
-					// Fill 512-byte array
-					int j = 0;
-					while(j < IFLASH_PAGE_SIZE)
-					{
-						if(j < wind)
-						{
-							// Write data
-							page[j] = shared_buffer[j];
-							//handled_bytes++;
-						}
-						else
-						{
-							// Append 0xFF
-							page[j] = 0xFF;
-						}
-
-						j++;
-					}
-								
-					// Write to page
-					if(flash_write_page(&page))
-					{
-						TRACE("http.c: page written successfully");
-						page_ctr++;
-					}
-					else
-					{
-						TRACE("http.c: page write FAILED");
-					}
-					
-					if(j= FLASH_BUFFER_END)
-	{
-		TRACE("http.c: ERROR - flash upper limit reached");
-	}
-
-	if(final)
-	{		
+		
 		return 2;
 	}
-	else
+	
+	if(pagebuff_index >= 512)
 	{
-		return 1;
+		pagebuff_index = send_pagebuff(pagebuff, pagebuff_index);	
 	}
+
+	return 1;
 }
 
 static uint8_t Config_Network(char *payload, int len)
@@ -4362,4 +3873,91 @@ static uint8_t interfaceCreate_Restart(void)
 		TRACE("http.c: WARNING: html truncated to prevent buffer overflow");
 		return 0;
 	}
-}
\ No newline at end of file
+}
+
+static uint8_t	process_pagebuff(uint8_t * buff_addr, uint16_t buff_index, uint8_t * match_addr)
+{
+	if(buff_index < BOUNDARY_MAX_LEN)
+	{
+		return 0;
+	}
+	// Search for ending boundary
+	uint16_t tmp_index = buff_index-1;
+	while(tmp_index >= 4)
+	{
+		// Latch onto '----'
+		if(buff_addr[tmp_index-1] == '\x2d' && buff_addr[tmp_index-2] == '\x2d' && buff_addr[tmp_index-3] == '\x2d' && buff_addr[tmp_index-4] == '\x2d')
+		{
+			uint8_t tmp_ID[BOUNDARY_MAX_LEN] = {0};
+			
+			uint16_t i=0;
+			while(i 0 &&\
+							(buff_addr[tmp_index] == '\x0d'\
+							|| buff_addr[tmp_index] == '\x0a'\
+							|| buff_addr[tmp_index] == '\x2d'));
+				
+				tmp_index++;
+				while(tmp_index < PAGEBUFF_SIZE)
+				{
+					buff_addr[tmp_index] = 0xFF;
+					tmp_index++;
+				}
+				
+				return 1;
+			}
+			else
+			{
+				break;
+			}
+		}
+		
+		tmp_index--;
+	}
+	
+	
+	return 0;
+}
+
+static uint16_t	send_pagebuff(uint8_t * buff_addr, uint16_t buff_index)
+{
+	// Always writes 1 page
+	if(!flash_write_page(buff_addr))
+	{
+		TRACE("http.c: ERROR - page write failed");
+	}
+	
+	if(buff_index >= IFLASH_PAGE_SIZE)
+	{
+		// Copy unwritten bytes into bottom of array
+		uint16_t tmp_index = buff_index - IFLASH_PAGE_SIZE;
+		for(uint16_t i=0;i
Date: Mon, 10 Apr 2017 14:50:54 +1000
Subject: [PATCH 029/169] Remove html buffer write messages

---
 ZodiacFX/src/http.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index a8629e3..6a09704 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -1862,11 +1862,9 @@ static uint8_t interfaceCreate_Frames(void)
 				""\
 			""\
 				);
-	TRACE("http.c: html written to buffer");
 
 	if(strlen(shared_buffer) < 2048)
 	{
-		TRACE("http.c: http/html written to buffer");
 		return 1;
 	}
 	else
@@ -1943,7 +1941,6 @@ static uint8_t interfaceCreate_Header(void)
 			""\
 				, hr, min) < SHARED_BUFFER_LEN)
 	{
-		TRACE("http.c: html written to buffer");
 		return 1;
 	}
 	else
@@ -2012,7 +2009,6 @@ static uint8_t interfaceCreate_Menu(void)
 		""\
 				) < SHARED_BUFFER_LEN)
 	{
-		TRACE("http.c: html written to buffer");
 		return 1;
 	}
 	else
@@ -2061,7 +2057,6 @@ static uint8_t interfaceCreate_Home(void)
 				, uid_buf[0], uid_buf[1], uid_buf[2], uid_buf[3]\
 				, VERSION, (int)ul_temp, hr, min) < SHARED_BUFFER_LEN)
 	{
-		TRACE("http.c: html written to buffer");
 		return 1;
 	}
 	else
@@ -2103,7 +2098,6 @@ static uint8_t interfaceCreate_Upload(void)
 		""\
 	) < SHARED_BUFFER_LEN)
 	{
-		TRACE("http.c: html written to buffer");
 		return 1;
 	}
 	else
@@ -2255,7 +2249,6 @@ static uint8_t interfaceCreate_Display_Home(void)
 		""\
 	) < SHARED_BUFFER_LEN)
 	{
-		TRACE("http.c: html written to buffer");
 		return 1;
 	}
 	else
@@ -2458,7 +2451,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step)
 					""\
 				) < SHARED_BUFFER_LEN)
 		{
-			TRACE("http.c: html (1/2) written to buffer");
 			return 1;
 		}
 		else
@@ -2743,7 +2735,6 @@ static uint8_t interfaceCreate_Display_OpenFlow(void)
 		, wi_ofStatus , wi_ofVersion , wi_ofTables , wi_ofFlows , wi_ofLookups , wi_ofMatches\
 	) < SHARED_BUFFER_LEN)
 	{
-		TRACE("http.c: html written to buffer");
 		return 1;
 	}
 	else
@@ -3246,7 +3237,6 @@ if (iLastFlow > 0)
 		""\
 	) < SHARED_BUFFER_LEN)
 	{
-		TRACE("http.c: html written to buffer");
 		return 1;
 	}
 	else
@@ -3429,7 +3419,6 @@ static uint8_t interfaceCreate_Display_Meters(void)
 		""\
 	) < SHARED_BUFFER_LEN)
 	{
-		TRACE("http.c: html written to buffer");
 		return 1;
 	}
 	else
@@ -3477,7 +3466,6 @@ static uint8_t interfaceCreate_Config_Home(void)
 		""\
 		) < SHARED_BUFFER_LEN)
 	{
-		TRACE("http.c: html written to buffer");
 		return 1;
 	}
 	else
@@ -3535,7 +3523,6 @@ static uint8_t interfaceCreate_Config_Network(void)
 			, Zodiac_Config.gateway_address[0], Zodiac_Config.gateway_address[1], Zodiac_Config.gateway_address[2], Zodiac_Config.gateway_address[3]\
 		) < SHARED_BUFFER_LEN)
 	{
-		TRACE("http.c: html written to buffer");
 		return 1;
 	}
 	else
@@ -3653,7 +3640,6 @@ static uint8_t interfaceCreate_Config_VLANs(void)
 		""\
 		) < SHARED_BUFFER_LEN)
 	{
-		TRACE("http.c: VLAN base written to buffer");
 		return 1;
 	}
 	else
@@ -3786,7 +3772,6 @@ static uint8_t interfaceCreate_Config_OpenFlow(void)
 		""\
 		) < SHARED_BUFFER_LEN)
 		{
-			TRACE("http.c: OpenFlow Config page written to buffer");
 			return 1;
 		}
 		else
@@ -3865,7 +3850,6 @@ static uint8_t interfaceCreate_Restart(void)
 		""\
 				) < SHARED_BUFFER_LEN)
 	{
-		TRACE("http.c: html written to buffer");
 		return 1;
 	}
 	else

From 7c8ae71dd6f009f5935a537efabc1771e8ce8418 Mon Sep 17 00:00:00 2001
From: Kristopher Chen 
Date: Mon, 10 Apr 2017 15:02:49 +1000
Subject: [PATCH 030/169] Add error message for oversized firmware

The web interface displays an error if firmware >~228k is uploaded.
---
 ZodiacFX/src/http.c | 172 +++++++++++++++++++++-----------------------
 1 file changed, 83 insertions(+), 89 deletions(-)

diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c
index 6a09704..d6fc6e3 100644
--- a/ZodiacFX/src/http.c
+++ b/ZodiacFX/src/http.c
@@ -338,14 +338,30 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err
 				else
 				{
 					upload_handler(NULL, 0);	// Clean up upload operation
-					if(interfaceCreate_Upload_Status(3))
+
+					if(flash_page_addr >= FLASH_BUFFER_END-IFLASH_PAGE_SIZE)
 					{
-						http_send(&shared_buffer, pcb, 1);
-						TRACE("http.c: Page sent successfully - %d bytes", strlen(shared_buffer));
+						if(interfaceCreate_Upload_Status(5))
+						{
+							http_send(&shared_buffer, pcb, 1);
+							TRACE("http.c: Page sent successfully - %d bytes", strlen(shared_buffer));
+						}
+						else
+						{
+							TRACE("http.c: Unable to serve page - buffer at %d bytes", strlen(shared_buffer));
+						}
 					}
 					else
 					{
-						TRACE("http.c: Unable to serve page - buffer at %d bytes", strlen(shared_buffer));
+						if(interfaceCreate_Upload_Status(3))
+						{
+							http_send(&shared_buffer, pcb, 1);
+							TRACE("http.c: Page sent successfully - %d bytes", strlen(shared_buffer));
+						}
+						else
+						{
+							TRACE("http.c: Unable to serve page - buffer at %d bytes", strlen(shared_buffer));
+						}
 					}
 				}
 			}
@@ -2113,98 +2129,77 @@ static uint8_t interfaceCreate_Upload(void)
 */
 static uint8_t interfaceCreate_Upload_Status(uint8_t sel)
 {
-	if(sel == 1)
-	{	
-		snprintf(shared_buffer, SHARED_BUFFER_LEN,\
-			""\
-				""\
-					""\
-						""\
-					""\
-					""\
-						"

"\ - "

Firmware Update

"\ - "

"\ - ""\ - "

Firmware upload successful.

"\ - "Zodiac FX will be updated on the next restart.

"\ - "
"\ - ""\ - "
"\ - ""\ - ""\ - ) < SHARED_BUFFER_LEN) - { - TRACE("http.c: html written to buffer"); - return 1; - } - else - { - TRACE("http.c: WARNING: html truncated to prevent buffer overflow"); - return 0; - } + snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + ""\ + ""\ + ""\ + "

"\ + "

Firmware Update

"\ + "

"\ + ""\ + ); + if(sel == 1) + { + snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + "

Firmware upload successful.

"\ + "Zodiac FX will be updated on the next restart.

"\ + "
"\ + ""\ + "
"\ + ); } - else + else if(sel == 2) { - snprintf(shared_buffer, SHARED_BUFFER_LEN,\ - ""\ - ""\ - ""\ - ""\ - ""\ - ""\ - "

"\ - "

Firmware Update

"\ - "

"\ - ""\ - ); - if(sel == 2) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "

Firmware upload interrupted. Please try again.

"\ - ); - } - else if(sel == 3) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "

Firmware upload failed. Unable to verify firmware. Please try again, or check the integrity of the firmware.

"\ - ); - } - else if(sel == 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "

Firmware upload in progress. Please try again in 30 seconds.

"\ + "

Firmware upload interrupted. Please try again.

"\ ); - } - else - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "

Firmware upload failed. Please try again.

"\ + } + else if(sel == 3) + { + snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + "

Firmware upload failed. Unable to verify firmware. Please try again, or check the integrity of the firmware.

"\ ); - } + } + else if(sel == 4) + { + snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + "

Firmware upload in progress. Please try again in 30 seconds.

"\ + ); + } + else if(sel == 5) + { + snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + "

Firmware upload failed. Zodiac FX supports binaries of up to 228k in size.

"\ + ); + } + else + { + snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + "

Firmware upload failed. Please try again.

"\ + ); + } - if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - ""\ - ""\ - ) < SHARED_BUFFER_LEN) - { - TRACE("http.c: html written to buffer"); - return 1; - } - else - { - TRACE("http.c: WARNING: html truncated to prevent buffer overflow"); - return 0; - } + if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + ""\ + ""\ + ) < SHARED_BUFFER_LEN) + { + return 1; } + else + { + TRACE("http.c: WARNING: html truncated to prevent buffer overflow"); + return 0; + } + } /* @@ -3814,7 +3809,6 @@ static uint8_t interfaceCreate_About(void) ""\ ) < SHARED_BUFFER_LEN) { - TRACE("http.c: html written to buffer"); return 1; } else From ddc37cf4a564e081e0419abc5fd8aff76454c3ed Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 10 Apr 2017 15:43:46 +1000 Subject: [PATCH 031/169] Fix meter features reply Supported band types is a bitmap of values --- ZodiacFX/src/openflow/openflow_13.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 72a3c83..7d213fd 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -1539,7 +1539,7 @@ int multi_meter_features_reply13(uint8_t *buffer, struct ofp13_multipart_request // Format reply with meter features meter_features.max_meter = htonl(MAX_METER_13); - meter_features.band_types = htonl(OFPMBT13_DSCP_REMARK | OFPMBT13_DROP); // Only OFPMBT_DROP supported + meter_features.band_types = htonl(1< Date: Sun, 16 Apr 2017 17:46:31 +1000 Subject: [PATCH 032/169] Stacking port stats message --- ZodiacFX/ZodiacFX.cproj | 558 +++++++++++++++---------------- ZodiacFX/src/command.c | 9 +- ZodiacFX/src/flash.c | 1 + ZodiacFX/src/openflow/openflow.h | 2 - ZodiacFX/src/stacking.c | 142 +++++++- ZodiacFX/src/stacking.h | 16 +- ZodiacFX/src/switch.c | 32 +- ZodiacFX/src/switch.h | 6 + 8 files changed, 453 insertions(+), 313 deletions(-) diff --git a/ZodiacFX/ZodiacFX.cproj b/ZodiacFX/ZodiacFX.cproj index 1d5afa1..ab4e3bd 100644 --- a/ZodiacFX/ZodiacFX.cproj +++ b/ZodiacFX/ZodiacFX.cproj @@ -285,290 +285,290 @@ - True - True - True - True - True - - - NDEBUG - scanf=iscanf - BOARD=USER_BOARD - ARM_MATH_CM4=true - printf=iprintf - UDD_ENABLE - - - False - - - ../common/applications/user_application/user_board/config - ../src/config - ../src/ASF/thirdparty/CMSIS/Lib/GCC - ../src/ASF/common/utils - ../src - ../src/ASF/sam/utils/fpu - ../src/ASF/sam/utils - ../src/ASF/sam/utils/preprocessor - ../src/ASF/sam/utils/cmsis/sam4e/include - ../src/ASF/common/boards - ../src/ASF/sam/utils/header_files - ../src/ASF/common/boards/user_board - ../src/ASF/thirdparty/CMSIS/Include - ../src/ASF/sam/utils/cmsis/sam4e/source/templates - ../src/ASF/sam/drivers/pmc - ../src/ASF/common/services/clock - ../src/ASF/common/services/ioport - ../src/ASF/common/services/spi/sam_usart_spi - ../src/ASF/common/services/spi - ../src/ASF/common/services/twi - ../src/ASF/sam/drivers/twi - ../src/ASF/sam/drivers/usart - ../src/ASF/sam/drivers/gmac - ../src/ASF/sam/drivers/matrix - ../src/ASF/sam/drivers/pio - ../src/ASF/sam/drivers/rtc - ../src/ASF/common/services/sleepmgr - ../src/ASF/common/services/usb - ../src/ASF/common/services/usb/class/cdc - ../src/ASF/common/services/usb/class/cdc/device - ../src/ASF/common/services/usb/udc - ../src/ASF/common/utils/stdio/stdio_usb - ../src/ASF/sam/drivers/udp - ../src/ASF/sam/drivers/tc - ../src/ASF/common/services/spi/sam_spi - ../src/ASF/sam/drivers/spi - ../src/ASF/sam/drivers/rstc - ../src/lwip/include - ../src/lwip - ../src/lwip/include/ipv4 - ../src/ASF/sam/drivers/afec - ../src/ASF/common/utils/membag - ../src/ASF/sam/drivers/efc - ../src/ASF/sam/services/flash_efc - - - Optimize (-O1) - -fdata-sections - True - True - -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 - - - libarm_cortexM4lf_math_softfp - libm - - - - - ../cmsis/linkerScripts - ../src/ASF/thirdparty/CMSIS/Lib/GCC - - - True - - -Wl,--defsym,__stack_size__=0x1400 -Wl,--entry=Reset_Handler -Wl,-section-start=.text=0x00410000 -Wl,--cref -mthumb -T../src/ASF/sam/utils/linker_scripts/sam4e/sam4e8/gcc/flash.ld - - - ../src/ASF/sam/drivers/efc - ../src/ASF/sam/services/flash_efc - - - -DARM_MATH_CM4=true -DBOARD=USER_BOARD -Dprintf=iprintf -Dscanf=iscanf -DUDD_ENABLE - False - - - ../common/applications/user_application/user_board/config - ../src/config - ../src/ASF/thirdparty/CMSIS/Lib/GCC - ../src/ASF/common/utils - ../src - ../src/ASF/sam/utils/fpu - ../src/ASF/sam/utils - ../src/ASF/sam/utils/preprocessor - ../src/ASF/sam/utils/cmsis/sam4e/include - ../src/ASF/common/boards - ../src/ASF/sam/utils/header_files - ../src/ASF/common/boards/user_board - ../src/ASF/thirdparty/CMSIS/Include - ../src/ASF/sam/utils/cmsis/sam4e/source/templates - ../src/ASF/sam/drivers/pmc - ../src/ASF/common/services/clock - ../src/ASF/common/services/ioport - ../src/ASF/common/services/spi/sam_usart_spi - ../src/ASF/common/services/spi - ../src/ASF/common/services/twi - ../src/ASF/sam/drivers/twi - ../src/ASF/sam/drivers/usart - ../src/ASF/sam/drivers/gmac - ../src/ASF/sam/drivers/matrix - ../src/ASF/sam/drivers/pio - ../src/ASF/sam/drivers/rtc - ../src/ASF/common/services/sleepmgr - ../src/ASF/common/services/usb - ../src/ASF/common/services/usb/class/cdc - ../src/ASF/common/services/usb/class/cdc/device - ../src/ASF/common/services/usb/udc - ../src/ASF/common/utils/stdio/stdio_usb - ../src/ASF/sam/drivers/udp - ../src/ASF/sam/drivers/tc - ../src/ASF/common/services/spi/sam_spi - ../src/ASF/sam/drivers/spi - ../src/ASF/sam/drivers/rstc - ../src/ASF/sam/drivers/afec - ../src/ASF/common/utils/membag - ../src/ASF/sam/drivers/efc - ../src/ASF/sam/services/flash_efc - - - + True + True + True + True + True + + + NDEBUG + scanf=iscanf + BOARD=USER_BOARD + ARM_MATH_CM4=true + printf=iprintf + UDD_ENABLE + + + False + + + ../common/applications/user_application/user_board/config + ../src/config + ../src/ASF/thirdparty/CMSIS/Lib/GCC + ../src/ASF/common/utils + ../src + ../src/ASF/sam/utils/fpu + ../src/ASF/sam/utils + ../src/ASF/sam/utils/preprocessor + ../src/ASF/sam/utils/cmsis/sam4e/include + ../src/ASF/common/boards + ../src/ASF/sam/utils/header_files + ../src/ASF/common/boards/user_board + ../src/ASF/thirdparty/CMSIS/Include + ../src/ASF/sam/utils/cmsis/sam4e/source/templates + ../src/ASF/sam/drivers/pmc + ../src/ASF/common/services/clock + ../src/ASF/common/services/ioport + ../src/ASF/common/services/spi/sam_usart_spi + ../src/ASF/common/services/spi + ../src/ASF/common/services/twi + ../src/ASF/sam/drivers/twi + ../src/ASF/sam/drivers/usart + ../src/ASF/sam/drivers/gmac + ../src/ASF/sam/drivers/matrix + ../src/ASF/sam/drivers/pio + ../src/ASF/sam/drivers/rtc + ../src/ASF/common/services/sleepmgr + ../src/ASF/common/services/usb + ../src/ASF/common/services/usb/class/cdc + ../src/ASF/common/services/usb/class/cdc/device + ../src/ASF/common/services/usb/udc + ../src/ASF/common/utils/stdio/stdio_usb + ../src/ASF/sam/drivers/udp + ../src/ASF/sam/drivers/tc + ../src/ASF/common/services/spi/sam_spi + ../src/ASF/sam/drivers/spi + ../src/ASF/sam/drivers/rstc + ../src/lwip/include + ../src/lwip + ../src/lwip/include/ipv4 + ../src/ASF/sam/drivers/afec + ../src/ASF/common/utils/membag + ../src/ASF/sam/drivers/efc + ../src/ASF/sam/services/flash_efc + + + Optimize (-O1) + -fdata-sections + True + True + -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 + + + libarm_cortexM4lf_math_softfp + libm + + + + + ../cmsis/linkerScripts + ../src/ASF/thirdparty/CMSIS/Lib/GCC + + + True + + -Wl,--defsym,__stack_size__=0x1400 -Wl,--entry=Reset_Handler -Wl,-section-start=.text=0x00410000 -Wl,--cref -mthumb -T../src/ASF/sam/utils/linker_scripts/sam4e/sam4e8/gcc/flash.ld + + + ../src/ASF/sam/drivers/efc + ../src/ASF/sam/services/flash_efc + + + -DARM_MATH_CM4=true -DBOARD=USER_BOARD -Dprintf=iprintf -Dscanf=iscanf -DUDD_ENABLE + False + + + ../common/applications/user_application/user_board/config + ../src/config + ../src/ASF/thirdparty/CMSIS/Lib/GCC + ../src/ASF/common/utils + ../src + ../src/ASF/sam/utils/fpu + ../src/ASF/sam/utils + ../src/ASF/sam/utils/preprocessor + ../src/ASF/sam/utils/cmsis/sam4e/include + ../src/ASF/common/boards + ../src/ASF/sam/utils/header_files + ../src/ASF/common/boards/user_board + ../src/ASF/thirdparty/CMSIS/Include + ../src/ASF/sam/utils/cmsis/sam4e/source/templates + ../src/ASF/sam/drivers/pmc + ../src/ASF/common/services/clock + ../src/ASF/common/services/ioport + ../src/ASF/common/services/spi/sam_usart_spi + ../src/ASF/common/services/spi + ../src/ASF/common/services/twi + ../src/ASF/sam/drivers/twi + ../src/ASF/sam/drivers/usart + ../src/ASF/sam/drivers/gmac + ../src/ASF/sam/drivers/matrix + ../src/ASF/sam/drivers/pio + ../src/ASF/sam/drivers/rtc + ../src/ASF/common/services/sleepmgr + ../src/ASF/common/services/usb + ../src/ASF/common/services/usb/class/cdc + ../src/ASF/common/services/usb/class/cdc/device + ../src/ASF/common/services/usb/udc + ../src/ASF/common/utils/stdio/stdio_usb + ../src/ASF/sam/drivers/udp + ../src/ASF/sam/drivers/tc + ../src/ASF/common/services/spi/sam_spi + ../src/ASF/sam/drivers/spi + ../src/ASF/sam/drivers/rstc + ../src/ASF/sam/drivers/afec + ../src/ASF/common/utils/membag + ../src/ASF/sam/drivers/efc + ../src/ASF/sam/services/flash_efc + + + - True - True - True - True - True - - - DEBUG - scanf=iscanf - BOARD=USER_BOARD - ARM_MATH_CM4=true - printf=iprintf - UDD_ENABLE - - - False - - - ../common/applications/user_application/user_board/config - ../src/config - ../src/ASF/thirdparty/CMSIS/Lib/GCC - ../src/ASF/common/utils - ../src - ../src/ASF/sam/utils/fpu - ../src/ASF/sam/utils - ../src/ASF/sam/utils/preprocessor - ../src/ASF/sam/utils/cmsis/sam4e/include - ../src/ASF/common/boards - ../src/ASF/sam/utils/header_files - ../src/ASF/common/boards/user_board - ../src/ASF/thirdparty/CMSIS/Include - ../src/ASF/sam/utils/cmsis/sam4e/source/templates - ../src/ASF/sam/drivers/pmc - ../src/ASF/common/services/clock - ../src/ASF/common/services/ioport - ../src/ASF/common/services/spi/sam_usart_spi - ../src/ASF/common/services/spi - ../src/ASF/common/services/twi - ../src/ASF/sam/drivers/twi - ../src/ASF/sam/drivers/usart - ../src/ASF/sam/drivers/gmac - ../src/ASF/sam/drivers/matrix - ../src/ASF/sam/drivers/pio - ../src/ASF/sam/drivers/rtc - ../src/ASF/common/services/sleepmgr - ../src/ASF/common/services/usb - ../src/ASF/common/services/usb/class/cdc - ../src/ASF/common/services/usb/class/cdc/device - ../src/ASF/common/services/usb/udc - ../src/ASF/common/utils/stdio/stdio_usb - ../src/ASF/sam/drivers/udp - ../src/lwip - ../src/lwip/include - ../src/lwip/include/ipv4 - ../src/ASF/sam/drivers/tc - ../src/ASF/common/services/spi/sam_spi - ../src/ASF/sam/drivers/spi - ../src/ASF/sam/drivers/rstc - ../src/ASF/sam/drivers/afec - ../src/ASF/common/utils/membag - ../src/ASF/sam/drivers/efc - ../src/ASF/sam/services/flash_efc - - - -fdata-sections - True - Maximum (-g3) - True - -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 - True - - - libarm_cortexM4lf_math_softfp - libm - - - - - ../cmsis/linkerScripts - ../src/ASF/thirdparty/CMSIS/Lib/GCC - - - True - - -Wl,--defsym,__stack_size__=0x1400 -Wl,--entry=Reset_Handler -Wl,--cref -mthumb -T../src/ASF/sam/utils/linker_scripts/sam4e/sam4e8/gcc/flash.ld - - - ../src/ASF/sam/drivers/efc - ../src/ASF/sam/services/flash_efc - - - Default (-g) - -DARM_MATH_CM4=true -DBOARD=USER_BOARD -Dprintf=iprintf -Dscanf=iscanf -DUDD_ENABLE - False - - - ../common/applications/user_application/user_board/config - ../src/config - ../src/ASF/thirdparty/CMSIS/Lib/GCC - ../src/ASF/common/utils - ../src - ../src/ASF/sam/utils/fpu - ../src/ASF/sam/utils - ../src/ASF/sam/utils/preprocessor - ../src/ASF/sam/utils/cmsis/sam4e/include - ../src/ASF/common/boards - ../src/ASF/sam/utils/header_files - ../src/ASF/common/boards/user_board - ../src/ASF/thirdparty/CMSIS/Include - ../src/ASF/sam/utils/cmsis/sam4e/source/templates - ../src/ASF/sam/drivers/pmc - ../src/ASF/common/services/clock - ../src/ASF/common/services/ioport - ../src/ASF/common/services/spi/sam_usart_spi - ../src/ASF/common/services/spi - ../src/ASF/common/services/twi - ../src/ASF/sam/drivers/twi - ../src/ASF/sam/drivers/usart - ../src/ASF/sam/drivers/gmac - ../src/ASF/sam/drivers/matrix - ../src/ASF/sam/drivers/pio - ../src/ASF/sam/drivers/rtc - ../src/ASF/common/services/sleepmgr - ../src/ASF/common/services/usb - ../src/ASF/common/services/usb/class/cdc - ../src/ASF/common/services/usb/class/cdc/device - ../src/ASF/common/services/usb/udc - ../src/ASF/common/utils/stdio/stdio_usb - ../src/ASF/sam/drivers/udp - ../src/ASF/sam/drivers/tc - ../src/ASF/common/services/spi/sam_spi - ../src/ASF/sam/drivers/spi - ../src/ASF/sam/drivers/rstc - ../src/ASF/sam/drivers/afec - ../src/ASF/common/utils/membag - ../src/ASF/sam/drivers/efc - ../src/ASF/sam/services/flash_efc - - - Default (-Wa,-g) - + True + True + True + True + True + + + DEBUG + scanf=iscanf + BOARD=USER_BOARD + ARM_MATH_CM4=true + printf=iprintf + UDD_ENABLE + + + False + + + ../common/applications/user_application/user_board/config + ../src/config + ../src/ASF/thirdparty/CMSIS/Lib/GCC + ../src/ASF/common/utils + ../src + ../src/ASF/sam/utils/fpu + ../src/ASF/sam/utils + ../src/ASF/sam/utils/preprocessor + ../src/ASF/sam/utils/cmsis/sam4e/include + ../src/ASF/common/boards + ../src/ASF/sam/utils/header_files + ../src/ASF/common/boards/user_board + ../src/ASF/thirdparty/CMSIS/Include + ../src/ASF/sam/utils/cmsis/sam4e/source/templates + ../src/ASF/sam/drivers/pmc + ../src/ASF/common/services/clock + ../src/ASF/common/services/ioport + ../src/ASF/common/services/spi/sam_usart_spi + ../src/ASF/common/services/spi + ../src/ASF/common/services/twi + ../src/ASF/sam/drivers/twi + ../src/ASF/sam/drivers/usart + ../src/ASF/sam/drivers/gmac + ../src/ASF/sam/drivers/matrix + ../src/ASF/sam/drivers/pio + ../src/ASF/sam/drivers/rtc + ../src/ASF/common/services/sleepmgr + ../src/ASF/common/services/usb + ../src/ASF/common/services/usb/class/cdc + ../src/ASF/common/services/usb/class/cdc/device + ../src/ASF/common/services/usb/udc + ../src/ASF/common/utils/stdio/stdio_usb + ../src/ASF/sam/drivers/udp + ../src/lwip + ../src/lwip/include + ../src/lwip/include/ipv4 + ../src/ASF/sam/drivers/tc + ../src/ASF/common/services/spi/sam_spi + ../src/ASF/sam/drivers/spi + ../src/ASF/sam/drivers/rstc + ../src/ASF/sam/drivers/afec + ../src/ASF/common/utils/membag + ../src/ASF/sam/drivers/efc + ../src/ASF/sam/services/flash_efc + + + -fdata-sections + True + Maximum (-g3) + True + -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 + True + + + libarm_cortexM4lf_math_softfp + libm + + + + + ../cmsis/linkerScripts + ../src/ASF/thirdparty/CMSIS/Lib/GCC + + + True + + -Wl,--defsym,__stack_size__=0x1400 -Wl,--entry=Reset_Handler -Wl,--cref -mthumb -T../src/ASF/sam/utils/linker_scripts/sam4e/sam4e8/gcc/flash.ld + + + ../src/ASF/sam/drivers/efc + ../src/ASF/sam/services/flash_efc + + + Default (-g) + -DARM_MATH_CM4=true -DBOARD=USER_BOARD -Dprintf=iprintf -Dscanf=iscanf -DUDD_ENABLE + False + + + ../common/applications/user_application/user_board/config + ../src/config + ../src/ASF/thirdparty/CMSIS/Lib/GCC + ../src/ASF/common/utils + ../src + ../src/ASF/sam/utils/fpu + ../src/ASF/sam/utils + ../src/ASF/sam/utils/preprocessor + ../src/ASF/sam/utils/cmsis/sam4e/include + ../src/ASF/common/boards + ../src/ASF/sam/utils/header_files + ../src/ASF/common/boards/user_board + ../src/ASF/thirdparty/CMSIS/Include + ../src/ASF/sam/utils/cmsis/sam4e/source/templates + ../src/ASF/sam/drivers/pmc + ../src/ASF/common/services/clock + ../src/ASF/common/services/ioport + ../src/ASF/common/services/spi/sam_usart_spi + ../src/ASF/common/services/spi + ../src/ASF/common/services/twi + ../src/ASF/sam/drivers/twi + ../src/ASF/sam/drivers/usart + ../src/ASF/sam/drivers/gmac + ../src/ASF/sam/drivers/matrix + ../src/ASF/sam/drivers/pio + ../src/ASF/sam/drivers/rtc + ../src/ASF/common/services/sleepmgr + ../src/ASF/common/services/usb + ../src/ASF/common/services/usb/class/cdc + ../src/ASF/common/services/usb/class/cdc/device + ../src/ASF/common/services/usb/udc + ../src/ASF/common/utils/stdio/stdio_usb + ../src/ASF/sam/drivers/udp + ../src/ASF/sam/drivers/tc + ../src/ASF/common/services/spi/sam_spi + ../src/ASF/sam/drivers/spi + ../src/ASF/sam/drivers/rstc + ../src/ASF/sam/drivers/afec + ../src/ASF/common/utils/membag + ../src/ASF/sam/drivers/efc + ../src/ASF/sam/services/flash_efc + + + Default (-Wa,-g) + "$(ToolchainDir)\arm-none-eabi-size.exe" $(OutputFileName)$(OutputFileExtension) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index 6bcd350..b314dce 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -61,8 +61,8 @@ extern uint16_t ofp13_oxm_inst_size[MAX_FLOWS_13]; extern struct flows_counter flow_counters[MAX_FLOWS_13]; extern struct flow_tbl_actions *flow_actions10[MAX_FLOWS_13]; extern int iLastFlow; -extern struct ofp10_port_stats phys10_port_stats[4]; -extern struct ofp13_port_stats phys13_port_stats[4]; +extern struct ofp10_port_stats phys10_port_stats[8]; +extern struct ofp13_port_stats phys13_port_stats[8]; extern struct table_counter table_counters[MAX_TABLES]; extern struct meter_entry13 *meter_entry[MAX_METER_13]; extern struct meter_band_stats_array band_stats_array[MAX_METER_13]; @@ -70,7 +70,8 @@ extern bool masterselect; extern bool stackenabled = false; extern bool trace = false; extern struct tcp_pcb *tcp_pcb; -extern uint8_t port_status[4]; +extern uint8_t port_status[8]; +extern uint8_t total_ports; extern int totaltime; extern int32_t ul_temp; extern int OF_Version; @@ -328,7 +329,7 @@ void command_root(char *command, char *param1, char *param2, char *param3) { int i; printf("\r\n-------------------------------------------------------------------------\r\n"); - for (i=0;i<4;i++) + for (i=0;i> 24)) #define NTOHL(x) HTONL(x) -#define SHARED_BUFFER_LEN 2048 - #define METER_PARTIAL 8 // Meter structure length, excluding header and bands #define SUCCESS 0 diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 3fe50c5..6010670 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -33,6 +33,7 @@ #include "trace.h" #include "switch.h" #include "lwip/def.h" +#include "openflow/openflow.h" /* SPI clock setting (Hz). */ static uint32_t gs_ul_spi_clock = 500000; @@ -60,13 +61,24 @@ uint8_t spi_state = 0; uint16_t spi_data_count = 0; uint16_t spi_command, spi_command_size; //bool spi_slave_send; -uint16_t spi_slave_send_size; +uint16_t spi_slave_send_size = sizeof(struct spi_port_stats); uint8_t timer_alt; uint8_t pending_spi_command = SPI_SEND_CLEAR; bool master_ready; +bool slave_ready; +uint8_t spi_dummy_bytes = 0; +struct spi_port_stats spi_p_stats; +uint8_t spi_stats_rr = 0; +uint8_t spi_stats_buffer[sizeof(struct spi_port_stats)]; +extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; +extern int OF_Version; +extern struct ofp10_port_stats phys10_port_stats[8]; +extern struct ofp13_port_stats phys13_port_stats[8]; void spi_master_initialize(void); void spi_slave_initialize(void); +void spi_port_stats(void); +void spi_port_status(void); /* * Initialize the SPI interface to MASTER or SLAVE based on the stacking jumper @@ -139,17 +151,19 @@ void Slave_timer(void) { if (timer_alt == 0) { - update_port_stats(); + spi_port_stats(); timer_alt = 1; return; } else if (timer_alt == 1) { - update_port_status(); + spi_port_status(); timer_alt = 2; return; } else if (timer_alt == 2) { - if(master_ready == false) return; // Wait until the master acknowledges us before sending anything + if(slave_ready == false || pending_spi_command != SPI_SEND_CLEAR) return; // Wait until the master acknowledges us before sending anything + spi_p_stats.premable = SPI_STATS_PREAMBLE; + memcpy(&spi_stats_buffer, &spi_p_stats, sizeof(struct spi_port_stats)); ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something pending_spi_command = SPI_SEND_STATS; // We are waiting to send port stats timer_alt = 0; @@ -157,6 +171,30 @@ void Slave_timer(void) } } +void spi_port_stats(void) +{ + spi_p_stats.tx_bytes[spi_stats_rr] += readtxbytes(spi_stats_rr+1); + spi_p_stats.rx_bytes[spi_stats_rr] += readrxbytes(spi_stats_rr+1); + spi_stats_rr++; + if (spi_stats_rr == 4) spi_stats_rr = 0; + return; +} + +void spi_port_status(void) +{ + // Copy out the old status so we know if it has changed + spi_p_stats.last_port_status[0] = spi_p_stats.port_status[0]; + spi_p_stats.last_port_status[1] = spi_p_stats.port_status[1]; + spi_p_stats.last_port_status[2] = spi_p_stats.port_status[2]; + spi_p_stats.last_port_status[3] = spi_p_stats.port_status[3]; + // Update port status + spi_p_stats.port_status[0] = (switch_read(30) & 32) >> 5; + spi_p_stats.port_status[1] = (switch_read(46) & 32) >> 5; + spi_p_stats.port_status[2] = (switch_read(62) & 32) >> 5; + spi_p_stats.port_status[3] = (switch_read(78) & 32) >> 5; + return; +} + /* * Master ready function * @@ -184,12 +222,62 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size) */ void MasterStackRcv(void) { - while(ioport_get_pin_level(SPI_IRQ1)) + static uint16_t data; + uint8_t uc_pcs; + bool irq = false; + int spi_count = 0; + irq = ioport_get_pin_level(SPI_IRQ1); + + spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); // Write 1 more byte to clean out buffer + while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + //spi_read(SPI_MASTER_BASE, &data, &uc_pcs); + spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); // Write 1 more byte to clean out buffer + while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + + while(irq) { for(int x = 0;x<10000;x++); - spi_write(SPI_MASTER_BASE, 0xaa, 0, 0); + spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + //printf("switch.c: SPI Read: %d - %02X\r\n", spi_count, data); + irq = ioport_get_pin_level(SPI_IRQ1); + spi_count++; + } + + if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) // Stats message + { + memcpy(&spi_p_stats, &shared_buffer, sizeof(struct spi_port_stats)); + port_status[4] = spi_p_stats.port_status[0]; + port_status[5] = spi_p_stats.port_status[1]; + port_status[6] = spi_p_stats.port_status[2]; + port_status[7] = spi_p_stats.port_status[3]; + + if (OF_Version == 1) + { + phys10_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; + phys10_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; + phys10_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; + phys10_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; + phys10_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; + phys10_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; + phys10_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; + phys10_port_stats[8].rx_bytes += spi_p_stats.rx_bytes[3]; + } + + if (OF_Version == 4) + { + phys13_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; + phys13_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; + phys13_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; + phys13_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; + phys13_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; + phys13_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; + phys13_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; + phys13_port_stats[8].rx_bytes += spi_p_stats.rx_bytes[3]; + } } + return; } @@ -200,12 +288,48 @@ void MasterStackRcv(void) */ void SPI_Handler(void) { - master_ready = true; + static uint16_t data; + uint8_t uc_pcs; + + if (slave_ready == false) // Is this the first data we have received? + { + if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) + { + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + if (data == 0xaa) + { + ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ + slave_ready = true; + } + return; + } + } if(pending_spi_command == SPI_SEND_STATS) // We send the master our port stats { - pending_spi_command = SPI_SEND_CLEAR; // Clear the pending command - ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done + if (spi_slave_send_size <= 0) + { + if (spi_dummy_bytes < 2) + { + spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); + spi_dummy_bytes++; + return; + } + pending_spi_command = SPI_SEND_CLEAR; // Clear the pending command + ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done + spi_slave_send_size = sizeof(struct spi_port_stats); + spi_dummy_bytes = 0; + } else { + spi_write(SPI_SLAVE_BASE, spi_stats_buffer[sizeof(struct spi_port_stats) - spi_slave_send_size], 0, 0); + //spi_write(SPI_SLAVE_BASE, spi_slave_send_size, 0, 0); + spi_slave_send_size--; + } return; } + + if(pending_spi_command == SPI_SEND_CLEAR) + { + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + ioport_set_pin_level(SPI_IRQ1, false); + } } \ No newline at end of file diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 1881fcc..d839f7b 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -38,9 +38,21 @@ #define SPI_SEND_CLEAR 0 #define SPI_SEND_STATS 1 #define SPI_SEND_PKT 2 -#define SPI_SLAVE_PREAMBLE 0xAAAAAAAB -#define SPI_MASTER_PREAMBLE 0xBBBBBBBC +#define SPI_STATS_PREAMBLE 0xABAB +#define SPI_PACKET_PREAMBLE 0xBCBC +struct spi_port_stats { + + uint16_t premable; + uint8_t port_status[4]; + uint8_t last_port_status[4]; + uint64_t rx_bytes[4]; + uint64_t tx_bytes[4]; + uint64_t rx_dropped[4]; + uint64_t tx_dropped[4]; +}; + + void stacking_init(bool master); void MasterReady(void); void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size); diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index accfc8f..aaea5f6 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -47,10 +47,11 @@ extern struct tcp_conn tcp_conn; extern struct zodiac_config Zodiac_Config; extern int OF_Version; uint8_t gmacbuffer[GMAC_FRAME_LENTGH_MAX]; -struct ofp10_port_stats phys10_port_stats[4]; -struct ofp13_port_stats phys13_port_stats[4]; -uint8_t port_status[4]; -uint8_t last_port_status[4]; +struct ofp10_port_stats phys10_port_stats[8]; +struct ofp13_port_stats phys13_port_stats[8]; +uint8_t port_status[8]; +uint8_t last_port_status[8]; +uint8_t total_ports = 4; extern uint8_t NativePortMatrix; extern bool masterselect; extern bool stackenabled; @@ -67,13 +68,6 @@ static volatile uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; uint8_t stats_rr = 0; -// Internal functions -int readtxbytes(int port); -int readrxbytes(int port); -int readtxdrop(int port); -int readrxdrop(int port); -int readrxcrcerr(int port); - struct usart_spi_device USART_SPI_DEVICE = { /* Board specific select ID. */ @@ -469,18 +463,22 @@ void task_switch(struct netif *netif) uint32_t ul_rcv_size = 0; uint8_t tag = 0; int8_t in_port = 0; - + + // Check if the slave device has a packet to send us + if(masterselect == false && ioport_get_pin_level(SPI_IRQ1) && stackenabled == true) + { + MasterStackRcv(); + } + // Check if the slave device is connected and enable stacking if(masterselect == false && !ioport_get_pin_level(SPI_IRQ1) && stackenabled == false) { - MasterReady(); + MasterReady(); // Let the slave know the master is ready stackenabled = true; + total_ports = 8; } - - // Check if the slave device has a packet to send us - if(masterselect == false && ioport_get_pin_level(SPI_IRQ1) && stackenabled == true) MasterStackRcv(); - // Slave house keeping + // Slave house keeping timer if(masterselect == true) { if((sys_get_ms() - slave_timer) > 500) // every 500 ms (0.5 secs) diff --git a/ZodiacFX/src/switch.h b/ZodiacFX/src/switch.h index 69e4c4e..f7d30a7 100644 --- a/ZodiacFX/src/switch.h +++ b/ZodiacFX/src/switch.h @@ -32,6 +32,7 @@ #define SPI_Handler SPI_Handler #define SPI_IRQn SPI_IRQn +#define SHARED_BUFFER_LEN 2048 void spi_init(void); void switch_init(void); @@ -47,4 +48,9 @@ void stacking_init(bool master); void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size); void MasterStackRcv(void); +int readtxbytes(int port); +int readrxbytes(int port); +int readtxdrop(int port); +int readrxdrop(int port); +int readrxcrcerr(int port); #endif /* SWITCH_H_ */ From 8b44d1a9e520104637a37b006a0cac5586c67134 Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Wed, 19 Apr 2017 10:09:54 +1000 Subject: [PATCH 033/169] Added stacking slave send packet --- ZodiacFX/src/stacking.c | 91 ++++++++++++++++++++++++++--------------- ZodiacFX/src/stacking.h | 11 ++++- ZodiacFX/src/switch.c | 47 +++++++++++++++------ 3 files changed, 103 insertions(+), 46 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 6010670..c0482ae 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -53,15 +53,14 @@ static uint32_t gs_ul_spi_clock = 500000; // Global variables extern uint8_t last_port_status[4]; extern uint8_t port_status[4]; +extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; +extern int OF_Version; +extern struct ofp10_port_stats phys10_port_stats[8]; +extern struct ofp13_port_stats phys13_port_stats[8]; // Local variables -uint32_t *spi_cmd_buffer; -uint32_t spi_slv_preamble; -uint8_t spi_state = 0; -uint16_t spi_data_count = 0; -uint16_t spi_command, spi_command_size; -//bool spi_slave_send; -uint16_t spi_slave_send_size = sizeof(struct spi_port_stats); +uint16_t spi_slave_send_size; +uint16_t spi_slave_send_count; uint8_t timer_alt; uint8_t pending_spi_command = SPI_SEND_CLEAR; bool master_ready; @@ -70,10 +69,7 @@ uint8_t spi_dummy_bytes = 0; struct spi_port_stats spi_p_stats; uint8_t spi_stats_rr = 0; uint8_t spi_stats_buffer[sizeof(struct spi_port_stats)]; -extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; -extern int OF_Version; -extern struct ofp10_port_stats phys10_port_stats[8]; -extern struct ofp13_port_stats phys13_port_stats[8]; +struct spi_packet *spi_packet; void spi_master_initialize(void); void spi_slave_initialize(void); @@ -163,9 +159,12 @@ void Slave_timer(void) { if(slave_ready == false || pending_spi_command != SPI_SEND_CLEAR) return; // Wait until the master acknowledges us before sending anything spi_p_stats.premable = SPI_STATS_PREAMBLE; + spi_p_stats.spi_size = sizeof(struct spi_port_stats); memcpy(&spi_stats_buffer, &spi_p_stats, sizeof(struct spi_port_stats)); ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something pending_spi_command = SPI_SEND_STATS; // We are waiting to send port stats + spi_slave_send_size = sizeof(struct spi_port_stats); + spi_slave_send_count = spi_slave_send_size; timer_alt = 0; return; } @@ -212,7 +211,6 @@ void MasterReady(void) */ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size) { - return; } @@ -224,29 +222,31 @@ void MasterStackRcv(void) { static uint16_t data; uint8_t uc_pcs; - bool irq = false; int spi_count = 0; - irq = ioport_get_pin_level(SPI_IRQ1); + uint16_t spi_read_size; - spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); // Write 1 more byte to clean out buffer - while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - //spi_read(SPI_MASTER_BASE, &data, &uc_pcs); - spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); // Write 1 more byte to clean out buffer - while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - - while(irq) + for (int i = 0; i<6;i++) + { + spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); // Write 1 more byte to clean out buffer + while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + if (i > 2) spi_read(SPI_MASTER_BASE, &shared_buffer[i-3], &uc_pcs); // skip for first 2 bytes + } + + if (shared_buffer[0] != 0xAB && shared_buffer[0] != 0xBC) return; + spi_count = 4; + spi_read_size = shared_buffer[2] + (shared_buffer[3]*255); + while(spi_count < spi_read_size) { for(int x = 0;x<10000;x++); spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); - //printf("switch.c: SPI Read: %d - %02X\r\n", spi_count, data); - irq = ioport_get_pin_level(SPI_IRQ1); spi_count++; } - + if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) // Stats message { + TRACE("stacking.c: %d bytes of port stats data received from slave", spi_count); memcpy(&spi_p_stats, &shared_buffer, sizeof(struct spi_port_stats)); port_status[4] = spi_p_stats.port_status[0]; port_status[5] = spi_p_stats.port_status[1]; @@ -277,7 +277,16 @@ void MasterStackRcv(void) phys13_port_stats[8].rx_bytes += spi_p_stats.rx_bytes[3]; } } - + else if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) // Stats message + { + TRACE("stacking.c: %d bytes of packet data received from slave", spi_count); + spi_packet = &shared_buffer; + nnOF_tablelookup(spi_packet->pkt_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); + } else + { + TRACE("stacking.c: %d bytes of unknown data received from slave", spi_count); + } + return; } @@ -307,7 +316,7 @@ void SPI_Handler(void) if(pending_spi_command == SPI_SEND_STATS) // We send the master our port stats { - if (spi_slave_send_size <= 0) + if (spi_slave_send_count <= 0) { if (spi_dummy_bytes < 2) { @@ -317,17 +326,35 @@ void SPI_Handler(void) } pending_spi_command = SPI_SEND_CLEAR; // Clear the pending command ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done - spi_slave_send_size = sizeof(struct spi_port_stats); spi_dummy_bytes = 0; } else { - spi_write(SPI_SLAVE_BASE, spi_stats_buffer[sizeof(struct spi_port_stats) - spi_slave_send_size], 0, 0); - //spi_write(SPI_SLAVE_BASE, spi_slave_send_size, 0, 0); - spi_slave_send_size--; + spi_write(SPI_SLAVE_BASE, spi_stats_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); + spi_slave_send_count--; } return; } - - if(pending_spi_command == SPI_SEND_CLEAR) + + if(pending_spi_command == SPI_SEND_PKT) // We send the master our port stats + { + if (spi_slave_send_count <= 0) + { + if (spi_dummy_bytes < 2) + { + spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); + spi_dummy_bytes++; + return; + } + pending_spi_command = SPI_SEND_CLEAR; // Clear the pending command + ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done + spi_dummy_bytes = 0; + } else { + spi_write(SPI_SLAVE_BASE, shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); + spi_slave_send_count--; + } + return; + } + + if(pending_spi_command == SPI_SEND_CLEAR) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); ioport_set_pin_level(SPI_IRQ1, false); diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index d839f7b..a448465 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -42,8 +42,8 @@ #define SPI_PACKET_PREAMBLE 0xBCBC struct spi_port_stats { - uint16_t premable; + uint16_t spi_size; uint8_t port_status[4]; uint8_t last_port_status[4]; uint64_t rx_bytes[4]; @@ -51,7 +51,14 @@ struct spi_port_stats { uint64_t rx_dropped[4]; uint64_t tx_dropped[4]; }; - + +struct spi_packet { + uint16_t premable; + uint16_t spi_size; + uint32_t ul_rcv_size; + uint8_t tag; + uint8_t pkt_buffer[GMAC_FRAME_LENTGH_MAX]; +}; void stacking_init(bool master); void MasterReady(void); diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index aaea5f6..afb8c04 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -41,23 +41,31 @@ #include "ksz8795clx/ethernet_phy.h" #include "netif/etharp.h" -/** The GMAC driver instance */ -gmac_device_t gs_gmac_dev; +// Global variables extern struct tcp_conn tcp_conn; extern struct zodiac_config Zodiac_Config; extern int OF_Version; +extern uint8_t NativePortMatrix; +extern bool masterselect; +extern bool stackenabled; +extern uint8_t pending_spi_command; +extern struct spi_packet *spi_packet; +extern bool slave_ready; +extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; +extern uint16_t spi_slave_send_size; +extern uint16_t spi_slave_send_count; + +// Local variables +gmac_device_t gs_gmac_dev; uint8_t gmacbuffer[GMAC_FRAME_LENTGH_MAX]; struct ofp10_port_stats phys10_port_stats[8]; struct ofp13_port_stats phys13_port_stats[8]; uint8_t port_status[8]; uint8_t last_port_status[8]; uint8_t total_ports = 4; -extern uint8_t NativePortMatrix; -extern bool masterselect; -extern bool stackenabled; int slave_timer = 0; -/** Buffer for ethernet packets */ static volatile uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; +uint8_t stats_rr = 0; /* GMAC HW configurations */ #define BOARD_GMAC_PHY_ADDR 0 @@ -66,9 +74,6 @@ static volatile uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; #define USART_SPI_DEVICE_ID 1 #define USART_SPI_BAUDRATE 1000000 -uint8_t stats_rr = 0; - - struct usart_spi_device USART_SPI_DEVICE = { /* Board specific select ID. */ .id = USART_SPI_DEVICE_ID @@ -358,7 +363,7 @@ void GMAC_Handler(void) } /* -* Switch initialisation function +* Switch initialization function * */ void switch_init(void) @@ -534,8 +539,26 @@ void task_switch(struct netif *netif) } } else { - // TODO: Send packet to master - return; + if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) + { + uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); + uint8_t tag = *tail_tag + 1; + phys10_port_stats[tag-1].rx_packets++; + phys13_port_stats[tag-1].rx_packets++; + ul_rcv_size--; // remove the tail first + spi_packet = &shared_buffer; + spi_packet->premable = SPI_PACKET_PREAMBLE; + spi_packet->ul_rcv_size = ul_rcv_size; + spi_packet->tag = tag + 4; + spi_packet->spi_size = 9 + ul_rcv_size; + memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); + pending_spi_command = SPI_SEND_PKT; // We are waiting to send port stats + //spi_slave_send_size = sizeof(shared_buffer); + spi_slave_send_size = spi_packet->spi_size; + spi_slave_send_count = spi_slave_send_size; + ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something + return; + } } } return; From 12961a8323d5e6e68dda8a0b0649172635c44353 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Wed, 19 Apr 2017 11:42:25 +1000 Subject: [PATCH 034/169] Fix port stats update --- ZodiacFX/src/stacking.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index c0482ae..9e65f41 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -262,7 +262,7 @@ void MasterStackRcv(void) phys10_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; phys10_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; phys10_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; - phys10_port_stats[8].rx_bytes += spi_p_stats.rx_bytes[3]; + phys10_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; } if (OF_Version == 4) @@ -274,7 +274,7 @@ void MasterStackRcv(void) phys13_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; phys13_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; phys13_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; - phys13_port_stats[8].rx_bytes += spi_p_stats.rx_bytes[3]; + phys13_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; } } else if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) // Stats message From e6548495e6aabc1f7a5dd1f8ac1c22b56c2eca9c Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Wed, 19 Apr 2017 11:43:15 +1000 Subject: [PATCH 035/169] Clean up comments --- ZodiacFX/src/switch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index afb8c04..28aa51a 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -552,8 +552,7 @@ void task_switch(struct netif *netif) spi_packet->tag = tag + 4; spi_packet->spi_size = 9 + ul_rcv_size; memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); - pending_spi_command = SPI_SEND_PKT; // We are waiting to send port stats - //spi_slave_send_size = sizeof(shared_buffer); + pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet spi_slave_send_size = spi_packet->spi_size; spi_slave_send_count = spi_slave_send_size; ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something From 9d973347dc600b44b60e8654b9ba9578aa41b15b Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Wed, 19 Apr 2017 12:38:36 +1000 Subject: [PATCH 036/169] Adjust port stat struct externs --- ZodiacFX/src/http.c | 4 ++-- ZodiacFX/src/openflow/openflow.c | 4 ++-- ZodiacFX/src/openflow/openflow_10.c | 2 +- ZodiacFX/src/openflow/openflow_13.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index cedb2da..1e7aac6 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -67,8 +67,8 @@ extern struct meter_entry13 *meter_entry[MAX_METER_13]; extern struct meter_band_stats_array band_stats_array[MAX_METER_13]; extern int iLastFlow; extern int iLastMeter; -extern struct ofp10_port_stats phys10_port_stats[4]; -extern struct ofp13_port_stats phys13_port_stats[4]; +extern struct ofp10_port_stats phys10_port_stats[8]; +extern struct ofp13_port_stats phys13_port_stats[8]; extern struct table_counter table_counters[MAX_TABLES]; // Local Variables diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index f34975b..5948164 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -43,8 +43,8 @@ // Global variables extern struct zodiac_config Zodiac_Config; extern uint8_t port_status[4]; -extern struct ofp10_port_stats phys10_port_stats[4]; -extern struct ofp13_port_stats phys13_port_stats[4]; +extern struct ofp10_port_stats phys10_port_stats[8]; +extern struct ofp13_port_stats phys13_port_stats[8]; // Local Variables struct ofp_switch_config Switch_config; diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index ec20e0c..a9392b4 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -52,7 +52,7 @@ extern struct table_counter table_counters[MAX_TABLES]; extern int OF_Version; extern bool rcv_freq; extern uint8_t NativePortMatrix; -extern struct ofp10_port_stats phys10_port_stats[4]; +extern struct ofp10_port_stats phys10_port_stats[8]; extern uint8_t port_status[4]; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern struct zodiac_config Zodiac_Config; diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 7d213fd..9a08a36 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -58,7 +58,7 @@ extern uint8_t *ofp13_oxm_match[MAX_FLOWS_13]; extern uint8_t *ofp13_oxm_inst[MAX_FLOWS_13]; extern uint16_t ofp13_oxm_inst_size[MAX_FLOWS_13]; extern struct flows_counter flow_counters[MAX_FLOWS_13]; -extern struct ofp13_port_stats phys13_port_stats[4]; +extern struct ofp13_port_stats phys13_port_stats[8]; extern struct table_counter table_counters[MAX_TABLES]; extern uint8_t port_status[4]; extern struct ofp_switch_config Switch_config; From a31b1adee0d6a975584faad4436a63e5bb555236 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Wed, 19 Apr 2017 12:41:53 +1000 Subject: [PATCH 037/169] Adjust port status externs --- ZodiacFX/src/openflow/of_helper.c | 4 ++-- ZodiacFX/src/openflow/openflow.c | 2 +- ZodiacFX/src/openflow/openflow_10.c | 2 +- ZodiacFX/src/openflow/openflow_13.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index d90384f..c1bc8f6 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -52,8 +52,8 @@ extern int iLastFlow; extern int iLastMeter; extern int OF_Version; extern int totaltime; -extern uint8_t last_port_status[4]; -extern uint8_t port_status[4]; +extern uint8_t last_port_status[8]; +extern uint8_t port_status[8]; extern struct flows_counter flow_counters[MAX_FLOWS_13]; extern struct table_counter table_counters[MAX_TABLES]; extern struct meter_entry13 *meter_entry[MAX_METER_13]; diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index 5948164..07cae39 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -42,7 +42,7 @@ // Global variables extern struct zodiac_config Zodiac_Config; -extern uint8_t port_status[4]; +extern uint8_t port_status[8]; extern struct ofp10_port_stats phys10_port_stats[8]; extern struct ofp13_port_stats phys13_port_stats[8]; diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index a9392b4..eb7afef 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -53,7 +53,7 @@ extern int OF_Version; extern bool rcv_freq; extern uint8_t NativePortMatrix; extern struct ofp10_port_stats phys10_port_stats[8]; -extern uint8_t port_status[4]; +extern uint8_t port_status[8]; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern struct zodiac_config Zodiac_Config; extern struct ofp_switch_config Switch_config; diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 9a08a36..ecef269 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -60,7 +60,7 @@ extern uint16_t ofp13_oxm_inst_size[MAX_FLOWS_13]; extern struct flows_counter flow_counters[MAX_FLOWS_13]; extern struct ofp13_port_stats phys13_port_stats[8]; extern struct table_counter table_counters[MAX_TABLES]; -extern uint8_t port_status[4]; +extern uint8_t port_status[8]; extern struct ofp_switch_config Switch_config; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern int multi_pos; From f20a31d3a665e5d972882f2c1cdd37e2dff7552a Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Wed, 19 Apr 2017 12:42:22 +1000 Subject: [PATCH 038/169] Adjust port status externs --- ZodiacFX/src/http.c | 2 +- ZodiacFX/src/stacking.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 1e7aac6..094b96c 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -48,7 +48,7 @@ extern int totaltime; extern int32_t ul_temp; extern struct zodiac_config Zodiac_Config; -extern uint8_t port_status[4]; +extern uint8_t port_status[8]; extern uint32_t uid_buf[4]; // Unique identifier extern struct tcp_pcb *tcp_pcb; extern int OF_Version; diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 9e65f41..75bd0ac 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -51,8 +51,8 @@ static uint32_t gs_ul_spi_clock = 500000; #define SPI_DLYBCT 0x10 // Global variables -extern uint8_t last_port_status[4]; -extern uint8_t port_status[4]; +extern uint8_t last_port_status[8]; +extern uint8_t port_status[8]; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern int OF_Version; extern struct ofp10_port_stats phys10_port_stats[8]; From 1c3dc6657426243b48eb3ee84101a20477f0515c Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Wed, 19 Apr 2017 12:51:40 +1000 Subject: [PATCH 039/169] Modify OF13 port stats output --- ZodiacFX/src/openflow/openflow_13.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index ecef269..b1241d3 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -67,6 +67,8 @@ extern int multi_pos; extern uint8_t NativePortMatrix; extern bool reply_more_flag; extern uint32_t reply_more_xid; +extern uint8_t total_ports; + extern int meter_handler(uint32_t id, uint16_t bytes); // Internal functions @@ -1111,7 +1113,7 @@ int multi_tablefeat_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg */ int multi_portstats_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) { - struct ofp13_port_stats zodiac_port_stats[3]; + struct ofp13_port_stats zodiac_port_stats[total_ports-1]; struct ofp13_multipart_reply reply; struct ofp13_port_stats_request *port_req = msg->body; int stats_size = 0; @@ -1120,7 +1122,7 @@ int multi_portstats_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg if (port == OFPP13_ANY) { - stats_size = (sizeof(struct ofp13_port_stats) * 3); // Assumes 3 ports + stats_size = (sizeof(struct ofp13_port_stats) * (total_ports-1)); // total ports, excluding controller port len = sizeof(struct ofp13_multipart_reply) + stats_size; reply.header.version = OF_Version; @@ -1130,7 +1132,7 @@ int multi_portstats_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg reply.type = htons(OFPMP13_PORT_STATS); reply.flags = 0; - for(int k=0; k<3;k++) + for(int k=0; k<(total_ports-1);k++) { zodiac_port_stats[k].port_no = htonl(k+1); zodiac_port_stats[k].rx_packets = htonll(phys13_port_stats[k].rx_packets); From e45200ccc3a72704670527563c622be94fbf2301 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Wed, 19 Apr 2017 12:56:01 +1000 Subject: [PATCH 040/169] Modify OF10 port stats output --- ZodiacFX/src/openflow/openflow_10.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index eb7afef..422115a 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -57,6 +57,7 @@ extern uint8_t port_status[8]; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern struct zodiac_config Zodiac_Config; extern struct ofp_switch_config Switch_config; +extern uint8_t total_ports; //Internal Functions void packet_in(uint8_t *buffer, uint16_t ul_size, uint8_t port, uint8_t reason); @@ -638,7 +639,7 @@ void stats_table_reply(struct ofp_stats_request *msg) */ void stats_port_reply(struct ofp_stats_request *msg) { - struct ofp10_port_stats zodiac_port_stats[3]; + struct ofp10_port_stats zodiac_port_stats[total_ports-1]; struct ofp10_stats_reply reply; struct ofp10_port_stats_request *port_req = msg->body; int stats_size = 0; @@ -648,7 +649,7 @@ void stats_port_reply(struct ofp_stats_request *msg) if (port == OFPP_NONE) { - stats_size = (sizeof(struct ofp10_port_stats) * 3); + stats_size = (sizeof(struct ofp10_port_stats) * (total_ports-1)); len = sizeof(struct ofp10_stats_reply) + stats_size; reply.header.version = OF_Version; @@ -658,7 +659,7 @@ void stats_port_reply(struct ofp_stats_request *msg) reply.type = htons(OFPST_PORT); reply.flags = 0; - for(k=0; k<3;k++) + for(k=0; k<(total_ports-1);k++) { zodiac_port_stats[k].port_no = htons(k+1); zodiac_port_stats[k].rx_packets = htonll(phys10_port_stats[k].rx_packets); From d15643bbb76dba4f50638a54b99b7db262329283 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Wed, 19 Apr 2017 13:00:42 +1000 Subject: [PATCH 041/169] Remove OF13 features port count Unused in OpenFlow 13 features reply message --- ZodiacFX/src/openflow/openflow_13.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index b1241d3..77fcc96 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -671,11 +671,6 @@ void of13_message(struct ofp_header *ofph, int size, int len) void features_reply13(uint32_t xid) { uint64_t datapathid = 0; - int numofports = 0; - for(int n=0;n<4;n++) - { - if(Zodiac_Config.of_port[n]==1)numofports++; - } struct ofp13_switch_features features; uint8_t buf[256]; int bufsize = sizeof(struct ofp13_switch_features); From fcebcb03f6963e0962193c34bbc8523cebf08823 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Wed, 19 Apr 2017 16:14:42 +1000 Subject: [PATCH 042/169] Modify port status message output count Support 8 ports --- ZodiacFX/src/openflow/of_helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index c1bc8f6..afddfe7 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -64,6 +64,7 @@ extern struct ofp13_flow_mod *flow_match13[MAX_FLOWS_13]; extern uint8_t *ofp13_oxm_match[MAX_FLOWS_13]; extern uint8_t *ofp13_oxm_inst[MAX_FLOWS_13]; extern uint16_t ofp13_oxm_inst_size[MAX_FLOWS_13]; +extern uint8_t total_ports; // Local Variables uint8_t timer_alt; @@ -140,7 +141,7 @@ void nnOF_timer(void) } else if (timer_alt == 1){ update_port_status(); // If port status has changed send a port status message - for (int x=0;x<4;x++) + for (int x=0;x Date: Wed, 19 Apr 2017 16:19:01 +1000 Subject: [PATCH 043/169] Fix size value byte shift --- ZodiacFX/src/stacking.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 75bd0ac..ee4ab55 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -234,7 +234,7 @@ void MasterStackRcv(void) if (shared_buffer[0] != 0xAB && shared_buffer[0] != 0xBC) return; spi_count = 4; - spi_read_size = shared_buffer[2] + (shared_buffer[3]*255); + spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); while(spi_count < spi_read_size) { for(int x = 0;x<10000;x++); From b76af8789863b7b8fd2991a2522bcba038f4220d Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Sun, 23 Apr 2017 15:42:14 +1000 Subject: [PATCH 044/169] Updated gmac_write --- ZodiacFX/src/ksz8795clx/ethernet_phy.c | 3 +- ZodiacFX/src/openflow/openflow_10.c | 49 +++++++------------------ ZodiacFX/src/openflow/openflow_13.c | 50 ++++++++++---------------- ZodiacFX/src/switch.c | 19 +++++++++- ZodiacFX/src/switch.h | 2 +- 5 files changed, 52 insertions(+), 71 deletions(-) diff --git a/ZodiacFX/src/ksz8795clx/ethernet_phy.c b/ZodiacFX/src/ksz8795clx/ethernet_phy.c index 2a72388..f734ba8 100644 --- a/ZodiacFX/src/ksz8795clx/ethernet_phy.c +++ b/ZodiacFX/src/ksz8795clx/ethernet_phy.c @@ -289,8 +289,7 @@ err_t ethernetif_init(struct netif *netif) static err_t gmac_low_level_output(struct netif *netif, struct pbuf *p) { - gmac_write(p->payload, p->len, 128); - //gmac_write(p->payload, p->len, NativePortMatrix); + gmac_write(p->payload, p->len, 128, 0); } diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 422115a..547ee2a 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -58,6 +58,7 @@ extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern struct zodiac_config Zodiac_Config; extern struct ofp_switch_config Switch_config; extern uint8_t total_ports; +extern bool stackenabled; //Internal Functions void packet_in(uint8_t *buffer, uint16_t ul_size, uint8_t port, uint8_t reason); @@ -173,30 +174,13 @@ void nnOF10_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) { case OFPAT10_OUTPUT: action_out = act_hdr; - if (ntohs(action_out->port) <= 255 && ntohs(action_out->port) != port) // physical port - { - outport = (1<< (ntohs(action_out->port)-1)); - gmac_write(p_uc_data, packet_size, outport); - } - - if (ntohs(action_out->port) == OFPP_IN_PORT) - { - outport = (1<< (port-1)); - gmac_write(p_uc_data, packet_size, outport); - } - - if (ntohs(action_out->port) == OFPP_ALL || ntohs(action_out->port) == OFPP_FLOOD) - { - outport = (15 - NativePortMatrix) - (1<<(port-1)); - gmac_write(p_uc_data, packet_size, outport); - } - if (ntohs(action_out->port) == OFPP_CONTROLLER) { int pisize = ntohs(action_out->max_len); if (pisize > packet_size) pisize = packet_size; packet_in(p_uc_data, pisize, port, OFPR_ACTION); } + gmac_write(p_uc_data, packet_size, ntohs(action_out->port), port); break; case OFPAT10_SET_DL_SRC: @@ -427,6 +411,10 @@ void features_reply10(uint32_t xid) { if(Zodiac_Config.of_port[n]==1)numofports++; } + if(stackenabled == true) + { + numofports += 4; // Add the slave ports + } struct ofp10_switch_features features; struct ofp10_phy_port phys_port[numofports]; uint8_t buf[256]; @@ -445,15 +433,14 @@ void features_reply10(uint32_t xid) features.n_tables = 1; // Number of flow tables features.capabilities = htonl(OFPC10_FLOW_STATS + OFPC10_TABLE_STATS + OFPC10_PORT_STATS); // Switch Capabilities features.actions = htonl((1 << OFPAT10_OUTPUT) + (1 << OFPAT10_SET_VLAN_VID) + (1 << OFPAT10_SET_DL_SRC) + (1 << OFPAT10_SET_DL_DST) + (1 << OFPAT10_SET_NW_SRC) + (1 << OFPAT10_SET_NW_DST) + (1 << OFPAT10_SET_TP_SRC) + (1 << OFPAT10_SET_TP_DST)); // Action Capabilities - uint8_t mac[] = {0x00,0x00,0x00,0x00,0x00,0x00}; memcpy(&buf, &features, sizeof(struct ofp10_switch_features)); update_port_status(); //update port status - for(l = 0; l< 4; l++) + for(l = 0; l< total_ports; l++) { - if(Zodiac_Config.of_port[l] == 1) + if(Zodiac_Config.of_port[l] == 1 || l > 3) // If l > 3 then stacking is enabled so include the 4 port from the slave { phys_port[j].port_no = HTONS(l+1); for(k = 0; k<6; k++) // Generate random MAC address @@ -476,7 +463,6 @@ void features_reply10(uint32_t xid) j ++; } } - memcpy(&buf[sizeof(struct ofp10_switch_features)], phys_port, sizeof(phys_port)); sendtcp(&buf, bufsize); return; @@ -729,23 +715,14 @@ void packet_out(struct ofp_header *msg) int size = NTOHS(po->header.length) - ((sizeof(struct ofp_packet_out) + NTOHS(po->actions_len))); uint16_t *eport; eport = ptr - 4; - int outPort = NTOHS(*eport); - int inPort = NTOHS(*iport); - - if (outPort == OFPP_TABLE) + TRACE("openflow_10.c: Packet out port 0x%X (%d bytes)", NTOHS(*eport), size); + + if (NTOHS(*eport) == OFPP_TABLE) { - nnOF_tablelookup(ptr, &size, inPort); + nnOF_tablelookup(ptr, &size, NTOHS(*iport)); return; } - - if (outPort == OFPP_FLOOD || outPort == OFPP13_ALL) - { - outPort = (15 - NativePortMatrix) - (1<<(inPort-1)); - } else - { - outPort = 1 << (outPort-1); - } - gmac_write(ptr, size, outPort); + gmac_write(ptr, size, NTOHS(*eport), NTOHS(*iport)); return; } diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 77fcc96..2d01a6f 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -68,7 +68,7 @@ extern uint8_t NativePortMatrix; extern bool reply_more_flag; extern uint32_t reply_more_xid; extern uint8_t total_ports; - +extern bool stackenabled; extern int meter_handler(uint32_t id, uint16_t bytes); // Internal functions @@ -224,31 +224,18 @@ void nnOF13_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) set_ip_checksum(p_uc_data, packet_size, fields.payload - p_uc_data); recalculate_ip_checksum = false; } - struct ofp13_action_output *act_output = act_hdr; - if (htonl(act_output->port) < OFPP13_MAX && htonl(act_output->port) != port) - { - int outport = (1<< (ntohl(act_output->port)-1)); - TRACE("openflow_13.c: Output to port %d (%d bytes)", ntohl(act_output->port), packet_size); - gmac_write(p_uc_data, packet_size, outport); - } else if (htonl(act_output->port) == OFPP13_IN_PORT) - { - int outport = (1<< (port-1)); - TRACE("openflow_13.c: Output to in_port %d (%d bytes)", port, packet_size); - gmac_write(p_uc_data, packet_size, outport); - } else if (htonl(act_output->port) == OFPP13_CONTROLLER) + if (htonl(act_output->port) == OFPP13_CONTROLLER) { int pisize = ntohs(act_output->max_len); if (pisize > packet_size) pisize = packet_size; TRACE("openflow_13.c: Output to controller (%d bytes)", packet_size); packet_in13(p_uc_data, pisize, port, OFPR_ACTION, i); - } else if (htonl(act_output->port) == OFPP13_FLOOD || htonl(act_output->port) == OFPP13_ALL) - { - int outport = (15 - NativePortMatrix) - (1<<(port-1)); - if (htonl(act_output->port) == OFPP13_FLOOD) TRACE("openflow_13.c: Output to FLOOD (%d bytes)", packet_size); - if (htonl(act_output->port) == OFPP13_ALL) TRACE("openflow_13.c: Output to ALL (%d bytes)", packet_size); - gmac_write(p_uc_data, packet_size, outport); + break; } + + gmac_write(p_uc_data, packet_size, htonl(act_output->port), port); + } break; @@ -900,10 +887,14 @@ int multi_aggregate_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg int multi_portdesc_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) { int numofports = 0; - for(int n=0;n<4;n++) + for(int n=0;n 3) // If l > 3 then stacking is enabled so include the 4 port from the slave { phys_port[j].port_no = htonl(l+1); for(int k = 0; k<6; k++) // Generate random MAC address @@ -946,7 +937,6 @@ int multi_portdesc_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) j ++; } } - memcpy(reply->body, &phys_port[0],sizeof(phys_port)); return len; } @@ -1992,16 +1982,14 @@ void packet_out13(struct ofp_header *msg) struct ofp13_action_header *act_hdr = po->actions; if (ntohs(act_hdr->type) != OFPAT13_OUTPUT) return; struct ofp13_action_output *act_out = act_hdr; - uint32_t outPort = htonl(act_out->port); - if (outPort == OFPP13_FLOOD) + //uint32_t outPort = htonl(act_out->port); + TRACE("openflow_13.c: Packet out port 0x%X (%d bytes)", htonl(act_out->port), size); + if (htonl(act_out->port) == OFPP13_TABLE) { - outPort = 7 - (1 << (inPort-1)); // Need to fix this, may also send out the Non-OpenFlow port - } else { - outPort = 1 << (outPort-1); - TRACE("openflow_13.c: Packet out FLOOD (%d bytes)", size); + nnOF_tablelookup(ptr, &size, inPort); + return; } - TRACE("openflow_13.c: Packet out port %d (%d bytes)", outPort, size); - gmac_write(ptr, size, outPort); + gmac_write(ptr, size, htonl(act_out->port), inPort); return; } diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 28aa51a..b825785 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -318,8 +318,25 @@ void update_port_status(void) * @param port - the port to send the data out from. * */ -void gmac_write(uint8_t *p_buffer, uint16_t ul_size, uint8_t port) +void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) { + TRACE("switch.c: gmac_write to port 0x%X (%d bytes)", port, ul_size); + + // Convert OpenFlow port to physical port number + if (port == OFPP_FLOOD || port == OFPP_ALL || port == OFPP13_FLOOD || port == OFPP13_ALL) // Send packet out all ports except the port it arrived on + { + TRACE("switch.c: Packet out FLOOD (%d bytes)", ul_size); + port = (15 - NativePortMatrix) - (1<<(inport-1)); + } else if (port == OFPP13_IN_PORT) // Send it back out the port it arrived on + { + port = inport; + TRACE("openflow_13.c: Output to in_port %d (%d bytes)", port, ul_size); + } else if (port < 128) // Send it out the specified port + { + port = 1 << (port-1); + } + + TRACE("switch.c: Writing data to switch port %d (%d bytes)", port, ul_size); if (ul_size > GMAC_FRAME_LENTGH_MAX) { return; diff --git a/ZodiacFX/src/switch.h b/ZodiacFX/src/switch.h index f7d30a7..c0fb57b 100644 --- a/ZodiacFX/src/switch.h +++ b/ZodiacFX/src/switch.h @@ -37,7 +37,7 @@ void spi_init(void); void switch_init(void); void task_switch(struct netif *netif); -void gmac_write(uint8_t *p_buffer, uint16_t ul_size, uint8_t port); +void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport); int switch_read(uint8_t param1); int switch_write(uint8_t param1, uint8_t param2); void update_port_stats(void); From e94e206603e8a8c87ddfde7e9841f05b50875f70 Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Mon, 24 Apr 2017 12:13:16 +1000 Subject: [PATCH 045/169] SPI master send --- ZodiacFX/src/main.c | 3 +- ZodiacFX/src/stacking.c | 89 +++++++++++++++++++++++++++++++++++++++-- ZodiacFX/src/stacking.h | 4 +- ZodiacFX/src/switch.c | 18 +++++++-- ZodiacFX/src/switch.h | 1 - 5 files changed, 106 insertions(+), 9 deletions(-) diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c index 6beb3bf..07ffcb9 100644 --- a/ZodiacFX/src/main.c +++ b/ZodiacFX/src/main.c @@ -202,10 +202,11 @@ int main (void) while(1) { task_switch(&gs_net_if); + task_command(cCommand, cCommand_last); // Only run the following tasks if set to Master if(masterselect == false) { - task_command(cCommand, cCommand_last); + //task_command(cCommand, cCommand_last); sys_check_timeouts(); task_openflow(); } diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index ee4ab55..7e62a91 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -70,6 +70,9 @@ struct spi_port_stats spi_p_stats; uint8_t spi_stats_rr = 0; uint8_t spi_stats_buffer[sizeof(struct spi_port_stats)]; struct spi_packet *spi_packet; +bool end_receive; +uint8_t spi_receive_port = 0; +uint16_t spi_receive_count; void spi_master_initialize(void); void spi_slave_initialize(void); @@ -209,8 +212,40 @@ void MasterReady(void) * Master send function * */ -void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size) +void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) { + uint8_t uc_pcs; + static uint16_t data; + uint8_t *p_buffer; + p_buffer = p_uc_data; + uint8_t outport; + + if (port < 255) + { + outport = port; + } else { + port = 255; + } + + TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); + // Write preamble + spi_write(SPI_MASTER_BASE, 0xcd, 0, 0); + for(int x = 0;x<10000;x++); + spi_write(SPI_MASTER_BASE, 0xcd, 0, 0); + for(int x = 0;x<10000;x++); + spi_write(SPI_MASTER_BASE, port, 0, 0); + for(int x = 0;x<10000;x++); + + for (int i = 0; i < ul_size; i++) { + for(int x = 0;x<10000;x++); + spi_write(SPI_MASTER_BASE, p_buffer[i], 0, 0); + while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + } + // Write end bytes + for(int x = 0;x<10000;x++); + spi_write(SPI_MASTER_BASE, 0xde, 0, 0); + for(int x = 0;x<10000;x++); + spi_write(SPI_MASTER_BASE, 0xef, 0, 0); return; } @@ -353,10 +388,58 @@ void SPI_Handler(void) } return; } - + if(pending_spi_command == SPI_SEND_CLEAR) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - ioport_set_pin_level(SPI_IRQ1, false); + if (data == 0xcd) pending_spi_command = SPI_RCV_PREAMBLE; + return; + } + + if(pending_spi_command == SPI_RCV_PREAMBLE) + { + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + if (data == 0xcd) + { + pending_spi_command = SPI_RECEIVE; + memset(&shared_buffer,0,sizeof(shared_buffer)); + } else { + pending_spi_command = SPI_SEND_CLEAR; + } + return; + } + + if(pending_spi_command == SPI_RECEIVE) + { + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + //printf("stacking.c: SPI data received %0x\r\n", data); + // Check if this is an end marker + if (data == 0xde) + { + end_receive = true; + } else if (data == 0xef && end_receive == true) + { + if (spi_receive_port == 255) + { + gmac_write(&shared_buffer, spi_receive_count, OFPP13_FLOOD, 0); + } else{ + gmac_write(&shared_buffer, spi_receive_count, spi_receive_port-4, 0); + } + pending_spi_command = SPI_SEND_CLEAR; + spi_receive_port = 0; + end_receive = false; + spi_receive_count =0; + return; + } + + if (spi_receive_port == 0) + { + spi_receive_port = data; + return; + } + + shared_buffer[spi_receive_count] = data; + spi_receive_count++; } + } \ No newline at end of file diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index a448465..5186751 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -38,6 +38,8 @@ #define SPI_SEND_CLEAR 0 #define SPI_SEND_STATS 1 #define SPI_SEND_PKT 2 +#define SPI_RECEIVE 3 +#define SPI_RCV_PREAMBLE 4 #define SPI_STATS_PREAMBLE 0xABAB #define SPI_PACKET_PREAMBLE 0xBCBC @@ -62,7 +64,7 @@ struct spi_packet { void stacking_init(bool master); void MasterReady(void); -void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size); +void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port); void MasterStackRcv(void); void Slave_timer(void); diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index b825785..24a7b26 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -326,17 +326,29 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) if (port == OFPP_FLOOD || port == OFPP_ALL || port == OFPP13_FLOOD || port == OFPP13_ALL) // Send packet out all ports except the port it arrived on { TRACE("switch.c: Packet out FLOOD (%d bytes)", ul_size); + if(masterselect == false) MasterStackSend(p_buffer, ul_size, port); port = (15 - NativePortMatrix) - (1<<(inport-1)); } else if (port == OFPP13_IN_PORT) // Send it back out the port it arrived on { port = inport; - TRACE("openflow_13.c: Output to in_port %d (%d bytes)", port, ul_size); - } else if (port < 128) // Send it out the specified port + TRACE("switch.c: Output to in_port %d (%d bytes)", port, ul_size); + } else if (port < 5) // Send it out the specified port { port = 1 << (port-1); + } else if (port > 4 && port < 128) + { + if(masterselect == false) // If we are the master then send to the slave + { + TRACE("switch13.c: Sending packet to slave to send out port %d (%d bytes)", port, ul_size); + MasterStackSend(p_buffer, ul_size, port); // Send it slave + return; + } + // If slave then write to port + port -= 4; + port = 1 << (port-1); } - TRACE("switch.c: Writing data to switch port %d (%d bytes)", port, ul_size); + TRACE("switch.c: Writing data to switch port matrix %d (%d bytes)", port, ul_size); if (ul_size > GMAC_FRAME_LENTGH_MAX) { return; diff --git a/ZodiacFX/src/switch.h b/ZodiacFX/src/switch.h index c0fb57b..f51edb6 100644 --- a/ZodiacFX/src/switch.h +++ b/ZodiacFX/src/switch.h @@ -45,7 +45,6 @@ void update_port_status(void); void disableOF(void); void enableOF(void); void stacking_init(bool master); -void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size); void MasterStackRcv(void); int readtxbytes(int port); From d1c09219fef219dfbc2c2d4ee20d38fd6159c67d Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 24 Apr 2017 15:22:01 +1000 Subject: [PATCH 046/169] Fix specific port stat reply --- ZodiacFX/src/openflow/openflow_13.c | 39 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 2d01a6f..afbe84f 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -1098,7 +1098,6 @@ int multi_tablefeat_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg */ int multi_portstats_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) { - struct ofp13_port_stats zodiac_port_stats[total_ports-1]; struct ofp13_multipart_reply reply; struct ofp13_port_stats_request *port_req = msg->body; int stats_size = 0; @@ -1107,6 +1106,7 @@ int multi_portstats_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg if (port == OFPP13_ANY) { + struct ofp13_port_stats zodiac_port_stats[total_ports-1]; stats_size = (sizeof(struct ofp13_port_stats) * (total_ports-1)); // total ports, excluding controller port len = sizeof(struct ofp13_multipart_reply) + stats_size; @@ -1136,7 +1136,10 @@ int multi_portstats_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg } memcpy(buffer, &reply, sizeof(struct ofp13_multipart_reply)); memcpy(buffer+sizeof(struct ofp13_multipart_reply), &zodiac_port_stats[0], stats_size); - } else if (port <= OFPP13_MAX) { + } + else if (port > 0 && port <= total_ports) // Respond to request for ports 1-4 or 1-8 (stacking) + { + struct ofp13_port_stats zodiac_port_stats; stats_size = sizeof(struct ofp13_port_stats); len = sizeof(struct ofp13_multipart_reply) + stats_size; @@ -1147,22 +1150,26 @@ int multi_portstats_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg reply.type = htons(OFPMP13_PORT_STATS); reply.flags = 0; - zodiac_port_stats[port].port_no = htonl(port); - zodiac_port_stats[port].rx_packets = htonll(phys13_port_stats[port-1].rx_packets); - zodiac_port_stats[port].tx_packets = htonll(phys13_port_stats[port-1].tx_packets); - zodiac_port_stats[port].rx_bytes = htonll(phys13_port_stats[port-1].rx_bytes); - zodiac_port_stats[port].tx_bytes = htonll(phys13_port_stats[port-1].tx_bytes); - zodiac_port_stats[port].rx_crc_err = htonll(phys13_port_stats[port-1].rx_crc_err); - zodiac_port_stats[port].rx_dropped = htonll(phys13_port_stats[port-1].rx_dropped); - zodiac_port_stats[port].tx_dropped = htonll(phys13_port_stats[port-1].tx_dropped); - zodiac_port_stats[port].rx_frame_err = 0; - zodiac_port_stats[port].rx_over_err = 0; - zodiac_port_stats[port].tx_errors = 0; - zodiac_port_stats[port].rx_errors = 0; - zodiac_port_stats[port].collisions = 0; + zodiac_port_stats.port_no = htonl(port); + zodiac_port_stats.rx_packets = htonll(phys13_port_stats[port-1].rx_packets); + zodiac_port_stats.tx_packets = htonll(phys13_port_stats[port-1].tx_packets); + zodiac_port_stats.rx_bytes = htonll(phys13_port_stats[port-1].rx_bytes); + zodiac_port_stats.tx_bytes = htonll(phys13_port_stats[port-1].tx_bytes); + zodiac_port_stats.rx_crc_err = htonll(phys13_port_stats[port-1].rx_crc_err); + zodiac_port_stats.rx_dropped = htonll(phys13_port_stats[port-1].rx_dropped); + zodiac_port_stats.tx_dropped = htonll(phys13_port_stats[port-1].tx_dropped); + zodiac_port_stats.rx_frame_err = 0; + zodiac_port_stats.rx_over_err = 0; + zodiac_port_stats.tx_errors = 0; + zodiac_port_stats.rx_errors = 0; + zodiac_port_stats.collisions = 0; memcpy(buffer, &reply, sizeof(struct ofp13_multipart_reply)); - memcpy(buffer+sizeof(struct ofp13_multipart_reply), &zodiac_port_stats[port], stats_size); + memcpy(buffer+sizeof(struct ofp13_multipart_reply), &zodiac_port_stats, stats_size); + } + else + { + TRACE("openflow_13.c: requested port is out of range"); } return len; } From e86872cc2b3b322558ea5e3f2a5ebb5cedf98029 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 24 Apr 2017 15:38:50 +1000 Subject: [PATCH 047/169] Add error message for invalid stats port request [OF v1.3] --- ZodiacFX/src/openflow/openflow_13.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index afbe84f..c23d028 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -1170,6 +1170,7 @@ int multi_portstats_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg else { TRACE("openflow_13.c: requested port is out of range"); + of_error13(buffer, OFPET13_BAD_REQUEST, OFPBRC13_BAD_PORT); } return len; } From 7c723f1fd03333a2dde9045c451b32e16c9cec5f Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 24 Apr 2017 16:54:30 +1000 Subject: [PATCH 048/169] Fix port stats reply [OF v1.3] Only OpenFlow ports should report statistics --- ZodiacFX/src/openflow/openflow_13.c | 131 +++++++++++++++++----------- 1 file changed, 82 insertions(+), 49 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index c23d028..342943e 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -1099,6 +1099,7 @@ int multi_tablefeat_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg int multi_portstats_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) { struct ofp13_multipart_reply reply; + struct ofp13_port_stats zodiac_port_stats; struct ofp13_port_stats_request *port_req = msg->body; int stats_size = 0; int len = 0; @@ -1106,66 +1107,98 @@ int multi_portstats_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg if (port == OFPP13_ANY) { - struct ofp13_port_stats zodiac_port_stats[total_ports-1]; - stats_size = (sizeof(struct ofp13_port_stats) * (total_ports-1)); // total ports, excluding controller port - len = sizeof(struct ofp13_multipart_reply) + stats_size; - + // Find number of OpenFlow ports present + uint8_t ofports = 0; + for(uint8_t k=0; kheader.xid; reply.type = htons(OFPMP13_PORT_STATS); reply.flags = 0; - - for(int k=0; k<(total_ports-1);k++) + + // Write reply header to buffer + memcpy(buffer, &reply, sizeof(struct ofp13_multipart_reply)); + // Increment buffer pointer + buffer += sizeof(struct ofp13_multipart_reply); + + // Write port stats to reply message + for(uint8_t k=0; k 0 && port <= total_ports) // Respond to request for ports 1-4 or 1-8 (stacking) { - struct ofp13_port_stats zodiac_port_stats; - stats_size = sizeof(struct ofp13_port_stats); - len = sizeof(struct ofp13_multipart_reply) + stats_size; - - reply.header.version = OF_Version; - reply.header.type = OFPT13_MULTIPART_REPLY; - reply.header.length = htons(len); - reply.header.xid = msg->header.xid; - reply.type = htons(OFPMP13_PORT_STATS); - reply.flags = 0; - - zodiac_port_stats.port_no = htonl(port); - zodiac_port_stats.rx_packets = htonll(phys13_port_stats[port-1].rx_packets); - zodiac_port_stats.tx_packets = htonll(phys13_port_stats[port-1].tx_packets); - zodiac_port_stats.rx_bytes = htonll(phys13_port_stats[port-1].rx_bytes); - zodiac_port_stats.tx_bytes = htonll(phys13_port_stats[port-1].tx_bytes); - zodiac_port_stats.rx_crc_err = htonll(phys13_port_stats[port-1].rx_crc_err); - zodiac_port_stats.rx_dropped = htonll(phys13_port_stats[port-1].rx_dropped); - zodiac_port_stats.tx_dropped = htonll(phys13_port_stats[port-1].tx_dropped); - zodiac_port_stats.rx_frame_err = 0; - zodiac_port_stats.rx_over_err = 0; - zodiac_port_stats.tx_errors = 0; - zodiac_port_stats.rx_errors = 0; - zodiac_port_stats.collisions = 0; - - memcpy(buffer, &reply, sizeof(struct ofp13_multipart_reply)); - memcpy(buffer+sizeof(struct ofp13_multipart_reply), &zodiac_port_stats, stats_size); + // Check if port is NOT native + if(!(NativePortMatrix & (1<<(port-1)))) + { + stats_size = sizeof(struct ofp13_port_stats); + len = sizeof(struct ofp13_multipart_reply) + stats_size; + + reply.header.version = OF_Version; + reply.header.type = OFPT13_MULTIPART_REPLY; + reply.header.length = htons(len); + reply.header.xid = msg->header.xid; + reply.type = htons(OFPMP13_PORT_STATS); + reply.flags = 0; + + zodiac_port_stats.port_no = htonl(port); + zodiac_port_stats.rx_packets = htonll(phys13_port_stats[port-1].rx_packets); + zodiac_port_stats.tx_packets = htonll(phys13_port_stats[port-1].tx_packets); + zodiac_port_stats.rx_bytes = htonll(phys13_port_stats[port-1].rx_bytes); + zodiac_port_stats.tx_bytes = htonll(phys13_port_stats[port-1].tx_bytes); + zodiac_port_stats.rx_crc_err = htonll(phys13_port_stats[port-1].rx_crc_err); + zodiac_port_stats.rx_dropped = htonll(phys13_port_stats[port-1].rx_dropped); + zodiac_port_stats.tx_dropped = htonll(phys13_port_stats[port-1].tx_dropped); + zodiac_port_stats.rx_frame_err = 0; + zodiac_port_stats.rx_over_err = 0; + zodiac_port_stats.tx_errors = 0; + zodiac_port_stats.rx_errors = 0; + zodiac_port_stats.collisions = 0; + + memcpy(buffer, &reply, sizeof(struct ofp13_multipart_reply)); + memcpy(buffer+sizeof(struct ofp13_multipart_reply), &zodiac_port_stats, stats_size); + } + else + { + TRACE("openflow_13.c: requested port is out of range"); + of_error13(buffer, OFPET13_BAD_REQUEST, OFPBRC13_BAD_PORT); + } } else { From e745cc227fbe129154e49160813213757babd90a Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 24 Apr 2017 17:08:57 +1000 Subject: [PATCH 049/169] Use shared_buffer for stats reply [OF v1.0] --- ZodiacFX/src/openflow/openflow_10.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 547ee2a..0d19117 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -630,9 +630,11 @@ void stats_port_reply(struct ofp_stats_request *msg) struct ofp10_port_stats_request *port_req = msg->body; int stats_size = 0; int k, len; - char buf[1024]; int port = ntohs(port_req->port_no); + // Clear shared_buffer + memset(&shared_buffer, 0, SHARED_BUFFER_LEN); + if (port == OFPP_NONE) { stats_size = (sizeof(struct ofp10_port_stats) * (total_ports-1)); @@ -662,8 +664,8 @@ void stats_port_reply(struct ofp_stats_request *msg) zodiac_port_stats[k].collisions = 0; } - memcpy(buf, &reply, sizeof(struct ofp10_stats_reply)); - memcpy(buf + sizeof(struct ofp10_stats_reply), &zodiac_port_stats[0], stats_size); + memcpy(shared_buffer, &reply, sizeof(struct ofp10_stats_reply)); + memcpy(shared_buffer + sizeof(struct ofp10_stats_reply), &zodiac_port_stats[0], stats_size); } else { @@ -691,10 +693,10 @@ void stats_port_reply(struct ofp_stats_request *msg) zodiac_port_stats[port].rx_errors = 0; zodiac_port_stats[port].collisions = 0; - memcpy(buf, &reply, sizeof(struct ofp10_stats_reply)); - memcpy(buf + sizeof(struct ofp10_stats_reply), &zodiac_port_stats[port], stats_size); + memcpy(shared_buffer, &reply, sizeof(struct ofp10_stats_reply)); + memcpy(shared_buffer + sizeof(struct ofp10_stats_reply), &zodiac_port_stats[port], stats_size); } - sendtcp(&buf, len); + sendtcp(&shared_buffer, len); return; } From b97339c8ef593d5c68c700128912ae90d6b62e58 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 24 Apr 2017 17:31:33 +1000 Subject: [PATCH 050/169] Fix port stats reply (WIP) [OF v1.0] --- ZodiacFX/src/openflow/openflow_10.c | 69 ++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 0d19117..2e1bfa8 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -625,21 +625,34 @@ void stats_table_reply(struct ofp_stats_request *msg) */ void stats_port_reply(struct ofp_stats_request *msg) { - struct ofp10_port_stats zodiac_port_stats[total_ports-1]; + struct ofp10_port_stats zodiac_port_stats; struct ofp10_stats_reply reply; struct ofp10_port_stats_request *port_req = msg->body; int stats_size = 0; - int k, len; + int len = 0; int port = ntohs(port_req->port_no); + uint8_t * buffer = shared_buffer; // Local position index // Clear shared_buffer memset(&shared_buffer, 0, SHARED_BUFFER_LEN); if (port == OFPP_NONE) { - stats_size = (sizeof(struct ofp10_port_stats) * (total_ports-1)); - len = sizeof(struct ofp10_stats_reply) + stats_size; + // Find number of OpenFlow ports present + uint8_t ofports = 0; + for(uint8_t k=0; k Date: Tue, 25 Apr 2017 07:10:23 +1000 Subject: [PATCH 051/169] Fixed gmac_write port map --- ZodiacFX/src/stacking.c | 2 +- ZodiacFX/src/switch.c | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 7e62a91..b705864 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -316,7 +316,7 @@ void MasterStackRcv(void) { TRACE("stacking.c: %d bytes of packet data received from slave", spi_count); spi_packet = &shared_buffer; - nnOF_tablelookup(spi_packet->pkt_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); + nnOF_tablelookup(&spi_packet->pkt_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); } else { TRACE("stacking.c: %d bytes of unknown data received from slave", spi_count); diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 24a7b26..3fc16a5 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -321,13 +321,23 @@ void update_port_status(void) void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) { TRACE("switch.c: gmac_write to port 0x%X (%d bytes)", port, ul_size); - // Convert OpenFlow port to physical port number if (port == OFPP_FLOOD || port == OFPP_ALL || port == OFPP13_FLOOD || port == OFPP13_ALL) // Send packet out all ports except the port it arrived on { TRACE("switch.c: Packet out FLOOD (%d bytes)", ul_size); - if(masterselect == false) MasterStackSend(p_buffer, ul_size, port); - port = (15 - NativePortMatrix) - (1<<(inport-1)); + if(masterselect == false) + { + MasterStackSend(p_buffer, ul_size, port); + if (inport < 5) + { + port = (15 - NativePortMatrix) - (1<<(inport-1)); + } else { + port = 15 - NativePortMatrix; + } + } else { + inport -= 4; + port = (15 - (1<<(inport-1))); + } } else if (port == OFPP13_IN_PORT) // Send it back out the port it arrived on { port = inport; From fb3bb77e86cf046c0c1de87aaabfe059387322e6 Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Tue, 25 Apr 2017 07:59:23 +1000 Subject: [PATCH 052/169] Fixed stacking packet buffer --- ZodiacFX/src/openflow/openflow_10.c | 28 ++++++++++++++-------------- ZodiacFX/src/stacking.c | 20 +++++++++++--------- ZodiacFX/src/stacking.h | 1 + ZodiacFX/src/switch.c | 2 +- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 2e1bfa8..107d2cb 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -704,22 +704,22 @@ void stats_port_reply(struct ofp_stats_request *msg) reply.type = htons(OFPST_PORT); reply.flags = 0; - zodiac_port_stats[port].port_no = htons(port); - zodiac_port_stats[port].rx_packets = htonll(phys10_port_stats[port-1].rx_packets); - zodiac_port_stats[port].tx_packets = htonll(phys10_port_stats[port-1].tx_packets); - zodiac_port_stats[port].rx_bytes = htonll(phys10_port_stats[port-1].rx_bytes); - zodiac_port_stats[port].tx_bytes = htonll(phys10_port_stats[port-1].tx_bytes); - zodiac_port_stats[port].rx_crc_err = htonll(phys10_port_stats[port-1].rx_crc_err); - zodiac_port_stats[port].rx_dropped = htonll(phys10_port_stats[port-1].rx_dropped); - zodiac_port_stats[port].tx_dropped = htonll(phys10_port_stats[port-1].tx_dropped); - zodiac_port_stats[port].rx_frame_err = 0; - zodiac_port_stats[port].rx_over_err = 0; - zodiac_port_stats[port].tx_errors = 0; - zodiac_port_stats[port].rx_errors = 0; - zodiac_port_stats[port].collisions = 0; + zodiac_port_stats.port_no = htons(port); + zodiac_port_stats.rx_packets = htonll(phys10_port_stats[port-1].rx_packets); + zodiac_port_stats.tx_packets = htonll(phys10_port_stats[port-1].tx_packets); + zodiac_port_stats.rx_bytes = htonll(phys10_port_stats[port-1].rx_bytes); + zodiac_port_stats.tx_bytes = htonll(phys10_port_stats[port-1].tx_bytes); + zodiac_port_stats.rx_crc_err = htonll(phys10_port_stats[port-1].rx_crc_err); + zodiac_port_stats.rx_dropped = htonll(phys10_port_stats[port-1].rx_dropped); + zodiac_port_stats.tx_dropped = htonll(phys10_port_stats[port-1].tx_dropped); + zodiac_port_stats.rx_frame_err = 0; + zodiac_port_stats.rx_over_err = 0; + zodiac_port_stats.tx_errors = 0; + zodiac_port_stats.rx_errors = 0; + zodiac_port_stats.collisions = 0; memcpy(shared_buffer, &reply, sizeof(struct ofp10_stats_reply)); - memcpy(shared_buffer + sizeof(struct ofp10_stats_reply), &zodiac_port_stats[port], stats_size); + memcpy(shared_buffer + sizeof(struct ofp10_stats_reply), &zodiac_port_stats, stats_size); } sendtcp(&shared_buffer, len); return; diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index b705864..1e2384e 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -36,7 +36,7 @@ #include "openflow/openflow.h" /* SPI clock setting (Hz). */ -static uint32_t gs_ul_spi_clock = 500000; +static uint32_t gs_ul_spi_clock = 1000000; /* Chip select. */ #define SPI_CHIP_SEL 0 @@ -54,6 +54,7 @@ static uint32_t gs_ul_spi_clock = 500000; extern uint8_t last_port_status[8]; extern uint8_t port_status[8]; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; +extern uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; extern int OF_Version; extern struct ofp10_port_stats phys10_port_stats[8]; extern struct ofp13_port_stats phys13_port_stats[8]; @@ -230,21 +231,21 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); // Write preamble spi_write(SPI_MASTER_BASE, 0xcd, 0, 0); - for(int x = 0;x<10000;x++); + for(int x = 0;xpkt_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); + memcpy(gs_uc_eth_buffer, &spi_packet->pkt_buffer, GMAC_FRAME_LENTGH_MAX); + nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); } else { TRACE("stacking.c: %d bytes of unknown data received from slave", spi_count); diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 5186751..347c2c5 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -42,6 +42,7 @@ #define SPI_RCV_PREAMBLE 4 #define SPI_STATS_PREAMBLE 0xABAB #define SPI_PACKET_PREAMBLE 0xBCBC +#define SPI_SEND_WAIT 500 struct spi_port_stats { uint16_t premable; diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 3fc16a5..9abef31 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -64,7 +64,7 @@ uint8_t port_status[8]; uint8_t last_port_status[8]; uint8_t total_ports = 4; int slave_timer = 0; -static volatile uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; +uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; uint8_t stats_rr = 0; /* GMAC HW configurations */ From cf7b0bb23b113070423bbe10f2fd86d2b8494511 Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Tue, 25 Apr 2017 08:56:01 +1000 Subject: [PATCH 053/169] Fixed slave ports list --- ZodiacFX/src/command.c | 27 +++++++++++++++++---------- ZodiacFX/src/stacking.c | 12 ++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index b314dce..c51836c 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -335,22 +335,29 @@ void command_root(char *command, char *param1, char *param2, char *param3) printf("\r\nPort %d\r\n",i+1); if (port_status[i] == 1) printf(" Status: UP\r\n"); if (port_status[i] == 0) printf(" Status: DOWN\r\n"); - for (int x=0;x 3) { - if (Zodiac_Config.vlan_list[x].portmap[i] == 1) + printf(" VLAN type: OpenFlow\r\n"); + printf(" VLAN ID: n/a\r\n"); + } else + { + for (int x=0;x 3) printf(" RX Packets: %" PRIu64 "\r\n", phys10_port_stats[i].rx_packets); + if (Zodiac_Config.of_port[i] == 1 || i > 3) printf(" TX Packets: %" PRIu64 "\r\n", phys10_port_stats[i].tx_packets); printf(" RX Dropped Packets: %" PRIu64 "\r\n", phys10_port_stats[i].rx_dropped); printf(" TX Dropped Packets: %" PRIu64 "\r\n", phys10_port_stats[i].tx_dropped); printf(" RX CRC Errors: %" PRIu64 "\r\n", phys10_port_stats[i].rx_crc_err); @@ -359,8 +366,8 @@ void command_root(char *command, char *param1, char *param2, char *param3) { printf(" RX Bytes: %" PRIu64 "\r\n", phys13_port_stats[i].rx_bytes); printf(" TX Bytes: %" PRIu64 "\r\n", phys13_port_stats[i].tx_bytes); - if (Zodiac_Config.of_port[i] == 1) printf(" RX Packets: %" PRIu64 "\r\n", phys13_port_stats[i].rx_packets); - if (Zodiac_Config.of_port[i] == 1) printf(" TX Packets: %" PRIu64 "\r\n", phys13_port_stats[i].tx_packets); + if (Zodiac_Config.of_port[i] == 1 || i > 3) printf(" RX Packets: %" PRIu64 "\r\n", phys13_port_stats[i].rx_packets); + if (Zodiac_Config.of_port[i] == 1 || i > 3) printf(" TX Packets: %" PRIu64 "\r\n", phys13_port_stats[i].tx_packets); printf(" RX Dropped Packets: %" PRIu64 "\r\n", phys13_port_stats[i].rx_dropped); printf(" TX Dropped Packets: %" PRIu64 "\r\n", phys13_port_stats[i].tx_dropped); printf(" RX CRC Errors: %" PRIu64 "\r\n", phys13_port_stats[i].rx_crc_err); diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 1e2384e..98c41a9 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -224,8 +224,18 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) if (port < 255) { outport = port; + phys10_port_stats[port-1].tx_packets++; + phys13_port_stats[port-1].tx_packets++; } else { port = 255; + if (port_status[4] == 1) phys10_port_stats[4].tx_packets++; + if (port_status[4] == 1) phys13_port_stats[4].tx_packets++; + if (port_status[5] == 1) phys10_port_stats[5].tx_packets++; + if (port_status[5] == 1) phys13_port_stats[5].tx_packets++; + if (port_status[6] == 1) phys10_port_stats[6].tx_packets++; + if (port_status[6] == 1) phys13_port_stats[6].tx_packets++; + if (port_status[7] == 1) phys10_port_stats[7].tx_packets++; + if (port_status[7] == 1) phys13_port_stats[7].tx_packets++; } TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); @@ -318,6 +328,8 @@ void MasterStackRcv(void) TRACE("stacking.c: %d bytes of packet data received from slave", spi_count); spi_packet = &shared_buffer; memcpy(gs_uc_eth_buffer, &spi_packet->pkt_buffer, GMAC_FRAME_LENTGH_MAX); + phys10_port_stats[spi_packet->tag-1].rx_packets++; + phys13_port_stats[spi_packet->tag-1].rx_packets++; nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); } else { From be712abad726907fd603fe0c7753414cc37070b9 Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Tue, 25 Apr 2017 15:26:26 +1000 Subject: [PATCH 054/169] Stacking performance tuning --- ZodiacFX/src/main.c | 4 ++-- ZodiacFX/src/stacking.c | 2 +- ZodiacFX/src/stacking.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c index 07ffcb9..22528c5 100644 --- a/ZodiacFX/src/main.c +++ b/ZodiacFX/src/main.c @@ -202,11 +202,11 @@ int main (void) while(1) { task_switch(&gs_net_if); - task_command(cCommand, cCommand_last); + //task_command(cCommand, cCommand_last); // Only run the following tasks if set to Master if(masterselect == false) { - //task_command(cCommand, cCommand_last); + task_command(cCommand, cCommand_last); sys_check_timeouts(); task_openflow(); } diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 98c41a9..38c1e54 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -36,7 +36,7 @@ #include "openflow/openflow.h" /* SPI clock setting (Hz). */ -static uint32_t gs_ul_spi_clock = 1000000; +static uint32_t gs_ul_spi_clock = 2000000; /* Chip select. */ #define SPI_CHIP_SEL 0 diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 347c2c5..f160bd7 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -42,7 +42,7 @@ #define SPI_RCV_PREAMBLE 4 #define SPI_STATS_PREAMBLE 0xABAB #define SPI_PACKET_PREAMBLE 0xBCBC -#define SPI_SEND_WAIT 500 +#define SPI_SEND_WAIT 200 struct spi_port_stats { uint16_t premable; From 8260f71fe0735b517bc6f687d170663a1fdf9f0c Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 28 Apr 2017 09:38:00 +1000 Subject: [PATCH 055/169] Add buffer size check for stats reply [OF v1.3] --- ZodiacFX/src/openflow/openflow_13.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 342943e..df19919 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -1155,10 +1155,17 @@ int multi_portstats_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg zodiac_port_stats.rx_errors = 0; zodiac_port_stats.collisions = 0; - // Write port stats to buffer - memcpy(buffer, &zodiac_port_stats, sizeof(struct ofp13_port_stats)); - // Increment buffer pointer - buffer += sizeof(struct ofp13_port_stats); + if((buffer + sizeof(struct ofp13_port_stats)) < (shared_buffer + SHARED_BUFFER_LEN)) + { + // Write port stats to buffer + memcpy(buffer, &zodiac_port_stats, sizeof(struct ofp13_port_stats)); + // Increment buffer pointer + buffer += sizeof(struct ofp13_port_stats); + } + else + { + TRACE("openflow_13.c: unable to write port stats to shared buffer"); + } } } } From b0488203a08c6d29442a87e12eda4bdc37b2c8bf Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 28 Apr 2017 10:26:08 +1000 Subject: [PATCH 056/169] Fix port stats reply [OF v1.0] --- ZodiacFX/src/openflow/openflow_10.c | 88 ++++++++++++++++++----------- 1 file changed, 54 insertions(+), 34 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 2e1bfa8..46fe808 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -664,7 +664,7 @@ void stats_port_reply(struct ofp_stats_request *msg) memcpy(buffer, &reply, sizeof(struct ofp10_stats_reply)); buffer += sizeof(struct ofp10_stats_reply); - // Write port stats to reply message + // Write port stats to reply message for(uint8_t k=0; k 0 && port <= total_ports) // Respond to request for ports 1-4 or 1-8 (stacking) { - stats_size = sizeof(struct ofp10_port_stats); - len = sizeof(struct ofp10_stats_reply) + stats_size; - - reply.header.version = OF_Version; - reply.header.type = OFPT10_STATS_REPLY; - reply.header.length = htons(len); - reply.header.xid = msg->header.xid; - reply.type = htons(OFPST_PORT); - reply.flags = 0; - - zodiac_port_stats[port].port_no = htons(port); - zodiac_port_stats[port].rx_packets = htonll(phys10_port_stats[port-1].rx_packets); - zodiac_port_stats[port].tx_packets = htonll(phys10_port_stats[port-1].tx_packets); - zodiac_port_stats[port].rx_bytes = htonll(phys10_port_stats[port-1].rx_bytes); - zodiac_port_stats[port].tx_bytes = htonll(phys10_port_stats[port-1].tx_bytes); - zodiac_port_stats[port].rx_crc_err = htonll(phys10_port_stats[port-1].rx_crc_err); - zodiac_port_stats[port].rx_dropped = htonll(phys10_port_stats[port-1].rx_dropped); - zodiac_port_stats[port].tx_dropped = htonll(phys10_port_stats[port-1].tx_dropped); - zodiac_port_stats[port].rx_frame_err = 0; - zodiac_port_stats[port].rx_over_err = 0; - zodiac_port_stats[port].tx_errors = 0; - zodiac_port_stats[port].rx_errors = 0; - zodiac_port_stats[port].collisions = 0; - - memcpy(shared_buffer, &reply, sizeof(struct ofp10_stats_reply)); - memcpy(shared_buffer + sizeof(struct ofp10_stats_reply), &zodiac_port_stats[port], stats_size); + // Check if port is NOT native + if(!(NativePortMatrix & (1<<(port-1)))) + { + stats_size = sizeof(struct ofp10_port_stats); + len = sizeof(struct ofp10_stats_reply) + stats_size; + + reply.header.version = OF_Version; + reply.header.type = OFPT10_STATS_REPLY; + reply.header.length = htons(len); + reply.header.xid = msg->header.xid; + reply.type = htons(OFPST_PORT); + reply.flags = 0; + + zodiac_port_stats.port_no = htons(port); + zodiac_port_stats.rx_packets = htonll(phys10_port_stats[port-1].rx_packets); + zodiac_port_stats.tx_packets = htonll(phys10_port_stats[port-1].tx_packets); + zodiac_port_stats.rx_bytes = htonll(phys10_port_stats[port-1].rx_bytes); + zodiac_port_stats.tx_bytes = htonll(phys10_port_stats[port-1].tx_bytes); + zodiac_port_stats.rx_crc_err = htonll(phys10_port_stats[port-1].rx_crc_err); + zodiac_port_stats.rx_dropped = htonll(phys10_port_stats[port-1].rx_dropped); + zodiac_port_stats.tx_dropped = htonll(phys10_port_stats[port-1].tx_dropped); + zodiac_port_stats.rx_frame_err = 0; + zodiac_port_stats.rx_over_err = 0; + zodiac_port_stats.tx_errors = 0; + zodiac_port_stats.rx_errors = 0; + zodiac_port_stats.collisions = 0; + + memcpy(shared_buffer, &reply, sizeof(struct ofp10_stats_reply)); + memcpy(shared_buffer + sizeof(struct ofp10_stats_reply), &zodiac_port_stats, stats_size); + } + else + { + TRACE("openflow_13.c: requested port is out of range"); + of_error13(buffer, OFPET13_BAD_REQUEST, OFPBRC13_BAD_PORT); + } + } + else + { + TRACE("openflow_13.c: requested port is out of range"); + of_error13(buffer, OFPET13_BAD_REQUEST, OFPBRC13_BAD_PORT); } sendtcp(&shared_buffer, len); return; From 85c38022b13d8cbaa7d4401ca1b123c6e3bc0e0f Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 28 Apr 2017 10:42:34 +1000 Subject: [PATCH 057/169] Fix port stats error messages [OF v1.0] --- ZodiacFX/src/openflow/openflow_10.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 46fe808..09e5b9f 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -732,14 +732,14 @@ void stats_port_reply(struct ofp_stats_request *msg) } else { - TRACE("openflow_13.c: requested port is out of range"); - of_error13(buffer, OFPET13_BAD_REQUEST, OFPBRC13_BAD_PORT); + TRACE("openflow_10.c: requested port is out of range"); + of10_error(buffer, OFPET10_BAD_REQUEST, OFPBRC10_BAD_STAT); } } else { - TRACE("openflow_13.c: requested port is out of range"); - of_error13(buffer, OFPET13_BAD_REQUEST, OFPBRC13_BAD_PORT); + TRACE("openflow_10.c: requested port is out of range"); + of10_error(buffer, OFPET10_BAD_REQUEST, OFPBRC10_BAD_STAT); } sendtcp(&shared_buffer, len); return; From cdc1b437f5488a3641007efe2ee0a3710afb839b Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 28 Apr 2017 13:19:49 +1000 Subject: [PATCH 058/169] Modify WI Display: Ports structure --- ZodiacFX/src/http.c | 105 +++++++++++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 35 deletions(-) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 094b96c..72d4a73 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -70,6 +70,7 @@ extern int iLastMeter; extern struct ofp10_port_stats phys10_port_stats[8]; extern struct ofp13_port_stats phys13_port_stats[8]; extern struct table_counter table_counters[MAX_TABLES]; +extern uint8_t total_ports; // Local Variables struct tcp_pcb *http_pcb; @@ -485,7 +486,15 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err if(interfaceCreate_Display_Ports(1)) { - // Call TCP output & close the connection + http_send(&shared_buffer, pcb, 0); + } + else + { + TRACE("http.c: Unable to serve page - buffer at %d bytes", strlen(shared_buffer)); + } + + if(interfaceCreate_Display_Ports(2)) + { http_send(&shared_buffer, pcb, 1); TRACE("http.c: Page sent successfully - %d bytes", strlen(shared_buffer)); } @@ -829,7 +838,7 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err { // Only write to buffer - don't send http_send(&shared_buffer, pcb, 0); - TRACE("http.c: updated ports page sent successfully (1/2) - %d bytes", strlen(shared_buffer)); + TRACE("http.c: updated ports page sent successfully (1/3) - %d bytes", strlen(shared_buffer)); } else { @@ -837,10 +846,21 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err } if(interfaceCreate_Display_Ports(1)) + { + // Call TCP output & close the connection + http_send(&shared_buffer, pcb, 0); + TRACE("http.c: updated ports page sent successfully (2/3) - %d bytes", strlen(shared_buffer)); + } + else + { + TRACE("http.c: unable to serve updated page - buffer at %d bytes", strlen(shared_buffer)); + } + + if(interfaceCreate_Display_Ports(2)) { // Call TCP output & close the connection http_send(&shared_buffer, pcb, 1); - TRACE("http.c: updated ports page sent successfully (2/2) - %d bytes", strlen(shared_buffer)); + TRACE("http.c: updated ports page sent successfully (3/3) - %d bytes", strlen(shared_buffer)); } else { @@ -2261,35 +2281,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) { if(step == 0) { - int currPort; - - // Create status strings - char portStatusch[2][5]; - snprintf(portStatusch[0], 5, "DOWN"); - snprintf(portStatusch[1], 5, "UP"); - - // Create VLAN type strings - char portvlType[3][11]; - snprintf(portvlType[0], 11, "n/a"); - snprintf(portvlType[1], 11, "OpenFlow"); - snprintf(portvlType[2], 11, "Native"); - - // Create - int vlArr[4] = { 0 }; - - // Count active VLANs, store list value in vlArr - int x; - uint8_t vlCtr = 0; - for (x=0;x"\ ); snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer), html_style_body); - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + if (snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ "table {"\ "border-collapse: collapse;"\ "border: 1px solid black;"\ @@ -2340,6 +2331,49 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) ""\ ""\ "Status:"\ + ) < SHARED_BUFFER_LEN) + { + return 1; + } + else + { + TRACE("http.c: WARNING: html truncated to prevent buffer overflow"); + return 0; + } +// ------------------------------------------------------ + } + else if(step == 1) + { + int currPort; + + // Create status strings + char portStatusch[2][5]; + snprintf(portStatusch[0], 5, "DOWN"); + snprintf(portStatusch[1], 5, "UP"); + + // Create VLAN type strings + char portvlType[3][11]; + snprintf(portvlType[0], 11, "n/a"); + snprintf(portvlType[1], 11, "OpenFlow"); + snprintf(portvlType[2], 11, "Native"); + + // Create + int vlArr[4] = { 0 }; + + // Count active VLANs, store list value in vlArr + int x; + uint8_t vlCtr = 0; + for (x=0;x%s"\ "%s"\ "%s"\ @@ -2399,7 +2433,7 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) ""\ "VLAN ID:"\ ); - + // Create VLAN dropdown for each port for(x=0;x<4;x++) { @@ -2454,7 +2488,7 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) return 0; } } - else if(step == 1) + else if(step == 2) { if(OF_Version == 1) { @@ -2553,6 +2587,7 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ "%"PRIu64""\ ""\ +// ---------------------------------------------------------------------------------------------------------- ""\ "RX Packets:"\ "%"PRIu64""\ From b34517703c2de90d477715022422d24d84d6e5c7 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 28 Apr 2017 13:33:30 +1000 Subject: [PATCH 059/169] Add additional step in WI Display: Ports page Final commit before adjusting to accommodate stacking (8 ports) --- ZodiacFX/src/http.c | 130 +++++++++++++++++++++++++++++++------------- 1 file changed, 91 insertions(+), 39 deletions(-) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 72d4a73..641659c 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -494,6 +494,15 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err } if(interfaceCreate_Display_Ports(2)) + { + http_send(&shared_buffer, pcb, 0); + } + else + { + TRACE("http.c: Unable to serve page - buffer at %d bytes", strlen(shared_buffer)); + } + + if(interfaceCreate_Display_Ports(3)) { http_send(&shared_buffer, pcb, 1); TRACE("http.c: Page sent successfully - %d bytes", strlen(shared_buffer)); @@ -838,7 +847,7 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err { // Only write to buffer - don't send http_send(&shared_buffer, pcb, 0); - TRACE("http.c: updated ports page sent successfully (1/3) - %d bytes", strlen(shared_buffer)); + TRACE("http.c: updated ports page sent successfully (1/4) - %d bytes", strlen(shared_buffer)); } else { @@ -849,7 +858,7 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err { // Call TCP output & close the connection http_send(&shared_buffer, pcb, 0); - TRACE("http.c: updated ports page sent successfully (2/3) - %d bytes", strlen(shared_buffer)); + TRACE("http.c: updated ports page sent successfully (2/4) - %d bytes", strlen(shared_buffer)); } else { @@ -857,10 +866,21 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err } if(interfaceCreate_Display_Ports(2)) + { + // Call TCP output & close the connection + http_send(&shared_buffer, pcb, 0); + TRACE("http.c: updated ports page sent successfully (3/4) - %d bytes", strlen(shared_buffer)); + } + else + { + TRACE("http.c: unable to serve updated page - buffer at %d bytes", strlen(shared_buffer)); + } + + if(interfaceCreate_Display_Ports(3)) { // Call TCP output & close the connection http_send(&shared_buffer, pcb, 1); - TRACE("http.c: updated ports page sent successfully (3/3) - %d bytes", strlen(shared_buffer)); + TRACE("http.c: updated ports page sent successfully (4/4) - %d bytes", strlen(shared_buffer)); } else { @@ -2340,7 +2360,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) TRACE("http.c: WARNING: html truncated to prevent buffer overflow"); return 0; } -// ------------------------------------------------------ } else if(step == 1) { @@ -2522,42 +2541,57 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ "%"PRIu64""\ ""\ + , phys10_port_stats[0].rx_bytes, phys10_port_stats[1].rx_bytes, phys10_port_stats[2].rx_bytes, phys10_port_stats[3].rx_bytes + , phys10_port_stats[0].tx_bytes, phys10_port_stats[1].tx_bytes, phys10_port_stats[2].tx_bytes, phys10_port_stats[3].tx_bytes + , phys10_port_stats[0].rx_packets, phys10_port_stats[1].rx_packets, phys10_port_stats[2].rx_packets, phys10_port_stats[3].rx_packets + , phys10_port_stats[0].tx_packets, phys10_port_stats[1].tx_packets, phys10_port_stats[2].tx_packets, phys10_port_stats[3].tx_packets + ) < SHARED_BUFFER_LEN) + { + TRACE("http.c: html (2/2) written to buffer"); + return 1; + } + else + { + TRACE("http.c: WARNING: html truncated to prevent buffer overflow"); + return 0; + } + } + else + { + // of v1.3 + if( snprintf(shared_buffer, SHARED_BUFFER_LEN,\ + ""\ + "RX Bytes:"\ + "%"PRIu64""\ + "%"PRIu64""\ + "%"PRIu64""\ + "%"PRIu64""\ + ""\ ""\ - "RX Dropped Packets:"\ + "TX Bytes:"\ "%"PRIu64""\ "%"PRIu64""\ "%"PRIu64""\ "%"PRIu64""\ ""\ ""\ - "TX Dropped Packets:"\ + "RX Packets:"\ "%"PRIu64""\ "%"PRIu64""\ "%"PRIu64""\ "%"PRIu64""\ ""\ ""\ - "RX CRC Errors:"\ + "TX Packets:"\ "%"PRIu64""\ "%"PRIu64""\ "%"PRIu64""\ "%"PRIu64""\ ""\ - ""\ - "
"\ - ""\ - "
"\ - ""\ - ""\ - ""\ - ""\ - , phys10_port_stats[0].rx_bytes, phys10_port_stats[1].rx_bytes, phys10_port_stats[2].rx_bytes, phys10_port_stats[3].rx_bytes - , phys10_port_stats[0].tx_bytes, phys10_port_stats[1].tx_bytes, phys10_port_stats[2].tx_bytes, phys10_port_stats[3].tx_bytes - , phys10_port_stats[0].rx_packets, phys10_port_stats[1].rx_packets, phys10_port_stats[2].rx_packets, phys10_port_stats[3].rx_packets - , phys10_port_stats[0].tx_packets, phys10_port_stats[1].tx_packets, phys10_port_stats[2].tx_packets, phys10_port_stats[3].tx_packets - , phys10_port_stats[0].rx_dropped, phys10_port_stats[1].rx_dropped, phys10_port_stats[2].rx_dropped, phys10_port_stats[3].rx_dropped - , phys10_port_stats[0].tx_dropped, phys10_port_stats[1].tx_dropped, phys10_port_stats[2].tx_dropped, phys10_port_stats[3].tx_dropped - , phys10_port_stats[0].rx_crc_err, phys10_port_stats[1].rx_crc_err, phys10_port_stats[2].rx_crc_err, phys10_port_stats[3].rx_crc_err + , phys13_port_stats[0].rx_bytes, phys13_port_stats[1].rx_bytes, phys13_port_stats[2].rx_bytes, phys13_port_stats[3].rx_bytes + , phys13_port_stats[0].tx_bytes, phys13_port_stats[1].tx_bytes, phys13_port_stats[2].tx_bytes, phys13_port_stats[3].tx_bytes + , phys13_port_stats[0].rx_packets, phys13_port_stats[1].rx_packets, phys13_port_stats[2].rx_packets, phys13_port_stats[3].rx_packets + , phys13_port_stats[0].tx_packets, phys13_port_stats[1].tx_packets, phys13_port_stats[2].tx_packets, phys13_port_stats[3].tx_packets ) < SHARED_BUFFER_LEN) { TRACE("http.c: html (2/2) written to buffer"); @@ -2569,39 +2603,60 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) return 0; } } - else + } + else if(step == 3) + { + if(OF_Version == 1) { - // of v1.3 + // of v1.0 if( snprintf(shared_buffer, SHARED_BUFFER_LEN,\ - ""\ - "RX Bytes:"\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - ""\ ""\ - "TX Bytes:"\ + "RX Dropped Packets:"\ "%"PRIu64""\ "%"PRIu64""\ "%"PRIu64""\ "%"PRIu64""\ ""\ -// ---------------------------------------------------------------------------------------------------------- ""\ - "RX Packets:"\ + "TX Dropped Packets:"\ "%"PRIu64""\ "%"PRIu64""\ "%"PRIu64""\ "%"PRIu64""\ ""\ ""\ - "TX Packets:"\ + "RX CRC Errors:"\ "%"PRIu64""\ "%"PRIu64""\ "%"PRIu64""\ "%"PRIu64""\ ""\ + ""\ + "
"\ + ""\ + "
"\ + ""\ + ""\ + ""\ + ""\ + , phys10_port_stats[0].rx_dropped, phys10_port_stats[1].rx_dropped, phys10_port_stats[2].rx_dropped, phys10_port_stats[3].rx_dropped + , phys10_port_stats[0].tx_dropped, phys10_port_stats[1].tx_dropped, phys10_port_stats[2].tx_dropped, phys10_port_stats[3].tx_dropped + , phys10_port_stats[0].rx_crc_err, phys10_port_stats[1].rx_crc_err, phys10_port_stats[2].rx_crc_err, phys10_port_stats[3].rx_crc_err + ) < SHARED_BUFFER_LEN) + { + TRACE("http.c: html (2/2) written to buffer"); + return 1; + } + else + { + TRACE("http.c: WARNING: html truncated to prevent buffer overflow"); + return 0; + } + } + else + { + // of v1.3 + if( snprintf(shared_buffer, SHARED_BUFFER_LEN,\ ""\ "RX Dropped Packets:"\ "%"PRIu64""\ @@ -2631,10 +2686,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) ""\ ""\ ""\ - , phys13_port_stats[0].rx_bytes, phys13_port_stats[1].rx_bytes, phys13_port_stats[2].rx_bytes, phys13_port_stats[3].rx_bytes - , phys13_port_stats[0].tx_bytes, phys13_port_stats[1].tx_bytes, phys13_port_stats[2].tx_bytes, phys13_port_stats[3].tx_bytes - , phys13_port_stats[0].rx_packets, phys13_port_stats[1].rx_packets, phys13_port_stats[2].rx_packets, phys13_port_stats[3].rx_packets - , phys13_port_stats[0].tx_packets, phys13_port_stats[1].tx_packets, phys13_port_stats[2].tx_packets, phys13_port_stats[3].tx_packets , phys13_port_stats[0].rx_dropped, phys13_port_stats[1].rx_dropped, phys13_port_stats[2].rx_dropped, phys13_port_stats[3].rx_dropped , phys13_port_stats[0].tx_dropped, phys13_port_stats[1].tx_dropped, phys13_port_stats[2].tx_dropped, phys13_port_stats[3].tx_dropped , phys13_port_stats[0].rx_crc_err, phys13_port_stats[1].rx_crc_err, phys13_port_stats[2].rx_crc_err, phys13_port_stats[3].rx_crc_err @@ -2650,6 +2701,7 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) } } } + else { TRACE("http.c: Display: Ports step error"); From b0e785e55483c9ef8a3d87becbf0e7c35bc519b3 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 28 Apr 2017 14:35:42 +1000 Subject: [PATCH 060/169] Expand WI Display: Ports display range Now displays 8 ports in a stacking configuration. --- ZodiacFX/src/http.c | 288 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 265 insertions(+), 23 deletions(-) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 641659c..1968743 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -2311,7 +2311,7 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) ""\ ""\ ""\ @@ -2103,7 +2105,21 @@ static uint8_t interfaceCreate_Home(void) "CPU UID: %d-%d-%d-%d
"\ "Firmware Version: %s
"\ "CPU Temp: %d C
"\ - "Uptime: %02d:%02d"\ + "Uptime: %02d:%02d
"\ + ); + if(stackenabled == true) + { + snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + "Stacking: enabled" + ); + } + else + { + snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + "Stacking: disabled" + ); + } + if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ "

"\ "
"\ ""\ From d9b5868767efd47328a6bfa5f4ebe7459f106938 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 1 May 2017 10:10:20 +1000 Subject: [PATCH 064/169] Remove masterselect cli output --- ZodiacFX/src/command.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index c51836c..7e8f433 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -559,8 +559,6 @@ void command_config(char *command, char *param1, char *param2, char *param3) } else { printf(" Force OpenFlow version: Disabled\r\n"); } - if (masterselect == true) printf(" Stacking Select: SLAVE\r\n"); - if (masterselect == false) printf(" Stacking Select: MASTER\r\n"); if (stackenabled == true) printf(" Stacking Status: Enabled\r\n"); if (stackenabled == false) printf(" Stacking Status: Disabled\r\n"); if (Zodiac_Config.ethtype_filter == 1) printf(" EtherType Filtering: Enabled\r\n"); From 61148d6cd31e556be01c1c6a652dcdf6d20eb343 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 1 May 2017 16:38:53 +1000 Subject: [PATCH 065/169] Modify slave->master packet send stability More reliable transmission of packets by waiting for master to send next dummy byte. --- ZodiacFX/src/stacking.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 251814f..b81da7e 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -400,10 +400,11 @@ void SPI_Handler(void) return; } - if(pending_spi_command == SPI_SEND_PKT) // We send the master our port stats + if(pending_spi_command == SPI_SEND_PKT) // Send slave packet to master { if (spi_slave_send_count <= 0) { + // Flush out last two bytes if (spi_dummy_bytes < 2) { spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); @@ -414,8 +415,14 @@ void SPI_Handler(void) ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done spi_dummy_bytes = 0; } else { - spi_write(SPI_SLAVE_BASE, shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); - spi_slave_send_count--; + while(spi_slave_send_count > 0) + { + // CHECK IF INTERRUPTS NEED TO BE DISABLED + spi_write(SPI_SLAVE_BASE, shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); + spi_slave_send_count--; + // Wait for master to send the next byte + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + } } return; } From ee2386ccc6590828d9b49039272c98adf2700eeb Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 1 May 2017 22:19:50 +1000 Subject: [PATCH 066/169] Clean up comments & misc fixes Missing extern added Additional debug statement added --- ZodiacFX/src/http.c | 2 ++ ZodiacFX/src/stacking.c | 4 +++- ZodiacFX/src/switch.c | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 906362c..3e0a9f6 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -91,6 +91,8 @@ static bool restart_required = false; // Track if any configuration changes are static bool file_upload = false; // Multi-part firmware file upload flag static bool post_pending = false; +extern bool stackenabled; + static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err); static err_t http_accept(void *arg, struct tcp_pcb *pcb, err_t err); void http_send(char *buffer, struct tcp_pcb *pcb, bool out); diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index b81da7e..fc5958e 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -246,6 +246,7 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) spi_write(SPI_MASTER_BASE, 0xcd, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); for(int x = 0;x Master %d", sys_get_ms() - rcv_time); if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) // Stats message { @@ -417,7 +419,6 @@ void SPI_Handler(void) } else { while(spi_slave_send_count > 0) { - // CHECK IF INTERRUPTS NEED TO BE DISABLED spi_write(SPI_SLAVE_BASE, shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); spi_slave_send_count--; // Wait for master to send the next byte @@ -431,6 +432,7 @@ void SPI_Handler(void) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); if (data == 0xcd) pending_spi_command = SPI_RCV_PREAMBLE; + // START PROCESSING return; } diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 54d4559..08d1f92 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -580,6 +580,7 @@ void task_switch(struct netif *netif) { if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) { + // Prepare packet to send from SLAVE to MASTER uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); uint8_t tag = *tail_tag + 1; phys10_port_stats[tag-1].rx_packets++; From 8b88ac8cf36fe9776b8238d26004abf5122a2181 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 1 May 2017 22:20:41 +1000 Subject: [PATCH 067/169] Add timer to stacking Profiles the tx/rx sections --- ZodiacFX/src/stacking.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index fc5958e..15e35f2 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -34,6 +34,7 @@ #include "switch.h" #include "lwip/def.h" #include "openflow/openflow.h" +#include "timers.h" /* SPI clock setting (Hz). */ static uint32_t gs_ul_spi_clock = 2000000; @@ -239,30 +240,32 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) } TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); + uint32_t snd_time = sys_get_ms(); // Write preamble spi_write(SPI_MASTER_BASE, 0xcd, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - for(int x = 0;x Slave %d", sys_get_ms() - snd_time); return; } @@ -287,10 +290,11 @@ void MasterStackRcv(void) if (shared_buffer[0] != 0xAB && shared_buffer[0] != 0xBC) return; spi_count = 4; - spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); + spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); + uint32_t rcv_time = sys_get_ms(); while(spi_count < spi_read_size) { - for(int x = 0;xSLAVE) uint8_t uc_pcs; if (slave_ready == false) // Is this the first data we have received? @@ -442,6 +447,7 @@ void SPI_Handler(void) if (data == 0xcd) { pending_spi_command = SPI_RECEIVE; + receive_timeout = sys_get_ms(); memset(&shared_buffer,0,sizeof(shared_buffer)); } else { pending_spi_command = SPI_SEND_CLEAR; From 94aa0c678097a048ced28a07d85ed9cb36b0fb38 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 2 May 2017 13:41:14 +1000 Subject: [PATCH 068/169] Fix packet end detection 0xDE 0xEF detection was causing errors in MASTER -> SLAVE packet receive --- ZodiacFX/src/stacking.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 15e35f2..4562fb0 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -72,7 +72,7 @@ struct spi_port_stats spi_p_stats; uint8_t spi_stats_rr = 0; uint8_t spi_stats_buffer[sizeof(struct spi_port_stats)]; struct spi_packet *spi_packet; -bool end_receive; +bool end_check; uint8_t spi_receive_port = 0; uint16_t spi_receive_count; @@ -461,20 +461,34 @@ void SPI_Handler(void) // Check if this is an end marker if (data == 0xde) { - end_receive = true; - } else if (data == 0xef && end_receive == true) + end_check = true; + return; + } + else if (end_check == true) { - if (spi_receive_port == 255) + if(data == 0xef) { - gmac_write(&shared_buffer, spi_receive_count, OFPP13_FLOOD, 0); - } else{ - gmac_write(&shared_buffer, spi_receive_count, spi_receive_port-4, 0); + if (spi_receive_port == 255) + { + gmac_write(&shared_buffer, spi_receive_count, OFPP13_FLOOD, 0); + } else{ + gmac_write(&shared_buffer, spi_receive_count, spi_receive_port-4, 0); + } + pending_spi_command = SPI_SEND_CLEAR; + spi_receive_port = 0; + end_check = false; + spi_receive_count =0; + return; + } + else + { + shared_buffer[spi_receive_count] = 0xde; + spi_receive_count++; + shared_buffer[spi_receive_count] = data; + spi_receive_count++; + end_check = false; + return; } - pending_spi_command = SPI_SEND_CLEAR; - spi_receive_port = 0; - end_receive = false; - spi_receive_count =0; - return; } if (spi_receive_port == 0) From 933cd83e96acce200a74c9423412c3b66deccc1c Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 2 May 2017 16:27:34 +1000 Subject: [PATCH 069/169] Fix SPI packet header size check --- ZodiacFX/src/stacking.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 4562fb0..48860c2 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -281,14 +281,19 @@ void MasterStackRcv(void) uint16_t spi_read_size; uint32_t spi_crc_rcv; - for (int i = 0; i<6;i++) + for (int i = 0; i<7;i++) { spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); // Write 1 more byte to clean out buffer while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); if (i > 2) spi_read(SPI_MASTER_BASE, &shared_buffer[i-3], &uc_pcs); // skip for first 2 bytes } - if (shared_buffer[0] != 0xAB && shared_buffer[0] != 0xBC) return; + // Preamble must be 0xABAB or 0xBCBC + if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) + { + TRACE("stacking.c: ERROR - BAD SPI HEADER - PACKET DROPPED"); + return; + } spi_count = 4; spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); uint32_t rcv_time = sys_get_ms(); From 87e1d464fc3cf1acb89d8f04b4fb1e3a84130621 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 2 May 2017 17:11:53 +1000 Subject: [PATCH 070/169] Add error handling for spi read size Error will result in packet being dropped - needs to be fixed. --- ZodiacFX/src/stacking.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 48860c2..ee3993a 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -291,11 +291,16 @@ void MasterStackRcv(void) // Preamble must be 0xABAB or 0xBCBC if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) { - TRACE("stacking.c: ERROR - BAD SPI HEADER - PACKET DROPPED"); + TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE - PACKET DROPPED"); return; } spi_count = 4; spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); + if(spi_read_size > 1600) + { + TRACE("stacking.c: ERROR - BAD SPI HEADER READ SIZE - PACKET DROPPED"); + return; + } uint32_t rcv_time = sys_get_ms(); while(spi_count < spi_read_size) { From 342cc3cb6f6f939241d49f7b3b1b5eeff172bc1b Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 2 May 2017 18:24:04 +1000 Subject: [PATCH 071/169] Fix SPI packet CRC size 32-bit value required for large packets --- ZodiacFX/src/stacking.h | 2 +- ZodiacFX/src/switch.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 9fc4681..500316c 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -59,7 +59,7 @@ struct spi_packet { uint16_t premable; uint16_t spi_size; uint32_t ul_rcv_size; - uint16_t spi_crc; + uint32_t spi_crc; uint8_t tag; uint8_t pkt_buffer[GMAC_FRAME_LENTGH_MAX]; }; diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 08d1f92..5c479e4 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -595,7 +595,7 @@ void task_switch(struct netif *netif) spi_packet->spi_crc += gs_uc_eth_buffer[x]; } spi_packet->tag = tag + 4; - spi_packet->spi_size = 11 + ul_rcv_size; + spi_packet->spi_size = 13 + ul_rcv_size; memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet spi_slave_send_size = spi_packet->spi_size; From 66c7584989c558029c8f39d1a93e8cc9ba1bb00a Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 2 May 2017 18:25:57 +1000 Subject: [PATCH 072/169] Adjust SLAVE -> MASTER transmit process --- ZodiacFX/src/stacking.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index ee3993a..e5dea4d 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -304,11 +304,12 @@ void MasterStackRcv(void) uint32_t rcv_time = sys_get_ms(); while(spi_count < spi_read_size) { - for(volatile int x = 0;x Master %d", sys_get_ms() - rcv_time); @@ -438,6 +439,7 @@ void SPI_Handler(void) spi_slave_send_count--; // Wait for master to send the next byte while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); } } return; From 006f3903f578a48132528c7348fbc490daf3098e Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 5 May 2017 14:59:53 +1000 Subject: [PATCH 073/169] Modify stacking master->slave transmission handling --- ZodiacFX/src/stacking.c | 190 +++++++++++++++++++++++++++------------- 1 file changed, 129 insertions(+), 61 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index e5dea4d..6cbdc18 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -244,25 +244,25 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) // Write preamble spi_write(SPI_MASTER_BASE, 0xcd, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - for(volatile int x = 0;x Slave %d", sys_get_ms() - snd_time); @@ -281,74 +281,51 @@ void MasterStackRcv(void) uint16_t spi_read_size; uint32_t spi_crc_rcv; - for (int i = 0; i<7;i++) - { - spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); // Write 1 more byte to clean out buffer - while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - if (i > 2) spi_read(SPI_MASTER_BASE, &shared_buffer[i-3], &uc_pcs); // skip for first 2 bytes - } +// TEST ________________________________________________________________ + spi_read_size = 1600; + // ignore dummy bytes + spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); + while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); + while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - // Preamble must be 0xABAB or 0xBCBC - if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) - { - TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE - PACKET DROPPED"); - return; - } - spi_count = 4; - spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); - if(spi_read_size > 1600) - { - TRACE("stacking.c: ERROR - BAD SPI HEADER READ SIZE - PACKET DROPPED"); - return; - } uint32_t rcv_time = sys_get_ms(); + while(spi_count < spi_read_size) { spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); //for(volatile int x = 0;x 1600) + { + spi_read_size = 1600; + } + } + } spi_count++; while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); //TRACE("%x", shared_buffer[spi_count]); + } TRACE("stacking.c: ------- ------- Slave -> Master %d", sys_get_ms() - rcv_time); - if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) // Stats message + TRACE("stacking.c: MASTER received preamble - %x, %x", shared_buffer[0], shared_buffer[1]); + if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) { - TRACE("stacking.c: %d bytes of port stats data received from slave", spi_count); - memcpy(&spi_p_stats, &shared_buffer, sizeof(struct spi_port_stats)); - port_status[4] = spi_p_stats.port_status[0]; - port_status[5] = spi_p_stats.port_status[1]; - port_status[6] = spi_p_stats.port_status[2]; - port_status[7] = spi_p_stats.port_status[3]; - - if (OF_Version == 1) - { - phys10_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; - phys10_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; - phys10_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; - phys10_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; - phys10_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; - phys10_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; - phys10_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; - phys10_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; - } - - if (OF_Version == 4) - { - phys13_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; - phys13_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; - phys13_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; - phys13_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; - phys13_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; - phys13_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; - phys13_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; - phys13_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; - } + TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE"); + return; } - else if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) // packet + + if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) { - TRACE("stacking.c: %d bytes of packet data received from slave", spi_count); spi_crc_rcv = 0; spi_packet = &shared_buffer; if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) return; // Packet size is corrupt @@ -362,15 +339,106 @@ void MasterStackRcv(void) TRACE("stacking.c: Corrupt slave packet CRC mismatch %x != %x",spi_packet->spi_crc ,spi_crc_rcv); return; } + TRACE("stacking.c: received packet (%d bytes)", spi_packet->ul_rcv_size); memcpy(gs_uc_eth_buffer, &spi_packet->pkt_buffer, GMAC_FRAME_LENTGH_MAX); phys10_port_stats[spi_packet->tag-1].rx_packets++; phys13_port_stats[spi_packet->tag-1].rx_packets++; nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); - } else - { - TRACE("stacking.c: %d bytes of unknown data received from slave", spi_count); + return; } return; +// END TEST ________________________________________________________________ + + //for (int i = 0; i<7;i++) + //{ + //spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); // Write 1 more byte to clean out buffer + //while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + //if (i > 2) spi_read(SPI_MASTER_BASE, &shared_buffer[i-3], &uc_pcs); // skip for first 2 bytes + //} + // + //// Preamble must be 0xABAB or 0xBCBC + //if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) + //{ + //TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE - PACKET DROPPED"); + //return; + //} + //spi_count = 4; + //spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); + //if(spi_read_size > 1600) + //{ + //TRACE("stacking.c: ERROR - BAD SPI HEADER READ SIZE - PACKET DROPPED"); + //return; + //} + //uint32_t rcv_time = sys_get_ms(); + //while(spi_count < spi_read_size) + //{ + //spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + ////for(volatile int x = 0;x Master %d", sys_get_ms() - rcv_time); + // + //if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) // Stats message + //{ + //TRACE("stacking.c: %d bytes of port stats data received from slave", spi_count); + //memcpy(&spi_p_stats, &shared_buffer, sizeof(struct spi_port_stats)); + //port_status[4] = spi_p_stats.port_status[0]; + //port_status[5] = spi_p_stats.port_status[1]; + //port_status[6] = spi_p_stats.port_status[2]; + //port_status[7] = spi_p_stats.port_status[3]; + // + //if (OF_Version == 1) + //{ + //phys10_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; + //phys10_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; + //phys10_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; + //phys10_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; + //phys10_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; + //phys10_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; + //phys10_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; + //phys10_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; + //} +// + //if (OF_Version == 4) + //{ + //phys13_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; + //phys13_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; + //phys13_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; + //phys13_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; + //phys13_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; + //phys13_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; + //phys13_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; + //phys13_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; + //} + //} + //else if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) // packet + //{ + //TRACE("stacking.c: %d bytes of packet data received from slave", spi_count); + //spi_crc_rcv = 0; + //spi_packet = &shared_buffer; + //if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) return; // Packet size is corrupt + //for(int x = 0;xul_rcv_size;x++) + //{ + //spi_crc_rcv += spi_packet->pkt_buffer[x]; + //} + //// Make sure we received the entire packet + //if (spi_packet->spi_crc != spi_crc_rcv) + //{ + //TRACE("stacking.c: Corrupt slave packet CRC mismatch %x != %x",spi_packet->spi_crc ,spi_crc_rcv); + //return; + //} + //memcpy(gs_uc_eth_buffer, &spi_packet->pkt_buffer, GMAC_FRAME_LENTGH_MAX); + //phys10_port_stats[spi_packet->tag-1].rx_packets++; + //phys13_port_stats[spi_packet->tag-1].rx_packets++; + //nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); + //} else + //{ + //TRACE("stacking.c: %d bytes of unknown data received from slave", spi_count); + //} + //return; } /* From cc36eb5aaa5ef781a58ed7cebee4899cf9ee271d Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 5 May 2017 18:32:08 +1000 Subject: [PATCH 074/169] Add descriptions for spi packet struct --- ZodiacFX/src/stacking.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 500316c..5107044 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -56,11 +56,11 @@ struct spi_port_stats { }; struct spi_packet { - uint16_t premable; - uint16_t spi_size; - uint32_t ul_rcv_size; - uint32_t spi_crc; - uint8_t tag; + uint16_t premable; // Transmission preamble + uint16_t spi_size; // SPI transmission size + uint32_t ul_rcv_size; // Actual packet size + uint32_t spi_crc; // Calculated CRC of packet + uint8_t tag; // Port number (1-8, or 255) uint8_t pkt_buffer[GMAC_FRAME_LENTGH_MAX]; }; From 40265a1a8fc6ca690ecedcaaef23659bd583e3bb Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 5 May 2017 18:32:18 +1000 Subject: [PATCH 075/169] Add SPI_HEADER_SIZE definition --- ZodiacFX/src/stacking.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 5107044..b1f9224 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -43,6 +43,7 @@ #define SPI_STATS_PREAMBLE 0xABAB #define SPI_PACKET_PREAMBLE 0xBCBC #define SPI_SEND_WAIT 500 +#define SPI_HEADER_SIZE 13 struct spi_port_stats { uint16_t premable; From 3c40eeb7da0a3b77f1530f0346e362bb88540699 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 5 May 2017 18:33:02 +1000 Subject: [PATCH 076/169] Adjust spi size calculation --- ZodiacFX/src/switch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 5c479e4..6f8249a 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -350,7 +350,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) if(masterselect == false) // If we are the master then send to the slave { TRACE("switch13.c: Sending packet to slave to send out port %d (%d bytes)", port, ul_size); - MasterStackSend(p_buffer, ul_size, port); // Send it slave + MasterStackSend(p_buffer, ul_size, port); // Send it to slave return; } // If slave then write to port @@ -595,7 +595,7 @@ void task_switch(struct netif *netif) spi_packet->spi_crc += gs_uc_eth_buffer[x]; } spi_packet->tag = tag + 4; - spi_packet->spi_size = 13 + ul_rcv_size; + spi_packet->spi_size = SPI_HEADER_SIZE + ul_rcv_size; memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet spi_slave_send_size = spi_packet->spi_size; From 95ee398eb9bdf732cf0152047a1a22bfaa7e4714 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 5 May 2017 18:33:11 +1000 Subject: [PATCH 077/169] Re-enable TRACE --- ZodiacFX/src/trace.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/trace.h b/ZodiacFX/src/trace.h index 1ae4861..d831a3d 100644 --- a/ZodiacFX/src/trace.h +++ b/ZodiacFX/src/trace.h @@ -1,5 +1,5 @@ extern bool trace; -//#define TRACE(fmt, ...) if (trace) { printf(fmt "\r\n", ## __VA_ARGS__); } +#define TRACE(fmt, ...) if (trace) { printf(fmt "\r\n", ## __VA_ARGS__); } // build with this instead, to disable trace for performance. -#define TRACE(...) ; +//#define TRACE(...) ; From 96ee3bf735c4aa74c67d8de066f005c76bddce0c Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 5 May 2017 18:45:56 +1000 Subject: [PATCH 078/169] Add SLAVE -> MASTER test pattern --- ZodiacFX/src/stacking.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 6cbdc18..6ae2c08 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -159,6 +159,30 @@ void Slave_timer(void) { spi_port_status(); timer_alt = 2; + // ***** Generate SLAVE -> MASTER test pattern ***** + if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) + { + // PREPARE TEST PACKET from SLAVE to MASTER + spi_packet = &shared_buffer; + spi_packet->premable = SPI_PACKET_PREAMBLE; + spi_packet->ul_rcv_size = 1400; + spi_packet->spi_crc = 0; + uint8_t*ind_ptr = &spi_packet->pkt_buffer; + uint8_t walk = 0; + for(uint16_t x = 0;x<1400;x++) + { + ind_ptr[x] = walk; + spi_packet->spi_crc += walk; + walk++; + } + spi_packet->tag = 2 + 4; + spi_packet->spi_size = SPI_HEADER_SIZE + 1400; + pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet + spi_slave_send_size = spi_packet->spi_size; + spi_slave_send_count = spi_slave_send_size; + ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something + } + // ***** END ***** return; } else if (timer_alt == 2) { @@ -579,6 +603,7 @@ void SPI_Handler(void) shared_buffer[spi_receive_count] = data; spi_receive_count++; + //spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); } } \ No newline at end of file From 8cda2a59a929b55a969a756266dfb3ac226a0cce Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 5 May 2017 18:47:00 +1000 Subject: [PATCH 079/169] Add MASTER -> SLAVE test pattern --- ZodiacFX/src/openflow/of_helper.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index afddfe7..7bc6224 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -66,6 +66,12 @@ extern uint8_t *ofp13_oxm_inst[MAX_FLOWS_13]; extern uint16_t ofp13_oxm_inst_size[MAX_FLOWS_13]; extern uint8_t total_ports; +// ***** Support for SPI test pattern ***** +uint8_t test_pattern(void); +extern void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port); +extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; +// ***** END ***** + // Local Variables uint8_t timer_alt; static uint16_t VLAN_VID_MASK = 0x0fff; @@ -148,6 +154,10 @@ void nnOF_timer(void) } timer_alt = 2; } else if (timer_alt == 2){ + // ***** Generate SPI MASTER -> SLAVE test pattern ***** + test_pattern(); + MasterStackSend(&shared_buffer, 1400, 8); + // ***** END ***** flow_timeouts(); timer_alt = 0; } @@ -1441,3 +1451,15 @@ uint32_t get_bound_flows(uint32_t id) return count; } + +// ***** Generate SPI test pattern ***** +uint8_t test_pattern(void) +{ + uint8_t pattern = 0; + for(uint16_t i=0;i<1400;i++) + { + shared_buffer[i] = pattern++; + } + return; +} +// ***** END ***** From 15880367fe42b77d483be7921261d50ded1be09f Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 5 May 2017 22:52:37 +1000 Subject: [PATCH 080/169] Comment out SLAVE -> MASTER test pattern --- ZodiacFX/src/stacking.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 6ae2c08..b3f31a7 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -182,6 +182,28 @@ void Slave_timer(void) spi_slave_send_count = spi_slave_send_size; ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something } + //if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) + //{ + //// PREPARE TEST PACKET from SLAVE to MASTER + //spi_packet = &shared_buffer; + //spi_packet->premable = SPI_PACKET_PREAMBLE; + //spi_packet->ul_rcv_size = 1400; + //spi_packet->spi_crc = 0; + //uint8_t*ind_ptr = &spi_packet->pkt_buffer; + //uint8_t walk = 0; + //for(uint16_t x = 0;x<1400;x++) + //{ + //ind_ptr[x] = walk; + //spi_packet->spi_crc += walk; + //walk++; + //} + //spi_packet->tag = 2 + 4; + //spi_packet->spi_size = SPI_HEADER_SIZE + 1400; + //pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet + //spi_slave_send_size = spi_packet->spi_size; + //spi_slave_send_count = spi_slave_send_size; + //ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something + //} // ***** END ***** return; } else if (timer_alt == 2) From 563a6d96c288e5d463cda4f982b9a4c1c13e78ae Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 5 May 2017 22:56:06 +1000 Subject: [PATCH 081/169] Remove previous SLAVE -> MASTER test pattern Intended to be a part of the previous commit --- ZodiacFX/src/stacking.c | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index b3f31a7..366a8e2 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -160,28 +160,6 @@ void Slave_timer(void) spi_port_status(); timer_alt = 2; // ***** Generate SLAVE -> MASTER test pattern ***** - if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) - { - // PREPARE TEST PACKET from SLAVE to MASTER - spi_packet = &shared_buffer; - spi_packet->premable = SPI_PACKET_PREAMBLE; - spi_packet->ul_rcv_size = 1400; - spi_packet->spi_crc = 0; - uint8_t*ind_ptr = &spi_packet->pkt_buffer; - uint8_t walk = 0; - for(uint16_t x = 0;x<1400;x++) - { - ind_ptr[x] = walk; - spi_packet->spi_crc += walk; - walk++; - } - spi_packet->tag = 2 + 4; - spi_packet->spi_size = SPI_HEADER_SIZE + 1400; - pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet - spi_slave_send_size = spi_packet->spi_size; - spi_slave_send_count = spi_slave_send_size; - ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something - } //if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) //{ //// PREPARE TEST PACKET from SLAVE to MASTER From c7b7874c86e311de3abd075b31e88385ab8b77ec Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 5 May 2017 23:00:25 +1000 Subject: [PATCH 082/169] Modify MASTER -> SLAVE to use spi packet header --- ZodiacFX/src/stacking.c | 45 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 366a8e2..36d1d1c 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -243,9 +243,10 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) uint8_t uc_pcs; static uint16_t data; uint8_t *p_buffer; - p_buffer = p_uc_data; uint8_t outport; + uint8_t spi_head_buffer[SPI_HEADER_SIZE] = {0}; + if (port < 255) { outport = port; @@ -263,6 +264,48 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) if (port_status[7] == 1) phys13_port_stats[7].tx_packets++; } + // ***** Prepare packet to send from MASTER to SLAVE ***** + // ***** TODO: check if packet statistics need to be updated at this point ***** + //phys10_port_stats[tag-1].rx_packets++; + //phys13_port_stats[tag-1].rx_packets++; + // Prepare header (shared_buffer already contains the packet data) + spi_packet = &spi_head_buffer; + spi_packet->premable = SPI_PACKET_PREAMBLE; + spi_packet->ul_rcv_size = ul_size; + spi_packet->spi_crc = 0; + for(int x = 0;xspi_crc += p_uc_data[x]; + } + spi_packet->tag = port; + spi_packet->spi_size = SPI_HEADER_SIZE + ul_size; + + TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); + TRACE("stacking.c: ------- ------- Master -> Slave"); + + // Send a dummy byte + //spi_write(SPI_MASTER_BASE, 0xff, 0, 0); + + // Send the SPI packet header + for(uint16_t ct=0; ct SLAVE method - this will never run in the current implementation ***** TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); uint32_t snd_time = sys_get_ms(); // Write preamble From 8a361ca552792283a1a6c6082f24f0bbfdfc5dfa Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 5 May 2017 23:13:29 +1000 Subject: [PATCH 083/169] Clean up error messages and comments --- ZodiacFX/src/stacking.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 36d1d1c..d9e37cd 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -49,7 +49,7 @@ static uint32_t gs_ul_spi_clock = 2000000; /* Delay before SPCK. */ #define SPI_DLYBS 0x40 /* Delay between consecutive transfers. */ -#define SPI_DLYBCT 0x10 +#define SPI_DLYBCT 0x10//0x10 // Global variables extern uint8_t last_port_status[8]; @@ -348,7 +348,7 @@ void MasterStackRcv(void) uint16_t spi_read_size; uint32_t spi_crc_rcv; -// TEST ________________________________________________________________ + // ***** Modified SLAVE -> MASTER receive ***** spi_read_size = 1600; // ignore dummy bytes spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); @@ -379,8 +379,6 @@ void MasterStackRcv(void) } spi_count++; while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - //TRACE("%x", shared_buffer[spi_count]); - } TRACE("stacking.c: ------- ------- Slave -> Master %d", sys_get_ms() - rcv_time); @@ -395,7 +393,11 @@ void MasterStackRcv(void) { spi_crc_rcv = 0; spi_packet = &shared_buffer; - if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) return; // Packet size is corrupt + if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) + { + TRACE("stacking.c: ERROR - BAD PACKET SIZE"); + return; // Packet size is corrupt + } for(int x = 0;xul_rcv_size;x++) { spi_crc_rcv += spi_packet->pkt_buffer[x]; @@ -414,7 +416,9 @@ void MasterStackRcv(void) return; } return; -// END TEST ________________________________________________________________ + // ***** END ***** + + // ***** Previous implementation below - port stats needs to be re-implemented //for (int i = 0; i<7;i++) //{ @@ -560,7 +564,7 @@ void SPI_Handler(void) // Flush out last two bytes if (spi_dummy_bytes < 2) { - spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); + spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); // ***** spi_dummy_bytes++; return; } From 32eb21f991ca3d744a0dd21b3d4e5470ee2babc5 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 5 May 2017 23:24:49 +1000 Subject: [PATCH 084/169] Modify MASTER -> SLAVE receive handling --- ZodiacFX/src/stacking.c | 114 ++++++++++++++++++++++------------------ 1 file changed, 62 insertions(+), 52 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index d9e37cd..8cdc372 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -586,71 +586,81 @@ void SPI_Handler(void) if(pending_spi_command == SPI_SEND_CLEAR) { + // ***** Modified MASTER -> SLAVE receiver ***** + uint16_t spi_count = 0; + uint16_t spi_read_size = 1600; + + // Discard dummy byte (attempts to prevent unwanted bytes before first proper read) + spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xcd) pending_spi_command = SPI_RCV_PREAMBLE; - // START PROCESSING - return; - } - - if(pending_spi_command == SPI_RCV_PREAMBLE) - { + spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xcd) + + // Testing - additional preamble read detection (i.e. detect 0xBC 0xBC SPI header preamble before main loop) + //spi_read(SPI_SLAVE_BASE, &shared_buffer[spi_count], &uc_pcs); + //spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); + //spi_count++; + //spi_read(SPI_SLAVE_BASE, &shared_buffer[spi_count], &uc_pcs); + //spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); + //spi_count++; + + while(spi_count < spi_read_size) { - pending_spi_command = SPI_RECEIVE; - receive_timeout = sys_get_ms(); - memset(&shared_buffer,0,sizeof(shared_buffer)); - } else { - pending_spi_command = SPI_SEND_CLEAR; + spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_SLAVE_BASE, &shared_buffer[spi_count], &uc_pcs); + // (processing may cause timing problems - none found during testing) + if(spi_read_size == 1600) + { + if(spi_count == 3) + { + spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); + if(spi_read_size > 1600) + { + spi_read_size = 1600; + } + } + } + spi_count++; } - return; - } - if(pending_spi_command == SPI_RECEIVE) - { - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - // Check if this is an end marker - if (data == 0xde) + uint32_t spi_crc_rcv = 0; + spi_packet = &shared_buffer; + + // Check that the preamble is as expected + if (!(shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC)) { - end_check = true; return; } - else if (end_check == true) + + // Check against maximum packet size + if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) { - if(data == 0xef) - { - if (spi_receive_port == 255) - { - gmac_write(&shared_buffer, spi_receive_count, OFPP13_FLOOD, 0); - } else{ - gmac_write(&shared_buffer, spi_receive_count, spi_receive_port-4, 0); - } - pending_spi_command = SPI_SEND_CLEAR; - spi_receive_port = 0; - end_check = false; - spi_receive_count =0; - return; - } - else - { - shared_buffer[spi_receive_count] = 0xde; - spi_receive_count++; - shared_buffer[spi_receive_count] = data; - spi_receive_count++; - end_check = false; - return; - } + return; + } + + // Calculated CRC of the received data + for(uint16_t ct=0; ctul_rcv_size; ct++) + { + spi_crc_rcv += spi_packet->pkt_buffer[ct]; } - - if (spi_receive_port == 0) + + // Check calculated CRC against received CRC + if (spi_packet->spi_crc != spi_crc_rcv) { - spi_receive_port = data; return; } - shared_buffer[spi_receive_count] = data; - spi_receive_count++; - //spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + if (spi_packet->tag == 255) + { + gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, OFPP13_FLOOD, 0); + } + else if (spi_packet->tag <= 8) + { + gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, spi_packet->tag-4, 0); + } + return; + + // ***** END ***** } - } \ No newline at end of file From d897df84e35d2d04b8b1138cb4def9aa8e0ea6e2 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 5 May 2017 23:25:08 +1000 Subject: [PATCH 085/169] Set SPI_SEND_WAIT to 0 Needs to be removed in the future --- ZodiacFX/src/stacking.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index b1f9224..a772679 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -42,7 +42,7 @@ #define SPI_RCV_PREAMBLE 4 #define SPI_STATS_PREAMBLE 0xABAB #define SPI_PACKET_PREAMBLE 0xBCBC -#define SPI_SEND_WAIT 500 +#define SPI_SEND_WAIT 0 #define SPI_HEADER_SIZE 13 struct spi_port_stats { From 344f2e01c978957155d37bdce614df2172f1450d Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Sun, 7 May 2017 15:02:29 +1000 Subject: [PATCH 086/169] Revert "Stacking Changes" --- ZodiacFX/src/command.c | 2 + ZodiacFX/src/http.c | 22 +- ZodiacFX/src/openflow/of_helper.c | 22 -- ZodiacFX/src/stacking.c | 387 ++++++++---------------------- ZodiacFX/src/stacking.h | 13 +- ZodiacFX/src/switch.c | 5 +- ZodiacFX/src/trace.h | 4 +- 7 files changed, 112 insertions(+), 343 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index 7e8f433..c51836c 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -559,6 +559,8 @@ void command_config(char *command, char *param1, char *param2, char *param3) } else { printf(" Force OpenFlow version: Disabled\r\n"); } + if (masterselect == true) printf(" Stacking Select: SLAVE\r\n"); + if (masterselect == false) printf(" Stacking Select: MASTER\r\n"); if (stackenabled == true) printf(" Stacking Status: Enabled\r\n"); if (stackenabled == false) printf(" Stacking Status: Disabled\r\n"); if (Zodiac_Config.ethtype_filter == 1) printf(" EtherType Filtering: Enabled\r\n"); diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 3e0a9f6..1968743 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -91,8 +91,6 @@ static bool restart_required = false; // Track if any configuration changes are static bool file_upload = false; // Multi-part firmware file upload flag static bool post_pending = false; -extern bool stackenabled; - static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err); static err_t http_accept(void *arg, struct tcp_pcb *pcb, err_t err); void http_send(char *buffer, struct tcp_pcb *pcb, bool out); @@ -2085,8 +2083,6 @@ static uint8_t interfaceCreate_Home(void) int hr = (totaltime/2)/3600; int t = (totaltime/2)%3600; int min = t/60; - - sprintf(shared_buffer, http_header); @@ -2098,7 +2094,7 @@ static uint8_t interfaceCreate_Home(void) ""\ ""\ ""\ @@ -2107,21 +2103,7 @@ static uint8_t interfaceCreate_Home(void) "CPU UID: %d-%d-%d-%d
"\ "Firmware Version: %s
"\ "CPU Temp: %d C
"\ - "Uptime: %02d:%02d
"\ - ); - if(stackenabled == true) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "Stacking: enabled" - ); - } - else - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "Stacking: disabled" - ); - } - if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + "Uptime: %02d:%02d"\ "

"\ ""\ ""\ diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index 7bc6224..afddfe7 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -66,12 +66,6 @@ extern uint8_t *ofp13_oxm_inst[MAX_FLOWS_13]; extern uint16_t ofp13_oxm_inst_size[MAX_FLOWS_13]; extern uint8_t total_ports; -// ***** Support for SPI test pattern ***** -uint8_t test_pattern(void); -extern void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port); -extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; -// ***** END ***** - // Local Variables uint8_t timer_alt; static uint16_t VLAN_VID_MASK = 0x0fff; @@ -154,10 +148,6 @@ void nnOF_timer(void) } timer_alt = 2; } else if (timer_alt == 2){ - // ***** Generate SPI MASTER -> SLAVE test pattern ***** - test_pattern(); - MasterStackSend(&shared_buffer, 1400, 8); - // ***** END ***** flow_timeouts(); timer_alt = 0; } @@ -1451,15 +1441,3 @@ uint32_t get_bound_flows(uint32_t id) return count; } - -// ***** Generate SPI test pattern ***** -uint8_t test_pattern(void) -{ - uint8_t pattern = 0; - for(uint16_t i=0;i<1400;i++) - { - shared_buffer[i] = pattern++; - } - return; -} -// ***** END ***** diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 8cdc372..251814f 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -34,7 +34,6 @@ #include "switch.h" #include "lwip/def.h" #include "openflow/openflow.h" -#include "timers.h" /* SPI clock setting (Hz). */ static uint32_t gs_ul_spi_clock = 2000000; @@ -49,7 +48,7 @@ static uint32_t gs_ul_spi_clock = 2000000; /* Delay before SPCK. */ #define SPI_DLYBS 0x40 /* Delay between consecutive transfers. */ -#define SPI_DLYBCT 0x10//0x10 +#define SPI_DLYBCT 0x10 // Global variables extern uint8_t last_port_status[8]; @@ -72,7 +71,7 @@ struct spi_port_stats spi_p_stats; uint8_t spi_stats_rr = 0; uint8_t spi_stats_buffer[sizeof(struct spi_port_stats)]; struct spi_packet *spi_packet; -bool end_check; +bool end_receive; uint8_t spi_receive_port = 0; uint16_t spi_receive_count; @@ -159,30 +158,6 @@ void Slave_timer(void) { spi_port_status(); timer_alt = 2; - // ***** Generate SLAVE -> MASTER test pattern ***** - //if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) - //{ - //// PREPARE TEST PACKET from SLAVE to MASTER - //spi_packet = &shared_buffer; - //spi_packet->premable = SPI_PACKET_PREAMBLE; - //spi_packet->ul_rcv_size = 1400; - //spi_packet->spi_crc = 0; - //uint8_t*ind_ptr = &spi_packet->pkt_buffer; - //uint8_t walk = 0; - //for(uint16_t x = 0;x<1400;x++) - //{ - //ind_ptr[x] = walk; - //spi_packet->spi_crc += walk; - //walk++; - //} - //spi_packet->tag = 2 + 4; - //spi_packet->spi_size = SPI_HEADER_SIZE + 1400; - //pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet - //spi_slave_send_size = spi_packet->spi_size; - //spi_slave_send_count = spi_slave_send_size; - //ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something - //} - // ***** END ***** return; } else if (timer_alt == 2) { @@ -243,10 +218,9 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) uint8_t uc_pcs; static uint16_t data; uint8_t *p_buffer; + p_buffer = p_uc_data; uint8_t outport; - uint8_t spi_head_buffer[SPI_HEADER_SIZE] = {0}; - if (port < 255) { outport = port; @@ -264,75 +238,30 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) if (port_status[7] == 1) phys13_port_stats[7].tx_packets++; } - // ***** Prepare packet to send from MASTER to SLAVE ***** - // ***** TODO: check if packet statistics need to be updated at this point ***** - //phys10_port_stats[tag-1].rx_packets++; - //phys13_port_stats[tag-1].rx_packets++; - // Prepare header (shared_buffer already contains the packet data) - spi_packet = &spi_head_buffer; - spi_packet->premable = SPI_PACKET_PREAMBLE; - spi_packet->ul_rcv_size = ul_size; - spi_packet->spi_crc = 0; - for(int x = 0;xspi_crc += p_uc_data[x]; - } - spi_packet->tag = port; - spi_packet->spi_size = SPI_HEADER_SIZE + ul_size; - - TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); - TRACE("stacking.c: ------- ------- Master -> Slave"); - - // Send a dummy byte - //spi_write(SPI_MASTER_BASE, 0xff, 0, 0); - - // Send the SPI packet header - for(uint16_t ct=0; ct SLAVE method - this will never run in the current implementation ***** TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); - uint32_t snd_time = sys_get_ms(); // Write preamble spi_write(SPI_MASTER_BASE, 0xcd, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - //for(volatile int x = 0;x Slave %d", sys_get_ms() - snd_time); return; } @@ -348,56 +277,64 @@ void MasterStackRcv(void) uint16_t spi_read_size; uint32_t spi_crc_rcv; - // ***** Modified SLAVE -> MASTER receive ***** - spi_read_size = 1600; - // ignore dummy bytes - spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); - spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); - while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); - spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); - while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - - uint32_t rcv_time = sys_get_ms(); + for (int i = 0; i<6;i++) + { + spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); // Write 1 more byte to clean out buffer + while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + if (i > 2) spi_read(SPI_MASTER_BASE, &shared_buffer[i-3], &uc_pcs); // skip for first 2 bytes + } + if (shared_buffer[0] != 0xAB && shared_buffer[0] != 0xBC) return; + spi_count = 4; + spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); while(spi_count < spi_read_size) { - spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); - //for(volatile int x = 0;x 1600) - { - spi_read_size = 1600; - } - } - } - spi_count++; while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + spi_count++; } - TRACE("stacking.c: ------- ------- Slave -> Master %d", sys_get_ms() - rcv_time); - TRACE("stacking.c: MASTER received preamble - %x, %x", shared_buffer[0], shared_buffer[1]); - if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) + if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) // Stats message { - TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE"); - return; + TRACE("stacking.c: %d bytes of port stats data received from slave", spi_count); + memcpy(&spi_p_stats, &shared_buffer, sizeof(struct spi_port_stats)); + port_status[4] = spi_p_stats.port_status[0]; + port_status[5] = spi_p_stats.port_status[1]; + port_status[6] = spi_p_stats.port_status[2]; + port_status[7] = spi_p_stats.port_status[3]; + + if (OF_Version == 1) + { + phys10_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; + phys10_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; + phys10_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; + phys10_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; + phys10_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; + phys10_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; + phys10_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; + phys10_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; + } + + if (OF_Version == 4) + { + phys13_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; + phys13_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; + phys13_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; + phys13_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; + phys13_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; + phys13_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; + phys13_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; + phys13_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; + } } - - if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) + else if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) // packet { + TRACE("stacking.c: %d bytes of packet data received from slave", spi_count); spi_crc_rcv = 0; spi_packet = &shared_buffer; - if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) - { - TRACE("stacking.c: ERROR - BAD PACKET SIZE"); - return; // Packet size is corrupt - } + if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) return; // Packet size is corrupt for(int x = 0;xul_rcv_size;x++) { spi_crc_rcv += spi_packet->pkt_buffer[x]; @@ -408,108 +345,15 @@ void MasterStackRcv(void) TRACE("stacking.c: Corrupt slave packet CRC mismatch %x != %x",spi_packet->spi_crc ,spi_crc_rcv); return; } - TRACE("stacking.c: received packet (%d bytes)", spi_packet->ul_rcv_size); memcpy(gs_uc_eth_buffer, &spi_packet->pkt_buffer, GMAC_FRAME_LENTGH_MAX); phys10_port_stats[spi_packet->tag-1].rx_packets++; phys13_port_stats[spi_packet->tag-1].rx_packets++; nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); - return; + } else + { + TRACE("stacking.c: %d bytes of unknown data received from slave", spi_count); } return; - // ***** END ***** - - // ***** Previous implementation below - port stats needs to be re-implemented - - //for (int i = 0; i<7;i++) - //{ - //spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); // Write 1 more byte to clean out buffer - //while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - //if (i > 2) spi_read(SPI_MASTER_BASE, &shared_buffer[i-3], &uc_pcs); // skip for first 2 bytes - //} - // - //// Preamble must be 0xABAB or 0xBCBC - //if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) - //{ - //TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE - PACKET DROPPED"); - //return; - //} - //spi_count = 4; - //spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); - //if(spi_read_size > 1600) - //{ - //TRACE("stacking.c: ERROR - BAD SPI HEADER READ SIZE - PACKET DROPPED"); - //return; - //} - //uint32_t rcv_time = sys_get_ms(); - //while(spi_count < spi_read_size) - //{ - //spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); - ////for(volatile int x = 0;x Master %d", sys_get_ms() - rcv_time); - // - //if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) // Stats message - //{ - //TRACE("stacking.c: %d bytes of port stats data received from slave", spi_count); - //memcpy(&spi_p_stats, &shared_buffer, sizeof(struct spi_port_stats)); - //port_status[4] = spi_p_stats.port_status[0]; - //port_status[5] = spi_p_stats.port_status[1]; - //port_status[6] = spi_p_stats.port_status[2]; - //port_status[7] = spi_p_stats.port_status[3]; - // - //if (OF_Version == 1) - //{ - //phys10_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; - //phys10_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; - //phys10_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; - //phys10_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; - //phys10_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; - //phys10_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; - //phys10_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; - //phys10_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; - //} -// - //if (OF_Version == 4) - //{ - //phys13_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; - //phys13_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; - //phys13_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; - //phys13_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; - //phys13_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; - //phys13_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; - //phys13_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; - //phys13_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; - //} - //} - //else if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) // packet - //{ - //TRACE("stacking.c: %d bytes of packet data received from slave", spi_count); - //spi_crc_rcv = 0; - //spi_packet = &shared_buffer; - //if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) return; // Packet size is corrupt - //for(int x = 0;xul_rcv_size;x++) - //{ - //spi_crc_rcv += spi_packet->pkt_buffer[x]; - //} - //// Make sure we received the entire packet - //if (spi_packet->spi_crc != spi_crc_rcv) - //{ - //TRACE("stacking.c: Corrupt slave packet CRC mismatch %x != %x",spi_packet->spi_crc ,spi_crc_rcv); - //return; - //} - //memcpy(gs_uc_eth_buffer, &spi_packet->pkt_buffer, GMAC_FRAME_LENTGH_MAX); - //phys10_port_stats[spi_packet->tag-1].rx_packets++; - //phys13_port_stats[spi_packet->tag-1].rx_packets++; - //nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); - //} else - //{ - //TRACE("stacking.c: %d bytes of unknown data received from slave", spi_count); - //} - //return; } /* @@ -520,7 +364,6 @@ void MasterStackRcv(void) void SPI_Handler(void) { static uint16_t data; - static uint32_t receive_timeout = 0; // Timeout for SPI data receive (MASTER->SLAVE) uint8_t uc_pcs; if (slave_ready == false) // Is this the first data we have received? @@ -557,14 +400,13 @@ void SPI_Handler(void) return; } - if(pending_spi_command == SPI_SEND_PKT) // Send slave packet to master + if(pending_spi_command == SPI_SEND_PKT) // We send the master our port stats { if (spi_slave_send_count <= 0) { - // Flush out last two bytes if (spi_dummy_bytes < 2) { - spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); // ***** + spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); spi_dummy_bytes++; return; } @@ -572,95 +414,62 @@ void SPI_Handler(void) ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done spi_dummy_bytes = 0; } else { - while(spi_slave_send_count > 0) - { - spi_write(SPI_SLAVE_BASE, shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); - spi_slave_send_count--; - // Wait for master to send the next byte - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - } + spi_write(SPI_SLAVE_BASE, shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); + spi_slave_send_count--; } return; } if(pending_spi_command == SPI_SEND_CLEAR) { - // ***** Modified MASTER -> SLAVE receiver ***** - uint16_t spi_count = 0; - uint16_t spi_read_size = 1600; - - // Discard dummy byte (attempts to prevent unwanted bytes before first proper read) - spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); + if (data == 0xcd) pending_spi_command = SPI_RCV_PREAMBLE; + return; + } + + if(pending_spi_command == SPI_RCV_PREAMBLE) + { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - - // Testing - additional preamble read detection (i.e. detect 0xBC 0xBC SPI header preamble before main loop) - //spi_read(SPI_SLAVE_BASE, &shared_buffer[spi_count], &uc_pcs); - //spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); - //spi_count++; - //spi_read(SPI_SLAVE_BASE, &shared_buffer[spi_count], &uc_pcs); - //spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); - //spi_count++; - - while(spi_count < spi_read_size) + if (data == 0xcd) { - spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_SLAVE_BASE, &shared_buffer[spi_count], &uc_pcs); - // (processing may cause timing problems - none found during testing) - if(spi_read_size == 1600) - { - if(spi_count == 3) - { - spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); - if(spi_read_size > 1600) - { - spi_read_size = 1600; - } - } - } - spi_count++; + pending_spi_command = SPI_RECEIVE; + memset(&shared_buffer,0,sizeof(shared_buffer)); + } else { + pending_spi_command = SPI_SEND_CLEAR; } + return; + } - uint32_t spi_crc_rcv = 0; - spi_packet = &shared_buffer; - - // Check that the preamble is as expected - if (!(shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC)) + if(pending_spi_command == SPI_RECEIVE) + { + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + // Check if this is an end marker + if (data == 0xde) { - return; - } - - // Check against maximum packet size - if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) + end_receive = true; + } else if (data == 0xef && end_receive == true) { + if (spi_receive_port == 255) + { + gmac_write(&shared_buffer, spi_receive_count, OFPP13_FLOOD, 0); + } else{ + gmac_write(&shared_buffer, spi_receive_count, spi_receive_port-4, 0); + } + pending_spi_command = SPI_SEND_CLEAR; + spi_receive_port = 0; + end_receive = false; + spi_receive_count =0; return; } - - // Calculated CRC of the received data - for(uint16_t ct=0; ctul_rcv_size; ct++) - { - spi_crc_rcv += spi_packet->pkt_buffer[ct]; - } - - // Check calculated CRC against received CRC - if (spi_packet->spi_crc != spi_crc_rcv) + + if (spi_receive_port == 0) { + spi_receive_port = data; return; } - if (spi_packet->tag == 255) - { - gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, OFPP13_FLOOD, 0); - } - else if (spi_packet->tag <= 8) - { - gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, spi_packet->tag-4, 0); - } - return; - - // ***** END ***** + shared_buffer[spi_receive_count] = data; + spi_receive_count++; } + } \ No newline at end of file diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index a772679..9fc4681 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -42,8 +42,7 @@ #define SPI_RCV_PREAMBLE 4 #define SPI_STATS_PREAMBLE 0xABAB #define SPI_PACKET_PREAMBLE 0xBCBC -#define SPI_SEND_WAIT 0 -#define SPI_HEADER_SIZE 13 +#define SPI_SEND_WAIT 500 struct spi_port_stats { uint16_t premable; @@ -57,11 +56,11 @@ struct spi_port_stats { }; struct spi_packet { - uint16_t premable; // Transmission preamble - uint16_t spi_size; // SPI transmission size - uint32_t ul_rcv_size; // Actual packet size - uint32_t spi_crc; // Calculated CRC of packet - uint8_t tag; // Port number (1-8, or 255) + uint16_t premable; + uint16_t spi_size; + uint32_t ul_rcv_size; + uint16_t spi_crc; + uint8_t tag; uint8_t pkt_buffer[GMAC_FRAME_LENTGH_MAX]; }; diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 6f8249a..54d4559 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -350,7 +350,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) if(masterselect == false) // If we are the master then send to the slave { TRACE("switch13.c: Sending packet to slave to send out port %d (%d bytes)", port, ul_size); - MasterStackSend(p_buffer, ul_size, port); // Send it to slave + MasterStackSend(p_buffer, ul_size, port); // Send it slave return; } // If slave then write to port @@ -580,7 +580,6 @@ void task_switch(struct netif *netif) { if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) { - // Prepare packet to send from SLAVE to MASTER uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); uint8_t tag = *tail_tag + 1; phys10_port_stats[tag-1].rx_packets++; @@ -595,7 +594,7 @@ void task_switch(struct netif *netif) spi_packet->spi_crc += gs_uc_eth_buffer[x]; } spi_packet->tag = tag + 4; - spi_packet->spi_size = SPI_HEADER_SIZE + ul_rcv_size; + spi_packet->spi_size = 11 + ul_rcv_size; memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet spi_slave_send_size = spi_packet->spi_size; diff --git a/ZodiacFX/src/trace.h b/ZodiacFX/src/trace.h index d831a3d..1ae4861 100644 --- a/ZodiacFX/src/trace.h +++ b/ZodiacFX/src/trace.h @@ -1,5 +1,5 @@ extern bool trace; -#define TRACE(fmt, ...) if (trace) { printf(fmt "\r\n", ## __VA_ARGS__); } +//#define TRACE(fmt, ...) if (trace) { printf(fmt "\r\n", ## __VA_ARGS__); } // build with this instead, to disable trace for performance. -//#define TRACE(...) ; +#define TRACE(...) ; From edfb8b6b02749872f9b2e6f1b2416d0f2ba531b9 Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Sun, 7 May 2017 15:08:28 +1000 Subject: [PATCH 087/169] Stacking UI updates --- ZodiacFX/src/command.c | 2 -- ZodiacFX/src/http.c | 22 ++++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index c51836c..7e8f433 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -559,8 +559,6 @@ void command_config(char *command, char *param1, char *param2, char *param3) } else { printf(" Force OpenFlow version: Disabled\r\n"); } - if (masterselect == true) printf(" Stacking Select: SLAVE\r\n"); - if (masterselect == false) printf(" Stacking Select: MASTER\r\n"); if (stackenabled == true) printf(" Stacking Status: Enabled\r\n"); if (stackenabled == false) printf(" Stacking Status: Disabled\r\n"); if (Zodiac_Config.ethtype_filter == 1) printf(" EtherType Filtering: Enabled\r\n"); diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 1968743..3e0a9f6 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -91,6 +91,8 @@ static bool restart_required = false; // Track if any configuration changes are static bool file_upload = false; // Multi-part firmware file upload flag static bool post_pending = false; +extern bool stackenabled; + static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err); static err_t http_accept(void *arg, struct tcp_pcb *pcb, err_t err); void http_send(char *buffer, struct tcp_pcb *pcb, bool out); @@ -2083,6 +2085,8 @@ static uint8_t interfaceCreate_Home(void) int hr = (totaltime/2)/3600; int t = (totaltime/2)%3600; int min = t/60; + + sprintf(shared_buffer, http_header); @@ -2094,7 +2098,7 @@ static uint8_t interfaceCreate_Home(void) ""\ ""\ ""\ @@ -2103,7 +2107,21 @@ static uint8_t interfaceCreate_Home(void) "CPU UID: %d-%d-%d-%d
"\ "Firmware Version: %s
"\ "CPU Temp: %d C
"\ - "Uptime: %02d:%02d"\ + "Uptime: %02d:%02d
"\ + ); + if(stackenabled == true) + { + snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + "Stacking: enabled" + ); + } + else + { + snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ + "Stacking: disabled" + ); + } + if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ "

"\ ""\ ""\ From c67a3b9a15907f5e05a9b41b753adad7fb6c6420 Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Sun, 7 May 2017 15:14:49 +1000 Subject: [PATCH 088/169] Timing update --- ZodiacFX/src/stacking.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 9fc4681..6850532 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -42,7 +42,7 @@ #define SPI_RCV_PREAMBLE 4 #define SPI_STATS_PREAMBLE 0xABAB #define SPI_PACKET_PREAMBLE 0xBCBC -#define SPI_SEND_WAIT 500 +#define SPI_SEND_WAIT 100 struct spi_port_stats { uint16_t premable; From 8c3a40b5779c7fc3be8f3897073830cc9ab9a3f7 Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Wed, 10 May 2017 12:54:16 +1000 Subject: [PATCH 089/169] SPI Tuning --- ZodiacFX/src/openflow/openflow.c | 3 + ZodiacFX/src/stacking.c | 379 ++++++++++++++++++++++--------- ZodiacFX/src/stacking.h | 17 +- ZodiacFX/src/switch.c | 46 ++-- ZodiacFX/src/trace.h | 4 +- 5 files changed, 315 insertions(+), 134 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index 07cae39..999c384 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -39,12 +39,14 @@ #include "lwip/tcp.h" #include "lwip/err.h" #include "timers.h" +#include "stacking.h" // Global variables extern struct zodiac_config Zodiac_Config; extern uint8_t port_status[8]; extern struct ofp10_port_stats phys10_port_stats[8]; extern struct ofp13_port_stats phys13_port_stats[8]; +extern bool stackenabled; // Local Variables struct ofp_switch_config Switch_config; @@ -354,6 +356,7 @@ void task_openflow(void) { fast_of_timer = sys_get_ms(); nnOF_timer(); + if (stackenabled == true) masterslave_test(); if (heartbeat > (HB_INTERVAL * 2) && tcp_con_state == 1) //If we haven't heard anything from the controller for more then the heartbeat interval send an echo request { diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 251814f..cd599b0 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -23,7 +23,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - * Author: Paul Zanna + * Authors: Paul Zanna + * & Kristopher Chen * */ @@ -34,9 +35,10 @@ #include "switch.h" #include "lwip/def.h" #include "openflow/openflow.h" +#include "timers.h" /* SPI clock setting (Hz). */ -static uint32_t gs_ul_spi_clock = 2000000; +static uint32_t gs_ul_spi_clock = 120000000; /* Chip select. */ #define SPI_CHIP_SEL 0 @@ -46,7 +48,7 @@ static uint32_t gs_ul_spi_clock = 2000000; /* Clock phase. */ #define SPI_CLK_PHASE 0 /* Delay before SPCK. */ -#define SPI_DLYBS 0x40 +#define SPI_DLYBS 0x30 /* Delay between consecutive transfers. */ #define SPI_DLYBCT 0x10 @@ -71,14 +73,16 @@ struct spi_port_stats spi_p_stats; uint8_t spi_stats_rr = 0; uint8_t spi_stats_buffer[sizeof(struct spi_port_stats)]; struct spi_packet *spi_packet; -bool end_receive; +bool end_check; uint8_t spi_receive_port = 0; uint16_t spi_receive_count; +uint32_t rcv_time; void spi_master_initialize(void); void spi_slave_initialize(void); void spi_port_stats(void); void spi_port_status(void); +void SPI_Handler1(void); /* * Initialize the SPI interface to MASTER or SLAVE based on the stacking jumper @@ -129,6 +133,7 @@ void spi_slave_initialize(void) */ void spi_master_initialize(void) { + uint32_t ul_sysclk_div = sysclk_get_cpu_hz() / gs_ul_spi_clock; /* Configure an SPI peripheral. */ spi_enable_clock(SPI_MASTER_BASE); spi_disable(SPI_MASTER_BASE); @@ -140,7 +145,7 @@ void spi_master_initialize(void) spi_set_peripheral_chip_select_value(SPI_MASTER_BASE, SPI_CHIP_SEL); spi_set_transfer_delay(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_DLYBS, SPI_DLYBCT); spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT); - spi_set_baudrate_div(SPI_MASTER_BASE, SPI_CHIP_SEL, (sysclk_get_cpu_hz() / gs_ul_spi_clock)); + spi_set_baudrate_div(SPI_MASTER_BASE, SPI_CHIP_SEL, (ul_sysclk_div)); spi_set_clock_polarity(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY); spi_set_clock_phase(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE); @@ -161,15 +166,18 @@ void Slave_timer(void) return; } else if (timer_alt == 2) { - if(slave_ready == false || pending_spi_command != SPI_SEND_CLEAR) return; // Wait until the master acknowledges us before sending anything - spi_p_stats.premable = SPI_STATS_PREAMBLE; - spi_p_stats.spi_size = sizeof(struct spi_port_stats); - memcpy(&spi_stats_buffer, &spi_p_stats, sizeof(struct spi_port_stats)); - ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something - pending_spi_command = SPI_SEND_STATS; // We are waiting to send port stats - spi_slave_send_size = sizeof(struct spi_port_stats); - spi_slave_send_count = spi_slave_send_size; - timer_alt = 0; + // Send SLAVE port stats if SLAVE is in the clear state + if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) + { + spi_p_stats.premable = SPI_STATS_PREAMBLE; + spi_p_stats.spi_size = sizeof(struct spi_port_stats); + memcpy(&spi_stats_buffer, &spi_p_stats, sizeof(struct spi_port_stats)); + ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something + pending_spi_command = SPI_SEND_STATS; // We are waiting to send port stats + spi_slave_send_size = sizeof(struct spi_port_stats); + spi_slave_send_count = spi_slave_send_size; + timer_alt = 0; + } return; } } @@ -209,6 +217,8 @@ void MasterReady(void) return; } +// ##################### SPI MASTER Send and Receive Functions ##################### + /* * Master send function * @@ -218,9 +228,10 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) uint8_t uc_pcs; static uint16_t data; uint8_t *p_buffer; - p_buffer = p_uc_data; uint8_t outport; + uint8_t spi_head_buffer[SPI_HEADER_SIZE] = {0}; + if (port < 255) { outport = port; @@ -237,31 +248,36 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) if (port_status[7] == 1) phys10_port_stats[7].tx_packets++; if (port_status[7] == 1) phys13_port_stats[7].tx_packets++; } + // Prepare header (shared_buffer already contains the packet data) + spi_packet = &spi_head_buffer; + spi_packet->premable = SPI_PACKET_PREAMBLE; + spi_packet->ul_rcv_size = ul_size; + spi_packet->spi_crc = 0; + for(int x = 0;xspi_crc += p_uc_data[x]; + } + spi_packet->tag = port; + spi_packet->spi_size = SPI_HEADER_SIZE + ul_size; TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); - // Write preamble - spi_write(SPI_MASTER_BASE, 0xcd, 0, 0); - while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - for(int x = 0;x Slave"); - for (int i = 0; i < ul_size; i++) { - for(int x = 0;x 2) spi_read(SPI_MASTER_BASE, &shared_buffer[i-3], &uc_pcs); // skip for first 2 bytes - } + // ***** Modified SLAVE -> MASTER receive ***** + spi_read_size = 1600; + // ignore dummy bytes + spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); + while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); + while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - if (shared_buffer[0] != 0xAB && shared_buffer[0] != 0xBC) return; - spi_count = 4; - spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); while(spi_count < spi_read_size) { - for(int x = 0;x 1600) + { + spi_read_size = 1600; + } + } + } spi_count++; + while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); } + printf("stacking.c: ------- ------- Slave -> Master %d\r\n", sys_get_ms() - rcv_time); - if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) // Stats message + TRACE("stacking.c: MASTER received preamble - %x, %x", shared_buffer[0], shared_buffer[1]); + if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) + { + TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE"); + return; + } + + if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) + { + /* Process Received SPI Packet */ + spi_crc_rcv = 0; + spi_packet = &shared_buffer; + if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) + { + TRACE("stacking.c: ERROR - BAD PACKET SIZE"); + return; // Packet size is corrupt + } + for(int x = 0;xul_rcv_size;x++) + { + spi_crc_rcv += spi_packet->pkt_buffer[x]; + } + // Make sure we received the entire packet + if (spi_packet->spi_crc != spi_crc_rcv) + { + TRACE("stacking.c: Corrupt slave packet CRC mismatch %x != %x",spi_packet->spi_crc ,spi_crc_rcv); + return; + } + TRACE("stacking.c: received packet (%d bytes)", spi_packet->ul_rcv_size); + // Copy packet into Ethernet buffer + memcpy(gs_uc_eth_buffer, &spi_packet->pkt_buffer, GMAC_FRAME_LENTGH_MAX); + // Update port stats + phys10_port_stats[spi_packet->tag-1].rx_packets++; + phys13_port_stats[spi_packet->tag-1].rx_packets++; + // Send packet to OpenFlow table lookup function for processing + nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); + return; + } + else if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) { + /* Process Received Port Stats */ TRACE("stacking.c: %d bytes of port stats data received from slave", spi_count); memcpy(&spi_p_stats, &shared_buffer, sizeof(struct spi_port_stats)); port_status[4] = spi_p_stats.port_status[0]; @@ -316,8 +383,7 @@ void MasterStackRcv(void) phys10_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; phys10_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; } - - if (OF_Version == 4) + else if (OF_Version == 4) { phys13_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; phys13_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; @@ -329,32 +395,10 @@ void MasterStackRcv(void) phys13_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; } } - else if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) // packet - { - TRACE("stacking.c: %d bytes of packet data received from slave", spi_count); - spi_crc_rcv = 0; - spi_packet = &shared_buffer; - if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) return; // Packet size is corrupt - for(int x = 0;xul_rcv_size;x++) - { - spi_crc_rcv += spi_packet->pkt_buffer[x]; - } - // Make sure we received the entire packet - if (spi_packet->spi_crc != spi_crc_rcv) - { - TRACE("stacking.c: Corrupt slave packet CRC mismatch %x != %x",spi_packet->spi_crc ,spi_crc_rcv); - return; - } - memcpy(gs_uc_eth_buffer, &spi_packet->pkt_buffer, GMAC_FRAME_LENTGH_MAX); - phys10_port_stats[spi_packet->tag-1].rx_packets++; - phys13_port_stats[spi_packet->tag-1].rx_packets++; - nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); - } else - { - TRACE("stacking.c: %d bytes of unknown data received from slave", spi_count); - } return; } + +// ##################### SPI SLAVE Send and Receive Functions ##################### /* * SPI interface IRQ handler @@ -364,6 +408,7 @@ void MasterStackRcv(void) void SPI_Handler(void) { static uint16_t data; + static uint32_t receive_timeout = 0; // Timeout for SPI data receive (MASTER->SLAVE) uint8_t uc_pcs; if (slave_ready == false) // Is this the first data we have received? @@ -400,13 +445,14 @@ void SPI_Handler(void) return; } - if(pending_spi_command == SPI_SEND_PKT) // We send the master our port stats + if(pending_spi_command == SPI_SEND_PKT) // Send slave packet to master { if (spi_slave_send_count <= 0) { + // Flush out last two bytes if (spi_dummy_bytes < 2) { - spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); + spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); // ***** spi_dummy_bytes++; return; } @@ -414,8 +460,14 @@ void SPI_Handler(void) ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done spi_dummy_bytes = 0; } else { - spi_write(SPI_SLAVE_BASE, shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); - spi_slave_send_count--; + while(spi_slave_send_count > 0) + { + spi_write(SPI_SLAVE_BASE, shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); + spi_slave_send_count--; + // Wait for master to send the next byte + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + } } return; } @@ -423,53 +475,174 @@ void SPI_Handler(void) if(pending_spi_command == SPI_SEND_CLEAR) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xcd) pending_spi_command = SPI_RCV_PREAMBLE; + if (data == 0xBC) + { + pending_spi_command = SPI_RCV_PREAMBLE; + } return; } - + if(pending_spi_command == SPI_RCV_PREAMBLE) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xcd) + if (data == 0xBC) { pending_spi_command = SPI_RECEIVE; - memset(&shared_buffer,0,sizeof(shared_buffer)); - } else { + //memset(&shared_buffer,0,sizeof(shared_buffer)); // ***** + // Write preamble to SPI packet header + shared_buffer[0] = 0xBC; + shared_buffer[1] = 0xBC; + } + else + { pending_spi_command = SPI_SEND_CLEAR; } return; } - + if(pending_spi_command == SPI_RECEIVE) { - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - // Check if this is an end marker - if (data == 0xde) - { - end_receive = true; - } else if (data == 0xef && end_receive == true) + // ***** Modified MASTER -> SLAVE receiver ***** + static uint16_t spi_count = 2; + static uint16_t spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + + // Read next byte + spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_SLAVE_BASE, &shared_buffer[spi_count], &uc_pcs); + + if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 3) { - if (spi_receive_port == 255) + spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); + if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) { - gmac_write(&shared_buffer, spi_receive_count, OFPP13_FLOOD, 0); - } else{ - gmac_write(&shared_buffer, spi_receive_count, spi_receive_port-4, 0); + // ERROR: over-sized packet data + // Clean up and return + pending_spi_command = SPI_SEND_CLEAR; + spi_count = 2; + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + return; } - pending_spi_command = SPI_SEND_CLEAR; - spi_receive_port = 0; - end_receive = false; - spi_receive_count =0; + } + + // Check if more bytes need to be read + if(spi_count < (spi_read_size-1)) + { + // Wait for next interrupt + spi_count++; return; } + + uint32_t spi_crc_rcv = 0; + spi_packet = &shared_buffer; - if (spi_receive_port == 0) + // Check against maximum packet size + if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) + { + // ERROR: payload data too large + // Clean up and return + pending_spi_command = SPI_SEND_CLEAR; + spi_count = 2; + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + slavemaster_test(); + return; + } + + // Calculated CRC of the received data + for(uint16_t ct=0; ctul_rcv_size; ct++) + { + spi_crc_rcv += spi_packet->pkt_buffer[ct]; + } + + // Check calculated CRC against received CRC + if (spi_packet->spi_crc != spi_crc_rcv) { - spi_receive_port = data; + // ERROR: corrupt packet + // Clean up and return + pending_spi_command = SPI_SEND_CLEAR; + spi_count = 2; + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; return; } - shared_buffer[spi_receive_count] = data; - spi_receive_count++; + if (spi_packet->tag == 255) + { + gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, OFPP13_FLOOD, 0); + } + else if (spi_packet->tag <= 8) + { + gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, spi_packet->tag-4, 0); + } + // Packet receive complete + // Clean up and return + pending_spi_command = SPI_SEND_CLEAR; + spi_count = 2; + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + slavemaster_test(); + return; + + } + +} + + +void SPI_Handler1(void) +{ + static uint16_t spi_count = 0; + uint8_t uc_pcs; + + if((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_OVRES) == 0) + { + printf("overrun!\r\n"); + } + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_SLAVE_BASE, &shared_buffer[spi_count], &uc_pcs); + spi_count++; + if (spi_count > 2000) + { + printf("full!\r\n"); + spi_count = 0; } - +} + +// ##################### SPI Test Functions ##################### + +uint8_t masterslave_test(void) +{ + uint8_t pattern = 0; + for(uint16_t i=0;i<1400;i++) + { + shared_buffer[i] = pattern++; + } + rcv_time = sys_get_ms(); + MasterStackSend(&shared_buffer, 1400, 8); + return; +} + +uint8_t slavemaster_test(void) +{ + // Note: the pending check may need to be moved outside of the function call + if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) + { + // PREPARE TEST PACKET from SLAVE to MASTER + spi_packet = &shared_buffer; + spi_packet->premable = SPI_PACKET_PREAMBLE; + spi_packet->ul_rcv_size = 1400; + spi_packet->spi_crc = 0; + uint8_t*ind_ptr = &spi_packet->pkt_buffer; + uint8_t walk = 0; + for(uint16_t x = 0;x<1400;x++) + { + ind_ptr[x] = walk; + spi_packet->spi_crc += walk; + walk++; + } + spi_packet->tag = 2 + 4; + spi_packet->spi_size = SPI_HEADER_SIZE + 1400; + pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet + spi_slave_send_size = spi_packet->spi_size; + spi_slave_send_count = spi_slave_send_size; + ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something + } + return; } \ No newline at end of file diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 6850532..9396f4d 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -42,7 +42,8 @@ #define SPI_RCV_PREAMBLE 4 #define SPI_STATS_PREAMBLE 0xABAB #define SPI_PACKET_PREAMBLE 0xBCBC -#define SPI_SEND_WAIT 100 +#define SPI_SEND_WAIT 0 +#define SPI_HEADER_SIZE 13 struct spi_port_stats { uint16_t premable; @@ -56,11 +57,11 @@ struct spi_port_stats { }; struct spi_packet { - uint16_t premable; - uint16_t spi_size; - uint32_t ul_rcv_size; - uint16_t spi_crc; - uint8_t tag; + uint16_t premable; // Transmission preamble + uint16_t spi_size; // SPI transmission size + uint32_t ul_rcv_size; // Actual packet size + uint32_t spi_crc; // Calculated CRC of packet + uint8_t tag; // Port number (1-8, or 255) uint8_t pkt_buffer[GMAC_FRAME_LENTGH_MAX]; }; @@ -70,4 +71,8 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port); void MasterStackRcv(void); void Slave_timer(void); +// ***** Stacking Test Functions ***** +uint8_t masterslave_test(void); // Send pattern from master -> slave +uint8_t slavemaster_test(void); // Send pattern from slave -> master + #endif /* STACKING_H_ */ \ No newline at end of file diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 54d4559..f1471ac 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -327,7 +327,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) TRACE("switch.c: Packet out FLOOD (%d bytes)", ul_size); if(masterselect == false) { - MasterStackSend(p_buffer, ul_size, port); + //MasterStackSend(p_buffer, ul_size, port); // Send it slave if (inport < 5) { port = (15 - NativePortMatrix) - (1<<(inport-1)); @@ -350,7 +350,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) if(masterselect == false) // If we are the master then send to the slave { TRACE("switch13.c: Sending packet to slave to send out port %d (%d bytes)", port, ul_size); - MasterStackSend(p_buffer, ul_size, port); // Send it slave + //MasterStackSend(p_buffer, ul_size, port); // Send it slave return; } // If slave then write to port @@ -528,7 +528,7 @@ void task_switch(struct netif *netif) if((sys_get_ms() - slave_timer) > 500) // every 500 ms (0.5 secs) { slave_timer = sys_get_ms(); - Slave_timer(); // Slave timer + //Slave_timer(); // Slave timer } } @@ -580,26 +580,26 @@ void task_switch(struct netif *netif) { if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) { - uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); - uint8_t tag = *tail_tag + 1; - phys10_port_stats[tag-1].rx_packets++; - phys13_port_stats[tag-1].rx_packets++; - ul_rcv_size--; // remove the tail first - spi_packet = &shared_buffer; - spi_packet->premable = SPI_PACKET_PREAMBLE; - spi_packet->ul_rcv_size = ul_rcv_size; - spi_packet->spi_crc = 0; - for(int x = 0;xspi_crc += gs_uc_eth_buffer[x]; - } - spi_packet->tag = tag + 4; - spi_packet->spi_size = 11 + ul_rcv_size; - memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); - pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet - spi_slave_send_size = spi_packet->spi_size; - spi_slave_send_count = spi_slave_send_size; - ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something + //uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); + //uint8_t tag = *tail_tag + 1; + //phys10_port_stats[tag-1].rx_packets++; + //phys13_port_stats[tag-1].rx_packets++; + //ul_rcv_size--; // remove the tail first + //spi_packet = &shared_buffer; + //spi_packet->premable = SPI_PACKET_PREAMBLE; + //spi_packet->ul_rcv_size = ul_rcv_size; + //spi_packet->spi_crc = 0; + //for(int x = 0;xspi_crc += gs_uc_eth_buffer[x]; + //} + //spi_packet->tag = tag + 4; + //spi_packet->spi_size = 11 + ul_rcv_size; + //memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); + //pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet + //spi_slave_send_size = spi_packet->spi_size; + //spi_slave_send_count = spi_slave_send_size; + //ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something return; } } diff --git a/ZodiacFX/src/trace.h b/ZodiacFX/src/trace.h index 1ae4861..d831a3d 100644 --- a/ZodiacFX/src/trace.h +++ b/ZodiacFX/src/trace.h @@ -1,5 +1,5 @@ extern bool trace; -//#define TRACE(fmt, ...) if (trace) { printf(fmt "\r\n", ## __VA_ARGS__); } +#define TRACE(fmt, ...) if (trace) { printf(fmt "\r\n", ## __VA_ARGS__); } // build with this instead, to disable trace for performance. -#define TRACE(...) ; +//#define TRACE(...) ; From 0058800353e7560feef2f499ee582b1754f0dd92 Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Wed, 10 May 2017 16:32:28 +1000 Subject: [PATCH 090/169] SPI Cleanup --- ZodiacFX/src/main.c | 1 - ZodiacFX/src/stacking.c | 29 +++-------------------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c index 22528c5..6beb3bf 100644 --- a/ZodiacFX/src/main.c +++ b/ZodiacFX/src/main.c @@ -202,7 +202,6 @@ int main (void) while(1) { task_switch(&gs_net_if); - //task_command(cCommand, cCommand_last); // Only run the following tasks if set to Master if(masterselect == false) { diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index cd599b0..1d1343c 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -50,7 +50,7 @@ static uint32_t gs_ul_spi_clock = 120000000; /* Delay before SPCK. */ #define SPI_DLYBS 0x30 /* Delay between consecutive transfers. */ -#define SPI_DLYBCT 0x10 +#define SPI_DLYBCT 0x15 // Global variables extern uint8_t last_port_status[8]; @@ -82,7 +82,6 @@ void spi_master_initialize(void); void spi_slave_initialize(void); void spi_port_stats(void); void spi_port_status(void); -void SPI_Handler1(void); /* * Initialize the SPI interface to MASTER or SLAVE based on the stacking jumper @@ -253,6 +252,7 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) spi_packet->premable = SPI_PACKET_PREAMBLE; spi_packet->ul_rcv_size = ul_size; spi_packet->spi_crc = 0; + // Calculate CRC value for(int x = 0;xspi_crc += p_uc_data[x]; @@ -261,7 +261,6 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) spi_packet->spi_size = SPI_HEADER_SIZE + ul_size; TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); - TRACE("stacking.c: ------- ------- Master -> Slave"); // Send the SPI packet header for(uint16_t ct=0; ct MASTER receive ***** spi_read_size = 1600; // ignore dummy bytes spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); @@ -306,7 +304,6 @@ void MasterStackRcv(void) while(spi_count < spi_read_size) { spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); - //for(volatile int x = 0;x 2000) - { - printf("full!\r\n"); - spi_count = 0; - } -} - // ##################### SPI Test Functions ##################### uint8_t masterslave_test(void) From 99649a55f65e803cd1c8d5dffa2a246ccf2f4a09 Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Thu, 11 May 2017 14:42:52 +1000 Subject: [PATCH 091/169] SPI transfer size update --- ZodiacFX/src/stacking.c | 123 +++++++++++++++++++++++----------------- ZodiacFX/src/stacking.h | 8 ++- 2 files changed, 77 insertions(+), 54 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 1d1343c..88a2266 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -120,7 +120,7 @@ void spi_slave_initialize(void) spi_set_peripheral_chip_select_value(SPI_SLAVE_BASE, SPI_CHIP_SEL); spi_set_clock_polarity(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY); spi_set_clock_phase(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE); - spi_set_bits_per_transfer(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT); + spi_set_bits_per_transfer(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_16_BIT); spi_enable_interrupt(SPI_SLAVE_BASE, SPI_IER_RDRF); spi_enable(SPI_SLAVE_BASE); ioport_set_pin_level(SPI_IRQ1, false); @@ -143,7 +143,7 @@ void spi_master_initialize(void) spi_disable_loopback(SPI_MASTER_BASE); spi_set_peripheral_chip_select_value(SPI_MASTER_BASE, SPI_CHIP_SEL); spi_set_transfer_delay(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_DLYBS, SPI_DLYBCT); - spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT); + spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_16_BIT); spi_set_baudrate_div(SPI_MASTER_BASE, SPI_CHIP_SEL, (ul_sysclk_div)); spi_set_clock_polarity(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY); spi_set_clock_phase(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE); @@ -211,7 +211,10 @@ void spi_port_status(void) */ void MasterReady(void) { - spi_write(SPI_MASTER_BASE, 0xaa, 0, 0); + static uint16_t data; + spi_write(SPI_MASTER_BASE, 0xaaaa, 0, 0); + while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_MASTER_BASE, &data, &uc_pcs); master_ready = true; return; } @@ -228,9 +231,10 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) static uint16_t data; uint8_t *p_buffer; uint8_t outport; - + uint16_t ct; uint8_t spi_head_buffer[SPI_HEADER_SIZE] = {0}; + // Update packet counters if (port < 255) { outport = port; @@ -247,11 +251,12 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) if (port_status[7] == 1) phys10_port_stats[7].tx_packets++; if (port_status[7] == 1) phys13_port_stats[7].tx_packets++; } + // Prepare header (shared_buffer already contains the packet data) spi_packet = &spi_head_buffer; - spi_packet->premable = SPI_PACKET_PREAMBLE; spi_packet->ul_rcv_size = ul_size; spi_packet->spi_crc = 0; + // Calculate CRC value for(int x = 0;xtag = port; spi_packet->spi_size = SPI_HEADER_SIZE + ul_size; - - TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); - + + // Send Preamble + spi_write(SPI_MASTER_BASE, SPI_PACKET_PREAMBLE, 0, 0); + while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + spi_write(SPI_MASTER_BASE, SPI_PACKET_PREAMBLE, 0, 0); + while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + // Send the SPI packet header - for(uint16_t ct=0; ct 1600) - { - spi_read_size = 1600; - } - } - } - spi_count++; while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_MASTER_BASE, &shared_buffer + spi_count, &uc_pcs); + spi_count+=2; + if(spi_count > SPI_MAX_PKT_SIZE) + { + TRACE("stacking.c: ERROR - Master read overrun!"); + return; + } } + printf("stacking.c: ------- ------- Slave -> Master %d\r\n", sys_get_ms() - rcv_time); - - TRACE("stacking.c: MASTER received preamble - %x, %x", shared_buffer[0], shared_buffer[1]); + if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) { TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE"); return; } + // Process received data if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) { - /* Process Received SPI Packet */ spi_crc_rcv = 0; spi_packet = &shared_buffer; if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) @@ -408,12 +424,13 @@ void SPI_Handler(void) static uint32_t receive_timeout = 0; // Timeout for SPI data receive (MASTER->SLAVE) uint8_t uc_pcs; + // SPI initialisation if (slave_ready == false) // Is this the first data we have received? { if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xaa) + if (data == 0xAAAA) { ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ slave_ready = true; @@ -422,7 +439,8 @@ void SPI_Handler(void) } } - if(pending_spi_command == SPI_SEND_STATS) // We send the master our port stats + // We send the master our port stats + if(pending_spi_command == SPI_SEND_STATS) { if (spi_slave_send_count <= 0) { @@ -442,7 +460,8 @@ void SPI_Handler(void) return; } - if(pending_spi_command == SPI_SEND_PKT) // Send slave packet to master + // Send slave packet to master + if(pending_spi_command == SPI_SEND_PKT) { if (spi_slave_send_count <= 0) { @@ -453,7 +472,7 @@ void SPI_Handler(void) spi_dummy_bytes++; return; } - pending_spi_command = SPI_SEND_CLEAR; // Clear the pending command + pending_spi_command = SPI_SEND_READY; // Clear the pending command ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done spi_dummy_bytes = 0; } else { @@ -469,30 +488,32 @@ void SPI_Handler(void) return; } - if(pending_spi_command == SPI_SEND_CLEAR) + // Waiting to receive data + if(pending_spi_command == SPI_SEND_READY) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xBC) + if (data == 0xBCBC) { pending_spi_command = SPI_RCV_PREAMBLE; } return; } + // Recieve data from the master if(pending_spi_command == SPI_RCV_PREAMBLE) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xBC) + if (data == 0xBCBC) { pending_spi_command = SPI_RECEIVE; - //memset(&shared_buffer,0,sizeof(shared_buffer)); // ***** - // Write preamble to SPI packet header shared_buffer[0] = 0xBC; shared_buffer[1] = 0xBC; + shared_buffer[2] = 0xBC; + shared_buffer[3] = 0xBC; } else { - pending_spi_command = SPI_SEND_CLEAR; + pending_spi_command = SPI_SEND_READY; } return; } @@ -515,7 +536,7 @@ void SPI_Handler(void) { // ERROR: over-sized packet data // Clean up and return - pending_spi_command = SPI_SEND_CLEAR; + pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; return; @@ -538,7 +559,7 @@ void SPI_Handler(void) { // ERROR: payload data too large // Clean up and return - pending_spi_command = SPI_SEND_CLEAR; + pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; //slavemaster_test(); @@ -556,7 +577,7 @@ void SPI_Handler(void) { // ERROR: corrupt packet // Clean up and return - pending_spi_command = SPI_SEND_CLEAR; + pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; return; @@ -572,7 +593,7 @@ void SPI_Handler(void) } // Packet receive complete // Clean up and return - pending_spi_command = SPI_SEND_CLEAR; + pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; slavemaster_test(); @@ -599,7 +620,7 @@ uint8_t masterslave_test(void) uint8_t slavemaster_test(void) { // Note: the pending check may need to be moved outside of the function call - if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) + if (slave_ready == true && pending_spi_command == SPI_SEND_READY) { // PREPARE TEST PACKET from SLAVE to MASTER spi_packet = &shared_buffer; diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 9396f4d..e4d8e8a 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -35,15 +35,17 @@ #define SPI_Handler SPI_Handler #define SPI_IRQn SPI_IRQn -#define SPI_SEND_CLEAR 0 +#define SPI_SEND_READY 0 #define SPI_SEND_STATS 1 #define SPI_SEND_PKT 2 #define SPI_RECEIVE 3 #define SPI_RCV_PREAMBLE 4 #define SPI_STATS_PREAMBLE 0xABAB #define SPI_PACKET_PREAMBLE 0xBCBC +#define SPI_PACKET_EOF 0xCDCD #define SPI_SEND_WAIT 0 -#define SPI_HEADER_SIZE 13 +#define SPI_HEADER_SIZE 12 +#define SPI_MAX_PKT_SIZE 1600 struct spi_port_stats { uint16_t premable; @@ -57,11 +59,11 @@ struct spi_port_stats { }; struct spi_packet { - uint16_t premable; // Transmission preamble uint16_t spi_size; // SPI transmission size uint32_t ul_rcv_size; // Actual packet size uint32_t spi_crc; // Calculated CRC of packet uint8_t tag; // Port number (1-8, or 255) + uint8_t pad; // Padding to align to even byte count uint8_t pkt_buffer[GMAC_FRAME_LENTGH_MAX]; }; From 1e345bcbbfe398bde48342a8627163e13923853b Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Thu, 11 May 2017 16:20:37 +1000 Subject: [PATCH 092/169] Single IRQ receive --- ZodiacFX/src/stacking.c | 87 +++++++++++++++++++---------------------- ZodiacFX/src/stacking.h | 1 - 2 files changed, 40 insertions(+), 48 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 88a2266..4a545cb 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -50,7 +50,7 @@ static uint32_t gs_ul_spi_clock = 120000000; /* Delay before SPCK. */ #define SPI_DLYBS 0x30 /* Delay between consecutive transfers. */ -#define SPI_DLYBCT 0x15 +#define SPI_DLYBCT 0x20 // Global variables extern uint8_t last_port_status[8]; @@ -423,6 +423,7 @@ void SPI_Handler(void) static uint16_t data; static uint32_t receive_timeout = 0; // Timeout for SPI data receive (MASTER->SLAVE) uint8_t uc_pcs; + uint32_t spi_crc_rcv = 0; // SPI initialisation if (slave_ready == false) // Is this the first data we have received? @@ -439,7 +440,7 @@ void SPI_Handler(void) } } - // We send the master our port stats + // We are sending the master our port stats if(pending_spi_command == SPI_SEND_STATS) { if (spi_slave_send_count <= 0) @@ -460,7 +461,7 @@ void SPI_Handler(void) return; } - // Send slave packet to master + // We are sending the master a packet if(pending_spi_command == SPI_SEND_PKT) { if (spi_slave_send_count <= 0) @@ -499,73 +500,67 @@ void SPI_Handler(void) return; } - // Recieve data from the master + // We recieved the first preamble bytes from the master if(pending_spi_command == SPI_RCV_PREAMBLE) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); if (data == 0xBCBC) { - pending_spi_command = SPI_RECEIVE; - shared_buffer[0] = 0xBC; - shared_buffer[1] = 0xBC; - shared_buffer[2] = 0xBC; - shared_buffer[3] = 0xBC; - } - else + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + if (data == 0xBCBC) + { + pending_spi_command = SPI_RECEIVE; + shared_buffer[0] = 0xBC; + shared_buffer[1] = 0xBC; + shared_buffer[2] = 0xBC; + shared_buffer[3] = 0xBC; + } else + { + pending_spi_command = SPI_SEND_READY; + return; + } + } else { pending_spi_command = SPI_SEND_READY; + return; } - return; } if(pending_spi_command == SPI_RECEIVE) { // ***** Modified MASTER -> SLAVE receiver ***** - static uint16_t spi_count = 2; + static uint16_t spi_count = 4; static uint16_t spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - - // Read next byte - spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_SLAVE_BASE, &shared_buffer[spi_count], &uc_pcs); + bool eof_flag = false; - if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 3) + // Read receive bytes + while(spi_count < SPI_MAX_PKT_SIZE) { - spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); - if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) + if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) { - // ERROR: over-sized packet data - // Clean up and return - pending_spi_command = SPI_SEND_READY; - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - return; + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + if (data = SPI_PACKET_EOF) + { + if (eof_flag == false) eof_flag = true; + if (eof_flag == true) break; + } + memcpy(&shared_buffer + spi_count, &data, 2); + spi_count += 2; } } - - // Check if more bytes need to be read - if(spi_count < (spi_read_size-1)) - { - // Wait for next interrupt - spi_count++; - return; - } - - uint32_t spi_crc_rcv = 0; - spi_packet = &shared_buffer; - + // Check against maximum packet size + spi_packet = &shared_buffer; if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) { // ERROR: payload data too large // Clean up and return pending_spi_command = SPI_SEND_READY; - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - //slavemaster_test(); + TRACE("stacking.c: ERROR - Slave receive bad packet size!"); return; } - + // Calculated CRC of the received data for(uint16_t ct=0; ctul_rcv_size; ct++) { @@ -578,8 +573,7 @@ void SPI_Handler(void) // ERROR: corrupt packet // Clean up and return pending_spi_command = SPI_SEND_READY; - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + TRACE("stacking.c: ERROR - Slave receive bad CRC!"); return; } @@ -591,11 +585,10 @@ void SPI_Handler(void) { gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, spi_packet->tag-4, 0); } + // Packet receive complete // Clean up and return pending_spi_command = SPI_SEND_READY; - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; slavemaster_test(); return; diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index e4d8e8a..919552b 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -28,7 +28,6 @@ * */ - #ifndef STACKING_H_ #define STACKING_H_ From 3092ae7a8b868fc489a945f92aa510f45fbfc264 Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Sun, 14 May 2017 22:34:57 +1000 Subject: [PATCH 093/169] Save 1 --- ZodiacFX/src/stacking.c | 83 ++++++++++++++++++++++------------------- ZodiacFX/src/switch.c | 7 ++-- 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 4a545cb..edf2202 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -65,7 +65,7 @@ extern struct ofp13_port_stats phys13_port_stats[8]; uint16_t spi_slave_send_size; uint16_t spi_slave_send_count; uint8_t timer_alt; -uint8_t pending_spi_command = SPI_SEND_CLEAR; +uint8_t pending_spi_command = SPI_SEND_READY; bool master_ready; bool slave_ready; uint8_t spi_dummy_bytes = 0; @@ -77,6 +77,7 @@ bool end_check; uint8_t spi_receive_port = 0; uint16_t spi_receive_count; uint32_t rcv_time; +bool slave_preamble = true; void spi_master_initialize(void); void spi_slave_initialize(void); @@ -166,7 +167,7 @@ void Slave_timer(void) } else if (timer_alt == 2) { // Send SLAVE port stats if SLAVE is in the clear state - if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) + if (slave_ready == true && pending_spi_command == SPI_SEND_READY) { spi_p_stats.premable = SPI_STATS_PREAMBLE; spi_p_stats.spi_size = sizeof(struct spi_port_stats); @@ -212,7 +213,8 @@ void spi_port_status(void) void MasterReady(void) { static uint16_t data; - spi_write(SPI_MASTER_BASE, 0xaaaa, 0, 0); + uint8_t uc_pcs; + spi_write(SPI_MASTER_BASE, 0xAAAA, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); spi_read(SPI_MASTER_BASE, &data, &uc_pcs); master_ready = true; @@ -232,6 +234,7 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) uint8_t *p_buffer; uint8_t outport; uint16_t ct; + int spi_count = 0; uint8_t spi_head_buffer[SPI_HEADER_SIZE] = {0}; // Update packet counters @@ -268,10 +271,10 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) // Send Preamble spi_write(SPI_MASTER_BASE, SPI_PACKET_PREAMBLE, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + spi_read(SPI_MASTER_BASE, &data, &uc_pcs); spi_write(SPI_MASTER_BASE, SPI_PACKET_PREAMBLE, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + spi_read(SPI_MASTER_BASE, &data, &uc_pcs); // Send the SPI packet header for(ct=0; ct Master %d\r\n", sys_get_ms() - rcv_time); + TRACE("stacking.c: ------- ------- Slave -> Master %d\r\n", sys_get_ms() - rcv_time); if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) { @@ -424,8 +427,9 @@ void SPI_Handler(void) static uint32_t receive_timeout = 0; // Timeout for SPI data receive (MASTER->SLAVE) uint8_t uc_pcs; uint32_t spi_crc_rcv = 0; + uint8_t *data_offset; - // SPI initialisation + // SPI initialization if (slave_ready == false) // Is this the first data we have received? { if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) @@ -447,11 +451,11 @@ void SPI_Handler(void) { if (spi_dummy_bytes < 2) { - spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); + spi_write(SPI_SLAVE_BASE, 0xFFFF, 0, 0); spi_dummy_bytes++; return; } - pending_spi_command = SPI_SEND_CLEAR; // Clear the pending command + pending_spi_command = SPI_SEND_READY; // Clear the pending command ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done spi_dummy_bytes = 0; } else { @@ -469,21 +473,35 @@ void SPI_Handler(void) // Flush out last two bytes if (spi_dummy_bytes < 2) { - spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); // ***** + spi_write(SPI_SLAVE_BASE, 0xFFFF, 0, 0); // ***** spi_dummy_bytes++; return; } pending_spi_command = SPI_SEND_READY; // Clear the pending command ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done spi_dummy_bytes = 0; + slave_preamble = true; } else { + if (slave_preamble == true) + { + // Send Preamble + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + spi_write(SPI_SLAVE_BASE, SPI_PACKET_PREAMBLE, 0, 0); + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + spi_write(SPI_SLAVE_BASE, SPI_PACKET_PREAMBLE, 0, 0); + slave_preamble = false; + } while(spi_slave_send_count > 0) { - spi_write(SPI_SLAVE_BASE, shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); - spi_slave_send_count--; // Wait for master to send the next byte while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + data_offset = &shared_buffer + (spi_slave_send_size - spi_slave_send_count); + memcpy(&data, data_offset, 2); + spi_write(SPI_SLAVE_BASE, &data, 0, 0); + spi_slave_send_count -= 2; } } return; @@ -500,27 +518,18 @@ void SPI_Handler(void) return; } - // We recieved the first preamble bytes from the master + // We received the first preamble bytes from the master if(pending_spi_command == SPI_RCV_PREAMBLE) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); if (data == 0xBCBC) { - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xBCBC) - { pending_spi_command = SPI_RECEIVE; - shared_buffer[0] = 0xBC; - shared_buffer[1] = 0xBC; - shared_buffer[2] = 0xBC; - shared_buffer[3] = 0xBC; - } else - { - pending_spi_command = SPI_SEND_READY; - return; - } - } else + //shared_buffer[0] = 0xBC; + //shared_buffer[1] = 0xBC; + //shared_buffer[2] = 0xBC; + //shared_buffer[3] = 0xBC; + } else { pending_spi_command = SPI_SEND_READY; return; @@ -529,8 +538,7 @@ void SPI_Handler(void) if(pending_spi_command == SPI_RECEIVE) { - // ***** Modified MASTER -> SLAVE receiver ***** - static uint16_t spi_count = 4; + static uint16_t spi_count = 0; static uint16_t spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; bool eof_flag = false; @@ -617,7 +625,6 @@ uint8_t slavemaster_test(void) { // PREPARE TEST PACKET from SLAVE to MASTER spi_packet = &shared_buffer; - spi_packet->premable = SPI_PACKET_PREAMBLE; spi_packet->ul_rcv_size = 1400; spi_packet->spi_crc = 0; uint8_t*ind_ptr = &spi_packet->pkt_buffer; diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index f1471ac..d06b67f 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -578,7 +578,7 @@ void task_switch(struct netif *netif) } } else { - if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) + if (slave_ready == true && pending_spi_command == SPI_SEND_READY) { //uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); //uint8_t tag = *tail_tag + 1; @@ -586,7 +586,6 @@ void task_switch(struct netif *netif) //phys13_port_stats[tag-1].rx_packets++; //ul_rcv_size--; // remove the tail first //spi_packet = &shared_buffer; - //spi_packet->premable = SPI_PACKET_PREAMBLE; //spi_packet->ul_rcv_size = ul_rcv_size; //spi_packet->spi_crc = 0; //for(int x = 0;xspi_crc += gs_uc_eth_buffer[x]; //} //spi_packet->tag = tag + 4; - //spi_packet->spi_size = 11 + ul_rcv_size; + //spi_packet->spi_size = SPI_HEADER_SIZE + ul_rcv_size; //memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); //pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet //spi_slave_send_size = spi_packet->spi_size; //spi_slave_send_count = spi_slave_send_size; //ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something - return; + //return; } } } From bc6ba7994607cddc61474a65998ee28f037f5495 Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Mon, 15 May 2017 08:51:07 +1000 Subject: [PATCH 094/169] Revert "Save 1" This reverts commit 3092ae7a8b868fc489a945f92aa510f45fbfc264. --- ZodiacFX/src/stacking.c | 83 +++++++++++++++++++---------------------- ZodiacFX/src/switch.c | 7 ++-- 2 files changed, 42 insertions(+), 48 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index edf2202..4a545cb 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -65,7 +65,7 @@ extern struct ofp13_port_stats phys13_port_stats[8]; uint16_t spi_slave_send_size; uint16_t spi_slave_send_count; uint8_t timer_alt; -uint8_t pending_spi_command = SPI_SEND_READY; +uint8_t pending_spi_command = SPI_SEND_CLEAR; bool master_ready; bool slave_ready; uint8_t spi_dummy_bytes = 0; @@ -77,7 +77,6 @@ bool end_check; uint8_t spi_receive_port = 0; uint16_t spi_receive_count; uint32_t rcv_time; -bool slave_preamble = true; void spi_master_initialize(void); void spi_slave_initialize(void); @@ -167,7 +166,7 @@ void Slave_timer(void) } else if (timer_alt == 2) { // Send SLAVE port stats if SLAVE is in the clear state - if (slave_ready == true && pending_spi_command == SPI_SEND_READY) + if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) { spi_p_stats.premable = SPI_STATS_PREAMBLE; spi_p_stats.spi_size = sizeof(struct spi_port_stats); @@ -213,8 +212,7 @@ void spi_port_status(void) void MasterReady(void) { static uint16_t data; - uint8_t uc_pcs; - spi_write(SPI_MASTER_BASE, 0xAAAA, 0, 0); + spi_write(SPI_MASTER_BASE, 0xaaaa, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); spi_read(SPI_MASTER_BASE, &data, &uc_pcs); master_ready = true; @@ -234,7 +232,6 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) uint8_t *p_buffer; uint8_t outport; uint16_t ct; - int spi_count = 0; uint8_t spi_head_buffer[SPI_HEADER_SIZE] = {0}; // Update packet counters @@ -271,10 +268,10 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) // Send Preamble spi_write(SPI_MASTER_BASE, SPI_PACKET_PREAMBLE, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_MASTER_BASE, &data, &uc_pcs); + spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); spi_write(SPI_MASTER_BASE, SPI_PACKET_PREAMBLE, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_MASTER_BASE, &data, &uc_pcs); + spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); // Send the SPI packet header for(ct=0; ct Master %d\r\n", sys_get_ms() - rcv_time); + printf("stacking.c: ------- ------- Slave -> Master %d\r\n", sys_get_ms() - rcv_time); if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) { @@ -427,9 +424,8 @@ void SPI_Handler(void) static uint32_t receive_timeout = 0; // Timeout for SPI data receive (MASTER->SLAVE) uint8_t uc_pcs; uint32_t spi_crc_rcv = 0; - uint8_t *data_offset; - // SPI initialization + // SPI initialisation if (slave_ready == false) // Is this the first data we have received? { if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) @@ -451,11 +447,11 @@ void SPI_Handler(void) { if (spi_dummy_bytes < 2) { - spi_write(SPI_SLAVE_BASE, 0xFFFF, 0, 0); + spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); spi_dummy_bytes++; return; } - pending_spi_command = SPI_SEND_READY; // Clear the pending command + pending_spi_command = SPI_SEND_CLEAR; // Clear the pending command ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done spi_dummy_bytes = 0; } else { @@ -473,35 +469,21 @@ void SPI_Handler(void) // Flush out last two bytes if (spi_dummy_bytes < 2) { - spi_write(SPI_SLAVE_BASE, 0xFFFF, 0, 0); // ***** + spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); // ***** spi_dummy_bytes++; return; } pending_spi_command = SPI_SEND_READY; // Clear the pending command ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done spi_dummy_bytes = 0; - slave_preamble = true; } else { - if (slave_preamble == true) - { - // Send Preamble - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - spi_write(SPI_SLAVE_BASE, SPI_PACKET_PREAMBLE, 0, 0); - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - spi_write(SPI_SLAVE_BASE, SPI_PACKET_PREAMBLE, 0, 0); - slave_preamble = false; - } while(spi_slave_send_count > 0) { + spi_write(SPI_SLAVE_BASE, shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); + spi_slave_send_count--; // Wait for master to send the next byte while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - data_offset = &shared_buffer + (spi_slave_send_size - spi_slave_send_count); - memcpy(&data, data_offset, 2); - spi_write(SPI_SLAVE_BASE, &data, 0, 0); - spi_slave_send_count -= 2; } } return; @@ -518,18 +500,27 @@ void SPI_Handler(void) return; } - // We received the first preamble bytes from the master + // We recieved the first preamble bytes from the master if(pending_spi_command == SPI_RCV_PREAMBLE) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); if (data == 0xBCBC) { + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + if (data == 0xBCBC) + { pending_spi_command = SPI_RECEIVE; - //shared_buffer[0] = 0xBC; - //shared_buffer[1] = 0xBC; - //shared_buffer[2] = 0xBC; - //shared_buffer[3] = 0xBC; - } else + shared_buffer[0] = 0xBC; + shared_buffer[1] = 0xBC; + shared_buffer[2] = 0xBC; + shared_buffer[3] = 0xBC; + } else + { + pending_spi_command = SPI_SEND_READY; + return; + } + } else { pending_spi_command = SPI_SEND_READY; return; @@ -538,7 +529,8 @@ void SPI_Handler(void) if(pending_spi_command == SPI_RECEIVE) { - static uint16_t spi_count = 0; + // ***** Modified MASTER -> SLAVE receiver ***** + static uint16_t spi_count = 4; static uint16_t spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; bool eof_flag = false; @@ -625,6 +617,7 @@ uint8_t slavemaster_test(void) { // PREPARE TEST PACKET from SLAVE to MASTER spi_packet = &shared_buffer; + spi_packet->premable = SPI_PACKET_PREAMBLE; spi_packet->ul_rcv_size = 1400; spi_packet->spi_crc = 0; uint8_t*ind_ptr = &spi_packet->pkt_buffer; diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index d06b67f..f1471ac 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -578,7 +578,7 @@ void task_switch(struct netif *netif) } } else { - if (slave_ready == true && pending_spi_command == SPI_SEND_READY) + if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) { //uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); //uint8_t tag = *tail_tag + 1; @@ -586,6 +586,7 @@ void task_switch(struct netif *netif) //phys13_port_stats[tag-1].rx_packets++; //ul_rcv_size--; // remove the tail first //spi_packet = &shared_buffer; + //spi_packet->premable = SPI_PACKET_PREAMBLE; //spi_packet->ul_rcv_size = ul_rcv_size; //spi_packet->spi_crc = 0; //for(int x = 0;xspi_crc += gs_uc_eth_buffer[x]; //} //spi_packet->tag = tag + 4; - //spi_packet->spi_size = SPI_HEADER_SIZE + ul_rcv_size; + //spi_packet->spi_size = 11 + ul_rcv_size; //memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); //pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet //spi_slave_send_size = spi_packet->spi_size; //spi_slave_send_count = spi_slave_send_size; //ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something - //return; + return; } } } From ca3e01e292e0fe80c02ba1ca818cf283f6521902 Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Mon, 15 May 2017 08:51:25 +1000 Subject: [PATCH 095/169] Revert "Single IRQ receive" This reverts commit 1e345bcbbfe398bde48342a8627163e13923853b. --- ZodiacFX/src/stacking.c | 87 ++++++++++++++++++++++------------------- ZodiacFX/src/stacking.h | 1 + 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 4a545cb..88a2266 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -50,7 +50,7 @@ static uint32_t gs_ul_spi_clock = 120000000; /* Delay before SPCK. */ #define SPI_DLYBS 0x30 /* Delay between consecutive transfers. */ -#define SPI_DLYBCT 0x20 +#define SPI_DLYBCT 0x15 // Global variables extern uint8_t last_port_status[8]; @@ -423,7 +423,6 @@ void SPI_Handler(void) static uint16_t data; static uint32_t receive_timeout = 0; // Timeout for SPI data receive (MASTER->SLAVE) uint8_t uc_pcs; - uint32_t spi_crc_rcv = 0; // SPI initialisation if (slave_ready == false) // Is this the first data we have received? @@ -440,7 +439,7 @@ void SPI_Handler(void) } } - // We are sending the master our port stats + // We send the master our port stats if(pending_spi_command == SPI_SEND_STATS) { if (spi_slave_send_count <= 0) @@ -461,7 +460,7 @@ void SPI_Handler(void) return; } - // We are sending the master a packet + // Send slave packet to master if(pending_spi_command == SPI_SEND_PKT) { if (spi_slave_send_count <= 0) @@ -500,67 +499,73 @@ void SPI_Handler(void) return; } - // We recieved the first preamble bytes from the master + // Recieve data from the master if(pending_spi_command == SPI_RCV_PREAMBLE) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); if (data == 0xBCBC) { - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xBCBC) - { - pending_spi_command = SPI_RECEIVE; - shared_buffer[0] = 0xBC; - shared_buffer[1] = 0xBC; - shared_buffer[2] = 0xBC; - shared_buffer[3] = 0xBC; - } else - { - pending_spi_command = SPI_SEND_READY; - return; - } - } else + pending_spi_command = SPI_RECEIVE; + shared_buffer[0] = 0xBC; + shared_buffer[1] = 0xBC; + shared_buffer[2] = 0xBC; + shared_buffer[3] = 0xBC; + } + else { pending_spi_command = SPI_SEND_READY; - return; } + return; } if(pending_spi_command == SPI_RECEIVE) { // ***** Modified MASTER -> SLAVE receiver ***** - static uint16_t spi_count = 4; + static uint16_t spi_count = 2; static uint16_t spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - bool eof_flag = false; + + // Read next byte + spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_SLAVE_BASE, &shared_buffer[spi_count], &uc_pcs); - // Read receive bytes - while(spi_count < SPI_MAX_PKT_SIZE) + if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 3) { - if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) + spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); + if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) { - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data = SPI_PACKET_EOF) - { - if (eof_flag == false) eof_flag = true; - if (eof_flag == true) break; - } - memcpy(&shared_buffer + spi_count, &data, 2); - spi_count += 2; + // ERROR: over-sized packet data + // Clean up and return + pending_spi_command = SPI_SEND_READY; + spi_count = 2; + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + return; } } - - // Check against maximum packet size + + // Check if more bytes need to be read + if(spi_count < (spi_read_size-1)) + { + // Wait for next interrupt + spi_count++; + return; + } + + uint32_t spi_crc_rcv = 0; spi_packet = &shared_buffer; + + // Check against maximum packet size if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) { // ERROR: payload data too large // Clean up and return pending_spi_command = SPI_SEND_READY; - TRACE("stacking.c: ERROR - Slave receive bad packet size!"); + spi_count = 2; + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + //slavemaster_test(); return; } - + // Calculated CRC of the received data for(uint16_t ct=0; ctul_rcv_size; ct++) { @@ -573,7 +578,8 @@ void SPI_Handler(void) // ERROR: corrupt packet // Clean up and return pending_spi_command = SPI_SEND_READY; - TRACE("stacking.c: ERROR - Slave receive bad CRC!"); + spi_count = 2; + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; return; } @@ -585,10 +591,11 @@ void SPI_Handler(void) { gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, spi_packet->tag-4, 0); } - // Packet receive complete // Clean up and return pending_spi_command = SPI_SEND_READY; + spi_count = 2; + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; slavemaster_test(); return; diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 919552b..e4d8e8a 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -28,6 +28,7 @@ * */ + #ifndef STACKING_H_ #define STACKING_H_ From dbb35d35702dcc084b28a61a94c02966c19e79bc Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Mon, 15 May 2017 08:51:34 +1000 Subject: [PATCH 096/169] Revert "SPI transfer size update" This reverts commit 99649a55f65e803cd1c8d5dffa2a246ccf2f4a09. --- ZodiacFX/src/stacking.c | 123 +++++++++++++++++----------------------- ZodiacFX/src/stacking.h | 8 +-- 2 files changed, 54 insertions(+), 77 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 88a2266..1d1343c 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -120,7 +120,7 @@ void spi_slave_initialize(void) spi_set_peripheral_chip_select_value(SPI_SLAVE_BASE, SPI_CHIP_SEL); spi_set_clock_polarity(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY); spi_set_clock_phase(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE); - spi_set_bits_per_transfer(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_16_BIT); + spi_set_bits_per_transfer(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT); spi_enable_interrupt(SPI_SLAVE_BASE, SPI_IER_RDRF); spi_enable(SPI_SLAVE_BASE); ioport_set_pin_level(SPI_IRQ1, false); @@ -143,7 +143,7 @@ void spi_master_initialize(void) spi_disable_loopback(SPI_MASTER_BASE); spi_set_peripheral_chip_select_value(SPI_MASTER_BASE, SPI_CHIP_SEL); spi_set_transfer_delay(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_DLYBS, SPI_DLYBCT); - spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_16_BIT); + spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT); spi_set_baudrate_div(SPI_MASTER_BASE, SPI_CHIP_SEL, (ul_sysclk_div)); spi_set_clock_polarity(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY); spi_set_clock_phase(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE); @@ -211,10 +211,7 @@ void spi_port_status(void) */ void MasterReady(void) { - static uint16_t data; - spi_write(SPI_MASTER_BASE, 0xaaaa, 0, 0); - while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_MASTER_BASE, &data, &uc_pcs); + spi_write(SPI_MASTER_BASE, 0xaa, 0, 0); master_ready = true; return; } @@ -231,10 +228,9 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) static uint16_t data; uint8_t *p_buffer; uint8_t outport; - uint16_t ct; + uint8_t spi_head_buffer[SPI_HEADER_SIZE] = {0}; - // Update packet counters if (port < 255) { outport = port; @@ -251,12 +247,11 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) if (port_status[7] == 1) phys10_port_stats[7].tx_packets++; if (port_status[7] == 1) phys13_port_stats[7].tx_packets++; } - // Prepare header (shared_buffer already contains the packet data) spi_packet = &spi_head_buffer; + spi_packet->premable = SPI_PACKET_PREAMBLE; spi_packet->ul_rcv_size = ul_size; spi_packet->spi_crc = 0; - // Calculate CRC value for(int x = 0;xtag = port; spi_packet->spi_size = SPI_HEADER_SIZE + ul_size; - - // Send Preamble - spi_write(SPI_MASTER_BASE, SPI_PACKET_PREAMBLE, 0, 0); - while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); - spi_write(SPI_MASTER_BASE, SPI_PACKET_PREAMBLE, 0, 0); - while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); - + + TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); + // Send the SPI packet header - for(ct=0; ct 1600) + { + spi_read_size = 1600; + } + } + } + spi_count++; while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_MASTER_BASE, &shared_buffer + spi_count, &uc_pcs); - spi_count+=2; - if(spi_count > SPI_MAX_PKT_SIZE) - { - TRACE("stacking.c: ERROR - Master read overrun!"); - return; - } } - printf("stacking.c: ------- ------- Slave -> Master %d\r\n", sys_get_ms() - rcv_time); - + + TRACE("stacking.c: MASTER received preamble - %x, %x", shared_buffer[0], shared_buffer[1]); if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) { TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE"); return; } - // Process received data if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) { + /* Process Received SPI Packet */ spi_crc_rcv = 0; spi_packet = &shared_buffer; if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) @@ -424,13 +408,12 @@ void SPI_Handler(void) static uint32_t receive_timeout = 0; // Timeout for SPI data receive (MASTER->SLAVE) uint8_t uc_pcs; - // SPI initialisation if (slave_ready == false) // Is this the first data we have received? { if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xAAAA) + if (data == 0xaa) { ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ slave_ready = true; @@ -439,8 +422,7 @@ void SPI_Handler(void) } } - // We send the master our port stats - if(pending_spi_command == SPI_SEND_STATS) + if(pending_spi_command == SPI_SEND_STATS) // We send the master our port stats { if (spi_slave_send_count <= 0) { @@ -460,8 +442,7 @@ void SPI_Handler(void) return; } - // Send slave packet to master - if(pending_spi_command == SPI_SEND_PKT) + if(pending_spi_command == SPI_SEND_PKT) // Send slave packet to master { if (spi_slave_send_count <= 0) { @@ -472,7 +453,7 @@ void SPI_Handler(void) spi_dummy_bytes++; return; } - pending_spi_command = SPI_SEND_READY; // Clear the pending command + pending_spi_command = SPI_SEND_CLEAR; // Clear the pending command ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done spi_dummy_bytes = 0; } else { @@ -488,32 +469,30 @@ void SPI_Handler(void) return; } - // Waiting to receive data - if(pending_spi_command == SPI_SEND_READY) + if(pending_spi_command == SPI_SEND_CLEAR) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xBCBC) + if (data == 0xBC) { pending_spi_command = SPI_RCV_PREAMBLE; } return; } - // Recieve data from the master if(pending_spi_command == SPI_RCV_PREAMBLE) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xBCBC) + if (data == 0xBC) { pending_spi_command = SPI_RECEIVE; + //memset(&shared_buffer,0,sizeof(shared_buffer)); // ***** + // Write preamble to SPI packet header shared_buffer[0] = 0xBC; shared_buffer[1] = 0xBC; - shared_buffer[2] = 0xBC; - shared_buffer[3] = 0xBC; } else { - pending_spi_command = SPI_SEND_READY; + pending_spi_command = SPI_SEND_CLEAR; } return; } @@ -536,7 +515,7 @@ void SPI_Handler(void) { // ERROR: over-sized packet data // Clean up and return - pending_spi_command = SPI_SEND_READY; + pending_spi_command = SPI_SEND_CLEAR; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; return; @@ -559,7 +538,7 @@ void SPI_Handler(void) { // ERROR: payload data too large // Clean up and return - pending_spi_command = SPI_SEND_READY; + pending_spi_command = SPI_SEND_CLEAR; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; //slavemaster_test(); @@ -577,7 +556,7 @@ void SPI_Handler(void) { // ERROR: corrupt packet // Clean up and return - pending_spi_command = SPI_SEND_READY; + pending_spi_command = SPI_SEND_CLEAR; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; return; @@ -593,7 +572,7 @@ void SPI_Handler(void) } // Packet receive complete // Clean up and return - pending_spi_command = SPI_SEND_READY; + pending_spi_command = SPI_SEND_CLEAR; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; slavemaster_test(); @@ -620,7 +599,7 @@ uint8_t masterslave_test(void) uint8_t slavemaster_test(void) { // Note: the pending check may need to be moved outside of the function call - if (slave_ready == true && pending_spi_command == SPI_SEND_READY) + if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) { // PREPARE TEST PACKET from SLAVE to MASTER spi_packet = &shared_buffer; diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index e4d8e8a..9396f4d 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -35,17 +35,15 @@ #define SPI_Handler SPI_Handler #define SPI_IRQn SPI_IRQn -#define SPI_SEND_READY 0 +#define SPI_SEND_CLEAR 0 #define SPI_SEND_STATS 1 #define SPI_SEND_PKT 2 #define SPI_RECEIVE 3 #define SPI_RCV_PREAMBLE 4 #define SPI_STATS_PREAMBLE 0xABAB #define SPI_PACKET_PREAMBLE 0xBCBC -#define SPI_PACKET_EOF 0xCDCD #define SPI_SEND_WAIT 0 -#define SPI_HEADER_SIZE 12 -#define SPI_MAX_PKT_SIZE 1600 +#define SPI_HEADER_SIZE 13 struct spi_port_stats { uint16_t premable; @@ -59,11 +57,11 @@ struct spi_port_stats { }; struct spi_packet { + uint16_t premable; // Transmission preamble uint16_t spi_size; // SPI transmission size uint32_t ul_rcv_size; // Actual packet size uint32_t spi_crc; // Calculated CRC of packet uint8_t tag; // Port number (1-8, or 255) - uint8_t pad; // Padding to align to even byte count uint8_t pkt_buffer[GMAC_FRAME_LENTGH_MAX]; }; From e5a810ab5dbd14b944a230e083120afc0cd9b9ec Mon Sep 17 00:00:00 2001 From: Paul Zanna Date: Mon, 15 May 2017 09:07:54 +1000 Subject: [PATCH 097/169] Restart SPI Tuning --- ZodiacFX/src/stacking.c | 24 ++++++++++++------------ ZodiacFX/src/stacking.h | 2 +- ZodiacFX/src/switch.c | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 1d1343c..c25a1ca 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -38,7 +38,7 @@ #include "timers.h" /* SPI clock setting (Hz). */ -static uint32_t gs_ul_spi_clock = 120000000; +static uint32_t gs_ul_spi_clock = 20000000; /* Chip select. */ #define SPI_CHIP_SEL 0 @@ -65,7 +65,7 @@ extern struct ofp13_port_stats phys13_port_stats[8]; uint16_t spi_slave_send_size; uint16_t spi_slave_send_count; uint8_t timer_alt; -uint8_t pending_spi_command = SPI_SEND_CLEAR; +uint8_t pending_spi_command = SPI_SEND_READY; bool master_ready; bool slave_ready; uint8_t spi_dummy_bytes = 0; @@ -166,7 +166,7 @@ void Slave_timer(void) } else if (timer_alt == 2) { // Send SLAVE port stats if SLAVE is in the clear state - if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) + if (slave_ready == true && pending_spi_command == SPI_SEND_READY) { spi_p_stats.premable = SPI_STATS_PREAMBLE; spi_p_stats.spi_size = sizeof(struct spi_port_stats); @@ -432,7 +432,7 @@ void SPI_Handler(void) spi_dummy_bytes++; return; } - pending_spi_command = SPI_SEND_CLEAR; // Clear the pending command + pending_spi_command = SPI_SEND_READY; // Clear the pending command ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done spi_dummy_bytes = 0; } else { @@ -453,7 +453,7 @@ void SPI_Handler(void) spi_dummy_bytes++; return; } - pending_spi_command = SPI_SEND_CLEAR; // Clear the pending command + pending_spi_command = SPI_SEND_READY; // Clear the pending command ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done spi_dummy_bytes = 0; } else { @@ -469,7 +469,7 @@ void SPI_Handler(void) return; } - if(pending_spi_command == SPI_SEND_CLEAR) + if(pending_spi_command == SPI_SEND_READY) { spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); if (data == 0xBC) @@ -492,7 +492,7 @@ void SPI_Handler(void) } else { - pending_spi_command = SPI_SEND_CLEAR; + pending_spi_command = SPI_SEND_READY; } return; } @@ -515,7 +515,7 @@ void SPI_Handler(void) { // ERROR: over-sized packet data // Clean up and return - pending_spi_command = SPI_SEND_CLEAR; + pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; return; @@ -538,7 +538,7 @@ void SPI_Handler(void) { // ERROR: payload data too large // Clean up and return - pending_spi_command = SPI_SEND_CLEAR; + pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; //slavemaster_test(); @@ -556,7 +556,7 @@ void SPI_Handler(void) { // ERROR: corrupt packet // Clean up and return - pending_spi_command = SPI_SEND_CLEAR; + pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; return; @@ -572,7 +572,7 @@ void SPI_Handler(void) } // Packet receive complete // Clean up and return - pending_spi_command = SPI_SEND_CLEAR; + pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; slavemaster_test(); @@ -599,7 +599,7 @@ uint8_t masterslave_test(void) uint8_t slavemaster_test(void) { // Note: the pending check may need to be moved outside of the function call - if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) + if (slave_ready == true && pending_spi_command == SPI_SEND_READY) { // PREPARE TEST PACKET from SLAVE to MASTER spi_packet = &shared_buffer; diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 9396f4d..3ff7532 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -35,7 +35,7 @@ #define SPI_Handler SPI_Handler #define SPI_IRQn SPI_IRQn -#define SPI_SEND_CLEAR 0 +#define SPI_SEND_READY 0 #define SPI_SEND_STATS 1 #define SPI_SEND_PKT 2 #define SPI_RECEIVE 3 diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index f1471ac..a8f4142 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -578,7 +578,7 @@ void task_switch(struct netif *netif) } } else { - if (slave_ready == true && pending_spi_command == SPI_SEND_CLEAR) + if (slave_ready == true && pending_spi_command == SPI_SEND_READY) { //uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); //uint8_t tag = *tail_tag + 1; From 3c717ec63dad5fb8d44f4ab9e4e0f67b50d86613 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 10:04:46 +1000 Subject: [PATCH 098/169] Modify SPI initialisation to 16-bit transfers --- ZodiacFX/src/stacking.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index c25a1ca..da71cb4 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -120,7 +120,7 @@ void spi_slave_initialize(void) spi_set_peripheral_chip_select_value(SPI_SLAVE_BASE, SPI_CHIP_SEL); spi_set_clock_polarity(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY); spi_set_clock_phase(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE); - spi_set_bits_per_transfer(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT); + spi_set_bits_per_transfer(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_16_BIT); spi_enable_interrupt(SPI_SLAVE_BASE, SPI_IER_RDRF); spi_enable(SPI_SLAVE_BASE); ioport_set_pin_level(SPI_IRQ1, false); @@ -143,7 +143,7 @@ void spi_master_initialize(void) spi_disable_loopback(SPI_MASTER_BASE); spi_set_peripheral_chip_select_value(SPI_MASTER_BASE, SPI_CHIP_SEL); spi_set_transfer_delay(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_DLYBS, SPI_DLYBCT); - spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT); + spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_16_BIT); spi_set_baudrate_div(SPI_MASTER_BASE, SPI_CHIP_SEL, (ul_sysclk_div)); spi_set_clock_polarity(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY); spi_set_clock_phase(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE); From 54f0aa4ff7221513c1f72c4bb4a30f6a6a50ec6d Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 10:09:07 +1000 Subject: [PATCH 099/169] Discard reads during master -> slave transfer Function call currently kept for timing --- ZodiacFX/src/stacking.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index da71cb4..a7f744d 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -265,14 +265,14 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) // Send the SPI packet header for(uint16_t ct=0; ct Date: Mon, 15 May 2017 10:47:05 +1000 Subject: [PATCH 100/169] Add padding to spi packet Fix alignment for 16-bit transfers --- ZodiacFX/src/stacking.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 3ff7532..5377f53 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -43,7 +43,7 @@ #define SPI_STATS_PREAMBLE 0xABAB #define SPI_PACKET_PREAMBLE 0xBCBC #define SPI_SEND_WAIT 0 -#define SPI_HEADER_SIZE 13 +#define SPI_HEADER_SIZE 14 struct spi_port_stats { uint16_t premable; @@ -62,6 +62,7 @@ struct spi_packet { uint32_t ul_rcv_size; // Actual packet size uint32_t spi_crc; // Calculated CRC of packet uint8_t tag; // Port number (1-8, or 255) + uint8_t pad; // Pad to 14 bytes uint8_t pkt_buffer[GMAC_FRAME_LENTGH_MAX]; }; From 3383aa94e0e04a6e1e9a4614cbbe7c6991b7dfb1 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 10:47:32 +1000 Subject: [PATCH 101/169] Add master -> slave 16-bit transfers --- ZodiacFX/src/stacking.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index a7f744d..a5682b0 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -263,17 +263,17 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); // Send the SPI packet header - for(uint16_t ct=0; ct>8); // upper 8 bits - if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 3) + if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 4) { spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) @@ -526,7 +513,7 @@ void SPI_Handler(void) if(spi_count < (spi_read_size-1)) { // Wait for next interrupt - spi_count++; + spi_count+=2; return; } From 638681bc30a9bf1eb5fc302220f9d1a46b224bcc Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 11:13:55 +1000 Subject: [PATCH 102/169] Comment out port stats Removed while 16-bit transfers are implemented - will be re-implemented after. --- ZodiacFX/src/stacking.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index a5682b0..f2cc68c 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -424,22 +424,22 @@ void SPI_Handler(void) if(pending_spi_command == SPI_SEND_STATS) // We send the master our port stats { - if (spi_slave_send_count <= 0) - { - if (spi_dummy_bytes < 2) - { - spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); - spi_dummy_bytes++; - return; - } - pending_spi_command = SPI_SEND_READY; // Clear the pending command - ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done - spi_dummy_bytes = 0; - } else { - spi_write(SPI_SLAVE_BASE, spi_stats_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); - spi_slave_send_count--; - } - return; + //static uint16_t spi_slave_send_count; + //if (spi_slave_send_count <= 0) + //{ + //if (spi_dummy_bytes < 2) + //{ + //spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); + //spi_dummy_bytes++; + //return; + //} + //pending_spi_command = SPI_SEND_READY; // Clear the pending command + //ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done + //spi_dummy_bytes = 0; + //} else { + //spi_write(SPI_SLAVE_BASE, spi_stats_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); + //} + //return; } if(pending_spi_command == SPI_SEND_PKT) // Send slave packet to master From a5e24d9363e7aca705ee85163f58897ba002822d Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 11:47:23 +1000 Subject: [PATCH 103/169] Add slave -> master 16-bit transfers --- ZodiacFX/src/stacking.c | 70 +++++++++++++++++++---------------------- ZodiacFX/src/switch.c | 2 -- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index f2cc68c..63c81ba 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -63,12 +63,10 @@ extern struct ofp13_port_stats phys13_port_stats[8]; // Local variables uint16_t spi_slave_send_size; -uint16_t spi_slave_send_count; uint8_t timer_alt; uint8_t pending_spi_command = SPI_SEND_READY; bool master_ready; bool slave_ready; -uint8_t spi_dummy_bytes = 0; struct spi_port_stats spi_p_stats; uint8_t spi_stats_rr = 0; uint8_t spi_stats_buffer[sizeof(struct spi_port_stats)]; @@ -174,7 +172,6 @@ void Slave_timer(void) ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something pending_spi_command = SPI_SEND_STATS; // We are waiting to send port stats spi_slave_send_size = sizeof(struct spi_port_stats); - spi_slave_send_count = spi_slave_send_size; timer_alt = 0; } return; @@ -292,32 +289,34 @@ void MasterStackRcv(void) uint16_t spi_read_size; uint32_t spi_crc_rcv; - spi_read_size = 1600; + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; // ignore dummy bytes - spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + spi_read(SPI_MASTER_BASE, &data, &uc_pcs); spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + spi_read(SPI_MASTER_BASE, &data, &uc_pcs); spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); while(spi_count < spi_read_size) { - spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + spi_read(SPI_MASTER_BASE, &data, &uc_pcs); spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); + + shared_buffer[spi_count] = data; // lower 8 bits + shared_buffer[spi_count+1] = (data>>8); // upper 8 bits + // MAY CAUSE TIMING PROBLEMS - if(spi_read_size == 1600) + if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 4) { - if(spi_count == 3) + spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); + if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) { - spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); - if(spi_read_size > 1600) - { - spi_read_size = 1600; - } + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; } } - spi_count++; + + spi_count+=2; while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); } printf("stacking.c: ------- ------- Slave -> Master %d\r\n", sys_get_ms() - rcv_time); @@ -391,7 +390,10 @@ void MasterStackRcv(void) phys13_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; phys13_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; } + + return; } + return; } @@ -443,29 +445,24 @@ void SPI_Handler(void) } if(pending_spi_command == SPI_SEND_PKT) // Send slave packet to master - { - if (spi_slave_send_count <= 0) + { + for(uint16_t ct=0; ct 0) - { - spi_write(SPI_SLAVE_BASE, shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); - spi_slave_send_count--; - // Wait for master to send the next byte - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - } + spi_write(SPI_SLAVE_BASE, *(uint16_t*)&shared_buffer[ct], 0, 0); + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); // ***** ***** TODO: MODIFY TO IF STATEMENT; REMOVE spi_slave_send_count ***** ***** + spi_read(SPI_SLAVE_BASE, NULL, NULL); } + + // Flush out last two bytes + for(uint8_t spi_dummy_bytes=0; spi_dummy_bytes<2; spi_dummy_bytes++) + { + spi_write(SPI_SLAVE_BASE, 0xFFFF, 0, 0); // ***** + spi_dummy_bytes++; + } + + // Cleanup + pending_spi_command = SPI_SEND_READY; // Clear the pending command + ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done return; } @@ -605,7 +602,6 @@ uint8_t slavemaster_test(void) spi_packet->spi_size = SPI_HEADER_SIZE + 1400; pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet spi_slave_send_size = spi_packet->spi_size; - spi_slave_send_count = spi_slave_send_size; ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something } return; diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index a8f4142..25c3056 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -53,7 +53,6 @@ extern struct spi_packet *spi_packet; extern bool slave_ready; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern uint16_t spi_slave_send_size; -extern uint16_t spi_slave_send_count; // Local variables gmac_device_t gs_gmac_dev; @@ -598,7 +597,6 @@ void task_switch(struct netif *netif) //memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); //pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet //spi_slave_send_size = spi_packet->spi_size; - //spi_slave_send_count = spi_slave_send_size; //ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something return; } From a31c4ace1432c7d42d3dfe7c91f7cdf2151486bb Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 12:44:54 +1000 Subject: [PATCH 104/169] Add debug variables --- ZodiacFX/src/openflow/openflow.c | 19 +++++++++++++++++++ ZodiacFX/src/stacking.c | 17 ++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index 999c384..6b33138 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -87,6 +87,12 @@ void tcp_error(void * arg, err_t err); static err_t of_receive(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err); static err_t of_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len); +// ####### Stacking debug stats ####### +extern uint32_t spi_debug_slave_rx_errors; +extern uint32_t spi_debug_master_rx_errors; +extern uint32_t spi_debug_master_rx_count; +extern uint32_t spi_debug_master_tx_count; + /* * Converts a 64bit value from host to network format * @@ -357,6 +363,19 @@ void task_openflow(void) fast_of_timer = sys_get_ms(); nnOF_timer(); if (stackenabled == true) masterslave_test(); + + // ####### print master debug stats every 5s ####### + static time_ctr = 0; + if(time_ctr == 10) + { + printf("master rx errors: %d\nmaster rx count: %d\nmaster tx count: %d\n",spi_debug_master_rx_errors,spi_debug_master_rx_count,spi_debug_master_tx_count); + time_ctr = 0; + } + else + { + time_ctr++; + } + // ####### END ####### if (heartbeat > (HB_INTERVAL * 2) && tcp_con_state == 1) //If we haven't heard anything from the controller for more then the heartbeat interval send an echo request { diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 63c81ba..5079332 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -81,6 +81,12 @@ void spi_slave_initialize(void); void spi_port_stats(void); void spi_port_status(void); +// ########## Test Variables ########## +uint32_t spi_debug_slave_rx_errors = 0; +uint32_t spi_debug_master_rx_errors = 0; +uint32_t spi_debug_master_rx_count = 0; +uint32_t spi_debug_master_tx_count = 0; + /* * Initialize the SPI interface to MASTER or SLAVE based on the stacking jumper * @@ -325,6 +331,7 @@ void MasterStackRcv(void) if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) { TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE"); + spi_debug_master_rx_errors++; return; } @@ -336,6 +343,7 @@ void MasterStackRcv(void) if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) { TRACE("stacking.c: ERROR - BAD PACKET SIZE"); + spi_debug_master_rx_errors++; return; // Packet size is corrupt } for(int x = 0;xul_rcv_size;x++) @@ -346,8 +354,12 @@ void MasterStackRcv(void) if (spi_packet->spi_crc != spi_crc_rcv) { TRACE("stacking.c: Corrupt slave packet CRC mismatch %x != %x",spi_packet->spi_crc ,spi_crc_rcv); + spi_debug_master_rx_errors++; return; } + + spi_debug_master_rx_count++; + TRACE("stacking.c: received packet (%d bytes)", spi_packet->ul_rcv_size); // Copy packet into Ethernet buffer memcpy(gs_uc_eth_buffer, &spi_packet->pkt_buffer, GMAC_FRAME_LENTGH_MAX); @@ -445,7 +457,7 @@ void SPI_Handler(void) } if(pending_spi_command == SPI_SEND_PKT) // Send slave packet to master - { + { for(uint16_t ct=0; ct Date: Mon, 15 May 2017 12:45:09 +1000 Subject: [PATCH 105/169] Move spi read call --- ZodiacFX/src/stacking.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 5079332..5c702e9 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -460,16 +460,16 @@ void SPI_Handler(void) { for(uint16_t ct=0; ct Date: Mon, 15 May 2017 14:12:25 +1000 Subject: [PATCH 106/169] Revert "Move spi read call" This reverts commit 0e69522fc9074d13f5f15bf962244238b3520ac1. --- ZodiacFX/src/stacking.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 5c702e9..5079332 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -460,16 +460,16 @@ void SPI_Handler(void) { for(uint16_t ct=0; ct Date: Mon, 15 May 2017 14:12:28 +1000 Subject: [PATCH 107/169] Revert "Add debug variables" This reverts commit a31c4ace1432c7d42d3dfe7c91f7cdf2151486bb. --- ZodiacFX/src/openflow/openflow.c | 19 ------------------- ZodiacFX/src/stacking.c | 17 +---------------- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index 6b33138..999c384 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -87,12 +87,6 @@ void tcp_error(void * arg, err_t err); static err_t of_receive(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err); static err_t of_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len); -// ####### Stacking debug stats ####### -extern uint32_t spi_debug_slave_rx_errors; -extern uint32_t spi_debug_master_rx_errors; -extern uint32_t spi_debug_master_rx_count; -extern uint32_t spi_debug_master_tx_count; - /* * Converts a 64bit value from host to network format * @@ -363,19 +357,6 @@ void task_openflow(void) fast_of_timer = sys_get_ms(); nnOF_timer(); if (stackenabled == true) masterslave_test(); - - // ####### print master debug stats every 5s ####### - static time_ctr = 0; - if(time_ctr == 10) - { - printf("master rx errors: %d\nmaster rx count: %d\nmaster tx count: %d\n",spi_debug_master_rx_errors,spi_debug_master_rx_count,spi_debug_master_tx_count); - time_ctr = 0; - } - else - { - time_ctr++; - } - // ####### END ####### if (heartbeat > (HB_INTERVAL * 2) && tcp_con_state == 1) //If we haven't heard anything from the controller for more then the heartbeat interval send an echo request { diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 5079332..63c81ba 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -81,12 +81,6 @@ void spi_slave_initialize(void); void spi_port_stats(void); void spi_port_status(void); -// ########## Test Variables ########## -uint32_t spi_debug_slave_rx_errors = 0; -uint32_t spi_debug_master_rx_errors = 0; -uint32_t spi_debug_master_rx_count = 0; -uint32_t spi_debug_master_tx_count = 0; - /* * Initialize the SPI interface to MASTER or SLAVE based on the stacking jumper * @@ -331,7 +325,6 @@ void MasterStackRcv(void) if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) { TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE"); - spi_debug_master_rx_errors++; return; } @@ -343,7 +336,6 @@ void MasterStackRcv(void) if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) { TRACE("stacking.c: ERROR - BAD PACKET SIZE"); - spi_debug_master_rx_errors++; return; // Packet size is corrupt } for(int x = 0;xul_rcv_size;x++) @@ -354,12 +346,8 @@ void MasterStackRcv(void) if (spi_packet->spi_crc != spi_crc_rcv) { TRACE("stacking.c: Corrupt slave packet CRC mismatch %x != %x",spi_packet->spi_crc ,spi_crc_rcv); - spi_debug_master_rx_errors++; return; } - - spi_debug_master_rx_count++; - TRACE("stacking.c: received packet (%d bytes)", spi_packet->ul_rcv_size); // Copy packet into Ethernet buffer memcpy(gs_uc_eth_buffer, &spi_packet->pkt_buffer, GMAC_FRAME_LENTGH_MAX); @@ -457,7 +445,7 @@ void SPI_Handler(void) } if(pending_spi_command == SPI_SEND_PKT) // Send slave packet to master - { + { for(uint16_t ct=0; ct Date: Mon, 15 May 2017 14:12:31 +1000 Subject: [PATCH 108/169] Revert "Add slave -> master 16-bit transfers" This reverts commit a5e24d9363e7aca705ee85163f58897ba002822d. --- ZodiacFX/src/stacking.c | 70 ++++++++++++++++++++++------------------- ZodiacFX/src/switch.c | 2 ++ 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 63c81ba..f2cc68c 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -63,10 +63,12 @@ extern struct ofp13_port_stats phys13_port_stats[8]; // Local variables uint16_t spi_slave_send_size; +uint16_t spi_slave_send_count; uint8_t timer_alt; uint8_t pending_spi_command = SPI_SEND_READY; bool master_ready; bool slave_ready; +uint8_t spi_dummy_bytes = 0; struct spi_port_stats spi_p_stats; uint8_t spi_stats_rr = 0; uint8_t spi_stats_buffer[sizeof(struct spi_port_stats)]; @@ -172,6 +174,7 @@ void Slave_timer(void) ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something pending_spi_command = SPI_SEND_STATS; // We are waiting to send port stats spi_slave_send_size = sizeof(struct spi_port_stats); + spi_slave_send_count = spi_slave_send_size; timer_alt = 0; } return; @@ -289,34 +292,32 @@ void MasterStackRcv(void) uint16_t spi_read_size; uint32_t spi_crc_rcv; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + spi_read_size = 1600; // ignore dummy bytes - spi_read(SPI_MASTER_BASE, &data, &uc_pcs); + spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_MASTER_BASE, &data, &uc_pcs); + spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); while(spi_count < spi_read_size) { - spi_read(SPI_MASTER_BASE, &data, &uc_pcs); + spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); - - shared_buffer[spi_count] = data; // lower 8 bits - shared_buffer[spi_count+1] = (data>>8); // upper 8 bits - // MAY CAUSE TIMING PROBLEMS - if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 4) + if(spi_read_size == 1600) { - spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); - if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) + if(spi_count == 3) { - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); + if(spi_read_size > 1600) + { + spi_read_size = 1600; + } } } - - spi_count+=2; + spi_count++; while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); } printf("stacking.c: ------- ------- Slave -> Master %d\r\n", sys_get_ms() - rcv_time); @@ -390,10 +391,7 @@ void MasterStackRcv(void) phys13_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; phys13_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; } - - return; } - return; } @@ -445,24 +443,29 @@ void SPI_Handler(void) } if(pending_spi_command == SPI_SEND_PKT) // Send slave packet to master - { - for(uint16_t ct=0; ct 0) + { + spi_write(SPI_SLAVE_BASE, shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); + spi_slave_send_count--; + // Wait for master to send the next byte + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + } } - - // Cleanup - pending_spi_command = SPI_SEND_READY; // Clear the pending command - ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done return; } @@ -602,6 +605,7 @@ uint8_t slavemaster_test(void) spi_packet->spi_size = SPI_HEADER_SIZE + 1400; pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet spi_slave_send_size = spi_packet->spi_size; + spi_slave_send_count = spi_slave_send_size; ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something } return; diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 25c3056..a8f4142 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -53,6 +53,7 @@ extern struct spi_packet *spi_packet; extern bool slave_ready; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern uint16_t spi_slave_send_size; +extern uint16_t spi_slave_send_count; // Local variables gmac_device_t gs_gmac_dev; @@ -597,6 +598,7 @@ void task_switch(struct netif *netif) //memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); //pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet //spi_slave_send_size = spi_packet->spi_size; + //spi_slave_send_count = spi_slave_send_size; //ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something return; } From 211f47a0e12cb9031cd5b62bbc422f06787650b5 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 14:12:36 +1000 Subject: [PATCH 109/169] Revert "Comment out port stats" This reverts commit 638681bc30a9bf1eb5fc302220f9d1a46b224bcc. --- ZodiacFX/src/stacking.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index f2cc68c..a5682b0 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -424,22 +424,22 @@ void SPI_Handler(void) if(pending_spi_command == SPI_SEND_STATS) // We send the master our port stats { - //static uint16_t spi_slave_send_count; - //if (spi_slave_send_count <= 0) - //{ - //if (spi_dummy_bytes < 2) - //{ - //spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); - //spi_dummy_bytes++; - //return; - //} - //pending_spi_command = SPI_SEND_READY; // Clear the pending command - //ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done - //spi_dummy_bytes = 0; - //} else { - //spi_write(SPI_SLAVE_BASE, spi_stats_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); - //} - //return; + if (spi_slave_send_count <= 0) + { + if (spi_dummy_bytes < 2) + { + spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); + spi_dummy_bytes++; + return; + } + pending_spi_command = SPI_SEND_READY; // Clear the pending command + ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done + spi_dummy_bytes = 0; + } else { + spi_write(SPI_SLAVE_BASE, spi_stats_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); + spi_slave_send_count--; + } + return; } if(pending_spi_command == SPI_SEND_PKT) // Send slave packet to master From 75e7a4b0a85e9ca9b56692a2fac3cd983a2be2bf Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 14:12:42 +1000 Subject: [PATCH 110/169] Revert "Add master -> slave 16-bit transfers" This reverts commit 3383aa94e0e04a6e1e9a4614cbbe7c6991b7dfb1. --- ZodiacFX/src/stacking.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index a5682b0..a7f744d 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -263,17 +263,17 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); // Send the SPI packet header - for(uint16_t ct=0; ct>8); // upper 8 bits + spi_read(SPI_SLAVE_BASE, &shared_buffer[spi_count], &uc_pcs); - if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 4) + if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 3) { spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) @@ -513,7 +526,7 @@ void SPI_Handler(void) if(spi_count < (spi_read_size-1)) { // Wait for next interrupt - spi_count+=2; + spi_count++; return; } From dab20e27e7ac68beb05a584ed5ffbc5bb2993c1c Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 14:23:56 +1000 Subject: [PATCH 111/169] Modify test output messages --- ZodiacFX/src/stacking.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index a7f744d..63cc809 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -320,7 +320,7 @@ void MasterStackRcv(void) spi_count++; while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); } - printf("stacking.c: ------- ------- Slave -> Master %d\r\n", sys_get_ms() - rcv_time); + printf("stacking.c: ------- ------- rtt %d\r\n", sys_get_ms() - rcv_time); TRACE("stacking.c: MASTER received preamble - %x, %x", shared_buffer[0], shared_buffer[1]); if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) @@ -357,6 +357,7 @@ void MasterStackRcv(void) phys13_port_stats[spi_packet->tag-1].rx_packets++; // Send packet to OpenFlow table lookup function for processing nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); + printf("stacking.c: ------- ------- response ok\r\n"); return; } else if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) From 6d781003bbfb8cf4d2a80f557e5b26d1fe1c4080 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 14:39:32 +1000 Subject: [PATCH 112/169] Re-commit master -> slave 16-bit transfers --- ZodiacFX/src/stacking.c | 43 +++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 63cc809..8fd1709 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -263,17 +263,17 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); // Send the SPI packet header - for(uint16_t ct=0; ct SLAVE receiver ***** static uint16_t spi_count = 2; static uint16_t spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + + // Write preamble to SPI packet header + shared_buffer[0] = 0xBC; + shared_buffer[1] = 0xBC; // Read next byte spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_SLAVE_BASE, &shared_buffer[spi_count], &uc_pcs); + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + + shared_buffer[spi_count] = data; // lower 8 bits + shared_buffer[spi_count+1] = (data>>8); // upper 8 bits - if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 3) + if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 4) { spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) @@ -523,11 +512,12 @@ void SPI_Handler(void) } } + // Increment the index + spi_count+=2; // Check if more bytes need to be read if(spi_count < (spi_read_size-1)) { // Wait for next interrupt - spi_count++; return; } @@ -578,7 +568,6 @@ void SPI_Handler(void) spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; slavemaster_test(); return; - } } From 1408f959f67200fdda5f0d9a67bfa94547a68420 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 14:41:15 +1000 Subject: [PATCH 113/169] Remove hard-coded maximum spi packet size --- ZodiacFX/src/stacking.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 8fd1709..ee0ad83 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -292,7 +292,7 @@ void MasterStackRcv(void) uint16_t spi_read_size; uint32_t spi_crc_rcv; - spi_read_size = 1600; + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; // ignore dummy bytes spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); @@ -306,14 +306,14 @@ void MasterStackRcv(void) spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); // MAY CAUSE TIMING PROBLEMS - if(spi_read_size == 1600) + if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) { if(spi_count == 3) { spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); - if(spi_read_size > 1600) + if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) { - spi_read_size = 1600; + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; } } } From b1c694bb7b3b0541582d5f985677cead583e90c9 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 14:50:05 +1000 Subject: [PATCH 114/169] Re-commit modified slave -> master 16-bit transfers --- ZodiacFX/src/stacking.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index ee0ad83..2156752 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -63,7 +63,7 @@ extern struct ofp13_port_stats phys13_port_stats[8]; // Local variables uint16_t spi_slave_send_size; -uint16_t spi_slave_send_count; +int32_t spi_slave_send_count; uint8_t timer_alt; uint8_t pending_spi_command = SPI_SEND_READY; bool master_ready; @@ -303,12 +303,16 @@ void MasterStackRcv(void) while(spi_count < spi_read_size) { - spi_read(SPI_MASTER_BASE, &shared_buffer[spi_count], &uc_pcs); + // Read 2 bytes and store into buffer + spi_read(SPI_MASTER_BASE, &data, &uc_pcs); + shared_buffer[spi_count] = data; // lower 8 bits + shared_buffer[spi_count+1] = (data>>8); // upper 8 bits + spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); // MAY CAUSE TIMING PROBLEMS if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) { - if(spi_count == 3) + if(spi_count == 4) { spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) @@ -317,7 +321,7 @@ void MasterStackRcv(void) } } } - spi_count++; + spi_count+=2; while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); } printf("stacking.c: ------- ------- rtt %d\r\n", sys_get_ms() - rcv_time); @@ -457,11 +461,13 @@ void SPI_Handler(void) pending_spi_command = SPI_SEND_READY; // Clear the pending command ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done spi_dummy_bytes = 0; - } else { + } + else + { while(spi_slave_send_count > 0) { - spi_write(SPI_SLAVE_BASE, shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); - spi_slave_send_count--; + spi_write(SPI_SLAVE_BASE, *(uint16_t*)&shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); + spi_slave_send_count-=2; // Wait for master to send the next byte while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); From 5e1b28889acbbce283ea111e1bb12f309fe24a58 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 15:04:58 +1000 Subject: [PATCH 115/169] Move master -> slave receiver into loop --- ZodiacFX/src/stacking.c | 50 ++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 2156752..1764b71 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -495,37 +495,37 @@ void SPI_Handler(void) // Write preamble to SPI packet header shared_buffer[0] = 0xBC; shared_buffer[1] = 0xBC; - - // Read next byte - spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - - shared_buffer[spi_count] = data; // lower 8 bits - shared_buffer[spi_count+1] = (data>>8); // upper 8 bits - if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 4) + /***** Receive the rest of the packet *****/ + + while(spi_count < (spi_read_size-1)) { - spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); - if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) + spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); + + shared_buffer[spi_count] = data; // lower 8 bits + shared_buffer[spi_count+1] = (data>>8); // upper 8 bits + + if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 4) { - // ERROR: over-sized packet data - // Clean up and return - pending_spi_command = SPI_SEND_READY; - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - return; + spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); + if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) + { + // ERROR: over-sized packet data + // Clean up and return + pending_spi_command = SPI_SEND_READY; + spi_count = 2; + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + return; + } } + + // Increment the counter + spi_count+=2; } - // Increment the index - spi_count+=2; - // Check if more bytes need to be read - if(spi_count < (spi_read_size-1)) - { - // Wait for next interrupt - return; - } + /***** Process the received packet *****/ uint32_t spi_crc_rcv = 0; spi_packet = &shared_buffer; From 8ded4fc7c98101416324d6a1eb4775ba5b869788 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 15:20:03 +1000 Subject: [PATCH 116/169] Add master-side stacking debug output --- ZodiacFX/src/openflow/openflow.c | 21 +++++++++++++++++++++ ZodiacFX/src/stacking.c | 7 +++++++ ZodiacFX/src/stacking.h | 10 +++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index 999c384..36427fd 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -87,6 +87,9 @@ void tcp_error(void * arg, err_t err); static err_t of_receive(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err); static err_t of_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len); +// ####### SPI debug output ####### +extern struct spi_debug_stats spi_debug; + /* * Converts a 64bit value from host to network format * @@ -357,6 +360,24 @@ void task_openflow(void) fast_of_timer = sys_get_ms(); nnOF_timer(); if (stackenabled == true) masterslave_test(); + + // ####### print master debug stats every 5s ####### + static time_ctr = 0; + if(time_ctr == 10) + { + printf("master tx packets: %d\r\nmaster rx packets: %d\r\nmaster rx bad size: %d\r\nmaster rx bad preamble: %d\r\nmaster rx bad crc: %d\r\n",\ + spi_debug.master_tx_count,\ + spi_debug.master_rx_count,\ + spi_debug.master_rx_error_bad_size,\ + spi_debug.master_rx_error_bad_preamble,\ + spi_debug.master_rx_error_bad_crc); + time_ctr = 0; + } + else + { + time_ctr++; + } + // ####### END ####### if (heartbeat > (HB_INTERVAL * 2) && tcp_con_state == 1) //If we haven't heard anything from the controller for more then the heartbeat interval send an echo request { diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 1764b71..2c31cbc 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -83,6 +83,8 @@ void spi_slave_initialize(void); void spi_port_stats(void); void spi_port_status(void); +struct spi_debug_stats spi_debug; + /* * Initialize the SPI interface to MASTER or SLAVE based on the stacking jumper * @@ -330,6 +332,7 @@ void MasterStackRcv(void) if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) { TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE"); + spi_debug.master_rx_error_bad_preamble++; return; } @@ -341,6 +344,7 @@ void MasterStackRcv(void) if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) { TRACE("stacking.c: ERROR - BAD PACKET SIZE"); + spi_debug.master_rx_error_bad_size++; return; // Packet size is corrupt } for(int x = 0;xul_rcv_size;x++) @@ -351,6 +355,7 @@ void MasterStackRcv(void) if (spi_packet->spi_crc != spi_crc_rcv) { TRACE("stacking.c: Corrupt slave packet CRC mismatch %x != %x",spi_packet->spi_crc ,spi_crc_rcv); + spi_debug.master_rx_error_bad_crc++; return; } TRACE("stacking.c: received packet (%d bytes)", spi_packet->ul_rcv_size); @@ -362,6 +367,7 @@ void MasterStackRcv(void) // Send packet to OpenFlow table lookup function for processing nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); printf("stacking.c: ------- ------- response ok\r\n"); + spi_debug.master_rx_count++; return; } else if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) @@ -588,6 +594,7 @@ uint8_t masterslave_test(void) shared_buffer[i] = pattern++; } rcv_time = sys_get_ms(); + spi_debug.master_tx_count++; MasterStackSend(&shared_buffer, 1400, 8); return; } diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 5377f53..c2b0caf 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -64,7 +64,15 @@ struct spi_packet { uint8_t tag; // Port number (1-8, or 255) uint8_t pad; // Pad to 14 bytes uint8_t pkt_buffer[GMAC_FRAME_LENTGH_MAX]; -}; +}; + +struct spi_debug_stats { + uint32_t master_tx_count; + uint32_t master_rx_count; + uint32_t master_rx_error_bad_preamble; + uint32_t master_rx_error_bad_size; + uint32_t master_rx_error_bad_crc; +}; void stacking_init(bool master); void MasterReady(void); From c7281501e7317c150c42068b34222b22781bf25c Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 15:52:08 +1000 Subject: [PATCH 117/169] Tweak stacking performance --- ZodiacFX/src/stacking.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 2c31cbc..a170e61 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -38,7 +38,7 @@ #include "timers.h" /* SPI clock setting (Hz). */ -static uint32_t gs_ul_spi_clock = 20000000; +static uint32_t gs_ul_spi_clock = 30000000; /* Chip select. */ #define SPI_CHIP_SEL 0 @@ -50,7 +50,7 @@ static uint32_t gs_ul_spi_clock = 20000000; /* Delay before SPCK. */ #define SPI_DLYBS 0x30 /* Delay between consecutive transfers. */ -#define SPI_DLYBCT 0x15 +#define SPI_DLYBCT 0x06 // Global variables extern uint8_t last_port_status[8]; From c094bbefd71765aff1fda8f7f3760449bfd0120b Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 15:52:23 +1000 Subject: [PATCH 118/169] Add spi register check timeout --- ZodiacFX/src/stacking.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index a170e61..2476abd 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -475,7 +475,20 @@ void SPI_Handler(void) spi_write(SPI_SLAVE_BASE, *(uint16_t*)&shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); spi_slave_send_count-=2; // Wait for master to send the next byte - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + uint16_t timeout = 0; + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0) + { + if(timeout > 100) + { + pending_spi_command = SPI_SEND_READY; // Clear the pending command + ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done + return; + } + else + { + timeout++; + } + } spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); } } @@ -507,7 +520,21 @@ void SPI_Handler(void) while(spi_count < (spi_read_size-1)) { spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0); + uint16_t timeout = 0; + while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0) + { + if(timeout > 100) + { + pending_spi_command = SPI_SEND_READY; // Clear the pending command + spi_count = 2; + spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + return; + } + else + { + timeout++; + } + } spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); shared_buffer[spi_count] = data; // lower 8 bits From ddb12d6f8b3712ba82e7b9b73af075bea7a204db Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 16:10:41 +1000 Subject: [PATCH 119/169] Merge slave->master packet & stats send states --- ZodiacFX/src/stacking.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 2476abd..99d260f 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -432,28 +432,8 @@ void SPI_Handler(void) return; } } - - if(pending_spi_command == SPI_SEND_STATS) // We send the master our port stats - { - if (spi_slave_send_count <= 0) - { - if (spi_dummy_bytes < 2) - { - spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); - spi_dummy_bytes++; - return; - } - pending_spi_command = SPI_SEND_READY; // Clear the pending command - ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done - spi_dummy_bytes = 0; - } else { - spi_write(SPI_SLAVE_BASE, spi_stats_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); - spi_slave_send_count--; - } - return; - } - if(pending_spi_command == SPI_SEND_PKT) // Send slave packet to master + if(pending_spi_command == SPI_SEND_PKT || pending_spi_command == SPI_SEND_STATS) // Send data to master { if (spi_slave_send_count <= 0) { From 7eb4a190b37d597d3ace43ade4114bb41bbb54d3 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 16:11:01 +1000 Subject: [PATCH 120/169] Fix typo --- ZodiacFX/src/stacking.c | 6 +++--- ZodiacFX/src/stacking.h | 4 ++-- ZodiacFX/src/switch.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 99d260f..e37d086 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -170,7 +170,7 @@ void Slave_timer(void) // Send SLAVE port stats if SLAVE is in the clear state if (slave_ready == true && pending_spi_command == SPI_SEND_READY) { - spi_p_stats.premable = SPI_STATS_PREAMBLE; + spi_p_stats.preamble = SPI_STATS_PREAMBLE; spi_p_stats.spi_size = sizeof(struct spi_port_stats); memcpy(&spi_stats_buffer, &spi_p_stats, sizeof(struct spi_port_stats)); ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something @@ -251,7 +251,7 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) } // Prepare header (shared_buffer already contains the packet data) spi_packet = &spi_head_buffer; - spi_packet->premable = SPI_PACKET_PREAMBLE; + spi_packet->preamble = SPI_PACKET_PREAMBLE; spi_packet->ul_rcv_size = ul_size; spi_packet->spi_crc = 0; // Calculate CRC value @@ -613,7 +613,7 @@ uint8_t slavemaster_test(void) { // PREPARE TEST PACKET from SLAVE to MASTER spi_packet = &shared_buffer; - spi_packet->premable = SPI_PACKET_PREAMBLE; + spi_packet->preamble = SPI_PACKET_PREAMBLE; spi_packet->ul_rcv_size = 1400; spi_packet->spi_crc = 0; uint8_t*ind_ptr = &spi_packet->pkt_buffer; diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index c2b0caf..2cff7dc 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -46,7 +46,7 @@ #define SPI_HEADER_SIZE 14 struct spi_port_stats { - uint16_t premable; + uint16_t preamble; uint16_t spi_size; uint8_t port_status[4]; uint8_t last_port_status[4]; @@ -57,7 +57,7 @@ struct spi_port_stats { }; struct spi_packet { - uint16_t premable; // Transmission preamble + uint16_t preamble; // Transmission preamble uint16_t spi_size; // SPI transmission size uint32_t ul_rcv_size; // Actual packet size uint32_t spi_crc; // Calculated CRC of packet diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index a8f4142..73129c0 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -586,7 +586,7 @@ void task_switch(struct netif *netif) //phys13_port_stats[tag-1].rx_packets++; //ul_rcv_size--; // remove the tail first //spi_packet = &shared_buffer; - //spi_packet->premable = SPI_PACKET_PREAMBLE; + //spi_packet->preamble = SPI_PACKET_PREAMBLE; //spi_packet->ul_rcv_size = ul_rcv_size; //spi_packet->spi_crc = 0; //for(int x = 0;x Date: Mon, 15 May 2017 16:13:42 +1000 Subject: [PATCH 121/169] Comment out stacking test functions --- ZodiacFX/src/openflow/openflow.c | 38 ++++++++++++++++---------------- ZodiacFX/src/stacking.c | 7 +++--- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index 36427fd..e7272ac 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -359,25 +359,25 @@ void task_openflow(void) { fast_of_timer = sys_get_ms(); nnOF_timer(); - if (stackenabled == true) masterslave_test(); - - // ####### print master debug stats every 5s ####### - static time_ctr = 0; - if(time_ctr == 10) - { - printf("master tx packets: %d\r\nmaster rx packets: %d\r\nmaster rx bad size: %d\r\nmaster rx bad preamble: %d\r\nmaster rx bad crc: %d\r\n",\ - spi_debug.master_tx_count,\ - spi_debug.master_rx_count,\ - spi_debug.master_rx_error_bad_size,\ - spi_debug.master_rx_error_bad_preamble,\ - spi_debug.master_rx_error_bad_crc); - time_ctr = 0; - } - else - { - time_ctr++; - } - // ####### END ####### + ////if (stackenabled == true) masterslave_test(); + //// + ////// ####### print master debug stats every 5s ####### + ////static time_ctr = 0; + ////if(time_ctr == 10) + ////{ + ////printf("master tx packets: %d\r\nmaster rx packets: %d\r\nmaster rx bad size: %d\r\nmaster rx bad preamble: %d\r\nmaster rx bad crc: %d\r\n",\ + ////spi_debug.master_tx_count,\ + ////spi_debug.master_rx_count,\ + ////spi_debug.master_rx_error_bad_size,\ + ////spi_debug.master_rx_error_bad_preamble,\ + ////spi_debug.master_rx_error_bad_crc); + ////time_ctr = 0; + ////} + ////else + ////{ + ////time_ctr++; + ////} + ////// ####### END ####### if (heartbeat > (HB_INTERVAL * 2) && tcp_con_state == 1) //If we haven't heard anything from the controller for more then the heartbeat interval send an echo request { diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index e37d086..2bffb20 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -326,7 +326,7 @@ void MasterStackRcv(void) spi_count+=2; while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); } - printf("stacking.c: ------- ------- rtt %d\r\n", sys_get_ms() - rcv_time); + ////printf("stacking.c: ------- ------- rtt %d\r\n", sys_get_ms() - rcv_time); TRACE("stacking.c: MASTER received preamble - %x, %x", shared_buffer[0], shared_buffer[1]); if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) @@ -366,7 +366,7 @@ void MasterStackRcv(void) phys13_port_stats[spi_packet->tag-1].rx_packets++; // Send packet to OpenFlow table lookup function for processing nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); - printf("stacking.c: ------- ------- response ok\r\n"); + ////printf("stacking.c: ------- ------- response ok\r\n"); spi_debug.master_rx_count++; return; } @@ -551,7 +551,6 @@ void SPI_Handler(void) pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - //slavemaster_test(); return; } @@ -585,7 +584,7 @@ void SPI_Handler(void) pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - slavemaster_test(); + ////slavemaster_test(); return; } From ff84405e48270a4ade641dbc92c93ac11be95a56 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 16:20:08 +1000 Subject: [PATCH 122/169] Re-commit packet handling --- ZodiacFX/src/switch.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 73129c0..5e077f7 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -580,26 +580,26 @@ void task_switch(struct netif *netif) { if (slave_ready == true && pending_spi_command == SPI_SEND_READY) { - //uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); - //uint8_t tag = *tail_tag + 1; - //phys10_port_stats[tag-1].rx_packets++; - //phys13_port_stats[tag-1].rx_packets++; - //ul_rcv_size--; // remove the tail first - //spi_packet = &shared_buffer; - //spi_packet->preamble = SPI_PACKET_PREAMBLE; - //spi_packet->ul_rcv_size = ul_rcv_size; - //spi_packet->spi_crc = 0; - //for(int x = 0;xspi_crc += gs_uc_eth_buffer[x]; - //} - //spi_packet->tag = tag + 4; - //spi_packet->spi_size = 11 + ul_rcv_size; - //memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); - //pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet - //spi_slave_send_size = spi_packet->spi_size; - //spi_slave_send_count = spi_slave_send_size; - //ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something + uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); + uint8_t tag = *tail_tag + 1; + phys10_port_stats[tag-1].rx_packets++; + phys13_port_stats[tag-1].rx_packets++; + ul_rcv_size--; // remove the tail first + spi_packet = &shared_buffer; + spi_packet->preamble = SPI_PACKET_PREAMBLE; + spi_packet->ul_rcv_size = ul_rcv_size; + spi_packet->spi_crc = 0; + for(int x = 0;xspi_crc += gs_uc_eth_buffer[x]; + } + spi_packet->tag = tag + 4; + spi_packet->spi_size = 11 + ul_rcv_size; + memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); + pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet + spi_slave_send_size = spi_packet->spi_size; + spi_slave_send_count = spi_slave_send_size; + ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something return; } } From 9500f530e02f66e95b81154abfef8d90d22c3c5b Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 17:00:54 +1000 Subject: [PATCH 123/169] Fix spi header length --- ZodiacFX/src/switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 5e077f7..9717910 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -594,7 +594,7 @@ void task_switch(struct netif *netif) spi_packet->spi_crc += gs_uc_eth_buffer[x]; } spi_packet->tag = tag + 4; - spi_packet->spi_size = 11 + ul_rcv_size; + spi_packet->spi_size = SPI_HEADER_SIZE + ul_rcv_size; memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet spi_slave_send_size = spi_packet->spi_size; From 521b6736048de844f8dec2a7f9c05b6507be480b Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 15 May 2017 17:25:47 +1000 Subject: [PATCH 124/169] Re-enable packet processing --- ZodiacFX/src/switch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 9717910..fdb8f0a 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -327,7 +327,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) TRACE("switch.c: Packet out FLOOD (%d bytes)", ul_size); if(masterselect == false) { - //MasterStackSend(p_buffer, ul_size, port); // Send it slave + MasterStackSend(p_buffer, ul_size, port); // Send it slave if (inport < 5) { port = (15 - NativePortMatrix) - (1<<(inport-1)); @@ -350,7 +350,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) if(masterselect == false) // If we are the master then send to the slave { TRACE("switch13.c: Sending packet to slave to send out port %d (%d bytes)", port, ul_size); - //MasterStackSend(p_buffer, ul_size, port); // Send it slave + MasterStackSend(p_buffer, ul_size, port); // Send it slave return; } // If slave then write to port @@ -528,7 +528,7 @@ void task_switch(struct netif *netif) if((sys_get_ms() - slave_timer) > 500) // every 500 ms (0.5 secs) { slave_timer = sys_get_ms(); - //Slave_timer(); // Slave timer + Slave_timer(); // Slave timer } } From 08521d69d79eec723aef9f1654f530f9ed854e96 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 11:04:11 +1000 Subject: [PATCH 125/169] Fix SPI stats send --- ZodiacFX/src/stacking.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 2bffb20..435e4d9 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -71,7 +71,6 @@ bool slave_ready; uint8_t spi_dummy_bytes = 0; struct spi_port_stats spi_p_stats; uint8_t spi_stats_rr = 0; -uint8_t spi_stats_buffer[sizeof(struct spi_port_stats)]; struct spi_packet *spi_packet; bool end_check; uint8_t spi_receive_port = 0; @@ -172,7 +171,7 @@ void Slave_timer(void) { spi_p_stats.preamble = SPI_STATS_PREAMBLE; spi_p_stats.spi_size = sizeof(struct spi_port_stats); - memcpy(&spi_stats_buffer, &spi_p_stats, sizeof(struct spi_port_stats)); + memcpy(&shared_buffer, &spi_p_stats, sizeof(struct spi_port_stats)); ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something pending_spi_command = SPI_SEND_STATS; // We are waiting to send port stats spi_slave_send_size = sizeof(struct spi_port_stats); From 7d0c523b94424c477f1e12d7a5cfce45ba07b374 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 11:04:48 +1000 Subject: [PATCH 126/169] Revert "Fix SPI stats send" This reverts commit 08521d69d79eec723aef9f1654f530f9ed854e96. --- ZodiacFX/src/stacking.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 435e4d9..2bffb20 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -71,6 +71,7 @@ bool slave_ready; uint8_t spi_dummy_bytes = 0; struct spi_port_stats spi_p_stats; uint8_t spi_stats_rr = 0; +uint8_t spi_stats_buffer[sizeof(struct spi_port_stats)]; struct spi_packet *spi_packet; bool end_check; uint8_t spi_receive_port = 0; @@ -171,7 +172,7 @@ void Slave_timer(void) { spi_p_stats.preamble = SPI_STATS_PREAMBLE; spi_p_stats.spi_size = sizeof(struct spi_port_stats); - memcpy(&shared_buffer, &spi_p_stats, sizeof(struct spi_port_stats)); + memcpy(&spi_stats_buffer, &spi_p_stats, sizeof(struct spi_port_stats)); ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something pending_spi_command = SPI_SEND_STATS; // We are waiting to send port stats spi_slave_send_size = sizeof(struct spi_port_stats); From 754759b35387870635ae9e3465153ce2ece9aa02 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 11:04:51 +1000 Subject: [PATCH 127/169] Revert "Re-enable packet processing" This reverts commit 521b6736048de844f8dec2a7f9c05b6507be480b. --- ZodiacFX/src/switch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index fdb8f0a..9717910 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -327,7 +327,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) TRACE("switch.c: Packet out FLOOD (%d bytes)", ul_size); if(masterselect == false) { - MasterStackSend(p_buffer, ul_size, port); // Send it slave + //MasterStackSend(p_buffer, ul_size, port); // Send it slave if (inport < 5) { port = (15 - NativePortMatrix) - (1<<(inport-1)); @@ -350,7 +350,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) if(masterselect == false) // If we are the master then send to the slave { TRACE("switch13.c: Sending packet to slave to send out port %d (%d bytes)", port, ul_size); - MasterStackSend(p_buffer, ul_size, port); // Send it slave + //MasterStackSend(p_buffer, ul_size, port); // Send it slave return; } // If slave then write to port @@ -528,7 +528,7 @@ void task_switch(struct netif *netif) if((sys_get_ms() - slave_timer) > 500) // every 500 ms (0.5 secs) { slave_timer = sys_get_ms(); - Slave_timer(); // Slave timer + //Slave_timer(); // Slave timer } } From 08bb69754033991f0ed39e3642c7a898fb1403b6 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 11:05:02 +1000 Subject: [PATCH 128/169] Revert "Fix spi header length" This reverts commit 9500f530e02f66e95b81154abfef8d90d22c3c5b. --- ZodiacFX/src/switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 9717910..5e077f7 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -594,7 +594,7 @@ void task_switch(struct netif *netif) spi_packet->spi_crc += gs_uc_eth_buffer[x]; } spi_packet->tag = tag + 4; - spi_packet->spi_size = SPI_HEADER_SIZE + ul_rcv_size; + spi_packet->spi_size = 11 + ul_rcv_size; memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet spi_slave_send_size = spi_packet->spi_size; From b640dadc5a23f04246b139cfddf9aa392f0177f7 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 11:05:14 +1000 Subject: [PATCH 129/169] Revert "Re-commit packet handling" This reverts commit ff84405e48270a4ade641dbc92c93ac11be95a56. --- ZodiacFX/src/switch.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 5e077f7..73129c0 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -580,26 +580,26 @@ void task_switch(struct netif *netif) { if (slave_ready == true && pending_spi_command == SPI_SEND_READY) { - uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); - uint8_t tag = *tail_tag + 1; - phys10_port_stats[tag-1].rx_packets++; - phys13_port_stats[tag-1].rx_packets++; - ul_rcv_size--; // remove the tail first - spi_packet = &shared_buffer; - spi_packet->preamble = SPI_PACKET_PREAMBLE; - spi_packet->ul_rcv_size = ul_rcv_size; - spi_packet->spi_crc = 0; - for(int x = 0;xspi_crc += gs_uc_eth_buffer[x]; - } - spi_packet->tag = tag + 4; - spi_packet->spi_size = 11 + ul_rcv_size; - memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); - pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet - spi_slave_send_size = spi_packet->spi_size; - spi_slave_send_count = spi_slave_send_size; - ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something + //uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); + //uint8_t tag = *tail_tag + 1; + //phys10_port_stats[tag-1].rx_packets++; + //phys13_port_stats[tag-1].rx_packets++; + //ul_rcv_size--; // remove the tail first + //spi_packet = &shared_buffer; + //spi_packet->preamble = SPI_PACKET_PREAMBLE; + //spi_packet->ul_rcv_size = ul_rcv_size; + //spi_packet->spi_crc = 0; + //for(int x = 0;xspi_crc += gs_uc_eth_buffer[x]; + //} + //spi_packet->tag = tag + 4; + //spi_packet->spi_size = 11 + ul_rcv_size; + //memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); + //pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet + //spi_slave_send_size = spi_packet->spi_size; + //spi_slave_send_count = spi_slave_send_size; + //ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something return; } } From 9f94995c1e8f46e882152efd8f40d088be2cc861 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 11:05:36 +1000 Subject: [PATCH 130/169] Revert "Comment out stacking test functions" This reverts commit 1ec5e3795512a58eaa9f3b0ff7cffa68318e4885. --- ZodiacFX/src/openflow/openflow.c | 38 ++++++++++++++++---------------- ZodiacFX/src/stacking.c | 7 +++--- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index e7272ac..36427fd 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -359,25 +359,25 @@ void task_openflow(void) { fast_of_timer = sys_get_ms(); nnOF_timer(); - ////if (stackenabled == true) masterslave_test(); - //// - ////// ####### print master debug stats every 5s ####### - ////static time_ctr = 0; - ////if(time_ctr == 10) - ////{ - ////printf("master tx packets: %d\r\nmaster rx packets: %d\r\nmaster rx bad size: %d\r\nmaster rx bad preamble: %d\r\nmaster rx bad crc: %d\r\n",\ - ////spi_debug.master_tx_count,\ - ////spi_debug.master_rx_count,\ - ////spi_debug.master_rx_error_bad_size,\ - ////spi_debug.master_rx_error_bad_preamble,\ - ////spi_debug.master_rx_error_bad_crc); - ////time_ctr = 0; - ////} - ////else - ////{ - ////time_ctr++; - ////} - ////// ####### END ####### + if (stackenabled == true) masterslave_test(); + + // ####### print master debug stats every 5s ####### + static time_ctr = 0; + if(time_ctr == 10) + { + printf("master tx packets: %d\r\nmaster rx packets: %d\r\nmaster rx bad size: %d\r\nmaster rx bad preamble: %d\r\nmaster rx bad crc: %d\r\n",\ + spi_debug.master_tx_count,\ + spi_debug.master_rx_count,\ + spi_debug.master_rx_error_bad_size,\ + spi_debug.master_rx_error_bad_preamble,\ + spi_debug.master_rx_error_bad_crc); + time_ctr = 0; + } + else + { + time_ctr++; + } + // ####### END ####### if (heartbeat > (HB_INTERVAL * 2) && tcp_con_state == 1) //If we haven't heard anything from the controller for more then the heartbeat interval send an echo request { diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 2bffb20..e37d086 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -326,7 +326,7 @@ void MasterStackRcv(void) spi_count+=2; while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); } - ////printf("stacking.c: ------- ------- rtt %d\r\n", sys_get_ms() - rcv_time); + printf("stacking.c: ------- ------- rtt %d\r\n", sys_get_ms() - rcv_time); TRACE("stacking.c: MASTER received preamble - %x, %x", shared_buffer[0], shared_buffer[1]); if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) @@ -366,7 +366,7 @@ void MasterStackRcv(void) phys13_port_stats[spi_packet->tag-1].rx_packets++; // Send packet to OpenFlow table lookup function for processing nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); - ////printf("stacking.c: ------- ------- response ok\r\n"); + printf("stacking.c: ------- ------- response ok\r\n"); spi_debug.master_rx_count++; return; } @@ -551,6 +551,7 @@ void SPI_Handler(void) pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + //slavemaster_test(); return; } @@ -584,7 +585,7 @@ void SPI_Handler(void) pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - ////slavemaster_test(); + slavemaster_test(); return; } From 8c3d9fa0630690cdfea95dcec91b6aae74a7368b Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 11:07:16 +1000 Subject: [PATCH 131/169] Revert "Revert "Comment out stacking test functions"" This reverts commit 9f94995c1e8f46e882152efd8f40d088be2cc861. --- ZodiacFX/src/openflow/openflow.c | 38 ++++++++++++++++---------------- ZodiacFX/src/stacking.c | 7 +++--- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index 36427fd..e7272ac 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -359,25 +359,25 @@ void task_openflow(void) { fast_of_timer = sys_get_ms(); nnOF_timer(); - if (stackenabled == true) masterslave_test(); - - // ####### print master debug stats every 5s ####### - static time_ctr = 0; - if(time_ctr == 10) - { - printf("master tx packets: %d\r\nmaster rx packets: %d\r\nmaster rx bad size: %d\r\nmaster rx bad preamble: %d\r\nmaster rx bad crc: %d\r\n",\ - spi_debug.master_tx_count,\ - spi_debug.master_rx_count,\ - spi_debug.master_rx_error_bad_size,\ - spi_debug.master_rx_error_bad_preamble,\ - spi_debug.master_rx_error_bad_crc); - time_ctr = 0; - } - else - { - time_ctr++; - } - // ####### END ####### + ////if (stackenabled == true) masterslave_test(); + //// + ////// ####### print master debug stats every 5s ####### + ////static time_ctr = 0; + ////if(time_ctr == 10) + ////{ + ////printf("master tx packets: %d\r\nmaster rx packets: %d\r\nmaster rx bad size: %d\r\nmaster rx bad preamble: %d\r\nmaster rx bad crc: %d\r\n",\ + ////spi_debug.master_tx_count,\ + ////spi_debug.master_rx_count,\ + ////spi_debug.master_rx_error_bad_size,\ + ////spi_debug.master_rx_error_bad_preamble,\ + ////spi_debug.master_rx_error_bad_crc); + ////time_ctr = 0; + ////} + ////else + ////{ + ////time_ctr++; + ////} + ////// ####### END ####### if (heartbeat > (HB_INTERVAL * 2) && tcp_con_state == 1) //If we haven't heard anything from the controller for more then the heartbeat interval send an echo request { diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index e37d086..2bffb20 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -326,7 +326,7 @@ void MasterStackRcv(void) spi_count+=2; while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); } - printf("stacking.c: ------- ------- rtt %d\r\n", sys_get_ms() - rcv_time); + ////printf("stacking.c: ------- ------- rtt %d\r\n", sys_get_ms() - rcv_time); TRACE("stacking.c: MASTER received preamble - %x, %x", shared_buffer[0], shared_buffer[1]); if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) @@ -366,7 +366,7 @@ void MasterStackRcv(void) phys13_port_stats[spi_packet->tag-1].rx_packets++; // Send packet to OpenFlow table lookup function for processing nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); - printf("stacking.c: ------- ------- response ok\r\n"); + ////printf("stacking.c: ------- ------- response ok\r\n"); spi_debug.master_rx_count++; return; } @@ -551,7 +551,6 @@ void SPI_Handler(void) pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - //slavemaster_test(); return; } @@ -585,7 +584,7 @@ void SPI_Handler(void) pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - slavemaster_test(); + ////slavemaster_test(); return; } From 483d341faa3c24489a225fdefc09d5c983b051e6 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 11:08:00 +1000 Subject: [PATCH 132/169] Revert "Revert "Re-commit packet handling"" This reverts commit b640dadc5a23f04246b139cfddf9aa392f0177f7. --- ZodiacFX/src/switch.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 73129c0..5e077f7 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -580,26 +580,26 @@ void task_switch(struct netif *netif) { if (slave_ready == true && pending_spi_command == SPI_SEND_READY) { - //uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); - //uint8_t tag = *tail_tag + 1; - //phys10_port_stats[tag-1].rx_packets++; - //phys13_port_stats[tag-1].rx_packets++; - //ul_rcv_size--; // remove the tail first - //spi_packet = &shared_buffer; - //spi_packet->preamble = SPI_PACKET_PREAMBLE; - //spi_packet->ul_rcv_size = ul_rcv_size; - //spi_packet->spi_crc = 0; - //for(int x = 0;xspi_crc += gs_uc_eth_buffer[x]; - //} - //spi_packet->tag = tag + 4; - //spi_packet->spi_size = 11 + ul_rcv_size; - //memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); - //pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet - //spi_slave_send_size = spi_packet->spi_size; - //spi_slave_send_count = spi_slave_send_size; - //ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something + uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); + uint8_t tag = *tail_tag + 1; + phys10_port_stats[tag-1].rx_packets++; + phys13_port_stats[tag-1].rx_packets++; + ul_rcv_size--; // remove the tail first + spi_packet = &shared_buffer; + spi_packet->preamble = SPI_PACKET_PREAMBLE; + spi_packet->ul_rcv_size = ul_rcv_size; + spi_packet->spi_crc = 0; + for(int x = 0;xspi_crc += gs_uc_eth_buffer[x]; + } + spi_packet->tag = tag + 4; + spi_packet->spi_size = 11 + ul_rcv_size; + memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); + pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet + spi_slave_send_size = spi_packet->spi_size; + spi_slave_send_count = spi_slave_send_size; + ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something return; } } From 9119e8c89741d1f6c47ef1ed856704b46839f2ca Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 11:09:13 +1000 Subject: [PATCH 133/169] Revert "Revert "Fix spi header length"" This reverts commit 08bb69754033991f0ed39e3642c7a898fb1403b6. --- ZodiacFX/src/switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 5e077f7..9717910 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -594,7 +594,7 @@ void task_switch(struct netif *netif) spi_packet->spi_crc += gs_uc_eth_buffer[x]; } spi_packet->tag = tag + 4; - spi_packet->spi_size = 11 + ul_rcv_size; + spi_packet->spi_size = SPI_HEADER_SIZE + ul_rcv_size; memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet spi_slave_send_size = spi_packet->spi_size; From 1b98cab9c19dbebac59732615effdeb6ca21986a Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 11:09:44 +1000 Subject: [PATCH 134/169] Revert "Revert "Re-enable packet processing"" This reverts commit 754759b35387870635ae9e3465153ce2ece9aa02. --- ZodiacFX/src/switch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 9717910..fdb8f0a 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -327,7 +327,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) TRACE("switch.c: Packet out FLOOD (%d bytes)", ul_size); if(masterselect == false) { - //MasterStackSend(p_buffer, ul_size, port); // Send it slave + MasterStackSend(p_buffer, ul_size, port); // Send it slave if (inport < 5) { port = (15 - NativePortMatrix) - (1<<(inport-1)); @@ -350,7 +350,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) if(masterselect == false) // If we are the master then send to the slave { TRACE("switch13.c: Sending packet to slave to send out port %d (%d bytes)", port, ul_size); - //MasterStackSend(p_buffer, ul_size, port); // Send it slave + MasterStackSend(p_buffer, ul_size, port); // Send it slave return; } // If slave then write to port @@ -528,7 +528,7 @@ void task_switch(struct netif *netif) if((sys_get_ms() - slave_timer) > 500) // every 500 ms (0.5 secs) { slave_timer = sys_get_ms(); - //Slave_timer(); // Slave timer + Slave_timer(); // Slave timer } } From 89906c361999b924e69329a65399d947595a3b0a Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 11:10:33 +1000 Subject: [PATCH 135/169] Revert "Revert "Fix SPI stats send"" This reverts commit 7d0c523b94424c477f1e12d7a5cfce45ba07b374. --- ZodiacFX/src/stacking.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 2bffb20..435e4d9 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -71,7 +71,6 @@ bool slave_ready; uint8_t spi_dummy_bytes = 0; struct spi_port_stats spi_p_stats; uint8_t spi_stats_rr = 0; -uint8_t spi_stats_buffer[sizeof(struct spi_port_stats)]; struct spi_packet *spi_packet; bool end_check; uint8_t spi_receive_port = 0; @@ -172,7 +171,7 @@ void Slave_timer(void) { spi_p_stats.preamble = SPI_STATS_PREAMBLE; spi_p_stats.spi_size = sizeof(struct spi_port_stats); - memcpy(&spi_stats_buffer, &spi_p_stats, sizeof(struct spi_port_stats)); + memcpy(&shared_buffer, &spi_p_stats, sizeof(struct spi_port_stats)); ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something pending_spi_command = SPI_SEND_STATS; // We are waiting to send port stats spi_slave_send_size = sizeof(struct spi_port_stats); From d3980218c8308b86949f9207f561e22afc4710ae Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 18:04:36 +1000 Subject: [PATCH 136/169] Move spi debug stats into separate command --- ZodiacFX/src/command.c | 11 +++++++++++ ZodiacFX/src/openflow/openflow.c | 18 ------------------ ZodiacFX/src/stacking.c | 3 ++- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index 7e8f433..7f17187 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -1661,6 +1661,17 @@ void command_debug(char *command, char *param1, char *param2, char *param3) return; } + if (strcmp(command, "spi_stats")==0) + { + printf("master tx packets: %d\r\nmaster rx packets: %d\r\nmaster rx bad size: %d\r\nmaster rx bad preamble: %d\r\nmaster rx bad crc: %d\r\n",\ + spi_debug.master_tx_count,\ + spi_debug.master_rx_count,\ + spi_debug.master_rx_error_bad_size,\ + spi_debug.master_rx_error_bad_preamble,\ + spi_debug.master_rx_error_bad_crc + ); + } + // Unknown Command response printf("Unknown command\r\n"); return; diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index e7272ac..87d18d8 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -360,24 +360,6 @@ void task_openflow(void) fast_of_timer = sys_get_ms(); nnOF_timer(); ////if (stackenabled == true) masterslave_test(); - //// - ////// ####### print master debug stats every 5s ####### - ////static time_ctr = 0; - ////if(time_ctr == 10) - ////{ - ////printf("master tx packets: %d\r\nmaster rx packets: %d\r\nmaster rx bad size: %d\r\nmaster rx bad preamble: %d\r\nmaster rx bad crc: %d\r\n",\ - ////spi_debug.master_tx_count,\ - ////spi_debug.master_rx_count,\ - ////spi_debug.master_rx_error_bad_size,\ - ////spi_debug.master_rx_error_bad_preamble,\ - ////spi_debug.master_rx_error_bad_crc); - ////time_ctr = 0; - ////} - ////else - ////{ - ////time_ctr++; - ////} - ////// ####### END ####### if (heartbeat > (HB_INTERVAL * 2) && tcp_con_state == 1) //If we haven't heard anything from the controller for more then the heartbeat interval send an echo request { diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 435e4d9..8e8b127 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -278,6 +278,8 @@ void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); } + spi_debug.master_tx_count++; + return; } @@ -599,7 +601,6 @@ uint8_t masterslave_test(void) shared_buffer[i] = pattern++; } rcv_time = sys_get_ms(); - spi_debug.master_tx_count++; MasterStackSend(&shared_buffer, 1400, 8); return; } From 503c42a742d10c287cc1784f096335e82e8b2260 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 18:54:41 +1000 Subject: [PATCH 137/169] Add slave receive debug --- ZodiacFX/src/command.c | 18 ++++++++++++++++++ ZodiacFX/src/main.c | 3 ++- ZodiacFX/src/openflow/openflow.c | 3 --- ZodiacFX/src/stacking.c | 8 ++++++++ ZodiacFX/src/stacking.h | 7 +++++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index 7f17187..b267f17 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -38,6 +38,7 @@ #include "eeprom.h" #include "switch.h" #include "flash.h" +#include "stacking.h" #include "openflow/openflow.h" #include "openflow/of_helper.h" #include "lwip/def.h" @@ -84,6 +85,8 @@ uint8_t uCLIContext = 0; struct arp_header arp_test; uint8_t esc_char = 0; +// ####### SPI debug output ####### +extern struct spi_debug_stats spi_debug; // Internal Functions void saveConfig(void); @@ -1670,6 +1673,21 @@ void command_debug(char *command, char *param1, char *param2, char *param3) spi_debug.master_rx_error_bad_preamble,\ spi_debug.master_rx_error_bad_crc ); + return; + } + + if (strcmp(command, "spi_stats_slave")==0) + { + printf("slave tx packets: %d\r\nslave rx packets: %d\r\nslave tx timeout errors: %d\r\nslave rx timeout errors: %d\r\nslave rx bad size: %d\r\nslave rx bad preamble: %d\r\nslave rx bad crc: %d\r\n",\ + spi_debug.slave_tx_count,\ + spi_debug.slave_rx_count,\ + spi_debug.slave_tx_error_timeout,\ + spi_debug.slave_rx_error_timeout,\ + spi_debug.slave_rx_error_bad_size,\ + spi_debug.slave_rx_error_bad_preamble,\ + spi_debug.slave_rx_error_bad_crc + ); + return; } // Unknown Command response diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c index 6beb3bf..07ffcb9 100644 --- a/ZodiacFX/src/main.c +++ b/ZodiacFX/src/main.c @@ -202,10 +202,11 @@ int main (void) while(1) { task_switch(&gs_net_if); + task_command(cCommand, cCommand_last); // Only run the following tasks if set to Master if(masterselect == false) { - task_command(cCommand, cCommand_last); + //task_command(cCommand, cCommand_last); sys_check_timeouts(); task_openflow(); } diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index 87d18d8..89d320c 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -87,9 +87,6 @@ void tcp_error(void * arg, err_t err); static err_t of_receive(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err); static err_t of_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len); -// ####### SPI debug output ####### -extern struct spi_debug_stats spi_debug; - /* * Converts a 64bit value from host to network format * diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 8e8b127..9611c73 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -463,6 +463,8 @@ void SPI_Handler(void) { pending_spi_command = SPI_SEND_READY; // Clear the pending command ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done + + spi_debug.slave_tx_error_timeout++; return; } else @@ -472,6 +474,7 @@ void SPI_Handler(void) } spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); } + spi_debug.slave_tx_count++; } return; } @@ -509,6 +512,7 @@ void SPI_Handler(void) pending_spi_command = SPI_SEND_READY; // Clear the pending command spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + spi_debug.slave_rx_error_timeout++; return; } else @@ -531,6 +535,7 @@ void SPI_Handler(void) pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + spi_debug.slave_rx_error_bad_size++; return; } } @@ -552,6 +557,7 @@ void SPI_Handler(void) pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + spi_debug.slave_rx_error_bad_size++; return; } @@ -569,6 +575,7 @@ void SPI_Handler(void) pending_spi_command = SPI_SEND_READY; spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; + spi_debug.slave_rx_error_bad_crc++; return; } @@ -586,6 +593,7 @@ void SPI_Handler(void) spi_count = 2; spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; ////slavemaster_test(); + spi_debug.slave_rx_count++; return; } diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h index 2cff7dc..36e0243 100644 --- a/ZodiacFX/src/stacking.h +++ b/ZodiacFX/src/stacking.h @@ -72,6 +72,13 @@ struct spi_debug_stats { uint32_t master_rx_error_bad_preamble; uint32_t master_rx_error_bad_size; uint32_t master_rx_error_bad_crc; + uint32_t slave_tx_count; + uint32_t slave_rx_count; + uint32_t slave_tx_error_timeout; + uint32_t slave_rx_error_bad_preamble; + uint32_t slave_rx_error_bad_size; + uint32_t slave_rx_error_bad_crc; + uint32_t slave_rx_error_timeout; }; void stacking_init(bool master); From eb5f17c3254109319847ab2c5f40de33685f1121 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 16 May 2017 19:24:10 +1000 Subject: [PATCH 138/169] Lower spi clock for debug build --- ZodiacFX/src/stacking.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c index 9611c73..6d4fb9f 100644 --- a/ZodiacFX/src/stacking.c +++ b/ZodiacFX/src/stacking.c @@ -38,7 +38,7 @@ #include "timers.h" /* SPI clock setting (Hz). */ -static uint32_t gs_ul_spi_clock = 30000000; +static uint32_t gs_ul_spi_clock = 10000000; /* Chip select. */ #define SPI_CHIP_SEL 0 From 04aaf88f01e49082f41e2a811c370138a1364307 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:21:46 +1000 Subject: [PATCH 139/169] Remove stacking source files --- ZodiacFX/src/command.c | 1 - ZodiacFX/src/main.c | 1 - ZodiacFX/src/openflow/openflow.c | 1 - ZodiacFX/src/stacking.c | 642 ------------------------------- ZodiacFX/src/stacking.h | 94 ----- ZodiacFX/src/switch.c | 1 - 6 files changed, 740 deletions(-) delete mode 100644 ZodiacFX/src/stacking.c delete mode 100644 ZodiacFX/src/stacking.h diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index b267f17..3afb6b8 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -38,7 +38,6 @@ #include "eeprom.h" #include "switch.h" #include "flash.h" -#include "stacking.h" #include "openflow/openflow.h" #include "openflow/of_helper.h" #include "lwip/def.h" diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c index 07ffcb9..7b1e664 100644 --- a/ZodiacFX/src/main.c +++ b/ZodiacFX/src/main.c @@ -42,7 +42,6 @@ #include "command.h" #include "eeprom.h" #include "switch.h" -#include "stacking.h" #include "http.h" #include "flash.h" #include "openflow/openflow.h" diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index 89d320c..c2aed17 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -39,7 +39,6 @@ #include "lwip/tcp.h" #include "lwip/err.h" #include "timers.h" -#include "stacking.h" // Global variables extern struct zodiac_config Zodiac_Config; diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c deleted file mode 100644 index 6d4fb9f..0000000 --- a/ZodiacFX/src/stacking.c +++ /dev/null @@ -1,642 +0,0 @@ -/** - * @file - * stacking.c - * - * This file contains the stacking functions - * - */ - -/* - * This file is part of the Zodiac FX firmware. - * Copyright (c) 2017 Northbound Networks. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Authors: Paul Zanna - * & Kristopher Chen - * - */ - -#include -#include -#include "stacking.h" -#include "trace.h" -#include "switch.h" -#include "lwip/def.h" -#include "openflow/openflow.h" -#include "timers.h" - -/* SPI clock setting (Hz). */ -static uint32_t gs_ul_spi_clock = 10000000; - -/* Chip select. */ -#define SPI_CHIP_SEL 0 -#define SPI_CHIP_PCS spi_get_pcs(SPI_CHIP_SEL) -/* Clock polarity. */ -#define SPI_CLK_POLARITY 0 -/* Clock phase. */ -#define SPI_CLK_PHASE 0 -/* Delay before SPCK. */ -#define SPI_DLYBS 0x30 -/* Delay between consecutive transfers. */ -#define SPI_DLYBCT 0x06 - -// Global variables -extern uint8_t last_port_status[8]; -extern uint8_t port_status[8]; -extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; -extern uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; -extern int OF_Version; -extern struct ofp10_port_stats phys10_port_stats[8]; -extern struct ofp13_port_stats phys13_port_stats[8]; - -// Local variables -uint16_t spi_slave_send_size; -int32_t spi_slave_send_count; -uint8_t timer_alt; -uint8_t pending_spi_command = SPI_SEND_READY; -bool master_ready; -bool slave_ready; -uint8_t spi_dummy_bytes = 0; -struct spi_port_stats spi_p_stats; -uint8_t spi_stats_rr = 0; -struct spi_packet *spi_packet; -bool end_check; -uint8_t spi_receive_port = 0; -uint16_t spi_receive_count; -uint32_t rcv_time; - -void spi_master_initialize(void); -void spi_slave_initialize(void); -void spi_port_stats(void); -void spi_port_status(void); - -struct spi_debug_stats spi_debug; - -/* -* Initialize the SPI interface to MASTER or SLAVE based on the stacking jumper -* -*/ -void stacking_init(bool master) -{ - if (master) - { - spi_slave_initialize(); - ioport_set_pin_dir(SPI_IRQ1, IOPORT_DIR_OUTPUT); - } else { - spi_master_initialize(); - ioport_set_pin_dir(SPI_IRQ1, IOPORT_DIR_INPUT); - } - return; -} - -/* -* Initialize the SPI interface as a SLAVE -* -*/ -void spi_slave_initialize(void) -{ - NVIC_DisableIRQ(SPI_IRQn); - NVIC_ClearPendingIRQ(SPI_IRQn); - NVIC_SetPriority(SPI_IRQn, 0); - NVIC_EnableIRQ(SPI_IRQn); - - /* Configure an SPI peripheral. */ - spi_enable_clock(SPI_SLAVE_BASE); - spi_disable(SPI_SLAVE_BASE); - spi_reset(SPI_SLAVE_BASE); - spi_set_slave_mode(SPI_SLAVE_BASE); - spi_disable_mode_fault_detect(SPI_SLAVE_BASE); - spi_set_peripheral_chip_select_value(SPI_SLAVE_BASE, SPI_CHIP_SEL); - spi_set_clock_polarity(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY); - spi_set_clock_phase(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE); - spi_set_bits_per_transfer(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_16_BIT); - spi_enable_interrupt(SPI_SLAVE_BASE, SPI_IER_RDRF); - spi_enable(SPI_SLAVE_BASE); - ioport_set_pin_level(SPI_IRQ1, false); -} - -/* -* Initialize the SPI interface as a MASTER -* -*/ -void spi_master_initialize(void) -{ - uint32_t ul_sysclk_div = sysclk_get_cpu_hz() / gs_ul_spi_clock; - /* Configure an SPI peripheral. */ - spi_enable_clock(SPI_MASTER_BASE); - spi_disable(SPI_MASTER_BASE); - spi_reset(SPI_MASTER_BASE); - spi_set_lastxfer(SPI_MASTER_BASE); - spi_set_master_mode(SPI_MASTER_BASE); - spi_disable_mode_fault_detect(SPI_MASTER_BASE); - spi_disable_loopback(SPI_MASTER_BASE); - spi_set_peripheral_chip_select_value(SPI_MASTER_BASE, SPI_CHIP_SEL); - spi_set_transfer_delay(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_DLYBS, SPI_DLYBCT); - spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_16_BIT); - spi_set_baudrate_div(SPI_MASTER_BASE, SPI_CHIP_SEL, (ul_sysclk_div)); - spi_set_clock_polarity(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY); - spi_set_clock_phase(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE); - - spi_enable(SPI_MASTER_BASE); -} - -void Slave_timer(void) -{ - if (timer_alt == 0) - { - spi_port_stats(); - timer_alt = 1; - return; - } else if (timer_alt == 1) - { - spi_port_status(); - timer_alt = 2; - return; - } else if (timer_alt == 2) - { - // Send SLAVE port stats if SLAVE is in the clear state - if (slave_ready == true && pending_spi_command == SPI_SEND_READY) - { - spi_p_stats.preamble = SPI_STATS_PREAMBLE; - spi_p_stats.spi_size = sizeof(struct spi_port_stats); - memcpy(&shared_buffer, &spi_p_stats, sizeof(struct spi_port_stats)); - ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something - pending_spi_command = SPI_SEND_STATS; // We are waiting to send port stats - spi_slave_send_size = sizeof(struct spi_port_stats); - spi_slave_send_count = spi_slave_send_size; - timer_alt = 0; - } - return; - } -} - -void spi_port_stats(void) -{ - spi_p_stats.tx_bytes[spi_stats_rr] += readtxbytes(spi_stats_rr+1); - spi_p_stats.rx_bytes[spi_stats_rr] += readrxbytes(spi_stats_rr+1); - spi_stats_rr++; - if (spi_stats_rr == 4) spi_stats_rr = 0; - return; -} - -void spi_port_status(void) -{ - // Copy out the old status so we know if it has changed - spi_p_stats.last_port_status[0] = spi_p_stats.port_status[0]; - spi_p_stats.last_port_status[1] = spi_p_stats.port_status[1]; - spi_p_stats.last_port_status[2] = spi_p_stats.port_status[2]; - spi_p_stats.last_port_status[3] = spi_p_stats.port_status[3]; - // Update port status - spi_p_stats.port_status[0] = (switch_read(30) & 32) >> 5; - spi_p_stats.port_status[1] = (switch_read(46) & 32) >> 5; - spi_p_stats.port_status[2] = (switch_read(62) & 32) >> 5; - spi_p_stats.port_status[3] = (switch_read(78) & 32) >> 5; - return; -} - -/* -* Master ready function -* -*/ -void MasterReady(void) -{ - spi_write(SPI_MASTER_BASE, 0xaa, 0, 0); - master_ready = true; - return; -} - -// ##################### SPI MASTER Send and Receive Functions ##################### - -/* -* Master send function -* -*/ -void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) -{ - uint8_t uc_pcs; - static uint16_t data; - uint8_t *p_buffer; - uint8_t outport; - - uint8_t spi_head_buffer[SPI_HEADER_SIZE] = {0}; - - if (port < 255) - { - outport = port; - phys10_port_stats[port-1].tx_packets++; - phys13_port_stats[port-1].tx_packets++; - } else { - port = 255; - if (port_status[4] == 1) phys10_port_stats[4].tx_packets++; - if (port_status[4] == 1) phys13_port_stats[4].tx_packets++; - if (port_status[5] == 1) phys10_port_stats[5].tx_packets++; - if (port_status[5] == 1) phys13_port_stats[5].tx_packets++; - if (port_status[6] == 1) phys10_port_stats[6].tx_packets++; - if (port_status[6] == 1) phys13_port_stats[6].tx_packets++; - if (port_status[7] == 1) phys10_port_stats[7].tx_packets++; - if (port_status[7] == 1) phys13_port_stats[7].tx_packets++; - } - // Prepare header (shared_buffer already contains the packet data) - spi_packet = &spi_head_buffer; - spi_packet->preamble = SPI_PACKET_PREAMBLE; - spi_packet->ul_rcv_size = ul_size; - spi_packet->spi_crc = 0; - // Calculate CRC value - for(int x = 0;xspi_crc += p_uc_data[x]; - } - spi_packet->tag = port; - spi_packet->spi_size = SPI_HEADER_SIZE + ul_size; - - TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); - - // Send the SPI packet header - for(uint16_t ct=0; ct>8); // upper 8 bits - - spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); - // MAY CAUSE TIMING PROBLEMS - if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) - { - if(spi_count == 4) - { - spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); - if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) - { - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - } - } - } - spi_count+=2; - while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - } - ////printf("stacking.c: ------- ------- rtt %d\r\n", sys_get_ms() - rcv_time); - - TRACE("stacking.c: MASTER received preamble - %x, %x", shared_buffer[0], shared_buffer[1]); - if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) - { - TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE"); - spi_debug.master_rx_error_bad_preamble++; - return; - } - - if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) - { - /* Process Received SPI Packet */ - spi_crc_rcv = 0; - spi_packet = &shared_buffer; - if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) - { - TRACE("stacking.c: ERROR - BAD PACKET SIZE"); - spi_debug.master_rx_error_bad_size++; - return; // Packet size is corrupt - } - for(int x = 0;xul_rcv_size;x++) - { - spi_crc_rcv += spi_packet->pkt_buffer[x]; - } - // Make sure we received the entire packet - if (spi_packet->spi_crc != spi_crc_rcv) - { - TRACE("stacking.c: Corrupt slave packet CRC mismatch %x != %x",spi_packet->spi_crc ,spi_crc_rcv); - spi_debug.master_rx_error_bad_crc++; - return; - } - TRACE("stacking.c: received packet (%d bytes)", spi_packet->ul_rcv_size); - // Copy packet into Ethernet buffer - memcpy(gs_uc_eth_buffer, &spi_packet->pkt_buffer, GMAC_FRAME_LENTGH_MAX); - // Update port stats - phys10_port_stats[spi_packet->tag-1].rx_packets++; - phys13_port_stats[spi_packet->tag-1].rx_packets++; - // Send packet to OpenFlow table lookup function for processing - nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); - ////printf("stacking.c: ------- ------- response ok\r\n"); - spi_debug.master_rx_count++; - return; - } - else if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) - { - /* Process Received Port Stats */ - TRACE("stacking.c: %d bytes of port stats data received from slave", spi_count); - memcpy(&spi_p_stats, &shared_buffer, sizeof(struct spi_port_stats)); - port_status[4] = spi_p_stats.port_status[0]; - port_status[5] = spi_p_stats.port_status[1]; - port_status[6] = spi_p_stats.port_status[2]; - port_status[7] = spi_p_stats.port_status[3]; - - if (OF_Version == 1) - { - phys10_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; - phys10_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; - phys10_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; - phys10_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; - phys10_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; - phys10_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; - phys10_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; - phys10_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; - } - else if (OF_Version == 4) - { - phys13_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; - phys13_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; - phys13_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; - phys13_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; - phys13_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; - phys13_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; - phys13_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; - phys13_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; - } - } - return; -} - -// ##################### SPI SLAVE Send and Receive Functions ##################### - -/* -* SPI interface IRQ handler -* Used to receive data from the stacking interface -* -*/ -void SPI_Handler(void) -{ - static uint16_t data; - static uint32_t receive_timeout = 0; // Timeout for SPI data receive (MASTER->SLAVE) - uint8_t uc_pcs; - - if (slave_ready == false) // Is this the first data we have received? - { - if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) - { - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xaa) - { - ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ - slave_ready = true; - } - return; - } - } - - if(pending_spi_command == SPI_SEND_PKT || pending_spi_command == SPI_SEND_STATS) // Send data to master - { - if (spi_slave_send_count <= 0) - { - // Flush out last two bytes - if (spi_dummy_bytes < 2) - { - spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); // ***** - spi_dummy_bytes++; - return; - } - pending_spi_command = SPI_SEND_READY; // Clear the pending command - ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done - spi_dummy_bytes = 0; - } - else - { - while(spi_slave_send_count > 0) - { - spi_write(SPI_SLAVE_BASE, *(uint16_t*)&shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); - spi_slave_send_count-=2; - // Wait for master to send the next byte - uint16_t timeout = 0; - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0) - { - if(timeout > 100) - { - pending_spi_command = SPI_SEND_READY; // Clear the pending command - ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done - - spi_debug.slave_tx_error_timeout++; - return; - } - else - { - timeout++; - } - } - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - } - spi_debug.slave_tx_count++; - } - return; - } - - if(pending_spi_command == SPI_SEND_READY) - { - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xBCBC) - { - pending_spi_command = SPI_RECEIVE; - } - return; - } - - if(pending_spi_command == SPI_RECEIVE) - { - // ***** Modified MASTER -> SLAVE receiver ***** - static uint16_t spi_count = 2; - static uint16_t spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - - // Write preamble to SPI packet header - shared_buffer[0] = 0xBC; - shared_buffer[1] = 0xBC; - - /***** Receive the rest of the packet *****/ - - while(spi_count < (spi_read_size-1)) - { - spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); - uint16_t timeout = 0; - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0) - { - if(timeout > 100) - { - pending_spi_command = SPI_SEND_READY; // Clear the pending command - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - spi_debug.slave_rx_error_timeout++; - return; - } - else - { - timeout++; - } - } - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - - shared_buffer[spi_count] = data; // lower 8 bits - shared_buffer[spi_count+1] = (data>>8); // upper 8 bits - - if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 4) - { - spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); - if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) - { - // ERROR: over-sized packet data - // Clean up and return - pending_spi_command = SPI_SEND_READY; - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - spi_debug.slave_rx_error_bad_size++; - return; - } - } - - // Increment the counter - spi_count+=2; - } - - /***** Process the received packet *****/ - - uint32_t spi_crc_rcv = 0; - spi_packet = &shared_buffer; - - // Check against maximum packet size - if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) - { - // ERROR: payload data too large - // Clean up and return - pending_spi_command = SPI_SEND_READY; - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - spi_debug.slave_rx_error_bad_size++; - return; - } - - // Calculated CRC of the received data - for(uint16_t ct=0; ctul_rcv_size; ct++) - { - spi_crc_rcv += spi_packet->pkt_buffer[ct]; - } - - // Check calculated CRC against received CRC - if (spi_packet->spi_crc != spi_crc_rcv) - { - // ERROR: corrupt packet - // Clean up and return - pending_spi_command = SPI_SEND_READY; - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - spi_debug.slave_rx_error_bad_crc++; - return; - } - - if (spi_packet->tag == 255) - { - gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, OFPP13_FLOOD, 0); - } - else if (spi_packet->tag <= 8) - { - gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, spi_packet->tag-4, 0); - } - // Packet receive complete - // Clean up and return - pending_spi_command = SPI_SEND_READY; - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - ////slavemaster_test(); - spi_debug.slave_rx_count++; - return; - } - -} - -// ##################### SPI Test Functions ##################### - -uint8_t masterslave_test(void) -{ - uint8_t pattern = 0; - for(uint16_t i=0;i<1400;i++) - { - shared_buffer[i] = pattern++; - } - rcv_time = sys_get_ms(); - MasterStackSend(&shared_buffer, 1400, 8); - return; -} - -uint8_t slavemaster_test(void) -{ - // Note: the pending check may need to be moved outside of the function call - if (slave_ready == true && pending_spi_command == SPI_SEND_READY) - { - // PREPARE TEST PACKET from SLAVE to MASTER - spi_packet = &shared_buffer; - spi_packet->preamble = SPI_PACKET_PREAMBLE; - spi_packet->ul_rcv_size = 1400; - spi_packet->spi_crc = 0; - uint8_t*ind_ptr = &spi_packet->pkt_buffer; - uint8_t walk = 0; - for(uint16_t x = 0;x<1400;x++) - { - ind_ptr[x] = walk; - spi_packet->spi_crc += walk; - walk++; - } - spi_packet->tag = 2 + 4; - spi_packet->spi_size = SPI_HEADER_SIZE + 1400; - pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet - spi_slave_send_size = spi_packet->spi_size; - spi_slave_send_count = spi_slave_send_size; - ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something - } - return; -} \ No newline at end of file diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h deleted file mode 100644 index 36e0243..0000000 --- a/ZodiacFX/src/stacking.h +++ /dev/null @@ -1,94 +0,0 @@ -/** - * @file - * command.c - * - * This file contains the command line functions - * - */ - -/* - * This file is part of the Zodiac FX firmware. - * Copyright (c) 2016 Northbound Networks. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Author: Paul Zanna - * - * - */ - - -#ifndef STACKING_H_ -#define STACKING_H_ - -#define SPI_Handler SPI_Handler -#define SPI_IRQn SPI_IRQn - -#define SPI_SEND_READY 0 -#define SPI_SEND_STATS 1 -#define SPI_SEND_PKT 2 -#define SPI_RECEIVE 3 -#define SPI_RCV_PREAMBLE 4 -#define SPI_STATS_PREAMBLE 0xABAB -#define SPI_PACKET_PREAMBLE 0xBCBC -#define SPI_SEND_WAIT 0 -#define SPI_HEADER_SIZE 14 - -struct spi_port_stats { - uint16_t preamble; - uint16_t spi_size; - uint8_t port_status[4]; - uint8_t last_port_status[4]; - uint64_t rx_bytes[4]; - uint64_t tx_bytes[4]; - uint64_t rx_dropped[4]; - uint64_t tx_dropped[4]; -}; - -struct spi_packet { - uint16_t preamble; // Transmission preamble - uint16_t spi_size; // SPI transmission size - uint32_t ul_rcv_size; // Actual packet size - uint32_t spi_crc; // Calculated CRC of packet - uint8_t tag; // Port number (1-8, or 255) - uint8_t pad; // Pad to 14 bytes - uint8_t pkt_buffer[GMAC_FRAME_LENTGH_MAX]; -}; - -struct spi_debug_stats { - uint32_t master_tx_count; - uint32_t master_rx_count; - uint32_t master_rx_error_bad_preamble; - uint32_t master_rx_error_bad_size; - uint32_t master_rx_error_bad_crc; - uint32_t slave_tx_count; - uint32_t slave_rx_count; - uint32_t slave_tx_error_timeout; - uint32_t slave_rx_error_bad_preamble; - uint32_t slave_rx_error_bad_size; - uint32_t slave_rx_error_bad_crc; - uint32_t slave_rx_error_timeout; -}; - -void stacking_init(bool master); -void MasterReady(void); -void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port); -void MasterStackRcv(void); -void Slave_timer(void); - -// ***** Stacking Test Functions ***** -uint8_t masterslave_test(void); // Send pattern from master -> slave -uint8_t slavemaster_test(void); // Send pattern from slave -> master - -#endif /* STACKING_H_ */ \ No newline at end of file diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index fdb8f0a..d323cdd 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -33,7 +33,6 @@ #include "trace.h" #include "openflow/openflow.h" #include "switch.h" -#include "stacking.h" #include "conf_eth.h" #include "command.h" #include "timers.h" From c7913f511e6784e2b4af13a37a528cf75c0f6210 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:24:27 +1000 Subject: [PATCH 140/169] Remove CLI SPI debug stats --- ZodiacFX/src/command.c | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index 3afb6b8..386b4a7 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -84,9 +84,6 @@ uint8_t uCLIContext = 0; struct arp_header arp_test; uint8_t esc_char = 0; -// ####### SPI debug output ####### -extern struct spi_debug_stats spi_debug; - // Internal Functions void saveConfig(void); void command_root(char *command, char *param1, char *param2, char *param3); @@ -1641,12 +1638,6 @@ void command_debug(char *command, char *param1, char *param2, char *param3) return; } - if (strcmp(command, "spi")==0) - { - //stack_write(atoi(param1)); - return; - } - if (strcmp(command, "mem")==0) { printf("mem total: %d\r\n", membag_get_total()); @@ -1663,32 +1654,6 @@ void command_debug(char *command, char *param1, char *param2, char *param3) return; } - if (strcmp(command, "spi_stats")==0) - { - printf("master tx packets: %d\r\nmaster rx packets: %d\r\nmaster rx bad size: %d\r\nmaster rx bad preamble: %d\r\nmaster rx bad crc: %d\r\n",\ - spi_debug.master_tx_count,\ - spi_debug.master_rx_count,\ - spi_debug.master_rx_error_bad_size,\ - spi_debug.master_rx_error_bad_preamble,\ - spi_debug.master_rx_error_bad_crc - ); - return; - } - - if (strcmp(command, "spi_stats_slave")==0) - { - printf("slave tx packets: %d\r\nslave rx packets: %d\r\nslave tx timeout errors: %d\r\nslave rx timeout errors: %d\r\nslave rx bad size: %d\r\nslave rx bad preamble: %d\r\nslave rx bad crc: %d\r\n",\ - spi_debug.slave_tx_count,\ - spi_debug.slave_rx_count,\ - spi_debug.slave_tx_error_timeout,\ - spi_debug.slave_rx_error_timeout,\ - spi_debug.slave_rx_error_bad_size,\ - spi_debug.slave_rx_error_bad_preamble,\ - spi_debug.slave_rx_error_bad_crc - ); - return; - } - // Unknown Command response printf("Unknown command\r\n"); return; From 531fc4c1551a2ab81ebd369fc8cae5077953ae12 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:30:19 +1000 Subject: [PATCH 141/169] Remove stacking tasks --- ZodiacFX/src/switch.c | 91 +++++++++---------------------------------- ZodiacFX/src/switch.h | 2 - 2 files changed, 18 insertions(+), 75 deletions(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index d323cdd..3fc7978 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -51,8 +51,6 @@ extern uint8_t pending_spi_command; extern struct spi_packet *spi_packet; extern bool slave_ready; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; -extern uint16_t spi_slave_send_size; -extern uint16_t spi_slave_send_count; // Local variables gmac_device_t gs_gmac_dev; @@ -62,7 +60,6 @@ struct ofp13_port_stats phys13_port_stats[8]; uint8_t port_status[8]; uint8_t last_port_status[8]; uint8_t total_ports = 4; -int slave_timer = 0; uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; uint8_t stats_rr = 0; @@ -507,32 +504,6 @@ void task_switch(struct netif *netif) uint8_t tag = 0; int8_t in_port = 0; - // Check if the slave device has a packet to send us - if(masterselect == false && ioport_get_pin_level(SPI_IRQ1) && stackenabled == true) - { - MasterStackRcv(); - } - - // Check if the slave device is connected and enable stacking - if(masterselect == false && !ioport_get_pin_level(SPI_IRQ1) && stackenabled == false) - { - MasterReady(); // Let the slave know the master is ready - stackenabled = true; - total_ports = 8; - } - - // Slave house keeping timer - if(masterselect == true) - { - if((sys_get_ms() - slave_timer) > 500) // every 500 ms (0.5 secs) - { - slave_timer = sys_get_ms(); - Slave_timer(); // Slave timer - } - - } - - /* Main packet processing loop */ uint32_t dev_read = gmac_dev_read(&gs_gmac_dev, (uint8_t *) gs_uc_eth_buffer, sizeof(gs_uc_eth_buffer), &ul_rcv_size); if (dev_read == GMAC_OK) @@ -550,55 +521,29 @@ void task_switch(struct netif *netif) } } - if(masterselect == false) // Only process packets if board is set to MASTER - { - if (ul_rcv_size > 0) - { - uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); - uint8_t tag = *tail_tag + 1; - if (Zodiac_Config.OFEnabled == OF_ENABLED && Zodiac_Config.of_port[tag-1] == 1) - { - phys10_port_stats[tag-1].rx_packets++; - phys13_port_stats[tag-1].rx_packets++; - ul_rcv_size--; // remove the tail first - nnOF_tablelookup((uint8_t *) gs_uc_eth_buffer, &ul_rcv_size, tag); - return; - } else { - TRACE("switch.c: %d byte received from controller", ul_rcv_size); - struct pbuf *p; - p = pbuf_alloc(PBUF_RAW, ul_rcv_size+1, PBUF_POOL); - memcpy(p->payload, &gs_uc_eth_buffer,(ul_rcv_size-1)); - p->len = ul_rcv_size-1; - p->tot_len = ul_rcv_size-1; - netif->input(p, netif); - pbuf_free(p); - return; - } - } - } else + // Process packet + if (ul_rcv_size > 0) { - if (slave_ready == true && pending_spi_command == SPI_SEND_READY) + uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); + uint8_t tag = *tail_tag + 1; + if (Zodiac_Config.OFEnabled == OF_ENABLED && Zodiac_Config.of_port[tag-1] == 1) { - uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); - uint8_t tag = *tail_tag + 1; phys10_port_stats[tag-1].rx_packets++; phys13_port_stats[tag-1].rx_packets++; ul_rcv_size--; // remove the tail first - spi_packet = &shared_buffer; - spi_packet->preamble = SPI_PACKET_PREAMBLE; - spi_packet->ul_rcv_size = ul_rcv_size; - spi_packet->spi_crc = 0; - for(int x = 0;xspi_crc += gs_uc_eth_buffer[x]; - } - spi_packet->tag = tag + 4; - spi_packet->spi_size = SPI_HEADER_SIZE + ul_rcv_size; - memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); - pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet - spi_slave_send_size = spi_packet->spi_size; - spi_slave_send_count = spi_slave_send_size; - ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something + nnOF_tablelookup((uint8_t *) gs_uc_eth_buffer, &ul_rcv_size, tag); + return; + } + else + { + TRACE("switch.c: %d byte received from controller", ul_rcv_size); + struct pbuf *p; + p = pbuf_alloc(PBUF_RAW, ul_rcv_size+1, PBUF_POOL); + memcpy(p->payload, &gs_uc_eth_buffer,(ul_rcv_size-1)); + p->len = ul_rcv_size-1; + p->tot_len = ul_rcv_size-1; + netif->input(p, netif); + pbuf_free(p); return; } } diff --git a/ZodiacFX/src/switch.h b/ZodiacFX/src/switch.h index f51edb6..33c72aa 100644 --- a/ZodiacFX/src/switch.h +++ b/ZodiacFX/src/switch.h @@ -44,8 +44,6 @@ void update_port_stats(void); void update_port_status(void); void disableOF(void); void enableOF(void); -void stacking_init(bool master); -void MasterStackRcv(void); int readtxbytes(int port); int readrxbytes(int port); From 734cd2eb8ccdcfcb7cf3bac0145f2837d76e0dbb Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:35:23 +1000 Subject: [PATCH 142/169] Remove stacking initialisations --- ZodiacFX/src/main.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c index 7b1e664..bf6d49f 100644 --- a/ZodiacFX/src/main.c +++ b/ZodiacFX/src/main.c @@ -130,13 +130,6 @@ int main (void) board_init(); get_serial(&uid_buf); - // Set up the GPIO pin for the Mater Select jumper - ioport_init(); - ioport_set_pin_dir(MASTER_SEL, IOPORT_DIR_INPUT); - - masterselect = ioport_get_pin_level(MASTER_SEL); // true = slave - stacking_init(masterselect); // Initialise the stacking connector as either master or slave - irq_initialize_vectors(); // Initialize interrupt vector table support. cpu_irq_enable(); // Enable interrupts From 43b1231c2563bdff7fd264fb979e585963279c63 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:41:20 +1000 Subject: [PATCH 143/169] Revert gmac_write function to dev_80 version --- ZodiacFX/src/switch.c | 50 +++++++------------------------------------ 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 3fc7978..63f9e2d 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -314,52 +314,14 @@ void update_port_status(void) * @param port - the port to send the data out from. * */ -void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) +void gmac_write(uint8_t *p_buffer, uint16_t ul_size, uint8_t port) { - TRACE("switch.c: gmac_write to port 0x%X (%d bytes)", port, ul_size); - // Convert OpenFlow port to physical port number - if (port == OFPP_FLOOD || port == OFPP_ALL || port == OFPP13_FLOOD || port == OFPP13_ALL) // Send packet out all ports except the port it arrived on - { - TRACE("switch.c: Packet out FLOOD (%d bytes)", ul_size); - if(masterselect == false) - { - MasterStackSend(p_buffer, ul_size, port); // Send it slave - if (inport < 5) - { - port = (15 - NativePortMatrix) - (1<<(inport-1)); - } else { - port = 15 - NativePortMatrix; - } - } else { - inport -= 4; - port = (15 - (1<<(inport-1))); - } - } else if (port == OFPP13_IN_PORT) // Send it back out the port it arrived on - { - port = inport; - TRACE("switch.c: Output to in_port %d (%d bytes)", port, ul_size); - } else if (port < 5) // Send it out the specified port - { - port = 1 << (port-1); - } else if (port > 4 && port < 128) - { - if(masterselect == false) // If we are the master then send to the slave - { - TRACE("switch13.c: Sending packet to slave to send out port %d (%d bytes)", port, ul_size); - MasterStackSend(p_buffer, ul_size, port); // Send it slave - return; - } - // If slave then write to port - port -= 4; - port = 1 << (port-1); - } - - TRACE("switch.c: Writing data to switch port matrix %d (%d bytes)", port, ul_size); if (ul_size > GMAC_FRAME_LENTGH_MAX) { return; } - + + // Update port stats if (port & 1) phys10_port_stats[0].tx_packets++; if (port & 2) phys10_port_stats[1].tx_packets++; if (port & 4) phys10_port_stats[2].tx_packets++; @@ -368,6 +330,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) if (port & 2) phys13_port_stats[1].tx_packets++; if (port & 4) phys13_port_stats[2].tx_packets++; if (port & 8) phys13_port_stats[3].tx_packets++; + // Add padding if (ul_size < 60) { @@ -377,7 +340,9 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) last_byte = gmacbuffer + 60; *last_byte = port; gmac_dev_write(&gs_gmac_dev, &gmacbuffer, 61, NULL); - } else { + } + else + { memcpy(&gmacbuffer,p_buffer, ul_size); uint8_t *last_byte; last_byte = gmacbuffer + ul_size; @@ -385,6 +350,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) ul_size++; // Increase packet size by 1 to allow for the tail tag. uint32_t write_size = gmac_dev_write(&gs_gmac_dev, &gmacbuffer, ul_size, NULL); } + return; } From 20fe76ec1e2f7e8154f8697be7e762a708e8899d Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:43:50 +1000 Subject: [PATCH 144/169] Remove stackenabled variable --- ZodiacFX/src/command.c | 3 --- ZodiacFX/src/http.c | 15 +-------------- ZodiacFX/src/main.c | 1 - ZodiacFX/src/openflow/openflow.c | 2 -- ZodiacFX/src/openflow/openflow_10.c | 5 ----- ZodiacFX/src/openflow/openflow_13.c | 5 ----- ZodiacFX/src/switch.c | 1 - 7 files changed, 1 insertion(+), 31 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index 386b4a7..f4428c4 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -67,7 +67,6 @@ extern struct table_counter table_counters[MAX_TABLES]; extern struct meter_entry13 *meter_entry[MAX_METER_13]; extern struct meter_band_stats_array band_stats_array[MAX_METER_13]; extern bool masterselect; -extern bool stackenabled = false; extern bool trace = false; extern struct tcp_pcb *tcp_pcb; extern uint8_t port_status[8]; @@ -558,8 +557,6 @@ void command_config(char *command, char *param1, char *param2, char *param3) } else { printf(" Force OpenFlow version: Disabled\r\n"); } - if (stackenabled == true) printf(" Stacking Status: Enabled\r\n"); - if (stackenabled == false) printf(" Stacking Status: Disabled\r\n"); if (Zodiac_Config.ethtype_filter == 1) printf(" EtherType Filtering: Enabled\r\n"); if (Zodiac_Config.ethtype_filter != 1) printf(" EtherType Filtering: Disabled\r\n"); printf("\r\n-------------------------------------------------------------------------\r\n\n"); diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 3e0a9f6..7cef6b4 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -91,8 +91,6 @@ static bool restart_required = false; // Track if any configuration changes are static bool file_upload = false; // Multi-part firmware file upload flag static bool post_pending = false; -extern bool stackenabled; - static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err); static err_t http_accept(void *arg, struct tcp_pcb *pcb, err_t err); void http_send(char *buffer, struct tcp_pcb *pcb, bool out); @@ -2109,18 +2107,7 @@ static uint8_t interfaceCreate_Home(void) "CPU Temp: %d C
"\ "Uptime: %02d:%02d
"\ ); - if(stackenabled == true) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "Stacking: enabled" - ); - } - else - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "Stacking: disabled" - ); - } + if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ "

"\ ""\ diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c index bf6d49f..2765678 100644 --- a/ZodiacFX/src/main.c +++ b/ZodiacFX/src/main.c @@ -52,7 +52,6 @@ struct netif gs_net_if; struct zodiac_config Zodiac_Config; int charcount, charcount_last; bool masterselect; -bool stackenabled; int portmap[4]; int32_t ul_temp; uint8_t NativePortMatrix; diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index c2aed17..07cae39 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -45,7 +45,6 @@ extern struct zodiac_config Zodiac_Config; extern uint8_t port_status[8]; extern struct ofp10_port_stats phys10_port_stats[8]; extern struct ofp13_port_stats phys13_port_stats[8]; -extern bool stackenabled; // Local Variables struct ofp_switch_config Switch_config; @@ -355,7 +354,6 @@ void task_openflow(void) { fast_of_timer = sys_get_ms(); nnOF_timer(); - ////if (stackenabled == true) masterslave_test(); if (heartbeat > (HB_INTERVAL * 2) && tcp_con_state == 1) //If we haven't heard anything from the controller for more then the heartbeat interval send an echo request { diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 09e5b9f..99d2d4b 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -58,7 +58,6 @@ extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern struct zodiac_config Zodiac_Config; extern struct ofp_switch_config Switch_config; extern uint8_t total_ports; -extern bool stackenabled; //Internal Functions void packet_in(uint8_t *buffer, uint16_t ul_size, uint8_t port, uint8_t reason); @@ -411,10 +410,6 @@ void features_reply10(uint32_t xid) { if(Zodiac_Config.of_port[n]==1)numofports++; } - if(stackenabled == true) - { - numofports += 4; // Add the slave ports - } struct ofp10_switch_features features; struct ofp10_phy_port phys_port[numofports]; uint8_t buf[256]; diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index df19919..45d5e0d 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -68,7 +68,6 @@ extern uint8_t NativePortMatrix; extern bool reply_more_flag; extern uint32_t reply_more_xid; extern uint8_t total_ports; -extern bool stackenabled; extern int meter_handler(uint32_t id, uint16_t bytes); // Internal functions @@ -891,10 +890,6 @@ int multi_portdesc_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) { if(Zodiac_Config.of_port[n]==1) numofports++; } - if(stackenabled == true) - { - numofports += 4; // Add the slave ports - } struct ofp13_multipart_reply *reply; struct ofp13_port phys_port[numofports]; uint16_t len = sizeof(struct ofp13_multipart_reply) + sizeof(phys_port); diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 63f9e2d..8490abb 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -46,7 +46,6 @@ extern struct zodiac_config Zodiac_Config; extern int OF_Version; extern uint8_t NativePortMatrix; extern bool masterselect; -extern bool stackenabled; extern uint8_t pending_spi_command; extern struct spi_packet *spi_packet; extern bool slave_ready; From 28ffbf1f050884078bf7927d735058880c034c85 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:44:51 +1000 Subject: [PATCH 145/169] Remove masterselect variable --- ZodiacFX/src/main.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c index 2765678..4010674 100644 --- a/ZodiacFX/src/main.c +++ b/ZodiacFX/src/main.c @@ -51,7 +51,6 @@ struct netif gs_net_if; struct zodiac_config Zodiac_Config; int charcount, charcount_last; -bool masterselect; int portmap[4]; int32_t ul_temp; uint8_t NativePortMatrix; @@ -194,12 +193,7 @@ int main (void) { task_switch(&gs_net_if); task_command(cCommand, cCommand_last); - // Only run the following tasks if set to Master - if(masterselect == false) - { - //task_command(cCommand, cCommand_last); - sys_check_timeouts(); - task_openflow(); - } + sys_check_timeouts(); + task_openflow(); } } From aadd986af6244abb3650829e3823b5bb5fff19b1 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:49:55 +1000 Subject: [PATCH 146/169] Remove stacking reference in openflow features reply --- ZodiacFX/src/openflow/openflow_10.c | 4 ++-- ZodiacFX/src/openflow/openflow_13.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 99d2d4b..099adfc 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -433,9 +433,9 @@ void features_reply10(uint32_t xid) memcpy(&buf, &features, sizeof(struct ofp10_switch_features)); update_port_status(); //update port status - for(l = 0; l< total_ports; l++) + for(l = 0; l 3) // If l > 3 then stacking is enabled so include the 4 port from the slave + if(Zodiac_Config.of_port[l] == 1) { phys_port[j].port_no = HTONS(l+1); for(k = 0; k<6; k++) // Generate random MAC address diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 45d5e0d..fd3b7aa 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -906,9 +906,9 @@ int multi_portdesc_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) uint8_t mac[] = {0x00,0x00,0x00,0x00,0x00,0x00}; update_port_status(); //update port status - for(int l = 0; l< total_ports; l++) + for(int l = 0; l 3) // If l > 3 then stacking is enabled so include the 4 port from the slave + if(Zodiac_Config.of_port[l] == 1) { phys_port[j].port_no = htonl(l+1); for(int k = 0; k<6; k++) // Generate random MAC address From f8bd8522b21b9f87beeac48ca59680d865be6c76 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:51:42 +1000 Subject: [PATCH 147/169] Remove unused externs --- ZodiacFX/src/command.c | 1 - ZodiacFX/src/switch.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index f4428c4..1c7157c 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -66,7 +66,6 @@ extern struct ofp13_port_stats phys13_port_stats[8]; extern struct table_counter table_counters[MAX_TABLES]; extern struct meter_entry13 *meter_entry[MAX_METER_13]; extern struct meter_band_stats_array band_stats_array[MAX_METER_13]; -extern bool masterselect; extern bool trace = false; extern struct tcp_pcb *tcp_pcb; extern uint8_t port_status[8]; diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 8490abb..c11e7e7 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -45,10 +45,8 @@ extern struct tcp_conn tcp_conn; extern struct zodiac_config Zodiac_Config; extern int OF_Version; extern uint8_t NativePortMatrix; -extern bool masterselect; extern uint8_t pending_spi_command; extern struct spi_packet *spi_packet; -extern bool slave_ready; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; // Local variables From 3e061a05123550893fd31bfa088acc649edd0db4 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:51:51 +1000 Subject: [PATCH 148/169] Update function prototype --- ZodiacFX/src/switch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/switch.h b/ZodiacFX/src/switch.h index 33c72aa..e4b132a 100644 --- a/ZodiacFX/src/switch.h +++ b/ZodiacFX/src/switch.h @@ -37,7 +37,7 @@ void spi_init(void); void switch_init(void); void task_switch(struct netif *netif); -void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport); +void gmac_write(uint8_t *p_buffer, uint16_t ul_size, uint8_t port); int switch_read(uint8_t param1); int switch_write(uint8_t param1, uint8_t param2); void update_port_stats(void); From 9fe295e4dcc3820deeed2b106dfeb4745da40e73 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 11:06:39 +1000 Subject: [PATCH 149/169] Modify gmac_write calls --- ZodiacFX/src/ksz8795clx/ethernet_phy.c | 2 +- ZodiacFX/src/openflow/openflow_10.c | 4 ++-- ZodiacFX/src/openflow/openflow_13.c | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ZodiacFX/src/ksz8795clx/ethernet_phy.c b/ZodiacFX/src/ksz8795clx/ethernet_phy.c index f734ba8..c529f4f 100644 --- a/ZodiacFX/src/ksz8795clx/ethernet_phy.c +++ b/ZodiacFX/src/ksz8795clx/ethernet_phy.c @@ -289,7 +289,7 @@ err_t ethernetif_init(struct netif *netif) static err_t gmac_low_level_output(struct netif *netif, struct pbuf *p) { - gmac_write(p->payload, p->len, 128, 0); + gmac_write(p->payload, p->len, 128); } diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 099adfc..18992e2 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -179,7 +179,7 @@ void nnOF10_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) if (pisize > packet_size) pisize = packet_size; packet_in(p_uc_data, pisize, port, OFPR_ACTION); } - gmac_write(p_uc_data, packet_size, ntohs(action_out->port), port); + gmac_write(p_uc_data, packet_size, ntohs(action_out->port)); break; case OFPAT10_SET_DL_SRC: @@ -764,7 +764,7 @@ void packet_out(struct ofp_header *msg) nnOF_tablelookup(ptr, &size, NTOHS(*iport)); return; } - gmac_write(ptr, size, NTOHS(*eport), NTOHS(*iport)); + gmac_write(ptr, size, NTOHS(*eport)); return; } diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index fd3b7aa..566a555 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -233,7 +233,7 @@ void nnOF13_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) break; } - gmac_write(p_uc_data, packet_size, htonl(act_output->port), port); + gmac_write(p_uc_data, packet_size, htonl(act_output->port)); } break; @@ -2025,14 +2025,13 @@ void packet_out13(struct ofp_header *msg) struct ofp13_action_header *act_hdr = po->actions; if (ntohs(act_hdr->type) != OFPAT13_OUTPUT) return; struct ofp13_action_output *act_out = act_hdr; - //uint32_t outPort = htonl(act_out->port); TRACE("openflow_13.c: Packet out port 0x%X (%d bytes)", htonl(act_out->port), size); if (htonl(act_out->port) == OFPP13_TABLE) { nnOF_tablelookup(ptr, &size, inPort); return; } - gmac_write(ptr, size, htonl(act_out->port), inPort); + gmac_write(ptr, size, htonl(act_out->port)); return; } From 1da9de0abebba80f01d500e03166e0896bae7ce8 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 11:09:18 +1000 Subject: [PATCH 150/169] Remove 8-port display in web interface --- ZodiacFX/src/http.c | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 7cef6b4..7c2f967 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -2354,15 +2354,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "Port 3"\ "Port 4"\ ); - if (total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "Port 5"\ - "Port 6"\ - "Port 7"\ - "Port 8"\ - ); - } if ( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ ""\ @@ -2417,17 +2408,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) , portStatusch[port_status[0]], portStatusch[port_status[1]], portStatusch[port_status[2]], portStatusch[port_status[3]]\ ); - if (total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "%s"\ - "%s"\ - "%s"\ - "%s"\ - , portStatusch[port_status[4]], portStatusch[port_status[5]], portStatusch[port_status[6]], portStatusch[port_status[7]]\ - ); - } - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ ""\ ""\ @@ -2477,16 +2457,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) ); } } - - if (total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "OpenFlow"\ - "OpenFlow"\ - "OpenFlow"\ - "OpenFlow"\ - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ ""\ @@ -2535,16 +2505,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) ""\ ); } - - if (total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "-"\ - "-"\ - "-"\ - "-"\ - ); - } if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ ""\ From 68bd2c39647f0f979947cbb5604e5ef0bb18c388 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 11:11:56 +1000 Subject: [PATCH 151/169] Remove 8-port stats in web interface --- ZodiacFX/src/http.c | 141 -------------------------------------------- 1 file changed, 141 deletions(-) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 7c2f967..0bdc5e4 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -70,7 +70,6 @@ extern int iLastMeter; extern struct ofp10_port_stats phys10_port_stats[8]; extern struct ofp13_port_stats phys13_port_stats[8]; extern struct table_counter table_counters[MAX_TABLES]; -extern uint8_t total_ports; // Local Variables struct tcp_pcb *http_pcb; @@ -2534,16 +2533,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].rx_bytes, phys10_port_stats[1].rx_bytes, phys10_port_stats[2].rx_bytes, phys10_port_stats[3].rx_bytes ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].rx_bytes, phys10_port_stats[5].rx_bytes, phys10_port_stats[6].rx_bytes, phys10_port_stats[7].rx_bytes - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2556,16 +2545,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].tx_bytes, phys10_port_stats[1].tx_bytes, phys10_port_stats[2].tx_bytes, phys10_port_stats[3].tx_bytes ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].tx_bytes, phys10_port_stats[5].tx_bytes, phys10_port_stats[6].tx_bytes, phys10_port_stats[7].tx_bytes - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2578,16 +2557,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].rx_packets, phys10_port_stats[1].rx_packets, phys10_port_stats[2].rx_packets, phys10_port_stats[3].rx_packets ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].rx_packets, phys10_port_stats[5].rx_packets, phys10_port_stats[6].rx_packets, phys10_port_stats[7].rx_packets - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2600,16 +2569,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].tx_packets, phys10_port_stats[1].tx_packets, phys10_port_stats[2].tx_packets, phys10_port_stats[3].tx_packets ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].tx_packets, phys10_port_stats[5].tx_packets, phys10_port_stats[6].tx_packets, phys10_port_stats[7].tx_packets - ); - } if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ) < SHARED_BUFFER_LEN) @@ -2637,16 +2596,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].rx_bytes, phys13_port_stats[1].rx_bytes, phys13_port_stats[2].rx_bytes, phys13_port_stats[3].rx_bytes ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].rx_bytes, phys13_port_stats[5].rx_bytes, phys13_port_stats[6].rx_bytes, phys13_port_stats[7].rx_bytes - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2659,16 +2608,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].tx_bytes, phys13_port_stats[1].tx_bytes, phys13_port_stats[2].tx_bytes, phys13_port_stats[3].tx_bytes ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].tx_bytes, phys13_port_stats[5].tx_bytes, phys13_port_stats[6].tx_bytes, phys13_port_stats[7].tx_bytes - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2681,16 +2620,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].rx_packets, phys13_port_stats[1].rx_packets, phys13_port_stats[2].rx_packets, phys13_port_stats[3].rx_packets ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].rx_packets, phys13_port_stats[5].rx_packets, phys13_port_stats[6].rx_packets, phys13_port_stats[7].rx_packets - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2703,16 +2632,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].tx_packets, phys13_port_stats[1].tx_packets, phys13_port_stats[2].tx_packets, phys13_port_stats[3].tx_packets ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].tx_packets, phys13_port_stats[5].tx_packets, phys13_port_stats[6].tx_packets, phys13_port_stats[7].tx_packets - ); - } if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ) < SHARED_BUFFER_LEN) @@ -2743,16 +2662,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].rx_dropped, phys10_port_stats[1].rx_dropped, phys10_port_stats[2].rx_dropped, phys10_port_stats[3].rx_dropped ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].rx_dropped, phys10_port_stats[5].rx_dropped, phys10_port_stats[6].rx_dropped, phys10_port_stats[7].rx_dropped - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2765,16 +2674,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].tx_dropped, phys10_port_stats[1].tx_dropped, phys10_port_stats[2].tx_dropped, phys10_port_stats[3].tx_dropped ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].tx_dropped, phys10_port_stats[5].tx_dropped, phys10_port_stats[6].tx_dropped, phys10_port_stats[7].tx_dropped - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2787,16 +2686,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].rx_crc_err, phys10_port_stats[1].rx_crc_err, phys10_port_stats[2].rx_crc_err, phys10_port_stats[3].rx_crc_err ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].rx_crc_err, phys10_port_stats[5].rx_crc_err, phys10_port_stats[6].rx_crc_err, phys10_port_stats[7].rx_crc_err - ); - } if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2832,16 +2721,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].rx_dropped, phys13_port_stats[1].rx_dropped, phys13_port_stats[2].rx_dropped, phys13_port_stats[3].rx_dropped ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].rx_dropped, phys13_port_stats[5].rx_dropped, phys13_port_stats[6].rx_dropped, phys13_port_stats[7].rx_dropped - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2854,16 +2733,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].tx_dropped, phys13_port_stats[1].tx_dropped, phys13_port_stats[2].tx_dropped, phys13_port_stats[3].tx_dropped ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].tx_dropped, phys13_port_stats[5].tx_dropped, phys13_port_stats[6].tx_dropped, phys13_port_stats[7].tx_dropped - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2876,16 +2745,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].rx_crc_err, phys13_port_stats[1].rx_crc_err, phys13_port_stats[2].rx_crc_err, phys13_port_stats[3].rx_crc_err ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].rx_dropped, phys13_port_stats[5].rx_crc_err, phys13_port_stats[6].rx_crc_err, phys13_port_stats[7].rx_crc_err - ); - } if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ From a15023a254aee7f0d7cb6e2866cbc8bfbbfd239f Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 11:12:28 +1000 Subject: [PATCH 152/169] Clean up stacking-related comments --- ZodiacFX/src/openflow/openflow_10.c | 2 +- ZodiacFX/src/openflow/openflow_13.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 18992e2..79a120c 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -693,7 +693,7 @@ void stats_port_reply(struct ofp_stats_request *msg) } } } - else if (port > 0 && port <= total_ports) // Respond to request for ports 1-4 or 1-8 (stacking) + else if (port > 0 && port <= total_ports) // Respond to request for ports { // Check if port is NOT native if(!(NativePortMatrix & (1<<(port-1)))) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 566a555..2a3d0d9 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -1164,7 +1164,7 @@ int multi_portstats_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg } } } - else if (port > 0 && port <= total_ports) // Respond to request for ports 1-4 or 1-8 (stacking) + else if (port > 0 && port <= total_ports) // Respond to request for ports { // Check if port is NOT native if(!(NativePortMatrix & (1<<(port-1)))) From 97690994726f46e2f587963d6ba50fa5af9e6272 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 11:17:38 +1000 Subject: [PATCH 153/169] Modify total_ports variable into a macro --- ZodiacFX/src/command.c | 3 +-- ZodiacFX/src/config/config_zodiac.h | 2 ++ ZodiacFX/src/openflow/of_helper.c | 3 +-- ZodiacFX/src/openflow/openflow_10.c | 9 ++++----- ZodiacFX/src/openflow/openflow_13.c | 11 +++++------ ZodiacFX/src/switch.c | 1 - 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index 1c7157c..83c90d9 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -69,7 +69,6 @@ extern struct meter_band_stats_array band_stats_array[MAX_METER_13]; extern bool trace = false; extern struct tcp_pcb *tcp_pcb; extern uint8_t port_status[8]; -extern uint8_t total_ports; extern int totaltime; extern int32_t ul_temp; extern int OF_Version; @@ -326,7 +325,7 @@ void command_root(char *command, char *param1, char *param2, char *param3) { int i; printf("\r\n-------------------------------------------------------------------------\r\n"); - for (i=0;i 0 && port <= total_ports) // Respond to request for ports + else if (port > 0 && port <= TOTAL_PORTS) // Respond to request for ports { // Check if port is NOT native if(!(NativePortMatrix & (1<<(port-1)))) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 2a3d0d9..3ee1097 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -67,7 +67,6 @@ extern int multi_pos; extern uint8_t NativePortMatrix; extern bool reply_more_flag; extern uint32_t reply_more_xid; -extern uint8_t total_ports; extern int meter_handler(uint32_t id, uint16_t bytes); // Internal functions @@ -886,7 +885,7 @@ int multi_aggregate_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg int multi_portdesc_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) { int numofports = 0; - for(int n=0;n 0 && port <= total_ports) // Respond to request for ports + else if (port > 0 && port <= TOTAL_PORTS) // Respond to request for ports { // Check if port is NOT native if(!(NativePortMatrix & (1<<(port-1)))) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index c11e7e7..393a8c4 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -56,7 +56,6 @@ struct ofp10_port_stats phys10_port_stats[8]; struct ofp13_port_stats phys13_port_stats[8]; uint8_t port_status[8]; uint8_t last_port_status[8]; -uint8_t total_ports = 4; uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; uint8_t stats_rr = 0; From 5fc225392ab0b5854140b91eacccb25775dc3e1a Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 11:20:21 +1000 Subject: [PATCH 154/169] Clean up unused variables --- ZodiacFX/src/openflow/of_helper.c | 5 ----- ZodiacFX/src/openflow/openflow_10.c | 1 - ZodiacFX/src/switch.c | 2 -- 3 files changed, 8 deletions(-) diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index 817d184..9b6439f 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -1227,12 +1227,8 @@ int flow_stats_msg10(char *buffer, int first, int last) int flow_stats_msg13(char *buffer, int first, int last) { struct ofp13_flow_stats flow_stats; - int stats_size = 0; char *buffer_ptr = buffer; - int inst_size; - int stats_len; int len; - int pad = 0; for(int k = first; k Date: Tue, 23 May 2017 11:56:11 +1000 Subject: [PATCH 155/169] Update port stats struct array sizes --- ZodiacFX/src/command.c | 6 +++--- ZodiacFX/src/http.c | 4 ++-- ZodiacFX/src/openflow/of_helper.c | 4 ++-- ZodiacFX/src/openflow/openflow.c | 6 +++--- ZodiacFX/src/openflow/openflow_10.c | 4 ++-- ZodiacFX/src/openflow/openflow_13.c | 4 ++-- ZodiacFX/src/switch.c | 8 ++++---- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index 83c90d9..8c1befa 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -61,14 +61,14 @@ extern uint16_t ofp13_oxm_inst_size[MAX_FLOWS_13]; extern struct flows_counter flow_counters[MAX_FLOWS_13]; extern struct flow_tbl_actions *flow_actions10[MAX_FLOWS_13]; extern int iLastFlow; -extern struct ofp10_port_stats phys10_port_stats[8]; -extern struct ofp13_port_stats phys13_port_stats[8]; +extern struct ofp10_port_stats phys10_port_stats[TOTAL_PORTS]; +extern struct ofp13_port_stats phys13_port_stats[TOTAL_PORTS]; extern struct table_counter table_counters[MAX_TABLES]; extern struct meter_entry13 *meter_entry[MAX_METER_13]; extern struct meter_band_stats_array band_stats_array[MAX_METER_13]; extern bool trace = false; extern struct tcp_pcb *tcp_pcb; -extern uint8_t port_status[8]; +extern uint8_t port_status[TOTAL_PORTS]; extern int totaltime; extern int32_t ul_temp; extern int OF_Version; diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 0bdc5e4..c9f7d45 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -67,8 +67,8 @@ extern struct meter_entry13 *meter_entry[MAX_METER_13]; extern struct meter_band_stats_array band_stats_array[MAX_METER_13]; extern int iLastFlow; extern int iLastMeter; -extern struct ofp10_port_stats phys10_port_stats[8]; -extern struct ofp13_port_stats phys13_port_stats[8]; +extern struct ofp10_port_stats phys10_port_stats[TOTAL_PORTS]; +extern struct ofp13_port_stats phys13_port_stats[TOTAL_PORTS]; extern struct table_counter table_counters[MAX_TABLES]; // Local Variables diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index 9b6439f..5c84566 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -52,8 +52,8 @@ extern int iLastFlow; extern int iLastMeter; extern int OF_Version; extern int totaltime; -extern uint8_t last_port_status[8]; -extern uint8_t port_status[8]; +extern uint8_t last_port_status[TOTAL_PORTS]; +extern uint8_t port_status[TOTAL_PORTS]; extern struct flows_counter flow_counters[MAX_FLOWS_13]; extern struct table_counter table_counters[MAX_TABLES]; extern struct meter_entry13 *meter_entry[MAX_METER_13]; diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index 07cae39..27d4ffa 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -42,9 +42,9 @@ // Global variables extern struct zodiac_config Zodiac_Config; -extern uint8_t port_status[8]; -extern struct ofp10_port_stats phys10_port_stats[8]; -extern struct ofp13_port_stats phys13_port_stats[8]; +extern uint8_t port_status[TOTAL_PORTS]; +extern struct ofp10_port_stats phys10_port_stats[TOTAL_PORTS]; +extern struct ofp13_port_stats phys13_port_stats[TOTAL_PORTS]; // Local Variables struct ofp_switch_config Switch_config; diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 0317c3c..46cfad4 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -52,8 +52,8 @@ extern struct table_counter table_counters[MAX_TABLES]; extern int OF_Version; extern bool rcv_freq; extern uint8_t NativePortMatrix; -extern struct ofp10_port_stats phys10_port_stats[8]; -extern uint8_t port_status[8]; +extern struct ofp10_port_stats phys10_port_stats[TOTAL_PORTS]; +extern uint8_t port_status[TOTAL_PORTS]; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern struct zodiac_config Zodiac_Config; extern struct ofp_switch_config Switch_config; diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 3ee1097..c40dad7 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -58,9 +58,9 @@ extern uint8_t *ofp13_oxm_match[MAX_FLOWS_13]; extern uint8_t *ofp13_oxm_inst[MAX_FLOWS_13]; extern uint16_t ofp13_oxm_inst_size[MAX_FLOWS_13]; extern struct flows_counter flow_counters[MAX_FLOWS_13]; -extern struct ofp13_port_stats phys13_port_stats[8]; +extern struct ofp13_port_stats phys13_port_stats[TOTAL_PORTS]; extern struct table_counter table_counters[MAX_TABLES]; -extern uint8_t port_status[8]; +extern uint8_t port_status[TOTAL_PORTS]; extern struct ofp_switch_config Switch_config; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern int multi_pos; diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 7dc6cef..caf19df 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -52,10 +52,10 @@ extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; // Local variables gmac_device_t gs_gmac_dev; uint8_t gmacbuffer[GMAC_FRAME_LENTGH_MAX]; -struct ofp10_port_stats phys10_port_stats[8]; -struct ofp13_port_stats phys13_port_stats[8]; -uint8_t port_status[8]; -uint8_t last_port_status[8]; +struct ofp10_port_stats phys10_port_stats[TOTAL_PORTS]; +struct ofp13_port_stats phys13_port_stats[TOTAL_PORTS]; +uint8_t port_status[TOTAL_PORTS]; +uint8_t last_port_status[TOTAL_PORTS]; uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; uint8_t stats_rr = 0; From c9055747df93dfeb85112a44c96e884e0ef5ff2e Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 12:34:07 +1000 Subject: [PATCH 156/169] Fix web interface status page --- ZodiacFX/src/http.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index c9f7d45..23e827f 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -2105,6 +2105,8 @@ static uint8_t interfaceCreate_Home(void) "Firmware Version: %s
"\ "CPU Temp: %d C
"\ "Uptime: %02d:%02d
"\ + , uid_buf[0], uid_buf[1], uid_buf[2], uid_buf[3]\ + , VERSION, (int)ul_temp, hr, min\ ); if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ @@ -2114,8 +2116,7 @@ static uint8_t interfaceCreate_Home(void) ""\ ""\ ""\ - , uid_buf[0], uid_buf[1], uid_buf[2], uid_buf[3]\ - , VERSION, (int)ul_temp, hr, min) < SHARED_BUFFER_LEN) + ) < SHARED_BUFFER_LEN ) { return 1; } From a02689b9052830edd73ff8e90072c33230b8503c Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 14:33:11 +1000 Subject: [PATCH 157/169] Revert tablelookup changes --- ZodiacFX/src/openflow/openflow_13.c | 37 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index c40dad7..4d5fee7 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -222,18 +222,31 @@ void nnOF13_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) set_ip_checksum(p_uc_data, packet_size, fields.payload - p_uc_data); recalculate_ip_checksum = false; } + struct ofp13_action_output *act_output = act_hdr; - if (htonl(act_output->port) == OFPP13_CONTROLLER) + if (htonl(act_output->port) < OFPP13_MAX && htonl(act_output->port) != port) + { + int outport = (1<< (ntohl(act_output->port)-1)); + TRACE("openflow_13.c: Output to port %d (%d bytes)", ntohl(act_output->port), packet_size); + gmac_write(p_uc_data, packet_size, outport); + } else if (htonl(act_output->port) == OFPP13_IN_PORT) + { + int outport = (1<< (port-1)); + TRACE("openflow_13.c: Output to in_port %d (%d bytes)", port, packet_size); + gmac_write(p_uc_data, packet_size, outport); + } else if (htonl(act_output->port) == OFPP13_CONTROLLER) { int pisize = ntohs(act_output->max_len); if (pisize > packet_size) pisize = packet_size; TRACE("openflow_13.c: Output to controller (%d bytes)", packet_size); packet_in13(p_uc_data, pisize, port, OFPR_ACTION, i); - break; + } else if (htonl(act_output->port) == OFPP13_FLOOD || htonl(act_output->port) == OFPP13_ALL) + { + int outport = (15 - NativePortMatrix) - (1<<(port-1)); + if (htonl(act_output->port) == OFPP13_FLOOD) TRACE("openflow_13.c: Output to FLOOD (%d bytes)", packet_size); + if (htonl(act_output->port) == OFPP13_ALL) TRACE("openflow_13.c: Output to ALL (%d bytes)", packet_size); + gmac_write(p_uc_data, packet_size, outport); } - - gmac_write(p_uc_data, packet_size, htonl(act_output->port)); - } break; @@ -931,6 +944,7 @@ int multi_portdesc_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) j ++; } } + memcpy(reply->body, &phys_port[0],sizeof(phys_port)); return len; } @@ -2024,13 +2038,16 @@ void packet_out13(struct ofp_header *msg) struct ofp13_action_header *act_hdr = po->actions; if (ntohs(act_hdr->type) != OFPAT13_OUTPUT) return; struct ofp13_action_output *act_out = act_hdr; - TRACE("openflow_13.c: Packet out port 0x%X (%d bytes)", htonl(act_out->port), size); - if (htonl(act_out->port) == OFPP13_TABLE) + uint32_t outPort = htonl(act_out->port); + if (outPort == OFPP13_FLOOD) { - nnOF_tablelookup(ptr, &size, inPort); - return; + outPort = 7 - (1 << (inPort-1)); // Need to fix this, may also send out the Non-OpenFlow port + } else { + outPort = 1 << (outPort-1); + TRACE("openflow_13.c: Packet out FLOOD (%d bytes)", size); } - gmac_write(ptr, size, htonl(act_out->port)); + TRACE("openflow_13.c: Packet out port %d (%d bytes)", outPort, size); + gmac_write(ptr, size, outPort); return; } From 7162fb85682faae338aeefe872f5e5ba358f5dc9 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 14:39:06 +1000 Subject: [PATCH 158/169] Revert OF10 tablelookup changes --- ZodiacFX/src/openflow/openflow_10.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 46cfad4..81d399a 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -101,7 +101,7 @@ void nnOF10_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) uint16_t packet_size; struct packet_fields fields = {0}; packet_fields_parser(p_uc_data, &fields); - + memcpy(&packet_size, ul_size, 2); uint16_t eth_prot; memcpy(ð_prot, p_uc_data + 12, 2); @@ -121,6 +121,7 @@ void nnOF10_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) uint16_t tcpport; uint32_t ipadr; uint16_t vlantag = htons(0x8100); + int outport = 0; table_counters[0].lookup_count++; @@ -171,13 +172,30 @@ void nnOF10_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) { case OFPAT10_OUTPUT: action_out = act_hdr; + if (ntohs(action_out->port) <= 255 && ntohs(action_out->port) != port) // physical port + { + outport = (1<< (ntohs(action_out->port)-1)); + gmac_write(p_uc_data, packet_size, outport); + } + + if (ntohs(action_out->port) == OFPP_IN_PORT) + { + outport = (1<< (port-1)); + gmac_write(p_uc_data, packet_size, outport); + } + + if (ntohs(action_out->port) == OFPP_ALL || ntohs(action_out->port) == OFPP_FLOOD) + { + outport = (15 - NativePortMatrix) - (1<<(port-1)); + gmac_write(p_uc_data, packet_size, outport); + } + if (ntohs(action_out->port) == OFPP_CONTROLLER) { int pisize = ntohs(action_out->max_len); if (pisize > packet_size) pisize = packet_size; packet_in(p_uc_data, pisize, port, OFPR_ACTION); } - gmac_write(p_uc_data, packet_size, ntohs(action_out->port)); break; case OFPAT10_SET_DL_SRC: From 132f8618d9c0e001df39a4f9de3bcbcf509b4405 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 15:04:44 +1000 Subject: [PATCH 159/169] Revert OF10 packet out changes --- ZodiacFX/src/openflow/openflow_10.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 81d399a..9502836 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -773,14 +773,23 @@ void packet_out(struct ofp_header *msg) int size = NTOHS(po->header.length) - ((sizeof(struct ofp_packet_out) + NTOHS(po->actions_len))); uint16_t *eport; eport = ptr - 4; - TRACE("openflow_10.c: Packet out port 0x%X (%d bytes)", NTOHS(*eport), size); - - if (NTOHS(*eport) == OFPP_TABLE) + int outPort = NTOHS(*eport); + int inPort = NTOHS(*iport); + + if (outPort == OFPP_TABLE) { - nnOF_tablelookup(ptr, &size, NTOHS(*iport)); + nnOF_tablelookup(ptr, &size, inPort); return; } - gmac_write(ptr, size, NTOHS(*eport)); + + if (outPort == OFPP_FLOOD || outPort == OFPP13_ALL) + { + outPort = (15 - NativePortMatrix) - (1<<(inPort-1)); + } else + { + outPort = 1 << (outPort-1); + } + gmac_write(ptr, size, outPort); return; } From d68254e54965e50af4821a3d99984b1e9b6a4337 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 16:38:18 +1000 Subject: [PATCH 160/169] Modify ethernet buffer declaration --- ZodiacFX/src/switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index caf19df..533262d 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -56,7 +56,7 @@ struct ofp10_port_stats phys10_port_stats[TOTAL_PORTS]; struct ofp13_port_stats phys13_port_stats[TOTAL_PORTS]; uint8_t port_status[TOTAL_PORTS]; uint8_t last_port_status[TOTAL_PORTS]; -uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; +static volatile uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; uint8_t stats_rr = 0; /* GMAC HW configurations */ From c5be33ed2e5445c7574c95ef7e8fe73379303bfd Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 17:01:04 +1000 Subject: [PATCH 161/169] Remove stacking source from project --- ZodiacFX/ZodiacFX.cproj | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ZodiacFX/ZodiacFX.cproj b/ZodiacFX/ZodiacFX.cproj index ab4e3bd..bb1eeff 100644 --- a/ZodiacFX/ZodiacFX.cproj +++ b/ZodiacFX/ZodiacFX.cproj @@ -720,12 +720,6 @@ compile - - compile - - - compile - compile From 1e235b16c04dc9a58786268fe244b8eaa61cff1b Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 26 May 2017 13:38:05 +1000 Subject: [PATCH 162/169] Adjust web interface flow display Web interface now correctly displays flows after a clear_flows call --- ZodiacFX/src/http.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 23e827f..9846d63 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -2909,6 +2909,12 @@ static uint8_t interfaceCreate_Display_Flows(void) flowEnd = iLastFlow; } + // Re-base start of flows if flows have been cleared + if(flowBase > iLastFlow) + { + flowBase = 0; + } + sprintf(shared_buffer, http_header); snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ From ab7bd0c76a70d520eb5c408918ddc1884aca87da Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 26 May 2017 14:17:32 +1000 Subject: [PATCH 163/169] Modify flow stats reply Check send buffer before formatting flows --- ZodiacFX/src/openflow/openflow_13.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 4d5fee7..c6ed7f9 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -810,6 +810,13 @@ int multi_flow_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) */ void multi_flow_more_reply13(void) { + uint16_t sndbuf = tcp_sndbuf(tcp_pcb); + if(sndbuf < 2048) + { + TRACE("openflow_13.c: waiting to reply with more flows, sndbuf @ %d", sndbuf); + return; + } + // Clear shared_buffer memset(&shared_buffer, 0, SHARED_BUFFER_LEN); From 17b86d295c08043035ba3bfcffad509a22e194f8 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 26 May 2017 15:42:26 +1000 Subject: [PATCH 164/169] Fix function description --- ZodiacFX/src/openflow/of_helper.c | 2 +- ZodiacFX/src/openflow/openflow_10.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index 5c84566..b7a9eef 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -1015,7 +1015,7 @@ void remove_flow13(int flow_id) } /* -* Remove a flow entry from the flow table (OF 1.3) +* Remove a flow entry from the flow table (OF 1.0) * * @param flow_id - the index number of the flow to remove * diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 9502836..600c075 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -833,6 +833,7 @@ void packet_in(uint8_t *buffer, uint16_t ul_size, uint8_t port, uint8_t reason) */ void flow_mod(struct ofp_header *msg) { + /**/TRACE("____________________ FLOWMOD ENTRY"); struct ofp_flow_mod * ptr_fm; ptr_fm = (struct ofp_flow_mod *) msg; @@ -841,22 +842,27 @@ void flow_mod(struct ofp_header *msg) { case OFPFC_ADD: + /**/TRACE("____________________ ADD"); flow_add(msg); break; case OFPFC_MODIFY: + /**/TRACE("____________________ MODIFY"); flow_modify(msg); break; case OFPFC_MODIFY_STRICT: + /**/TRACE("____________________ MODIFY STRICT"); flow_modify_strict(msg); break; case OFPFC_DELETE: + /**/TRACE("____________________ DELETE"); flow_delete(msg); break; case OFPFC_DELETE_STRICT: + /**/TRACE("____________________ DELETE STRICT"); flow_delete_strict(msg); break; From 7ffa2ae14157d358bf2a0fa24ed17ad32bb173de Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 26 May 2017 15:42:30 +1000 Subject: [PATCH 165/169] Revert "Fix function description" This reverts commit 17b86d295c08043035ba3bfcffad509a22e194f8. --- ZodiacFX/src/openflow/of_helper.c | 2 +- ZodiacFX/src/openflow/openflow_10.c | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index b7a9eef..5c84566 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -1015,7 +1015,7 @@ void remove_flow13(int flow_id) } /* -* Remove a flow entry from the flow table (OF 1.0) +* Remove a flow entry from the flow table (OF 1.3) * * @param flow_id - the index number of the flow to remove * diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 600c075..9502836 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -833,7 +833,6 @@ void packet_in(uint8_t *buffer, uint16_t ul_size, uint8_t port, uint8_t reason) */ void flow_mod(struct ofp_header *msg) { - /**/TRACE("____________________ FLOWMOD ENTRY"); struct ofp_flow_mod * ptr_fm; ptr_fm = (struct ofp_flow_mod *) msg; @@ -842,27 +841,22 @@ void flow_mod(struct ofp_header *msg) { case OFPFC_ADD: - /**/TRACE("____________________ ADD"); flow_add(msg); break; case OFPFC_MODIFY: - /**/TRACE("____________________ MODIFY"); flow_modify(msg); break; case OFPFC_MODIFY_STRICT: - /**/TRACE("____________________ MODIFY STRICT"); flow_modify_strict(msg); break; case OFPFC_DELETE: - /**/TRACE("____________________ DELETE"); flow_delete(msg); break; case OFPFC_DELETE_STRICT: - /**/TRACE("____________________ DELETE STRICT"); flow_delete_strict(msg); break; From 579d8ea1a37115ba418eea31612e5f715eb738c0 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 26 May 2017 15:43:11 +1000 Subject: [PATCH 166/169] Fix function description --- ZodiacFX/src/openflow/of_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index 5c84566..b7a9eef 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -1015,7 +1015,7 @@ void remove_flow13(int flow_id) } /* -* Remove a flow entry from the flow table (OF 1.3) +* Remove a flow entry from the flow table (OF 1.0) * * @param flow_id - the index number of the flow to remove * From 160208eea46614058153ffeb901ec191ff2f66f6 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 26 May 2017 16:09:37 +1000 Subject: [PATCH 167/169] Fix debug message for flow creation (OF10) --- ZodiacFX/src/openflow/openflow_10.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 9502836..2883406 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -897,7 +897,7 @@ void flow_add(struct ofp_header *msg) of10_error(msg, OFPET10_FLOW_MOD_FAILED, OFPFMFC10_ALL_TABLES_FULL); return; } - TRACE("Allocating %d bytes at %p for flow %d\r\n", sizeof(struct ofp_flow_mod), iLastFlow+1); + TRACE("Allocating %d bytes at %p for flow %d", sizeof(struct ofp_flow_mod), flow_match10[iLastFlow], iLastFlow+1); memcpy(flow_match10[iLastFlow], ptr_fm, sizeof(struct ofp_flow_mod)); From 3a2eb0a9de9f080448e19e3ceea24495474fc737 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 26 May 2017 16:38:12 +1000 Subject: [PATCH 168/169] Add flowmod OF10 TRACE messages uncomment when debugging OF10 issue --- ZodiacFX/src/openflow/openflow_10.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 2883406..c4f4310 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -833,6 +833,7 @@ void packet_in(uint8_t *buffer, uint16_t ul_size, uint8_t port, uint8_t reason) */ void flow_mod(struct ofp_header *msg) { + ///**/TRACE("____________________ FLOWMOD ENTRY"); struct ofp_flow_mod * ptr_fm; ptr_fm = (struct ofp_flow_mod *) msg; @@ -841,6 +842,7 @@ void flow_mod(struct ofp_header *msg) { case OFPFC_ADD: + ///**/TRACE("____________________ ADD"); flow_add(msg); break; From d881dfde34d24556e9d3bd2710f1a39234039691 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Fri, 26 May 2017 17:08:22 +1000 Subject: [PATCH 169/169] Update README for 0.81 --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6f35202..78459f7 100644 --- a/README.md +++ b/README.md @@ -14,17 +14,17 @@ This repository contains the entire open-source firmware for the Zodiac FX inclu The latest firmware is available in the [Northbound Networks Forums](http://forums.northboundnetworks.com/index.php?topic=52.0). -Starting from version 0.80, Zodiac FX supports firmware updates via the CLI and web interface. In order to make this possible, major changes were made to the firmware flashing process. Follow the update process below, based on your current firmware version. +Starting from version 0.81, Zodiac FX supports firmware updates via the CLI and web interface. In order to make this possible, major changes were made to the firmware flashing process. Follow the update process below, based on your current firmware version. -#### For firmware versions BEFORE version 0.80 +#### For firmware versions BEFORE version 0.81 -To update to version 0.80 or later, a **full upgrade firmware** needs to be flashed. +To update to version 0.81 or later, a **full upgrade firmware** needs to be flashed. Download the latest **full upgrade firmware** from the [Northbound Networks Forums](http://forums.northboundnetworks.com/index.php?topic=52.0) - 'Full Upgrade Firmware (v0.XX) - ZodiacFX_vXX_full_install.bin' Follow the firmware update process detailed in **Section 2. Updating Firmware** in the [Zodiac FX User Guide](http://forums.northboundnetworks.com/downloads/zodiac_fx/guides/ZodiacFX_UserGuide_0317.pdf). -#### For firmware versions AFTER version 0.80 +#### For firmware versions AFTER version 0.81 The update process has been simplified for the newer releases. @@ -83,7 +83,7 @@ The Zodiac FX uses a simple additive checksum to verify the integrity of the upl To sign your own modified firmware, follow the steps below: * Build a 'Release' binary of the modified firmware * Update the Zodiac FX with the modified firmware - * Follow the instructions outlined in Flashing/Updating the Firmware - For firmware versions AFTER version 0.80 + * Follow the instructions outlined in Flashing/Updating the Firmware - For firmware versions AFTER version 0.81 * The firmware will fail the verification check, but will still be stored inside the Zodiac FX flash memory * In the root context of the CLI, type in the hidden command 'get crc' * Open the ZodiacFX.bin file in a hex editor, and append the 8 bytes to the end of the firmware file @@ -99,6 +99,12 @@ Issues can also be [raised](https://github.com/NorthboundNetworks/ZodiacFX/issue ## Release Notes +**Version 0.81** +* Firmware upload fixes (full upgrade required) +* Metering bug-fixes & updates (initial DSCP remark support) +* Port stat output bug-fixes +* Web interface improvements + **Version 0.80** * Firmware upload via CLI and web interface added * Metering added to OpenFlow 1.3