示例#1
0
/**
 * def system(command)
 */
static mp_obj_t os_system(mp_obj_t command_in)
{
    int res;
    char command[128];
    struct vstr_chan_t chout;

    strncpy(command, mp_obj_str_get_str(command_in), membersof(command));
    command[membersof(command) - 1] = '\0';

    vstr_chan_init(&chout);

    res = fs_call(command, sys_get_stdin(), &chout, NULL);

    if (res == -ENOENT) {
        nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
                                                "Command not found: '%s'",
                                                mp_obj_str_get_str(command_in)));
    } else if (res != 0) {
        nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
                                                "Command failed with %d",
                                                res));
    }

    return (mp_obj_new_str_from_vstr(&mp_type_str,
                                     vstr_chan_get_vstr(&chout)));
}
示例#2
0
文件: main.c 项目: wuwx/simba
static void print_header()
{
    int i;

    std_printf(FSTR("+"));

    for (i = 0; i < membersof(adc); i++) {
        std_printf(FSTR("--------+"));
    }

    std_printf(FSTR("\r\n"
                    "|"));

    for (i = 0; i < membersof(adc); i++) {
        std_printf(FSTR(" %6s |"), analog_pins[i].name_p);
    }

    std_printf(FSTR("\r\n"
                    "+"));

    for (i = 0; i < membersof(adc); i++) {
        std_printf(FSTR("--------+"));
    }

    std_printf(FSTR("\r\n"));
}
示例#3
0
文件: main.c 项目: eerimoq/simba
int test_add_get_remove(struct harness_t *harness)
{
    struct hash_map_t map;
    struct hash_map_bucket_t buckets[8];
    struct hash_map_entry_t entries[4];

    hash_map_init(&map,
                  buckets,
                  membersof(buckets),
                  entries,
                  membersof(entries),
                  hash);

    /* Add three entries. */
    BTASSERT(hash_map_add(&map, 37, (void *)34) == 0);
    BTASSERT(hash_map_add(&map, 38, (void *)35) == 0);
    BTASSERT(hash_map_add(&map, 39, (void *)36) == 0);
    BTASSERT(hash_map_add(&map, 39, (void *)36) == 0);

    /* Get them. */
    BTASSERT(hash_map_get(&map, 38) == (void *)35);
    BTASSERT(hash_map_get(&map, 39) == (void *)36);
    BTASSERT(hash_map_get(&map, 37) == (void *)34);

    /* Remove first two. */
    BTASSERT(hash_map_remove(&map, 37) == 0);
    BTASSERT(hash_map_remove(&map, 38) == 0);
    BTASSERT(hash_map_remove(&map, 38) == -1);

    /* Get removed entries. */
    BTASSERT(hash_map_get(&map, 37) == NULL);
    BTASSERT(hash_map_get(&map, 38) == NULL);

    /* Get, remove and get last entry. */
    BTASSERT(hash_map_get(&map, 39) == (void *)36);
    BTASSERT(hash_map_remove(&map, 39) == 0);
    BTASSERT(hash_map_remove(&map, 39) == -1);
    BTASSERT(hash_map_get(&map, 39) == NULL);

    /* Add one entry over limit. */
    BTASSERT(hash_map_add(&map, 37, (void *)4) == 0);
    BTASSERT(hash_map_add(&map, 39, (void *)5) == 0);
    BTASSERT(hash_map_add(&map, 41, (void *)6) == 0);
    BTASSERT(hash_map_add(&map, 43, (void *)7) == 0);
    BTASSERT(hash_map_add(&map, 45, (void *)8) == -ENOMEM);

    return (0);
}
示例#4
0
文件: main.c 项目: wuwx/simba
int test_read_write(struct harness_t *harness_p)
{
    struct canif_frame_t frame;
    struct canif_frame_t frames[1];
    struct mcp2515_driver_t mcp2515;

    BTASSERT(mcp2515_init(&mcp2515,
                          &spi_device[0],
                          &pin_d10_dev,
                          &exti_device[0],
                          MCP2515_MODE_LOOPBACK,
                          MCP2515_SPEED_1000KBPS,
                          NULL,
                          frames,
                          membersof(frames)) == 0);
    BTASSERT(mcp2515_start(&mcp2515) == 0);

    /* Write a frame to the device. */
    memset(&frame, 0, sizeof(frame));
    frame.id = 57;
    frame.data[0] = 9;
    BTASSERT(mcp2515_write(&mcp2515, &frame) == 0);

    /* Read a frame from the device. */
    memset(&frame, 0, sizeof(frame));
    BTASSERT(mcp2515_read(&mcp2515, &frame) == 0);

    /* Verify frame contents. */
    BTASSERT(frame.id == 57);
    BTASSERT(frame.data[0] == 9);

    BTASSERT(mcp2515_stop(&mcp2515) == 0);

    return (0);
}
示例#5
0
文件: main.c 项目: eerimoq/simba
int test_get_temp(struct harness_t *harness_p)
{
    struct owi_driver_t owi;
    struct ds18b20_driver_t ds;
    struct owi_device_t devices[4];
    char buf[24];
    int number_of_sensors;

    BTASSERT(owi_init(&owi, &pin_d7_dev, devices, membersof(devices)) == 0);
    BTASSERT(ds18b20_init(&ds, &owi) == 0);

    time_busy_wait_us(50000);

    number_of_sensors = owi_search(&owi);

    std_printf(FSTR("number_of_sensors = %d\r\n"), number_of_sensors);

    BTASSERT(number_of_sensors == 2);

    strcpy(buf, "drivers/ds18b20/list");
    BTASSERT(fs_call(buf, NULL, sys_get_stdout(), NULL) == 0);

    time_busy_wait_us(50000);

    return (0);
}
示例#6
0
文件: main.c 项目: eerimoq/simba
static int test_read_performance(struct harness_t *harness_p)
{
    int i, block, res;
    struct time_t start, stop, diff;
    float seconds;
    unsigned long bytes_per_seconds;
    int number_of_blocks = 32;

    /* Write reference data to given block and verify that it was
       written. */
    for (i = 0; i < membersof(buf); i++) {
        buf[i] = (i & 0xff);
    }

    time_get(&start);

    /* Write to and read from the first five blocks. */
    for (block = 0; block < number_of_blocks; block++) {
        BTASSERT((res = sd_read_block(&sd, buf, block)) == SD_BLOCK_SIZE,
                 ", res = %d\r\n", res);
    }

    time_get(&stop);
    time_diff(&diff, &stop, &start);
    seconds = (diff.seconds + diff.nanoseconds / 1000000000.0f);
    bytes_per_seconds = ((SD_BLOCK_SIZE * number_of_blocks) / seconds);

    std_printf(FSTR("Read 32 blocks of %d bytes in %f s (%lu bytes/s).\r\n"),
               SD_BLOCK_SIZE,
               seconds,
               bytes_per_seconds);

    return (0);
}
示例#7
0
文件: main.c 项目: eerimoq/simba
static int test_put_get_int(struct harness_t *harness)
{
    struct fifo_int_t fifo;
    int buf[4];
    int value;

    BTASSERT(fifo_init_int(&fifo, buf, membersof(buf)) == 0);

    /* Put into the fifo. */
    value = 10;
    BTASSERT(fifo_put_int(&fifo, &value) == 0);
    value = 20;
    BTASSERT(fifo_put_int(&fifo, &value) == 0);
    value = 30;
    BTASSERT(fifo_put_int(&fifo, &value) == 0);
    value = 40;
    BTASSERT(fifo_put_int(&fifo, &value) == -1);

    /* Get from the fifo. */
    BTASSERT(fifo_get_int(&fifo, &value) == 0);
    BTASSERT(value == 10);
    BTASSERT(fifo_get_int(&fifo, &value) == 0);
    BTASSERT(value == 20);
    BTASSERT(fifo_get_int(&fifo, &value) == 0);
    BTASSERT(value == 30);
    BTASSERT(fifo_get_int(&fifo, &value) == -1);

    return (0);
}
示例#8
0
文件: main.c 项目: wuwx/simba
static int test_pcm1611s(struct harness_t *harness_p)
{
#if !defined(SKIP_TEST_PCM1611S)

    int i;
    int samples_per_second = 2 * 11025;
    struct dac_driver_t dac;

    BTASSERT(dac_init(&dac,
                      &dac_0_dev,
                      &pin_0_dev,
                      &pin_1_dev,
                      samples_per_second) == 0);

    for (i = 0; i < membersof(dac_gen_pcm1611s); i += 4096) {
        memcpy(samples, &dac_gen_pcm1611s[i], sizeof(samples));
        BTASSERT(dac_async_convert(&dac,
                                   (uint32_t *)samples,
                                   4096 / 2) == 0);
    }

    BTASSERT(dac_async_wait(&dac) == 0);

    return (0);

#else
    
    return (1);
    
#endif
}
示例#9
0
文件: battery.c 项目: eerimoq/romeo
int battery_async_convert(struct battery_t *battery_p)
{
    /* Start asynchronous convertion. */
    return (adc_async_convert(&battery_p->adc,
                              battery_p->ongoing.samples,
                              membersof(battery_p->ongoing.samples)));
}
示例#10
0
文件: main.c 项目: eerimoq/simba
static int storage_init(fat16_read_t *read_p,
                        fat16_write_t *write_p,
                        void **arg_pp)
{
    struct usb_host_device_t *device_p;
    union usb_message_t message;

    std_printf(FSTR("USB storage.\r\n"));

    /* Initialize the USB host driver. */
    usb_host_init(&usb,
                  &usb_device[0],
                  host_devices,
                  membersof(host_devices));

    usb_host_class_mass_storage_init(&mass_storage,
                                     &usb,
                                     mass_storage_devices,
                                     membersof(mass_storage_devices));
    usb_host_class_mass_storage_start(&mass_storage);

    /* Start the USB driver. */
    usb_host_start(&usb);

    chan_read(&usb.control, &message, sizeof(message));

    std_printf(FSTR("The USB control thread read a message of type %d\r\n"),
               message.header.type);

    if (message.header.type != USB_MESSAGE_TYPE_ADD) {
        std_printf(FSTR("bad message type %d\r\n"), message.header.type);
        return (-1);
    }

    device_p = usb_host_device_open(&usb, message.add.device);

    *read_p = read_block;
    *write_p = write_block;
    *arg_pp = device_p;

    return (0);

}
示例#11
0
文件: socket_stub.c 项目: wuwx/simba
int socket_open_udp(struct socket_t *self_p)
{
    if (number_of_sockets >= membersof(sockets)) {
        return (-1);
    }

    sockets[number_of_sockets++] = self_p;

    return (chan_init(&self_p->base, read, write, size));
}
示例#12
0
文件: main.c 项目: eerimoq/simba
static int test_read_write(struct harness_t *harness_p)
{
    int i, block, res;

    /* Write to and read from the first five blocks. */
    for (block = 0; block < 5; block++) {
        /* Write reference data to given block and verify that it was
           written. */
        for (i = 0; i < membersof(buf); i++) {
            buf[i] = ((block + i) & 0xff);
        }

        BTASSERT((res = sd_write_block(&sd, block, buf)) == SD_BLOCK_SIZE,
                 ", res = %d\r\n", res);
        memset(buf, 0, sizeof(buf));
        BTASSERT((res = sd_read_block(&sd, buf, block)) == SD_BLOCK_SIZE,
                 ", res = %d\r\n", res);

        for (i = 0; i < membersof(buf); i++) {
            BTASSERT(buf[i] == ((block + i) & 0xff));
        }

        /* Write zeros to given block and verify that it was
           written. */
        for (i = 0; i < membersof(buf); i++) {
            buf[i] = 0;
        }

        memset(buf, 0, sizeof(buf));
        BTASSERT((res = sd_write_block(&sd, block, buf)) == SD_BLOCK_SIZE,
                 ", res = %d\r\n", res);
        memset(buf, -1, sizeof(buf));
        BTASSERT((res = sd_read_block(&sd, buf, block)) == SD_BLOCK_SIZE,
                 ", res = %d\r\n", res);

        for (i = 0; i < membersof(buf); i++) {
            BTASSERT(buf[i] == 0);
        }
    }

    return (0);
}
示例#13
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);
}
示例#14
0
/**
 * Calculate timer setting, prescale and count value, given speed (bps),
 * number of bits in timer. Returns zero(0) if fails otherwise prescale
 * value/index, and timer top.
 * @param[in] speed bits per second, transmitter/receiver.
 * @param[in] bits number of bits in counter (8 or 16 bit timer).
 * @param[out] nticks timer top value.
 * @return prescale or zero(0).
 */
