serial.h File Reference


Detailed Description

API for serial communication via UART or SPI.

Software License
See the MBCSL for details.
Author:
Sven Schlender (kontakt at mobacon dot de)
Date:
2010-10-29

enum  UARTBaudrates_t {
  BAUDRATE_0_3 = 0, BAUDRATE_1_2, BAUDRATE_2_4, BAUDRATE_9_6,
  BAUDRATE_19_2, BAUDRATE_57_6, BAUDRATE_115_2, BAUDRATE_4_8,
  BAUDRATE_38_4, BAUDRATE_COUNT
}
 The supported baudrates of the UART module. More...
enum  SPIModes_t {
  SPIMODE_0 = 0, SPIMODE_1, SPIMODE_2, SPIMODE_3,
  SPIMODE_COUNT
}
 The typical SPI master clock modes. More...
enum  SPIClockFrequencies_t {
  SPIFREQ_10M4 = 0, SPIFREQ_2M6, SPIFREQ_650K, SPIFREQ_COUNT,
  SPIFREQ_SLAVE
}
 The supported clock frequencies in SPI master mode. More...
enum  SerialServerConnection_t { SERIAL_SERVER_NOT_RUNNING = 0, SERIAL_SERVER_IS_LISTENING, SERIAL_SERVER_CONNECTED }
 The serial server states. More...
void SerialInit (SerialMode_t Mode)
 Initializes the serial module in the requested mode.
WORD SerialGetTCPPort (BOOL bPersistent)
 Delivers the current configured TCP port of the serial server.
UARTBaudrates_t SerialGetUARTBaudrate (void)
 Delivers the currently used baudrate in the UART mode.
SPIClockFrequencies_t SerialGetSPIFrequency (void)
 Delivers the currently used frequency of SPI master mode.
SPIModes_t SerialGetSPIMode (void)
 Delivers the currently used clock mode in SPI master mode.
BOOL bSerialGetSPIMasterSample (void)
 Delivers the sampling mode of the input signal in SPI master mode.
void SerialSetUARTBaudrate (UARTBaudrates_t eBaudrate)
 Sets the UART baudrate in UART mode.
void SerialSetSPIMasterSample (BOOL bSample)
 Sets the sampling mode of the input signal in SPI master mode.
void SerialSetSPIFrequency (SPIClockFrequencies_t Frequency)
 Sets the clock frequency in SPI master mode.
void SerialSetSPIMode (SPIModes_t Mode)
 Sets the SPI clock mode in SPI master mode.
void SerialSetTCPPort (WORD Port)
 Configures a new TCP port for the serial server.
void SerialResetToFactory (void)
 Resets the serial module EEPROM section to well known start parameters.
BOOL SerialInitTask (void)
 After initializing network and application stuff the application should call this function to prepare task members needed for proper serial task operation.
void SerialStopTask (void)
 On network errors or shut down events these function should be called by the main application to proper stop the serial tasks (i.e disconnecting a connected client).
BOOL bSerialCheckForStoppedTask (void)
 Before shutting down the application should poll for valid serial task shutdown.
void SerialTask (void)
 Call this function periodically from main application to execute serial module tasks.
SerialServerConnection_t SerialGetServerState (void)
 This function delivers the current state of the serial server.
DWORD SerialGetConnectedIP (void)
 Delivers the IP of a client who is connected to serial server.
DWORD SerialGetTXCounter (void)
 Delivers the count of bytes the serial server has received from a client.
DWORD SerialGetRXCounter (void)
 Delivers the count of bytes the serial server has sent to a client.
void SerialSendTCPData (void)
 The given character is put into the TCP/IP transmit FIFO buffer.
void SerialRegisterHandling (void)
 Call this function to serve the virtual register set accessed by the SPI master.
void SerialShutdown (void)
 Call this function to process shutdown actions for serial server and serial connections.


Enumeration Type Documentation

The serial server states.

Enumerator:
SERIAL_SERVER_NOT_RUNNING  Inactive server.
SERIAL_SERVER_IS_LISTENING  Running, waiting for client connect.
SERIAL_SERVER_CONNECTED  Client connected, waiting for data.

The supported clock frequencies in SPI master mode.

Enumerator:
SPIFREQ_10M4  10.4 MBit/s (wow!).
SPIFREQ_2M6  2.6 MBit/s.
SPIFREQ_650K  650 KBit/s.
SPIFREQ_COUNT  Dummy for getting the count of all supported frequencies.
SPIFREQ_SLAVE  Inofficial mode, only internal use.

enum SPIModes_t

The typical SPI master clock modes.

Enumerator:
SPIMODE_0  Transmit occurs on transition from low to high, idle state is low.
SPIMODE_1  Transmit occurs on transition from high to low, idle state is low.
SPIMODE_2  Transmit occurs on transition from high to low, idle state is high.
SPIMODE_3  Transmit occurs on transition from low to high, idle state is high.
SPIMODE_COUNT  Dummy for getting the count of all supported modes.

The supported baudrates of the UART module.

