Example #1
0
bool Isp_initSpi(void) 
{
#if defined(__PIC32MZ__)
    // 1. SDI1
    SDI1Rbits.SDI1R = 0x0b; //SDI1 = RPD14
    ANSELDbits.ANSD14 = 0;  // D14 not anolog
    PORTDbits.RD14 = 1;      // input
    TRISDbits.TRISD14 =   1; // pull-up
    // 2. SDO1
    RPD10Rbits.RPD10R = 0x05; //SDO1 = RPD10
    // 3. CS
    ANSELEbits.ANSE9 = 0;  // E9 not anolog
    TRISEbits.TRISE9 =   0; // pull-up

    clkObject.peripheralClock = 200000000/6; //200000000/6;
#endif
    drvSPIObject = DRV_SPI_Initialize(DRV_SPI_INDEX_0, (SYS_MODULE_INIT *)&initConf_1);

    drvSPIHandle = DRV_SPI_Open( DRV_SPI_INDEX_0, DRV_IO_INTENT_BLOCKING );
    if( drvSPIHandle== NULL )
    {
        //SYS_ASSERT(false, "SPI Open error");
        return false;
    }

    // Without the SPIFE bit set we can't run at 20MHz.  Not sure why as this bit
    // seems like it is only applicable in SPI frame mode, which we are not using.
//    SPI1CONSET = 0x00000200;
    return true;
}
bool DRV_WIFI_SpiInit(void)
{
    drvSPIHandle = DRV_SPI_Open(DRV_WIFI_SPI_INDEX, DRV_IO_INTENT_READWRITE|DRV_IO_INTENT_BLOCKING);
    if (drvSPIHandle == (DRV_SPI_BUFFER_HANDLE)NULL)
    {
        //WDRV_ASSERT(false, "SPI open error");
        return false;
    }

    // Without the SPIFE bit set we can't run at 20MHz.  Not sure why as this bit
    // seems like it is only applicable in SPI frame mode, which we are not using.
    //SPI1CONSET = 0x00000200;
    return true;
}
static bool Spi_Init(void)
{
    if (s_SpiHandle == NULL) {
        s_SpiHandle = DRV_SPI_Open(WDRV_SPI_INDEX, DRV_IO_INTENT_READWRITE|DRV_IO_INTENT_BLOCKING);
        if (s_SpiHandle == (DRV_SPI_BUFFER_HANDLE)NULL)
        {
            WDRV_ASSERT(false, "SPI init failed");
            return false;
        }
    }

    WDRV_SemInit(&g_wdrv_priv.dmaTxSync);
    WDRV_SemInit(&g_wdrv_priv.dmaRxSync);

    return true;
}
Example #4
0
bool Isp_initSpi(void)
{
#if defined (__32MZ2048ECH144__)

#if defined(MRF24W_IN_SPI1)
    // 1. SDI1
    SDI1Rbits.SDI1R = 0x0b; //SDI1 = RPD14
    PLIB_PORTS_PinModePerPortSelect(PORTS_ID_0, PORT_CHANNEL_D,PORTS_BIT_POS_14,PORTS_PIN_MODE_DIGITAL); // D14 not anolog
    PLIB_PORTS_PinDirectionInputSet(PORTS_ID_0, PORT_CHANNEL_D,PORTS_BIT_POS_14);                        //D14   input
    //  //PORTDbits.RD14 = 1;      // pull-up
    // 2. SDO1
    RPD10Rbits.RPD10R = 0x05; //SDO1 = RPD10

#elif defined(MRF24W_IN_SPI4)
    // 1. SDI4   = RG7
    SDI4Rbits.SDI4R = 0x01; //SDI4 = RPG7
    PLIB_PORTS_PinModePerPortSelect(PORTS_ID_0, PORT_CHANNEL_G,PORTS_BIT_POS_7,PORTS_PIN_MODE_DIGITAL);  // G7 not anolog
    PLIB_PORTS_PinDirectionInputSet(PORTS_ID_0, PORT_CHANNEL_G,PORTS_BIT_POS_7);                         //G7  input
    //PORTGbits.RG7 = 1; // pull-up

    // 2. SDO4 =RB3
    PLIB_PORTS_PinModePerPortSelect(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_3,PORTS_PIN_MODE_DIGITAL); // B3 not anolog
    RPB3Rbits.RPB3R = 0x08; //RPB8 = SDO4
#endif
    // CS port not analog
    PLIB_PORTS_PinModePerPortSelect(PORTS_ID_0, WF_CS_PORT_CHANNEL,WF_CS_BIT_POS,PORTS_PIN_MODE_DIGITAL);

#endif
    drvSPIObject = DRV_SPI_Initialize(DRV_SPI_INDEX_0, (SYS_MODULE_INIT *)&initConf_1);

    drvSPIHandle = DRV_SPI_Open( DRV_SPI_INDEX_0, DRV_IO_INTENT_BLOCKING );
    if( drvSPIHandle== NULL )
    {
        //SYS_ASSERT(false, "SPI Open error");
        return false;
    }

    // Without the SPIFE bit set we can't run at 20MHz.  Not sure why as this bit
    // seems like it is only applicable in SPI frame mode, which we are not using.
    SPI1CONSET = 0x00000200;
    return true;
}
Example #5
0
bool DRV_WIFI_SpiInit()
{
#if defined(PLIB_PORTS_ExistsPortsDirection)
    if (PLIB_PORTS_ExistsPortsDirection(PORTS_ID_0))
    {
        WF_CS_Init();
    }
#endif

    WF_CS_Deassert(); // Disable chip select before initialization

    drvSPIHandle = DRV_SPI_Open(DRV_WIFI_SPI_INDEX, DRV_IO_INTENT_READWRITE|DRV_IO_INTENT_BLOCKING);
    if (drvSPIHandle == (DRV_SPI_BUFFER_HANDLE)NULL)
    {
        //DRV_WIFI_ASSERT(false, "SPI open error");
        return false;
    }

    return true;
}
Example #6
0
void APP_Tasks ( void )
{
    switch ( appData.state )
    {
        case APP_STATE_INIT:
        {
            if(appData.status.ready)
            {
                appData.state = APP_STATE_RUN;
                break;
            }            
            if(appData.status.SPIReady==false)
            {
                appData.LED.SPIHandle = DRV_SPI_Open(DRV_SPI_INDEX_0,
                                                    DRV_IO_INTENT_EXCLUSIVE |
                                                    DRV_IO_INTENT_WRITE |
                                                    DRV_IO_INTENT_NONBLOCKING
                                               );     
                appData.status.SPIReady = ( DRV_HANDLE_INVALID != appData.LED.SPIHandle );
            }
            if(appData.status.TimerDriverReady==false)
            {
                appData.timer.driver.handle = DRV_TMR_Open(
                        DRV_TMR_INDEX_0,
                        DRV_IO_INTENT_READWRITE|DRV_IO_INTENT_EXCLUSIVE);
                appData.status.TimerDriverReady = 
                        (appData.timer.driver.handle != DRV_HANDLE_INVALID);
            }     
            if(appData.status.SPIReady && appData.status.TimerDriverReady)
            {
                appData.LED.start=0;                
                appData.state=APP_STATE_TIMER_START;
            }
            break;
        }        
        case APP_STATE_TIMER_START:
        {  
            if(DRV_TMR_AlarmRegister(appData.timer.driver.handle,
                    DRV_TMR_CounterFrequencyGet(appData.timer.driver.handle)/25,
                    true,
                    0,
                    &TimerCallback)
                )
            {                
                if(DRV_TMR_Start(appData.timer.driver.handle))
                {
                    appData.status.ready=true;
                    appData.state=APP_STATE_RUN;
                }
            }
            break;
        }        
        case APP_STATE_RUN:
        {
            if(!SendingToStrip())
            {                
                APP_TASKS_ACTIVITY_SET;
                PopulateStrip(&appData.LED);
                appData.state=APP_STATE_SEND_STRIP;
            }
            break;
        }
        case APP_STATE_SEND_STRIP:
        {
            if(appData.status.readyForNext)
            {
                appData.status.readyForNext=false;
                SendLEDStrip(&appData.LED);
                /* write each pixel out to the SPI buffer */            
                /* give the data over to the SPI system to send to the LED strip */
                appData.state=APP_STATE_WAIT;
                APP_TASKS_ACTIVITY_CLEAR;
            }
            break;
        }
        case APP_STATE_WAIT:
        {
            /* wait for the SPI transaction to finish. */
            if(SendingToStrip())
            {
                break;
            }
            appData.LED.start++;
            appData.state=APP_STATE_RUN;
            break;
        }        
        case APP_STATE_ERROR:
        {
            break;
        }
        default:
        {
            /* shouldn't get here. */
            APP_Initialize();
            break;
        }
    }
    if(appData.activityLED.blinkCount++>appData.activityLED.interval)
    {
        mActivityLEDInvert();
        appData.activityLED.blinkCount=0;
    }        
}