]> rtime.felk.cvut.cz Git - arc.git/commitdiff
Added more board info for SPI. Spi cleanup
authormahi <devnull@localhost>
Sat, 3 Mar 2012 19:31:17 +0000 (20:31 +0100)
committermahi <devnull@localhost>
Sat, 3 Mar 2012 19:31:17 +0000 (20:31 +0100)
arch/ppc/mpc55xx/drivers/Spi.c
boards/mpc5604b_trk/board_info.txt
boards/mpc5606s_xpc560s/board_info.txt

index c236fc8bec994a05f51d6125a83a3d3d3d0069ec..2b3724ab96c3ebed7228e5001afb7196b493571a 100644 (file)
@@ -40,9 +40,9 @@
  *   - DMA and FIFO is implementations\r
  *   - Soft CS by callback\r
  *\r
- *\r
- *   Device\r
+ *   Devices\r
  *   - MPC5606S\r
+ *   - MPC5604B\r
  *\r
  * Implementation Notes:\r
  * - This driver implements SPI_LEVEL_DELIVERED = 2 but with a number\r
 #define SPI_INTERNAL_MTU    72\r
 \r
 /* The depth of the HW FIFO */\r
-#define FIFO_DEPTH                     5\r
+#define FIFO_DEPTH                     4\r
 \r
 /* Define for debug purposes, checks that SPI/DMA is ok */\r
-//#define STEP_VALIDATION              1\r
+#define STEP_VALIDATION                1\r
 \r
 #define MODULE_NAME    "/driver/Spi"\r
 \r
 #define RAMLOG_DEC(_x)\r
 #endif\r
 \r
+#define SPI_ASSERT(_exp)       if( !(_exp) ) while(1) {}\r
+\r
 /* ----------------------------[private macro]-------------------------------*/\r
 \r
 #ifndef MIN\r
 #define GET_SPI_HW_PTR(_unit)  \\r
         ((volatile struct DSPI_tag *)(0xFFF90000 + 0x4000*(_unit)))\r
 \r
-#define GET_SPI_UNIT_PTR(_unit) &Spi_Unit[_unit]\r
+#define GET_SPI_UNIT_PTR(_unit) &Spi_Unit[Spi_CtrlToUnit[_unit]]\r
 \r
 #define ENABLE_EOQ_INTERRUPT(_spi_hw) _spi_hw->RSER.B.EOQF_RE = 1\r
 #define DISABLE_EOQ_INTERRUPT(_spi_hw) _spi_hw->RSER.B.EOQF_RE = 0\r
