.. index:: calling-c .. _calling-c: .. Created calling-c.rst: Sun 21 Aug 2022 13:48:57 AEST .. Full Path: /home/tp/mecrisp-unofficial-doc/calling-c.rst .. Author Copyright 2022 by t.j.porter .. Made by /home/tp/projects/scripts/makerst.sh -->/usr/local/bin/makerst .. license: MIT, please see COPYING Calling C ========= Calling C Functions from Forth and Vice Versa. ---------------------------------------------- Calling C Functions from Forth ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: Word osDelay from rtos.s // ----------------------------------------------------------------------------- Wortbirne Flag_visible, "osDelay" @ ( u -- n ) Wait for Timeout (Time Delay). /// \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value /// \return status code that indicates the execution status of the function. // osStatus_t osDelay (uint32_t ticks); // ----------------------------------------------------------------------------- rtos_osDelay: push {r0-r3, lr} movs r0, tos // ticks bl osDelay movs tos, r0 pop {r0-r3, pc} If the C function itself calls Forth words the Data Stack Pointer SPS and Top Of Stack TOS registers have to be passed to the Forth words. See https://github.com/spyren/Mecrisp-Cube/blob/master/sdcard/man/CallingCFunction.md which is part of :ref:`Mecrisp Cube` in my recent :ref:`Unusual Forths` page.