Python interface updated for new methods of interrupt callback of python function to avoid the non-re-entrant nature of the Python C interface.
This commit is contained in:
parent
c82d1dd27c
commit
5bdebd6385
9 changed files with 176 additions and 60 deletions
|
|
@ -23,21 +23,15 @@
|
|||
|
||||
#include "PythonVProc.h"
|
||||
|
||||
// Pointer types for external API functions. Must match prototypes in VUser.h
|
||||
typedef int (*wfunc_p) (const unsigned, const unsigned, const int, const unsigned);
|
||||
typedef int (*rfunc_p) (const unsigned, unsigned *, const int, const unsigned);
|
||||
typedef int (*wbfunc_p) (const unsigned, void *, const unsigned, const unsigned);
|
||||
typedef int (*rbfunc_p) (const unsigned, void *, const unsigned, const unsigned);
|
||||
typedef int (*tkfunc_p) (const unsigned, const unsigned );
|
||||
typedef void (*regirqfunc_p) (const pVUserIrqCB_t, const unsigned);
|
||||
|
||||
// Define pointers to the external API functions
|
||||
static wfunc_p Vwrite;
|
||||
static rfunc_p Vread;
|
||||
static wbfunc_p VburstWrite;
|
||||
static rbfunc_p VburstRead;
|
||||
static tkfunc_p Vtick;
|
||||
static regirqfunc_p VregIrq;
|
||||
static regirqfunc_p VregIrqPy;
|
||||
static pyirqcb_p PyIrqCB;
|
||||
static pyfetchirq_p PyFetchIrq_;
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Function to load VProc shared object and create bindings to
|
||||
|
|
@ -68,13 +62,13 @@ static int BindToApiFuncs(void)
|
|||
fprintf(stderr, "***ERROR: failed to find symbol VRead\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if ((VburstWrite = (wbfunc_p)dlsym(hdl, "VBurstWrite")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "***ERROR: failed to find symbol VBurstWrite\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if ((VburstRead = (rbfunc_p)dlsym(hdl, "VBurstRead")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "***ERROR: failed to find symbol VBurstRead\n");
|
||||
|
|
@ -87,9 +81,21 @@ static int BindToApiFuncs(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if ((VregIrq = (regirqfunc_p)dlsym(hdl, "VRegIrq")) == NULL)
|
||||
if ((VregIrqPy = (regirqfunc_p)dlsym(hdl, "VRegIrqPy")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "***ERROR: failed to find symbol VRegIrq\n");
|
||||
fprintf(stderr, "***ERROR: failed to find symbol VRegIrqPy\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((PyIrqCB = (pyirqcb_p)dlsym(hdl, "PyIrqCB")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "***ERROR: failed to find symbol PyIrqCB\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((PyFetchIrq_ = (pyfetchirq_p)dlsym(hdl, "PyFetchIrq")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "***ERROR: failed to find symbol PyFetchIrq\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -117,6 +123,9 @@ int RunPython(const int node)
|
|||
return status;
|
||||
}
|
||||
|
||||
// Register the Python interface interrupt callback function
|
||||
PyRegIrq(PyIrqCB, node);
|
||||
|
||||
Py_Initialize();
|
||||
|
||||
sprintf(strbuf, "VUserMain%d", node);
|
||||
|
|
@ -195,8 +204,6 @@ uint32_t PyPrint(const char* str)
|
|||
|
||||
uint32_t PyWrite (const uint32_t addr, const uint32_t data, const int delta, const uint32_t node)
|
||||
{
|
||||
//printf("PyWrite: addr=0x%08x data=0x%08x delta=%d node=%d\n", addr, data, delta, node);
|
||||
|
||||
return Vwrite(addr, data, delta, node);
|
||||
}
|
||||
|
||||
|
|
@ -206,8 +213,6 @@ uint32_t PyWrite (const uint32_t addr, const uint32_t data, const int delta, con
|
|||
|
||||
uint32_t PyRead (const uint32_t addr, const int delta, const uint32_t node)
|
||||
{
|
||||
//printf("PyRead: addr=0x%08x delta=%d node=%d\n", addr, delta, node);
|
||||
|
||||
uint32_t rdata;
|
||||
|
||||
int status = Vread(addr, &rdata, delta, node);
|
||||
|
|
@ -221,8 +226,6 @@ uint32_t PyRead (const uint32_t addr, const int delta, const uint32_t node)
|
|||
|
||||
uint32_t PyTick (const uint32_t ticks, const uint32_t node)
|
||||
{
|
||||
//printf("PyTick: ticks=%d node=%d\n", ticks, node);
|
||||
|
||||
return Vtick(ticks, node);
|
||||
}
|
||||
|
||||
|
|
@ -232,7 +235,6 @@ uint32_t PyTick (const uint32_t ticks, const uint32_t node)
|
|||
|
||||
uint32_t PyBurstWrite (const uint32_t addr, void *data, const uint32_t len, const uint32_t node)
|
||||
{
|
||||
//printf("addr=0x%08x data_p=0x%p data[1]=0x%08x len = %d node = %d", addr, data, ((uint32_t*)data)[1], len, node);
|
||||
return VburstWrite(addr, data, len, node);
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +244,6 @@ uint32_t PyBurstWrite (const uint32_t addr, void *data, const uint32_t len, cons
|
|||
|
||||
uint32_t PyBurstRead (const uint32_t addr, void *data, const uint32_t len, const uint32_t node)
|
||||
{
|
||||
|
||||
return VburstRead(addr, data, len, node);
|
||||
}
|
||||
|
||||
|
|
@ -250,11 +251,18 @@ uint32_t PyBurstRead (const uint32_t addr, void *data, const uint32_t len, const
|
|||
// VRegIrq wrapper function for Python
|
||||
// ------------------------------------------------------------
|
||||
|
||||
uint32_t PyRegIrq (const pVUserIrqCB_t func, const uint32_t node)
|
||||
uint32_t PyRegIrq (const pPyIrqCB_t func, const uint32_t node)
|
||||
{
|
||||
//printf("PyRegIrq %p %d\n", func, node);
|
||||
|
||||
VregIrq(func, node);
|
||||
VregIrqPy(func, node);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// PyFetchIrq wrapper function
|
||||
// ------------------------------------------------------------
|
||||
|
||||
uint32_t PyFetchIrq (void *irq, const uint32_t node)
|
||||
{
|
||||
PyFetchIrq_(irq, node);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,12 +31,25 @@
|
|||
|
||||
#define DEFAULTSTRBUFSIZE 256
|
||||
|
||||
// Pointer types for external API functions. Must match prototypes in VUser.h
|
||||
typedef int (*wfunc_p) (const unsigned, const unsigned, const int, const unsigned);
|
||||
typedef int (*rfunc_p) (const unsigned, unsigned *, const int, const unsigned);
|
||||
typedef int (*wbfunc_p) (const unsigned, void *, const unsigned, const unsigned);
|
||||
typedef int (*rbfunc_p) (const unsigned, void *, const unsigned, const unsigned);
|
||||
typedef int (*tkfunc_p) (const unsigned, const unsigned );
|
||||
typedef void (*regirqfunc_p) (const pPyIrqCB_t, const unsigned);
|
||||
typedef int (*pyirqcb_p) (const int, const int);
|
||||
typedef uint32_t (*pyfetchirq_p) (void *, const uint32_t);
|
||||
|
||||
// API functions called from python
|
||||
int RunPython (const int node);
|
||||
uint32_t PyWrite (const uint32_t addr, const uint32_t data, const int delta, const uint32_t node);
|
||||
uint32_t PyWrite (const uint32_t addr, const uint32_t data, const int delta, const uint32_t node);
|
||||
uint32_t PyRead (const uint32_t addr, const int delta, const uint32_t node);
|
||||
uint32_t PyTick (const uint32_t ticks, const uint32_t node);
|
||||
uint32_t PyBurstWrite (const uint32_t addr, void *data, const uint32_t len, const uint32_t node);
|
||||
uint32_t PyBurstRead (const uint32_t addr, void *data, const uint32_t len, const uint32_t node);
|
||||
uint32_t PyRegIrq (const pVUserIrqCB_t func, const uint32_t node);
|
||||
uint32_t PyBurstWrite (const uint32_t addr, void *data, const uint32_t len, const uint32_t node);
|
||||
uint32_t PyBurstRead (const uint32_t addr, void *data, const uint32_t len, const uint32_t node);
|
||||
|
||||
uint32_t PyRegIrq (const pPyIrqCB_t func, const uint32_t node);
|
||||
uint32_t PyFetchIrq (void *irq, const uint32_t node);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -20,36 +20,58 @@
|
|||
// along with VProc. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//=====================================================================
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "VUser.h"
|
||||
#include "PythonVProc.h"
|
||||
|
||||
#define SLEEPFOREVER {while(1) VTick(0x7fffffff, node);}
|
||||
|
||||
// In Python 64 nodes is the maximum (the default), but check this hasn't been
|
||||
// overridden to a large number.
|
||||
#if VP_MAX_NODES > 64
|
||||
#error "**ERROR: VP_MAX_NODES > 64 is unsupported"
|
||||
#endif
|
||||
|
||||
static uint64_t active_node = 0;
|
||||
|
||||
static void VUserMain(int node)
|
||||
{
|
||||
int status = RunPython(node);
|
||||
|
||||
if (status)
|
||||
if (active_node)
|
||||
{
|
||||
printf("***ERROR: RunPython(%d) returned error status %d\n", node, status);
|
||||
fprintf(stderr, "***ERROR: Under Python only a single instance of VProc is supported at this time.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
active_node |= (uint64_t)1 << node;
|
||||
|
||||
int status = RunPython(node);
|
||||
|
||||
if (status)
|
||||
{
|
||||
fprintf(stderr, "***ERROR: RunPython(%d) returned error status %d\n", node, status);
|
||||
}
|
||||
}
|
||||
|
||||
SLEEPFOREVER;
|
||||
}
|
||||
|
||||
void VUserMain0() {VUserMain(0);}
|
||||
void VUserMain1() {VUserMain(1);}
|
||||
void VUserMain2() {VUserMain(2);}
|
||||
void VUserMain3() {VUserMain(3);}
|
||||
void VUserMain4() {VUserMain(4);}
|
||||
void VUserMain5() {VUserMain(5);}
|
||||
void VUserMain6() {VUserMain(6);}
|
||||
void VUserMain7() {VUserMain(7);}
|
||||
void VUserMain8() {VUserMain(8);}
|
||||
void VUserMain9() {VUserMain(9);}
|
||||
void VUserMain10() {VUserMain(10);}
|
||||
void VUserMain11() {VUserMain(11);}
|
||||
void VUserMain12() {VUserMain(12);}
|
||||
void VUserMain13() {VUserMain(13);}
|
||||
void VUserMain14() {VUserMain(14);}
|
||||
void VUserMain15() {VUserMain(15);}
|
||||
// Bindings for VUserMain<n> entry points.
|
||||
|
||||
void VUserMain0() {VUserMain(0);} void VUserMain1() {VUserMain(1);} void VUserMain2() {VUserMain(2);} void VUserMain3() {VUserMain(3);}
|
||||
void VUserMain4() {VUserMain(4);} void VUserMain5() {VUserMain(5);} void VUserMain6() {VUserMain(6);} void VUserMain7() {VUserMain(7);}
|
||||
void VUserMain8() {VUserMain(8);} void VUserMain9() {VUserMain(9);} void VUserMain10() {VUserMain(10);} void VUserMain11() {VUserMain(11);}
|
||||
void VUserMain12() {VUserMain(12);} void VUserMain13() {VUserMain(13);} void VUserMain14() {VUserMain(14);} void VUserMain15() {VUserMain(15);}
|
||||
void VUserMain16() {VUserMain(16);} void VUserMain17() {VUserMain(17);} void VUserMain18() {VUserMain(18);} void VUserMain19() {VUserMain(19);}
|
||||
void VUserMain20() {VUserMain(20);} void VUserMain21() {VUserMain(21);} void VUserMain22() {VUserMain(22);} void VUserMain23() {VUserMain(23);}
|
||||
void VUserMain24() {VUserMain(24);} void VUserMain25() {VUserMain(25);} void VUserMain26() {VUserMain(26);} void VUserMain27() {VUserMain(27);}
|
||||
void VUserMain28() {VUserMain(28);} void VUserMain29() {VUserMain(29);} void VUserMain30() {VUserMain(30);} void VUserMain31() {VUserMain(31);}
|
||||
void VUserMain32() {VUserMain(32);} void VUserMain33() {VUserMain(33);} void VUserMain34() {VUserMain(34);} void VUserMain35() {VUserMain(35);}
|
||||
void VUserMain36() {VUserMain(36);} void VUserMain37() {VUserMain(37);} void VUserMain38() {VUserMain(38);} void VUserMain39() {VUserMain(39);}
|
||||
void VUserMain40() {VUserMain(40);} void VUserMain41() {VUserMain(41);} void VUserMain42() {VUserMain(42);} void VUserMain43() {VUserMain(43);}
|
||||
void VUserMain44() {VUserMain(44);} void VUserMain45() {VUserMain(45);} void VUserMain46() {VUserMain(46);} void VUserMain47() {VUserMain(47);}
|
||||
void VUserMain48() {VUserMain(48);} void VUserMain49() {VUserMain(49);} void VUserMain50() {VUserMain(50);} void VUserMain51() {VUserMain(51);}
|
||||
void VUserMain52() {VUserMain(52);} void VUserMain53() {VUserMain(53);} void VUserMain54() {VUserMain(54);} void VUserMain55() {VUserMain(55);}
|
||||
void VUserMain56() {VUserMain(56);} void VUserMain57() {VUserMain(57);} void VUserMain58() {VUserMain(58);} void VUserMain59() {VUserMain(59);}
|
||||
void VUserMain60() {VUserMain(60);} void VUserMain61() {VUserMain(61);} void VUserMain62() {VUserMain(62);} void VUserMain63() {VUserMain(63);}
|
||||
Loading…
Add table
Add a link
Reference in a new issue