static uint8_t timer_setting(uint16_t speed, uint8_t bits, uint16_t* nticks) 
{
  uint16_t max_ticks = (1 << bits) - 1;
  uint8_t res = 0;
  for (uint8_t i = membersof(prescale) - 1; i > 0; i--) {
    uint16_t scale = (uint16_t) pgm_read_word(&prescale[i]);
    uint16_t count = (F_CPU / scale) / speed;
    if (count > res && count < max_ticks) {
      *nticks = count;
      res = i;
    }
  }
  return (res);
}
示例#15
0
文件: main.c 项目: wuwx/simba
static int test_list_devices(struct harness_t *harness_p)
{
    BTASSERT(usb_host_init(&usb,
                           &usb_device[0],
                           host_devices,
                           membersof(host_devices)) == 0);
    BTASSERT(usb_host_start(&usb) == 0);

    std_printf(FSTR("ADDRESS  CLASS  VENDOR  PRODUCT\r\n"));

    BTASSERT(usb_host_stop(&usb) == 0);

    return (0);
}
示例#16
0
文件: main.c 项目: wuwx/simba
static int test_sine_440_hz(struct harness_t *harness_p)
{
#if !defined(SKIP_TEST_SINE_440_HZ)
    
    int i;
    float sample;
    int samples_per_second = (membersof(dac_gen_sine) * 440);
    struct dac_driver_t dac;
    int total_number_of_samples;

    BTASSERT(dac_init(&dac,
                      &dac_0_dev,
                      &pin_0_dev,
                      NULL,
                      samples_per_second) == 0);

    /* Samples are in the range -1.0 to 1.0. Convert them to the range
       0 to AMPLITUDE_MAX. */
    for (i = 0; i < membersof(samples); i++) {
        sample = dac_gen_sine[i % membersof(dac_gen_sine)];
        samples[i] =  AMPLITUDE_MAX * ((sample + 1.0) / 2.0);
    }

    std_printf(FSTR("Converting %d samples.\r\n"), (int)membersof(samples));
    BTASSERT(dac_convert(&dac, (uint32_t *)samples, membersof(samples) / 2) == 0);

    /* Converting the signal on the DAC0-pin for 5 seconds. */
    total_number_of_samples = (5 * samples_per_second);
    std_printf(FSTR("Converting %d samples.\r\n"),
               total_number_of_samples);

    for (i = 0; i < total_number_of_samples; i += membersof(samples)) {
        BTASSERT(dac_async_convert(&dac,
                                   (uint32_t *)samples,
                                   membersof(samples) / 2) == 0);
        std_printf(FSTR("Samples left = %d\r\n"), total_number_of_samples - i);
    }

    std_printf(FSTR("Waiting for last samples to be converted\r\n"));

    BTASSERT(dac_async_wait(&dac) == 0);
    
    return (0);

#else

    (void)dac_gen_sine;
    
    return (1);
    
#endif
}
示例#17
0
文件: console.c 项目: wuwx/simba
int console_init(void)
{
    /* Initialize the CDC driver object. */
    usb_device_class_cdc_init(&module.console.cdc,
                              0,
                              2,
                              3,
                              module.console.rxbuf,
                              sizeof(module.console.rxbuf));
    module.console.drivers[0] = &module.console.cdc.base;

    /* Initialize the USB device driver. */
    usb_device_init(&module.console.usb,
                    &usb_device[0],
                    module.console.drivers,
                    membersof(module.console.drivers),
                    usb_device_descriptors);

    return (0);
}
示例#18
0
/**
 * Read from the file for the current song and add samples to the
 * DAC. In case the song ends, open the next song as preparation for
 * the next call to this function.
 */
