예제 #1
0
파일: op_dfu.c 프로젝트: Crash1/TauLabs
void DataDownload(DownloadAction action) {
	if ((DeviceState == downloading)) {

		uint8_t packetSize;
		uint32_t offset;
		uint32_t partoffset;
		SendBuffer[0] = 0x01;
		SendBuffer[1] = Download;
		SendBuffer[2] = downPacketCurrent >> 24;
		SendBuffer[3] = downPacketCurrent >> 16;
		SendBuffer[4] = downPacketCurrent >> 8;
		SendBuffer[5] = downPacketCurrent;
		if (downPacketCurrent == downPacketTotal - 1) {
			packetSize = downSizeOfLastPacket;
		} else {
			packetSize = 14;
		}
		for (uint8_t x = 0; x < packetSize; ++x) {
			partoffset = (downPacketCurrent * 14 * 4) + (x * 4);
			offset = baseOfAdressType(downType) + partoffset;
			if (!flash_read(SendBuffer + (6 + x * 4), offset,
					currentProgrammingDestination)) {
				DeviceState = Last_operation_failed;
			}
		}
		downPacketCurrent = downPacketCurrent + 1;
		if (downPacketCurrent > downPacketTotal - 1) {
			DeviceState = Last_operation_Success;
			Aditionals = (uint32_t) Download;
		}
		sendData(SendBuffer + 1, 63);
	}
예제 #2
0
void DataDownload(DownloadAction action) {
	if ((DeviceState == downloading)) {

		uint8_t packetSize;
		uint32_t offset;
		uint32_t partoffset;
		SendBuffer[0] = 0x01;
		SendBuffer[1] = Download;
		SendBuffer[2] = downPacketCurrent >> 24;
		SendBuffer[3] = downPacketCurrent >> 16;
		SendBuffer[4] = downPacketCurrent >> 8;
		SendBuffer[5] = downPacketCurrent;
		if (downPacketCurrent == downPacketTotal - 1) {
			packetSize = downSizeOfLastPacket;
		} else {
			packetSize = 14;
		}
		for (uint8_t x = 0; x < packetSize; ++x) {
			partoffset = (downPacketCurrent * 14 * 4) + (x * 4);
			offset = baseOfAdressType(downType) + partoffset;
			switch (currentProgrammingDestination) {
			case Remote_flash_via_spi:
				if (downType == Descript) {
					SendBuffer[6 + (x * 4)]
							= spi_dev_desc[(uint8_t) partoffset];
					SendBuffer[7 + (x * 4)] = spi_dev_desc[(uint8_t) partoffset
							+ 1];
					SendBuffer[8 + (x * 4)] = spi_dev_desc[(uint8_t) partoffset
							+ 2];
					SendBuffer[9 + (x * 4)] = spi_dev_desc[(uint8_t) partoffset
							+ 3];
				}
				break;
			case Self_flash:
				SendBuffer[6 + (x * 4)] = *FLASH_If_Read(offset);
				SendBuffer[7 + (x * 4)] = *FLASH_If_Read(offset + 1);
				SendBuffer[8 + (x * 4)] = *FLASH_If_Read(offset + 2);
				SendBuffer[9 + (x * 4)] = *FLASH_If_Read(offset + 3);
				break;
			}

		}
		//PIOS USB_SIL_Write(EP1_IN, (uint8_t*) SendBuffer, 64);
		downPacketCurrent = downPacketCurrent + 1;
		if (downPacketCurrent > downPacketTotal - 1) {
			// STM_EVAL_LEDOn(LED2);
			DeviceState = Last_operation_Success;
			Aditionals = (uint32_t) Download;
		}
		PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB, SendBuffer + 1, 63);//FIX+1
		//PIOS SetEPTxValid(ENDP1);
	}