Skip to content

Commit

Permalink
Refactoring for TestInterface support
Browse files Browse the repository at this point in the history
  • Loading branch information
azonenberg committed Aug 28, 2018
1 parent 3ca8fef commit b4cffd8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
14 changes: 7 additions & 7 deletions jtagclient/main.cpp
Expand Up @@ -50,7 +50,7 @@ using namespace std;

void ShowUsage();
void ShowVersion();
void PrintDeviceInfo(JtagDevice* pdev);
void PrintDeviceInfo(TestableDevice* pdev);

#ifndef _WIN32
void sig_handler(int sig);
Expand Down Expand Up @@ -385,7 +385,7 @@ int main(int argc, char* argv[])
}

//Get the device
JtagDevice* device = iface.GetDevice(devnum);
auto device = iface.GetDevice(devnum);
if(device == NULL)
{
throw JtagExceptionWrapper(
Expand Down Expand Up @@ -474,7 +474,7 @@ int main(int argc, char* argv[])
case MODE_ERASE:
{
//Get the device
JtagDevice* device = iface.GetDevice(devnum);
auto device = iface.GetDevice(devnum);
if(device == NULL)
{
throw JtagExceptionWrapper(
Expand All @@ -500,7 +500,7 @@ int main(int argc, char* argv[])
case MODE_REBOOT:
{
//Get the device
JtagDevice* device = iface.GetDevice(devnum);
auto device = iface.GetDevice(devnum);
if(device == NULL)
{
throw JtagExceptionWrapper(
Expand All @@ -526,7 +526,7 @@ int main(int argc, char* argv[])
case MODE_LOCK:
{
//Get the device
JtagDevice* device = iface.GetDevice(devnum);
auto device = iface.GetDevice(devnum);
if(device == NULL)
{
throw JtagExceptionWrapper(
Expand All @@ -551,7 +551,7 @@ int main(int argc, char* argv[])
case MODE_UNLOCK:
{
//Get the device
JtagDevice* device = iface.GetDevice(devnum);
auto device = iface.GetDevice(devnum);
if(device == NULL)
{
throw JtagExceptionWrapper(
Expand Down Expand Up @@ -596,7 +596,7 @@ int main(int argc, char* argv[])
\ingroup jtagclient
*/
void PrintDeviceInfo(JtagDevice* pdev)
void PrintDeviceInfo(TestableDevice* pdev)
{
if(pdev == NULL)
{
Expand Down
34 changes: 24 additions & 10 deletions jtagsh/commands.cpp
Expand Up @@ -53,7 +53,7 @@ void TopLevelShell(NetworkedJtagInterface& iface)
fflush(stderr);

//Get the command
char* cmd = readline("jtag-chain> ");
char* cmd = readline("jtag> ");
if(cmd == NULL)
return;
add_history(cmd);
Expand All @@ -70,6 +70,8 @@ void TopLevelShell(NetworkedJtagInterface& iface)
OnAutodetect(iface, false);
else if(scmd == "autodetect quiet")
OnAutodetect(iface, true);
else if(scmd == "ls")
OnTargets(iface);

//Select a new device and run the shell for it
else if(scmd.find("select") == 0)
Expand Down Expand Up @@ -113,10 +115,14 @@ void TopLevelShell(NetworkedJtagInterface& iface)
}
}

void DeviceShell(JtagDevice* pdev)
void DeviceShell(TestableDevice* pdev)
{
char prompt[32];
snprintf(prompt, sizeof(prompt), "jtag-device%zu> ", pdev->GetChainIndex());
size_t index = 0;
JtagDevice* pj = dynamic_cast<JtagDevice*>(pdev);
if(pj)
index = pj->GetChainIndex();
snprintf(prompt, sizeof(prompt), "jtag/device%zu> ", index);

while(true)
{
Expand Down Expand Up @@ -164,7 +170,7 @@ void DeviceShell(JtagDevice* pdev)
return;
else if(args[0] == "info")
pdev->PrintInfo();
else if(args[0] == "targets")
else if(args[0] == "ls")
OnTargets(dynamic_cast<DebuggerInterface*>(pdev));

else if(args[0] == "lock")
Expand Down Expand Up @@ -215,7 +221,7 @@ void DeviceShell(JtagDevice* pdev)
//Do stuff that takes arguments
else if(args[0] == "select")
{
OnTarget(dynamic_cast<DebuggerInterface*>(pdev), args);
OnTarget(dynamic_cast<DebuggerInterface*>(pdev), args, index);
continue;
}
else if(args[0] == "program")
Expand Down Expand Up @@ -247,22 +253,25 @@ void DeviceShell(JtagDevice* pdev)
}
}

void TargetShell(DebuggableDevice* pdev)
void TargetShell(DebuggableDevice* pdev, unsigned int ndev, unsigned int ntarget)
{
if(pdev == NULL)
{
LogError("The \"target\" shell requires a debuggable device\n");
return;
}

char prompt[64];
snprintf(prompt, sizeof(prompt), "jtag/device%u/target%u> ", ndev, ntarget);

while(true)
{
//Make sure past command output prints above the prompt
fflush(stdout);
fflush(stderr);

//Get the command
char* cmd = readline("debug-target> ");
char* cmd = readline(prompt);
if(cmd == NULL)
return;
add_history(cmd);
Expand Down Expand Up @@ -335,12 +344,17 @@ void OnAutodetect(NetworkedJtagInterface& iface, bool quiet)
{
//Figure out what devices we have
iface.InitializeChain(quiet);
}

void OnTargets(NetworkedJtagInterface& iface)
{
//TODO: how to handle non-JTAG interfaces?

//Print out a list of what we found
LogNotice("%10s %7s %10s %-60s %-50s\n", "Index", "IR len", "ID code", "Description", "Device capabilities");
for(size_t i=0; i<iface.GetDeviceCount(); i++)
{
auto pdev = iface.GetDevice(i);
auto pdev = iface.GetJtagDevice(i);

//Figure out what this device is
vector<string> alist;
Expand Down Expand Up @@ -380,7 +394,7 @@ void OnAutodetect(NetworkedJtagInterface& iface, bool quiet)
LogNotice("\nNOTE: Capabilities listed are based on ID code scan only, and may be restricted by device security bits.\n");
}

void OnTarget(DebuggerInterface* iface, const vector<string>& args)
void OnTarget(DebuggerInterface* iface, const vector<string>& args, unsigned int ndev)
{
//Sanity checks
if(iface == NULL)
Expand Down Expand Up @@ -410,7 +424,7 @@ void OnTarget(DebuggerInterface* iface, const vector<string>& args)
//Run the interactive shell
auto ptarget = iface->GetTarget(tnum);
LogNotice("Selected target %u: %s\n", tnum, ptarget->GetDescription().c_str());
TargetShell(ptarget);
TargetShell(ptarget, ndev, tnum);
}

void OnProgram(ProgrammableDevice* pdev, const vector<string>& args)
Expand Down
7 changes: 4 additions & 3 deletions jtagsh/jtagsh.h
Expand Up @@ -50,11 +50,12 @@
#include <signal.h>

void TopLevelShell(NetworkedJtagInterface& iface);
void DeviceShell(JtagDevice* pdev);
void TargetShell(DebuggableDevice* pdev);
void DeviceShell(TestableDevice* pdev);
void TargetShell(DebuggableDevice* pdev, unsigned int ndev, unsigned int ntarget);

void OnAutodetect(NetworkedJtagInterface& iface, bool quiet);
void OnTarget(DebuggerInterface* iface, const std::vector<std::string>& args);
void OnTargets(NetworkedJtagInterface& iface);
void OnTarget(DebuggerInterface* iface, const std::vector<std::string>& args, unsigned int ndev);
void OnProgram(ProgrammableDevice* pdev, const std::vector<std::string>& args);
void OnTargets(DebuggerInterface* iface);

Expand Down

0 comments on commit b4cffd8

Please sign in to comment.