Enumerator:
BAUDRATE_0_3  300 Baud.
BAUDRATE_1_2  1200 Baud.
BAUDRATE_2_4  2400 Baud.
BAUDRATE_9_6  9600 Baud.
BAUDRATE_19_2  19200 Baud.
BAUDRATE_57_6  57600 Baud.
BAUDRATE_115_2  115200 Baud.
BAUDRATE_4_8  4800 Baud.
BAUDRATE_38_4  38400 Baud.
BAUDRATE_COUNT  Dummy for getting the count of all supported baudrates.


Function Documentation

BOOL bSerialCheckForStoppedTask ( void   ) 

Before shutting down the application should poll for valid serial task shutdown.

Return values:
TRUE The task has successfully stopped.
FALSE Stopping the serial task is pending.

BOOL bSerialGetSPIMasterSample ( void   ) 

Delivers the sampling mode of the input signal in SPI master mode.

The mode can be read indepently from the current active NetzerIO mode.

Return values:
FALSE Input data sampled at middle of data output time.
TRUE Input data sampled at end of data output time.

DWORD SerialGetConnectedIP ( void   ) 

Delivers the IP of a client who is connected to serial server.

Returns:
The IP address as 32 bit value, 0 if no client is connected.

DWORD SerialGetRXCounter ( void   ) 

Delivers the count of bytes the serial server has sent to a client.

The counter is set to zero while a new session starts.

Returns:
The counter value.

SerialServerConnection_t SerialGetServerState ( void   ) 

This function delivers the current state of the serial server.

Returns:
The current state.

SPIClockFrequencies_t SerialGetSPIFrequency ( void   ) 

Delivers the currently used frequency of SPI master mode.

The frequency can be read indepently from the current active NetzerIO mode.

Returns:
The frequency as enumerated value.

SPIModes_t SerialGetSPIMode ( void   ) 

Delivers the currently used clock mode in SPI master mode.

The mode can be read indepently from the current active NetzerIO mode.

Returns:
The SPI clock mode as enumerated value.

WORD SerialGetTCPPort ( BOOL  bPersistent  ) 

Delivers the current configured TCP port of the serial server.

Parameters:
bPersistent If TRUE the return value is read from EEPROM. If FALSE the value is taken from the current state.
Returns:
The port of the listening serial server.

DWORD SerialGetTXCounter ( void   ) 

Delivers the count of bytes the serial server has received from a client.

The counter is set to zero while a new session starts.

Returns:
The counter value.

UARTBaudrates_t SerialGetUARTBaudrate ( void   ) 

Delivers the currently used baudrate in the UART mode.

The baudrate can be read indepently from the current active NetzerIO mode.

Returns:
The baudrate as enumerated value.

void SerialInit ( SerialMode_t  Mode  ) 

Initializes the serial module in the requested mode.

Should be called once at startup (very early).

Parameters:
Mode Specifies the mode for NetzerIO. GPIO module must know this because it configures some port pins also for the serial modes.

BOOL SerialInitTask ( void   ) 

After initializing network and application stuff the application should call this function to prepare task members needed for proper serial task operation.

Return values:
TRUE Initialization was successful.
FALSE Initialization failed, try again later.

void SerialSendTCPData ( void   ) 

The given character is put into the TCP/IP transmit FIFO buffer.

The function is not thread safe and must only be called from interrupt context routines!

Communication takes place via the global variable SerialIsrCharacter.

void SerialSetSPIFrequency ( SPIClockFrequencies_t  Frequency  ) 

Sets the clock frequency in SPI master mode.

If in SPI master mode the change takes effect directly. The new mode is stored persistent in EEPROM.

Parameters:
Frequency The frequency as enumerated value.

void SerialSetSPIMasterSample ( BOOL  bSample  ) 

Sets the sampling mode of the input signal in SPI master mode.

If in SPI master mode the change takes effect directly. The new mode is stored persistent in EEPROM.

Parameters:
bSample If FALSE, the input data is sampled at middle of data output time. If TRUE, the input data is sampled at end of data output time.

void SerialSetSPIMode ( SPIModes_t  Mode  ) 

Sets the SPI clock mode in SPI master mode.

If in SPI master mode the change takes effect directly. The new mode is stored persistent in EEPROM.

Parameters:
Mode The SPI clock mode as enumerated value.

void SerialSetTCPPort ( WORD  Port  ) 

Configures a new TCP port for the serial server.

This value is stored persistent in EEPROM.

Parameters:
Port The new port value.

void SerialSetUARTBaudrate ( UARTBaudrates_t  eBaudrate  ) 

Sets the UART baudrate in UART mode.

If in UART mode the change takes effect directly. The new mode is stored persistent in EEPROM.

Parameters:
eBaudrate The baudrate as enumerated value.

void SerialStopTask ( void   ) 

On network errors or shut down events these function should be called by the main application to proper stop the serial tasks (i.e disconnecting a connected client).

void SerialTask ( void   ) 

Call this function periodically from main application to execute serial module tasks.


Generated on Fri Mar 29 10:34:28 2013 for Netzer by  doxygen 1.5.5