コード例 #1
0
ファイル: ISL12026.cpp プロジェクト: AD7ZJ/arm7lib
/**
 * Set the time of the alarm in HH:MM:SS.
 *
 * @param alarm pointer to RTCTime object that contains the alarm time
 */
void ISL12026::EnableAlarm(const RTCTime *alarm)
{
    uint8_t data[20];

    // Set the time register values.
    WriteEnable();

    I2C0::GetInstance()->Start(WriteCCR);

    data[0] = 0x00;
    data[1] = 0x00;

    // Seconds.
    data[2] = 0x80 | ConvertDecimalToBCD(alarm->seconds);

    // Minutes.
    data[3] =  0x80 | ConvertDecimalToBCD(alarm->minutes);

    // Hours.
    data[4] = 0x80 | ConvertDecimalToBCD(alarm->hours);

    data[5] = 0x00;
    data[6] = 0x00;
    data[7] = 0x00;
    data[8] = 0x00;
    data[9] = 0x00;
    data[10] = 0x00;

    I2C0::GetInstance()->Write(data, 5);
    I2C0::GetInstance()->Stop();

    WriteDisable();


    // Set the alarm and interrupt enable bits.
    WriteEnable();

    I2C0::GetInstance()->Start(WriteCCR);

    data[0] = 0x00;
    data[1] = ControlRegister;
    data[2] = ControlRegisterAlarm1 | ControlRegisterInterruptMode;

    I2C0::GetInstance()->Write(data, 3);
    I2C0::GetInstance()->Stop();

    WriteDisable();
}
コード例 #2
0
/******************************************************************************
  函数(模块)名称:void SectorErase(unsigned int SectorAddr)
  功能:	FLASH块擦除函数
  输入参数:FLASH块地址,从0开始         	              		
  输出参数: 无         	 		   		 
  其它说明: 
*******************************************************************************/
void BlockErase_SST25(unsigned int BlockAddr)
{
    unsigned char Addr0,Addr1,Addr2;
    unsigned long WritedAddr;
    WritedAddr = (unsigned long)BlockAddr;
    WritedAddr=WritedAddr<<15;
    
    Addr0=(unsigned char)WritedAddr;
    WritedAddr=WritedAddr>>8;
    
    Addr1=(unsigned char)WritedAddr;
    WritedAddr=WritedAddr>>8;
    
    Addr2=(unsigned char)WritedAddr;
    
    WriteEnable();
    SPI_CE_L;
    SPI_Send_Byte(BlorkErase_Command);//发送命令
    SPI_Send_Byte(Addr2);              //发送地址
    SPI_Send_Byte(Addr1);
    SPI_Send_Byte(Addr0);
    SPI_CE_H;
    WriteDisable();
    while(ReadStatus()&Busy_BIT);
}
コード例 #3
0
/******************************************************************************
  函数(模块)名称:void MultiByteWrite(unsigned long WriteAddr,unsigned char *WriteData,unsigned int WriteLent)
  功能:	FLASH字节写函数
  输入参数:写地址,写数据         	              		
  输出参数: 无         	 		   		 
  其它说明: 
*******************************************************************************/
void MultiByteWrite_SST25(unsigned long WriteAddr,unsigned char *WriteData,unsigned int WriteLent)
{
    unsigned char Addr0,Addr1,Addr2;
    Addr0=(unsigned char)WriteAddr;
    WriteAddr=WriteAddr>>8;
    
    Addr1=(unsigned char)WriteAddr;
    WriteAddr=WriteAddr>>8;
    
    Addr2=(unsigned char)WriteAddr;
    
    WriteEnable();
    SPI_CE_L;
    SPI_Send_Byte(AAIProgram_Command);  //发送命令
    SPI_Send_Byte(Addr2);               //发送地址
    SPI_Send_Byte(Addr1);
    SPI_Send_Byte(Addr0);
    SPI_Send_Byte(*WriteData++);        //发送数据
    SPI_CE_H;
    //__delay_cycles(50);                 // Delay;
    while(ReadStatus()&Busy_BIT);
    for(unsigned int i=0;i<WriteLent-1;i++)
    {
        SPI_CE_L;
        SPI_Send_Byte(AAIProgram_Command);    //发送命令
        SPI_Send_Byte(*WriteData++);          //发送数据
        SPI_CE_H;
        while(ReadStatus()&Busy_BIT);
    }
    WriteDisable();
    while(ReadStatus()&WEL_BIT);
    
}
コード例 #4
0
/******************************************************************************
  函数(模块)名称:void ChipErase(void)
  功能:	FLASH芯片全部擦除函数
  输入参数:无         	              		
  输出参数: 无         	 		   		 
  其它说明: 
*******************************************************************************/
void ChipErase_SST25(void)
{
    WriteEnable();
    SPI_CE_L;
    SPI_Send_Byte(ChipErase_Command);//发送命令
    SPI_CE_H;
    WriteDisable();
    while(ReadStatus()&Busy_BIT);
   
}
コード例 #5
0
// 页写
// pBuf:数据存储区
// WriteAddr:开始写入的地址(24bit)
// NumBytesToWrite:要写入的字节数(最大256),该数不应该超过该页的剩余字节数!!!
// 对于 W25P80/16,每次页写时,必须以偶数地址为起始地址,且至少写入 2 个字节数据。
// 以下实现中:
// 1) 当要写入的字节数大于该页剩余字节数时,将忽略超过的字节;
// 2) 当写入起始地址为奇地址时,则先读出前一地址数据,然后从前一地址开始写入,将此前读出的该地址数据作为第一个数据;
// 3) 当写入结束地址为偶地址时,则继续向下一地址写入无效数据 BLANK_8(等同于未写入)。
bool CSerialFlash::PageProgram(u8* pBuf, u32 WriteAddr, u32 NumBytesToWrite, u32 *NumBytesWritten)
{
	if (WriteAddr >= CHIP_SIZE)
        return false;
    
    if (NumBytesToWrite == 0)
	{
        if (NumBytesWritten)
            *NumBytesWritten = NumBytesToWrite;
    
        return true;
    }

    NumBytesToWrite = min(NumBytesToWrite, PAGE_SIZE - WriteAddr%PAGE_SIZE);
    if (NumBytesWritten)
        *NumBytesWritten = NumBytesToWrite;
    
	u8 tmp;
    u32 odd = 0;
	if (WriteAddr%2 == 1) // As to W25P80/16, Write once at least 2 bytes.
	{
        odd = 1;
        WriteAddr--;
        u32 numBytesRead = 0;
        Read(&tmp, WriteAddr, 1, &numBytesRead);
        if (numBytesRead != 1)
            return false;
	}
	
	u32 addr = WriteAddr<<8;
	RevertByteOrder32(&addr);
	
	if (!WriteEnable())
        return false;
	
	NssLow();
	m_spi.Send(FLASH_PageProgram);
	m_spi.Send(addr, 3);
	if (odd)
		m_spi.Send(tmp);
	for (int i = 0; i < NumBytesToWrite; i++)
		m_spi.Send(pBuf[i]);
	if ((odd + NumBytesToWrite)%2 == 1)
		m_spi.Send(BLANK_8);
	NssHigh();
    
	bool res = WaitForReady_WTO();
    
    if (!WriteDisable())
        return false;
    else
        return res;
}
コード例 #6
0
ファイル: ISL12026.cpp プロジェクト: AD7ZJ/arm7lib
/**
 * Disable the alarm.
 */
