Example #1
0
void
task1_handler(void *arg)
{
    struct os_task *t;

    /* Set the led pin for the E407 devboard */
    g_led_pin = LED_BLINK_PIN;
    hal_gpio_init_out(g_led_pin, 1);

    while (1) {
        t = os_sched_get_current_task();
        assert(t->t_func == task1_handler);

        ++g_task1_loops;

        /* Wait one second */
        os_time_delay(1000);

        /* Toggle the LED */
        hal_gpio_toggle(g_led_pin);

        /* Release semaphore to task 2 */
        os_sem_release(&g_test_sem);
    }
}
Example #2
0
static void 
sem_test_1_task1_handler(void *arg)
{
    os_error_t err;
    struct os_task *t;
    int i;;

    for (i = 0; i < 3; i++) {
        t = os_sched_get_current_task();
        TEST_ASSERT(t->t_func == sem_test_1_task1_handler);


        err = os_sem_pend(&g_sem1, 0);
        TEST_ASSERT(err == OS_OK);

        /* Sleep to let other tasks run */
        os_time_delay(100);

        /* Release the semaphore */
        err = os_sem_release(&g_sem1);
        TEST_ASSERT(err == OS_OK);

        /* Sleep to let other tasks run */
        os_time_delay(100);
    }

    os_test_restart();
}
Example #3
0
static void
task1_handler(void *arg)
{
    struct os_task *t;

    /* Set the led pin for the E407 devboard */
    g_led_pin = LED_BLINK_PIN;
    hal_gpio_init_out(g_led_pin, 1);

    console_printf("\nSensors Test App\n");

    while (1) {
        t = os_sched_get_current_task();
        assert(t->t_func == task1_handler);

        ++g_task1_loops;

        /* Wait one second */
        os_time_delay(OS_TICKS_PER_SEC * MYNEWT_VAL(SENSOR_OIC_OBS_RATE));

        /* Toggle the LED */
        (void)hal_gpio_toggle(g_led_pin);

        /* Release semaphore to task 2 */
        os_sem_release(&g_test_sem);
    }
}
struct os_event *
os_eventq_get(struct os_eventq *evq)
{
    struct os_event *ev;
    os_sr_t sr;

    OS_ENTER_CRITICAL(sr);
pull_one:
    ev = STAILQ_FIRST(&evq->evq_list);
    if (ev) {
        STAILQ_REMOVE(&evq->evq_list, ev, os_event, ev_next);
        ev->ev_queued = 0;
    } else {
        evq->evq_task = os_sched_get_current_task();
        os_sched_sleep(evq->evq_task, OS_TIMEOUT_NEVER);
        OS_EXIT_CRITICAL(sr);

        os_sched(NULL, 0);

        OS_ENTER_CRITICAL(sr);
        evq->evq_task = NULL;
        goto pull_one;
    }
    OS_EXIT_CRITICAL(sr);

    return (ev);
}
Example #5
0
int
ble_hs_locked_by_cur_task(void)
{
    struct os_task *owner;

    owner = ble_hs_mutex.mu_owner;
    return owner != NULL && owner == os_sched_get_current_task();
}
Example #6
0
static void 
sem_test_sleep_task_handler(void *arg)
{
    struct os_task *t;

    t = os_sched_get_current_task();
    TEST_ASSERT(t->t_func == sem_test_sleep_task_handler);

    os_time_delay(2000);
    os_test_restart();
}
Example #7
0
int
ble_hs_start(void)
{
    int rc;

    ble_hs_parent_task = os_sched_get_current_task();

    ble_hs_heartbeat_timer_reset();

    rc = ble_hs_startup_go();
    return rc;
}
Example #8
0
void 
sem_test_sleep_task_handler(void *arg)
{
    struct os_task *t;

    t = os_sched_get_current_task();
    TEST_ASSERT(t->t_func == sem_test_sleep_task_handler);

    os_time_delay(2 * OS_TICKS_PER_SEC);
#if MYNEWT_VAL(SELFTEST)
    os_test_restart();
#endif
}
Example #9
0
int
ble_hs_locked_by_cur_task(void)
{
    struct os_task *owner;

#if BLE_HS_DEBUG
    if (!os_started()) {
        return ble_hs_dbg_mutex_locked;
    }
#endif

    owner = ble_hs_mutex.mu_owner;
    return owner != NULL && owner == os_sched_get_current_task();
}
Example #10
0
int
ble_hs_start(void)
{
    int rc;

    ble_hs_parent_task = os_sched_get_current_task();

    ble_hs_heartbeat_timer_reset(BLE_HS_HEARTBEAT_OS_TICKS);

    ble_gatts_start();

    rc = ble_hs_startup_go();
    return rc;
}
Example #11
0
void
task2_handler(void *arg)
{
    struct os_task *t;

    while (1) {
        /* just for debug; task 2 should be the running task */
        t = os_sched_get_current_task();
        assert(t->t_func == task2_handler);

        /* Increment # of times we went through task loop */
        ++g_task2_loops;

        /* Wait for semaphore from ISR */
        os_sem_pend(&g_test_sem, OS_TIMEOUT_NEVER);
    }
}
Example #12
0
int 
os_task_sanity_checkin(struct os_task *t)
{
    int rc; 

    if (t == NULL) {
        t = os_sched_get_current_task();
    }

    rc = os_sanity_check_reset(&t->t_sanity_check);
    if (rc != OS_OK) {
        goto err;
    }

    return (0);
err:
    return (rc);
}
Example #13
0
void
task1_handler(void *arg)
{
    struct os_task *t;
    int prev_pin_state, curr_pin_state;
    struct image_version ver;

    /* Set the led pin for the E407 devboard */
    g_led_pin = LED_BLINK_PIN;
    hal_gpio_init_out(g_led_pin, 1);

    if (imgr_my_version(&ver) == 0) {
        console_printf("\nSlinky_OIC %u.%u.%u.%u\n",
          ver.iv_major, ver.iv_minor, ver.iv_revision,
          (unsigned int)ver.iv_build_num);
    } else {
        console_printf("\nSlinky\n");
    }

    while (1) {
        t = os_sched_get_current_task();
        assert(t->t_func == task1_handler);

        ++g_task1_loops;

        /* Wait one second */
        os_time_delay(OS_TICKS_PER_SEC);

        /* Toggle the LED */
        prev_pin_state = hal_gpio_read(g_led_pin);
        curr_pin_state = hal_gpio_toggle(g_led_pin);
        LOG_INFO(&my_log, LOG_MODULE_DEFAULT, "GPIO toggle from %u to %u",
            prev_pin_state, curr_pin_state);
        STATS_INC(g_stats_gpio_toggle, toggles);

        /* Release semaphore to task 2 */
        os_sem_release(&g_test_sem);
    }
}
Example #14
0
/**
 * sem test basic 
 *  
 * Basic semaphore tests
 * 
 * @return int 
 */
