Beispiel #1
0
int http_server_start(struct http_server_t *self_p)
{
    ASSERTN(self_p != NULL, EINVAL);

    struct http_server_connection_t *connection_p;

    /* Spawn the listener thread. */
    self_p->listener_p->thrd.id_p =
        thrd_spawn(listener_main,
                   self_p,
                   0,
                   self_p->listener_p->thrd.stack.buf_p,
                   self_p->listener_p->thrd.stack.size);

    connection_p = self_p->connections_p;

    /* Spawn the connection threads. */
    while (connection_p->thrd.stack.buf_p != NULL) {
        connection_p->thrd.id_p =
            thrd_spawn(connection_main,
                       connection_p,
                       0,
                       connection_p->thrd.stack.buf_p,
                       connection_p->thrd.stack.size);

        connection_p++;
    }

    return (0);
}
Beispiel #2
0
static int test_all(struct harness_t *harness_p)
{
    struct time_t timeout = {
        .seconds = 0,
        .nanoseconds = 0
    };

    sem_init(&sem, 1, 1);
    sem_init(&sem2, 2, 2);
    
    /* 1. Take all resources. */
    BTASSERT(sem_take(&sem, &timeout) == -ETIMEDOUT);

    /* Create two thrds with higher priority than this thrd. */
    thrd_spawn(sem_main,
               NULL,
               -10,
               t0_stack,
               sizeof(t0_stack));
    thrd_spawn(sem_main,
               NULL,
               -10,
               t1_stack,
               sizeof(t1_stack));

    /* 3. Wait until both threads are waiting for sem. */
    sem_take(&sem2, NULL);
    sem_take(&sem2, NULL);

    /* 4. Start both threads. */
    sem_give(&sem, 2);

    /* 6. Wait for both threads. */
    sem_take(&sem2, NULL);
    sem_take(&sem2, NULL);

    return (0);
}