static int play_chunk(struct music_player_t *self_p)
{
    const char *path_p;
    uint32_t *buf_p;
    size_t size;
    int i;

    /* Read samples from the file. */
    buf_p = self_p->samples.buf[self_p->samples.index];
    self_p->samples.index++;
    self_p->samples.index %= membersof(self_p->samples.buf);
    size = fat16_file_read(&self_p->file,
                           buf_p,
                           sizeof(self_p->samples.buf[0]));

    /* Optional down sampling of the read samples. */
    if (self_p->down_sampling_mask != 0xfffffffful) {
        for (i = 0; i < size / 4; i++) {
            buf_p[i] &= self_p->down_sampling_mask;
        }
    }

    if (size > 0) {
        /* Add samples for DAC convertion. */
        dac_async_convert(self_p->dac_p, buf_p, size / 4);
    } else {
        /* Start playing the next file in the queue. */
        fat16_file_close(&self_p->file);

        if ((path_p = self_p->cb.next_song_path_p(self_p->cb.arg_p)) != NULL) {
            strcpy(self_p->path, path_p);
            std_printf(FSTR("Playing | %s\r\n"), self_p->path);
            fat16_file_open(self_p->fat16_p, &self_p->file, path_p, O_READ);
        } else {
            self_p->state = STATE_IDLE;
        }
    }

    return (0);
}
示例#19
0
文件: main.c 项目: wuwx/simba
    /* { &adc_1_dev, &pin_gpio27_dev, "gpio27" }, */
    /* { &adc_1_dev, &pin_gpio25_dev, "gpio25" }, */
    /* { &adc_1_dev, &pin_gpio26_dev, "gpio26" } */
};

