Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contributions related to Medium Article #11

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
JSON-parsable results
  • Loading branch information
nowinnovation authored and nOw Innovation committed Jun 10, 2022
commit a8dcccd7e3c58764fbe2829b1a8973a60d1cd02d
88 changes: 85 additions & 3 deletions lib_jtag_core/test/apps/py3/bindings/py3SwigHere.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,97 @@ extern unsigned long int pyBSDLDeviceId(std::string pathToBSDL) {
}
return 0;
}
/*
typedef struct _pin_ctrl
{
char pinname[MAX_ELEMENT_SIZE];
int pintype;

extern std::vector<int> pyBSDLPinSequence(std::string pathToBSDL) {
std::vector<int> result;
char physical_pin[MAX_ELEMENT_SIZE];

int ctrl_bit_number;
int out_bit_number;
int in_bit_number;
}pin_ctrl;
*/

extern std::vector<std::string> pyBSDLPinSequence(std::string pathToBSDL) {
std::vector<std::string> result;
if(pContext) {
unsigned bytesPerElement=0, elementCount=0;
std::vector<pin_ctrl> pinSequence = epBSDLPinSequence(pContext, (char*)pathToBSDL.c_str(), &bytesPerElement);
if( bytesPerElement == sizeof(pin_ctrl) ) {
for(unsigned i = 0; i<pinSequence.size(); i++) {
result.push_back(i);
static char formatter[] = {
"{"
"\"name\":\"%0.64s\","
"\"physical\":\"%0.64s\","
"\"type\": %8i,"
"\"ctrl_bit\": %8i,"
"\"out_bit\": %8i,"
"\"in_bit\": %8i"
"}"
};
char bfJsonConversion[256]="";
sprintf(bfJsonConversion,formatter,
pinSequence[i].pinname,
pinSequence[i].physical_pin,
pinSequence[i].pintype,
pinSequence[i].ctrl_bit_number,
pinSequence[i].out_bit_number,
pinSequence[i].in_bit_number
);
result.push_back(bfJsonConversion);
}
}
}

return result;
}

/*
typedef struct _jtag_chain
{
int bit_index;

int bit_cell_type; // BC_1,BC_2,...

char pinname[MAX_ELEMENT_SIZE]; // Pin name.

int bit_type; // None , ctrl , in, out.

int safe_state; // Default - Safe state. (0,1,-1)

int control_bit_index; // Indicate the associated control bit. -1 if no control bit.
int control_disable_state;
int control_disable_result;

}jtag_chain;
*/