static void 
sem_test_basic_handler(void *arg)
{
    struct os_task *t;
    struct os_sem *sem;
    os_error_t err;

    sem = &g_sem1;
    t = os_sched_get_current_task();

    /* Test some error cases */
    TEST_ASSERT(os_sem_init(NULL, 1)    == OS_INVALID_PARM);
    TEST_ASSERT(os_sem_delete(NULL)     == OS_INVALID_PARM);
    TEST_ASSERT(os_sem_release(NULL)    == OS_INVALID_PARM);
    TEST_ASSERT(os_sem_pend(NULL, 1)    == OS_INVALID_PARM);

    /* Get the semaphore */
    err = os_sem_pend(sem, 0);
    TEST_ASSERT(err == 0,
                "Did not get free semaphore immediately (err=%d)", err);

    /* Check semaphore internals */
    TEST_ASSERT(sem->sem_tokens == 0 && SLIST_EMPTY(&sem->sem_head),
                "Semaphore internals wrong after getting semaphore\n"
                "%s\n"
                "Task: task=%p prio=%u", sem_test_sem_to_s(sem), t, t->t_prio);

    /* Get the semaphore again; should fail */
    err = os_sem_pend(sem, 0);
    TEST_ASSERT(err == OS_TIMEOUT,
                "Did not time out waiting for semaphore (err=%d)", err);

    /* Check semaphore internals */
    TEST_ASSERT(sem->sem_tokens == 0 && SLIST_EMPTY(&sem->sem_head),
                "Semaphore internals wrong after getting semaphore\n"
                "%s\n"
                "Task: task=%p prio=%u\n", sem_test_sem_to_s(sem), t,
                t->t_prio);

    /* Release semaphore */
    err = os_sem_release(sem);
    TEST_ASSERT(err == 0,
                "Could not release semaphore I own (err=%d)", err);

    /* Check semaphore internals */
    TEST_ASSERT(sem->sem_tokens == 1 && SLIST_EMPTY(&sem->sem_head),
                "Semaphore internals wrong after releasing semaphore\n"
                "%s\n"
                "Task: task=%p prio=%u\n", sem_test_sem_to_s(sem), t,
                t->t_prio);

    /* Release it again */
    err = os_sem_release(sem);
    TEST_ASSERT(err == 0,
                "Could not release semaphore again (err=%d)\n", err);

    /* Check semaphore internals */
    TEST_ASSERT(sem->sem_tokens == 2 && SLIST_EMPTY(&sem->sem_head),
                "Semaphore internals wrong after releasing semaphore\n"
                "%s\n"
                "Task: task=%p prio=%u\n", sem_test_sem_to_s(sem), t,
                t->t_prio);

    /* "Delete" it */
    err = os_sem_delete(sem);
    TEST_ASSERT(err == 0,
                "Could not delete semaphore (err=%d)", err);

    /* Check semaphore internals */
    TEST_ASSERT(sem->sem_tokens == 0 && SLIST_EMPTY(&sem->sem_head),
                "Semaphore internals wrong after deleting semaphore\n"
                "%s\n"
                "Task: task=%p prio=%u\n", sem_test_sem_to_s(sem), t,
                t->t_prio);

    os_test_restart();
}
Example #15
0
/**
 * Indicates whether the host's parent task is currently running.
 */
int
ble_hs_is_parent_task(void)
{
    return os_sched_get_current_task() == ble_hs_parent_task;
}
Example #16
0
/**
 * Indicates whether the host's parent task is currently running.
 */
int
ble_hs_is_parent_task(void)
{
    return !os_started() || os_sched_get_current_task() == ble_hs_parent_task;
}