Exemplo n.º 1
0
/************************************************************************
* Function: MCHP25AA02E48Init                                                  
*                                                                       
* Overview: this function setup SPI and IOs connected to EEPROM
*                                                                       
* Input: none                                                          
*                                                                       
* Output: none
*                                                                       
************************************************************************/
void MCHP25AA02E48Init(DRV_SPI_INIT_DATA *pInitData)
{
    // initialize the SPI channel to be used
    // SPI_CHANNEL_USED is defined in the hardware profile
    DRV_SPI_Initialize(pInitData->channel, pInitData);
    memcpy(&eepromInitData, pInitData, sizeof(DRV_SPI_INIT_DATA));
}
Exemplo n.º 2
0
/************************************************************************
* Function: void MCHP25AA02E48WriteByte(BYTE data, WORD address)                                           
*                                                                       
* Overview: this function writes a byte to the address specified
*                                                                       
* Input: data to be written and address
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void MCHP25AA02E48WriteByte(BYTE data, WORD address)
{
    MCHP25AA02E48WriteEnable();

    while(!DRVSPILock(eepromInitData.channel))
        ;

    DRV_SPI_Initialize(eepromInitData.channel, (DRV_SPI_INIT_DATA *)&eepromInitData);

    MCHP25AA02E48CSLow();

    DRVSPIPut(eepromInitData.channel, EEPROM_CMD_WRITE);
    DRVSPIGet(eepromInitData.channel);

    DRVSPIPut(eepromInitData.channel, ((WORD_VAL) address).v[0]);
    DRVSPIGet(eepromInitData.channel);

    DRVSPIPut(eepromInitData.channel, data);
    DRVSPIGet(eepromInitData.channel);

    MCHP25AA02E48CSHigh();

    DRVSPIUnLock(eepromInitData.channel);

    // Wait for write end
    while(MCHP25AA02E48ReadStatus().Bits.WIP);
}
Exemplo n.º 3
0
/************************************************************************
* Function: MCHP25LC256Init                                                  
*                                                                       
* Overview: this function setup SPI and IOs connected to EEPROM
*                                                                       
* Input: none                                                          
*                                                                       
* Output: none
*                                                                       
************************************************************************/
void MCHP25LC256Init(DRV_SPI_INIT_DATA *pInitData)
{
    // initialize the SPI channel to be used
    // SPI_CHANNEL_USED is defined in the hardware profile
    DRV_SPI_Initialize(pInitData->channel, pInitData);
    MCHP25LC256_spi_channel = pInitData->channel;
}
Exemplo n.º 4
0
/************************************************************************
* Function: void SST25ReadArray(DWORD address, BYTE* pData, nCount)
*                                                                       
* Overview: this function reads data into buffer specified
*                                                                       
* Input: flash memory address, pointer to the data buffer, data number
*                                                                       
************************************************************************/
void SST25ReadArray(DWORD address, BYTE *pData, WORD nCount)
{
    while(!SPILock(spiInitData.channel))
        ;

    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);

    SST25CSLow();

    SPIPut(spiInitData.channel, SST25_CMD_READ);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[2]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[1]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[0]);
    SPIGet(spiInitData.channel);

    while(nCount--)
    {
        SPIPut(spiInitData.channel, 0);
        *pData++ = SPIGet(spiInitData.channel);
    }

    SST25CSHigh();
    SPIUnLock(spiInitData.channel);
}
Exemplo n.º 5
0
/************************************************************************
* Function: BYTE MCHP25AA02E48ReadByte(WORD address)             
*                                                                       
* Overview: this function reads a byte from the address specified         
*                                                                       
* Input: address                                                     
*                                                                       
* Output: data read
*                                                                       
************************************************************************/
BYTE MCHP25AA02E48ReadByte(WORD address)
{
    BYTE    temp;
    
    
    while(!DRVSPILock(eepromInitData.channel))
        ;

    DRV_SPI_Initialize(eepromInitData.channel, (DRV_SPI_INIT_DATA *)&eepromInitData);

    MCHP25AA02E48CSLow();

    DRVSPIPut(eepromInitData.channel, EEPROM_CMD_READ);
    DRVSPIGet(eepromInitData.channel);

    DRVSPIPut(eepromInitData.channel, ((WORD_VAL) address).v[0]);
    DRVSPIGet(eepromInitData.channel);

    DRVSPIPut(eepromInitData.channel, 0);
    temp = DRVSPIGet(eepromInitData.channel);

    MCHP25AA02E48CSHigh();
    DRVSPIUnLock(eepromInitData.channel);

    return (temp);
}
Exemplo n.º 6
0
/************************************************************************
* Function: void SST25SectorErase(DWORD address)                                           
*                                                                       
* Overview: this function erases a 4Kb sector
*                                                                       
* Input: address within sector to be erased
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void SST25SectorErase(DWORD address)
{
    SST25WriteEnable();
    
    while(!SPILock(spiInitData.channel))
        ;

    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);

    SST25CSLow();

    SPIPut(spiInitData.channel, SST25_CMD_SER);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[2]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[1]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[0]);
    SPIGet(spiInitData.channel);

    SST25CSHigh();
    SPIUnLock(spiInitData.channel);

    // Wait for write end
    while(SST25IsWriteBusy());
}
Exemplo n.º 7
0
/******************************************************************************
  Function:
    void DRV_TCON_SPI_Initialize( const SYS_MODULE_INIT * const init )

  Summary:
    Initializes hardware and data for the given module

  Description:
    This routine initializes hardware for the instance of the NVM module,
    using the hardware initialization given data.  It also initializes all
    necessary internal data.

  Parameters:
    pInitData - Pointer to the data structure containing all data
                necessary to initialize the hardware. This pointer may
                be null if no data is required and static initialization
                values are to be used.

  Returns:
    None
******************************************************************************/
void DRV_TCON_SPI_Initialize(DRV_SPI_INIT_DATA *pInitData)
{
    // initialize the SPI channel to be used
    DRV_SPI_Initialize(pInitData);
    memcpy(&spiInitData, pInitData, sizeof(DRV_SPI_INIT_DATA));

}
Exemplo n.º 8
0
/******************************************************************************
  Function:
    void DRV_NVM_M25P80_SectorErase( uint32_t address )

  Summary:
    Erase the sector specified by the given address.

  Description:
    This routine erases the sector of where the given address resides.

  Parameters:
    None

  Returns:
    None
******************************************************************************/
void DRV_NVM_M25P80_SectorErase(uint32_t address)
{
    // Note: This sector erase do not check for block protection (BP [3:0]).
    //       This function undo the block protection and erases
    //       the sector of the given address.
    DRV_NVM_M25P80_WriteStatusRegister(0x00);

    while(!SPILOCK(spiInitData.channel));

    DRV_SPI_Initialize((DRV_SPI_INIT_DATA *)&spiInitData);

    DRV_NVM_M25P80_WriteEnable();

    DRV_NVM_M25P80_ChipSelectEnable();

    PUTSPIBYTE(spiInitData.channel, M25P80_CMD_SER);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS) address).uint8Address[2]);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS) address).uint8Address[1]);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS) address).uint8Address[0]);

    DRV_NVM_M25P80_ChipSelectDisable();

    SPIUNLOCK(spiInitData.channel);

    // Wait for write end
    while(DRV_NVM_M25P80_IsWriteBusy());
}
Exemplo n.º 9
0
/************************************************************************
* Function: BYTE SST25ReadByte(DWORD address)             
*                                                                       
* Overview: this function reads a byte from the address specified         
*                                                                       
* Input: address                                                     
*                                                                       
* Output: data read
*                                                                       
************************************************************************/
BYTE SST25ReadByte(DWORD address)
{
    BYTE    temp;
    
    while(!SPILock(spiInitData.channel))
        ;
    
    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);

    SST25CSLow();

    SPIPut(spiInitData.channel, SST25_CMD_READ);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[2]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[1]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[0]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, 0);
    temp = SPIGet(spiInitData.channel);

    SST25CSHigh();

    SPIUnLock(spiInitData.channel);

    return (temp);
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
/************************************************************************
* Function: SST25Init                                                  
*                                                                       
* Overview: this function setup SPI and IOs connected to SST25
*                                                                       
* Input: none                                                          
*                                                                       
* Output: none
*                                                                       
************************************************************************/
void SST25Init(DRV_SPI_INIT_DATA *pInitData)
{
    // initialize the SPI channel to be used
    // SPI_CHANNEL_USED is defined in the hardware profile
    DRV_SPI_Initialize(pInitData->channel, pInitData);
    memcpy(&spiInitData, pInitData, sizeof(DRV_SPI_INIT_DATA));

    SST25ResetWriteProtection();
}
Exemplo n.º 12
0
/************************************************************************
* Function: void SST25ResetWriteProtection()
*                                                                       
* Overview: this function reset write protection bits
*                                                                       
* Input: none                                                     
*                                                                       
* Output: none
*                                                                       
************************************************************************/
void SST25ResetWriteProtection(void)
{
#if defined(USE_M25P80)    
    BYTE status;
#endif

    while(!SPILock(spiInitData.channel))
        ;
    
    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);

    SST25CSLow();
    
    // send write enable command
    SPIPut(spiInitData.channel, SST25_CMD_EWSR);
    SPIGet(spiInitData.channel);
	
    SST25CSHigh();
	
