Changeset 923a033 in rtems for bsps


Ignore:
Timestamp:
Mar 6, 2019, 10:48:00 AM (8 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
847638a
Parents:
b934898
git-author:
Sebastian Huber <sebastian.huber@…> (03/06/19 10:48:00)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/06/19 12:07:16)
Message:

bsp/atsam: Change CS delay after transfer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bsps/arm/atsam/spi/atsam_spi_bus.c

    rb934898 r923a033  
    7272  bool chip_select_decode;
    7373  uint8_t spi_id;
     74  uint32_t peripheral_clk_per_us;
     75  uint32_t spi_mr;
    7476  uint32_t spi_csr[4];
    7577} atsam_spi_bus;
     
    8082}
    8183
    82 static uint8_t atsam_calculate_dlybcs(uint16_t delay_in_us)
    83 {
    84   return (
    85     (BOARD_MCK / delay_in_us) < 0xFF) ?
    86     (BOARD_MCK / delay_in_us) : 0xFF;
     84static uint8_t atsam_calculate_dlybcs(const atsam_spi_bus *bus)
     85{
     86  uint32_t dlybcs = bus->base.delay_usecs * bus->peripheral_clk_per_us;
     87
     88  if (dlybcs > 0xff) {
     89    dlybcs = 0xff;
     90  }
     91
     92  return dlybcs;
    8793}
    8894
     
    127133static void atsam_configure_spi(atsam_spi_bus *bus)
    128134{
    129   uint8_t delay_cs;
    130135  uint32_t scbr;
    131136  uint32_t csr = 0;
    132   uint32_t mode = 0;
     137  uint32_t mr;
    133138  uint32_t cs = bus->base.cs;
    134139
    135   delay_cs = atsam_calculate_dlybcs(bus->base.delay_usecs);
    136140  scbr = atsam_calculate_scbr(bus->base.speed_hz);
    137141
    138   mode |= SPI_MR_DLYBCS(delay_cs);
    139   mode |= SPI_MR_MSTR;
    140   mode |= SPI_MR_MODFDIS;
     142  mr = bus->spi_mr;
     143
    141144  if (bus->chip_select_decode) {
    142     mode |= SPI_MR_PCS(bus->base.cs);
    143     mode |= SPI_MR_PCSDEC;
     145    mr |= SPI_MR_PCS(bus->base.cs);
     146    mr |= SPI_MR_PCSDEC;
    144147    cs /= 4;
    145148  } else {
    146     mode |= SPI_PCS(bus->base.cs);
    147   }
    148 
    149   bus->spi_regs->SPI_MR = mode;
     149    mr |= SPI_PCS(bus->base.cs);
     150  }
     151
     152  bus->spi_regs->SPI_MR = mr;
    150153
    151154  csr = bus->spi_csr[cs]
     
    346349      || msg->bits_per_word != bus->base.bits_per_word
    347350      || msg->cs != bus->base.cs
    348       || msg->delay_usecs != bus->base.delay_usecs
    349351  ) {
    350352    if (
     
    361363    bus->base.bits_per_word = msg->bits_per_word;
    362364    bus->base.cs = msg->cs;
    363     bus->base.delay_usecs = msg->delay_usecs;
    364365    atsam_configure_spi(bus);
    365366  }
     
    408409
    409410  if (bus->transfer_in_progress == 0) {
     411    const spi_ioc_transfer *msg = bus->msg_current;
     412
     413    if (msg->delay_usecs != bus->base.delay_usecs) {
     414      uint32_t mr;
     415      uint32_t mr_dlybcs;
     416
     417      bus->base.delay_usecs = msg->delay_usecs;
     418      mr_dlybcs = SPI_MR_DLYBCS(atsam_calculate_dlybcs(bus));
     419      bus->spi_mr = mr_dlybcs | SPI_MR_MSTR | SPI_MR_MODFDIS;
     420
     421      mr = bus->spi_regs->SPI_MR;
     422      mr &= ~SPI_MR_DLYBCS_Msk;
     423      mr |= mr_dlybcs;
     424      bus->spi_regs->SPI_MR = mr;
     425    }
     426
    410427    atsam_spi_copy_back_rx_after_dma_transfer(bus);
    411428    atsam_spi_setup_transfer(bus);
     
    618635  bus->base.bits_per_word = 8;
    619636  bus->base.speed_hz = bus->base.max_speed_hz;
    620   bus->base.delay_usecs = 1;
    621637  bus->base.cs = 1;
    622638  bus->spi_id = config->spi_peripheral_id;
    623639  bus->spi_regs = config->spi_regs;
    624640  bus->chip_select_decode = config->chip_select_decode;
     641  bus->peripheral_clk_per_us = BOARD_MCK / 1000000;
     642  bus->spi_mr = SPI_MR_MSTR | SPI_MR_MODFDIS;
    625643
    626644  for (i = 0; i < RTEMS_ARRAY_SIZE(bus->spi_csr); ++i) {
Note: See TracChangeset for help on using the changeset viewer.