nuttx-apps/lte/alt1250
Xiang Xiao f9f59bd0f8 !apps: drop redundant casts on tv_sec/tv_nsec and fix printf formats
Now that time_t is unconditionally 64-bit (signed int64_t) and the
struct timespec fields tv_sec / tv_nsec are wide enough on their own,
the explicit (uint64_t)/(int64_t)/(int) casts that used to guard the
multiplications and subtractions in *_us / *_ms / *_ns helpers are no
longer needed.  Drop them to keep the timekeeping math readable.

In the same spirit, this commit also normalises the printf-style format
specifiers and casts used to print tv_sec / tv_nsec / tv_usec values.
The prior code was a mix of "%d"/"%u"/"%ld"/"%lu"/"%lld" with matching
(int)/(unsigned long)/(long long) casts; some formats truncated time_t
on 32-bit hosts, others mismatched signedness or width.  Replace all
such cases with the portable POSIX-recommended forms:

  - tv_sec  (time_t,       signed, impl-defined width) -> %jd  + (intmax_t)
  - tv_nsec (long,         signed)                     -> %ld  (no cast)
  - tv_usec (suseconds_t / long)                       -> %ld  (no cast)

Also drop two stale `(FAR const time_t *)&ts.tv_sec` casts that are
unnecessary now that ts.tv_sec is plain time_t.

Arithmetic-cleanup files (existing scope):

  - benchmarks/cyclictest/cyclictest.c:        timediff_us()
  - benchmarks/sd_bench/sd_bench_main.c:       get_time_delta_us()
  - examples/oneshot/oneshot_main.c:           maxus computation
  - examples/watchdog/watchdog_main.c:         current_time_ms (x2)
  - industry/nxmodbus/nxmb_internal.h:         nxmb_util_clock_ms()
  - netutils/ntpclient/ntpclient.c:            timespec2ntp()
  - netutils/ptpd/ptpd.c:                      ptp_adjtime()
  - system/dd/dd_main.c:                       elapsed accounting
  - testing/drivers/drivertest/drivertest_posix_timer.c:
                                               get_timestamp()
  - testing/drivers/sd_stress/sd_stress_main.c:get_time_delta()
  - testing/sched/getprime/getprime_main.c:    elapsed accounting
  - testing/sched/pthread_mutex_perf/pthread_mutex_perf.c:
                                               timespec_avg()

Printf-format-fix files (new in this revision):

  - examples/adjtime/adjtime_main.c
  - examples/charger/charger_main.c
  - examples/netpkt/netpkt_ethercat.c
  - fsutils/mkfatfs/mkfatfs.c
  - graphics/tiff/tiff_initialize.c
  - netutils/ptpd/ptpd.c
  - nshlib/nsh_timcmds.c
  - system/coredump/coredump.c
  - system/ptpd/ptpd_main.c
  - testing/drivers/drivertest/drivertest_oneshot.c
  - testing/mm/kasantest/kasantest.c
  - testing/ostest/semtimed.c
  - testing/sched/pthread_mutex_perf/pthread_mutex_perf.c
  - testing/sched/timerjitter/timerjitter.c
  - testing/testsuites/kernel/time/cases/clock_test_clock01.c
  - testing/testsuites/kernel/time/cases/clock_test_smoke.c

No behavioural change.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2026-05-22 13:38:25 +08:00
..
callback_handlers lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
usock_handlers !apps: drop redundant casts on tv_sec/tv_nsec and fix printf formats 2026-05-22 13:38:25 +08:00
alt1250_atcmd.c lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_atcmd.h lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_container.c lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_container.h lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_daemon.h lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_dbg.h include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
alt1250_devevent.c lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_devevent.h lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_devif.c apps: Fix minor issues for latest toolchains 2026-01-23 10:00:52 +08:00
alt1250_devif.h apps: Fix minor issues for latest toolchains 2026-01-23 10:00:52 +08:00
alt1250_main.c lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_netdev.c lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_netdev.h lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_postproc.h lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_reset_seq.c lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_reset_seq.h lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_select.c lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_select.h lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_socket.c lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_socket.h lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_usockevent.c lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_usockevent.h lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_usockif.c lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_usockif.h lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_util.c lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
alt1250_util.h lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
CMakeLists.txt lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
Kconfig lte/alt1250: Select NET_USRSOCK_ICMP if LTE_ALT1250 is enabled 2024-07-16 21:46:23 +08:00
Make.defs lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
Makefile lte: migrate to SPDX identifier 2024-12-21 13:53:10 +08:00
README.txt lte: Add usrsock daemon for ALT1250 LTE modem 2023-06-07 01:51:33 +08:00

