Those helpers allow to define some typical kinds of chat matches and
scripts with more ease/less boilerplate.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
A Kconfig item is added and the buffer
is embedded into the modem_cmux struct.
The default value is increased from 16 to 64 bytes in
an effort to reduce the number of modem_pipe_receive() calls.
CONFIG_MODEM_CHAT_LOG_BUFFER is renamed
to CONFIG_MODEM_CHAT_LOG_BUFFER_SIZE for consistency.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
Add a configurable delay between when a byte is received and
MODEM_PIPE_EVENT_RECEIVE_READY is sent.
This fixes data reception at baud rates above 460800, and
most likely also reduces the workload at any baud rate
when receiving bytes by not going through the work item
and callbacks for every single byte.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
- Set all the state bits before calling uart_rx_enable() because
interrupts may happen already before it returns.
- Fix the byte count in the "Receive buffer overrun" log.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
- Add the frame data length to the frame header log.
- Log the dropped frames as well.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
The previous default value made UART TXs of size > 1145
time out at a baud rate of 115200.
It should not be so small that it can cause undesirable timeouts.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
MODEM_UBX: Adds Support for UBX Messages in Modem Subsystem.
GNSS API Supported: get_supported_systems, set_fix_rate, get_fix_rate,
set_enabled_systems, get_enabled_systems, set_navigation_mode,
get_navigation_mode.
Boards Tested: MIMXRT1062_FMURT6, VMU_RT1170.
Note: Partial support for U-BLOX Messages is provided as of now.
Signed-off-by: Sumit Batra <sumit.batra@nxp.com>
Signed-off-by: Mayank Mahajan <mayankmahajan.x@nxp.com>
The added configuration files allow the sample to be run
on the nRF52840 present on the nRF9160 DK with the nRF9160
(running SLM) being the modem and communication happening
through pins that are routed internally between the two.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
This allows to properly drop single CMUX frames that are
too big to fit in the receive buffer, keeping track of
where they end so that following frames are received
correctly regardless of the data contents.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
The SOF delimiter byte may be omitted when a frame follows another
that just ended with that byte.
The parsing used to expect that second delimiter anyway,
which resulted in PPP frames going missing.
As an additional improvement, dropped bytes as well as the length
of received frames are now (debug) logged.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
modem_pipe_attach() can send events before returning, which could
provoke a crash as ppp->pipe, still NULL at that time, could be
used either in receiving (if the pipe had some data pending) or
in sending (if the PPP module had already been attached and had
some data to send in its transmit buffer).
ppp->pipe is now set before modem_pipe_attach().
Also, the ATTACHED_BIT is now set only after having actually attached.
And finally, the send_work is now scheduled on PIPE_EVENT_OPENED
so that data is flushed when the (closed) attached pipe is opened.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
This makes the modem backends use the log level
set for the modem modules instead of the default one.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
Changes include:
- Improving handling of frames for unconfigured DLCIs.
- Adding logs and outputting error codes in failure cases.
- Adding warnings to not reuse buffers.
- Fixing comments.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
Refactors modem chat module to use TRANSMIT_IDLE event instead
of polling when transmitting, cleaning up the transmit handler
by combining duplicate code and using an internal state instead
of multiple iterators to track send state.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Remove receive and transmit timeouts which are no
longer useful as the RECEIVE_READY and
TRANSMIT_IDLE events will be used to efficiently
manage timeouts between transmit/receive calls.
Then update the the in-tree drivers using the
modem_chat module to omit the process timeout
parameter.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Implement TRANSMIT_IDLE event for modem_ppp module. This addition
optimizes the sys workque CPU time when performing a throughput
test from 36% to 5%, while only reducing the throughput by 12%.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Use transmit idle event to synchronize with data transmitted
through DLCI pipes to test TRANSMIT_IDLE implementation.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Implement transmit idle event both for transmitting data to the
bus, and for the individual DLCI channels.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
This PR makes the modem_chat wait until a chat script chat
request has been sent before accepting responses to said
request.
This helps ensure that an unsolicitet response is not mistaken
for a response to a request, which is especially problematic
if the chat script chat is using an any match.
For example, start chat script sending AT+CGMI, expecting the
modem name as a response followed by OK
> start script, waiting for response immediately
> start sending "AT+CGMI"
> receive "+CEREG 1,0" while sending
> script accepts "+CEREG 1,0" as the response to "AT+CGMI"
> "AT+CGMI" sent
> receive "QUECTEL BG95"
> receive "OK"
script handler got "+CEREG 1,0" instead of "QUECTEL BG95"
After this PR:
> start script
> start sending AT+CGMI
> receive "+CEREG 1,0" while sending
> "AT+CGMI" sent
> start waiting for response
> receive "QUECTEL BG95"
> script accepts "QUECTEL BG95" as response to "AT+CGMI"
> receive "OK"
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
This optimization aggregates frame headers before adding to the ring buffer
and computes the FCS of the frame header in one operation.
This approach improves execution efficiency and reduces memory footprint.
This code adjustment aligns with the changes proposed in https://github.com/zephyrproject-rtos/zephyr/pull/67062.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Implement transmit idle notification for TTY backend. Since TTY
has an "infinite" transmit buffer, we invoke transmit idle
immediately after writing the data to the TTY file.
The test suite for the TTY backend has been updated to match the
new behavior.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Make async and interrupt driven UART backends notify transmit
idle when transmit is idle.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Add transmit idle event to modem_pipe_event enum. This will
allow modules to await transmit idle before trying to transmit
more data, instead of blindly calling modem_pipe_transmit in
a loop until all data has been accepted.
This will reduce the time spent trying to transmit data while
the backend is blocked.
Similarly to the RECEIVE_READY event, backends will call
modem_pipe_notify_transmit_idle() to indicate that transmit
is idle, and the TRANSMIT_IDLE event will be reinvoked when
the modem pipe is attached to synchronize the state of the
pipe with the user of it.
Additionally, the TRANSMIT_IDLE event is also invoked when the
modem is opened to further help synchronization with the user
of the pipe.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Some modems don't start sending resync flags as described in
3G TS 27.010 V2.0.0 5.2.5, which results in the CMUX being
stuck in resync mode for said modems.
This patch simplifies the resync mechanism to simply drop
invalid frames, and wait for atleast two consequtive frame
flags (stop+start).
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
DLCI receive buffer may overrun if data is not processed fast
enough. This error was not reported before this patch, resulting
in unexplained missing bytes.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
The CMUX resync mechanism can get stuck between states
MODEM_CMUX_RECEIVE_STATE_RESYNC_0 and
MODEM_CMUX_RECEIVE_STATE_RESYNC_1 if the resync flags, which are
sent only once in state MODEM_CMUX_RECEIVE_STATE_SOF, are not
responded to, or the response is lost.
This patch ensures resync flags are sent from states
MODEM_CMUX_RECEIVE_STATE_SOF, MODEM_CMUX_RECEIVE_STATE_RESYNC_1
and MODEM_CMUX_RECEIVE_STATE_RESYNC_2 if its determined that the
resync flags are not being responded to.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
The chat module contains an array of three lists of matches,
one of which are static, two of which are contained within the
currently running script. The current match, which is an
object stored in one of the three lists, is stored in its own
pointer in the chat module context.
A memory error occurs when the script is stopped, while the
chat module is using one of the matches stored withing the
script. This commit clears the match pointer when the script
is stopped if the match is stored within the script.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
In cases where the data is bigger than 127 bytes,
the first bit of the second byte of the data length field
used to always be set.
This is wrong as according to the 3GPP 27.010 spec
only the first bit of the first byte is the EA bit;
all the others denote the data length.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
Added missing command and message handling for use existing
modem cmux for DCE role.
DCE CMUX connection can be now initialized from DTE side.
Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
The UART flush is not relevant for the async UART implementation.
UART drivers should handle this internally.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Use single ring buffer and protect it with a spinlock as it is
shared between backend and UART thread (ISR). This is simpler
than the double ring buffer setup.
The receive idle timeout has also been made configurable
instead of being a hardcoded value.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
The current implementation only waits for the RX disabled event
to determine if the UART is closed. It should wait for all RX
buffers to be released, and the TX to be done as well.
We now also call uart_tx_abort() when closing the pipe.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Possible NULL pointer dereferences where discovered by static
code analysis, they are addressed in this commit.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
This commit reuses the string "Unknown %s frame type" for two
log messages, as suggested by ycsin.
Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
This commit resets the state of the CMUX receive state
machine when the CMUX instance is attached to a pipe.
Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
This commit adds logging for CMUX frames and commands and
their data, for both transmit and receive. It also removes
the superseded LOG_DBG() lines like "Received frame".
Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
This commit resets the receive ring buffer for each DLCI
pipe when they are opened. They may have old data stored
from last time they where opened.
Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
This commit adds a check to the async connect and disconnect
functions to validate the CMUX is not already connected
or disconnected respectively. This was already part of the
sync connect and disconnect functions, so the sync functions
now simply wrap the async functions to avoid duplicate code.
Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>