#elif defined(BOARD_ESP12E)

struct analog_pin_t analog_pins[] = {
    { &adc_0_dev,  &pin_a0_dev,  "a0" }
};

#else
#    error "Board not supported."
#endif

struct adc_driver_t adc[membersof(analog_pins)];

static void print_header()
{
    int i;

    std_printf(FSTR("+"));

    for (i = 0; i < membersof(adc); i++) {
        std_printf(FSTR("--------+"));
    }

    std_printf(FSTR("\r\n"
                    "|"));

    for (i = 0; i < membersof(adc); i++) {
示例#20
0
文件: main.c 项目: eerimoq/simba
static void init(void)
{
    long number;
    struct fat16_dir_t dir;
    struct fat16_dir_entry_t entry;
    struct song_t *song_p;
    uint32_t seconds;
    fat16_read_t read;
    fat16_write_t write;
    void * arg_p;

    sys_start();
    uart_module_init();

    uart_init(&uart, &uart_device[0], 38400, qinbuf, sizeof(qinbuf));
    uart_start(&uart);

    sys_set_stdout(&uart.chout);

    std_printf(sys_get_info());

    fs_command_init(&cmd_list, FSTR("/list"), cmd_list_cb, NULL);
    fs_command_register(&cmd_list);
    fs_command_init(&cmd_play, FSTR("/play"), cmd_play_cb, NULL);
    fs_command_register(&cmd_play);
    fs_command_init(&cmd_pause, FSTR("/pause"), cmd_pause_cb, NULL);
    fs_command_register(&cmd_pause);
    fs_command_init(&cmd_next, FSTR("/next"), cmd_next_cb, NULL);
    fs_command_register(&cmd_next);
    fs_command_init(&cmd_prev, FSTR("/prev"), cmd_prev_cb, NULL);
    fs_command_register(&cmd_prev);
    fs_command_init(&cmd_stop, FSTR("/stop"), cmd_stop_cb, NULL);
    fs_command_register(&cmd_stop);
    fs_command_init(&cmd_repeat, FSTR("/repeat"), cmd_repeat_cb, NULL);
    fs_command_register(&cmd_repeat);
    fs_command_init(&cmd_set_bits_per_sample,
                    FSTR("/set_bits_per_sample"),
                    cmd_set_bits_per_sample_cb,
                    NULL);
    fs_command_register(&cmd_set_bits_per_sample);

    if (storage_init(&read, &write, &arg_p) != 0) {
        std_printf(FSTR("storage init failed\r\n"));
        return;
    }

    std_printf(FSTR("initializing fat16\r\n"));
    fat16_init(&fs, read, write, arg_p, 0);

    std_printf(FSTR("fat16 initialized\r\n"));

    if (fat16_mount(&fs) != 0) {
        std_printf(FSTR("failed to mount fat16\r\n"));
        return;
    }

    std_printf(FSTR("fat16 mounted\r\n"));

    event_init(&event);

    exti_module_init();

    /* Initialize the buttons. */
    exti_init(&buttons[0],
              &exti_d18_dev,
              EXTI_TRIGGER_FALLING_EDGE,
              on_button_play,
              NULL);
    exti_start(&buttons[0]);
    exti_init(&buttons[1],
              &exti_d19_dev,
              EXTI_TRIGGER_FALLING_EDGE,
              on_button_prev,
              NULL);
    exti_start(&buttons[1]);
    exti_init(&buttons[2],
              &exti_d20_dev,
              EXTI_TRIGGER_FALLING_EDGE,
              on_button_next,
              NULL);
    exti_start(&buttons[2]);
    exti_init(&buttons[3],
              &exti_d21_dev,
              EXTI_TRIGGER_FALLING_EDGE,
              on_button_stop,
              NULL);
    exti_start(&buttons[3]);

    dac_init(&dac,
             &dac_0_dev,
             &pin_dac0_dev,
             &pin_dac1_dev,
             2 * SAMPLES_PER_SOCOND);

    hash_map_init(&song_map,
                  buckets,
                  membersof(buckets),
                  entries,
                  membersof(entries),
                  hash_number);

    sem_init(&sem, 0, 1);

    music_player_init(&music_player,
                      &fs,
                      &dac,
                      get_current_song_path,
                      get_next_song_path,
                      NULL);

    /* Initialize the song number. */
    current_song = FIRST_SONG_NUMBER;
    number = FIRST_SONG_NUMBER;

    /* Add songs to the hash map. */
    fat16_dir_open(&fs, &dir, ".", O_READ);

    while (fat16_dir_read(&dir, &entry) == 1) {
        if (number - FIRST_SONG_NUMBER == membersof(songs)) {
            std_printf("Maximum number of songs already added. "
                       "Skipping the rest of the songs.\r\n");
            break;
        }

        /* Skip folders. */
        if (entry.is_dir == 1) {
            continue;
        }

        song_p = &songs[number - FIRST_SONG_NUMBER];

        /* Initialize the song entry. */
        song_p->number = number;
        strcpy(song_p->name, entry.name);
        seconds = (entry.size / 4 / SAMPLES_PER_SOCOND);
        song_p->minutes = (seconds / 60);
        song_p->seconds = (seconds % 60);

        std_printf("Adding song %s to playlist.\r\n",
                   entry.name);

        hash_map_add(&song_map, number, song_p);
        number++;
    }

    fat16_dir_close(&dir);

    last_song_number = (number - 1);

    music_player_start(&music_player);
}
示例#21
0
文件: main.c 项目: wuwx/simba
int test_env(struct harness_t *harness_p)
{
    struct thrd_environment_variable_t global_variables[2];
    struct thrd_environment_variable_t variables[4];

    /* Default thread environment is setup correctly. */
    BTASSERT(thrd_get_env("FOO") == NULL);

    /* Set and get are not possible for a thread without an
       environment. */
    BTASSERT(thrd_init_env(NULL, 0) == 0);
    BTASSERT(thrd_set_env("CWD", "/") == -1);
    BTASSERT(thrd_get_env("CWD") == NULL);

    /* Initialize the global environment. */
    BTASSERT(thrd_init_global_env(global_variables,
                                  membersof(global_variables)) == 0);

    /* Set and get global variables. */
    BTASSERT(thrd_set_global_env("N1", "G1") == 0);
    BTASSERT(thrd_get_global_env("N1") != NULL);
    BTASSERT(strcmp(thrd_get_global_env("N1"), "G1") == 0);

    BTASSERT(thrd_set_global_env("N2", "G2") == 0);
    BTASSERT(thrd_get_global_env("N2") != NULL);
    BTASSERT(strcmp(thrd_get_env("N2"), "G2") == 0);

    /* Get from global environment using the thread local get
       function. */
    BTASSERT(thrd_get_env("N1") != NULL);
    BTASSERT(strcmp(thrd_get_env("N1"), "G1") == 0);

    /* Initialize the environment for the current thread. */
    BTASSERT(thrd_init_env(variables, membersof(variables)) == 0);

    /* Set and get variables. The global N1 is overridden. */
    BTASSERT(thrd_set_env("N1", "L1") == 0);
    BTASSERT(thrd_get_env("N1") != NULL);
    BTASSERT(strcmp(thrd_get_env("N1"), "L1") == 0);

    BTASSERT(thrd_set_env("N2", "L2") == 0);
    BTASSERT(thrd_get_env("N2") != NULL);
    BTASSERT(strcmp(thrd_get_env("N2"), "L2") == 0);

    BTASSERT(thrd_set_env("N3", "L3") == 0);
    BTASSERT(thrd_get_env("N3") != NULL);
    BTASSERT(strcmp(thrd_get_env("N3"), "L3") == 0);

    BTASSERT(thrd_set_env("N4", "L4") == 0);
    BTASSERT(thrd_get_env("N4") != NULL);
    BTASSERT(strcmp(thrd_get_env("N4"), "L4") == 0);

    /* Overwrite a value. */
    BTASSERT(thrd_set_env("N4", "L44") == 0);
    BTASSERT(thrd_get_env("N4") != NULL);
    BTASSERT(strcmp(thrd_get_env("N4"), "L44") == 0);

    /* No free space. */
    BTASSERT(thrd_set_env("N5", "L5") == -1);

    /* Remove a variable. */
    BTASSERT(thrd_set_env("N2", NULL) == 0);

    /* Set and get another variable. */
    BTASSERT(thrd_set_env("N6", "L6") == 0);
    BTASSERT(thrd_get_env("N6") != NULL);
    BTASSERT(strcmp(thrd_get_env("N6"), "L6") == 0);

    /* Get a non-existing variable. */
    BTASSERT(thrd_get_env("N7") == NULL);

    /* Remove the local environment. */
    BTASSERT(thrd_init_env(NULL, 0) == 0);

    /* Remove the global environment. */
    BTASSERT(thrd_init_global_env(NULL, 0) == 0);

    return (0);
}
示例#22
0
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 *
 * This file is part of the Arduino Che Cosa project.
 */

#include "Cosa/Fai.hh"

#if defined(NREFLECTION)
#define descr_name 0
#define values_name 0
#else
static const char descr_name[] __PROGMEM = "Cosa::Fai::digital_pins_t";
static const char values_name[] __PROGMEM = "values";
#endif
static const Ciao::Descriptor::member_t descr_members[] __PROGMEM = {
  {
    Ciao::UINT32_TYPE,
    1,
    values_name,
    0
  }
};
const Ciao::Descriptor::user_t Fai::Descriptor::digital_pins_t __PROGMEM = {
  Fai::Descriptor::DIGITAL_PINS_ID,
  descr_name,
  descr_members,
  membersof(descr_members)
};

示例#23
0
文件: main.c 项目: wuwx/simba
static int test_read_write_sizes(struct harness_t *harness_p)
{
    int i;
    uint8_t write_buf[153];
    uint8_t read_buf[153];

    /* Write zeros to the EEPROM. */
    memset(&write_buf[0], 0, sizeof(write_buf));
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,
                              0,
                              &write_buf[0],
                              sizeof(write_buf)) == sizeof(write_buf));

    /* Read and verify the written data. */
    memset(&read_buf[0], -1, sizeof(read_buf));
    BTASSERT(eeprom_i2c_read(&eeprom_i2c,
                             &read_buf[0],
                             0,
                             sizeof(read_buf)) ==  sizeof(read_buf));
    BTASSERTM(&read_buf[0], &write_buf[0], sizeof(write_buf));

    /* Write various sizes at various alignments. */
    for (i = 0; i < membersof(write_buf); i++) {
        write_buf[i] = (membersof(write_buf) - i);
    }

    BTASSERT(eeprom_i2c_write(&eeprom_i2c,   0,  &write_buf[0],   1) ==  1);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,   1,  &write_buf[1],   2) ==  2);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,   3,  &write_buf[3],   3) ==  3);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,   6,  &write_buf[6],   4) ==  4);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,  10, &write_buf[10],   5) ==  5);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,  15, &write_buf[15],   6) ==  6);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,  21, &write_buf[21],   7) ==  7);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,  28, &write_buf[28],   8) ==  8);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,  36, &write_buf[36],   9) ==  9);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,  45, &write_buf[45],  10) == 10);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,  55, &write_buf[55],  11) == 11);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,  66, &write_buf[66],  12) == 12);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,  78, &write_buf[78],  13) == 13);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c,  91, &write_buf[91],  14) == 14);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c, 105, &write_buf[105], 15) == 15);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c, 120, &write_buf[120], 16) == 16);
    BTASSERT(eeprom_i2c_write(&eeprom_i2c, 136, &write_buf[136], 17) == 17);

    /* Read and verify the written data. */
    memset(&read_buf[0], -1, sizeof(read_buf));

    BTASSERT(eeprom_i2c_read(&eeprom_i2c,  &read_buf[0],    0,  1) ==  1);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c,  &read_buf[1],    1,  2) ==  2);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c,  &read_buf[3],    3,  3) ==  3);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c,  &read_buf[6],    6,  4) ==  4);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c, &read_buf[10],   10,  5) ==  5);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c, &read_buf[15],   15,  6) ==  6);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c, &read_buf[21],   21,  7) ==  7);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c, &read_buf[28],   28,  8) ==  8);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c, &read_buf[36],   36,  9) ==  9);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c, &read_buf[45],   45, 10) == 10);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c, &read_buf[55],   55, 11) == 11);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c, &read_buf[66],   66, 12) == 12);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c, &read_buf[78],   78, 13) == 13);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c, &read_buf[91],   91, 14) == 14);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c, &read_buf[105], 105, 15) == 15);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c, &read_buf[120], 120, 16) == 16);
    BTASSERT(eeprom_i2c_read(&eeprom_i2c, &read_buf[136], 136, 17) == 17);

    /* Verify that read and written data match. */
    BTASSERTM(&read_buf[0], &write_buf[0], sizeof(write_buf));

    return (0);
}
示例#24
0
文件: esp_wifi.c 项目: wuwx/simba
void esp_wifi_print(void *chout_p)
{
    ASSERTNRV(chout_p != NULL, EINVAL);

    int i;
    int number_of_infos;
    int number_of_connections;
    struct esp_wifi_softap_station_info_t info[4];
    struct inet_if_ip_info_t ip_info;
    char buf[16];
    char *op_mode_p;
    char *phy_mode_p;
    const char *connection_status_p;
    char *dhcp_status_p;

    /* Get the operating mode. */
    switch (esp_wifi_get_op_mode()) {

    case esp_wifi_op_mode_null_t:
        op_mode_p = "NULL";
        break;

    case esp_wifi_op_mode_station_t:
        op_mode_p = "STA";
        break;

    case esp_wifi_op_mode_softap_t:
        op_mode_p = "AP";
        break;

    case esp_wifi_op_mode_station_softap_t:
        op_mode_p = "STA-AP";
        break;

    default:
        op_mode_p = "INVALID";
        break;
    }

    /* Get the physical mode. */
    switch (esp_wifi_get_phy_mode()) {

    case esp_wifi_phy_mode_11b_t:
        phy_mode_p = "b";
        break;

    case esp_wifi_phy_mode_11g_t:
        phy_mode_p = "g";
        break;

    case esp_wifi_phy_mode_11n_t:
        phy_mode_p = "n";
        break;

    default:
        phy_mode_p = "invalid";
        break;
    }

    /* Get the DHCP server status. */
    switch (esp_wifi_softap_dhcp_server_status()) {

    case esp_wifi_dhcp_status_running_t:
        dhcp_status_p = "running";
        break;

    case esp_wifi_dhcp_status_stopped_t:
        dhcp_status_p = "stopped";
        break;

    default:
        dhcp_status_p = "invalid";
        break;
    }

    std_fprintf(chout_p,
                FSTR("General information:\r\n"
                     "  Operating mode: %s\r\n"
                     "  Physical mode: 11%s\r\n"
                     "\r\n"),
                op_mode_p,
                phy_mode_p);

    memset(&ip_info, 0, sizeof(ip_info));
    esp_wifi_softap_get_ip_info(&ip_info);
    number_of_connections = esp_wifi_softap_get_number_of_connected_stations();
    number_of_infos = esp_wifi_softap_get_station_info(info,
                                                       membersof(info));

    std_fprintf(chout_p,
                FSTR("SoftAP:\r\n"
                     "  DHCP server status: %s\r\n"
                     "  Address: %s\r\n"),
                dhcp_status_p,
                inet_ntoa(&ip_info.address, &buf[0]));

    std_fprintf(chout_p,
                FSTR("  Netmask: %s\r\n"),
                inet_ntoa(&ip_info.netmask, &buf[0]));

    std_fprintf(chout_p,
                FSTR("  Gateway: %s\r\n"
                     "  Number of connections: %d\r\n"),
                inet_ntoa(&ip_info.gateway, &buf[0]),
                number_of_connections);

    for (i = 0; i < number_of_infos; i++) {
        std_fprintf(chout_p,
                    FSTR("    [%d]: BSSID: %02x:%02x:%02x:%02x:%02x:%02x,"
                         " IP: %s\r\n"),
                    i,
                    (int)info[i].bssid[0],
                    (int)info[i].bssid[1],
                    (int)info[i].bssid[2],
                    (int)info[i].bssid[3],
                    (int)info[i].bssid[4],
                    (int)info[i].bssid[5],
                    inet_ntoa(&info[i].ip_address, &buf[0]));
    }

    /* Get the station connection status. */
    connection_status_p =
        esp_wifi_station_status_as_string(esp_wifi_station_get_status());

    /* Get the DHCP client status. */
    switch (esp_wifi_station_dhcp_client_status()) {

    case esp_wifi_dhcp_status_running_t:
        dhcp_status_p = "running";
        break;

    case esp_wifi_dhcp_status_stopped_t:
        dhcp_status_p = "stopped";
        break;

    default:
        dhcp_status_p = "invalid";
        break;
    }

    memset(&ip_info, 0, sizeof(ip_info));
    esp_wifi_station_get_ip_info(&ip_info);

    std_fprintf(chout_p,
                FSTR("\r\n"
                     "Station:\r\n"
                     "  DHCP client status: %s\r\n"
                     "  Conenction status: %s\r\n"
                     "  Address: %s\r\n"),
                dhcp_status_p,
                connection_status_p,
                inet_ntoa(&ip_info.address, &buf[0]));

    std_fprintf(chout_p,
                FSTR("  Netmask: %s\r\n"),
                inet_ntoa(&ip_info.netmask, &buf[0]));

    std_fprintf(chout_p,
                FSTR("  Gateway: %s\r\n"
                     "\r\n"),
                inet_ntoa(&ip_info.gateway, &buf[0]));
}