void ISL12026::DisableAlarm()
{
    uint8_t data[4];

    // Set the alarm enable bit.
    WriteEnable();

    I2C0::GetInstance()->Start(WriteCCR);

    data[0] = 0x00;
    data[1] = ControlRegister;
    data[2] = 0x00;

    I2C0::GetInstance()->Write(data, 3);
    I2C0::GetInstance()->Stop();

    WriteDisable();
}
コード例 #7
0
bool CSerialFlash::SectorErase(u32 addr)
{  
	addr <<= 8;
	RevertByteOrder32(&addr);
	
    if (!WriteEnable())
        return false;
       
  	NssLow();   
    m_spi.Send(FLASH_BlockErase); 
    m_spi.Send(addr, 3);
	NssHigh();     	      
    
    bool res = WaitForReady_WTO();
  	
    if (!WriteDisable())
        return false;
    else
        return res;
}  
コード例 #8
0
ファイル: ISL12026.cpp プロジェクト: AD7ZJ/arm7lib
/**
 * Set the RTC time to the RTCTime object value.
 *
 * @param time pointer to desired time.
 */
void ISL12026::SetTime(const RTCTime *time)
{
    uint8_t data[10];

    WriteEnable();

    // Set the time register values.
    I2C0::GetInstance()->Start(WriteCCR);

    data[0] = 0x00;
    data[1] = 0x30;

    // Seconds.
    data[2] = ConvertDecimalToBCD(time->seconds);

    // Minutes.
    data[3] = ConvertDecimalToBCD(time->minutes);

    // Hours.
    data[4] = 0x80 | ConvertDecimalToBCD(time->hours);

    // Days.
    data[5] = ConvertDecimalToBCD(time->day);

    // Month.
    data[6] = ConvertDecimalToBCD(time->month);

    // Tens/ones of years.
    data[7] = ConvertDecimalToBCD(time->year % 100);

    // Day of week.
    data[8] = 0x00;

    // Thousands/hundreds of years.
    data[9] = ConvertDecimalToBCD(time->year / 100);

    I2C0::GetInstance()->Write(data, 10);
    I2C0::GetInstance()->Stop();

    WriteDisable();
}
コード例 #9
0
bool CSerialFlash::WriteSR(u8 sr)
{
	// Note: WriteEnable is a must to W25P80/16, but not to OTP.
    // This is because the SR in W25P80/16 there are some non-volatile bits,
    // while the SR in OTP are all volatile bits.
    // So, the Write operation there is life limit to SerialFlash's SR.
    if (!WriteEnable())
        return false;
	
	NssLow();
	m_spi.Send(FLASH_WriteStatusReg);
	m_spi.Send(sr);
	NssHigh();

	bool res = WaitForReady_WTO();
    
    if (!WriteDisable())
        return false;
	else
        return res;
}
コード例 #10
0
bool CSerialFlash::ChipErase(void)
{
    if (!WriteEnable())
        return false;

	NssLow();
	m_spi.Send(FLASH_ChipErase);
	NssHigh();
	
	bool res = false;
    for (int i = 0; i < 20; i++)
    {
        res = WaitForReady_WTO();
        if (res)
            break;
  	}
    if (!WriteDisable())
        return false;
    else
        return res;
}