示例#1
0
文件: main.c 项目: eerimoq/simba
static int test_duty_cycles(struct harness_t *harness_p)
{
    int percentage;
    long duty_cycle;

    BTASSERT(pwm_soft_start(&pwm_soft[0]) == 0);
    BTASSERT(pwm_soft_start(&pwm_soft[1]) == 0);
    thrd_sleep_ms(100);

    /* Test various duty cycles. */
    for (percentage = 0; percentage <= 100; percentage += 10) {
        duty_cycle = pwm_soft_duty_cycle(percentage);

        BTASSERT(pwm_soft_set_duty_cycle(&pwm_soft[0], duty_cycle) == 0);
        BTASSERT(pwm_soft_set_duty_cycle(&pwm_soft[1], duty_cycle) == 0);
        
        std_printf(FSTR("Duty cycle: %ld\r\n"), duty_cycle);
        thrd_sleep_ms(100);
    }
    
    BTASSERT(pwm_soft_stop(&pwm_soft[0]) == 0);
    BTASSERT(pwm_soft_stop(&pwm_soft[1]) == 0);

    return (0);
}
示例#2
0
文件: socket_stub.c 项目: wuwx/simba
void socket_stub_input(int socket, void *buf_p, size_t size)
{
    struct socket_t *socket_p;

    while (1) {
        socket_p = sockets[socket];

        if (socket_p != NULL) {
            break;
        }

        thrd_sleep_ms(1);
    }

    /* Resume any polling thread. */
    sys_lock();

    if (chan_is_polled_isr(&socket_p->base)) {
        thrd_resume_isr(socket_p->base.reader_p, 0);
        socket_p->base.reader_p = NULL;
    }

    chan_write_isr(&qinput, &buf_p, sizeof(buf_p));
    chan_write_isr(&qinput, &size, sizeof(size));

    sys_unlock();
}
示例#3
0
文件: main.c 项目: wuwx/simba
int main()
{
    int value;
    struct analog_output_pin_t pin;

    sys_start();
    analog_output_pin_module_init();

    /* Initialize the analog output pin. */
    analog_output_pin_init(&pin, &pin_d10_dev);

    value = 0;
    
    while (1) {
        /* Write a sawtooth wave to the analog output pin. */
        analog_output_pin_write(&pin, value);
        value += 5;
        value %= 1024;

        /* Wait ten milliseconds. */
        thrd_sleep_ms(10);
    }

    return (0);
}
示例#4
0
文件: main.c 项目: wuwx/simba
int test_sleep(struct harness_t *harness_p)
{
    BTASSERT(thrd_sleep(0.001) == 0);
    BTASSERT(thrd_sleep_ms(1) == 0);
    BTASSERT(thrd_sleep_us(1000) == 0);

    return (0);
}
示例#5
0
文件: main.c 项目: wuwx/simba
int test_monitor_thread(struct harness_t *harness_p)
{
    char command[64];

    /* Missing print value. */
    strcpy(command, "/kernel/thrd/monitor/set_print");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == -EINVAL);

    /* Bad print integer value. */
    strcpy(command, "/kernel/thrd/monitor/set_print 2");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == -EINVAL);

    /* Bad print value. */
    strcpy(command, "/kernel/thrd/monitor/set_print foo");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == -EINVAL);

    /* Start printing. */
    strcpy(command, "/kernel/thrd/monitor/set_print 1");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == 0);

    /* Wait a while for monitor thread output.*/
    thrd_sleep_ms(30);

    strcpy(command, "/kernel/thrd/monitor/set_period_ms 10");
    BTASSERT(fs_call(command, NULL, chan_null(), NULL) == 0);

    /* Wait a while for monitor thread output.*/
    thrd_sleep_ms(30);

    /* Stop printing. */
    strcpy(command, "/kernel/thrd/monitor/set_print 0");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == 0);

    /* Missing period. */
    strcpy(command, "/kernel/thrd/monitor/set_period_ms");
    BTASSERT(fs_call(command, NULL, chan_null(), NULL) == -EINVAL);

    /* Bad period. */
    strcpy(command, "/kernel/thrd/monitor/set_period_ms bar");
    BTASSERT(fs_call(command, NULL, chan_null(), NULL) == -EINVAL);

    return (0);
}
示例#6
0
文件: main.c 项目: eerimoq/simba
static int test_duty_cycle_max(struct harness_t *harness_p)
{
    long duty_cycle;
    
    BTASSERT(pwm_soft_start(&pwm_soft[0]) == 0);
    BTASSERT(pwm_soft_start(&pwm_soft[1]) == 0);

    /* Always high for max duty cycle. */
    duty_cycle = pwm_soft_duty_cycle(100);
    BTASSERT(pwm_soft_set_duty_cycle(&pwm_soft[0], duty_cycle) == 0);
    BTASSERT(pwm_soft_set_duty_cycle(&pwm_soft[1], duty_cycle) == 0);
    
    thrd_sleep_ms(50);

    BTASSERT(pwm_soft_stop(&pwm_soft[0]) == 0);
    BTASSERT(pwm_soft_stop(&pwm_soft[1]) == 0);

    return (0);
}
示例#7
0
文件: main.c 项目: wuwx/simba
static int test_subscribe(struct harness_t *harness_p)
{
    struct mqtt_application_message_t foobar;

    /* Subscribe. */
    foobar.topic.buf_p = "foo/bar";
    foobar.topic.size = 7;
    foobar.qos = mqtt_qos_1_t;
    BTASSERT(mqtt_client_subscribe(&client, &foobar) == 0);

    thrd_sleep_ms(500);
    
    /* Unsubscribe. */
    foobar.topic.buf_p = "foo/bar";
    foobar.topic.size = 7;
    BTASSERT(mqtt_client_unsubscribe(&client, &foobar) == 0);

    return (0);
}
示例#8
0
文件: main.c 项目: wuwx/simba
static int test_read_timeout(struct harness_t *harness_p)
{
    struct fs_file_t file;
    uint8_t byte;
    uint8_t buf[516];
    int i, j;

    BTASSERT(fs_open(&file, "foo.txt", FS_WRITE | FS_CREAT | FS_TRUNC) == 0);

    byte = 0;

    for (i = 0; i < 130; i++) {
        BTASSERT(fs_write(&file, &byte, 1) == 1);
        byte++;
    }

    BTASSERT(fs_close(&file) == 0);

    /* Input read request packet. */
    socket_stub_input(0, "\x00""\x01""foo.txt""\x00""octet""\x00", 16);

    /* Read the packet three times (first transmission + two
       retransmissions). */
    for (i = 0; i < 3; i++) {
        socket_stub_output(&buf[0], 134);
        BTASSERT(buf[0] == 0);
        BTASSERT(buf[1] == 3);
        BTASSERT(buf[2] == 0);
        BTASSERT(buf[3] == 1);

        byte = 0;

        for (j = 0; j < 130; j++) {
            BTASSERT(buf[4 + j] == byte);
            byte++;
        }
    }

    thrd_sleep_ms(10);

    return (0);
}
示例#9
0
文件: main.c 项目: wuwx/simba
int main()
{
    int i, j;
    uint16_t samples[membersof(analog_pins)];

    sys_start();
    adc_module_init();

    for (i = 0; i < membersof(adc); i++) {
        adc_init(&adc[i],
                 analog_pins[i].adc_dev_p,
                 analog_pins[i].pin_dev_p,
                 ADC_REFERENCE_VCC,
                 1);
    }

    i = 0;

    while (1) {
        if ((i % 10) == 0) {
            print_header();
        }

        std_printf(FSTR("|"));

        for (j = 0; j < membersof(adc); j++) {
            samples[j] = 0xffff;
            adc_convert(&adc[j], &samples[j], 1);
        }

        for (j = 0; j < membersof(adc); j++) {
            std_printf(FSTR(" %6d |"), (int)samples[j]);
        }

        std_printf(FSTR("\r\n"));
        thrd_sleep_ms(500);
        i++;
    }

    return (0);
}
示例#10
0
文件: main.c 项目: wuwx/simba
static int test_write_timeout(struct harness_t *harness_p)
{
    uint8_t buf[4];
    int i;

    /* Input write request packet. */
    socket_stub_input(0, "\x00""\x02""fie.txt""\x00""octet""\x00", 16);

    /* Wait for the first ack packet + 2 retransmissions. */
    for (i = 0; i < 3; i++) {
        socket_stub_output(&buf[0], 4);
        BTASSERT(buf[0] == 0);
        BTASSERT(buf[1] == 4);
        BTASSERT(buf[2] == 0);
        BTASSERT(buf[3] == 0);
    }

    thrd_sleep_ms(100);

    return (0);
}
示例#11
0
文件: main.c 项目: eerimoq/simba
int main()
{
    struct pin_driver_t led;

    /* Start the system. */
    sys_start();

    /* Initialize the LED pin as output and set its value to 1. */
    pin_init(&led, &pin_led_dev, PIN_OUTPUT);
    pin_write(&led, 1);

    while (1) {
        /* Wait half a second. */
        thrd_sleep_ms(500);

        /* Toggle the LED on/off. */
        pin_toggle(&led);
    }

    return (0);
}
示例#12
0
文件: main.c 项目: eerimoq/simba
static int test_frequency(struct harness_t *harness_p)
{
    long frequency;

    for (frequency = 100; frequency < 10000; frequency += 1000) {
        /* Set the new frequency. */
        BTASSERT(pwm_soft_set_frequency(frequency) == 0);

        /* Run the PWM. */
        BTASSERT(pwm_soft_start(&pwm_soft[0]) == 0);
        BTASSERT(pwm_soft_set_duty_cycle(&pwm_soft[0],
                                         pwm_soft_duty_cycle(30)) == 0);
        thrd_sleep_ms(50);
        BTASSERT(pwm_soft_stop(&pwm_soft[0]) == 0);
    }

    /* May not change frequency when a PWM is started. */
    BTASSERT(pwm_soft_start(&pwm_soft[0]) == 0);
    BTASSERT(pwm_soft_set_frequency(frequency) == -1);
    BTASSERT(pwm_soft_stop(&pwm_soft[0]) == 0);
    
    return (0);
}
示例#13
0
文件: main.c 项目: wuwx/simba
static int test_read(struct harness_t *harness_p)
{
    struct fs_file_t file;
    uint8_t byte;
    uint8_t buf[516];
    int i;

    BTASSERT(fs_open(&file, "foo.txt", FS_WRITE | FS_CREAT | FS_TRUNC) == 0);

    byte = 0;

    for (i = 0; i < 1201; i++) {
        BTASSERT(fs_write(&file, &byte, 1) == 1);
        byte++;
    }

    BTASSERT(fs_close(&file) == 0);

    /* Input read request packet. */
    socket_stub_input(0, "\x00""\x01""foo.txt""\x00""octet""\x00", 16);

    /* Wait for the first data packet (bytes 0..511). */
    socket_stub_output(&buf[0], 516);
    BTASSERT(buf[0] == 0);
    BTASSERT(buf[1] == 3);
    BTASSERT(buf[2] == 0);
    BTASSERT(buf[3] == 1);

    byte = 0;

    for (i = 0; i < 512; i++) {
        BTASSERT(buf[4 + i] == byte);
        byte++;
    }

    /* Input bad acknowlegement packet. */
    socket_stub_input(1, "\x00""\x04""\x00""\x02", 4);

    /* Input acknowlegement packet. */
    socket_stub_input(1, "\x00""\x04""\x00""\x01", 4);

    /* Wait for the second data packet (bytes 512..1023). */
    socket_stub_output(&buf[0], 516);
    BTASSERT(buf[0] == 0);
    BTASSERT(buf[1] == 3);
    BTASSERT(buf[2] == 0);
    BTASSERT(buf[3] == 2);

    for (i = 0; i < 512; i++) {
        BTASSERT(buf[4 + i] == byte);
        byte++;
    }

    /* Input acknowlegement packet. */
    socket_stub_input(1, "\x00""\x04""\x00""\x02", 4);

    /* Wait for the second data packet (bytes 1024..1200). */
    socket_stub_output(&buf[0], 181);
    BTASSERT(buf[0] == 0);
    BTASSERT(buf[1] == 3);
    BTASSERT(buf[2] == 0);
    BTASSERT(buf[3] == 3);

    for (i = 0; i < 177; i++) {
        BTASSERT(buf[4 + i] == byte);
        byte++;
    }

    /* Input last acknowlegement packet. */
    socket_stub_input(1, "\x00""\x04""\x00""\x03", 4);

    thrd_sleep_ms(10);

    return (0);
}
示例#14
0
文件: main.c 项目: wuwx/simba
static int test_bad_request(struct harness_t *harness_p)
{
    uint8_t buf[516];

    /* Input bad write request packets. */
    socket_stub_input(0, "\x00", 1);
    socket_stub_input(0, "\x00""\x07", 2);

    /* Filename missing. */
    socket_stub_input(0, "\x00""\x02", 2);

    socket_stub_output(&buf[0], 22);
    BTASSERT(buf[0] == 0);
    BTASSERT(buf[1] == 5);
    BTASSERT(buf[2] == 0);
    BTASSERT(buf[3] == 0);
    BTASSERT(strcmp("malformed request", (char *)&buf[4]) == 0);

    /* Mode missing. */
    socket_stub_input(0, "\x00""\x02""file", 6);

    socket_stub_output(&buf[0], 22);
    BTASSERT(buf[0] == 0);
    BTASSERT(buf[1] == 5);
    BTASSERT(buf[2] == 0);
    BTASSERT(buf[3] == 0);
    BTASSERT(strcmp("malformed request", (char *)&buf[4]) == 0);

    /* Mode missing #2. */
    socket_stub_input(0, "\x00""\x02""file""\x00", 7);

    socket_stub_output(&buf[0], 22);
    BTASSERT(buf[0] == 0);
    BTASSERT(buf[1] == 5);
    BTASSERT(buf[2] == 0);
    BTASSERT(buf[3] == 0);
    BTASSERT(strcmp("malformed request", (char *)&buf[4]) == 0);

    /* Bad mode. */
    socket_stub_input(0, "\x00""\x02""file""\x00""ooooo", 12);

    socket_stub_output(&buf[0], 31);
    BTASSERT(buf[0] == 0);
    BTASSERT(buf[1] == 5);
    BTASSERT(buf[2] == 0);
    BTASSERT(buf[3] == 0);
    BTASSERT(strcmp("only binary mode supported", (char *)&buf[4]) == 0);

    /* Read non-existing file. */
    socket_stub_input(0, "\x00""\x01""nonexisting""\x00""octet""\x00", 20);

    socket_stub_output(&buf[0], 19);
    BTASSERT(buf[0] == 0);
    BTASSERT(buf[1] == 5);
    BTASSERT(buf[2] == 0);
    BTASSERT(buf[3] == 1);
    BTASSERT(strcmp("file not found", (char *)&buf[4]) == 0);

    thrd_sleep_ms(10);

    return (0);
}
示例#15
0
文件: main.c 项目: wuwx/simba
static int test_write(struct harness_t *harness_p)
{
    struct fs_file_t file;
    uint8_t byte;
    uint8_t ref_byte;
    uint8_t buf[516];
    int i;

    /* Input write request packet. */
    socket_stub_input(0, "\x00""\x02""bar.txt""\x00""octet""\x00", 16);

    /* Wait for the first ack packet. */
    socket_stub_output(&buf[0], 4);
    BTASSERT(buf[0] == 0);
    BTASSERT(buf[1] == 4);
    BTASSERT(buf[2] == 0);
    BTASSERT(buf[3] == 0);

    /* Write the first data packet (bytes 0-511). */
    buf[0] = 0;
    buf[1] = 3;
    buf[2] = 0;
    buf[3] = 1;
    byte = 0;

    for (i = 0; i < 512; i++) {
        buf[4 + i] = byte;
        byte++;
    }

    socket_stub_input(2, &buf[0], 516);

    /* Wait for the second ack packet. */
    socket_stub_output(&buf[0], 4);
    BTASSERT(buf[0] == 0);
    BTASSERT(buf[1] == 4);
    BTASSERT(buf[2] == 0);
    BTASSERT(buf[3] == 1);

    /* Write the second data packet (bytes 512-1023). */
    buf[0] = 0;
    buf[1] = 3;
    buf[2] = 0;
    buf[3] = 2;
    byte = 0;

    for (i = 0; i < 512; i++) {
        buf[4 + i] = byte;
        byte++;
    }

    socket_stub_input(2, &buf[0], 516);

    /* Wait for the third ack packet. */
    socket_stub_output(&buf[0], 4);
    BTASSERT(buf[0] == 0);
    BTASSERT(buf[1] == 4);
    BTASSERT(buf[2] == 0);
    BTASSERT(buf[3] == 2);

    /* Write the third data packet (bytes 1024-1100) with wrong block
       number. */
    buf[0] = 0;
    buf[1] = 3;
    buf[2] = 0;
    buf[3] = 2;
    byte = 0;

    for (i = 0; i < 77; i++) {
        buf[4 + i] = byte;
        byte++;
    }

    socket_stub_input(2, &buf[0], 81);

    thrd_sleep_ms(10);

    /* Correct block number. */
    buf[3] = 3;
    socket_stub_input(2, &buf[0], 81);

    /* Wait for the third ack packet. */
    socket_stub_output(&buf[0], 4);
    BTASSERT(buf[0] == 0);
    BTASSERT(buf[1] == 4);
    BTASSERT(buf[2] == 0);
    BTASSERT(buf[3] == 3);

    thrd_sleep_ms(10);

    /* Verify the contents of the file created by the TFTP server. */
    BTASSERT(fs_open(&file, "bar.txt", FS_READ) == 0);

    byte = 0;

    for (i = 0; i < 1101; i++) {
        BTASSERT(fs_read(&file, &ref_byte, 1) == 1);
        BTASSERT(ref_byte == byte);
        byte++;
    }

    BTASSERT(fs_close(&file) == 0);

    return (0);
}