Skip to content

Commit

Permalink
store register/peripheral setting in appropriate folder
Browse files Browse the repository at this point in the history
  • Loading branch information
haneefdm committed Oct 8, 2021
1 parent 9377356 commit 0210c91
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
10 changes: 5 additions & 5 deletions src/frontend/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ export class CortexDebugExtension {
if (Object.keys(this.rttPortMap).length > 0) { this.initializeRTT(args); }

if (!this.currentArgs.noDebug) {
this.registerProvider.debugSessionStarted();
this.registerProvider.debugSessionStarted(session);
}
this.peripheralProvider.debugSessionStarted((svdfile && !args.noDebug) ? svdfile : null, args.svdAddrGapThreshold);
this.peripheralProvider.debugSessionStarted(session, (svdfile && !args.noDebug) ? svdfile : null, args.svdAddrGapThreshold);
this.cleanupRTTTerminals();
}, (error) => {
// TODO: Error handling for unable to get arguments
Expand All @@ -519,9 +519,9 @@ export class CortexDebugExtension {

this.debuggerStatus = 'none';
if (!this.currentArgs.noDebug) {
this.registerProvider.debugSessionTerminated();
this.registerProvider.debugSessionTerminated(session);
}
this.peripheralProvider.debugSessionTerminated();
this.peripheralProvider.debugSessionTerminated(session);
if (this.swo) {
this.swo.debugSessionTerminated();
}
Expand Down Expand Up @@ -580,7 +580,7 @@ export class CortexDebugExtension {

private receivedStopEvent(e) {
this.debuggerStatus = 'stopped';
this.peripheralProvider.debugStopped();
this.peripheralProvider.debugStopped(vscode.debug.activeDebugSession);
if (this.currentArgs && !this.currentArgs.noDebug) {
this.registerProvider.debugStopped();
}
Expand Down
35 changes: 21 additions & 14 deletions src/frontend/views/peripheral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class PeripheralTreeProvider implements vscode.TreeDataProvider<Periphera
// tslint:disable-next-line:variable-name
public _onDidChangeTreeData: vscode.EventEmitter<PeripheralBaseNode | undefined> = new vscode.EventEmitter<PeripheralBaseNode | undefined>();
public readonly onDidChangeTreeData: vscode.Event<PeripheralBaseNode | undefined> = this._onDidChangeTreeData.event;
public session: vscode.DebugSession = null;

private peripherials: PeripheralNode[] = [];
private loaded: boolean = false;
Expand All @@ -40,7 +41,7 @@ export class PeripheralTreeProvider implements vscode.TreeDataProvider<Periphera
}

private loadSVD(SVDFile: string): Promise<any> {
return new Promise((resolve,reject) => {
return new Promise((resolve, reject) => {
if (!path.isAbsolute(SVDFile)) {
const fullpath = path.normalize(path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, SVDFile));
SVDFile = fullpath;
Expand Down Expand Up @@ -100,19 +101,19 @@ export class PeripheralTreeProvider implements vscode.TreeDataProvider<Periphera
}
}

public debugSessionStarted(svdfile: string, thresh: any): Thenable<any> {
public debugSessionStarted(session: vscode.DebugSession, svdfile: string, thresh: any): Thenable<any> {
return new Promise<void>((resolve, reject) => {
this.peripherials = [];
this.loaded = false;
this._onDidChangeTreeData.fire(undefined);

// Set the threshold between 0 and 32, with a default of 16 and a mukltiple of 8
this.gapThreshold = ((((typeof thresh) === 'number') ? Math.max(0, Math.min(thresh, 32)) : 16) + 7) & ~0x7;

if (svdfile) {
if (svdfile && !this.session && !this.loaded) {
setTimeout(() => {
this.loadSVD(svdfile).then(
() => {
this.session = session;
vscode.workspace.findFiles('.vscode/.cortex-debug.peripherals.state.json', null, 1).then((value) => {
if (value.length > 0) {
const fspath = value[0].fsPath;
Expand Down Expand Up @@ -159,20 +160,26 @@ export class PeripheralTreeProvider implements vscode.TreeDataProvider<Periphera
});
}

public debugSessionTerminated(): Thenable<any> {
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) {
const fspath = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, '.vscode', '.cortex-debug.peripherals.state.json');
this.saveState(fspath);
public debugSessionTerminated(session: vscode.DebugSession): Thenable<any> {
if (this.session.id === session.id) {
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) {
// Path should really be in the workspace storage but this is where we will live for now
const fspath = path.join(
session.workspaceFolder.uri.fsPath,
/*vscode.workspace.workspaceFolders[0].uri.fsPath,*/
'.vscode', '.cortex-debug.peripherals.state.json');
this.saveState(fspath);
}
this.session = null;
this.peripherials = [];
this.loaded = false;
this._onDidChangeTreeData.fire(undefined);
}

this.peripherials = [];
this.loaded = false;
this._onDidChangeTreeData.fire(undefined);
return Promise.resolve(true);
}

public debugStopped() {
if (this.loaded) {
public debugStopped(session: vscode.DebugSession) {
if (this.loaded && (session.id === this.session.id)) {
const promises = this.peripherials.map((p) => p.updateData());
Promise.all(promises).then((_) => { this._onDidChangeTreeData.fire(undefined); }, (_) => { this._onDidChangeTreeData.fire(undefined); });
}
Expand Down
21 changes: 16 additions & 5 deletions src/frontend/views/registers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class RegisterTreeProvider implements TreeDataProvider<BaseNode> {
// tslint:disable-next-line:variable-name
public _onDidChangeTreeData: EventEmitter<BaseNode | undefined> = new EventEmitter<BaseNode | undefined>();
public readonly onDidChangeTreeData: Event<BaseNode | undefined> = this._onDidChangeTreeData.event;
public session: vscode.DebugSession = null;

private registers: RegisterNode[];
private registerMap: { [index: number]: RegisterNode };
Expand Down Expand Up @@ -135,10 +136,16 @@ export class RegisterTreeProvider implements TreeDataProvider<BaseNode> {
}
}

public debugSessionTerminated() {
if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) {
const fspath = path.join(workspace.workspaceFolders[0].uri.fsPath, '.vscode', '.cortex-debug.registers.state.json');
this._saveState(fspath);
public debugSessionTerminated(session: vscode.DebugSession) {
if (this.session.id === session.id) {
// We don't have multi-session capability, yet, and this file should really be in workspace storage
if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) {
const fspath = path.join(session.workspaceFolder.uri.fsPath,
/* workspace.workspaceFolders[0].uri.fsPath,*/
'.vscode', '.cortex-debug.registers.state.json');
this._saveState(fspath);
}
this.session = null;
}

this.loaded = false;
Expand All @@ -147,7 +154,11 @@ export class RegisterTreeProvider implements TreeDataProvider<BaseNode> {
this._onDidChangeTreeData.fire(undefined);
}

public debugSessionStarted() {
public debugSessionStarted(session: vscode.DebugSession) {
if (!this.session) {
// This is to decide where to store settings
this.session = session;
}
this.loaded = false;
this.registers = [];
this.registerMap = {};
Expand Down

0 comments on commit 0210c91

Please sign in to comment.