To improve performance in FCS calculation, this commit replaces
the usage of the generic `crc8` function with the specific `crc8_rohc`
function in `modem_cmux.c`.
The `crc8_rohc` function utilizes a small table approach, enhancing
the efficiency of CRC-8/ROHC variant calculations while optimizing
memory usage.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
`ret` holds the amount of bytes received from the modem. However during
processing of the bytes its value is overwritten by the return value of
`modem_ubx_process_received_byte`, in practice discarding all but the
first byte read.
To prevent this, store the length in a separate variable.
Signed-off-by: Anders T. Akre <anders@akre.io>
The modem pipe APIs include synchronous calls to open/close,
which internally use a fixed timeout of 10 seconds. The timeout
should be configurable through the APIs, anywhere from K_NO_WAIT
to K_FOREVER.
This commit adds timeout parameters to the open/close APIs, and
updates in-tree usage of the open/close APIs to explicitly
provide the previously implicit timeout of 10 seconds.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Added `static const` to various `struct modem_pipe_api` and
`frame` in `modem_cmux_connect_handler` to make these structures
immutable and reduce RAM usage.
Corrected a typo, changing "consequtive" to "consecutive".
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Changed the `api` field in the `modem_pipe` structure to be
a pointer to constant.
This ensures that the `api` field remains immutable after
initialization.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
The cmux module does not properly cancel all work when it is
released from its modem pipe. Releasing CMUX must cancel all
work as the pipe is no longer available, as it is set to NULL.
If work remains which tries to transmit something to the now
released pipe, a NULL dereference occurs.
This exact issue occurs if a DLCI channel is trying to open
after the modem pipe has been released, as the CMUX component
will send an open request at a fixed interval.
The expected behavior is for the open request to be cancelled,
and further open requests to be prevented until cmux is again
attached to a pipe.
Lastly, added a check to ensure that the pipe is indeed released
when calling attach, to ensure all work is indeed stopped before
modifying the pipe and buffers.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Explicitly ignore the return value of net_pkt_read_u8() as the
net_pkt is validated before being queued for transmit within
modem_ppp_ppp_api_send()
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
The design of the pipe is overly complicated compared to the
in-tree and planned future use of the pipe module.
The pipe is currently designed to protect against multiple
threads calling any API simultaineously. This is not neccesary
as only one thread ever calls open/close/transmit/receive at
once, while the notification APIs are potentially called by a
different thread.
This commit removes the synchronization of calls to the open/
close/receive/transmit APIs. It also uses a k_event for thread
safe event and state handling instead of a k_mutex and k_condvar.
The callback is proteced by a k_sem as it modified using the
attach/release APIs, which can be called simultaneously to a
thread invoking the callback.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Trying to start a chat script using either modem_chat_run_script()
or modem_chat_run_script_async() should result in returning -EBUSY
without affecting the currently running script and thread waiting
on the current script to stop.
The current behavior causes the thread waiting for the current
script to stop to return with error -EAGAIN, and the thread trying
to start the new script to return with error -EBUSY.
This commit moves the reset of the sem the current thread is
waiting on, to after the check of whether a script is currently
running, leaving the current thread unaffected as is intended.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Add modem pipelink module which exposes modem pipes globally.
The pipelink module implements a callback to inform when a
pipe becomes available to use by whichever modem is attached
to it. This could be a shell, or a network interface.
The module aims to allow modem drivers to be split into modules,
and allowing applications to implement their own custom logic
without altering the modem drivers.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Add APIs for changing the contents of modem chat matches
safely at runtime.
This allows for reusing a single modem_chat_match at the cost
of placing the match and its buffers in RAM.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Add statistics module which tracks the usage of modem backend
transmit/receive buffers if implemented by a backend.
A modem backend may register itself to the modem backend
stat module, and advertise its transmit and receive buffer
sizes and momentary usage (length).
The modem backend module tracks the maximum usage, which can be
output to the shell using the "modem_stats buffer" shell command.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Modem chat scripts should be able to add a script command which
is simply a delay. The validation of chat scripts currently
disallows chat script commands which only have a timeout set.
Update modem_chat to allow modem chat script commands which
only have a timeout. Additionally do a bit of cleanup to
remove duplicate code.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
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>