Tags:
view all tags
%DASHBOARD{ section="dashboard_start" }% %DASHBOARD{ section="banner" image="%PUBURLPATH%/Cosmac/ForthSTM32WB/nucleo-header.jpg" title="CMSIS-RTOS for Mecrisp-Cube" titlestyle="color:#F00000;" }% %DASHBOARD{ section="box_start" title="Intro" width="485" height="400"}% ---+ Why a Preemptive Real Time Operating System? Forth systems traditionally make use of cooperative multitasking. It is very simple and clever. But it has its limits. If you write all your software by yourself, each software part can be cooperative. But if you want to benefit from middleware written by somebody else (and most probably not written in Forth), you can be sure that software is not cooperative (in the context of multitasking). Forth wants to rule your system. I would like to have a Forth system that is cooperative. It should extend the system, to make it interactive and easy to use. The Forth itself is only a thread and can be used as some sort of CLI for testing purposes or could be the main part of the application. %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" title="Contents" width="460" height="400"}% %TOC% %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="800" }% ---+ How to Create a Thread A very simple thread could be like this one, a boring blinker: <pre> : blink-thread ( -- ) begin led1@ 0= led1! \ toggle blue LED 200 osDelay drop \ wait 200 ms switch1? until 0 led1! ; </pre> If you type the word =blink-thread=, the blue LED blinks, after push the button SW1, the blinking stops an the =ok.= apears. But if you try to start the thread with <pre> ' blink-thread 0 0 osThreadNew </pre> Nothing happens and probably the Forth system hangs. Restart the Forth system with the Reset button _SW4_. If you create a new RTOS Thread, CMSIS-RTOS (!FreeRTOS) allocate some memory from the heap for the stack and the thread control block. But Forth thread needs another stack, the data stack. The blink-thread runs concurrent to the Forth interpreter and use the same data stack. This cannot work. Each thread must have its own data stack, the thread function can get one with =osNewDataStack= (see below for the assembler source). <pre> : blink-thread ( -- ) <b>osNewDataStack</b> begin led1@ 0= led1! \ toggle blue LED 200 osDelay drop switch1? until 0 led1! <b>osThreadExit</b> ; </pre> =osThreadExit= is needed to exit the thread, otherwise the Forth system hangs after leaving the thread. These threads are very similar to the _control tasks_ described in Starting Forth, Leo Brodie. But without _user variables_. If a thread wants to use variables and share these variables with other threads, the variables have to be protected by a mutex or a semaphore. Anyway variables have to be created by the main Forth thread (terminal task) before. Now you can interactively play with the words =osThreadGetId=, =osThreadGetState=, =osThreadSuspend=, and =osThreadResume= without the tedious edit-compile-download-run-abort. <pre> // ----------------------------------------------------------------------------- Wortbirne Flag_visible, "<b>osNewDataStack</b>" @ ( -- ) Creates an new data stack for a Forth thread. // ----------------------------------------------------------------------------- rtos_osNewDataStack: push {r0-r3, lr} ldr r0, =256 // 64 levels should be more than enough bl pvPortMalloc adds r7, r0, #256 // stack grows down movs tos, 42 pop {r0-r3, pc} </pre> %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="800" }% ---+ CMSIS-RTOS API * osNewDataStack * xPortGetFreeHeapSize ---++ Kernel Management Functions * osKernelGetTickCount * osKernelGetTickFreq * osKernelGetSysTimerCount * osKernelGetSysTimerFreq ---++ Generic Wait Functions * osDelay * osDelayUntil ---++ Thread Management * osThreadNew * osThreadGetId * osThreadGetState * osThreadSetPriority * osThreadGetPriority * osThreadYield * osThreadSuspend * osThreadResume * osThreadExit * osThreadTerminate * osThreadGetStackSpace * osThreadGetCount * osThreadEnumerate ---++ Timer Management Functions * osTimerNew * osTimerGetName * osTimerStart * osTimerStop * osTimerIsRunning * osTimerDelete ---++ Event Flags Management Functions * osEventFlagsNew * osEventFlagsSet * osEventFlagsClear * osEventFlagsGet * osEventFlagsWait * osEventFlagsDelete ---++ Mutex Management Functions * osMutexNew * osMutexAcquire * osMutexRelease * osMutexGetOwner * osMutexDelete ---++ Semaphore Management Functions * osSemaphoreNew * osSemaphoreAcquire * osSemaphoreRelease * osSemaphoreGetCount * osSemaphoreDelete ---++ Message Queue Management Functions * osMessageQueueNew * osMessageQueuePut * osMessageQueueGet * osMessageQueueGetCapacity * osMessageQueueGetMsgSize * osMessageQueueGetCount * osMessageQueueGetSpace * osMessageQueueReset * osMessageQueueDelete %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="dashboard_end" }% A multi-tasking wordset for Standard Forth, Andrew Haley http://www.complang.tuwien.ac.at/anton/euroforth/ef17/papers/haley-slides.pdf -- %USERSIG{PeterSchmid - 2020-04-07}% ---++ Comments %COMMENT%
Edit
|
Attach
|
Watch
|
P
rint version
|
H
istory
:
r60
|
r7
<
r6
<
r5
<
r4
|
B
acklinks
|
V
iew topic
|
Raw edit
|
More topic actions...
Topic revision: r5 - 2020-04-11
-
PeterSchmid
Home
Site map
Cosmac web
MRR web
MecrispCube web
SuperRandonnee web
TWiki web
Ursula web
Velo web
MecrispCube Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Edit
Attach
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback