Exemple #1
0
int test_exti(struct harness_t *harness_p)
{
    int i;
    struct exti_driver_t exti;
    struct pin_driver_t pin;

    pin_init(&pin, &pin_d4_dev, PIN_OUTPUT);
    pin_write(&pin, 1);
    
    BTASSERT(exti_init(&exti,
                       &exti_d3_dev,
                       EXTI_TRIGGER_FALLING_EDGE,
                       isr,
                       NULL) == 0);
    BTASSERT(exti_start(&exti) == 0);

    for (i = 0; i < 10; i++) {
        pin_write(&pin, 0);
        time_busy_wait_us(10000);
        pin_write(&pin, 1);
        time_busy_wait_us(10000);
    }

    std_printf(FSTR("flag = %d\r\n"), (int)flag);
    BTASSERT(flag == 10);

    return (0);
}
Exemple #2
0
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);
}
Exemple #3
0
static ssize_t uart_soft_write_cb(void *arg_p,
                                  const void *txbuf_p,
                                  size_t size)
{
    int i, j;
    uint8_t data;
    struct uart_soft_driver_t *self_p;
    const uint8_t *tx_p = txbuf_p;

    self_p = container_of(arg_p, struct uart_soft_driver_t, chout);

    for (i = 0; i < size; i++) {
        sys_lock();
        pin_write(&self_p->tx_pin, 0);

        /* Put 8 bits on the transmission wire. */
        data = tx_p[i];

        for (j = 0; j < 8; j++) {
            time_busy_wait_us(self_p->sample_time);
            pin_write(&self_p->tx_pin, data & 1);
            data >>= 1;
        }

        time_busy_wait_us(self_p->sample_time);
        pin_write(&self_p->tx_pin, 1);
        time_busy_wait_us(self_p->sample_time);
        sys_unlock();
    }

    return (size);
}
Exemple #4
0
/**
 * The interrupt service routine is called on falling edges. Read a
 * byte and write it on the receive channel.
 */
static void rx_isr(void *arg_p)
{
    int i;
    uint8_t data = 0, sample;
    struct uart_soft_driver_t *self_p = arg_p;

    /* Wait half the sample time so following samples are taken in the
       middle of the sample period.*/
    time_busy_wait_us(self_p->sample_time / 3);

    /* Get 8 bits. */
    for (i = 0; i < 8; i++) {
        time_busy_wait_us(self_p->sample_time);

        /* Sample the pin. */
        data >>= 1;
        sample = pin_read(&self_p->rx_pin);
        data |= (0x80 * sample);
    }

    /* Write data to input channel. */
    queue_write_isr(&self_p->chin, &data, sizeof(data));

    /* During the execution of this routinue multiple falling edges
       are detected by the hardware. The interrupt flag will be set
       and should be cleared to inhibit that the routine is executed
       twise per 8 bits.*/
    exti_clear(&self_p->rx_exti);
}
Exemple #5
0
int test_falling(struct harness_t *harness_p)
{
    int i;
    struct pcint_driver_t pcint;

    pin_write(&pin, 1);
    count = 0;

    BTASSERT(pcint_init(&pcint,
                        &pcint_a9_dev,
                        PCINT_TRIGGER_FALLING_EDGE,
                        isr,
                        NULL) == 0);
    BTASSERT(pcint_start(&pcint) == 0);

    /* 10 falling, 9 rising edges. */
    for (i = 0; i < 10; i++) {
        pin_write(&pin, 1);
        time_busy_wait_us(10000);
        pin_write(&pin, 0);
        time_busy_wait_us(10000);
    }

    BTASSERT(pcint_stop(&pcint) == 0);

    /* The interrupt is disabled, no increment. */
    pin_write(&pin, 1);
    time_busy_wait_us(10000);
    pin_write(&pin, 0);
    time_busy_wait_us(10000);

    std_printf(FSTR("count: %d\r\n"), count);
    BTASSERT(count == 10);

    return (0);
}
Exemple #6
0
/**
 * USB device driver setup callback.
 */
static int setup_isr(struct usb_device_driver_base_t *base_p,
                     struct usb_setup_t *setup_p)
{
    int res = 0;
    uint8_t direction;
    uint8_t type;
    struct usb_device_class_cdc_driver_t *self_p;

    self_p = (struct usb_device_class_cdc_driver_t *)base_p;

    type = (setup_p->request_type & REQUEST_TYPE_RECIPIENT_MASK);

    if (type != REQUEST_TYPE_RECIPIENT_INTERFACE) {
        return (1);
    }

    /* Is the addressed interface owned by this driver? */
    if (self_p->control_interface != setup_p->u.base.index) {
        return (1);
    }

    time_busy_wait_us(50);

    direction = (setup_p->request_type & REQUEST_TYPE_DATA_MASK);

    switch (direction) {

    case REQUEST_TYPE_DATA_DIRECTION_DEVICE_TO_HOST:
        switch (setup_p->request) {

        case USB_CDC_LINE_CODING:
            usb_device_write_isr(NULL,
                                 0,
                                 &self_p->line_info,
                                 sizeof(self_p->line_info));
            res = 0;
            break;

        default:
            res = -1;
            break;
        }

        break;

    case REQUEST_TYPE_DATA_DIRECTION_HOST_TO_DEVICE:
        switch (setup_p->request) {

        case USB_CDC_LINE_CODING:
            usb_device_read_isr(NULL,
                                0,
                                &self_p->line_info,
                                sizeof(self_p->line_info));
            check_reset_to_bootloader(self_p);
            res = 0;
            break;

        case USB_CDC_CONTROL_LINE_STATE:
            self_p->line_state = setup_p->u.base.value;
            check_reset_to_bootloader(self_p);
            res = 0;
            break;

        case USB_CDC_SEND_BREAK:
            /* Lost serial connection; mark line state as gone. */
            self_p->line_state = 0;
            res = 0;
            break;

        default:
            res = -1;
            break;
        }

        break;

    default:
        res = -1;
        break;
    }

    return (res);
}