Changeset 8eb5fbb6 in rtems


Ignore:
Timestamp:
Dec 15, 2016, 12:27:17 PM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
a4936b5
Parents:
d1c771c
git-author:
Sebastian Huber <sebastian.huber@…> (12/15/16 12:27:17)
git-committer:
Sebastian Huber <sebastian.huber@…> (12/16/16 08:04:57)
Message:

bsp/atsamv: Move XDMAD instance out of SPI driver

Use system initialization for XDMAD. Remove support for polling.

Location:
c/src/lib/libbsp/arm/atsam
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/atsam/libraries/libchip/include/xdmad.h

    rd1c771c r8eb5fbb6  
    130130        uint8_t  numControllers;
    131131        uint8_t  numChannels;
    132         uint8_t  pollingMode;
    133         uint8_t  pollingTimeout;
    134132        uint8_t  xdmaMutex;
    135133} sXdmad;
     
    218216/**     @}*/
    219217
     218extern sXdmad XDMAD_Instance;
     219
    220220/*----------------------------------------------------------------------------
    221221 *        Exported functions
  • c/src/lib/libbsp/arm/atsam/libraries/libchip/source/xdmad.c

    rd1c771c r8eb5fbb6  
    6666#include "../../../utils/utility.h"
    6767#include <rtems/irq-extension.h>
     68#include <rtems/sysinit.h>
    6869#include <bsp/fatal.h>
    6970#endif /* __rtems__ */
    7071#include <assert.h>
    71 static uint8_t xDmad_Initialized = 0;
    7272
    7373/*----------------------------------------------------------------------------
     
    141141 *----------------------------------------------------------------------------*/
    142142
    143 /**
    144  * \brief Initialize xDMA driver instance.
    145  * \param pXdmad Pointer to xDMA driver instance.
    146  * \param bPollingMode Polling DMA transfer:
    147  *                     1. Via XDMAD_IsTransferDone(); or
    148  *                     2. Via XDMAD_Handler().
    149  */
    150 void XDMAD_Initialize(sXdmad *pXdmad, uint8_t bPollingMode)
    151 {
     143sXdmad XDMAD_Instance;
     144
     145static void XDMAD_SysInitialize(void)
     146{
     147        sXdmad *pXdmad;
    152148        uint32_t j;
    153         uint32_t volatile timer = 0x7FF;
    154149        rtems_status_code sc;
    155150
    156         assert(pXdmad);
    157         LockMutex(pXdmad->xdmaMutex, timer);
    158 
    159         if (xDmad_Initialized) {
    160                 ReleaseMutex(pXdmad->xdmaMutex);
    161                 return;
    162         }
     151        pXdmad = &XDMAD_Instance;
    163152
    164153        pXdmad->pXdmacs = XDMAC;
    165         pXdmad->pollingMode = bPollingMode;
    166154        pXdmad->numControllers = XDMAC_CONTROLLER_NUM;
    167155        pXdmad->numChannels    = (XDMAC_GTYPE_NB_CH(XDMAC_GetType(XDMAC)) + 1);
     
    181169                bsp_fatal(ATSAM_FATAL_XDMA_IRQ_INSTALL);
    182170        }
    183 
    184         xDmad_Initialized = 1;
    185         ReleaseMutex(pXdmad->xdmaMutex);
    186 }
     171}
     172
     173RTEMS_SYSINIT_ITEM(XDMAD_SysInitialize, RTEMS_SYSINIT_BSP_START,
     174    RTEMS_SYSINIT_ORDER_LAST);
    187175
    188176
     
    382370                        pCh->fCallback(_iChannel, pCh->pArg);
    383371        }
    384 }
    385 
    386 /**
    387  * \brief Check if DMA transfer is finished.
    388  *        In polling mode XDMAD_Handler() is polled.
    389  * \param pDmad     Pointer to DMA driver instance.
    390  * \param dwChannel ControllerNumber << 8 | ChannelNumber.
    391  */
    392 eXdmadRC XDMAD_IsTransferDone(sXdmad *pXdmad, uint32_t dwChannel)
    393 {
    394         uint8_t iChannel = (dwChannel) & 0xFF;
    395         uint8_t state;
    396         assert(pXdmad != NULL);
    397 
    398         if (iChannel >= pXdmad->numChannels)
    399                 return XDMAD_ERROR;
    400 
    401         state = pXdmad->XdmaChannels[iChannel].state;
    402 
    403         if (state == XDMAD_STATE_ALLOCATED) return XDMAD_OK;
    404 
    405         if (state == XDMAD_STATE_FREE) return XDMAD_ERROR;
    406         else if (state != XDMAD_STATE_DONE) {
    407                 if (pXdmad->pollingMode)  XDMAD_Handler(pXdmad);
    408 
    409                 return XDMAD_BUSY;
    410         }
    411 
    412         return XDMAD_OK;
    413372}
    414373
     
    501460        pXdmad->XdmaChannels[iChannel].state = XDMAD_STATE_START;
    502461        XDMAC_EnableChannel(pXdmac, iChannel);
    503 
    504         if (pXdmad->pollingMode == 0)
    505                 XDMAC_EnableGIt(pXdmac, iChannel);
     462        XDMAC_EnableGIt(pXdmac, iChannel);
    506463
    507464        return XDMAD_OK;
  • c/src/lib/libbsp/arm/atsam/spi/atsam_spi_bus.c

    rd1c771c r8eb5fbb6  
    4242  int msg_error;
    4343  rtems_id msg_task;
    44   sXdmad xdma;
    45   Spid SpiDma;
     44  Spid spi;
    4645  uint32_t dma_tx_channel;
    4746  uint32_t dma_rx_channel;
     
    9493
    9594  SPID_Configure(
    96     &bus->SpiDma,
    97     bus->SpiDma.pSpiHw,
    98     bus->SpiDma.spiId,
     95    &bus->spi,
     96    bus->spi.pSpiHw,
     97    bus->spi.spiId,
    9998    (SPI_MR_DLYBCS(delay_cs) |
    10099      SPI_MR_MSTR |
    101100      SPI_MR_MODFDIS |
    102101      SPI_PCS(bus->base.cs)),
    103     &bus->xdma
     102    &XDMAD_Instance
    104103  );
    105104
     
    112111  atsam_set_phase_and_polarity(bus->base.mode, &csr);
    113112
    114   SPI_ConfigureNPCS(bus->SpiDma.pSpiHw, bus->base.cs, csr);
     113  SPI_ConfigureNPCS(bus->spi.pSpiHw, bus->base.cs, csr);
    115114}
    116115
     
    120119)
    121120{
    122   Xdmac *pXdmac = bus->xdma.pXdmacs;
     121  Xdmac *pXdmac = XDMAC;
    123122
    124123  XDMAC_SetDestinationAddr(pXdmac, bus->dma_rx_channel, (uint32_t)msg->rx_buf);
     
    136135{
    137136  if (!bus->chip_select_active){
    138     Spi *pSpiHw = bus->SpiDma.pSpiHw;
     137    Spi *pSpiHw = bus->spi.pSpiHw;
    139138
    140139    bus->chip_select_active = true;
     
    184183  if (bus->msg_cs_change) {
    185184    bus->chip_select_active = false;
    186     SPI_ReleaseCS(bus->SpiDma.pSpiHw);
    187     SPI_Disable(bus->SpiDma.pSpiHw);
     185    SPI_ReleaseCS(bus->spi.pSpiHw);
     186    SPI_Disable(bus->spi.pSpiHw);
    188187  }
    189188
     
    244243
    245244  rc = XDMAD_SetCallback(
    246     &bus->xdma,
     245    bus->spi.pXdmad,
    247246    bus->dma_rx_channel,
    248247    XDMAD_DoNothingCallback,
     
    252251
    253252  rc = XDMAD_SetCallback(
    254     &bus->xdma,
     253    bus->spi.pXdmad,
    255254    bus->dma_tx_channel,
    256255    XDMAD_DoNothingCallback,
     
    259258  assert(rc == XDMAD_OK);
    260259
    261   XDMAD_FreeChannel(bus->SpiDma.pXdmad, bus->dma_rx_channel);
    262   XDMAD_FreeChannel(bus->SpiDma.pXdmad, bus->dma_tx_channel);
    263 
    264   SPI_Disable(bus->SpiDma.pSpiHw);
    265   PMC_DisablePeripheral(bus->SpiDma.spiId);
     260  XDMAD_FreeChannel(bus->spi.pXdmad, bus->dma_rx_channel);
     261  XDMAD_FreeChannel(bus->spi.pXdmad, bus->dma_tx_channel);
     262
     263  SPI_Disable(bus->spi.pSpiHw);
     264  PMC_DisablePeripheral(bus->spi.spiId);
    266265
    267266  spi_bus_destroy_and_free(&bus->base);
     
    291290
    292291  bus->dma_tx_channel = XDMAD_AllocateChannel(
    293     &bus->xdma,
     292    bus->spi.pXdmad,
    294293    XDMAD_TRANSFER_MEMORY,
    295     bus->SpiDma.spiId
     294    bus->spi.spiId
    296295  );
    297296  assert(bus->dma_tx_channel != XDMAD_ALLOC_FAILED);
    298297
    299298  bus->dma_rx_channel = XDMAD_AllocateChannel(
    300     &bus->xdma,
    301     bus->SpiDma.spiId,
     299    bus->spi.pXdmad,
     300    bus->spi.spiId,
    302301    XDMAD_TRANSFER_MEMORY
    303302  );
     
    305304
    306305  rc = XDMAD_SetCallback(
    307     &bus->xdma,
     306    bus->spi.pXdmad,
    308307    bus->dma_rx_channel,
    309308    atsam_spi_dma_callback,
     
    313312
    314313  rc = XDMAD_SetCallback(
    315     &bus->xdma,
     314    bus->spi.pXdmad,
    316315    bus->dma_tx_channel,
    317316    atsam_spi_dma_callback,
     
    320319  assert(rc == XDMAD_OK);
    321320
    322   rc = XDMAD_PrepareChannel(&bus->xdma, bus->dma_rx_channel);
    323   assert(rc == XDMAD_OK);
    324 
    325   rc = XDMAD_PrepareChannel(&bus->xdma, bus->dma_tx_channel);
     321  rc = XDMAD_PrepareChannel(bus->spi.pXdmad, bus->dma_rx_channel);
     322  assert(rc == XDMAD_OK);
     323
     324  rc = XDMAD_PrepareChannel(bus->spi.pXdmad, bus->dma_tx_channel);
    326325  assert(rc == XDMAD_OK);
    327326
     
    337336  /* Setup RX */
    338337  memset(&cfg, 0, sizeof(cfg));
    339   channel = XDMAIF_Get_ChannelNumber(bus->SpiDma.spiId, XDMAD_TRANSFER_RX);
    340   cfg.mbr_sa = (uint32_t)&bus->SpiDma.pSpiHw->SPI_RDR;
     338  channel = XDMAIF_Get_ChannelNumber(bus->spi.spiId, XDMAD_TRANSFER_RX);
     339  cfg.mbr_sa = (uint32_t)&bus->spi.pSpiHw->SPI_RDR;
    341340  cfg.mbr_cfg =
    342341    XDMAC_CC_TYPE_PER_TRAN |
     
    351350    XDMAC_CC_PERID(channel);
    352351  rc = XDMAD_ConfigureTransfer(
    353     &bus->xdma,
     352    bus->spi.pXdmad,
    354353    bus->dma_rx_channel,
    355354    &cfg,
     
    362361  /* Setup TX  */
    363362  memset(&cfg, 0, sizeof(cfg));
    364   channel = XDMAIF_Get_ChannelNumber(bus->SpiDma.spiId, XDMAD_TRANSFER_TX);
    365   cfg.mbr_da = (uint32_t)&bus->SpiDma.pSpiHw->SPI_TDR;
     363  channel = XDMAIF_Get_ChannelNumber(bus->spi.spiId, XDMAD_TRANSFER_TX);
     364  cfg.mbr_da = (uint32_t)&bus->spi.pSpiHw->SPI_TDR;
    366365  cfg.mbr_cfg =
    367366    XDMAC_CC_TYPE_PER_TRAN |
     
    376375    XDMAC_CC_PERID(channel);
    377376  rc = XDMAD_ConfigureTransfer(
    378     &bus->xdma,
     377    bus->spi.pXdmad,
    379378    bus->dma_tx_channel,
    380379    &cfg,
     
    409408  bus->base.delay_usecs = 1;
    410409  bus->base.cs = 1;
    411   bus->SpiDma.spiId = spi_peripheral_id;
    412   bus->SpiDma.pSpiHw = spi_regs;
     410  bus->spi.spiId = spi_peripheral_id;
     411  bus->spi.pSpiHw = spi_regs;
    413412
    414413  PIO_Configure(pins, pin_count);
    415414  PMC_EnablePeripheral(spi_peripheral_id);
    416   XDMAD_Initialize(&bus->xdma, 0);
    417415  atsam_configure_spi(bus);
    418416  atsam_spi_init_xdma(bus);
Note: See TracChangeset for help on using the changeset viewer.