Serial Networks - FERAL Features¶
FERAL Configuration¶
RS-232¶
The following parameter can be configured for RS-232:
- bitRate
- startBits
- stopBits
- parityBits
Configuration Example
...
class RS232-config {
void RS232_2Nodes_115KBit_8E1() {
// Expected event sequence
// bit rate = 115200 --> 1bit takes 8.681us
ExpectedTimedLongEventSequence expectedEvents = new ExpectedTimedLongEventSequence(List.of(500190960L, 1L,// would be 190972, but rounding takes its edge
1000190960L, 2L, 1500190960L, 3L, 2000190960L, 4L));
receiver.setEventReceiver(expectedEvents);
configureRS232Network(115_200, 1, 1, 1);
runScenarioAndCheckResult(expectedEvents);
}
private void configureRS232Network(long bitRate, int startBits, int stopBits, int parityBits) {
network.setBitRate(bitRate);
network.setStartBits(startBits);
network.setStopBits(stopBits);
network.setParityBits(parityBits);
}
}
...
For further information of the parameter refer to the RS-232 section below.
SPI¶
The following parameter can be configured for SPI:
- bitRate
Configuration Example
...
class SPI-config {
SPINetwork network = new SPINetwork(director, 2);
network.setName("SPI network");
network.setBitRate(10_000_000);
}
For further information of the parameter refer to the SPI section below.
Test¶
RS-232¶
Example test code for a RS-232 component.
RS232-test Example
...
class RS232-test {
Scenario simulationScenario;
Director director;
SenderEventWorker sender;
ReceiverEventWorker receiver;
RS232Network network;
@BeforeEach
void setup() {
simulationScenario = new SimulationScenario();
director = new DiscreteEventMOCC("root director", simulationScenario);
sender = new SenderEventWorker(director, 1, SimulationDuration.ms(500));
receiver = new ReceiverEventWorker(director);
network = new RS232Network(director, 2);
// - Setup communication interfaces
network.getTopology().getApplicationInterface(0).addTxMessageType("", "app", 2);
network.getTopology().getApplicationInterface(1).addRxMessageType("", "app", 2);
// - Setup links from/to network
new Link(sender.getOutputPort("comm"), network.getTopology().getApplicationInterface(0).getInputPort("app"));
new Link(network.getTopology().getApplicationInterface(1).getOutputPort("app"), receiver.getInputPort("comm"));
}
@Test
@Tag("IntegrationTest")
void RS232_2Nodes_115KBit_8E1() {
// Expected event sequence
// bit rate = 115200 --> 1bit takes 8.681us
ExpectedTimedLongEventSequence expectedEvents = new ExpectedTimedLongEventSequence(List.of(500190960L, 1L,// would be 190972, but rounding takes its edge
1000190960L, 2L, 1500190960L, 3L, 2000190960L, 4L));
receiver.setEventReceiver(expectedEvents);
configureRS232Network(115_200, 1, 1, 1);
runScenarioAndCheckResult(expectedEvents);
}
private void configureRS232Network(long bitRate, int startBits, int stopBits, int parityBits) {
network.setBitRate(bitRate);
network.setStartBits(startBits);
network.setStopBits(stopBits);
network.setParityBits(parityBits);
}
}
SPI¶
Example test code for a SPI component.
SPI-test Example
...
class SPI-config {
@Test
@Tag("IntegrationTest")
void test() {
// Expected event sequence
// bit rate is 10MBits/s --> 1 bit takes 100ns
ExpectedTimedLongEventSequence expectedEvents = new ExpectedTimedLongEventSequence(List.of(
500001600L, 1L,
1000001600L, 2L,
1500001600L, 3L,
2000001600L, 4L
));
Scenario simulationScenario = new SimulationScenario();
Director director = new DiscreteEventMOCC("root director", simulationScenario);
// Discrete event applications for maximum accuracy
SenderEventWorker sender = new SenderEventWorker(director, 1, SimulationDuration.ms(500));
ReceiverEventWorker receiver = new ReceiverEventWorker(director, expectedEvents);
// SPI network configuration
SPINetwork network = new SPINetwork(director, 2);
network.setName("SPI network");
network.setBitRate(10_000_000);
// - Setup communication interfaces
network.getTopology().getApplicationInterface(0).addTxMessageType("", "app", 2);
network.getTopology().getApplicationInterface(1).addRxMessageType("", "app", 2);
// - Setup links from/to network
new Link(sender.getOutputPort("comm"), network.getTopology().getApplicationInterface(0).getInputPort("app"));
new Link(network.getTopology().getApplicationInterface(1).getOutputPort("app"), receiver.getInputPort("comm"));
simulationScenario.startSimulation(SimulationTime.ms(2200));
assertTrue(expectedEvents.check());
}
}
RS-232¶
The term RS-232 stands for "Recommended Standard 232" and it is a type of serial communication used for transmission of data normally in medium distances (up to 50 feet with the rate of 1.492kbps). As EIA defines, the RS232 is used for connecting Data Transmission Equipment (DTE) and Data Communication Equipment (DCE).
RS232 works on the two-way communication that exchanges data to one another. There are two devices connected to each other, (DTE) Data Transmission Equipment& (DCE) Data Communication Equipment which has the pins like TXD, RXD, and RTS& CTS. Now, from DTE source, the RTS generates the request to send the data. Then from the other side DCE, the CTS, clears the path for receiving the data. After clearing a path, it will give a signal to RTS of the DTE source to send the signal. Then the bits are transmitted from DTE to DCE. Now again from DCE source, the request can be generated by RTS and CTS of DTE sources clears the path for receiving the data and gives a signal to send the data. This is the whole process through which data transmission takes place.
Abbreviation | Description |
---|---|
TXD | Transmitter |
RXD | RECEIVER |
RTS | REQUEST TO SEND |
CTS | CLEAR TO SEND |
GND | GROUND |
For example: The signals set to logic 1. The data transmission starts from next bit and to inform this, DTE sends start bit to DCE. The start bit is always ‘0’ & next 5 to 9 characters is data bits. If we use parity bit, then 8 bits data can be transmitted whereas if parity doesn’t use, then 9 bits are being transmitted. The stop bits are sent by the transmitter whose values are 1, 1.5 or 2 bits after the data transmission.
SPI¶
SPI (Serial Peripheral Interface) is an interface bus commonly used for communication with flash memory, sensors, real-time clocks (RTCs), analog-to-digital converters, and more. The Serial Peripheral Interface bus was developed by Motorola to provide full-duplex synchronous serial communication between master and slave devices. SPI is a "synchronous" data bus, and a "clock" keeps both sides in perfect sync. The clock is an oscillating signal that tells the receiver exactly when to sample the bits on the data line. This could be the rising (low to high) or falling (high to low) edge of the clock signal. When the receiver detects that edge, it will immediately look at the data line to read the next. Because the clock is sent along with the data, specifying the speed isn't important, although devices will have a top speed at which they can operate.
SPI uses a master–slave architecture, described here with the terms "main" and "sub", where one main device orchestrates communication with some number of peripheral (sub) devices by driving the clock signal and chip select signal(s). A standard SPI connection involves a master connected to slaves using the serial clock (SCK), Master Out Slave In (MOSI), Master In Slave Out (MISO), and Slave Select (SS) lines. The SCK, MOSI, and MISO signals can be shared by slaves while each slave has a unique SS line.
SPI has four logic signals (which may have alternative names):
Abbreviation | Long name | Description |
---|---|---|
CS | Chip Select | Active-low chip select signal from main (master) to enable communication with a specific sub (slave) device. |
SCLK | Serial Clock | Clock signal from main (master) transitions for each serial data bit. |
MOSI | Main Out, Sub In (master out, slave in) | Serial data from main (master), highest bit first. |
MISO | Main In, Sub Out (master in, slave out) | Serial data from sub (slave), highest bit first. |
Data frames The SPI interface defines no protocol for data exchange, limiting overhead and allowing for high-speed data streaming. Clock polarity (CPOL) and clock phase (CPHA) can be specified as ‘0’ or ‘1’ to form four unique modes to provide flexibility in communication between master and slave. An SPI data frame is defined by the SS signal, and no start or stop bits are used (so, every SCLK transfers a data bit). The master must drive the SS signal to a given slave in order to initiate a read or a write. After SS is asserted (typically low), eight or more clock transitions can be asserted depending on the number of bits that must be transferred. Most SPI devices use units of 8-bit bytes, but any data size can be used.
Data transmission To begin communication, the SPI main first selects a sub-device by pulling its CS low If a waiting period is required, the main must wait for at least that period before issuing clock cycles. During each SPI clock cycle, full-duplex transmission of a single bit occurs. The main sends a bit on the MOSI line while the sub sends a bit on the MISO line, and then each reads their corresponding incoming bit. This sequence is maintained even when only one-directional data transfer is intended.
Clock polarity and phase In addition to setting the clock frequency, the main must also configure the clock polarity and phase concerning the data.