extern std::vector<std::string> pyBSDLChainSequence(std::string pathToBSDL) {
std::vector<std::string> result;
if(pContext) {
unsigned bytesPerElement=0, elementCount=0;
std::vector<jtag_chain> chainSequence = epBSDLChainSequence(pContext, (char*)pathToBSDL.c_str(), &bytesPerElement);
if( bytesPerElement == sizeof(jtag_chain) ) {
for(unsigned i = 0; i < chainSequence.size(); i++) {
static char formatter[] = {
"{"
"\"name\":\"%0.64s\","
"\"index\": %8i,"
"\"cell_type\": %8i,"
"\"bit_type\": %8i"
"}"
};
char bfJsonConversion[256]="";
sprintf(bfJsonConversion,formatter,
chainSequence[i].pinname,
chainSequence[i].bit_index,
chainSequence[i].bit_cell_type,
chainSequence[i].bit_type
);
result.push_back(bfJsonConversion);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib_jtag_core/test/apps/py3/bindings/py3SwigHere.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
extern void pyInitSwigHere();
extern void pyUninitSwigHere();
extern unsigned long int pyBSDLDeviceId(std::string pathToBSDL);
extern std::vector<int> pyBSDLPinSequence(std::string pathToBSDL);
extern std::vector<std::string> pyBSDLPinSequence(std::string pathToBSDL);
extern std::vector<std::string> pyBSDLChainSequence(std::string pathToBSDL);
7 changes: 4 additions & 3 deletions lib_jtag_core/test/apps/py3/bindings/py3SwigHere.i
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
#include "py3SwigHere.h"
%}

%template(vectori) std::vector<int>;
%template(c2json) std::vector<std::string>;

%extend std::vector<int> {
%extend std::vector<std::string> {
void empty_and_delete() {
for (std::vector<int>::iterator it = $self->begin();
for (std::vector<std::string>::iterator it = $self->begin();
it != $self->end(); ++it) {
// if it was a pointer, we could delete *it;
}
$self->clear();
}
}

%include "py3SwigHere.h"
15 changes: 14 additions & 1 deletion lib_jtag_core/test/apps/py3/py3UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from __future__ import print_function
import bindings as SWIGHERE
import json

class CSwigHere:
def __init__(self):
Expand All @@ -14,6 +15,9 @@ def pyBSDLDeviceId(self,pathToBSDL):
def pyBSDLPinSequence(self,pathToBSDL):
return SWIGHERE.pyBSDLPinSequence(pathToBSDL);

def pyBSDLChainSequence(self,pathToBSDL):
return SWIGHERE.pyBSDLChainSequence(pathToBSDL);

def __enter__(self):
SWIGHERE.pyInitSwigHere();
return self
Expand All @@ -27,6 +31,15 @@ def __exit__(self,exType,exValue,trace):
if len(sys.argv) > 1:
deviceId = instance.pyBSDLDeviceId(sys.argv[1])
if deviceId > 0:
chainMembers = []
pinList = instance.pyBSDLPinSequence(sys.argv[1])
print(pinList)
chainList = instance.pyBSDLChainSequence(sys.argv[1])
pinListJSON = [json.loads(s) for s in pinList]
chainListJSON = [ json.loads(s) for s in chainList]
chainListDict = { chain["index"]: chain for chain in chainListJSON}
for pin in pinListJSON:
chain_positions=[pin[key] for key in ["ctrl_bit","out_bit","in_bit"] if pin[key]>=0]
if any(chain_positions):
chainMembers.append(pin)
print(chainListDict)

32 changes: 28 additions & 4 deletions lib_jtag_core/test/imports/epCoreJTAG.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ extern std::vector<pin_ctrl> epBSDLPinSequence(SWIGHERE_CONTEXT oContext, char *
*pBytesPerElement = sizeof(pin_ctrl);
}
if(oContext==(SWIGHERE_CONTEXT)&garbageCollector) {
jtag_bsdl * details = jtag_bsdl_load_file(logger,MSG_DEBUG, 0, pathToBSDL);
const int sortPins=1;
jtag_bsdl * details = jtag_bsdl_load_file(logger,MSG_DEBUG, sortPins, pathToBSDL);
if ( details != NULL ) {
int number_of_pins = details->number_of_pins;
int i = 0;
Expand All @@ -91,7 +92,30 @@ extern std::vector<pin_ctrl> epBSDLPinSequence(SWIGHERE_CONTEXT oContext, char *
}

return result;
};
}

//extern std::vector<jtag_chain> epBSDLChainSequence(SWIGHERE_CONTEXT oContext, char * pathToFile, unsigned * pBytesPerElement,unsigned * pElementCount);
//extern std::vector<pin_ctrl> epBSDLPinSequence(SWIGHERE_CONTEXT oContext, char * pathToBSDL, unsigned * pBytesPerElement,unsigned * pElementCount) {
extern std::vector<jtag_chain> epBSDLChainSequence(SWIGHERE_CONTEXT oContext, char * pathToBSDL, unsigned * pBytesPerElement) {
int * p=NULL;
std::vector<jtag_chain> result;

if(pBytesPerElement != NULL) {
*pBytesPerElement = sizeof(jtag_chain);
}
if(oContext==(SWIGHERE_CONTEXT)&garbageCollector) {
const int sortPins=1;
jtag_bsdl * details = jtag_bsdl_load_file(logger,MSG_DEBUG, sortPins, pathToBSDL);
if ( details != NULL ) {
int number_of_chains = details->number_of_chainbits;
int i = 0;
if(number_of_chains>0) {
while(i<number_of_chains) {
jtag_chain * chain_list = details->chain_list;
result.push_back(chain_list[i]);
i++;
}
}
}
}

return result;
}