Line: 1 to 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Calling C Functions from Forth and Vice Versa | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Line: 7 to 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/on-the-aapcs-with-an-application-to-efficient-parameter-passing | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
< < |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
VFP Register UsageThe VFP-v2 co-processor has 32 single-precision registers, s0-s31, which may also be accessed as 16 double-precision registers, d0-d15 (with d0 overlapping s0, s1; d1 overlapping s2, s3; etc).Calling C Functions from Forth | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > |
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 below. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Calling Forth Words from C Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
< < | Stack Pointer and Top Of Stack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | Data Stack Pointer SPS is in R7 and Top Of Stack TOS is in R6. R7 can't be a register variable, that's why R12 is used as a temporary storage.
register uint32_t TOS asm ("r6"); register uint32_t PSP asm ("r12"); TOS = TOS; PSP = PSP;C function FS_include() from fs.c calls the Forth words FS_type and FS_evaluate .
/** * @brief * Interprets the content of the file. * @param[in] * str filename (w/ or w/o null termination) * @param[in] * count string length * @return * None */ void FS_include(uint8_t *str, int count) { FIL fil; /* File object */ FRESULT fr; /* FatFs return code */ register uint32_t TOS asm ("r6"); register uint32_t PSP asm ("r12"); TOS = TOS; PSP = PSP; memcpy(path, str, count); line[count] = 0; /* Open a text file */ fr = f_open(&fil, path, FA_READ); if (fr) { // open failed strcpy(line, "Err: file not found"); FS_type((uint8_t*)line, strlen(line)); return; } /* Read every line and interprets it */ while (f_gets(line, sizeof line, &fil)) { // line without \n FS_evaluate((uint8_t*)line, strlen(line)-1); } /* Close the file */ f_close(&fil); }Word include from fs.s calls the C function FS_include() .
@ ----------------------------------------------------------------------------- Wortbirne Flag_visible, "include" @ ( "filename" -- ) Interprets the content of the file. // void FS_include(uint8_t *str, int count) @ ----------------------------------------------------------------------------- include: push {r0-r3, lr} bl token // ( -- c-addr len ) movs r1, tos // len -> count drop movs r0, tos // c-addr -> str drop movs r12, psp // get psp bl FS_include movs psp, r12 // update psp pop {r0-r3, pc}The C function FS_include() from fs.c calls the Forth word evaluate by the FS_evaluate() function.
// void FS_evaluate(uint8_t* str, int count); .global FS_evaluate FS_evaluate: push {r4, r5, r7, lr} movs psp, r12 // get psp pushdatos movs tos, r0 // str pushdatos movs tos, r1 // count bl evaluate movs r12, psp // update psp pop {r4, r5, r7, pc} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-- Peter Schmid - 2020-07-13 |