Changeset 5cb23f4b in rtems


Ignore:
Timestamp:
Oct 1, 2018, 6:59:14 AM (11 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
0614743
Parents:
fca9132
git-author:
Sebastian Huber <sebastian.huber@…> (10/01/18 06:59:14)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/01/18 07:01:29)
Message:

bsp/atsam: Use binary semaphore for I2C

Remove superfluous sleep before each I2C transfer. Reset I2C module
after transfer timeouts.

Update #3534.

Location:
bsps/arm/atsam
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bsps/arm/atsam/i2c/atsam_i2c_bus.c

    rfca9132 r5cb23f4b  
    268268                atsam_i2c_next_packet(bus);
    269269                if (bus->msg_todo == 0 || err != 0) {
    270                         rtems_status_code sc;
    271 
    272270                        atsam_i2c_disable_interrupts(regs);
    273                         sc = rtems_event_transient_send(bus->task_id);
    274                         assert(sc == RTEMS_SUCCESSFUL);
     271                        rtems_binary_semaphore_post(&bus->sem);
    275272                } else {
    276273                        atsam_i2c_setup_transfer(bus, regs);
     
    282279atsam_i2c_transfer(i2c_bus *base, i2c_msg *msgs, uint32_t msg_count)
    283280{
    284         rtems_status_code sc;
    285281        atsam_i2c_bus *bus = (atsam_i2c_bus *)base;
    286282        Twihs *regs;
    287283        uint32_t i;
    288 
    289         rtems_task_wake_after(1);
     284        int eno;
    290285
    291286        if (msg_count < 1){
    292                 return 1;
     287                return 0;
    293288        }
    294289
     
    303298        bus->current_msg_todo = msgs[0].len;
    304299        bus->current_msg_byte = msgs[0].buf;
    305         bus->task_id = rtems_task_self();
    306300
    307301        regs = bus->regs;
     
    311305        regs->TWIHS_IER = ATSAMV_I2C_IRQ_ERROR;
    312306
    313         sc = rtems_event_transient_receive(RTEMS_WAIT, bus->base.timeout);
    314         if (sc != RTEMS_SUCCESSFUL){
    315                 rtems_event_transient_clear();
     307        eno = rtems_binary_semaphore_wait_timed_ticks(
     308                &bus->sem,
     309                bus->base.timeout
     310        );
     311        if (eno != 0) {
     312                TWI_ConfigureMaster(bus->regs, bus->output_clock, BOARD_MCK);
     313                rtems_binary_semaphore_try_wait(&bus->sem);
    316314                return -ETIMEDOUT;
    317315        }
     
    324322{
    325323        atsam_i2c_bus *bus = (atsam_i2c_bus *)base;
    326         Twihs *regs = bus->regs;
    327         TWI_ConfigureMaster(regs, clock, BOARD_MCK);
     324        bus->output_clock = clock;
     325        TWI_ConfigureMaster(bus->regs, clock, BOARD_MCK);
    328326        return 0;
    329327}
     
    342340
    343341static void
    344 atsam_i2c_init(atsam_i2c_bus *bus, uint32_t input_clock, Twihs *board_base,
    345     uint32_t board_id, const Pin *pins)
     342atsam_i2c_init(atsam_i2c_bus *bus, uint32_t board_id, const Pin *pins)
    346343{
    347344
     
    352349        ENABLE_PERIPHERAL(board_id);
    353350
    354         TWI_ConfigureMaster(board_base, input_clock, BOARD_MCK);
     351        TWI_ConfigureMaster(bus->regs, bus->output_clock, BOARD_MCK);
    355352}
    356353
     
    365362        atsam_i2c_bus *bus;
    366363        rtems_status_code sc;
    367         uint32_t board_id = (uint32_t) irq;
    368364
    369365        bus = (atsam_i2c_bus *) i2c_bus_alloc_and_init(sizeof(*bus));
     
    372368        }
    373369
     370        rtems_binary_semaphore_init(&bus->sem, "ATSAM I2C");
    374371        bus->regs = register_base;
    375372        bus->irq = irq;
    376 
    377         atsam_i2c_init(bus, I2C_BUS_CLOCK_DEFAULT, bus->regs,
    378             board_id, pins);
     373        bus->output_clock = I2C_BUS_CLOCK_DEFAULT;
     374
     375        atsam_i2c_init(bus, irq, pins);
    379376
    380377        sc = rtems_interrupt_handler_install(
    381378            irq,
    382             "Atsamv_I2C",
     379            "ATSAM I2C",
    383380            RTEMS_INTERRUPT_UNIQUE,
    384381            atsam_i2c_interrupt,
  • bsps/arm/atsam/include/bsp/atsam-i2c.h

    rfca9132 r5cb23f4b  
    2020
    2121#include <bsp.h>
     22#include <rtems/thread.h>
    2223#include <dev/i2c/i2c.h>
    2324
     
    5556        uint32_t current_msg_todo;
    5657        uint8_t *current_msg_byte;
    57         uint32_t input_clock;
     58        uint32_t output_clock;
    5859        bool read;
    59         rtems_id task_id;
     60        rtems_binary_semaphore sem;
    6061        rtems_vector_number irq;
    6162} atsam_i2c_bus;
Note: See TracChangeset for help on using the changeset viewer.