Skip to content

Commit

Permalink
Issue f9micro#157 - Demonstration of possible implementation to resol…
Browse files Browse the repository at this point in the history
…ve this issue: support for pager_start_thread() arg parameter.
  • Loading branch information
ab1aw committed Feb 26, 2019
1 parent 01b22b9 commit 08ba6c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 8 additions & 2 deletions user/apps/gpioer/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static inline void __USER_TEXT leds_onoff(int count)
__USER_TEXT
void *gpioer_thread(void *arg)
{
printf("\nENTER gpioer_thread(%p)\n", arg);
printf("gpioer thread: built-in leds blinking\n");
led_init();
while (1)
Expand All @@ -71,6 +72,7 @@ void *gpioer_thread(void *arg)
leds_onoff(count++);
L4_Sleep(L4_TimePeriod(500 * 1000));
}
printf("\nEXIT gpioer_thread()\n");
}


Expand All @@ -93,6 +95,7 @@ void *gpioer_thread(void *arg)
__USER_TEXT
void *button_monitor_thread(void *arg)
{
printf("\nENTER button_monitor_thread(%p)\n", arg);
gpio_config_input(GPIOA, BUTTON_CUSTOM_PIN, GPIO_PUPDR_DOWN);
printf("thread: built-in user button detection\n");
while (1)
Expand All @@ -104,21 +107,24 @@ void *button_monitor_thread(void *arg)
}
L4_Sleep(L4_TimePeriod(1000 * 200));
}
printf("\nEXIT button_monitor_thread()\n");
}

/* main() signature changed. */
__USER_TEXT
static void *main(void *user)
{
printf("\nENTER main(%p)\n", user);
count = 0;

threads[GPIOER_THREAD] = pager_create_thread();
threads[BUTTON_MONITOR_THREAD] = pager_create_thread();

pager_start_thread(threads[GPIOER_THREAD], gpioer_thread, NULL);
pager_start_thread(threads[BUTTON_MONITOR_THREAD], button_monitor_thread, NULL);
pager_start_thread(threads[GPIOER_THREAD], gpioer_thread, gpioer_thread);
pager_start_thread(threads[BUTTON_MONITOR_THREAD], button_monitor_thread, button_monitor_thread);

/* Return statement required. */
printf("\nEXIT main()\n");
return 0;
}

Expand Down
9 changes: 6 additions & 3 deletions user/lib/l4/pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ void thread_container(kip_t *kip_ptr, utcb_t *utcb_ptr,
L4_Word_t entry, L4_Word_t entry_arg)
{
L4_Msg_t msg;
printf("\nthread_container(0) %p %p\n", entry, entry_arg);
((thr_handler_t *)entry)((void *)entry_arg);
printf("\nthread_container(1) %p %p\n", entry, entry_arg);

L4_MsgClear(&msg);
L4_Set_MsgLabel(&msg, PAGER_REQUEST_LABEL);
Expand Down Expand Up @@ -259,7 +261,7 @@ L4_Word_t pager_start_thread(L4_ThreadId_t tid, void * (*thr_routine)(void *),
L4_MsgAppendWord(&msg, THREAD_START);
L4_MsgAppendWord(&msg, (L4_Word_t)tid.raw);
L4_MsgAppendWord(&msg, (L4_Word_t)thr_routine);
/* TODO: Ignore arg now */
L4_MsgAppendWord(&msg, (L4_Word_t)arg);

L4_MsgLoad(&msg);
tag = L4_Call(L4_Pager());
Expand Down Expand Up @@ -334,14 +336,15 @@ void pager_thread(user_struct *user,
break;
case THREAD_START: {
L4_Word_t entry;
L4_Word_t entry_arg;
L4_ThreadId_t tid;
L4_Word_t ret;

tid.raw = L4_MsgWord(&msg, 1);
entry = L4_MsgWord(&msg, 2);
/* TODO : ignore entry argument now */
entry_arg = L4_MsgWord(&msg, 3);

ret = __thread_start(pool, tid, entry, 0);
ret = __thread_start(pool, tid, entry, entry_arg);

L4_MsgClear(&msg);
L4_Set_Label(&msg.tag, PAGER_REPLY_LABEL);
Expand Down

0 comments on commit 08ba6c8

Please sign in to comment.