Example #1
0
BYTE PHYGetShortRAMAddr(BYTE address)
{
    BYTE toReturn;
    	
    #if defined(__C30__)
        IntStatus.CCP2IntF = RFIE;
        RFIE = 0;
    	PHY_CS = 0;
    	SPIPut((address<<1)&0b01111110);
        toReturn = SPIGet();
        PHY_CS = 1;
        RFIE = IntStatus.CCP2IntF;
    #else	
        IntStatus.CCP2IntF = RFIE;
        RFIE = 0;
        PHY_CSn = 0;
        NOP();
        SPIPut((address<<1)&0b01111110);
        toReturn = SPIGet();
        NOP();
        PHY_CSn = 1;
        RFIE = IntStatus.CCP2IntF;
    #endif    
    return toReturn;
}
Example #2
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);
}
Example #3
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);
}
Example #4
0
/************************************************************************
* Function: void SST25WriteByte(BYTE data, DWORD address)                                           
*                                                                       
* Overview: this function writes a byte to the address specified
*                                                                       
* Input: data to be written and address
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void SST25WriteByte(BYTE data, DWORD address)
{
   // SST25SectorErase(address);
	//DelayMs(100);	
    SST25WriteEnable();
    SST25SSLow();

    SPIPut(SST25_CMD_WRITE);
    SPIGet();

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

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

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

    SPIPut(data);
    SPIGet();

    SST25SSHigh();

    // Wait for write end
    while(SST25IsWriteBusy());
}
Example #5
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());
}
Example #6
0
BYTE PHYGetLongRAMAddr(WORD address)
{
    BYTE toReturn;
    
    #if defined(__C30__)
        IntStatus.CCP2IntF = RFIE;
        RFIE = 0;
    	PHY_CS = 0;
        SPIPut(((address>>3)&0b01111111)|0x80);
        SPIPut(((address<<5)&0b11100000));
        toReturn = SPIGet();
        PHY_CS = 1;	
        RFIE = IntStatus.CCP2IntF;
    #else    
        IntStatus.CCP2IntF = RFIE;
        RFIE = 0;
        PHY_CSn = 0;
        NOP();
        SPIPut(((address>>3)&0b01111111)|0x80);
        SPIPut(((address<<5)&0b11100000));
        toReturn = SPIGet();
        NOP();
        PHY_CSn = 1;
        RFIE = IntStatus.CCP2IntF;
    #endif    
    return toReturn;
}
Example #7
0
File: hal_radio.c Project: gxp/node
uint16  CC2420_ReadRegister(uint8 addr)
{
	uint16 data;
	uint8 status;
	MAKE_CC_CS_LOW();
	status = SPIPut(addr | 0x40);
	data = SPIGet();
	data = (data<<8) | SPIGet();
	MAKE_CC_CS_HIGH();
	return data;
}
Example #8
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());
}
Example #9
0
/************************************************************************
* Function: void SST25ResetWriteProtection()
*                                                                       
* Overview: this function reset write protection bits
*                                                                       
* Input: none                                                     
*                                                                       
* Output: none
*                                                                       
************************************************************************/
void SST25ResetWriteProtection(void)
{
#if defined(USE_M25P80)    
    uint8_t status;
#endif

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

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


    SST25CSLow();

    SPIPut(spiInitData.spiId, SST25_CMD_WRSR);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, 0);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SST25CSHigh();
 //   SPIUnLock(spiInitData.spiId);

    // Wait for write end
    while(SST25IsWriteBusy());
}
Example #10
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;

    SST25SSLow();
    SPIPut(SST25_CMD_RDSR);
    SPIGet();

    SPIPut(0);
    temp = SPIGet();
    SST25SSHigh();

    return (temp & 0x01);
}
Example #11
0
/************************************************************************
* Function: MCHP25LC256ReadStatus()                                          
*                                                                       
* Overview: this function reads status register
*                                                                       
* Input: none                                                          
*                                                                       
* Output: status register value
*                                                                       
************************************************************************/
union _MCHP25LC256Status_ MCHP25LC256ReadStatus(void)
{
    BYTE    temp;

