Used with eeprom_flash to write network configuration to STM32F103 flash

Dependents:   F103-Web-Server

Fork of my_eeprom_funcs by Chau Vo

Files at this revision

API Documentation at this revision

Comitter:
olympux
Date:
Thu Sep 01 14:14:26 2016 +0000
Parent:
21:23ae23754f0b
Commit message:
Add DHCP configuration

Changed in this revision

device_configuration.cpp Show annotated file Show diff for this revision Revisions of this file
device_configuration.h Show annotated file Show diff for this revision Revisions of this file
--- a/device_configuration.cpp	Thu Sep 01 12:22:10 2016 +0000
+++ b/device_configuration.cpp	Thu Sep 01 14:14:26 2016 +0000
@@ -50,6 +50,8 @@
 uint16_t u16SpecialChar;
 // uart
 uint16_t u16UartBaudrate, u16UartBits, u16UartStopBits, u16UartParity, u16UartHandshake;
+// dhcp vs static
+uint16_t u16EnableDHCP;
 
 // extra, not actually in EEPROM
 uint8_t u8IpAddr[4]; // keep device ip address in 8-bits
@@ -82,7 +84,8 @@
             uint16_t* remote_udp_ip, uint16_t remote_udp_port,
             uint16_t enable_tcp_server, uint16_t enable_tcp_client, uint16_t enable_udp_server, uint16_t enable_udp_client,
             uint16_t inter_data_period, uint16_t special_char,
-            uint16_t uart_baudrate, uint16_t uart_bits, uint16_t uart_stopbits, uint16_t uart_parity, uint16_t uart_handshake) {
+            uint16_t uart_baudrate, uint16_t uart_bits, uint16_t uart_stopbits, uint16_t uart_parity, uint16_t uart_handshake,
+            uint16_t enable_dhcp) {
     // Write network configuration
     // 4-byte IP address + 4-byte subnet + 4-byte gateway + 3-byte MAC
     // + local TCP server port + local UDP port
@@ -162,6 +165,9 @@
     writeEEPROMHalfWord(UART_PARITY_POS, uart_parity);
     writeEEPROMHalfWord(UART_HANDSHAKE_POS, uart_handshake);
     
+    // DHCP vs Static
+    writeEEPROMHalfWord(ENABLE_DHCP_POS, enable_dhcp);
+    
     disableEEPROMWriting();
     
     INFO("Successful");
@@ -265,6 +271,9 @@
         u16UartParity = readEEPROMHalfWord(UART_PARITY_POS);
         u16UartHandshake = readEEPROMHalfWord(UART_HANDSHAKE_POS);
         
+        // DHCP
+        u16EnableDHCP = readEEPROMHalfWord(ENABLE_DHCP_POS);
+        
         // convert to strings
         sprintf(strIpAddr, "%d.%d.%d.%d", u8IpAddr[0], u8IpAddr[1], u8IpAddr[2], u8IpAddr[3]);
         sprintf(strIpSubnet, "%d.%d.%d.%d", (uint8_t)u16IpSubnet[0], (uint8_t)u16IpSubnet[1], (uint8_t)u16IpSubnet[2], (uint8_t)u16IpSubnet[3]);
@@ -294,20 +303,22 @@
         
         u16AutoTransmitFlag = DEFAULT_DISABLE_FLAG_VALUE;
         u16TransmitPeriod = DEFAULT_TRANSMIT_PERIOD;
-        
+        // mode
         u16EnableTcpServer = DEFAULT_ENABLE_FLAG_VALUE;
         u16EnableTcpClient = DEFAULT_DISABLE_FLAG_VALUE;
         u16EnableUdpServer = DEFAULT_DISABLE_FLAG_VALUE;
         u16EnableUdpClient = DEFAULT_DISABLE_FLAG_VALUE;
-        
+        // signals
         u16InterDataPeriod = DEFAULT_INTER_DATA_PERIOD;
         u16SpecialChar = DEFAULT_SPECIAL_CHARACTER;
-        
+        // uart
         u16UartBaudrate = DEFAULT_UART_BAUDRATE;
         u16UartBits = DEFAULT_UART_BITS;
         u16UartStopBits = DEFAULT_UART_STOPBITS;
         u16UartParity = DEFAULT_UART_PARITY;
         u16UartHandshake = DEFAULT_UART_HANDSHAKE;
+        
+        u16EnableDHCP = DEFAULT_DISABLE_FLAG_VALUE;
     }
     
     INFO("Successful");
@@ -333,6 +344,8 @@
     
     INFO("Serial inter-data period: %d", u16InterDataPeriod);
     INFO("Special character: %.2x", u16SpecialChar);
+    
+    INFO("DHCP: %s", (u16EnableDHCP == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable");
 }
 
 void reset_default_device_configuration() {
@@ -367,6 +380,8 @@
     uint16_t uart_parity = DEFAULT_UART_PARITY;
     uint16_t uart_handshake = DEFAULT_UART_HANDSHAKE;
     
+    uint16_t enable_dhcp = DEFAULT_DISABLE_FLAG_VALUE;
+    
     // erase the device configured flag
     erase_device_configuration();
     
@@ -377,5 +392,6 @@
             remote_udp_ip, remote_udp_port,
             enable_tcp_server, enable_tcp_client, enable_udp_server, enable_udp_client,
             inter_data_period, special_char,
-            uart_baudrate, uart_bits, uart_stopbits, uart_parity, uart_handshake);
+            uart_baudrate, uart_bits, uart_stopbits, uart_parity, uart_handshake,
+            enable_dhcp);
 }
--- a/device_configuration.h	Thu Sep 01 12:22:10 2016 +0000
+++ b/device_configuration.h	Thu Sep 01 14:14:26 2016 +0000
@@ -66,6 +66,8 @@
 #define UART_STOPBITS_POS       76 // 16-bit
 #define UART_PARITY_POS         78 // 16-bit
 #define UART_HANDSHAKE_POS      80 // 16-bit
+// DHCP vs Static
+#define ENABLE_DHCP_POS         82 // 16-bit
 
 
 // prototypes
@@ -76,7 +78,8 @@
             uint16_t* remote_udp_ip, uint16_t remote_udp_port,
             uint16_t enable_tcp_server, uint16_t enable_tcp_client, uint16_t enable_udp_server, uint16_t enable_udp_client,
             uint16_t inter_data_period, uint16_t special_char,
-            uint16_t uart_baudrate, uint16_t uart_bits, uint16_t uart_stopbits, uint16_t uart_parity, uint16_t uart_handshake);
+            uint16_t uart_baudrate, uint16_t uart_bits, uint16_t uart_stopbits, uint16_t uart_parity, uint16_t uart_handshake,
+            uint16_t enable_dhcp);
 void read_device_configuration();
 void reset_default_device_configuration();