#if defined(USE_M25P80)    
    SST25CSLow();
    // verify if the WEL bit is set high
    while(1)
    {
        SPIPut(spiInitData.channel, SST25_CMD_RDSR);
        SPIGet(spiInitData.channel);

        status = 0xFF;
        while((status & SST25_STATUS_MASK) > 0)
        {
            SPIPut(spiInitData.channel, 0);
            status = SPIGet(spiInitData.channel);
        }
        if ((status & SST25_WEL_STATUS) == SST25_WEL_STATUS)
            break;
    }
    SST25CSHigh();
#endif


    SST25CSLow();

    SPIPut(spiInitData.channel, SST25_CMD_WRSR);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, 0);
    SPIGet(spiInitData.channel);

    SST25CSHigh();
    SPIUnLock(spiInitData.channel);

    // Wait for write end
    while(SST25IsWriteBusy());
}
Exemplo n.º 13
0
/************************************************************************
* Function: SST25WriteEnable()                                         
*                                                                       
* Overview: this function allows write/erase SST25. Must be called  
* before every write/erase command.                                         
*                                                                       
* Input: none                                                          
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void SST25WriteEnable(void)
{
    while(!SPILock(spiInitData.channel))
        ;
    
    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);

    SST25CSLow();
    SPIPut(spiInitData.channel, SST25_CMD_WREN);
    SPIGet(spiInitData.channel);
    SST25CSHigh();
    SPIUnLock(spiInitData.channel);
}
Exemplo n.º 14
0
/************************************************************************
* Function: MCHP25AA02E48WriteEnable()                                         
*                                                                       
* Overview: this function allows write/erase MCHP25AA02E48. Must be called  
* before every write/erase command.                                         
*                                                                       
* Input: none                                                          
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void MCHP25AA02E48WriteEnable(void)
{
    while(!DRVSPILock(eepromInitData.channel))
        ;

    DRV_SPI_Initialize(eepromInitData.channel, (DRV_SPI_INIT_DATA *)&eepromInitData);

    MCHP25AA02E48CSLow();
    DRVSPIPut(eepromInitData.channel, EEPROM_CMD_WREN);
    DRVSPIGet(eepromInitData.channel);
    MCHP25AA02E48CSHigh();
    
    DRVSPIUnLock(eepromInitData.channel);
}
Exemplo n.º 15
0
/******************************************************************************
  Function:
    void DRV_NVM_M25P80_Read(   uint32_t address,
                                uint8_t *pData,
                                uint16_t nCount )

  Summary:
    Reads an array of bytes from the specified address.

  Description:
    This routine reads an array of bytes from the specified address location. The
    read array is saved to the location pointed to by pData. The number of bytes
    to be read is specified by nCount.

  Parameters:
    address - starting address of the array to be read
    pData   - pointer to the destination of the read array
    nCount  - specifies the number of bytes to be read

  Returns:
    None
******************************************************************************/
void DRV_NVM_M25P80_Read(uint32_t address, uint8_t *pData, uint16_t nCount)
{
    while(!SPILOCK(spiInitData.channel));

    DRV_SPI_Initialize((DRV_SPI_INIT_DATA *)&spiInitData);

    DRV_NVM_M25P80_ChipSelectEnable();

    PUTSPIBYTE(spiInitData.channel, M25P80_CMD_READ);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS) address).uint8Address[2]);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS) address).uint8Address[1]);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS) address).uint8Address[0]);

    DRV_SPI_GetBuffer(spiInitData.channel, pData, nCount);

    DRV_NVM_M25P80_ChipSelectDisable();
    SPIUNLOCK(spiInitData.channel);
}
Exemplo n.º 16
0
/******************************************************************************
  Function:
    uint8_t DRV_NVM_M25P80_Write(   uint32_t address,
                                    uint8_t *pData,
                                    uint16_t nCount )

  Summary:
    Writes an array of bytes to a specified address.

  Description:
    This routine writes the array of bytes from the location pointed to by
    pData to the given address. The number of bytes to be written is specified
    by nCount.

  Parameters:
    address - starting address of the array to be written
    pData   - pointer to the source of the array
    nCount  - specifies the number of bytes to be written

  Returns:
    1 - if the write is successful
    0 - if the write was not successful
******************************************************************************/
uint8_t DRV_NVM_M25P80_Write(uint32_t address, uint8_t *pData, uint16_t nCount)
{

    uint32_t    addr;
    uint8_t     *pD;
    uint16_t    counter, sendCount, ret = 1;

    while(!SPILOCK(spiInitData.channel));

    DRV_SPI_Initialize((DRV_SPI_INIT_DATA *)&spiInitData);

    addr = address;
    pD = pData;

    // check in case previous erase or write is still ongoing
    while(DRV_NVM_M25P80_CheckWriteInProgress() == 1);
    // send write enable command
    DRV_NVM_M25P80_WriteEnable();

    for (counter = 0; counter < nCount; )
    {
        sendCount = 256 - (addr & 0xFF);
        if (sendCount > (nCount - counter))
            sendCount = (nCount - counter);

        ret = DRV_NVM_M25P80_WriteSector(addr, pD, sendCount);
        if (ret == 0)
            break;
        else
        {
            addr    += sendCount;
            pD      += sendCount;
            counter += sendCount;
        }

    }

    SPIUNLOCK(spiInitData.channel);

    return (ret);

}
Exemplo n.º 17
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;
}
Exemplo n.º 18
0
/************************************************************************
* Function: MCHP25AA02E48ReadStatus()                                          
*                                                                       
* Overview: this function reads status register
*                                                                       
* Input: none                                                          
*                                                                       
* Output: status register value
*                                                                       
************************************************************************/
union _MCHP25AA02E48Status_ MCHP25AA02E48ReadStatus(void)
{
    BYTE    temp;