    MCHP25LC256CSLow();
    SPIPut(MCHP25LC256_spi_channel, EEPROM_CMD_RDSR);
    SPIGet(MCHP25LC256_spi_channel);

    SPIPut(MCHP25LC256_spi_channel, 0);
    temp = SPIGet(MCHP25LC256_spi_channel);
    MCHP25LC256CSHigh();

    return (union _MCHP25LC256Status_)temp;
}
Example #12
0
/************************************************************************
* Function: BYTE SST25WriteArray(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
*                                                                     
************************************************************************/
uint8_t SST25WriteArray(uint32_t address, uint8_t *pData, uint16_t nCount)
{
    uint32_t   addr;
    uint8_t    *pD;
    uint16_t    counter;
#if defined(USE_M25P80)    
    uint8_t status;
#endif

    addr = address;
    pD = pData;

    // WRITE
    for(counter = 0; counter < nCount; counter++)
    {
        SST25WriteByte(*pD++, addr++);
    }

#if defined(USE_M25P80)

    // check status of Write in Progress
    // wait for BULK ERASE to be done
    SST25CSLow();
    SPIPut(spiInitData.spiId, SST25_CMD_RDSR);
    SPIGet(spiInitData.spiId);
    while(1)
    {
        SPIPut(spiInitData.spiId, 0);
        status = (SPIGet(spiInitData.spiId)& SST25_WIP_STATUS);
        if ((status & SST25_WIP_STATUS) == 0)
            break;
    }

    SST25CSHigh();
	
#endif

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

    return (1);
}
Example #13
0
/************************************************************************
* Function: BYTE SST25WriteArray(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 SST25WriteArray(DWORD address, BYTE *pData, WORD nCount)
{
    DWORD   addr;
    BYTE    *pD;
    WORD    counter;
#if defined(USE_M25P80)    
    BYTE status;
#endif

    addr = address;
    pD = pData;

    // WRITE
    for(counter = 0; counter < nCount; counter++)
    {
        SST25WriteByte(*pD++, addr++);
    }

#if defined(USE_M25P80)

    // check status of Write in Progress
    // 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

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

    return (1);
}
Example #14
0
/************************************************************************
* Function: MCHP25LC256WriteEnable()                                         
*                                                                       
* Overview: this function allows write/erase MCHP25LC256. Must be called  
* before every write/erase command.                                         
*                                                                       
* Input: none                                                          
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void MCHP25LC256WriteEnable(void)
{
    MCHP25LC256CSLow();
    SPIPut(MCHP25LC256_spi_channel, EEPROM_CMD_WREN);
    SPIGet(MCHP25LC256_spi_channel);
    MCHP25LC256CSHigh();
}
Example #15
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)
{
    SST25SSLow();
    SPIPut(SST25_CMD_WREN);
    SPIGet();
    SST25SSHigh();
}
Example #16
0
/************************************************************************
* Function: void SST25ResetWriteProtection()
*                                                                       
* Overview: this function reset write protection bits
*                                                                       
* Input: none                                                     
*                                                                       
* Output: none
*                                                                       
************************************************************************/
void SST25ResetWriteProtection(void)
{
    SST25SSLow();

    SPIPut(SST25_CMD_EWSR);
    SPIGet();

    SST25SSHigh();

    SST25SSLow();

    SPIPut(SST25_CMD_WRSR);
    SPIGet();

    SPIPut(0);
    SPIGet();

    SST25SSHigh();
}
Example #17
0
/************************************************************************
* Function: BYTE MCHP25LC256ReadByte(WORD address)             
*                                                                       
* Overview: this function reads a byte from the address specified         
*                                                                       
* Input: address                                                     
*                                                                       
* Output: data read
*                                                                       
************************************************************************/
BYTE MCHP25LC256ReadByte(WORD address)
{
    BYTE    temp;
    MCHP25LC256CSLow();

    SPIPut(MCHP25LC256_spi_channel, EEPROM_CMD_READ);
    SPIGet(MCHP25LC256_spi_channel);

    SPIPut(MCHP25LC256_spi_channel, ((WORD_VAL) address).v[1]);
    SPIGet(MCHP25LC256_spi_channel);

    SPIPut(MCHP25LC256_spi_channel, ((WORD_VAL) address).v[0]);
    SPIGet(MCHP25LC256_spi_channel);

    SPIPut(MCHP25LC256_spi_channel, 0);
    temp = SPIGet(MCHP25LC256_spi_channel);

    MCHP25LC256CSHigh();
    return (temp);
}
Example #18
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);
}
Example #19
0
File: hal_radio.c Project: gxp/node
void CC2420_FlushRxFIFO()
{
	MAKE_CC_CS_LOW();
	SPIPut(CC2420_RXFIFO | 0x40);
	SPIGet();
	MAKE_CC_CS_HIGH();
	MAKE_CC_CS_LOW();
	SPIPut(CC2420_SFLUSHRX);
    SPIPut(CC2420_SFLUSHRX);
    MAKE_CC_CS_HIGH();
}
Example #20
0
/************************************************************************
* Function: void MCHP25LC256ReadArray(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 MCHP25LC256ReadArray(WORD address, BYTE *pData, WORD nCount)
{
    MCHP25LC256CSLow();

    SPIPut(MCHP25LC256_spi_channel, EEPROM_CMD_READ);
    SPIGet(MCHP25LC256_spi_channel);

    SPIPut(MCHP25LC256_spi_channel, ((WORD_VAL) address).v[1]);
    SPIGet(MCHP25LC256_spi_channel);

    SPIPut(MCHP25LC256_spi_channel, ((WORD_VAL) address).v[0]);
    SPIGet(MCHP25LC256_spi_channel);

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

    MCHP25LC256CSHigh();
}
Example #21
0
/*********************************************************************
* Function:         void ReadMacAddress()
*
* PreCondition:     none
*
* Input:		    none
*
* Output:		    Reads MAC Address from MAC Address EEPROM
*
* Side Effects:	    none
*
* Overview:		    Uses the MAC Address from the EEPROM for addressing
*
* Note:			    
**********************************************************************/
void ReadMacAddress(void)
{
    RF_EEnCS_TRIS = 0;
    {
        uint8_t    Address0, Address1, Address2;
        RF_EEnCS = 0;
        SPIPut(0x03);   //Read Sequence to EEPROM
        SPIPut(0xFA);   //MAC address Start byte
        Address0 = SPIGet();
        Address1 = SPIGet();
        Address2 = SPIGet();
        RF_EEnCS = 1;
        if((Address0 == 0x00) && (Address1 == 0x04) && (Address2 == 0xA3))  //Compare the value against Microchip's OUI
        {
            RF_EEnCS = 0;
            SPIPut(0x03);
            SPIPut(0xFD);
            switch(MY_ADDRESS_LENGTH)
            {
            	case 8: myLongAddress[7] = 0x00;
                case 7: myLongAddress[6] = 0x04;
                case 6: myLongAddress[5] = 0xA3;
                case 5: myLongAddress[4] = 0xFF;
                case 4: myLongAddress[3] = 0xFE;
                case 3: myLongAddress[2] = SPIGet();
                case 2: myLongAddress[1] = SPIGet();
                case 1: myLongAddress[0] = SPIGet();
                        break;
                default: break;
            }
            RF_EEnCS = 1;
        }
    }
}
Example #22
0
/************************************************************************
* Function: void MCHP25LC256WriteByte(BYTE data, WORD address)                                           
*                                                                       
* Overview: this function writes a byte to the address specified
*                                                                       
* Input: data to be written and address
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void MCHP25LC256WriteByte(BYTE data, WORD address)
{
    MCHP25LC256WriteEnable();
    MCHP25LC256CSLow();

    SPIPut(MCHP25LC256_spi_channel, EEPROM_CMD_WRITE);
    SPIGet(MCHP25LC256_spi_channel);

    SPIPut(MCHP25LC256_spi_channel, ((WORD_VAL) address).v[1]);
    SPIGet(MCHP25LC256_spi_channel);

    SPIPut(MCHP25LC256_spi_channel, ((WORD_VAL) address).v[0]);
    SPIGet(MCHP25LC256_spi_channel);

    SPIPut(MCHP25LC256_spi_channel, data);
    SPIGet(MCHP25LC256_spi_channel);

    MCHP25LC256CSHigh();

    // Wait for write end
    while(MCHP25LC256ReadStatus().Bits.WIP);
}
Example #23
0
  void EEPROMRead(uint8_t *dest, uint8_t addr, uint8_t count)
  {   
      EE_nCS = 0;
      SPIPut(SPI_READ);
      SPIPut(addr);
      while( count )
      {
          *dest++ = SPIGet();
          count--;
      }
      EE_nCS = 1;     
 
  }
Example #24
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);
}
Example #25
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;
    SST25SSLow();

    SPIPut(SST25_CMD_READ);
    SPIGet();

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

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

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

    SPIPut(0);
    temp = SPIGet();

    SST25SSHigh();
    return (temp);
}
Example #26
0
/************************************************************************
* Function: void SST25ChipErase(void)
*                                                                       
* Overview: chip erase
*                                                                       
* Input: none
*                                                                       
************************************************************************/
void SST25ChipErase(void)
{
    SST25WriteEnable();

    SST25SSLow();

    SPIPut(SST25_CMD_ERASE);
    SPIGet();

    SST25SSHigh();

    // Wait for write end
    while(SST25IsWriteBusy());
}
Example #27
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();
    SST25SSLow();

    SPIPut(SST25_CMD_SER);
    SPIGet();

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

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

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

    SST25SSHigh();

    // Wait for write end
    DelayMs(100);
    while(SST25IsWriteBusy());
}
Example #28
0
File: hal_radio.c Project: gxp/node
uint8  CC2420_ReadRxFIFO(uint8 *length, uint8* data)
{
	uint8 status;
	uint8 i;

	status = CC2420_StrobCmd(CC2420_SNOP);
	// if the OSC is not stable yet
	if(status < 0x40) 
	{
		CC2420_Restart();
		return status;
	}
	MAKE_CC_CS_LOW();
	status = SPIPut(CC2420_RXFIFO | 0x40);
	*length = SPIGet();
	if(*length > 127)
	{
		MAKE_CC_CS_HIGH();
		MAKE_CC_CS_LOW();
		SPIPut(CC2420_SFLUSHRX);
        SPIPut(CC2420_SFLUSHRX);
        MAKE_CC_CS_HIGH();
        *length = 128;
        return status;
	}
	if (*length > 0)
	{
		for(i=0; i<*length; i++)
		{
			data = SPIGet();
			//UART_Put(data);
		}
	}
	MAKE_CC_CS_HIGH();
	return status;
}
Example #29
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)
{
    SST25SSLow();

    SPIPut(SST25_CMD_READ);
    SPIGet();

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

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

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

    while(nCount--)
    {
        SPIPut(0);
        *pData++ = SPIGet();
    }

    SST25SSHigh();
}
Example #30
0
    void NVMRead (BYTE *dest, WORD  src, BYTE count)
    {
        #if !defined(__C30__)
        BYTE oldGIEH;
        #endif
        
        #ifdef ENABLE_DEBUG
            ConsolePut('r');
            PrintChar( (BYTE)(((WORD)src>>8)&0xFF) );
            PrintChar( (BYTE)((WORD)src&0xFF) );
            ConsolePut('-');
            PrintChar( count );
        #endif
        #if !defined(__C30__)
            oldGIEH = 0;
            if ( INTCONbits.GIEH )
            {
                oldGIEH = 1;
            }
            INTCONbits.GIEH = 0;
        #endif

        SPISelectEEPROM();
        SPIPut( SPIREAD );
        SPIPut( (BYTE)(((WORD)src>>8) & 0xFF) );
        SPIPut( (BYTE)((WORD)src & 0xFF) );
        while( count )
        {
            *dest = SPIGet();
            #ifdef ENABLE_DEBUG
            #endif
            dest++;
            count--;
        }
        SPIUnselectEEPROM();

        #if !defined(__C30__)
            if (oldGIEH)
            {
                INTCONbits.GIEH = 1;
            }
        #endif

        #ifdef ENABLE_DEBUG
            ConsolePutROMString((ROM char * const)"\r\n");
        #endif
    }