0

Hi!  I have a timespec struct (defined in <time.h>) in my C project, built with gcc-rx (v8.3.0.202405) and newlib-nano.  It contains a long long seconds counter (8 bytes) and a long long nsec counter (8 bytes too.)  The timer is incremented by an MTU interrupt, and various application timers read this as needed.  This is simply a free-running counter that will “never” overflow in practice.

I need to guarantee atomicity of the structure reads/writes, as interrupts and the application are separate “threads”.  I define my cpu_time using _Atomic (defined in <stdatomic.h>) and gcc compiles fine.  I need to write/read this variable using copy instructions, as expected.  Accessing the struct members of the _Atomic struct generates a compiler error, which is also expected.  So, gcc seems to “know” what it’s dealing with.

The issue is at link time.  __atomic_load and __atomic_store are not found (“undefined reference.”)  I’m not 100% sure if newlib-nano supports these.  If so, what am I missing, and if not, are there any known light-weight libs out there I could use?

Thanks!

Frank Kjul Larsen answered
    • OK, found a solution for this if anybody else has the same question. With the RX FIT library (i.e. Smart Configurator) you also get an XCHG based lock/unlock routines, which are fine for my application (see r_bsp_locking.h/.c)