    while(!DRVSPILock(eepromInitData.channel))
        ;

    DRV_SPI_Initialize(eepromInitData.channel, (DRV_SPI_INIT_DATA *)&eepromInitData);

    MCHP25AA02E48CSLow();
    DRVSPIPut(eepromInitData.channel, EEPROM_CMD_RDSR);
    DRVSPIGet(eepromInitData.channel);

    DRVSPIPut(eepromInitData.channel, 0);
    temp = DRVSPIGet(eepromInitData.channel);
    MCHP25AA02E48CSHigh();
    DRVSPIUnLock(eepromInitData.channel);

    return (union _MCHP25AA02E48Status_)temp;
}
Exemplo n.º 19
0
/************************************************************************
* Function: BYTE SST25IsWriteBusy(void)  
*                                                                       
* Overview: this function reads status register and chek BUSY bit for write operation
*                                                                       
* Input: none                                                          
*                                                                       
* Output: non zero if busy
*                                                                       
************************************************************************/
BYTE SST25IsWriteBusy(void)
{
    BYTE    temp;

    while(!SPILock(spiInitData.channel))
        ;

    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);

    SST25CSLow();
    SPIPut(spiInitData.channel, SST25_CMD_RDSR);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, 0);
    temp = SPIGet(spiInitData.channel);
    SST25CSHigh();
    SPIUnLock(spiInitData.channel);

    return (temp & 0x01);
}
Exemplo n.º 20
0
void SYS_Initialize ( void* data )
{
    /* Core Processor Initialization */
    SYS_CLK_Initialize( NULL );
    sysObj.sysDevcon = SYS_DEVCON_Initialize(SYS_DEVCON_INDEX_0, (SYS_MODULE_INIT*)&sysDevconInit);
    SYS_DEVCON_PerformanceConfig(SYS_CLK_SystemFrequencyGet());
    SYS_DEVCON_JTAGEnable();
    SYS_PORTS_Initialize();
    sysObj.sysDma = SYS_DMA_Initialize((SYS_MODULE_INIT *)&sysDmaInit);




    /* Board Support Package Initialization */
    BSP_Initialize();

    /* Initialize Drivers */

    sysObj.drvTmr0 = DRV_TMR_Initialize(DRV_TMR_INDEX_0, (SYS_MODULE_INIT *)&drvTmr0InitData);

    SYS_INT_VectorPrioritySet(INT_VECTOR_T3, INT_PRIORITY_LEVEL1);
    SYS_INT_VectorSubprioritySet(INT_VECTOR_T3, INT_SUBPRIORITY_LEVEL0);
 
 
 
    /*** SPI Driver Index 0 initialization***/

 
    sysObj.spiObjectIdx0 = DRV_SPI_Initialize(DRV_SPI_INDEX_0, (const SYS_MODULE_INIT  * const)&drvSpi0InitData);

    /* Initialize System Services */
    SYS_INT_Initialize();  

    /* Initialize Middleware */
    /* Enable Global Interrupts */
    SYS_INT_Enable();

    /* Initialize the Application */
    LEDSCROLLER_Initialize();
}
Exemplo n.º 21
0
/******************************************************************************
  Function:
    uint8_t DRV_NVM_SST25VF064_Write(   uint32_t address,
                                        uint8_t *pData, 
                                        uint16_t nCount )

  Summary:
    Writes an array of bytes to a specified address.
    
  Description:
    This routine writes the array of bytes from the location pointed to by 
    pData to the given address. The number of bytes to be written is specified
    by nCount.

  Parameters:
    address - starting address of the array to be written
    pData   - pointer to the source of the array
    nCount  - specifies the number of bytes to be written

  Returns:
    1 - if the write is successful 
    0 - if the write was not successful
******************************************************************************/
uint8_t DRV_NVM_SST25VF064_Write(uint32_t address, uint8_t *pData, uint16_t nCount)
{

    uint32_t    addr;
    uint8_t     *pD;
    uint16_t    counter, sendCount, ret;

    while(!SPILOCK(spiInitData.channel));

    DRV_SPI_Initialize((DRV_SPI_INIT_DATA *)&spiInitData);

    addr = address;
    pD = pData;

    for (counter = 0; counter < nCount; )
    {
        sendCount = 256 - (addr & 0xFF);
        if (sendCount > (nCount - counter))
            sendCount = (nCount - counter);

        ret = DRV_NVM_SST25VF064_WriteSector(addr, pD, sendCount);
        if (ret == 0)
            break;
        else
        {
            addr    += sendCount;
            pD      += sendCount;
            counter += sendCount;
        }

    }

    SPIUNLOCK(spiInitData.channel);

    return (ret);

}
Exemplo n.º 22
0
/************************************************************************
* Function: void MCHP25AA02E48ReadArray(WORD address, BYTE* pData, nCount)
*                                                                       
* Overview: this function reads data into buffer specified
*                                                                       
* Input: flash memory address, pointer to the data buffer, data number
*                                                                       
************************************************************************/
void MCHP25AA02E48ReadArray(WORD address, BYTE *pData, WORD nCount)
{
    while(!DRVSPILock(eepromInitData.channel))
        ;

    DRV_SPI_Initialize(eepromInitData.channel, (DRV_SPI_INIT_DATA *)&eepromInitData);

    MCHP25AA02E48CSLow();

    DRVSPIPut(eepromInitData.channel, EEPROM_CMD_READ);
    DRVSPIGet(eepromInitData.channel);

    DRVSPIPut(eepromInitData.channel, ((WORD_VAL) address).v[0]);
    DRVSPIGet(eepromInitData.channel);

    while(nCount--)
    {
        DRVSPIPut(eepromInitData.channel, 0);
        *pData++ = DRVSPIGet(eepromInitData.channel);
    }

    MCHP25AA02E48CSHigh();
    DRVSPIUnLock(eepromInitData.channel);
}
Exemplo n.º 23
0
/*******************************************************************************
  Function:
    void SYS_Initialize ( void *data )

  Summary:
    Initializes the board, services, drivers, application and other modules

  Description:
    This routine initializes the board, services, drivers, application and other
    modules as configured at build time.  In a bare-metal environment (where no
    OS is supported), this routine should be called almost immediately after
    entering the "main" routine.

  Precondition:
    The C-language run-time environment and stack must have been initialized.

  Parameters:
    data        - Pointer to the system initialzation data structure containing
                  pointers to the board, system service, and driver
                  initialization routines
  Returns:
    None.

  Example:
    <code>
    SYS_INT_Initialize(NULL);
    </code>

  Remarks:
    Basic System Initialization Sequence:

    1.  Initilize minimal board services and processor-specific items
        (enough to use the board to initialize drivers and services)
    2.  Initialize all supported system services
    3.  Initialize all supported modules
        (libraries, drivers, middleware, and application-level modules)
    4.  Initialize the main (static) application, if present.

    The order in which services and modules are initialized and started may be
    important.

    For a static system (a system not using the ISP's dynamic implementation
    of the initialization and "Tasks" services) this routine is implemented
    for the specific configuration of an application.
 */