int main()
{
    struct harness_t harness;
    struct harness_testcase_t harness_testcases[] = {
        { test_all, "test_all" },
        { NULL, NULL }
    };

    sys_start();

    harness_init(&harness);
    harness_run(&harness, harness_testcases);

    return (0);
}
Beispiel #3
0
Datei: main.c Projekt: wuwx/simba
int test_preemptive(struct harness_t *harness_p)
{
    struct time_t timeout;
    struct time_t start, stop, duration;

    /* Spawn a low priority worker thread. */
    BTASSERT(thrd_spawn(preemptive_main,
                        NULL,
                        20,
                        preemptive_stack,
                        sizeof(preemptive_stack)) != NULL);

    BTASSERT(time_get(&start) == 0);

    /* Suspend this thread to make sure the worker thread is in its
       infinite loop. When the suspend timeout occurs, this thread
       will be scheduled since it has higher priority than the worker
       thread. */
    timeout.seconds = 0;
    timeout.nanoseconds = 10000000;
    BTASSERT(thrd_suspend(&timeout) == -ETIMEDOUT);

    BTASSERT(time_get(&stop) == 0);
    BTASSERT(time_subtract(&duration, &stop, &start) == 0);

    BTASSERT(duration.seconds == 0);
    BTASSERTI(duration.nanoseconds, >=, 10000000);

    return (0);
}
Beispiel #4
0
Datei: main.c Projekt: wuwx/simba
static int test_init(struct harness_t *harness_p)
{
    struct thrd_t *thrd_p;
    int port = REMOTE_HOST_PORT;
    char remote_host_ip[] = STRINGIFY(REMOTE_HOST_IP);
    struct inet_addr_t remote_host_address;

    self_p = thrd_self();

    std_printf(FSTR("Connecting to '%s:%d'.\r\n"), remote_host_ip, port);

    BTASSERT(inet_aton(remote_host_ip, &remote_host_address.ip) == 0);
    remote_host_address.port = port;

    BTASSERT(socket_open_tcp(&server_sock) == 0);
    BTASSERT(socket_connect(&server_sock, &remote_host_address) == 0);

    BTASSERT(mqtt_client_init(&client,
                              "mqtt_client",
                              NULL,
                              &server_sock,
                              &server_sock,
                              on_publish,
                              NULL) == 0);

    thrd_p = thrd_spawn(mqtt_client_main,
                        &client,
                        0,
                        stack,
                        sizeof(stack));

    thrd_set_log_mask(thrd_p, LOG_UPTO(DEBUG));

    return (0);
}
Beispiel #5
0
int music_player_start(struct music_player_t *self_p)
{
    self_p->thrd_p = thrd_spawn((void *(*)(void *))music_player_main,
                                self_p,
                                -30,
                                self_p->stack,
                                sizeof(self_p->stack));

    return (self_p->thrd_p == NULL);
}
Beispiel #6
0
static int init()
{
    struct inet_ip_addr_t ipaddr;
    struct inet_ip_addr_t netmask;
    struct inet_ip_addr_t gw;

    sys_start();

    std_printf(sys_get_info());

    uart_init(&ipuart, &uart_device[1], 115200, iprxbuf, sizeof(iprxbuf));
    uart_start(&ipuart);

    inet_module_init();
    socket_module_init();
    network_interface_slip_module_init();

    inet_aton("169.254.1.2", &ipaddr);
    inet_aton("255.255.255.0", &netmask);
    inet_aton("0.0.0.0", &gw);

    network_interface_slip_init(&slip,
                                &ipaddr,
                                &netmask,
                                &gw,
                                &ipuart.chout);
    network_interface_add(&slip.network_interface);
    network_interface_start(&slip.network_interface);

    thrd_spawn(slip_reader,
               NULL,
               0,
               stack,
               sizeof(stack));

    http_server_init(&server,
                     &listener,
                     connections,
                     NULL,
                     routes,
                     no_route);

    http_server_start(&server);

    return (0);
}
int main()
{
    uint32_t mask;

    init();

    /* Spawn the shell. */
    shell_args.chin_p = &uart.chin;
    shell_args.chout_p = &uart.chout;
    shell_args.username_p = NULL;
    shell_args.password_p = NULL;
    thrd_spawn(shell_entry,
               &shell_args,
               0,
               shell_stack,
               sizeof(shell_stack));

    while (1) {
        mask = (EVENT_BUTTON_PLAY
                | EVENT_BUTTON_NEXT
                | EVENT_BUTTON_PREV
                | EVENT_BUTTON_STOP);
        event_read(&event, &mask, sizeof(mask));

        if (mask & EVENT_BUTTON_PLAY) {
            handle_event_play();
        }

        if (mask & EVENT_BUTTON_NEXT) {
            handle_event_next();
        }

        if (mask & EVENT_BUTTON_PREV) {
            handle_event_prev();
        }

        if (mask & EVENT_BUTTON_STOP) {
            handle_event_stop();
        }
    }

    return (0);
}
Beispiel #8
0
Datei: main.c Projekt: wuwx/simba
int test_suspend_resume(struct harness_t *harness_p)
{
    int err;
    struct thrd_t *thrd_p;

    thrd_p = thrd_spawn(suspend_resume_main,
                        thrd_self(),
                        10,
                        suspend_resume_stack,
                        sizeof(suspend_resume_stack));

    err = thrd_suspend(NULL);
    BTASSERT(err == 3);

    /* Wait for the spawned thread to terminate, twice. */
    BTASSERT(thrd_join(thrd_p) == 0);
    BTASSERT(thrd_join(thrd_p) == 0);

    return (0);
}
Beispiel #9
0
int main()
{
    uint32_t mask;

    init();

    /* Spawn the shell. */
    shell_init(&shell, &uart.chin, &uart.chout, NULL, NULL, NULL, NULL);
    thrd_spawn(shell_main,
               &shell,
               0,
               shell_stack,
               sizeof(shell_stack));

    while (1) {
        mask = (EVENT_BUTTON_PLAY
                | EVENT_BUTTON_NEXT
                | EVENT_BUTTON_PREV
                | EVENT_BUTTON_STOP);
        event_read(&event, &mask, sizeof(mask));

        if (mask & EVENT_BUTTON_PLAY) {
            handle_event_play();
        }

        if (mask & EVENT_BUTTON_NEXT) {
            handle_event_next();
        }

        if (mask & EVENT_BUTTON_PREV) {
            handle_event_prev();
        }

        if (mask & EVENT_BUTTON_STOP) {
            handle_event_stop();
        }
    }

    return (0);
}