예제 #1
0
파일: i2c.c 프로젝트: nowhard/RVDT-DOL
static PT_THREAD(I2C_Read_Complete(struct pt *pt))//постобработка пакета
{
	PT_BEGIN(pt);
   if(i2c_channels.I2C_CHNL.channels.CRC==CRC_Check(i2c_channels.I2C_CHNL.i2c_buf,9))
   {
 	channels[11].channel_data=i2c_channels.I2C_CHNL.channels.DOL;
	channels[12].channel_data=i2c_channels.I2C_CHNL.channels.frequency;
	channels[13].channel_data=i2c_channels.I2C_CHNL.channels.mid_frequency;
	STATE_BYTE|=i2c_channels.I2C_CHNL.channels.state_byte;//обновляем байт состояния
   }
   i2c_buffer[0]=0;//не сбрасывать флаг инициализации
	
	PT_END(pt);	
}
예제 #2
0
//-----------------------------------------------------------------------------
uint8_t Send_Info(void) //using 0    //посылка информации об устройстве
{
		uint8_t    i=0;

	   //заголовок кадра---
	   TransferBuf[0]=0x00;
	   TransferBuf[1]=0xD7;
	   TransferBuf[2]=0x29;
	   //------------------
	   TransferBuf[3]=ADRESS_DEV;  // адрес узла
	   TransferBuf[4]=GET_DEV_INFO_RESP;  // код операции
	   TransferBuf[6]=STATE_BYTE;

	   for(i=0;i<20;i++)
	   {				  // записываем наименование изделия
			   if(i<DEVICE_NAME_LENGTH_SYM)
			   {
			     	TransferBuf[i+7]=DEV_NAME[i];
			   }
			   else
			   {
			   		TransferBuf[i+7]=0x00;
			   }
		}

	   for(i=0;i<5;i++)                   // записываем версию ПЗУ
	   {
	       if(i<DEVICE_VER_LENGTH_SYM)
		   {
		    	 TransferBuf[i+27]=VERSION[i];
		   }
	   }

	   TransferBuf[32]=CHANNEL_NUMBER;		   // количество каналов

	   for(i=0;i<CHANNEL_NUMBER;i++)				   // данные по каналу
       {
		  	TransferBuf[i*2+33]=((channels[i].settings.set.type)<<4)|channels[i].settings.set.modific; // байт данных
		  	TransferBuf[i*2+33+1]=0x00;							// резерв байт
	   }
	   for(i=0;i<dev_desc_len;i++)					// записываем примечание
	   {
			 TransferBuf[i+33+CHANNEL_NUMBER*2]=NOTICE[i];
	   }

	   TransferBuf[5]=28+CHANNEL_NUMBER*2+dev_desc_len;			// подсчет длины данных
	   TransferBuf[33+CHANNEL_NUMBER*2+dev_desc_len]=CRC_Check(&TransferBuf[1],32+CHANNEL_NUMBER*2+dev_desc_len); // подсчет контрольной суммы

	return (34+CHANNEL_NUMBER*2+dev_desc_len);
}
예제 #3
0
void Backup_SRAM_Write_Reg(void *backup_reg, void *source_reg,uint8_t reg_size)
{
	  uint8_t i=0;

	  uint8_t *back_crc=(uint8_t*)(BKPSRAM_BASE+sizeof(struct uks_parameters));

	  PWR_BackupAccessCmd(ENABLE);        // set PWR->CR.dbp = 1;
	  PWR_BackupRegulatorCmd(ENABLE);     // set PWR->CSR.bre = 1;

	  for(i=0;i<reg_size;i++)
	  {
		  *((uint8_t*)backup_reg+i)=*((uint8_t*)source_reg+i);
	  }

	  *back_crc=CRC_Check((uint8_t*)(uks_channels.backup_uks_params),sizeof(struct uks_parameters));
	  PWR_BackupAccessCmd(DISABLE);                     // reset PWR->CR.dbp = 0;
}
uint16_t MSPBSL_Connection::loadFile(std::string datalocation)
{
	uint16_t retValue = ACK;
	uint32_t i,j,block_start, block_end, block_offset=0, startadress, datasize, datapointer;
	uint8_t lastblock=0;
	std::string ignore = "\b\t\n\r\f\v "; //ignore those characters if they are between the strings. 
	std::string hexchars = "0123456789abcdefABCDEF";
	std::ifstream txt(datalocation.c_str()); 
	std::stringstream s;
	s << txt.rdbuf();
	std::string file = s.str();
	txt.close();
	uint16_t CRC_Return;

	MSPBSL_CRCEngine* Engine = new MSPBSL_CRCEngine("5/6xx");

	
	while(!lastblock)
	{
		//get start and end of current data block
		block_start=file.find("@", block_offset);	
		block_end=file.find_first_of("@q", block_start+1);
		block_offset=block_end;
		uint8_t* data;
		if(file[block_end] == 'q')
		{
			lastblock = 1;
		}

		//get start adress 
		i=file.find_first_of(ignore, block_start)-1;	//find last char of adress
		j=0;
		startadress=0;
		while(i != block_start) //manually calculate adress
		{
			startadress += hextoint(file[i]) * pow(double(16), int(j));
			i--;
			j++;
		}

		//parse data
		i=file.find_first_of(ignore, block_start);//put pointer after adress
		datapointer=0;
		datasize=0;
		data = new uint8_t[( block_end - block_start )];	//should be enough space, too much actually
		while(i < block_end)
		{
			if(hextoint(file[i]) == 0xFF)
			{
				i++;
				continue; //increase pointer if no hex character
			}

			//high nibble
			data[datapointer] = 16 * hextoint(file[i]);
			i++;
			//low nibble
			data[datapointer] += hextoint(file[i]);

			i++;
			datapointer++;
		}

		datasize = datapointer;
		retValue |= RX_DataBlockFast(data, startadress, datasize);
		{
			//CRC Check
			uint16_t retValue1 = retValue;
			retValue |= CRC_Check(&CRC_Return,startadress,datasize);
			retValue &= Engine->verify(data,datasize,CRC_Return);
			if (retValue == retValue1) printf("%s\n","CRC verification block was completed");
			//CRC Check

		}
		delete[] data;

	}//parser mainloop

	delete Engine;
	return retValue;
}