void SYS_Initialize(void* data)
{
    BSP_Initialize();

    // cache configuration
    cache_enable(0);
    SetPic32MZIoPins();

    /* Initializethe interrupt system  */
    SYS_INT_Initialize();

    /* Remap the SPI pins */
    PLIB_PORTS_RemapOutput(PORTS_ID_0, OTPUT_FUNC_SDO2, OUTPUT_PIN_RPG8);
    PLIB_PORTS_RemapInput(PORTS_ID_0, INPUT_FUNC_SDI2, INPUT_PIN_RPD7);

     /* set priority for SPI interrupt source */
    SYS_INT_VectorPrioritySet(INT_VECTOR_SPI2_TX, INT_PRIORITY_LEVEL3);
    SYS_INT_VectorPrioritySet(INT_VECTOR_SPI2_RX, INT_PRIORITY_LEVEL3);

    /* set sub-priority for SPI interrupt source */
    SYS_INT_VectorSubprioritySet(INT_VECTOR_SPI2_TX, INT_SUBPRIORITY_LEVEL1);
    SYS_INT_VectorSubprioritySet(INT_VECTOR_SPI2_RX, INT_SUBPRIORITY_LEVEL1);

    clkObject.systemClock = 200000000L;

    //Turn ON the system clock
    if(!SYS_TICK_Initialize(clkObject.systemClock, SYS_TICKS_PER_SECOND))
    {
        return;
    }

    SYS_INT_Enable();

    /* Initialize the clock system service. This is used
     * by the SPI Driver. */
    clkObject.MZperipheralClock[2] = 100000000L;
    clkObject.peripheralClock = 100000000L;
    
    /* Initialize the SPI driver */
    appDrvObjects.drvSPIObject = DRV_SPI_Initialize(DRV_SPI_INDEX_0,
            (SYS_MODULE_INIT *)&drvSPIInit);

    /* Initialize the SDCARD driver*/
    appDrvObjects.drvSDCARDObject = DRV_SDCARD_Initialize(DRV_SDCARD_INDEX_0,
            (SYS_MODULE_INIT *)&drvSDCARDInit);

    /* Initialize the SYS_FS Layer */
    SYS_FS_Initialize( (const void *) sysFATFSInit );
    
    if(!_SYS_DEBUG_INIT(SYS_DEBUG_PORT))
    {
        return;
    }

    if(!_SYS_CONSOLE_INIT(SYS_CONSOLE_PORT))
    {
        return;
    }

    if(!_SYS_RANDOM_INIT())
    {
        return;
    }

    if (!_SYS_COMMAND_INIT())
    {
        return;
    }

    if (!SYS_USERIO_Initialize(0))
    {
        return;
    }

    // TCP/IP stack initialization
    SYS_OUT_MESSAGE("TCPStack " TCPIP_STACK_VERSION "  ""                ");

    // Initialize the TCPIP stack
    if (!TCPIP_STACK_Init())
    {
       return;
    }

    APP_Initialize();

    return;

} //SYS_Initialize
Exemplo n.º 24
0
/************************************************************************
* Function: void SST25ChipErase(void)
*                                                                       
* Overview: chip erase
*                                                                       
* Input: none
*                                                                       
************************************************************************/
void SST25ChipErase(void)
{
#if defined(USE_M25P80)    
    BYTE status;
#endif

#if defined(USE_SST25VF016)
    SST25WriteEnable();
#endif

    while(!SPILock(spiInitData.channel))
        ;

    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);
    SST25CSLow();
