aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/FirmwareUpdateManager.cpp
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-01-01 17:28:19 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-01-01 17:28:19 +0200
commit25f5e6ddef7ef2fa0a747305847eeb4ceee5a2c9 (patch)
tree600a6623f866d48a522406b4d93e5f213d290c61 /Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/FirmwareUpdateManager.cpp
parent9a3114908dd0a4f61fc959ef0f352b2b6255a652 (diff)
downloadTango-25f5e6ddef7ef2fa0a747305847eeb4ceee5a2c9.tar.gz
Tango-25f5e6ddef7ef2fa0a747305847eeb4ceee5a2c9.zip
Added tango firmware update lib.
Diffstat (limited to 'Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/FirmwareUpdateManager.cpp')
-rw-r--r--Software/Visual_Studio/Firmware/Tango.FirmwareUpdateLib/FirmwareUpdateManager.cpp132
1 files changed, 132 insertions, 0 deletions
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