NOTICE:
=======
  This document should be opened in a text editor with a width of at least 150 characters.

alt1250 usrsock daemon
======================

  This software module is a usrsock daemon in NuttX for ALT1250 modem.
  The ALT1250 modem is a modem provided by Sony Semiconductor Israel. And it supports LTE Cat-M1 and NB-IoT network.
  

Implementation Structure
========================
                                                                                 Call registerd functions
                                                                                <-------------------------------------------------+
                                                                                                                                  |
+-------------------------------------------------------------------------------------------------------------------------------- | -------------+
| alt1250_daemon                                                                                                                  |              |
| ~~~~~~~~~~~~~~                                                            Response                                              |              |
|   +----------------------------------------------------------------------------------+                                          |              |
|   |                                                                                  |                                          |              |
|   V  Response    _________________________________________________________           |                            +--------------------------+ |
|   +------------- | usrsock handlers                    | post process    |           |            +-------------> |   Event call back task   | |
|   |              +_____________________________________+_________________+           |            |          +--> |   to an application      | |
|   |              | socket handler                      | postproc_socket |           |            |          |    +--------------------------+ |
|   |           |D | bind handler                        | postproc_bind   |           |            |          |                                 |
|   |           |I | listen handler                      | postproc_listen |  <-----+  |            |          |                                 |
|   |           |S |      .                              |        .        |        |  |            |          |                                 |
|   |           |P |      .                              |        .        |  Call  |  |            |          |                                 |
|   |   +-----> |A |      .                              |        .        |  Back  |  |            | Event    |                                 |
|   |   |       |T |---------------+---------------------+-----------------|        |  |            | Message  |                                 |
|   |   |       |C | ioctl handler | lapi power handler  | postproc_XXXX   |        |  |            |          |                                 |
|   |   |       |H |                 lapi normal handler | postproc_XXXX   |        |  |            |          |                                 |
|   |   |          |               | lapi ifreq handler  | postproc_XXXX   | ___________________________________________________________________ |
|   |   | usrsock  |                 lapi ltecmd handler | postproc_XXXX   | | Command Reply | Reset Event | Asynchronous Event | Select Event | |
|   |   | request  |               |         .           |        .        | |-----------------------------------------------------------------| |
|   |   |          |                         .           |        .        | | Device event handling                                           | |
|   |   |          +-------------------------------------------------------+ +-----------------------------------------------------------------+ |
|   |   |                                    |                    |                                      /                                       |
+-- | - | ---------------------------------- | ------------------ | ------------------------------------ | --------------------------------------+
    |   |                                    |   Send Command     |                                      | Event notify
    V   |                                    V                    V                                      |
-- /dev/usrsock --                   ----------------------------------- /dev/alt1250 -----------------------------------
+----------------+                   +----------------------------------------------------------------------------------+
|   User Sock    |                   |                             ALT1250 Device Driver                                |
+----------------+                   +----------------------------------------------------------------------------------+
                                     +---------------------------------------++-----------------------------------------+
                                     |          SPI Driver                   ||            GPIO Driver                  |
                                     +---------------------------------------++-----------------------------------------+

Behavior Overview
=================

  Basically, alt1250_daemon receives a request from NutX User Sock and performs the expected processing according to the request.

  Each request is processed by its own "usrsock handler" depending on its type, and the result is returned to the User Sock as a
  response. To achieve each of these operations, the "usrsock handler" sends a command to the alt1250 device driver. The post process
  function is registerd in the command to process the command response if necessary.

  The command is sent to the ALT1250 via SPI, and the ALT1250 returns a response according to the command to notify alt1250_daemon.
  The alt1250_daemon receives the command response from that notification and either returns the response to User Sock or calls the
  "post process function" that was registered by the "usrsock handler". "post process" will return a response or send further
  commands to ALT1250 depending on the content of the request.

  The ALT1250 may make event notifications, and these notifications are asynchronous. ALT1250 asynchronous events are notified by the
  device driver as well as command responses, and when the alt1250_daemon receives them, it passes them to a task for callback to
  notify the user application.