#if defined(USE_M25P80)    
    // send write enable command
    SPIPut(spiInitData.channel, SST25_CMD_EWSR);
    SPIGet(spiInitData.channel);

    SST25CSHigh();
    Nop();
    SST25CSLow();

    // verify if the WEL bit is set high
    while(1)
    {
        SPIPut(spiInitData.channel, SST25_CMD_RDSR);
        SPIGet(spiInitData.channel);
        status = 0xFF;
        while((status & SST25_STATUS_MASK) > 0)
        {
            SPIPut(spiInitData.channel, 0);
            status = SPIGet(spiInitData.channel);
        }
        if ((status & SST25_WEL_STATUS) == SST25_WEL_STATUS)
            break;
    }
    SST25CSHigh();
#endif

    SST25CSLow();

    SPIPut(spiInitData.channel, SST25_CMD_ERASE);
    SPIGet(spiInitData.channel);

    SST25CSHigh();

#if defined (USE_M25P80)
    // wait for BULK ERASE to be done
    SST25CSLow();
    SPIPut(spiInitData.channel, SST25_CMD_RDSR);
    SPIGet(spiInitData.channel);
    while(1)
    {
        SPIPut(spiInitData.channel, 0);
        status = (SPIGet(spiInitData.channel)& SST25_WIP_STATUS);
        if ((status & SST25_WIP_STATUS) == 0)
            break;
    }

    SST25CSHigh();
