Chau Vo / device_configuration

Dependents:   F103-Web-Server

Fork of my_eeprom_funcs by Chau Vo

my_eeprom_funcs.h

Committer:
olympux
Date:
2016-06-16
Revision:
13:7ffbbfe999c5
Parent:
12:613ab276bf37
Child:
14:17a44517b13d

File content as of revision 13:7ffbbfe999c5:

#ifndef __MY_EEPROM_FUNCS_H
#define __MY_EEPROM_FUNCS_H

#include "eeprom.h"


/*
* Default device network configuration
*/
#define DEFAULT_IP_ADDRESS      "192.168.0.249"
#define DEFAULT_IP_SUBNET       "255.255.255.0"
#define DEFAULT_IP_GATEWAY      "192.168.0.1"
#define DEFAULT_MAC0            0x00
#define DEFAULT_MAC1            0x08
#define DEFAULT_MAC2            0xDC
#define DEFAULT_MAC3            0x00
#define DEFAULT_MAC4            0x00
#define DEFAULT_MAC5            0x01

#define DEFAULT_ENABLE_FLAG_VALUE   0xA5A5
#define DEFAULT_DISABLE_FLAG_VALUE  0xAAAA

/*
* Positions of variables in EEPROM array
*/
#define IP_ADDRESS_POS         0
#define IP_SUBNET_POS          4
#define IP_GATEWAY_POS         8
#define TCP_SERVER_LOCAL_PORT_POS   12
#define UDP_SERVER_LOCAL_PORT_POS   13
#define CONFIGURED_IP_FLAG_POS      14
#define MAC_ADDRESS_POS        15
// EEPROM: for setting TCP server where this device connects to in TCP client mode
#define AUTO_TRANSMIT_FLAG_POS  18
#define AUTO_TRANSMIT_TIME_PERIOD_POS    19
#define TCP_SERVER_IP_ADDR_POS  20
#define TCP_SERVER_PORT_POS     24
#define ENABLE_TCP_SERVER       25
#define ENABLE_TCP_CLIENT       26
#define ENABLE_UDP_SERVER       27


/*
* External variables in main.c
*/
extern uint16_t VirtAddVarTab[];

// Device configuration
extern uint16_t u16ip_addr[], u16ip_subnet[], u16ip_gateway[], u16mac_addr[]; // 16-bits, directly loaded from eeprom
extern char str_ip_addr[], str_ip_subnet[], str_ip_gateway[], str_mac[]; // for printf and RPC, converted from 16-bits u16ip_xxx
extern uint8_t u8ip_addr[];// keep ip address in 8-bits
extern uint16_t configured_ip;  // flag indicates a static ip has been configured 0xA5A5
extern uint8_t u8mac[]; // mac in 8-bits

// TCP/UDP server
extern uint16_t tcp_server_local_port; // change to 7000 if internet required
extern uint16_t udp_server_local_port;

// TCP client
// this section is used to set the TCP server that this device connects to in TCP client mode.
// this device will update its status to the server every transmit_time_period.
extern uint16_t auto_transmit_flag, transmit_time_period ; // auto transmit status, time period = 1s
extern uint16_t u16server_ip_addr[]; // directly loaded from eeprom
extern uint8_t u8server_ip_addr[]; // server ip address in 8-bits
extern char str_server_ip_addr[];// for printf, converted from 16-bits u16server_ip_addr
extern uint16_t u16tcp_server_port; // directly loaded from eeprom
extern uint16_t u16enable_tcp_server, u16enable_tcp_client;// flags for enabling TCP client or TCP server

void write_eeprom_network(char* buf);
void load_eeprom_network(void);
void write_eeprom_tcpserver(char* buf);
void load_eeprom_tcpserver(void);

#endif