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
Language independent interface to bsdl parser
  • Loading branch information
nowinnovation authored and nOw Innovation committed Jun 8, 2022
commit b9e0078cfd37369547ff8106a81231d055c13c7c
4 changes: 3 additions & 1 deletion lib_jtag_core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required (VERSION 2.8.11)

# Recurse into the "linux" subdirectory.
# Recurse into the linux, imports and apps subdirectories.
add_subdirectory (linux)
add_subdirectory (imports)
#add_subdirectory (apps)

22 changes: 22 additions & 0 deletions lib_jtag_core/test/imports/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Create static and shared libraries and specify the source files.
# Any number of sources could be listed here.

add_library(epCoreJTAG_ STATIC epCoreJTAG.cxx)
add_library(epCoreJTAG SHARED epCoreJTAG.cxx)

# For static library, enable position independent code
set_property(TARGET epCoreJTAG_ PROPERTY POSITION_INDEPENDENT_CODE ON)

# Make sure the compiler can find include files for our library
# when other libraries or executables link to fftTOO
target_include_directories (epCoreJTAG_ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} "${STREETVIEWJTAG_SOURCE_DIR}/src")
target_include_directories (epCoreJTAG PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} "${STREETVIEWJTAG_SOURCE_DIR}/src")

set_property(TARGET epCoreJTAG PROPERTY INTERFACE_LINK_LIBRARIES jtag_bsdl)
set_property(TARGET epCoreJTAG_ PROPERTY INTERFACE_LINK_LIBRARIES jtag_bsdl)

add_executable(uiCoreJTAG uiCoreJTAG.cxx)
target_link_libraries(uiCoreJTAG epCoreJTAG jtag_bsdl)

add_executable(uiCoreJTAG_ uiCoreJTAG.cxx)
target_link_libraries(uiCoreJTAG_ epCoreJTAG jtag_bsdl)
72 changes: 72 additions & 0 deletions lib_jtag_core/test/imports/epCoreJTAG.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <stddef.h>
#include <stdio.h>
#include "libjtag_bsdl.h"

#include "epSwigHere.h"
#include <memory>
#include <type_traits>
#include <vector>


static void logger(char * string) {
printf("%s",string);
}

static class CLitterPile : private std::vector<SWIGHERE_CAST> {
private:
JTAGCORE_PRINT_FUNC logger;
public:
CLitterPile() {logger=::logger;}
void ensureInit() {
}
void deinit() {
}
void clear() {
//std::vector &self=*this;
for(SWIGHERE_CAST typedPtr : *this) {
switch(typedPtr.first) {
case SWIGHERE_TYPE::INTPTR: {
int * litter=(int*)typedPtr.second;
delete [] litter;
}
break;
default: // don't scope the default block
break;}
}
std::vector<SWIGHERE_CAST>::clear();
}
SWIGHERE_CAST push_back(const int * p) {
SWIGHERE_CAST tail(SWIGHERE_TYPE::INTPTR,(void*)p);
std::vector<SWIGHERE_CAST>::push_back(tail);
return tail;
}
~CLitterPile() {
clear();
}
} garbageCollector;

extern SWIGHERE_CONTEXT epInitSwigHere() {
garbageCollector.ensureInit();
return (SWIGHERE_CONTEXT) &garbageCollector;
}

extern void epUninitSwigHere(SWIGHERE_CONTEXT oContext) {
if(oContext == (SWIGHERE_CONTEXT) &garbageCollector) {
garbageCollector.clear();
garbageCollector.deinit();
}
}

extern long unsigned int epBSDLDeviceId(SWIGHERE_CONTEXT oContext, char * pathToBSDL) {
long int result = -1;
if(oContext == (SWIGHERE_CONTEXT)&garbageCollector) {
jtag_bsdl * details = jtag_bsdl_load_file(logger,MSG_DEBUG, 0, pathToBSDL);
if ( details != NULL ) {
result = details->chip_id;
jtag_bsdl_unload_file(details);
} else {
result = 0;
}
}
return (long unsigned int) result;
}
20 changes: 20 additions & 0 deletions lib_jtag_core/test/imports/epSwigHere.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// epSWIGHere.h for CoreJTAG
#pragma once
#include <utility>
#include <string>

typedef enum _SWIGHERE_TYPE {
VOIDPTR=0,
INTPTR
} SWIGHERE_TYPE;

typedef std::pair<SWIGHERE_TYPE,void *> SWIGHERE_CAST;
typedef std::pair<SWIGHERE_TYPE,int *> SWIGHERE_INTLIST;

typedef volatile void * SWIGHERE_CONTEXT;

extern SWIGHERE_CONTEXT epInitSwigHere();
extern long unsigned int epBSDLDeviceId(SWIGHERE_CONTEXT oContext, char * pathToFile);
extern SWIGHERE_INTLIST epSequence(SWIGHERE_CONTEXT oContext,unsigned * pBytesPerElement,unsigned * pElementCount);
//extern SWIGHERE_INTLIST epBSDLPinMap(SWIGHERE_CONTEXT oContext,unsigned * pBytesPerElement,unsigned * pElementCount);
extern void epUninitSwigHere(SWIGHERE_CONTEXT oContext);
19 changes: 19 additions & 0 deletions lib_jtag_core/test/imports/uiCoreJTAG.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "epSwigHere.h"

#include "libjtag_bsdl.h"

int main(int argc, char * argv[], char ** envp) {
SWIGHERE_CONTEXT context = epInitSwigHere();
if(context != NULL) {
if(argc>1) {
long unsigned int id = epBSDLDeviceId(context, argv[1]);
//SWIGHERE_INTLIST epSequence(SWIGHERE_CONTEXT oContext,unsigned * pBytesPerElement,unsigned * pElementCount);
//extern SWIGHERE_INTLIST epBSDLPinMap(SWIGHERE_CONTEXT oContext,unsigned * pBytesPerElement,unsigned * pElementCount);
printf("BSDL file describes device id %lx\r\n",id);
}
epUninitSwigHere(context);
context = NULL;
}
return 0;
}