#endif
    SPIUnLock(spiInitData.channel);
    
    // Wait for write end
    while(SST25IsWriteBusy());
}
Exemplo n.º 25
0
/************************************************************************
* Function: BYTE MCHP25AA02E48WriteArray(DWORD address, BYTE* pData, nCount)
*                                                                       
* Overview: this function writes a data array at the address specified
*                                                                       
* Input: flash memory address, pointer to the data array, data number
*                                                                       
* Output: return 1 if the operation was successfull
*                                                                     
************************************************************************/
BYTE MCHP25AA02E48WriteArray(DWORD address, BYTE *pData, WORD nCount)
{
    DWORD_VAL   addr;
    BYTE        *pD;
    WORD        counter;

    addr.Val = address;
    pD = pData;

    // WRITE
    MCHP25AA02E48WriteEnable();
    
    while(!DRVSPILock(eepromInitData.channel))
        ;

    DRV_SPI_Initialize(eepromInitData.channel, (DRV_SPI_INIT_DATA *)&eepromInitData);

    MCHP25AA02E48CSLow();

    DRVSPIPut(eepromInitData.channel, EEPROM_CMD_WRITE);
    DRVSPIGet(eepromInitData.channel);

    DRVSPIPut(eepromInitData.channel, addr.v[0]);
    DRVSPIGet(eepromInitData.channel);

    for(counter = 0; counter < nCount; counter++)
    {
        DRVSPIPut(eepromInitData.channel, *pD++);
        DRVSPIGet(eepromInitData.channel);
        addr.Val++;

        // check for page rollover
        if((addr.v[0] & 0x7f) == 0)
        {
            MCHP25AA02E48CSHigh();

            // Wait for completion of the write operation
            while(MCHP25AA02E48ReadStatus().Bits.WIP);

            // Start writing of the next page
            MCHP25AA02E48WriteEnable();
            MCHP25AA02E48CSLow();

            DRVSPIPut(eepromInitData.channel, EEPROM_CMD_WRITE);
            DRVSPIGet(eepromInitData.channel);

            DRVSPIPut(eepromInitData.channel, addr.v[0]);
            DRVSPIGet(eepromInitData.channel);
        }
    }

    MCHP25AA02E48CSHigh();
    DRVSPIUnLock(eepromInitData.channel);

    // Wait for write end
    while(MCHP25AA02E48ReadStatus().Bits.WIP);

    // VERIFY
    for(counter = 0; counter < nCount; counter++)
    {
        if(*pData != MCHP25AA02E48ReadByte(address))
            return (0);
        pData++;
        address++;
    }

    return (1);
}