QuantumLeaps / qpc-examples

Examples for the QP/C Real-Time Embedded Framework
9 stars 2 forks source link

It is failed when making blinky example in Macos 10.13 #5

Open hawkinchina opened 1 month ago

hawkinchina commented 1 month ago
  1. failed log:

➜ /Users/jack/Downloads/qp/qpc/examples/posix-win32/blinky >make gcc -MM -MT build/qf_port.o -c -g -O -fno-pie -std=c11 -pedantic -Wall -Wextra -W -I. -I../../../include -I../../../ports/posix-qv -DQP_API_VERSION=9999 ../../../ports/posix-qv/qf_port.c > build/qf_port.d gcc -c -g -O -fno-pie -std=c11 -pedantic -Wall -Wextra -W -I. -I../../../include -I../../../ports/posix-qv -DQP_API_VERSION=9999 ../../../ports/posix-qv/qf_port.c -o build/qf_port.o ../../../ports/posix-qv/qf_port.c:91:13: warning: implicit declaration of function 'clock_nanosleep' is invalid in C99 [-Wimplicit-function-declaration] if (clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next_tick, NULL) == 0) // success? ^ ../../../ports/posix-qv/qf_port.c:91:46: error: use of undeclared identifier 'TIMER_ABSTIME' if (clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next_tick, NULL) == 0) // success? ^ 1 warning and 1 error generated. make: *** [build/qf_port.o] Error 1

  1. Mac OS Sierra (10.12) and above implement clock_gettime() and does not require emulation. However clock_nanosleep() is still not implemented in any version of macOS or OS X. please check : https://github.com/ChisholmKyle/PosixMachTiming
quantum-leaps commented 1 month ago

Good to know that macOS is not POSIX. Thanks for reporting. What to do about it?

hawkinchina commented 1 month ago

I just simply include the files in the project of https://github.com/ChisholmKyle/PosixMachTiming timing_mach.c timing_mach.h.

and modify qf_port.c in the directory of posix-qv

  // sleep without drifting till next_tick (absolute), see NOTE03
   // if (clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next_tick, NULL) == 0) // success?
        if (clock_nanosleep_abstime(&next_tick) == 0) // success?  modified by jack_he.
        {
            QF_onClockTick(); 
        }

and then it is ok.

log info: ➜ /Users/jack/Downloads/qp/qpc/examples/posix-win32/blinky/build >./blinky LED OFF LED ON LED OFF LED ON LED OFF LED ON LED OFF LED ON LED OFF LED ON LED OFF LED ON LED OFF

quantum-leaps commented 1 month ago

The qpc and qpcpp POSIX ports have been adapted for APPLE. The changes have been checked into the qpc and qpcpp repos. With these changes, the examples should build and run on macOS. This includes the Spy build configurations. For example, here is the updated file qpc/ports/posix-qv/qf_port.c --MMS