From ea812b14c037816196adf2443815ca4a149f38d6 Mon Sep 17 00:00:00 2001
From: Kristopher Chen "\
"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)
"