diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-01-01 17:28:19 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-01-01 17:28:19 +0200 |
| commit | 25f5e6ddef7ef2fa0a747305847eeb4ceee5a2c9 (patch) | |
| tree | 600a6623f866d48a522406b4d93e5f213d290c61 /Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib | |
| parent | 9a3114908dd0a4f61fc959ef0f352b2b6255a652 (diff) | |
| download | Tango-25f5e6ddef7ef2fa0a747305847eeb4ceee5a2c9.tar.gz Tango-25f5e6ddef7ef2fa0a747305847eeb4ceee5a2c9.zip | |
Added tango firmware update lib.
Diffstat (limited to 'Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib')
24 files changed, 1950 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/AssemblyInfo.cpp b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/AssemblyInfo.cpp new file mode 100644 index 000000000..d56b68087 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/AssemblyInfo.cpp @@ -0,0 +1,38 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute(L"TwineFirmwareUpdateLib")]; +[assembly:AssemblyDescriptionAttribute(L"")]; +[assembly:AssemblyConfigurationAttribute(L"")]; +[assembly:AssemblyCompanyAttribute(L"")]; +[assembly:AssemblyProductAttribute(L"TwineFirmwareUpdateLib")]; +[assembly:AssemblyCopyrightAttribute(L"Copyright (c) 2017")]; +[assembly:AssemblyTrademarkAttribute(L"")]; +[assembly:AssemblyCultureAttribute(L"")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)];
\ No newline at end of file diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUDevice.cpp b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUDevice.cpp new file mode 100644 index 000000000..a2a29397f --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUDevice.cpp @@ -0,0 +1,292 @@ +#include "stdafx.h" +#include "stdio.h"; +#include "DFUDevice.h" +#include "DFUError.h" +#include "DFUException.h" +#include "ProgressForm.h" +#include "TwineDFUExtras.h" + +using namespace System::Runtime::InteropServices; +using namespace System::IO; + +namespace Tango +{ + namespace FirmwareUpdateLib + { + DFUDevice::DFUDevice() + { + TwineExtras = gcnew TwineDFUExtras(); + } + + DFUDevice::DFUDevice(tLMDFUDeviceInfo *deviceInfo, tLMDFUHandle deviceHandle) + { + devInfo = deviceInfo; + devHandle = deviceHandle; + TwineExtras = gcnew TwineDFUExtras(); + } + + DFUDevice::~DFUDevice() + { + try { + if (!_isDisposed) + { + _LMDFUDeviceClose(devHandle, FALSE); //Reset device? FALSE. + _isDisposed = true; + } + } + catch (Exception^ e) { + //Do Nothing... + } + } + + void DFUDevice::SwitchToDFUMode() + { + tLMDFUErr eRetcode = _LMDFUModeSwitch(devHandle); + _isDisposed = true; + + if (eRetcode != DFU_OK) + { + throw gcnew DFUException(eRetcode); + } + + Mode = DFUMode::DFU; + } + + void DFUDevice::ClearFlash() + { + tLMDFUErr eRetcode = _LMDFUErase(devHandle, 0, 0, true, NULL); + + if (eRetcode != DFU_OK) + { + throw gcnew DFUException(eRetcode); + } + } + + void DFUDevice::Reset() + { + tLMDFUErr eRetcode = _LMDFUDeviceClose(devHandle, TRUE); //Reset device? TRUE. + _isDisposed = true; + + if (eRetcode != DFU_OK) + { + throw gcnew DFUException(eRetcode); + } + } + + void DFUDevice::Upload(array<byte>^ bytes, ProgressCallbackDelegate^ callback) + { + tLMDFUParams *psDFU; + tLMDFUParams sDFU; + tLMDFUErr eRetcode; + + // If it supports the Tiva DFU protocol, read back + // some important parameters. + if (SupportsTivaExtensions) + { + // Read flash size parameters from the device. + eRetcode = _LMDFUParamsGet(devHandle, &sDFU); + + if (eRetcode != DFU_OK) + { + throw gcnew DFUException(eRetcode); + } + + psDFU = &sDFU; + } + else + { + // The device doesn't support the Tiva + // protocol so set the DFU parameter structure + // pointer to NULL. + psDFU = (tLMDFUParams *)0; + } + + //Create an unmanaged array of from the bytes. + pin_ptr<System::Byte> p = &bytes[0]; + unsigned char* pby = p; + unsigned char* pcFileBuf = reinterpret_cast<unsigned char*>(pby); + + //Create notification form. + IntPtr formHandle = IntPtr::Zero; + + if (callback != nullptr) + { + ProgressForm^ f = gcnew ProgressForm(callback, true); + formHandle = f->Handle; // forces the form Control to be created. + } + + //Upload the image and verify! + eRetcode = _LMDFUDownloadBin(devHandle, pcFileBuf, (unsigned long)bytes->Length, + AppStartAddress, TRUE, formHandle != IntPtr::Zero ? (HWND)formHandle.ToPointer() : NULL); + + if (eRetcode != DFU_OK) + { + throw gcnew DFUException(eRetcode); + } + } + + void DFUDevice::UploadTwineExtras(TwineDFUExtras^ extras, ProgressCallbackDelegate^ callback) + { + tLMDFUErr eRetcode; + MemoryStream^ ms = gcnew MemoryStream(); + BinaryWriter^ writer = gcnew BinaryWriter(ms, System::Text::Encoding::ASCII); + + //Write extension code. + writer->Write(EXTENSION_CODE); + + //Write date time. + writer->Write(extras->UploadDateTime->Ticks); + + //Write version. + writer->Write(extras->Version->Major); + writer->Write(extras->Version->Minor); + writer->Write(extras->Version->Build); + writer->Write(extras->Version->Revision); + + //Write Comments. + String^ fixedString = extras->Comments->PadRight(EXTENSION_COMMENTS_LENGTH, ' '); + writer->Write(fixedString->ToCharArray()); + + //Write Image size. + writer->Write(extras->ImageLength); + + array<byte>^ extraBytes = ms->ToArray(); + + delete writer; + delete ms; + + pin_ptr<System::Byte> pt = &extraBytes[0]; + unsigned char* pby2 = pt; + unsigned char* extraBuf = reinterpret_cast<unsigned char*>(pby2); + + //Create notification form. + IntPtr formHandle = IntPtr::Zero; + + if (callback != nullptr) + { + ProgressForm^ f = gcnew ProgressForm(callback, false); + formHandle = f->Handle; // forces the form Control to be created. + } + + //Upload the extra info! + eRetcode = _LMDFUDownloadBin(devHandle, extraBuf, EXTENSION_LENGTH, + FlashTopAddress - FlashBlockSize, FALSE, formHandle != IntPtr::Zero ? (HWND)formHandle.ToPointer() : NULL); + + if (eRetcode != DFU_OK) + { + throw gcnew DFUException(eRetcode); + } + } + + void DFUDevice::Download(ProgressCallbackDelegate^ callback) + { + tLMDFUParams *psDFU; + tLMDFUParams sDFU; + tLMDFUErr eRetcode; + size_t iLen; + unsigned long g_ulLength = 0; + + // If it supports the Tiva DFU protocol, read back + // some important parameters. + if (SupportsTivaExtensions) + { + // Read flash size parameters from the device. + eRetcode = _LMDFUParamsGet(devHandle, &sDFU); + + if (eRetcode != DFU_OK) + { + throw gcnew DFUException(eRetcode); + } + + psDFU = &sDFU; + } + else + { + // The device doesn't support the Tiva + // protocol so set the DFU parameter structure + // pointer to NULL. + psDFU = (tLMDFUParams *)0; + } + + //Allocate image buffer. + lastDownloadBytes = (unsigned char *)malloc(ImageLength); + + //Create notification form. + IntPtr formHandle = IntPtr::Zero; + + if (callback != nullptr) + { + ProgressForm^ f = gcnew ProgressForm(callback, false); + formHandle = f->Handle; // forces the form Control to be created. + } + + //Download image from device. + eRetcode = _LMDFUUpload(devHandle, lastDownloadBytes, AppStartAddress, ImageLength, TRUE, formHandle != IntPtr::Zero ? (HWND)formHandle.ToPointer() : NULL); + + if (eRetcode != DFU_OK) + { + throw gcnew DFUException(eRetcode); + } + } + + array<byte>^ DFUDevice::GetDownloadBytes() + { + //Create a managed array from the chars array. + IntPtr ptr(lastDownloadBytes); + array<Byte>^ bytes = gcnew array<Byte>(ImageLength); + Marshal::Copy(ptr, bytes, 0, ImageLength); + return bytes; + } + + void DFUDevice::FetchTwineExtras() + { + tLMDFUErr eRetcode; + + unsigned char *buffer; + + //Allocate image buffer. + buffer = (unsigned char *)malloc(EXTENSION_LENGTH); + + //Download extras from device. + eRetcode = _LMDFUUpload(devHandle, buffer, FlashTopAddress - FlashBlockSize, EXTENSION_LENGTH, TRUE, NULL); + + if (eRetcode == DFU_OK) + { + //Create a managed array from the chars array. + IntPtr ptr(buffer); + array<Byte>^ bytes = gcnew array<Byte>(EXTENSION_LENGTH); + Marshal::Copy(ptr, bytes, 0, EXTENSION_LENGTH); + + MemoryStream^ ms = gcnew MemoryStream(bytes); + BinaryReader^ reader = gcnew BinaryReader(ms, System::Text::Encoding::ASCII); + + bool hasExtras = reader->ReadInt32() == EXTENSION_CODE; + + if (hasExtras) + { + //Put has extras. + TwineExtras->HasExtras = true; + + //Create DateTime from ticks. + TwineExtras->UploadDateTime = gcnew DateTime(reader->ReadInt64()); + + //Create version. + TwineExtras->Version = gcnew Version(reader->ReadInt32(), reader->ReadInt32(), reader->ReadInt32(), reader->ReadInt32()); + + //Read Comments. + TwineExtras->Comments = gcnew String(reader->ReadChars(EXTENSION_COMMENTS_LENGTH)); + TwineExtras->Comments = TwineExtras->Comments->Trim(); + + //Read Image Length. + TwineExtras->ImageLength = reader->ReadInt32(); + + //Set Accurate Image Size + ImageLength = TwineExtras->ImageLength; + } + + delete reader; + delete ms; + } + } + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUDevice.h b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUDevice.h new file mode 100644 index 000000000..c5d954cb2 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUDevice.h @@ -0,0 +1,189 @@ +#include "DFUMode.h" +#include <stdio.h> +#include "stdafx.h" +#include <stdlib.h> +#include <conio.h> +#include <windows.h> +#include "lmdfu.h" +#include "lmdfuwrap.h" +#include "ProgressMode.h" +#include "TwineDFUExtras.h" + +#pragma once + +using namespace System; + +namespace Tango +{ + namespace FirmwareUpdateLib { + + /// <summary> + /// Represents the upload operation progress callback delegate. + /// </summary> + /// <param name="progressMode">The progress mode.</param> + /// <param name="current">The current.</param> + /// <param name="total">The total.</param> + public delegate void ProgressCallbackDelegate(ProgressMode progressMode, int current, int total); + + public ref class DFUDevice + { + private: + unsigned char *lastDownloadBytes; + tLMDFUDeviceInfo *devInfo; + tLMDFUHandle devHandle; + bool _isDisposed; + + public: + + /// <summary> + /// Vendor ID published in the device descriptor. + /// </summary> + property String^ VID; + /// <summary> + /// Product ID published in the device descriptor. + /// </summary> + property String^ PID; + /// <summary> + /// BCD device release number published in the device descriptor. + /// </summary> + property String^ DeviceName; + /// <summary> + /// The manufacturer name string published in the device. + /// </summary> + property String^ Manufacturer; + /// <summary> + /// The interface string published in the DFU interface descriptor. + /// </summary> + property String^ DFUInterface; + /// <summary> + /// The serial number string published in the device descriptor. + /// </summary> + property String^ SerialNumber; + /// <summary> + /// Maximum number of bytes that the device can accept per control-write transaction as published in the DFU functional descriptor. + /// </summary> + property int MaxTransfer; + /// <summary> + /// Determines the current DFU driver mode. (An update can only be applied while in DFU mode). + /// </summary> + property DFUMode Mode; + /// <summary> + /// Indicates that the device will detach and reattach automatically on receipt of the DFU_DETACH request whereas 'false' indicates that the host must issue a USB reset after the DFU_DETACH request. + /// </summary> + property bool WillDetach; + /// <summary> + /// Indicates that the device supports firmware download operations and: 'false' indicates that download is not supported. + /// </summary> + property bool ManifestTolerant; + + property bool UploadCable; + + property bool DownloadCable; + /// <summary> + ///Determines whether the DFU device supports the Tiva DFU binary protocol or false otherwise. (If not than AppStartAddress should be provided!). + /// </summary> + property bool SupportsTivaExtensions; + /// <summary> + /// The size of a flash block in bytes. + /// </summary> + property short FlashBlockSize; + /// <summary> + /// The number of blocks of flash in the device. Total flash size is NumFlashBlocks * FlashBlockSize. + /// </summary> + property short NumFlashBlocks; + /// <summary> + /// Address 1 byte above the highest location the boot loader can access. + /// </summary> + property long FlashTopAddress; + /// <summary> + /// Total flash size in bytes. + /// </summary> + property int FlashSize; + /// <summary> + /// Lowest address the boot loader can write or erase. + /// </summary> + property long AppStartAddress; + + /// <summary> + /// Image Size. + /// </summary> + property long ImageLength; + + /// <summary> + /// Optional Twine information which will be flashed to the top of the memory. + /// </summary> + property TwineDFUExtras^ TwineExtras; + + /// <summary> + /// Initializes a new instance of the <see cref="DFUDevice"/> class. + /// </summary> + DFUDevice(); + + /// <summary> + /// Finalizes an instance of the <see cref="DFUDevice"/> class. + /// </summary> + ~DFUDevice(); + + /// <summary> + /// Switch the device to DFU upgrade mode. + /// </summary> + void SwitchToDFUMode(); + + /// <summary> + /// Clears the flash. + /// </summary> + void ClearFlash(); + + /// <summary> + /// Resets the device. + /// </summary> + void Reset(); + + /// <summary> + /// Uploads the specified image bytes to the firmware via the DFU class. + /// </summary> + /// <param name="bytes">The bytes.</param> + /// <param name="callback">The progress callback.</param> + void Upload(array<byte>^ bytes, ProgressCallbackDelegate^ callback); + + /// <summary> + /// Uploads the specified twine extras to the top of the flash memory. + /// </summary> + /// <param name="extras">The extras.</param> + /// <param name="callback">The progress callback.</param> + void UploadTwineExtras(TwineDFUExtras^ extras, ProgressCallbackDelegate^ callback); + + /// <summary> + /// Downloads the existing image bytes from the firmware via the DFU class. + /// </summary> + /// <param name="callback">The progress callback.</param> + /// <returns></returns> + void Download(ProgressCallbackDelegate^ callback); + + /// <summary> + /// Gets the last download operation bytes. + /// </summary> + /// <returns></returns> + array<byte>^ GetDownloadBytes(); + + internal: + + const int EXTENSION_LENGTH = 1024; + const int EXTENSION_CODE = 1357; + const int EXTENSION_COMMENTS_LENGTH = 992; + + /// <summary> + /// Fetches the twine extras. + /// </summary> + void FetchTwineExtras(); + + /// <summary> + /// Initializes a new instance of the <see cref="DFUDevice"/> class. + /// </summary> + /// <param name="deviceInfo">The device information.</param> + /// <param name="deviceHandle">The device handle.</param> + DFUDevice(tLMDFUDeviceInfo *deviceInfo, tLMDFUHandle deviceHandle); + }; + + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUError.h b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUError.h new file mode 100644 index 000000000..2b0595829 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUError.h @@ -0,0 +1,27 @@ +#pragma once + +namespace Tango +{ + namespace FirmwareUpdateLib { + + public enum class DFUError + { + DFU_ERR_VERIFY_FAIL = -14, + DFU_ERR_CANT_VERIFY = -13, + DFU_ERR_DNLOAD_FAIL = -12, + DFU_ERR_STALL = -11, + DFU_ERR_TIMEOUT = -10, + DFU_ERR_DISCONNECTED = -9, + DFU_ERR_INVALID_SIZE = -8, + DFU_ERR_INVALID_ADDR = -7, + DFU_ERR_INVALID_FORMAT = -6, + DFU_ERR_UNSUPPORTED = -5, + DFU_ERR_UNKNOWN = -4, + DFU_ERR_NOT_FOUND = -3, + DFU_ERR_MEMORY = -2, + DFU_ERR_HANDLE = -1, + DFU_OK = 0, + }; + + } +} diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUException.cpp b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUException.cpp new file mode 100644 index 000000000..8c5eb9035 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUException.cpp @@ -0,0 +1,15 @@ +#include "stdafx.h" +#include "DFUException.h" + +using namespace System; + +namespace Tango +{ + namespace FirmwareUpdateLib + { + + DFUException::DFUException() + { + } + } +} diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUException.h b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUException.h new file mode 100644 index 000000000..e3c61c8e5 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUException.h @@ -0,0 +1,31 @@ +#include <stdio.h> +#include "stdafx.h" +#include <stdlib.h> +#include <conio.h> +#include <windows.h> +#include "lmdfu.h" +#include "lmdfuwrap.h" +#include "DFUError.h" + +#pragma once + +using namespace System; + +namespace Tango +{ + namespace FirmwareUpdateLib { + + ref class DFUException : + public Exception + { + internal: + DFUException(tLMDFUErr error) : Exception(gcnew String(_LMDFUErrorStringGet(error))) { Error = static_cast<DFUError>(error); }; + public: + property DFUError Error; + DFUException(); + DFUException(DFUError error) : Exception(error.ToString()) { Error = error; }; + DFUException(DFUError error, String^ message) : Exception(message) { Error = error; }; + }; + } +} + diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUMode.h b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUMode.h new file mode 100644 index 000000000..66f3f7352 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/DFUMode.h @@ -0,0 +1,13 @@ +#pragma once + +namespace Tango +{ + namespace FirmwareUpdateLib + { + public enum class DFUMode + { + RunTime, + DFU + }; + } +} diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/FirmwareUpdateManager.cpp b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/FirmwareUpdateManager.cpp new file mode 100644 index 000000000..556519e00 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/FirmwareUpdateManager.cpp @@ -0,0 +1,132 @@ +#include "FirmwareUpdateManager.h" +#include "lmdfu.h" +#include "lmdfuwrap.h" +#include "DFUMode.h" + +namespace Tango +{ + namespace FirmwareUpdateLib + { + void FirmwareUpdateManager::Initialize() + { + + tLMDFUErr eRetcode = _LMDFUInit(); + + if (eRetcode != DFU_OK) + { + switch (eRetcode) + { + case DFU_ERR_NOT_FOUND: + throw gcnew InvalidOperationException(DFU_ERR_NOT_FOUND_ERROR); + break; + case DFU_ERR_INVALID_ADDR: + throw gcnew InvalidOperationException(DFU_ERR_INVALID_ADDR_ERROR); + break; + default: + throw gcnew InvalidOperationException(DFU_ERR_UNKNOWN_ERROR); + break; + } + } + } + + List<DFUDevice^>^ FirmwareUpdateManager::GetAvailableDevices(bool fetchTwineExtras) + { + int iDevIndex = 0; + tLMDFUDeviceInfo devInfo; + tLMDFUHandle hHandle; + tLMDFUErr eRetcode; + unsigned short usStringLen; + char pcStringBuf[256]; + bool g_bReset = false; + + List<DFUDevice^>^ devices = gcnew List<DFUDevice^>(); + + do + { + eRetcode = _LMDFUDeviceOpen(iDevIndex, &devInfo, &hHandle); + + if (eRetcode == DFU_OK) + { + tLMDFUDeviceInfo *psDevInfo = &devInfo; + + DFUDevice^ device = gcnew DFUDevice(psDevInfo, hHandle); + + device->VID = String::Format("0x{0}", psDevInfo->usVID); + device->PID = String::Format("0x{0}", psDevInfo->usPID); + + //Device Name. + usStringLen = sizeof(pcStringBuf); + eRetcode = _LMDFUDeviceASCIIStringGet(hHandle, psDevInfo->ucProductString, + pcStringBuf, &usStringLen); + + device->DeviceName = eRetcode == DFU_OK ? gcnew String(pcStringBuf) : "Unknown"; + + //Manufacturer. + usStringLen = sizeof(pcStringBuf); + eRetcode = _LMDFUDeviceASCIIStringGet(hHandle, + psDevInfo->ucManufacturerString, + pcStringBuf, &usStringLen); + + device->Manufacturer = eRetcode == DFU_OK ? gcnew String(pcStringBuf) : "Unknown"; + + //DFU Interface. + usStringLen = sizeof(pcStringBuf); + eRetcode = _LMDFUDeviceASCIIStringGet(hHandle, + psDevInfo->ucDFUInterfaceString, + pcStringBuf, &usStringLen); + + device->DFUInterface = eRetcode == DFU_OK ? gcnew String(pcStringBuf) : "Unknown"; + + //Serial Number. + usStringLen = sizeof(pcStringBuf); + eRetcode = _LMDFUDeviceASCIIStringGet(hHandle, psDevInfo->ucSerialString, + pcStringBuf, &usStringLen); + device->SerialNumber = eRetcode == DFU_OK ? gcnew String(pcStringBuf) : "Unknown"; + + //Max bytes transfer. + device->MaxTransfer = psDevInfo->usTransferSize; + + //Current device mode. + device->Mode = psDevInfo->bDFUMode ? DFUMode::DFU : DFUMode::RunTime; + + //Supports Tiva extensions. (Good for updates) + device->SupportsTivaExtensions = psDevInfo->bSupportsTivaExtensions; + + //Attributes. + device->WillDetach = psDevInfo->ucDFUAttributes & DFU_ATTR_WILL_DETACH; + device->ManifestTolerant = psDevInfo->ucDFUAttributes & DFU_ATTR_MANIFEST_TOLERANT; + device->UploadCable = psDevInfo->ucDFUAttributes & DFU_ATTR_CAN_UPLOAD; + device->DownloadCable = psDevInfo->ucDFUAttributes & DFU_ATTR_CAN_DOWNLOAD; + + //Read device flash parameters. + tLMDFUParams sDFU; + if (device->SupportsTivaExtensions) + { + eRetcode = _LMDFUParamsGet(hHandle, &sDFU); + if (eRetcode == DFU_OK) + { + device->AppStartAddress = sDFU.ulAppStartAddr; + device->FlashTopAddress = sDFU.ulFlashTop; + device->FlashBlockSize = sDFU.usFlashBlockSize; + device->NumFlashBlocks = sDFU.usNumFlashBlocks; + device->ImageLength = device->FlashTopAddress - device->AppStartAddress; + device->FlashSize = device->FlashBlockSize * device->NumFlashBlocks; + + if (fetchTwineExtras) + { + device->FetchTwineExtras(); + } + } + } + + devices->Add(device); + } + + iDevIndex++; + + } while (eRetcode == DFU_OK); + + return devices; + } + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/FirmwareUpdateManager.h b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/FirmwareUpdateManager.h new file mode 100644 index 000000000..f176517c0 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/FirmwareUpdateManager.h @@ -0,0 +1,33 @@ +#include <stdio.h> +#include "stdafx.h" +#include <stdlib.h> +#include <conio.h> +#include <windows.h> +#include "lmdfu.h" +#include "lmdfuwrap.h" +#include "DFUDevice.h"; + +#pragma once + +using namespace System; +using namespace System::Collections; +using namespace System::Collections::Generic; + +namespace Tango +{ + namespace FirmwareUpdateLib + { + + public ref class FirmwareUpdateManager + { + //Initialization Errors + String^ DFU_ERR_NOT_FOUND_ERROR = "The driver for the USB Device Firmware Upgrade device cannot be found.\nBefore running this program, please connect the DFU device to this system\nand install the device driver when prompted by Windows. The device driver\ncan be found on the evaluation kit CD or can be found in the windows_drivers\ndirectory of your TivaWare installation.\n\n"; + String^ DFU_ERR_INVALID_ADDR_ERROR = "The driver for the USB Device Firmware Upgrade device was found but appears\nto be a version which this program does not support. Please download and\ninstall the latest device driver and example applications from the TI\nweb site to ensure that you are using compatible versions. The drivers\ncan be found in the windows_drivers directory of your TivaWare\ninstallation and the applications can be found in package \"Windows-side\nexamples for USB kits\" which may be downloaded from the web site at\nhttp://www.ti.com/software_updates.\n\n"; + String^ DFU_ERR_UNKNOWN_ERROR = "An error was reported while attempting to load the device driver for the \nUSB Device Firmware Upgrade device. If this error persists, please download\nand reinstall the latest device driver and example applications from the TI\nweb site. The drivers can be found in the windows_drivers directory of your\nTivaWare installation and the applications can be found in package\n\"Windows-side examples for USB kits\" which may be downloaded from\n"; + + public: + void Initialize(); + List<DFUDevice^>^ GetAvailableDevices(bool fetchTwineExtras); + }; + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/ProgressForm.cpp b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/ProgressForm.cpp new file mode 100644 index 000000000..25ac79e3a --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/ProgressForm.cpp @@ -0,0 +1,12 @@ +#include "stdafx.h" +#include "ProgressForm.h" + +using namespace System::Windows::Forms; + +namespace Tango +{ + namespace FirmwareUpdateLib + { + + } +} diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/ProgressForm.h b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/ProgressForm.h new file mode 100644 index 000000000..4953b7b15 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/ProgressForm.h @@ -0,0 +1,88 @@ +#include "DFUMode.h" +#include <stdio.h> +#include "stdafx.h" +#include <stdlib.h> +#include <conio.h> +#include <windows.h> +#include "lmdfu.h" +#include "lmdfuwrap.h" +#include "DFUDevice.h" +#include "ProgressMode.h" + +#pragma once + +using namespace System::Windows::Forms; + +namespace Tango +{ + namespace FirmwareUpdateLib + { + ref class ProgressForm : + public Form + { + private: + ProgressMode _mode; + int _currentTotal; + bool _verified; + bool _verifiable; + ProgressCallbackDelegate^ _callback; + + void RaiseCallback(ProgressMode mode, int current, int total) + { + if (_callback != nullptr) + { + _callback(mode, current, total); + } + } + public: + ProgressForm(ProgressCallbackDelegate^ callback, bool verifiable) + { + _verifiable = verifiable; + _callback = callback; + }; + protected: virtual void WndProc(System::Windows::Forms::Message% m) override + { + switch (m.Msg) + { + case WM_DFU_DOWNLOAD: + _verified = !_verifiable; + _mode = ProgressMode::Uploading; + _currentTotal = (int)m.WParam; + RaiseCallback(_mode, 0, _currentTotal); + break; + case WM_DFU_UPLOAD: + _verified = true; + _mode = ProgressMode::Downloading; + _currentTotal = (int)m.WParam; + RaiseCallback(_mode, 0, _currentTotal); + break; + case WM_DFU_VERIFY: + _verified = true; + _mode = ProgressMode::Verifying; + _currentTotal = (int)m.WParam; + RaiseCallback(_mode, 0, _currentTotal); + break; + case WM_DFU_COMPLETE: + if (_verified) + { + _mode = ProgressMode::Completed; + _currentTotal = (int)m.WParam; + RaiseCallback(_mode, 0, _currentTotal); + } + break; + case WM_DFU_ERROR: + _mode = ProgressMode::Error; + _currentTotal = (int)m.WParam; + RaiseCallback(_mode, 0, _currentTotal); + break; + case WM_DFU_PROGRESS: + RaiseCallback(_mode, (int)m.WParam, _currentTotal); + break; + } + + Form::WndProc(m); + } + }; + } +} + diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/ProgressMode.h b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/ProgressMode.h new file mode 100644 index 000000000..1c4d189ba --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/ProgressMode.h @@ -0,0 +1,16 @@ +#pragma once + +namespace Tango +{ + namespace FirmwareUpdateLib + { + public enum class ProgressMode + { + Uploading, + Downloading, + Verifying, + Error, + Completed, + }; + } +} diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/ReadMe.txt b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/ReadMe.txt new file mode 100644 index 000000000..677f64d62 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/ReadMe.txt @@ -0,0 +1,38 @@ +======================================================================== + DYNAMIC LINK LIBRARY : Twine.FirmwareUpdateLib Project Overview +======================================================================== + +AppWizard has created this Twine.FirmwareUpdateLib DLL for you. + +This file contains a summary of what you will find in each of the files that +make up your Twine.FirmwareUpdateLib application. + +Twine.FirmwareUpdateLib.vcxproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +Twine.FirmwareUpdateLib.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Twine.FirmwareUpdateLib.cpp + This is the main DLL source file. + +Twine.FirmwareUpdateLib.h + This file contains a class declaration. + +AssemblyInfo.cpp + Contains custom attributes for modifying assembly metadata. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/Stdafx.cpp b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/Stdafx.cpp new file mode 100644 index 000000000..d42872910 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/Stdafx.cpp @@ -0,0 +1,5 @@ +// stdafx.cpp : source file that includes just the standard includes +// Twine.FirmwareUpdateLib.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/Stdafx.h b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/Stdafx.h new file mode 100644 index 000000000..3cc4c24ef --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/Stdafx.h @@ -0,0 +1,7 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + + diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/Tango.FirmwareUpdateLib.vcxproj b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/Tango.FirmwareUpdateLib.vcxproj new file mode 100644 index 000000000..b6c273214 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/Tango.FirmwareUpdateLib.vcxproj @@ -0,0 +1,186 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <VCProjectVersion>15.0</VCProjectVersion> + <ProjectGuid>{DB79FB33-CE7A-49CF-AA89-F697E5CDB0F6}</ProjectGuid> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <Keyword>ManagedCProj</Keyword> + <RootNamespace>TwineFirmwareUpdate</RootNamespace> + <WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion> + <ProjectName>Tango.FirmwareUpdateLib</ProjectName> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v141</PlatformToolset> + <CLRSupport>true</CLRSupport> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v141</PlatformToolset> + <CLRSupport>true</CLRSupport> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v141</PlatformToolset> + <CLRSupport>true</CLRSupport> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v141</PlatformToolset> + <CLRSupport>true</CLRSupport> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)Build\Core\$(Configuration)</OutDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(SolutionDir)Build\Core\$(Configuration)</OutDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <AdditionalIncludeDirectories>..\SideChains\UpdateFirmwareLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <AdditionalDependencies /> + <AdditionalLibraryDirectories>D:\Development\TwinePrototype\Host\PcLab\SideChains\dfuprog\bin\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PrecompiledHeader>Use</PrecompiledHeader> + </ClCompile> + <Link> + <AdditionalDependencies /> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PrecompiledHeader>Use</PrecompiledHeader> + </ClCompile> + <Link> + <AdditionalDependencies /> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PrecompiledHeader>Use</PrecompiledHeader> + </ClCompile> + <Link> + <AdditionalDependencies /> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Data" /> + <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="DFUDevice.h" /> + <ClInclude Include="DFUError.h" /> + <ClInclude Include="DFUException.h" /> + <ClInclude Include="DFUMode.h" /> + <ClInclude Include="lmdfu.h" /> + <ClInclude Include="lmdfuwrap.h" /> + <ClInclude Include="ProgressForm.h" /> + <ClInclude Include="ProgressMode.h" /> + <ClInclude Include="resource.h" /> + <ClInclude Include="Stdafx.h" /> + <ClInclude Include="TwineDFUExtras.h" /> + <ClInclude Include="FirmwareUpdateManager.h" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="AssemblyInfo.cpp" /> + <ClCompile Include="DFUDevice.cpp" /> + <ClCompile Include="DFUException.cpp" /> + <ClCompile Include="lmdfuwrap.cpp" /> + <ClCompile Include="ProgressForm.cpp" /> + <ClCompile Include="Stdafx.cpp"> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> + </ClCompile> + <ClCompile Include="FirmwareUpdateManager.cpp" /> + </ItemGroup> + <ItemGroup> + <Text Include="ReadMe.txt" /> + </ItemGroup> + <ItemGroup> + <ResourceCompile Include="app.rc" /> + </ItemGroup> + <ItemGroup> + <Image Include="app.ico" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\SideChains\UpdateFirmwareLib\UpdateFirmwareLib.vcxproj"> + <Project>{cbf47870-840d-40fb-9d1a-61f4fe1b7c18}</Project> + </ProjectReference> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/Twine.FirmwareUpdate.vcxproj.filters b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/Twine.FirmwareUpdate.vcxproj.filters new file mode 100644 index 000000000..21f9becfa --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/Twine.FirmwareUpdate.vcxproj.filters @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <ClInclude Include="Stdafx.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="resource.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\SideChains\dfuprog\lmdfuwrap.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="DFUError.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="DFUDevice.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="Updater.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="DFUException.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="DFUMode.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="ProgressForm.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="ProgressMode.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="TwineDFUExtras.h"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> + <ItemGroup> + <ClCompile Include="AssemblyInfo.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="Stdafx.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\SideChains\dfuprog\lmdfuwrap.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="DFUDevice.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="Updater.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="DFUException.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="ProgressForm.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <Text Include="ReadMe.txt" /> + </ItemGroup> + <ItemGroup> + <ResourceCompile Include="app.rc"> + <Filter>Resource Files</Filter> + </ResourceCompile> + </ItemGroup> + <ItemGroup> + <Image Include="app.ico"> + <Filter>Resource Files</Filter> + </Image> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/TwineDFUExtras.h b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/TwineDFUExtras.h new file mode 100644 index 000000000..845e706d7 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/TwineDFUExtras.h @@ -0,0 +1,39 @@ +#pragma once + +using namespace System; + +namespace Tango +{ + namespace FirmwareUpdateLib + { + /// <summary> + /// Represents an optional information which will be written to the top of the + /// flash memory and can be used to save important data about the current saved image. + /// </summary> + public ref class TwineDFUExtras + { + public: + + /// <summary> + /// Determines whether the twine extras were found. + /// </summary> + property bool HasExtras; + /// <summary> + /// The date and time for the last upload operation on this device. + /// </summary> + property DateTime^ UploadDateTime; + /// <summary> + /// The version of the last uploaded image. + /// </summary> + property Version^ Version; + /// <summary> + /// Optional comments (Max 100 ASCII characters). + /// </summary> + property String^ Comments; + /// <summary> + /// The size of the last uploaded image. + /// </summary> + property int ImageLength; + }; + } +} diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/app.ico b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/app.ico Binary files differnew file mode 100644 index 000000000..789d7ccbb --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/app.ico diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/app.rc b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/app.rc Binary files differnew file mode 100644 index 000000000..eab43064f --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/app.rc diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/lmdfu.h b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/lmdfu.h new file mode 100644 index 000000000..c5a77a458 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/lmdfu.h @@ -0,0 +1,321 @@ +//***************************************************************************** +// +// lmdfu.h : main header file for the USB Device Firmware Upgrade DLL +// +// Copyright (c) 2008-2015 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.2.111 of the Tiva Firmware Development Package. +// +//***************************************************************************** + +#ifdef __cplusplus + +#pragma once + +#endif + +#include "resource.h" // main symbols + +#ifdef __cplusplus +// +// Functions exported by this DLL. +// +extern "C" { +#endif + +//**************************************************************************** +// +// Error codes returned by various API functions. +// +//**************************************************************************** +typedef enum +{ + DFU_ERR_VERIFY_FAIL = -14, + DFU_ERR_CANT_VERIFY = -13, + DFU_ERR_DNLOAD_FAIL = -12, + DFU_ERR_STALL = -11, + DFU_ERR_TIMEOUT = -10, + DFU_ERR_DISCONNECTED = -9, + DFU_ERR_INVALID_SIZE = -8, + DFU_ERR_INVALID_ADDR = -7, + DFU_ERR_INVALID_FORMAT = -6, + DFU_ERR_UNSUPPORTED = -5, + DFU_ERR_UNKNOWN = -4, + DFU_ERR_NOT_FOUND = -3, + DFU_ERR_MEMORY = -2, + DFU_ERR_HANDLE = -1, + DFU_OK = 0, +} +tLMDFUErr; + +//***************************************************************************** +// +// The current error status of the DFU device. These values are reported to +// the host in response to a USBD_DFU_REQUEST_GETSTATUS request and may be +// queried by calling LMDFUGetStatus(). +// +//***************************************************************************** +typedef enum +{ + STATUS_OK = 0, + STATUS_ERR_TARGET, + STATUS_ERR_FILE, + STATUS_ERR_WRITE, + STATUS_ERR_ERASE, + STATUS_ERR_CHECK_ERASED, + STATUS_ERR_PROG, + STATUS_ERR_VERIFY, + STATUS_ERR_ADDRESS, + STATUS_ERR_NOTDONE, + STATUS_ERR_FIRMWARE, + STATUS_ERR_VENDOR, + STATUS_ERR_USBR, + STATUS_ERR_POR, + STATUS_ERR_UNKNOWN, + STATUS_ERR_STALLEDPKT +} +tDFUStatus; + +//***************************************************************************** +// +// The size of the pcPartNumber array in tLMDFUDeviceInfo. This field contains +// a NULL terminated ASCII string containing the target part number in the +// form "lm3sxxxx" where "xxxx" is the 4 character part number. In cases where +// the part number can be represented using hexadecimal digits, it will also be +// encoded into the ulPartNumber field (which is left in the structure for +// backwards compatibility even though recent part numbers break the assumption +// that the part number can be encoded using hex). +// +//***************************************************************************** +#define NUM_PART_STRING_CHARS 10 + +//**************************************************************************** +// +// Device information as returned by LMDFUDeviceOpen(). +// +//**************************************************************************** +typedef struct +{ + unsigned short usVID; + unsigned short usPID; + unsigned short usDevice; + unsigned short usDetachTimeOut; + unsigned short usTransferSize; + unsigned char ucDFUAttributes; + unsigned char ucManufacturerString; + unsigned char ucProductString; + unsigned char ucSerialString; + unsigned char ucDFUInterfaceString; + bool bSupportsTivaExtensions; + bool bDFUMode; + unsigned long ulPartNumber; + char cRevisionMajor; + char cRevisionMinor; + char pcPartNumber[NUM_PART_STRING_CHARS]; +} +tLMDFUDeviceInfo; + +//**************************************************************************** +// +// DFU parameter information returned by LMDFUParamsGet(). +// +//**************************************************************************** +typedef struct +{ + unsigned short usFlashBlockSize; // The size of a flash block in bytes. + unsigned short usNumFlashBlocks; // The number of blocks of flash in the + // device. Total flash size is + // usNumFlashBlocks * usFlashBlockSize. + unsigned long ulFlashTop; // Address 1 byte above the highest + // location the boot loader can access. + unsigned long ulAppStartAddr; // Lowest address the boot loader can + // write or erase. +} +tLMDFUParams; + +//**************************************************************************** +// +// A handle to a DFU device. This handle is returned from a call to +// LMDFUDeviceOpen(). +// +//**************************************************************************** +typedef void *tLMDFUHandle; + +//**************************************************************************** +// +// Bit fields used in the ucDFUAttributes field of tLMDFUDeviceInfo. +// +//**************************************************************************** +#define DFU_ATTR_WILL_DETACH 0x08 +#define DFU_ATTR_MANIFEST_TOLERANT 0x04 +#define DFU_ATTR_CAN_UPLOAD 0x02 +#define DFU_ATTR_CAN_DOWNLOAD 0x01 + +//**************************************************************************** +// +// Windows Messages optionally sent during LMDFUDownload and LMDFUUpload. +// +//**************************************************************************** + +// A download operation is about to begin. The WPARAM value provides the +// number of transfers will be required to complete the operation. +// WPARAM = transfer count, LPARAM = LMDFUHandle +#define WM_DFU_DOWNLOAD (WM_USER + 0x200) + +// An upload operation is about to begin. The WPARAM value provides the +// number of transfers will be required to complete the operation. +// WPARAM = transfer count, LPARAM = LMDFUHandle +#define WM_DFU_UPLOAD (WM_USER + 0x201) + +// A verification cycle is beginning following a download. The WPARAM value +// provides the number of transfers that will be required to read back the +// downloaded image to verify that it is correct. +// WPARAM = transfer count, LPARAM = LMDFUHandle +#define WM_DFU_VERIFY (WM_USER + 0x202) + +// An erase operation about to begin. The WPARAM value provides the number of +// blocks that are to be erased. +// WPARAM = transfer count, LPARAM = LMDFUHandle +#define WM_DFU_ERASE (WM_USER + 0x203) + +// A download or upload operation has completed successfully +// WPARAM = 0, LPARAM = LMDFUHandle +#define WM_DFU_COMPLETE (WM_USER + 0x204) + +// An error was reported during the operation that was in progress. The +// operation has been aborted. +// WPARAM = 0, LPARAM = LMDFUHandle +#define WM_DFU_ERROR (WM_USER + 0x205) + +// A download, upload, erase or verify operation is in progress. This message +// provides information on the progress of the operation. The WPARAM parameter +// increments on each message until it reaches the value passed in the +// WM_DFU_ERASE, WM_DFU_DOWNLOAD, WM_DFU_UPLOAD or WM_DFU_VERIFY message sent +// at the start of the operation. +// WPARAM = transfers completed, LPARAM = LMDFUHandle +#define WM_DFU_PROGRESS (WM_USER + 0x206) + +//**************************************************************************** +// +// Exported function prototypes. +// +//**************************************************************************** +tLMDFUErr __stdcall LMDFUInit(void); +tLMDFUErr __stdcall LMDFUDeviceOpen(int iDeviceIndex, + tLMDFUDeviceInfo *psDevInfo, + tLMDFUHandle *phHandle); +tLMDFUErr __stdcall LMDFUDeviceClose(tLMDFUHandle hHandle, bool bReset); +tLMDFUErr __stdcall LMDFUDeviceStringGet(tLMDFUHandle hHandle, + unsigned char ucStringIndex, + unsigned short usLanguageID, + char *pcString, + unsigned short *pusStringLen); +tLMDFUErr __stdcall LMDFUDeviceASCIIStringGet(tLMDFUHandle hHandle, + unsigned char ucStringIndex, + char *pcString, + unsigned short *pusStringLen); +tLMDFUErr __stdcall LMDFUParamsGet(tLMDFUHandle hHandle, + tLMDFUParams *psParams); +tLMDFUErr __stdcall LMDFUIsValidImage(tLMDFUHandle hHandle, + unsigned char *pcDFUImage, + unsigned long ulImageLen, + bool *pbTivaFormat); +tLMDFUErr __stdcall LMDFUDownload(tLMDFUHandle hHandle, + unsigned char *pcDFUImage, + unsigned long ulImageLen, bool bVerify, + bool bIgnoreIDs, HWND hwndNotify); +tLMDFUErr __stdcall LMDFUDownloadBin(tLMDFUHandle hHandle, + unsigned char *pcBinaryImage, + unsigned long ulImageLen, + unsigned long ulStartAddr, + bool bVerify, HWND hwndNotify); +tLMDFUErr __stdcall LMDFUErase(tLMDFUHandle hHandle, unsigned long ulStartAddr, + unsigned long ulEraseLen, bool bVerify, + HWND hwndNotify); +tLMDFUErr __stdcall LMDFUBlankCheck(tLMDFUHandle hHandle, + unsigned long ulStartAddr, + unsigned long ulLen); +tLMDFUErr __stdcall LMDFUUpload(tLMDFUHandle hHandle, unsigned char *pcBuffer, + unsigned long ulStartAddr, + unsigned long ulImageLen, bool bRaw, + HWND hwndNotify); +tLMDFUErr __stdcall LMDFUStatusGet(tLMDFUHandle hHandle, tDFUStatus *pStatus); +tLMDFUErr __stdcall LMDFUModeSwitch(tLMDFUHandle hHandle); +char * __stdcall LMDFUErrorStringGet(tLMDFUErr eError); + +//**************************************************************************** +// +// Typedefs for each of the exported functions. This helps if applications +// want to link the DLL dynamically using LoadLibrary rather than linking +// directly to the lib file. +// +//**************************************************************************** +typedef tLMDFUErr (__stdcall *tLMDFUInit)(void); +typedef tLMDFUErr (__stdcall *tLMDFUDeviceOpen)(int iDeviceIndex, + tLMDFUDeviceInfo *psDevInfo, + tLMDFUHandle *phHandle); +typedef tLMDFUErr (__stdcall *tLMDFUDeviceClose)(tLMDFUHandle hHandle, + bool bReset); +typedef tLMDFUErr (__stdcall *tLMDFUDeviceStringGet)(tLMDFUHandle hHandle, + unsigned char ucStringIndex, + unsigned short usLanguageID, + char *pcString, + unsigned short *pusStringLen); +typedef tLMDFUErr (__stdcall *tLMDFUDeviceASCIIStringGet)(tLMDFUHandle hHandle, + unsigned char ucStringIndex, + char *pcString, + unsigned short *pusStringLen); +typedef tLMDFUErr (__stdcall *tLMDFUParamsGet)(tLMDFUHandle hHandle, + tLMDFUParams *psParams); +typedef tLMDFUErr (__stdcall *tLMDFUIsValidImage)(tLMDFUHandle hHandle, + unsigned char *pcDFUImage, + unsigned long ulImageLen, + bool *pbTivaFormat); +typedef tLMDFUErr (__stdcall *tLMDFUDownload)(tLMDFUHandle hHandle, + unsigned char *pcDFUImage, + unsigned long ulImageLen, + bool bVerify, + bool bIgnoreIDs, + HWND hwndNotify); +typedef tLMDFUErr (__stdcall *tLMDFUDownloadBin)(tLMDFUHandle hHandle, + unsigned char *pcBinaryImage, + unsigned long ulImageLen, + unsigned long ulStartAddr, + bool bVerify, + HWND hwndNotify); +typedef tLMDFUErr (__stdcall *tLMDFUErase)(tLMDFUHandle hHandle, + unsigned long ulStartAddr, + unsigned long ulEraseLen, + bool bVerify, + HWND hwndNotify); +typedef tLMDFUErr (__stdcall *tLMDFUBlankCheck)(tLMDFUHandle hHandle, + unsigned long ulStartAddr, + unsigned long ulLen); +typedef tLMDFUErr (__stdcall *tLMDFUUpload)(tLMDFUHandle hHandle, + unsigned char *pcBuffer, + unsigned long ulStartAddr, + unsigned long ulImageLen, + bool bRaw, HWND hwndNotify); +typedef tLMDFUErr (__stdcall *tLMDFUStatusGet)(tLMDFUHandle hHandle, + tDFUStatus *pStatus); +typedef char * (__stdcall *tLMDFUErrorStringGet)(tLMDFUErr eError); +typedef tLMDFUErr (__stdcall *tLMDFUModeSwitch)(tLMDFUHandle hHandle); + +#ifdef __cplusplus +} +#endif + diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/lmdfuwrap.cpp b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/lmdfuwrap.cpp new file mode 100644 index 000000000..4dc047dc5 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/lmdfuwrap.cpp @@ -0,0 +1,299 @@ +//***************************************************************************** +// +// lmdfuwrap.cpp : A thin wrapper over the lmdfu.dll library allowing it to be +// loaded dynamically rather than statically linking to its .lib +// file. +// +// Copyright (c) 2009-2017 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.4.178 of the Tiva Firmware Development Package. +// +//***************************************************************************** + +#include <windows.h> +#include "lmdfu.h" +#include "lmdfuwrap.h" + +//***************************************************************************** +// +// DLL module handle. +// +//***************************************************************************** +HINSTANCE hLMUSB = (HINSTANCE)NULL; + +//***************************************************************************** +// +// Function pointers for each DLL entry point. +// +//***************************************************************************** +tLMDFUInit pfnLMDFUInit = NULL; +tLMDFUDeviceOpen pfnLMDFUDeviceOpen = NULL; +tLMDFUDeviceClose pfnLMDFUDeviceClose = NULL; +tLMDFUDeviceStringGet pfnLMDFUDeviceStringGet = NULL; +tLMDFUDeviceASCIIStringGet pfnLMDFUDeviceASCIIStringGet = NULL; +tLMDFUParamsGet pfnLMDFUParamsGet = NULL; +tLMDFUIsValidImage pfnLMDFUIsValidImage = NULL; +tLMDFUDownload pfnLMDFUDownload = NULL; +tLMDFUDownloadBin pfnLMDFUDownloadBin = NULL; +tLMDFUErase pfnLMDFUErase = NULL; +tLMDFUBlankCheck pfnLMDFUBlankCheck = NULL; +tLMDFUUpload pfnLMDFUUpload = NULL; +tLMDFUStatusGet pfnLMDFUStatusGet = NULL; +tLMDFUErrorStringGet pfnLMDFUErrorStringGet = NULL; +tLMDFUModeSwitch pfnLMDFUModeSwitch = NULL; + +tLMDFUErr __stdcall _LMDFUInit(void) +{ + // + // Try to load the USB DLL. + // + hLMUSB = LoadLibrary(TEXT("lmdfu.dll")); + + // + // Did we find it? + // + if(hLMUSB) + { + // + // Yes - query all the entry point addresses. + // + pfnLMDFUInit = (tLMDFUInit)GetProcAddress(hLMUSB, "LMDFUInit"); + pfnLMDFUDeviceOpen = (tLMDFUDeviceOpen)GetProcAddress(hLMUSB, "LMDFUDeviceOpen"); + pfnLMDFUDeviceClose = (tLMDFUDeviceClose)GetProcAddress(hLMUSB, "LMDFUDeviceClose"); + pfnLMDFUDeviceStringGet = (tLMDFUDeviceStringGet)GetProcAddress(hLMUSB, "LMDFUDeviceStringGet"); + pfnLMDFUDeviceASCIIStringGet = (tLMDFUDeviceASCIIStringGet)GetProcAddress(hLMUSB, "LMDFUDeviceASCIIStringGet"); + pfnLMDFUParamsGet = (tLMDFUParamsGet)GetProcAddress(hLMUSB, "LMDFUParamsGet"); + pfnLMDFUIsValidImage = (tLMDFUIsValidImage)GetProcAddress(hLMUSB, "LMDFUIsValidImage"); + pfnLMDFUDownload = (tLMDFUDownload)GetProcAddress(hLMUSB, "LMDFUDownload"); + pfnLMDFUDownloadBin = (tLMDFUDownloadBin)GetProcAddress(hLMUSB, "LMDFUDownloadBin"); + pfnLMDFUErase = (tLMDFUErase)GetProcAddress(hLMUSB, "LMDFUErase"); + pfnLMDFUBlankCheck = (tLMDFUBlankCheck)GetProcAddress(hLMUSB, "LMDFUBlankCheck"); + pfnLMDFUUpload = (tLMDFUUpload)GetProcAddress(hLMUSB, "LMDFUUpload"); + pfnLMDFUStatusGet = (tLMDFUStatusGet)GetProcAddress(hLMUSB, "LMDFUStatusGet"); + pfnLMDFUErrorStringGet = (tLMDFUErrorStringGet)GetProcAddress(hLMUSB, "LMDFUErrorStringGet"); + pfnLMDFUModeSwitch = (tLMDFUModeSwitch)GetProcAddress(hLMUSB, "LMDFUModeSwitch"); + + // + // Make sure we actually queried all the expected entry points. + // + if(!pfnLMDFUInit || !pfnLMDFUDeviceOpen || !pfnLMDFUDeviceClose || + !pfnLMDFUDeviceStringGet || !pfnLMDFUDeviceASCIIStringGet || + !pfnLMDFUParamsGet || !pfnLMDFUIsValidImage || !pfnLMDFUDownload || + !pfnLMDFUDownloadBin || !pfnLMDFUErase || !pfnLMDFUBlankCheck || + !pfnLMDFUUpload || !pfnLMDFUStatusGet || !pfnLMDFUErrorStringGet || + !pfnLMDFUModeSwitch) + { + // + // We failed to query at least one entry point. Return + // DFU_ERR_INVALID_ADDR to signal to the caller that the driver + // is likely the wrong version. + // + return(DFU_ERR_INVALID_ADDR); + } + else + { + // + // We got all the expected function pointers so call the library + // init function and return it's response. + // + return(pfnLMDFUInit()); + } + } + else + { + // + // The DLL could not be found. This tends to suggest that the driver + // is not installed. Return an appropriate error code to the caller + // so that they can provide helpful information to the user. + // + return(DFU_ERR_NOT_FOUND); + } +} + +tLMDFUErr __stdcall _LMDFUDeviceOpen(int iDeviceIndex, + tLMDFUDeviceInfo *psDevInfo, + tLMDFUHandle *phHandle) +{ + if(pfnLMDFUDeviceOpen) + { + return(pfnLMDFUDeviceOpen(iDeviceIndex, psDevInfo, phHandle)); + } + + return(DFU_ERR_HANDLE); +} + +tLMDFUErr __stdcall _LMDFUDeviceClose(tLMDFUHandle hHandle, bool bReset) +{ + if(pfnLMDFUDeviceClose) + { + return(pfnLMDFUDeviceClose(hHandle, bReset)); + } + + return(DFU_ERR_HANDLE); +} + +tLMDFUErr __stdcall _LMDFUDeviceStringGet(tLMDFUHandle hHandle, + unsigned char ucStringIndex, + unsigned short usLanguageID, + char *pcString, + unsigned short *pusStringLen) +{ + if(pfnLMDFUDeviceStringGet) + { + return(pfnLMDFUDeviceStringGet(hHandle, ucStringIndex, usLanguageID, + pcString, pusStringLen)); + } + + return(DFU_ERR_HANDLE); +} + +tLMDFUErr __stdcall _LMDFUDeviceASCIIStringGet(tLMDFUHandle hHandle, + unsigned char ucStringIndex, + char *pcString, + unsigned short *pusStringLen) +{ + if(pfnLMDFUDeviceASCIIStringGet) + { + return(pfnLMDFUDeviceASCIIStringGet(hHandle, ucStringIndex, pcString, + pusStringLen)); + } + + return(DFU_ERR_HANDLE); +} + +tLMDFUErr __stdcall _LMDFUParamsGet(tLMDFUHandle hHandle, + tLMDFUParams *psParams) +{ + if(pfnLMDFUParamsGet) + { + return(pfnLMDFUParamsGet(hHandle, psParams)); + } + + return(DFU_ERR_HANDLE); +} + +tLMDFUErr __stdcall _LMDFUIsValidImage(tLMDFUHandle hHandle, + unsigned char *pcDFUImage, + unsigned long ulImageLen, + bool *pbTivaFormat) +{ + if(pfnLMDFUIsValidImage) + { + return(pfnLMDFUIsValidImage(hHandle, pcDFUImage, ulImageLen, + pbTivaFormat)); + } + + return(DFU_ERR_HANDLE); +} + +tLMDFUErr __stdcall _LMDFUDownload(tLMDFUHandle hHandle, + unsigned char *pcDFUImage, + unsigned long ulImageLen, bool bVerify, + bool bIgnoreIDs, HWND hwndNotify) +{ + if(pfnLMDFUDownload) + { + return(pfnLMDFUDownload(hHandle, pcDFUImage, ulImageLen, bVerify, + bIgnoreIDs, hwndNotify)); + } + + return(DFU_ERR_HANDLE); +} + +tLMDFUErr __stdcall _LMDFUDownloadBin(tLMDFUHandle hHandle, + unsigned char *pcBinaryImage, + unsigned long ulImageLen, + unsigned long ulStartAddr, + bool bVerify, HWND hwndNotify) +{ + if(pfnLMDFUDownloadBin) + { + return(pfnLMDFUDownloadBin(hHandle, pcBinaryImage, ulImageLen, + ulStartAddr, bVerify, hwndNotify)); + } + + return(DFU_ERR_HANDLE); +} + +tLMDFUErr __stdcall _LMDFUErase(tLMDFUHandle hHandle, unsigned long ulStartAddr, + unsigned long ulEraseLen, bool bVerify, + HWND hwndNotify) +{ + if(pfnLMDFUErase) + { + return(pfnLMDFUErase(hHandle, ulStartAddr, ulEraseLen, bVerify, + hwndNotify)); + } + + return(DFU_ERR_HANDLE); +} + +tLMDFUErr __stdcall _LMDFUBlankCheck(tLMDFUHandle hHandle, + unsigned long ulStartAddr, + unsigned long ulLen) +{ + if(pfnLMDFUBlankCheck) + { + return(pfnLMDFUBlankCheck(hHandle, ulStartAddr, ulLen)); + } + + return(DFU_ERR_HANDLE); +} + +tLMDFUErr __stdcall _LMDFUUpload(tLMDFUHandle hHandle, unsigned char *pcBuffer, + unsigned long ulStartAddr, + unsigned long ulImageLen, bool bRaw, + HWND hwndNotify) +{ + if(pfnLMDFUUpload) + { + return(pfnLMDFUUpload(hHandle, pcBuffer, ulStartAddr, ulImageLen, + bRaw, hwndNotify)); + } + + return(DFU_ERR_HANDLE); +} + +tLMDFUErr __stdcall _LMDFUStatusGet(tLMDFUHandle hHandle, tDFUStatus *pStatus) +{ + if(pfnLMDFUStatusGet) + { + return(pfnLMDFUStatusGet(hHandle, pStatus)); + } + + return(DFU_ERR_HANDLE); +} + +tLMDFUErr __stdcall _LMDFUModeSwitch(tLMDFUHandle hHandle) +{ + if(pfnLMDFUStatusGet) + { + return(pfnLMDFUModeSwitch(hHandle)); + } + + return(DFU_ERR_HANDLE); +} + +char * __stdcall _LMDFUErrorStringGet(tLMDFUErr eError) +{ + if(pfnLMDFUErrorStringGet) + { + return(pfnLMDFUErrorStringGet(eError)); + } + + return("Driver not installed"); +} diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/lmdfuwrap.h b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/lmdfuwrap.h new file mode 100644 index 000000000..808f836b2 --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/lmdfuwrap.h @@ -0,0 +1,78 @@ +//***************************************************************************** +// +// lmdfuwrap.h : A thin wrapper over the lmdfu.dll library allowing it to be +// loaded dynamically rather than statically linking to its .lib +// file. +// +// Copyright (c) 2009-2017 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.4.178 of the Tiva Firmware Development Package. +// +//***************************************************************************** + +#ifndef __LMDFUWRAP_H__ +#define __LMDFUWRAP_H__ + +//***************************************************************************** +// +// Wrapper function prototypes. +// +//***************************************************************************** +tLMDFUErr __stdcall _LMDFUInit(void); +tLMDFUErr __stdcall _LMDFUDeviceOpen(int iDeviceIndex, + tLMDFUDeviceInfo *psDevInfo, + tLMDFUHandle *phHandle); +tLMDFUErr __stdcall _LMDFUDeviceClose(tLMDFUHandle hHandle, bool bReset); +tLMDFUErr __stdcall _LMDFUDeviceStringGet(tLMDFUHandle hHandle, + unsigned char ucStringIndex, + unsigned short usLanguageID, + char *pcString, + unsigned short *pusStringLen); +tLMDFUErr __stdcall _LMDFUDeviceASCIIStringGet(tLMDFUHandle hHandle, + unsigned char ucStringIndex, + char *pcString, + unsigned short *pusStringLen); +tLMDFUErr __stdcall _LMDFUParamsGet(tLMDFUHandle hHandle, + tLMDFUParams *psParams); +tLMDFUErr __stdcall _LMDFUIsValidImage(tLMDFUHandle hHandle, + unsigned char *pcDFUImage, + unsigned long ulImageLen, + bool *pbTivaFormat); +tLMDFUErr __stdcall _LMDFUDownload(tLMDFUHandle hHandle, + unsigned char *pcDFUImage, + unsigned long ulImageLen, bool bVerify, + bool bIgnoreIDs, HWND hwndNotify); +tLMDFUErr __stdcall _LMDFUDownloadBin(tLMDFUHandle hHandle, + unsigned char *pcBinaryImage, + unsigned long ulImageLen, + unsigned long ulStartAddr, + bool bVerify, HWND hwndNotify); +tLMDFUErr __stdcall _LMDFUErase(tLMDFUHandle hHandle, unsigned long ulStartAddr, + unsigned long ulEraseLen, bool bVerify, + HWND hwndNotify); +tLMDFUErr __stdcall _LMDFUBlankCheck(tLMDFUHandle hHandle, + unsigned long ulStartAddr, + unsigned long ulLen); +tLMDFUErr __stdcall _LMDFUUpload(tLMDFUHandle hHandle, unsigned char *pcBuffer, + unsigned long ulStartAddr, + unsigned long ulImageLen, bool bRaw, + HWND hwndNotify); +tLMDFUErr __stdcall _LMDFUStatusGet(tLMDFUHandle hHandle, tDFUStatus *pStatus); +tLMDFUErr __stdcall _LMDFUModeSwitch(tLMDFUHandle hHandle); +char * __stdcall _LMDFUErrorStringGet(tLMDFUErr eError); + +#endif diff --git a/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/resource.h b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/resource.h new file mode 100644 index 000000000..d5ac7c42a --- /dev/null +++ b/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc |
