in editor/prepend/dapjs.js [2540:2793]
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var cortex_1 = __webpack_require__(2);
var K64F_1 = __webpack_require__(13);
var NRF51_1 = __webpack_require__(14);
var analyzer = new Uint32Array([
0x2180468c, 0x2600b5f0, 0x4f2c2501, 0x447f4c2c, 0x1c2b0049, 0x425b4033, 0x40230872, 0x085a4053,
0x425b402b, 0x40534023, 0x402b085a, 0x4023425b, 0x085a4053, 0x425b402b, 0x40534023, 0x402b085a,
0x4023425b, 0x085a4053, 0x425b402b, 0x40534023, 0x402b085a, 0x4023425b, 0x085a4053, 0x425b402b,
0x40534023, 0xc7083601, 0xd1d2428e, 0x2b004663, 0x4663d01f, 0x46b4009e, 0x24ff2701, 0x44844d11,
0x1c3a447d, 0x88418803, 0x4351409a, 0xd0122a00, 0x22011856, 0x780b4252, 0x40533101, 0x009b4023,
0x0a12595b, 0x42b1405a, 0x43d2d1f5, 0x4560c004, 0x2000d1e7, 0x2200bdf0, 0x46c0e7f8, 0x000000b6,
0xedb88320, 0x00000044,
]);
var FlashTarget = (function (_super) {
__extends(FlashTarget, _super);
function FlashTarget(device, platform) {
var _this = _super.call(this, device) || this;
_this.platform = platform;
_this.inited = false;
return _this;
}
/**
* Initialise the flash driver on the chip. Must be called before any of the other
* flash-related methods.
*/
FlashTarget.prototype.flashInit = function () {
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (this.inited) {
return [2 /*return*/];
}
// reset and halt
return [4 /*yield*/, this.reset(true)];
case 1:
// reset and halt
_a.sent();
// make sure we're in Thumb mode.
return [4 /*yield*/, this.writeCoreRegister(16 /* XPSR */, 1 << 24)];
case 2:
// make sure we're in Thumb mode.
_a.sent();
return [4 /*yield*/, this.writeCoreRegister(9 /* R9 */, this.platform.flashAlgo.staticBase)];
case 3:
_a.sent();
if (!this.platform.flashAlgo.analyzerSupported) return [3 /*break*/, 5];
return [4 /*yield*/, this.memory.writeBlock(this.platform.flashAlgo.analyzerAddress, analyzer)];
case 4:
_a.sent();
_a.label = 5;
case 5: return [4 /*yield*/, this.runCode(this.platform.flashAlgo.instructions, this.platform.flashAlgo.loadAddress, this.platform.flashAlgo.pcInit, this.platform.flashAlgo.loadAddress + 1, this.platform.flashAlgo.stackPointer, true, 0, 0, 0, 0)];
case 6:
result = _a.sent();
this.inited = true;
return [2 /*return*/, result];
}
});
});
};
/**
* Erase _all_ data stored in flash on the chip.
*/
FlashTarget.prototype.eraseChip = function () {
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!!this.inited) return [3 /*break*/, 2];
return [4 /*yield*/, this.flashInit()];
case 1:
_a.sent();
_a.label = 2;
case 2: return [4 /*yield*/, this.runCode(this.platform.flashAlgo.instructions, this.platform.flashAlgo.loadAddress, this.platform.flashAlgo.pcEraseAll, this.platform.flashAlgo.loadAddress + 1, this.platform.flashAlgo.stackPointer, false, 0, 0, 0)];
case 3:
result = _a.sent();
return [2 /*return*/, result];
}
});
});
};
/**
* Upload a program to flash memory on the chip.
* TODO: add a callback to provide progress data
*
* @param data Array of 32-bit integers to write to flash.
*/
FlashTarget.prototype.flash = function (data, address, progressCb) {
return __awaiter(this, void 0, void 0, function () {
var pageSizeWords, bufferAddress, flashStart, ptr, wordPtr, pageData, flashAddress;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!!this.inited) return [3 /*break*/, 2];
return [4 /*yield*/, this.flashInit()];
case 1:
_a.sent();
_a.label = 2;
case 2:
pageSizeWords = this.platform.flashAlgo.pageSize / 4;
bufferAddress = this.platform.flashAlgo.pageBuffers[0];
flashStart = address || this.platform.flashAlgo.flashStart;
ptr = 0;
_a.label = 3;
case 3:
if (!(ptr < data.byteLength)) return [3 /*break*/, 6];
wordPtr = ptr / 4;
pageData = data.subarray(wordPtr, wordPtr + pageSizeWords);
flashAddress = flashStart + ptr;
return [4 /*yield*/, this.memory.writeBlock(bufferAddress, pageData)];
case 4:
_a.sent();
return [4 /*yield*/, this.runCode(this.platform.flashAlgo.instructions, this.platform.flashAlgo.loadAddress, this.platform.flashAlgo.pcProgramPage, // pc
this.platform.flashAlgo.loadAddress + 1, // lr
this.platform.flashAlgo.stackPointer, // sp
/* upload? */
false,
/* args */
flashAddress, this.platform.flashAlgo.pageSize, bufferAddress)];
case 5:
_a.sent();
if (progressCb) {
progressCb(ptr / data.byteLength);
}
ptr += pageData.byteLength;
return [3 /*break*/, 3];
case 6:
if (progressCb) {
progressCb(1.0);
}
return [2 /*return*/];
}
});
});
};
FlashTarget.prototype.program = function (program, progressCb) {
return __awaiter(this, void 0, void 0, function () {
var totalBytes, cumulativeBytes, startTime, _loop_1, this_1, _i, _a, section, endTime, elapsedTime, transferRate;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, this.flashInit()];
case 1:
_b.sent();
return [4 /*yield*/, this.eraseChip()];
case 2:
_b.sent();
totalBytes = program.totalByteLength();
cumulativeBytes = 0;
startTime = Date.now();
_loop_1 = function (section) {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this_1.flash(section.data, section.address, function (progress) {
var sectionBytes = section.data.byteLength * progress;
progressCb((cumulativeBytes + sectionBytes) / totalBytes);
})];
case 1:
_a.sent();
cumulativeBytes += section.data.byteLength;
return [2 /*return*/];
}
});
};
this_1 = this;
_i = 0, _a = program.sections;
_b.label = 3;
case 3:
if (!(_i < _a.length)) return [3 /*break*/, 6];
section = _a[_i];
return [5 /*yield**/, _loop_1(section)];
case 4:
_b.sent();
_b.label = 5;
case 5:
_i++;
return [3 /*break*/, 3];
case 6:
endTime = Date.now();
elapsedTime = endTime - startTime;
transferRate = totalBytes / elapsedTime;
console.debug("Transfer took " + elapsedTime / 1000 + " s");
console.debug("Transfered " + totalBytes + " bytes at " + transferRate + " kB/s");
return [4 /*yield*/, this.flashUnInit()];
case 7:
_b.sent();
progressCb(1.0);
return [2 /*return*/];
}
});
});
};
FlashTarget.prototype.flashUnInit = function () {
this.inited = false;
};
return FlashTarget;
}(cortex_1.CortexM));
exports.FlashTarget = FlashTarget;
exports.FlashTargets = new Map();
exports.FlashTargets.set("0240", new K64F_1.K64F());
exports.FlashTargets.set("9900", new NRF51_1.NRF51());
/***/ }),