「App:Library:LVGL:docs:Porting:Operating system and interrupts」の版間の差分
| (同じ利用者による、間の11版が非表示) | |||
| 1行目: | 1行目: | ||
https://docs.lvgl.io/8.2/porting/os.html | https://docs.lvgl.io/8.2/porting/os.html | ||
| − | + | ||
| + | = Operating system and interrupts = | ||
{| class="wikitable" | {| class="wikitable" | ||
!英文 | !英文 | ||
| 6行目: | 7行目: | ||
|- | |- | ||
| | | | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
LVGL is not thread-safe by default. | LVGL is not thread-safe by default. | ||
| 18行目: | 13行目: | ||
* In ''events''. Learn more in Events. | * In ''events''. Learn more in Events. | ||
* In ''lv_timer''. Learn more in Timers. | * In ''lv_timer''. Learn more in Timers. | ||
| + | |LVGLは、デフォルトでは[https://ja.wikipedia.org/wiki/%E3%82%B9%E3%83%AC%E3%83%83%E3%83%89%E3%82%BB%E3%83%BC%E3%83%95 '''スレッドセーフ''']ではありません。 | ||
| + | |||
| + | ただし、以下の条件では、LVGL関連の関数を呼び出すことが有効です。 | ||
| + | * LVGLは、デフォルトではスレッドセーフではありません。''イベント''で。詳細については、イベントをご覧ください。 | ||
| + | * lv_timer''で''。詳細については、タイマーをご覧ください。 | ||
| + | |} | ||
| + | :[[App:Library:LVGL:docs:Porting#Operating system and interrupts|戻る : Previous]] | ||
== Tasks and threads == | == Tasks and threads == | ||
| − | If you need to use real tasks or threads, you need a mutex which should be invoked before the call of <code>lv_timer_handler</code> and released after it. Also, you have to use the same mutex in other tasks and threads around every LVGL (<code>lv_...</code>) related function call and code. This way you can use LVGL in a real multitasking environment. Just make use of a mutex to avoid the concurrent calling of LVGL functions. | + | {| class="wikitable" |
| + | !英文 | ||
| + | !自動翻訳 | ||
| + | |- | ||
| + | | | ||
| + | If you need to use real tasks or threads, you need a mutex which should be invoked before the call of <code style="color: #bb0000;">lv_timer_handler</code> and released after it. Also, you have to use the same mutex in other tasks and threads around every LVGL (<code style="color: #bb0000;">lv_...</code>) related function call and code. This way you can use LVGL in a real multitasking environment. Just make use of a mutex to avoid the concurrent calling of LVGL functions. | ||
Here is some pseudocode to illustrate the concept: | Here is some pseudocode to illustrate the concept: | ||
| + | <syntaxhighlight lang="C++" style="border: 1px dashed gray;"> | ||
static mutex_t lvgl_mutex; | static mutex_t lvgl_mutex; | ||
| − | + | ||
void lvgl_thread(void) | void lvgl_thread(void) | ||
{ | { | ||
| 52行目: | 60行目: | ||
} | } | ||
} | } | ||
| + | </syntaxhighlight> | ||
| + | | | ||
| + | |||
| + | 実際のタスクまたはスレッドを使用する必要がある場合は、<code style="color: #bb0000;">lv_timer_handler</code>を呼び出す前に呼び出して、その後に解放する[https://ja.wikipedia.org/wiki/%E3%83%9F%E3%83%A5%E3%83%BC%E3%83%86%E3%83%83%E3%82%AF%E3%82%B9 '''ミューテックス''']が必要です。また、すべてのLVGL(<code style="color: #bb0000;">lv_...</code>)関連の関数呼び出しとコードの周りの他のタスクとスレッドで同じミューテックスを使用する必要があります。このようにして、実際のマルチタスク環境でLVGLを使用できます。LVGL関数の同時呼び出しを回避するには、ミューテックスを使用するだけです。 | ||
| + | |||
| + | 概念を説明するためのいくつかの擬似コードを次に示します。 | ||
| + | <syntaxhighlight lang="C++" style="border: 1px dashed gray;"> | ||
| + | static mutex_t lvgl_mutex ; | ||
| + | |||
| + | void lvgl_thread (void ) | ||
| + | { | ||
| + | while (1 ) { | ||
| + | mutex_lock (&lvgl_mutex ); | ||
| + | lv_task_handler (); | ||
| + | mutex_unlock (&lvgl_mutex ); | ||
| + | thread_sleep (10 ); /*10ミリ秒間スリープ*/ | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void other_thread (void ) | ||
| + | { | ||
| + | / *LVGLAPIを使用している間は常にミューテックスを保持する必要があります*/ | ||
| + | mutex_lock (&lvgl_mutex ); | ||
| + | lv_obj_t * img = lv_img_create (lv_scr_act ()); | ||
| + | mutex_unlock (&lvgl_mutex ); | ||
| + | |||
| + | while (1 ) { | ||
| + | mutex_lock (&lvgl_mutex ); | ||
| + | /*次の画像に変更します*/ | ||
| + | lv_img_set_src (img 、 next_image ); | ||
| + | mutex_unlock (&lvgl_mutex ); | ||
| + | thread_sleep (2000 ); | ||
| + | } | ||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |} | ||
| + | :[[App:Library:LVGL:docs:Porting#Operating system and interrupts|戻る : Previous]] | ||
== Interrupts == | == Interrupts == | ||
| − | Try to avoid calling LVGL functions from interrupt handlers (except <code>lv_tick_inc()</code> and <code>lv_disp_flush_ready()</code>) | + | {| class="wikitable" |
| + | !英文 | ||
| + | !自動翻訳 | ||
| + | |- | ||
| + | | | ||
| + | Try to avoid calling LVGL functions from interrupt handlers (except <code style="color: #bb0000;">lv_tick_inc()</code> and <code style="color: #bb0000;">lv_disp_flush_ready()</code>). | ||
| − | |||
| + | But if you need to do this you have to disable the interrupt which uses LVGL functions while <code style="color: #bb0000;">lv_timer_handler</code> is running. | ||
| + | It's a better approach to simply set a flag or some value in the interrupt, and periodically check it in an LVGL timer (which is run by <code style="color: #bb0000;">lv_timer_handler</code>). | ||
| + | |割り込みハンドラー(<code style="color: #bb0000;">lv_tick_inc()</code>と<code style="color: #bb0000;">lv_disp_flush_ready()</code>を除く)からLVGL関数を呼び出さないようにしてください。 | ||
| + | ただし、これを行う必要がある場合は、<code style="color: #bb0000;">lv_timer_handler</code>の実行中にLVGL関数を使用する割り込みを無効にする必要があります。 | ||
| − | + | 割り込みにフラグまたは何らかの値を設定し、LVGLタイマー(<code style="color: #bb0000;">lv_timer_handler</code>によって実行される)で定期的にチェックすることをお勧めします。 | |
| − | [[App:Library:LVGL:docs:Porting|戻る : Previous]] | + | |} |
| + | :[[App:Library:LVGL:docs:Porting#Operating system and interrupts|戻る : Previous]] | ||
2022年8月18日 (木) 22:44時点における最新版
https://docs.lvgl.io/8.2/porting/os.html
Operating system and interrupts
| 英文 | 自動翻訳 |
|---|---|
|
LVGL is not thread-safe by default. However, in the following conditions it's valid to call LVGL related functions:
|
LVGLは、デフォルトではスレッドセーフではありません。
ただし、以下の条件では、LVGL関連の関数を呼び出すことが有効です。
|
Tasks and threads
| 英文 | 自動翻訳 |
|---|---|
|
If you need to use real tasks or threads, you need a mutex which should be invoked before the call of Here is some pseudocode to illustrate the concept: static mutex_t lvgl_mutex;
void lvgl_thread(void)
{
while(1) {
mutex_lock(&lvgl_mutex);
lv_task_handler();
mutex_unlock(&lvgl_mutex);
thread_sleep(10); /* sleep for 10 ms */
}
}
void other_thread(void)
{
/* You must always hold the mutex while using LVGL APIs */
mutex_lock(&lvgl_mutex);
lv_obj_t *img = lv_img_create(lv_scr_act());
mutex_unlock(&lvgl_mutex);
while(1) {
mutex_lock(&lvgl_mutex);
/* change to the next image */
lv_img_set_src(img, next_image);
mutex_unlock(&lvgl_mutex);
thread_sleep(2000);
}
}
|
実際のタスクまたはスレッドを使用する必要がある場合は、 概念を説明するためのいくつかの擬似コードを次に示します。 static mutex_t lvgl_mutex ;
void lvgl_thread (void )
{
while (1 ) {
mutex_lock (&lvgl_mutex );
lv_task_handler ();
mutex_unlock (&lvgl_mutex );
thread_sleep (10 ); /*10ミリ秒間スリープ*/
}
}
void other_thread (void )
{
/ *LVGLAPIを使用している間は常にミューテックスを保持する必要があります*/
mutex_lock (&lvgl_mutex );
lv_obj_t * img = lv_img_create (lv_scr_act ());
mutex_unlock (&lvgl_mutex );
while (1 ) {
mutex_lock (&lvgl_mutex );
/*次の画像に変更します*/
lv_img_set_src (img 、 next_image );
mutex_unlock (&lvgl_mutex );
thread_sleep (2000 );
}
}
|
Interrupts
| 英文 | 自動翻訳 |
|---|---|
|
Try to avoid calling LVGL functions from interrupt handlers (except
It's a better approach to simply set a flag or some value in the interrupt, and periodically check it in an LVGL timer (which is run by |
割り込みハンドラー(lv_tick_inc()とlv_disp_flush_ready()を除く)からLVGL関数を呼び出さないようにしてください。
|