These functions are used by weAutSys in due sequence to initialise the basic modules of the target, i.e mainly weAut_01, hardware. The use of those initialisation functions by user / application software requires extra care.
Data Structures | |
struct | conf_data_t |
The device's basic configuration data type. More... | |
Defines | |
#define | B1D6MODE_NONE 0 |
Usage mode of ports PD6 and PB1: none. | |
#define | B1D6MODE_RTSCTS_FLOWC 0x11 |
Usage mode of ports PD6 and PB1: RTS CTS input flow control. | |
#define | B1MODE_MASK 0xF0 |
Usage mask for PB1. | |
#define | B1MODE_RTS_FLOWC 0x10 |
Usage mode of port PB1 : RTS output flow control. | |
#define | D6MODE_CTS_FLOWC 0x01 |
Usage mode of port PD6 : CTS input flow control. | |
#define | D6MODE_MASK 0x0F |
Usage mask for PD6. | |
#define | ENCBUF_END 0x1FFF |
ENC's dual port RAM end. | |
#define | isCTSflowC |
Usage mode of port PD6 : CTS input flow control. | |
#define | isRTSflowC |
Usage mode of port PB1: RTS output flow control. | |
#define | RXBUF_END 0x1A0D |
Receive buffer end. | |
#define | TXBUF_STRT 0x1A0E |
Transmit buffer start. | |
Functions | |
void | encInit (void) |
Initialise the Ethernet controller ENC28J60. | |
void | encReset (void) |
Reset the Ethernet controller ENC28J60. | |
void | encSetBufferLimits (void) |
Set the sizes of ENC28J60's receive and transmit buffers. | |
uint8_t | getB1D6mode (void) __attribute__((always_inline)) |
Get the usage of the ports PD6 and PB1. | |
void | lanComStdInit (void) |
Initialise the LAN communication (standard way) | |
void | networkInit (void) |
Initialise the network stack. | |
void | persistInit (void) |
Initialise persistence / EEPROM handling. | |
void | setB1D6mode (uint8_t mode) |
Set the usage of the ports PD6 and PB1. | |
uint32_t | uartBaud (uint16_t uartPrescal, uint8_t x2) |
Calculate the true baudrate for a prescaler setting. | |
void | uartInit (uint16_t baudDivide, uint8_t x2, uint8_t len, uint8_t parity, uint8_t stopBits) |
Initialise the serial input (UART0) | |
uint16_t | uartPrescaler (uint32_t baudRate, uint8_t x2) |
Calculate the prescaler setting for a desired baudrate. | |
void | uartSetBaudDivide (uint16_t baudDivide) __attribute__((always_inline)) |
Set the UART0's baudrate divisor. | |
Variables | |
uint16_t | actPackInd |
Index of the actual receive packet in ENC's dual port memory. | |
conf_data_t | defaultConfData |
The device's basic default configuration data. | |
conf_data_t | defaultTypeConfData |
The device type's basic default configuration data in flash memory. |
#define RXBUF_END 0x1A0D |
Receive buffer end.
This should be an odd value due to ENC's bug B7 list point 11 (called ERXND there). Due to a bug the receive buffer start will always be 0x0000 i.e. the start of ENC's dual port RAM.
This setting (1A0D = 6669) leaves 5F2 = 1522 bytes for send buffer (and all else). This in-balance is due to not having multiple send packets in the ENC buffer which would hardly be organised with uIP while having multiple incoming packets buffered is normal operation.
#define TXBUF_STRT 0x1A0E |
Transmit buffer start.
This is the minimal and the initial / default value for the start of a transmit package in the dual port RAM. It should be even (due to an ENC bug) and must be larger than RXBUF_END as well as (considerably) smaller than the ENCBUF_END.
#define B1D6MODE_NONE 0 |
Usage mode of ports PD6 and PB1: none.
Application software may set and use these ports freely.
#define B1MODE_MASK 0xF0 |
Usage mask for PB1.
The upper four bits of b1d6Mode concern Port B1. If non of those bits is set the application software may set and use this port freely — i.e. according to hardware / jumpers.
#define D6MODE_MASK 0x0F |
Usage mask for PD6.
The lower four bits of b1d6Mode concern Port D6. If non of those bits is set the application software may set and use this port freely — i.e. according to hardware / jumpers.
#define D6MODE_CTS_FLOWC 0x01 |
Usage mode of port PD6 : CTS input flow control.
The port PD6 must be connected to the CTS output via a level shifter / inverter (MAX202 e.g.).
In this mode the UART software will signal their ability to receive more bytes according to UART_IN_SPACE_LIM (off) resp. (3 * UART_IN_SPACE_LIM) (om).
#define isCTSflowC |
Usage mode of port PD6 : CTS input flow control.
#define B1MODE_RTS_FLOWC 0x10 |
Usage mode of port PB1 : RTS output flow control.
The port PB1 must be connected to the RTS input via a level shifter / inverter (MAX202 e.g.).
In this mode the UART software will send only if the other station sets RTS to logic 0 (+12V).
Two (weAut_01 / weAutSys) devices with both set and jumpered to B1D6MODE_RTSCTS_FLOWC may very well be P2P connected by serial link.
#define isRTSflowC |
Usage mode of port PB1: RTS output flow control.
#define B1D6MODE_RTSCTS_FLOWC 0x11 |
Usage mode of ports PD6 and PB1: RTS CTS input flow control.
The port PD6 must be connected to the CTS output and PB1 to the RTS input — both via level shifters / inverters (MAX202 e.g.).
In this mode the UART software will use those ports for input and output flow control and all other settings and uses by application software are forbidden interference.
This is, of course, just D6MODE_CTS_FLOWC and B1MODE_RTS_FLOWC combined
void encSetBufferLimits | ( | void | ) |
Set the sizes of ENC28J60's receive and transmit buffers.
The ENC28J60's total buffer is 8191 bytes. This function divides this to a larger buffer for received packets at the begin and a smaller part as buffer for a transmit package (and maybe for all else).
Before changing the buffer limits this function disables and resets the receiver and transmitter and leaves it so (i.e. in reset state).
The receive packet index actPackInd as well as read and write pointers are set accordingly.
/note This function uses macros (defines) to set the buffer sizes.
void encReset | ( | void | ) |
Reset the Ethernet controller ENC28J60.
This function sends a (software) reset command to the ENC28J60. Due to an ENC28J60 bug (B7 errata point 1) this reset is quite hard as it scrambles the ENC's internal clocking. The only workaround is waiting 1 ms before attempting further accesses.
This function does nothing else: a) no further ENC settings due to the bug and b) no (conditional) log message, as for usages early after reset, no logging resources (like UART e.g.) may be available.
void encInit | ( | void | ) |
Initialise the Ethernet controller ENC28J60.
This function initialises the Ethernet driver ENC28J60 but does not reset it. This function should be called not earlier than 1ms after resetting the ENC by hardware signal or software command.
This function checks ENC's (PHY) clock ready and does nothing but setting the bit ENC_HWP in networkNotReady.
Otherwise the initialisation is done and all ENC related bits in networkNotReady will be cleared.
void networkInit | ( | void | ) |
Initialise the network stack.
This function initialises the Ethernet driver ENC28J60 and the uIP stack.
The driver IC ENC28J60 is not reset (encReset) here.
void lanComStdInit | ( | void | ) |
Initialise the LAN communication (standard way)
This function initialises the LAN communication in a standard way. If use DHCP is set in curIpConf (.useFlags) DHCP is initialiesd and nothing else is done.
Otherwise the IP configuration is set by the default configuration and NTP is initialised if be NTP client is set.
void persistInit | ( | void | ) |
Initialise persistence / EEPROM handling.
This function uses spin waiting for EEPROM (write) operations. It is to be used in initialisation (after reset) only.
void uartSetBaudDivide | ( | uint16_t | baudDivide | ) |
Set the UART0's baudrate divisor.
This function sets the baud rate prescaler register and hence the baud rate.
It is normally called indirectly while initialising. Calling while running may spoil ongoing transmissions.
baudDivide | 0..4096 |
void uartInit | ( | uint16_t | baudDivide, |
uint8_t | x2, | ||
uint8_t | len, | ||
uint8_t | parity, | ||
uint8_t | stopBits | ||
) |
Initialise the serial input (UART0)
This function is normally used after system reset.
To call this function while the system is running is not recommended or should at least be considered and tested very carefully.
UART 0 is initialised in asynchronous mode for receiving and transmitting (full duplex).
baudDivide | 0..4096 prescaler |
x2 | true: double speed (half receive samples) |
len | 5,6,7, 8 [default] (9 [not yet supported]) |
parity | 0=false: none; odd , even value: odd, even |
stopBits | 2: 2 stop bits, 1 [default]: 1 stop bit |
uint8_t getB1D6mode | ( | void | ) |
Get the usage of the ports PD6 and PB1.
These µController ports can be used in a variety of ways independent of the serial communication link. In the weAut_01 module PD5 can be jumpered to the CTS output via MAX202 level shifter / inverter and PB1 can be jumpered to the RTS input.
If so connected they may be used for input (RTS-) CTS- flow control if this mode is set so.
void setB1D6mode | ( | uint8_t | mode | ) |
Set the usage of the ports PD6 and PB1.
mode | the new mode |
uint16_t uartPrescaler | ( | uint32_t | baudRate, |
uint8_t | x2 | ||
) |
Calculate the prescaler setting for a desired baudrate.
The calculated and returned prescaler
divisor setting must be in the range 0 .. 4096. Otherwise the desired baudRate
can't even be approximated with the given processor frequency (e.g. F_CPU=20000000).
The effective baudRate can be calculated by uartBaud(uint16_t, uint8_t) to check the tolerance/error.
x2 | true: double speed (half receive samples) |
baudRate | the rate desired |
uint32_t uartBaud | ( | uint16_t | uartPrescal, |
uint8_t | x2 | ||
) |
Calculate the true baudrate for a prescaler setting.
uartPrescal | 0..4096 prescaler |
x2 | true: double speed (half receive samples) |
uint16_t actPackInd |
Index of the actual receive packet in ENC's dual port memory.
If at least one package has been received this will be the index to its begin. Most of the time this should be in accordance with ERXRDPT. Under most circumstances this must not be modified by user / application software.
The device's basic default configuration data.
These are the basic configuration data specific to the individual device. To survive power off one copy of these data is to be held in EEPROM at address eeConfigAdd = EEPROM[ EEPROM_POINTER2_EE_CONF ].
The device type's basic default configuration data in flash memory.
These are the basic default configuration data specific to the device type. These values typically are used only as long as no other device specific (individual) values were set in persistent EEPROM storage.
So this is just the first startup default before commissioning to use.