@@ -299,6 +301,8 @@ typedef struct {
     Spi_JobType                     currJobIndex;\r
        const Spi_SequenceConfigType *  currSeqPtr;     // The Sequence\r
        Spi_CallTypeType callType;                      // 1 -  if the current job is sync. 0 - if not\r
+       volatile struct DSPI_tag *      hwPtr;\r
+       uint8                                                   hwUnit;         // 0...\r
 } Spi_UnitType;\r
 \r
 typedef struct {\r
@@ -374,42 +378,35 @@ Spi_UnitType    Spi_Unit[SPI_CONTROLLER_CNT];
 Spi_SeqUnitType Spi_SeqUnit[SPI_MAX_SEQUENCE];\r
 Spi_JobUnitType Spi_JobUnit[SPI_MAX_JOB];\r
 Spi_ChannelInfoType Spi_ChannelInfo[SPI_MAX_CHANNEL];\r
+uint8 Spi_CtrlToUnit[4];\r
 \r
 \r
 #if (SPI_IMPLEMENTATION == SPI_DMA)\r
 /* When using DMA it assumes predefined names */\r
-Spi_DmaConfigType  Spi_DmaConfig[4] = {\r
+Spi_DmaConfigType  Spi_DmaConfig[SPI_CONTROLLER_CNT] = {\r
 #if (SPI_USE_HW_UNIT_0 == STD_ON )\r
        {\r
            .RxDmaChannel = DMA_DSPI_A_RESULT_CHANNEL,\r
            .TxDmaChannel = DMA_DSPI_A_COMMAND_CHANNEL,\r
        },\r
-#else\r
-       { (Dma_ChannelType)0, (Dma_ChannelType)0 },\r
 #endif\r
 #if (SPI_USE_HW_UNIT_1 == STD_ON )\r
        {\r
            .RxDmaChannel = DMA_DSPI_B_RESULT_CHANNEL,\r
            .TxDmaChannel = DMA_DSPI_B_COMMAND_CHANNEL,\r
        },\r
-#else\r
-       { (Dma_ChannelType)0, (Dma_ChannelType)0 },\r
 #endif\r
 #if (SPI_USE_HW_UNIT_2 == STD_ON )\r
        {\r
            .RxDmaChannel = DMA_DSPI_C_RESULT_CHANNEL,\r
            .TxDmaChannel = DMA_DSPI_C_COMMAND_CHANNEL,\r
        },\r
-#else\r
-       { (Dma_ChannelType)0, (Dma_ChannelType)0 },\r
 #endif\r
 #if (SPI_USE_HW_UNIT_3 == STD_ON )\r
        {\r
            .RxDmaChannel = DMA_DSPI_D_RESULT_CHANNEL,\r
            .TxDmaChannel = DMA_DSPI_D_COMMAND_CHANNEL,\r
        }\r
-#else\r
-       { (Dma_ChannelType)0, (Dma_ChannelType)0 },\r
 #endif\r
 };\r
 #endif\r
@@ -421,10 +418,10 @@ static void Spi_WriteJob_FIFO( Spi_JobType jobIndex );
 \r
 /**\r
  * Get the buffer for a channel.\r
- *\r
- * @param ch\r
- * @param length\r
- * @return\r
+ *
+ * @param ch
+ * @param length
+ * @return
  */\r
 static Spi_DataType *spiGetRxBuf(Spi_ChannelType ch, Spi_NumberOfDataType *length ) {\r
        Spi_DataType *buf;\r
@@ -453,19 +450,19 @@ static const Spi_DataType *spiGetTxBuf(Spi_ChannelType ch, Spi_NumberOfDataType
 }\r
 #endif\r
 \r
-static void Spi_Isr(uint32);\r
+static void Spi_Isr(Spi_UnitType *uPtr );\r
 \r
 static void Spi_Isr_A(void) {\r
-       Spi_Isr(DSPI_CTRL_A);\r
+       Spi_Isr(GET_SPI_UNIT_PTR(DSPI_CTRL_A));\r
 }\r
 static void Spi_Isr_B(void) {\r
-       Spi_Isr(DSPI_CTRL_B);\r
+       Spi_Isr(GET_SPI_UNIT_PTR(DSPI_CTRL_B));\r
 }\r
 static void Spi_Isr_C(void) {\r
-       Spi_Isr(DSPI_CTRL_C);\r
+       Spi_Isr(GET_SPI_UNIT_PTR(DSPI_CTRL_C));\r
 }\r
 static void Spi_Isr_D(void) {\r
-       Spi_Isr(DSPI_CTRL_D);\r
+       Spi_Isr(GET_SPI_UNIT_PTR(DSPI_CTRL_D));\r
 }\r
 /* ----------------------------[public functions]----------------------------*/\r
 \r
@@ -487,9 +484,15 @@ static void Spi_SetJobResult(Spi_JobType Job, Spi_JobResultType result) {
        Spi_JobUnit[Job].jobResult = result;\r
 }\r
 \r
+#if 1\r
+static void Spi_SetHWUnitStatus( Spi_UnitType *uPtr, Spi_StatusType status) {\r
+       uPtr->status = status;\r
+}\r
+#else\r
 static void Spi_SetHWUnitStatus(Spi_HWUnitType HWUnit, Spi_StatusType status) {\r
-       Spi_Unit[HWUnit].status = status;\r
+       Spi_Unit[Spi_CtrlToUnit[HWUnit]].status = status;\r
 }\r
+#endif\r
 \r
 /**\r
  * Get external Ptr to device from index\r
@@ -528,7 +531,7 @@ static const Spi_SequenceConfigType *Spi_GetSeqPtrFromIndex(
  * @return Ptr to the SPI unit\r
  */\r
 static Spi_UnitType *Spi_GetUnitPtrFromIndex(uint32 unit) {\r
-       return &Spi_Unit[unit];\r
+       return &Spi_Unit[Spi_CtrlToUnit[unit]];\r
 }\r
 \r
 /**\r
@@ -699,7 +702,7 @@ static int Spi_Rx_FIFO(Spi_UnitType *spiUnit) {
 \r
        if( jobUnitPtr->hwPtr->TCR.B.SPI_TCNT != jobUnitPtr->fifoSent ) {\r
 #if defined(STEP_VALIDATION)\r
-           while(1) {};\r
+           SPI_ASSERT(0);\r
 #endif\r
                return SPIE_BAD;\r
        }\r
@@ -719,7 +722,7 @@ static int Spi_Rx_FIFO(Spi_UnitType *spiUnit) {
 \r
     if( jobUnitPtr->fifoSent != jobUnitPtr->hwPtr->SR.B.RXCTR ) {\r
 #if defined(STEP_VALIDATION)\r
-        while(1) {};\r
+        SPI_ASSERT(0);\r
 #endif\r
         return SPIE_BAD;\r
     }\r
@@ -738,7 +741,7 @@ static int Spi_Rx_FIFO(Spi_UnitType *spiUnit) {
 \r
         if( copyCnt == 0  ) {\r
 #if defined(STEP_VALIDATION)\r
-        while(1) {};\r
+        SPI_ASSERT(0);\r
 #endif\r
             return SPIE_BAD;\r
         }\r
@@ -778,12 +781,12 @@ static int Spi_Rx_FIFO(Spi_UnitType *spiUnit) {
         }\r
        }\r
 \r
+#if defined(STEP_VALIDATION)\r
        /* Check if we are done with this job */\r
     if( 0 != jobUnitPtr->hwPtr->SR.B.RXCTR ) {\r
-        while(1) {};\r
+        SPI_ASSERT(0);\r
     }\r
-\r
-\r
+#endif\r
 \r
        return rv;\r
 }\r
@@ -795,11 +798,13 @@ static int Spi_Rx_FIFO(Spi_UnitType *spiUnit) {
 /**\r
  * ISR for End of Queue interrupt\r
  *\r
+ * The interrupt handling is quite simple. Since this driver assumes\r
+ * that we are the master the EOQ interrupt is sufficient to check.\r
+ *\r
  * @param unit The HW unit it happend on\r
  */\r
-static void Spi_Isr(uint32 unit) {\r
-       volatile struct DSPI_tag *spiHw = GET_SPI_HW_PTR(unit);\r
-       Spi_UnitType *spiUnit = GET_SPI_UNIT_PTR(unit);\r
+static void Spi_Isr( Spi_UnitType *uPtr) {\r
+       volatile struct DSPI_tag *spiHw = uPtr->hwPtr;\r
        int rv;\r
 \r
        RAMLOG_STR("Spi_Isr\n");\r
@@ -820,15 +825,21 @@ static void Spi_Isr(uint32 unit) {
        }\r
 \r
 #if (SPI_IMPLEMENTATION == SPI_DMA)\r
-       while (!Dma_ChannelDone(Spi_Unit[unit].dmaRxChannel)) {\r
+       while (!Dma_ChannelDone(uPtr->dmaRxChannel)) {\r
                Spi_Global.totalNbrOfWaitRxDMA++;\r
        }\r
 #endif\r
 \r
+#if defined(STEP_VALIDATION)\r
+       /* Since EOQF clears TXRXS */\r
+       SPI_ASSERT( (spiHw->SR.B.EOQF==1) && (spiHw->SR.B.TXRXS == 0));\r
+#endif\r
+\r
        /* Halt DSPI unit until we are ready for next transfer. */\r
        spiHw->MCR.B.HALT = 1;\r
        spiHw->SR.B.EOQF = 1;\r
 \r
+\r
        Spi_Global.totalNbrOfTranfers++;\r
 \r
        // Disable EOQ interrupts\r
@@ -845,26 +856,26 @@ static void Spi_Isr(uint32 unit) {
 \r
        // Update external buffers\r
 #if (SPI_IMPLEMENTATION==SPI_DMA)\r
-       rv = Spi_Rx_DMA(spiUnit);\r
+       rv = Spi_Rx_DMA(uPtr);\r
 \r
 #if (USE_DIO_CS == STD_ON)\r
-    void (*cb)(int) = Spi_JobUnit[spiUnit->currJobIndex].extDeviceCfgPtr->SpiCsCallback;\r
+    void (*cb)(int) = Spi_JobUnit[uPtr->currJobIndex].extDeviceCfgPtr->SpiCsCallback;\r
     if( cb != NULL ) {\r
         cb(0);\r
     }\r
 #endif\r
 #elif (SPI_IMPLEMENTATION==SPI_FIFO)\r
-       rv = Spi_Rx_FIFO(spiUnit);\r
+       rv = Spi_Rx_FIFO(uPtr);\r
 \r
        if( rv == SPIE_JOB_NOT_DONE ) {\r
            /* RX FIFO now empty, but the job is not done -> send more */\r
-           Spi_WriteJob_FIFO ( spiUnit->currJobIndex );\r
+           Spi_WriteJob_FIFO ( uPtr->currJobIndex );\r
                RAMLOG_STR("Spi_Isr END\n");\r
                return;\r
        }\r
 #if (USE_DIO_CS == STD_ON)\r
        else {\r
-           void (*cb)(int) = Spi_JobUnit[spiUnit->currJobIndex].extDeviceCfgPtr->SpiCsCallback;\r
+           void (*cb)(int) = Spi_JobUnit[uPtr->currJobIndex].extDeviceCfgPtr->SpiCsCallback;\r
            if( cb != NULL ) {\r
                cb(0);\r
            }\r
@@ -873,24 +884,24 @@ static void Spi_Isr(uint32 unit) {
 #endif\r
 \r
        // Call notification end\r
-       if (spiUnit->currJob->SpiJobEndNotification != NULL) {\r
-               spiUnit->currJob->SpiJobEndNotification();\r
+       if (uPtr->currJob->SpiJobEndNotification != NULL) {\r
+               uPtr->currJob->SpiJobEndNotification();\r
        }\r
 \r
        if (rv == SPIE_BAD) {\r
                // Fail both job and sequence\r
-               Spi_SetHWUnitStatus(unit, SPI_IDLE);\r
-               Spi_SetJobResult(spiUnit->currJob->SpiJobId, SPI_JOB_FAILED);\r
-               Spi_SetSequenceResult(spiUnit->currSeqPtr->SpiSequenceId,\r
+               Spi_SetHWUnitStatus(uPtr, SPI_IDLE);\r
+               Spi_SetJobResult(uPtr->currJob->SpiJobId, SPI_JOB_FAILED);\r
+               Spi_SetSequenceResult(uPtr->currSeqPtr->SpiSequenceId,\r
                                SPI_SEQ_FAILED);\r
 #if defined(STEP_VALIDATION)\r
-               while(1) {};\r
+               SPI_ASSERT(0);\r
 #endif\r
        } else {\r
                Spi_JobType nextJob;\r
 \r
                // The job is at least done..\r
-               Spi_SetJobResult(spiUnit->currJob->SpiJobId, SPI_JOB_OK);\r
+               Spi_SetJobResult(uPtr->currJob->SpiJobId, SPI_JOB_OK);\r
 \r
                // WriteNextJob should\r
                // 1. Update the JobResult to SPI_JOB_OK\r
@@ -905,21 +916,21 @@ static void Spi_Isr(uint32 unit) {
                //\r
                // So, I no clue what to use the priority thing for :(\r
 \r
-               nextJob = Spi_GetNextJob(spiUnit);\r
+               nextJob = Spi_GetNextJob(uPtr);\r
                if( nextJob != JOB_NOT_VALID ) {\r
                        Spi_JobWrite(nextJob);\r
                        RAMLOG_STR("more_jobs\n");\r
                } else {\r
                        // No more jobs, so set HwUnit and sequence IDLE/OK also.\r
-                       Spi_SetHWUnitStatus(unit, SPI_IDLE);\r
-                       Spi_SetSequenceResult(spiUnit->currSeqPtr->SpiSequenceId,\r
+                       Spi_SetHWUnitStatus(uPtr, SPI_IDLE);\r
+                       Spi_SetSequenceResult(uPtr->currSeqPtr->SpiSequenceId,\r
                                        SPI_SEQ_OK);\r
 \r
-                       if (spiUnit->currSeqPtr->SpiSeqEndNotification != NULL) {\r
-                               spiUnit->currSeqPtr->SpiSeqEndNotification();\r
+                       if (uPtr->currSeqPtr->SpiSeqEndNotification != NULL) {\r
+                               uPtr->currSeqPtr->SpiSeqEndNotification();\r
                        }\r
 \r
-                       Spi_SetHWUnitStatus(unit, SPI_IDLE);\r
+                       Spi_SetHWUnitStatus(uPtr, SPI_IDLE);\r
 \r
                        /* We are now ready for next transfer. */\r
                        spiHw->MCR.B.HALT = 1;\r
@@ -1155,9 +1166,9 @@ static void Spi_SetupCTAR(        Spi_HWUnitType unit,
 \r
 //-------------------------------------------------------------------\r
 \r
-static void Spi_InitController(uint32 unit) {\r
-       volatile struct DSPI_tag *spiHw = GET_SPI_HW_PTR(unit);\r
-       Spi_UnitType *spiUnit = GET_SPI_UNIT_PTR(unit);\r
+static void Spi_InitController(Spi_UnitType *uPtr ) {\r
+\r
+       volatile struct DSPI_tag *spiHw = uPtr->hwPtr;\r
 \r
        /* Module configuration register. */\r
        /* Master mode. */\r
@@ -1197,7 +1208,7 @@ static void Spi_InitController(uint32 unit) {
 \r
        // Setup CTAR's channel codes..\r
        for (int i = 0; i < 7; i++) {\r
-               spiUnit->channelCodes[i] = CH_NOT_VALID;\r
+               uPtr->channelCodes[i] = CH_NOT_VALID;\r
        }\r
 \r
        /* Force to stopped state. */\r
@@ -1213,7 +1224,7 @@ static void Spi_InitController(uint32 unit) {
 #endif\r
 \r
        // Install EOFQ int..\r
-       switch (unit) {\r
+       switch (uPtr->hwUnit) {\r
 #if defined(CFG_MPC560X)\r
        case 0:\r
        ISR_INSTALL_ISR2("SPI_A",Spi_Isr_A, DSPI_0_ISR_EOQF, 15, 0);\r
@@ -1248,25 +1259,25 @@ static void Spi_InitController(uint32 unit) {
 //-------------------------------------------------------------------\r
 \r
 #if (SPI_IMPLEMENTATION==SPI_DMA)\r
-static void Spi_DmaSetup(uint32 unit) {\r
+static void Spi_DmaSetup( Spi_UnitType *uPtr ) {\r
 \r
        Dma_TcdType *tcd;\r
 \r
-       tcd = &Spi_Unit[unit].dmaTxTCD;\r
+       tcd = &uPtr->dmaTxTCD;\r
        *tcd = Spi_DmaTx;\r
-       tcd->SADDR = (uint32) Spi_Unit[unit].txQueue;\r
-       tcd->DADDR = (uint32) &(GET_SPI_HW_PTR(unit)->PUSHR.R);\r
+       tcd->SADDR = (uint32) uPtr->txQueue;\r
+       tcd->DADDR = (uint32) &(uPtr->hwPtr->PUSHR.R);\r
 \r
-       Dma_StopChannel(Spi_Unit[unit].dmaTxChannel);\r
+       Dma_StopChannel(uPtr->dmaTxChannel);\r
        Dma_CheckConfig();\r
 \r
        // CITER and BITER set when we send\r
-       tcd = &Spi_Unit[unit].dmaRxTCD;\r
+       tcd = &uPtr->dmaRxTCD;\r
        *tcd = Spi_DmaRx;\r
-       tcd->SADDR = (uint32) &(GET_SPI_HW_PTR(unit)->POPR.R);\r
-       tcd->DADDR = (uint32) Spi_Unit[unit].rxQueue;\r
+       tcd->SADDR = (uint32) &(uPtr->hwPtr->POPR.R);\r
+       tcd->DADDR = (uint32) uPtr->rxQueue;\r
 \r
-       Dma_StopChannel(Spi_Unit[unit].dmaRxChannel);\r
+       Dma_StopChannel(uPtr->dmaRxChannel);\r
        Dma_CheckConfig();\r
 \r
 }\r
@@ -1275,8 +1286,12 @@ static void Spi_DmaSetup(uint32 unit) {
 //-------------------------------------------------------------------\r
 \r
 void Spi_Init(const Spi_ConfigType *ConfigPtr) {\r
-\r
        const Spi_JobConfigType *jobConfig2;\r
+       Spi_UnitType *uPtr;\r
+       uint32 confMask;\r
+       uint8 ctrlNr;\r
+       uint8 unitNr;\r
+\r
 \r
        memset(&Spi_Global,0,sizeof(Spi_Global));\r
        Spi_Global.configPtr = ConfigPtr;\r
@@ -1288,42 +1303,39 @@ void Spi_Init(const Spi_ConfigType *ConfigPtr) {
        for (Spi_SequenceType i = (Spi_SequenceType) 0; i < SPI_MAX_SEQUENCE; i++) {\r
                Spi_SetSequenceResult(i, SPI_SEQ_OK);\r
        }\r
-\r
        // Figure out what HW controllers that are used\r
        for (int j = 0; j < Spi_GetJobCnt(); j++) {\r
                jobConfig2 = &Spi_Global.configPtr->SpiJobConfig[j];\r
                Spi_Global.spiHwConfigured |= (1 << jobConfig2->SpiHwUnit);\r
        }\r
 \r
-       // Initialize controllers used\r
-       {\r
-               uint32 confMask;\r
-               uint8 confNr;\r
-\r
-               confMask = Spi_Global.spiHwConfigured;\r
+       confMask = Spi_Global.spiHwConfigured;\r
 \r
-               for (; confMask; confMask &= ~(1 << confNr)) {\r
-                       confNr = ilog2(confMask);\r
-                       DEBUG(DEBUG_LOW,"%s:Configured HW controller %d\n",MODULE_NAME,confNr);\r
-                       Spi_InitController(confNr);\r
-                       Spi_SetHWUnitStatus(confNr, SPI_IDLE);\r
+       for (; confMask; confMask &= ~(1 << ctrlNr)) {\r
+               ctrlNr = ilog2(confMask);\r
+               DEBUG(DEBUG_LOW,"%s:Configured HW controller %d\n",MODULE_NAME,ctrlNr);\r
+               uPtr = GET_SPI_UNIT_PTR(ctrlNr);\r
+               uPtr->hwPtr = GET_SPI_HW_PTR(ctrlNr);\r
+               uPtr->hwUnit = ctrlNr;\r
+               Spi_InitController(uPtr);\r
+               Spi_SetHWUnitStatus(uPtr, SPI_IDLE);\r
+               unitNr = Spi_CtrlToUnit[ctrlNr];\r
 \r
 #if (SPI_IMPLEMENTATION == SPI_DMA )\r
-                       // DMA init...\r
-                       //\r
+               // DMA init...\r
+               //\r
 \r
-                       /* Make sure that this channel shall be used. */\r
-                       //assert (ConfigPtr->SpiHwConfig[confNr].Activated);\r
-                       assert(Spi_DmaConfig[confNr].TxDmaChannel != (-1));\r
-                       assert(Spi_DmaConfig[confNr].RxDmaChannel != (-1));\r
+               /* Make sure that this channel shall be used. */\r
+               //assert (ConfigPtr->SpiHwConfig[ctrlNr].Activated);\r
+               assert(Spi_DmaConfig[unitNr].TxDmaChannel != (-1));\r
+               assert(Spi_DmaConfig[unitNr].RxDmaChannel != (-1));\r
 \r
-                       Spi_Unit[confNr].dmaTxChannel = Spi_DmaConfig[confNr].TxDmaChannel;\r
-                       Spi_Unit[confNr].dmaRxChannel = Spi_DmaConfig[confNr].RxDmaChannel;\r
+               uPtr->dmaTxChannel = Spi_DmaConfig[unitNr].TxDmaChannel;\r
+               uPtr->dmaRxChannel = Spi_DmaConfig[unitNr].RxDmaChannel;\r
 \r
-                       Spi_DmaSetup(confNr);\r
+               Spi_DmaSetup(uPtr);\r
 #endif\r
 \r
-               }\r
        }\r
 \r
        /* Setup the relations for Job, for easy access */\r
@@ -1412,6 +1424,8 @@ Std_ReturnType Spi_DeInit(void) {
        volatile struct DSPI_tag *spiHw;\r
        uint32 confMask;\r
        uint8 confNr;\r
+       Spi_UnitType *uPtr;\r
+\r
 \r
        VALIDATE_W_RV( ( TRUE == Spi_Global.initRun ), SPI_DEINIT_SERVICE_ID, SPI_E_UNINIT, E_NOT_OK );\r
        if (Spi_GetStatus() == SPI_BUSY)\r
@@ -1426,9 +1440,10 @@ Std_ReturnType Spi_DeInit(void) {
                spiHw = GET_SPI_HW_PTR(confNr);\r
                // Disable the hardware..\r
                spiHw->MCR.B.MDIS = 1;\r
+               uPtr = GET_SPI_UNIT_PTR(confNr);\r
 \r
-               Spi_InitController(confNr);\r
-               Spi_SetHWUnitStatus(confNr, SPI_IDLE);\r
+               Spi_InitController(uPtr);\r
+               Spi_SetHWUnitStatus(uPtr, SPI_IDLE);\r
        }\r
 \r
        // SPI022\r
@@ -1440,10 +1455,10 @@ Std_ReturnType Spi_DeInit(void) {
 \r
 #if (SPI_IMPLEMENTATION==SPI_DMA)\r
 /**\r
- *\r
- * @param spiUnit\r
- * @param jobConfig\r
- * @return\r
+ *
+ * @param spiUnit
+ * @param jobConfig
+ * @return
  */\r
 static void Spi_DoWrite_DMA(   Spi_UnitType *spiUnit,Spi_JobType jobIndex,\r
                                                const Spi_JobConfigType *jobConfig )\r
@@ -1592,7 +1607,7 @@ static void Spi_WriteJob_FIFO( Spi_JobType jobIndex )
 \r
 #if defined(STEP_VALIDATION)\r
     if(  jobUnitPtr->hwPtr->SR.B.TXCTR != 0 ) {\r
-        while(1) {};\r
+        SPI_ASSERT(0);\r
     }\r
 #endif\r
 \r
@@ -1614,9 +1629,11 @@ static void Spi_WriteJob_FIFO( Spi_JobType jobIndex )
         /* Set the Chip Select (PCS) */\r
         cmd.R |= (1 << (16 + jobUnitPtr->extDeviceCfgPtr->SpiCsIdentifier));\r
 \r
+#if defined(STEP_VALIDATION)\r
         if( cmd.B.EOQ == 1) {\r
-            while(1) {};\r
+            SPI_ASSERT(0);\r
         }\r
+#endif\r
 \r
         /* Push as much as we can (FIFO or Channel limits) */\r
         for(i=0; i < copyCnt ; i++ ) {\r
@@ -1672,7 +1689,7 @@ static void Spi_WriteJob_FIFO( Spi_JobType jobIndex )
 \r
 #if defined(STEP_VALIDATION)\r
        if( jobUnitPtr->fifoSent != jobUnitPtr->hwPtr->SR.B.TXCTR ) {\r
-           while(1);\r
+           SPI_ASSERT(0);\r
        }\r
 #endif\r
 \r
@@ -1692,19 +1709,19 @@ static void Spi_WriteJob_FIFO( Spi_JobType jobIndex )
         SPICommandType *curr;\r
         int i,lastIndex;\r
 \r
-        i = jobUnitPtr->hwPtr->SR.B.TXNXTPTR;\r
+        i = jobUnitPtr->hwPtr->SR.B.TXNXTPTR;  /* Next entry to send */\r
         lastIndex = ( i + jobUnitPtr->hwPtr->SR.B.TXCTR - 1 ) % FIFO_DEPTH;\r
         while( i != lastIndex )  {\r
             curr = base + i;\r
-            if( curr->B.EOQ == 1) {\r
-                while(1) {};\r
+            if( curr->B.EOQ == 1) {  /* This entry must not have EOQ set */\r
+                SPI_ASSERT(0);\r
             }\r
 \r
             i = (i + 1) % FIFO_DEPTH;\r
         }\r
         curr = base + i;\r
         if( curr->B.EOQ != 1) {\r
-            while(1) {};\r
+            SPI_ASSERT(0);             /* Last entry must have EOQ set */\r
         }\r
     }\r
 #endif\r
@@ -1737,17 +1754,17 @@ static void Spi_WriteJob_FIFO( Spi_JobType jobIndex )
  * @param jobIndex The job to write to the SPI bus\r
  */\r
 static void Spi_JobWrite(Spi_JobType jobIndex) {\r
-       Spi_UnitType *unitPtr = Spi_JobUnit[jobIndex].unitPtr;\r
+       Spi_UnitType *uPtr = Spi_JobUnit[jobIndex].unitPtr;\r
 \r
-       unitPtr->txCurrIndex = 0;\r
-       unitPtr->currJob = Spi_JobUnit[jobIndex].jobCfgPtr;\r
-       unitPtr->currJobIndex = jobIndex;\r
+       uPtr->txCurrIndex = 0;\r
+       uPtr->currJob = Spi_JobUnit[jobIndex].jobCfgPtr;\r
+       uPtr->currJobIndex = jobIndex;\r
 #if (SPI_IMPLEMENTATION == SPI_FIFO)\r
        Spi_JobUnit[jobIndex].txChCnt = 0;\r
        Spi_JobUnit[jobIndex].rxChCnt = 0;\r
 #endif\r
 \r
-       Spi_SetHWUnitStatus(Spi_JobUnit[jobIndex].jobCfgPtr->SpiHwUnit, SPI_BUSY);\r
+       Spi_SetHWUnitStatus(uPtr, SPI_BUSY);\r
        Spi_SetJobResult(jobIndex, SPI_JOB_PENDING);\r
 \r
 #if (USE_DIO_CS == STD_ON)\r
@@ -1757,7 +1774,7 @@ static void Spi_JobWrite(Spi_JobType jobIndex) {
 #endif\r
 \r
 #if (SPI_IMPLEMENTATION==SPI_DMA)\r
-       Spi_DoWrite_DMA( unitPtr, jobIndex, Spi_JobUnit[jobIndex].jobCfgPtr );\r
+       Spi_DoWrite_DMA( uPtr, jobIndex, Spi_JobUnit[jobIndex].jobCfgPtr );\r
 #elif (SPI_IMPLEMENTATION==SPI_FIFO)\r
        Spi_JobUnit[jobIndex].currTxChIndex = 0;\r
        Spi_WriteJob_FIFO ( jobIndex );\r
@@ -1788,25 +1805,25 @@ static void Spi_SeqWrite(Spi_SequenceType seqIndex, Spi_CallTypeType sync) {
 \r
        const Spi_SequenceConfigType *seqConfig;\r
        const Spi_JobConfigType *jobConfig;\r
-       Spi_UnitType *spiUnit;\r
+       Spi_UnitType *uPtr;\r
        Spi_JobType jobIndex;\r
 \r
        seqConfig = Spi_GetSeqPtrFromIndex(seqIndex);\r
        jobIndex = seqConfig->JobAssignment[0];\r
        jobConfig = Spi_GetJobPtrFromIndex(jobIndex);\r
 \r
-       spiUnit = Spi_GetUnitPtrFromIndex(jobConfig->SpiHwUnit);\r
+       uPtr = Spi_GetUnitPtrFromIndex(jobConfig->SpiHwUnit);\r
 \r
        /* Fill in the required fields for job and sequence.. */\r
-       spiUnit->currJobIndexPtr = &seqConfig->JobAssignment[0];\r
-       spiUnit->callType = sync;\r
-       spiUnit->currSeqPtr = seqConfig;\r
+       uPtr->currJobIndexPtr = &seqConfig->JobAssignment[0];\r
+       uPtr->callType = sync;\r
+       uPtr->currSeqPtr = seqConfig;\r
 \r
        Spi_SetSequenceResult(seqIndex, SPI_SEQ_PENDING);\r
 \r
        // Setup interrupt for end of queue\r
        if (    (Spi_Global.asyncMode == SPI_INTERRUPT_MODE) &&\r
-                       (spiUnit->callType== SPI_ASYNC_CALL)) {\r
+                       (uPtr->callType== SPI_ASYNC_CALL)) {\r
                DEBUG(DEBUG_MEDIUM,"%s: async/interrupt mode\n",MODULE_NAME);\r
        } else {\r
                DEBUG(DEBUG_MEDIUM,"%s: sync/polled mode\n",MODULE_NAME);\r
@@ -1818,9 +1835,9 @@ static void Spi_SeqWrite(Spi_SequenceType seqIndex, Spi_CallTypeType sync) {
 \r
        Spi_JobWrite(jobIndex);\r
 \r
-       if (spiUnit->callType == SPI_SYNC_CALL) {\r
+       if (uPtr->callType == SPI_SYNC_CALL) {\r
                while (Spi_GetSequenceResult(seqIndex) == SPI_SEQ_PENDING) {\r
-                       Spi_Isr(jobConfig->SpiHwUnit);\r
+                       Spi_Isr(uPtr);\r
                }\r
        }\r
 \r
@@ -2001,7 +2018,7 @@ Spi_SeqResultType Spi_GetSequenceResult(Spi_SequenceType Sequence) {
 Spi_StatusType Spi_GetHWUnitStatus(Spi_HWUnitType HWUnit) {\r
        VALIDATE_W_RV( ( TRUE == Spi_Global.initRun ), SPI_GETHWUNITSTATUS_SERVICE_ID, SPI_E_UNINIT, SPI_UNINIT );\r
 \r
-       return Spi_Unit[HWUnit].status;\r
+       return Spi_Unit[Spi_CtrlToUnit[HWUnit]].status;\r
 }\r
 \r
 //-------------------------------------------------------------------\r
@@ -2049,23 +2066,24 @@ void Spi_MainFunction_Handling(void) {
 void Spi_MainFunction_Driving(void) {\r
        volatile struct DSPI_tag *spiHw;\r
        uint32 confMask;\r
-       uint8 confNr;\r
-       Spi_UnitType *spiUnit;\r
+       uint8 ctrlNr;\r
+       Spi_UnitType *uPtr;\r
 \r
        // TODO: check that the queue is empty.. if so do the next job.\r
        if (Spi_Global.asyncMode == SPI_POLLING_MODE) {\r
                confMask = Spi_Global.spiHwConfigured;\r
 \r
-               for (; confMask; confMask &= ~(1 << confNr)) {\r
-                       confNr = ilog2(confMask);\r
-                       spiHw = GET_SPI_HW_PTR(confNr);\r
+               for (; confMask; confMask &= ~(1 << ctrlNr)) {\r
+                       ctrlNr = ilog2(confMask);\r
+                       uPtr = GET_SPI_UNIT_PTR(ctrlNr);\r
+                       spiHw = uPtr->hwPtr;\r
 \r
-                       if (Spi_GetHWUnitStatus(confNr) == SPI_BUSY) {\r
+                       if (Spi_GetHWUnitStatus(ctrlNr) == SPI_BUSY) {\r
                                if (spiHw->SR.B.TXRXS) {\r
                                        // Still not done..\r
                                } else {\r
-                                       spiUnit = GET_SPI_UNIT_PTR(confNr);\r
-                                       Spi_Isr(confNr);\r
+                                       uPtr = GET_SPI_UNIT_PTR(ctrlNr);\r
+                                       Spi_Isr(uPtr);\r
                                }\r
                        }\r
                }\r
index e54be902db9ea13f918a9eccb1e551921a43933f..5883e3f363bbca5164a2e229e096e9d9b4d53fcb 100644 (file)
@@ -30,7 +30,20 @@ Memory Map:
  0x4000_0000 -> 0x4000_bfff   SRAM\r
  \r
  \r
+SPI_0\r
+  PA[12] - SIN_0   - S_OUT/BROWN\r
+  PA[13] - SOUT_0  - S_IN/ORANGE \r
+  PA[14] - SCK_9   - S_CLK/BLUE\r
+  \r
+  PB[12] - CS1_0   - CS/GREEN  (both for software and hardware CS *)\r
+                               \r
+*) Depends on setting in port.\r
+\r
+SPI_1\r
+  Never tested\r
 \r
+SPI_2\r
+  Never tested\r
 \r
   \r
   \r
index da77e0bce13efa83248fa5a1ef93250a7a09564d..9c12b92e6f6759564b4d307f862e18e00d327f06 100644 (file)
@@ -43,37 +43,75 @@ Adding a SPI EEPROM (Microship 25LC160B)
 \r
 To the left are the pins as they are names in XPC56xxMBSCH (schema for the main board, page 11 of 12) \r
 \r
-<- XPC560S ->#<---------------------- MCU ---------------------------------------->\r
-             #       PAD Func         Per     #       Shared with\r
---------------------------------------------------------------------------------------------\r
-SINB,PJ1-7   # PB[7]  23  1  SIN_0     DSPI_0  56      (SIUL/PWM/Timer)\r
-SOUTB,PJ1-8  # PB[8]  24  1  SOUT_0    DSPI_0  55      (SIUL/PWM/Timer) \r
-SCKB,PJ1-9   # PB[9]  25  1  SCK_0     DSPI_0  54      (SIUL/PWM/Timer) \r
-PCSB2,PJ1-12 # PB[12] 28  3  PCS2_0    DSPI_0  48      (SIUL/LinFlex_1/Timer)\r
-PCSB1,PJ1-11 # PB[13] 29  3  PCS1_0    DSPI_0  49      (SIUL/LinFlex_1/Timer)\r
-PCSB0,PJ1-10 # PH[4]  103 1  PCS0_0    DSPI_0  61      (SIUL/PWM/Timer/Control)   Control=CLKOUT\r
-\r
-25LC160B\r
- CS - Connect to PJ1-11\r
- /WP - High\r
- /HOLD - Low\r
- Rest of the pins are obvious\r
+<- XPC560S ->#<---------------------- MCU --->\r
+             #       PAD Func              \r
+----------------------------------------------\r
+SINB,PJ1-7   # PB[7]  23  1  SIN_0    \r
+SOUTB,PJ1-8  # PB[8]  24  1  SOUT_0    \r
+SCKB,PJ1-9   # PB[9]  25  1  SCK_0      \r
+PCSB1,PJ1-11 # PB[13] 29  3  PCS1_0    \r
+\r
+PCSB2,PJ1-12 # PB[12] 28  3  PCS2_0    NOT USED\r
+PCSB0,PJ1-10 # PH[4]  103 1  PCS0_0    NOT USED\r
+\r
+SPI MEMORY \r
+  25LC160B\r
+    CS    - Connect to PJ1-11\r
+    /WP   - High\r
+    /HOLD - Low\r
+    Rest of the pins are obvious\r
  \r
- Connected with 5V logic\r
-\r
-PORT J will have the following layout \r
-(With ArcCore internal harness and SO/SI as seen from memory):\r
-\r
+    Connected with 5V logic\r
+\r
+---------------------------------- NOTE ----------------------------------\r
+  The xPC560S EVB v1.0.1 manual is total crap in chapter "3.8 Pin Mapping"\r
+  Known errors:\r
+   PJ1\r
+     PCS0.2, should be PCS1_0     \r
+   PJ9-Port F\r
+     As I understand it should map to Port F. However, PCS1_1 is\r
+     located on PCR[78]=PF[8] on CPU is connected to PF[0] on PJ9!!     \r
+---------------------------------- NOTE ----------------------------------  \r
+    \r
+SPI_0\r
+ PORT J will have the following layout \r
+ (With ArcCore internal harness and SO/SI as seen from memory):\r
+\r
+               1-X  X-2\r
+               3-X  X-4 \r
+               5-X  X-6\r
+    SO/Brown   7-X  X-8  SI/Orange\r
+    SCK/Blue   9-X  X-10  \r
+    CS/Green  11-X  X-12\r
+              13-X  X-14\r
+              15-X  X-16  \r
+    Gnd/Black 17-X  X-18 VCC/Red   \r
+\r
+\r
+SPI_1\r
+\r
+  PCR[20]/PB[4]/SCK_1\r
+  PCR[21]/PB[5]/SOUT_1\r
+  PCR[22]/PB[6]/SIN_1\r
+\r
+               PJ5 \r
              1-X  X-2\r
              3-X  X-4\r
-             5-X  X-6\r
-  SO/Brown   7-X  X-8  SI/Orange\r
-  SCK/Blue   9-X  X-10  \r
-  CS/Green  11-X  X-12\r
+  SCK/Blue   5-X  X-6 SI/Orange\r
+    SO/Brown 7-X  X-8  \r
+             9-X  X-10  \r
+            11-X  X-12\r
             13-X  X-14\r
             15-X  X-16  \r
   Gnd/Black 17-X  X-18 VCC/Red   \r
 \r
+       PJ9\r
+             CS/Green  (See NOTE)\r
+             | \r
+ ...   6 4 2 0\r
+       7 5 3 1\r
+\r
+\r
 \r
 \r
 \r