Changeset 02926290 in rtems


Ignore:
Timestamp:
Mar 6, 2019, 8:38:12 AM (6 weeks ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
b934898
Parents:
7604a130
git-author:
Sebastian Huber <sebastian.huber@…> (03/06/19 08:38:12)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/06/19 12:07:16)
Message:

bsp/atsam: Simplify SPI configuration

Do not use SPID_Configure() since this will enable the peripheral each
time and performs a software reset.

File:
1 edited

Legend:

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

    r7604a130 r02926290  
    6262  uint32_t msg_todo;
    6363  int msg_error;
    64   Spid spi;
     64  Spi *spi_regs;
    6565  uint32_t dma_tx_channel;
    6666  uint32_t dma_rx_channel;
     
    7171  bool chip_select_active;
    7272  bool chip_select_decode;
     73  uint8_t spi_id;
     74  uint32_t spi_csr[4];
    7375} atsam_spi_bus;
    7476
     
    145147  }
    146148
    147   SPID_Configure(
    148     &bus->spi,
    149     bus->spi.pSpiHw,
    150     bus->spi.spiId,
    151     mode,
    152     &XDMAD_Instance
    153   );
     149  bus->spi_regs->SPI_MR = mode;
    154150
    155151  csr =
     
    161157  atsam_set_phase_and_polarity(bus->base.mode, &csr);
    162158
    163   SPI_ConfigureNPCS(bus->spi.pSpiHw, cs, csr);
     159  SPI_ConfigureNPCS(bus->spi_regs, cs, csr);
     160}
     161
     162static void atsam_reset_spi(atsam_spi_bus *bus)
     163{
     164  bus->spi_regs->SPI_CR = SPI_CR_SPIDIS;
     165  bus->spi_regs->SPI_CR = SPI_CR_SWRST;
     166  bus->spi_regs->SPI_CR = SPI_CR_SWRST;
     167  bus->spi_regs->SPI_CR = SPI_CR_SPIEN;
    164168}
    165169
     
    322326{
    323327  if (!bus->chip_select_active){
    324     Spi *pSpiHw = bus->spi.pSpiHw;
     328    Spi *spi_regs = bus->spi_regs;
    325329
    326330    bus->chip_select_active = true;
    327331
    328332    if (bus->chip_select_decode) {
    329       pSpiHw->SPI_MR = (pSpiHw->SPI_MR & ~SPI_MR_PCS_Msk) | SPI_MR_PCS(msg->cs);
     333      spi_regs->SPI_MR = (spi_regs->SPI_MR & ~SPI_MR_PCS_Msk) | SPI_MR_PCS(msg->cs);
    330334    } else {
    331       SPI_ChipSelect(pSpiHw, 1 << msg->cs);
     335      SPI_ChipSelect(spi_regs, 1 << msg->cs);
    332336    }
    333     SPI_Enable(pSpiHw);
     337    SPI_Enable(spi_regs);
    334338  }
    335339
     
    374378  if (bus->msg_cs_change) {
    375379    bus->chip_select_active = false;
    376     SPI_ReleaseCS(bus->spi.pSpiHw);
    377     SPI_Disable(bus->spi.pSpiHw);
     380    SPI_ReleaseCS(bus->spi_regs);
     381    SPI_Disable(bus->spi_regs);
    378382  }
    379383
     
    436440
    437441  rc = XDMAD_SetCallback(
    438     bus->spi.pXdmad,
     442    &XDMAD_Instance,
    439443    bus->dma_rx_channel,
    440444    XDMAD_DoNothingCallback,
     
    444448
    445449  rc = XDMAD_SetCallback(
    446     bus->spi.pXdmad,
     450    &XDMAD_Instance,
    447451    bus->dma_tx_channel,
    448452    XDMAD_DoNothingCallback,
     
    451455  assert(rc == XDMAD_OK);
    452456
    453   XDMAD_FreeChannel(bus->spi.pXdmad, bus->dma_rx_channel);
    454   XDMAD_FreeChannel(bus->spi.pXdmad, bus->dma_tx_channel);
    455 
    456   SPI_Disable(bus->spi.pSpiHw);
    457   PMC_DisablePeripheral(bus->spi.spiId);
     457  XDMAD_FreeChannel(&XDMAD_Instance, bus->dma_rx_channel);
     458  XDMAD_FreeChannel(&XDMAD_Instance, bus->dma_tx_channel);
     459
     460  SPI_Disable(bus->spi_regs);
     461  PMC_DisablePeripheral(bus->spi_id);
    458462
    459463  rtems_cache_coherent_free(bus->dma_bufs);
     
    494498
    495499  bus->dma_tx_channel = XDMAD_AllocateChannel(
    496     bus->spi.pXdmad,
     500    &XDMAD_Instance,
    497501    XDMAD_TRANSFER_MEMORY,
    498     bus->spi.spiId
     502    bus->spi_id
    499503  );
    500504  assert(bus->dma_tx_channel != XDMAD_ALLOC_FAILED);
    501505
    502506  bus->dma_rx_channel = XDMAD_AllocateChannel(
    503     bus->spi.pXdmad,
    504     bus->spi.spiId,
     507    &XDMAD_Instance,
     508    bus->spi_id,
    505509    XDMAD_TRANSFER_MEMORY
    506510  );
     
    508512
    509513  rc = XDMAD_SetCallback(
    510     bus->spi.pXdmad,
     514    &XDMAD_Instance,
    511515    bus->dma_rx_channel,
    512516    atsam_spi_dma_callback,
     
    516520
    517521  rc = XDMAD_SetCallback(
    518     bus->spi.pXdmad,
     522    &XDMAD_Instance,
    519523    bus->dma_tx_channel,
    520524    atsam_spi_dma_callback,
     
    523527  assert(rc == XDMAD_OK);
    524528
    525   rc = XDMAD_PrepareChannel(bus->spi.pXdmad, bus->dma_rx_channel);
    526   assert(rc == XDMAD_OK);
    527 
    528   rc = XDMAD_PrepareChannel(bus->spi.pXdmad, bus->dma_tx_channel);
     529  rc = XDMAD_PrepareChannel(&XDMAD_Instance, bus->dma_rx_channel);
     530  assert(rc == XDMAD_OK);
     531
     532  rc = XDMAD_PrepareChannel(&XDMAD_Instance, bus->dma_tx_channel);
    529533  assert(rc == XDMAD_OK);
    530534
     
    540544  /* Setup RX */
    541545  memset(&cfg, 0, sizeof(cfg));
    542   channel = XDMAIF_Get_ChannelNumber(bus->spi.spiId, XDMAD_TRANSFER_RX);
    543   cfg.mbr_sa = (uint32_t)&bus->spi.pSpiHw->SPI_RDR;
     546  channel = XDMAIF_Get_ChannelNumber(bus->spi_id, XDMAD_TRANSFER_RX);
     547  cfg.mbr_sa = (uint32_t)&bus->spi_regs->SPI_RDR;
    544548  cfg.mbr_cfg =
    545549    XDMAC_CC_TYPE_PER_TRAN |
     
    558562    XDMAC_CNDC_NDSUP_SRC_PARAMS_UNCHANGED;
    559563  rc = XDMAD_ConfigureTransfer(
    560     bus->spi.pXdmad,
     564    &XDMAD_Instance,
    561565    bus->dma_rx_channel,
    562566    &cfg,
     
    569573  /* Setup TX  */
    570574  memset(&cfg, 0, sizeof(cfg));
    571   channel = XDMAIF_Get_ChannelNumber(bus->spi.spiId, XDMAD_TRANSFER_TX);
    572   cfg.mbr_da = (uint32_t)&bus->spi.pSpiHw->SPI_TDR;
     575  channel = XDMAIF_Get_ChannelNumber(bus->spi_id, XDMAD_TRANSFER_TX);
     576  cfg.mbr_da = (uint32_t)&bus->spi_regs->SPI_TDR;
    573577  cfg.mbr_cfg =
    574578    XDMAC_CC_TYPE_PER_TRAN |
     
    587591    XDMAC_CNDC_NDSUP_SRC_PARAMS_UPDATED;
    588592  rc = XDMAD_ConfigureTransfer(
    589     bus->spi.pXdmad,
     593    &XDMAD_Instance,
    590594    bus->dma_tx_channel,
    591595    &cfg,
     
    617621  bus->base.delay_usecs = 1;
    618622  bus->base.cs = 1;
    619   bus->spi.spiId = config->spi_peripheral_id;
    620   bus->spi.pSpiHw = config->spi_regs;
     623  bus->spi_id = config->spi_peripheral_id;
     624  bus->spi_regs = config->spi_regs;
    621625  bus->chip_select_decode = config->chip_select_decode;
    622626
     
    624628  PIO_Configure(config->pins, config->pin_count);
    625629  PMC_EnablePeripheral(config->spi_peripheral_id);
     630  atsam_reset_spi(bus);
    626631  atsam_configure_spi(bus);
    627632  atsam_spi_init_xdma(bus);
Note: See TracChangeset for help on using the changeset viewer.