diff --git a/code/VProc.h b/code/VProc.h index c1ad25c..92b8317 100644 --- a/code/VProc.h +++ b/code/VProc.h @@ -35,7 +35,7 @@ #include #include -#define VERSION_STRING "VProc version 1.7.2. Copyright (c) 2004-2024 Simon Southwell." +#define VERSION_STRING "VProc version 1.7.3. Copyright (c) 2004-2024 Simon Southwell." #ifndef VP_MAX_NODES #define VP_MAX_NODES 64 @@ -47,7 +47,8 @@ #define V_READ 2 #define BURSTLENLOBIT 2 -#define BELOBIT 14 +#define BEFIRSTLOBIT 14 +#define BELASTLOBIT 18 // Error types #define VP_USER_ERR 1 diff --git a/code/VProcClass.h b/code/VProcClass.h index 9b0d392..fe4fd92 100644 --- a/code/VProcClass.h +++ b/code/VProcClass.h @@ -57,15 +57,49 @@ public: *data = word; return status;}; - int burstWrite (const unsigned addr, void *data, const unsigned length) {return VBurstWrite (addr, data, length, node);}; - int burstRead (const unsigned addr, void *data, const unsigned length) {return VBurstRead (addr, data, length, node);}; - int tick (const unsigned ticks) {return VTick (ticks, node);}; - void regIrq (const pVUserIrqCB_t func) { VRegIrq (func, node);}; - void regInterrupt (const int level, const pVUserInt_t func) { VRegInterrupt (level, func, node);}; - void regUser (const pVUserCB_t func) { VRegUser (func, node);}; + int burstWrite (const unsigned addr, void *data, const unsigned wordlen) {return VBurstWrite (addr, data, wordlen, node);}; + int burstRead (const unsigned addr, void *data, const unsigned wordlen) {return VBurstRead (addr, data, wordlen, node);}; + int tick (const unsigned ticks) {return VTick (ticks, node);}; + void regIrq (const pVUserIrqCB_t func) { VRegIrq (func, node);}; + void regInterrupt (const int level, const pVUserInt_t func) { VRegInterrupt (level, func, node);}; + void regUser (const pVUserCB_t func) { VRegUser (func, node);}; + + + int burstWriteBytes (const unsigned byteaddr, void *data, const unsigned bytelen) {unsigned foff, loff; + unsigned wlen = calcWordLen(byteaddr, bytelen, foff, loff); + for (int idx = 0; idx < bytelen; idx++) + ((uint8_t*)bytebuf)[idx + (byteaddr&0x3)] = ((uint8_t*)data)[idx]; + + return VBurstWriteBE (byteaddr & ~(0x3), + bytebuf, + wlen, + (0xf << foff) & 0xf, + 0xf >> ((loff == 3) ? 0 : (3 - loff)), + node); + }; + + int burstReadBytes (const unsigned byteaddr, void *data, const unsigned bytelen) {unsigned foff, loff, wlen = calcWordLen(byteaddr, bytelen, foff, loff); + + int status = VBurstRead ((byteaddr & ~(0x3)), bytebuf, wlen, node); + + for (int idx = 0; idx < bytelen; idx++) + ((uint8_t*)data)[idx] = ((uint8_t*)bytebuf)[idx + (byteaddr & 0x3)]; + return status; + }; private: // VProc node number this object is accessing unsigned node; + + // Internal byte buffer + uint32_t bytebuf [(MAXBURSTLEN+1) * 4]; + + // Calculate the required word length, and first and last offsets, for given byte length with address offset + unsigned calcWordLen(const unsigned byteaddr, const unsigned bytelen, unsigned &foff, unsigned &loff) { + loff = (byteaddr + bytelen - 1) & 0x3; + foff = byteaddr & 0x3; + int diffoff = loff - foff; + return bytelen/4 + ((diffoff < 0) ? 1 : 0) + ((bytelen%4) ? 1 : 0); + }; }; \ No newline at end of file diff --git a/code/VUser.c b/code/VUser.c index d39d8f5..c8b3968 100644 --- a/code/VUser.c +++ b/code/VUser.c @@ -34,7 +34,7 @@ static void VUserInit (const unsigned node); // ========================================================================= -// Simulation interface functions +// Simulation interface functions // ========================================================================= // ------------------------------------------------------------------------- @@ -226,7 +226,7 @@ int VWriteBE (const unsigned addr, const unsigned data, const unsigned be, const sbuf.addr = addr; sbuf.data_out = data; - sbuf.rw = V_WRITE | ((be & 0xf) << BELOBIT); + sbuf.rw = V_WRITE | ((be & 0xf) << BEFIRSTLOBIT); sbuf.ticks = delta ? DELTA_CYCLE : 0; VExch(&sbuf, &rbuf, node); @@ -263,7 +263,7 @@ int VRead (const unsigned addr, unsigned *rdata, const int delta, const unsigned // Invokes a burst write message exchange // ------------------------------------------------------------------------- -int VBurstWrite (const unsigned addr, void *data, const unsigned len, const unsigned node) +int VBurstWrite (const unsigned addr, void *data, const unsigned wordlen, const unsigned node) { rcv_buf_t rbuf; send_buf_t sbuf; @@ -271,7 +271,31 @@ int VBurstWrite (const unsigned addr, void *data, const unsigned len, const unsi sbuf.addr = addr; sbuf.data_out = 0; sbuf.data_p = data; - sbuf.rw = V_WRITE | ((len & 0xfff) << BURSTLENLOBIT) | (0xf << BELOBIT);; + sbuf.rw = V_WRITE | ((wordlen & 0xfff) << BURSTLENLOBIT) | (0xf << BEFIRSTLOBIT) | (0xf << BELASTLOBIT); + sbuf.ticks = 0; + + VExch(&sbuf, &rbuf, node); + + return 0; +} + +// ------------------------------------------------------------------------- +// VBurstWrite() +// +// Invokes a burst write message exchange +// ------------------------------------------------------------------------- + +int VBurstWriteBE (const unsigned addr, void *data, const unsigned wordlen, const unsigned fbe, const unsigned lbe, const unsigned node) +{ + rcv_buf_t rbuf; + send_buf_t sbuf; + + sbuf.addr = addr; + sbuf.data_out = 0; + sbuf.data_p = data; + sbuf.rw = V_WRITE | ((wordlen & 0xfff) << BURSTLENLOBIT) | + ((fbe & 0xf) << BEFIRSTLOBIT) | + ((lbe & 0xf) << BELASTLOBIT); sbuf.ticks = 0; VExch(&sbuf, &rbuf, node); @@ -285,7 +309,7 @@ int VBurstWrite (const unsigned addr, void *data, const unsigned len, const unsi // Invokes a burst read message exchange // ------------------------------------------------------------------------- -int VBurstRead (const unsigned int addr, void *data, const unsigned len, const unsigned node) +int VBurstRead (const unsigned int addr, void *data, const unsigned wordlen, const unsigned node) { rcv_buf_t rbuf; send_buf_t sbuf; @@ -293,7 +317,7 @@ int VBurstRead (const unsigned int addr, void *data, const unsigned len, const u sbuf.addr = addr; sbuf.data_out = 0; sbuf.data_p = data; - sbuf.rw = V_READ | ((len & 0xfff) << 2); + sbuf.rw = V_READ | ((wordlen & 0xfff) << 2) | (0xffff << BEFIRSTLOBIT); sbuf.ticks = 0; VExch(&sbuf, &rbuf, node); @@ -344,7 +368,7 @@ void VRegInterrupt (const int level, const pVUserInt_t func, const unsigned node // ------------------------------------------------------------------------- // VRegIrq() -// +// // Registers a user function as a vector IRQ callback // ------------------------------------------------------------------------- diff --git a/code/VUser.h b/code/VUser.h index 70cd689..ebf4c40 100644 --- a/code/VUser.h +++ b/code/VUser.h @@ -33,6 +33,8 @@ #define MAX_INT_LEVEL 7 #define MIN_INT_LEVEL 1 +#define MAXBURSTLEN 4096 + // When compiling in windows (32- or 64-bit) ... #ifdef WIN32 # include @@ -69,8 +71,9 @@ typedef void *(*pThreadFunc_t)(void *); extern int VWrite (const unsigned addr, const unsigned data, const int delta, const unsigned node); extern int VWriteBE (const unsigned addr, const unsigned data, const unsigned be, const int delta, const unsigned node); extern int VRead (const unsigned addr, unsigned *data, const int delta, const unsigned node); -extern int VBurstWrite (const unsigned addr, void *data, const unsigned len, const unsigned node); -extern int VBurstRead (const unsigned addr, void *data, const unsigned len, const unsigned node); +extern int VBurstWrite (const unsigned addr, void *data, const unsigned wordlen, const unsigned node); +extern int VBurstWriteBE (const unsigned addr, void *data, const unsigned wordlen, const unsigned fbe, const unsigned lbe, const unsigned node); +extern int VBurstRead (const unsigned addr, void *data, const unsigned wordlen, const unsigned node); extern int VTick (const unsigned ticks, const unsigned node); extern void VRegInterrupt (const int level, const pVUserInt_t func, const unsigned node); extern void VRegIrq (const pVUserIrqCB_t func, const unsigned node); diff --git a/doc/VProc.pdf b/doc/VProc.pdf index dca9361..fb39a08 100644 Binary files a/doc/VProc.pdf and b/doc/VProc.pdf differ diff --git a/f_VProc.v b/f_VProc.v index 0902c25..c575845 100644 --- a/f_VProc.v +++ b/f_VProc.v @@ -98,6 +98,7 @@ reg Initialised; integer TickCount; integer BlkCount; integer AccIdx; +integer LBE; `ifndef VPROC_BYTE_ENABLE // When no byte enable define a local dummy register to @@ -224,6 +225,7 @@ begin WE <= VPRW[`WEBIT]; RD <= VPRW[`RDBIT]; BE <= VPRW[`BEBITS]; + LBE <= VPRW[`LBEBITS]; Addr <= VPAddr; // If new BlkCount is non-zero, setup burst transfer @@ -234,6 +236,12 @@ begin // Initialise the burst block counter with count bits BlkCount = VPRW[`BLKBITS]; + + // If a single word transfer, set the last flag + if (BlkCount == 1) + begin + BurstLast <= 1'b1; + end // On writes, override VPDataOut to get from burst access task VAccess at index 0 if (VPRW[`WEBIT]) @@ -261,6 +269,11 @@ begin if (BlkCount == 1) begin BurstLast <= 1'b1; + BE <= LBE; + end + else + begin + BE <= 4'hf; end // When bursting, reassert non-delta VPTicks value to break out of loop. diff --git a/f_vproc.vhd b/f_vproc.vhd index 02b019d..798fe01 100644 --- a/f_vproc.vhd +++ b/f_vproc.vhd @@ -61,15 +61,18 @@ end; architecture model of VProc is -constant WEbit : integer := 0; -constant RDbit : integer := 1; -constant BLKHIBIT : integer := 13; -constant BLKLOBIT : integer := 2; -constant BEHIBIT : integer := 17; -constant BELOBIT : integer := 14; -constant DeltaCycle : integer := -1; +constant WEbit : integer := 0; +constant RDbit : integer := 1; +constant BLKHIBIT : integer := 13; +constant BLKLOBIT : integer := 2; +constant BEFIRSTLOBIT : integer := 14; +constant BEFIRSTHIBIT : integer := 17; +constant BELASTLOBIT : integer := 18; +constant BELASTHIBIT : integer := 21; +constant DeltaCycle : integer := -1; -signal Initialised : integer := 0; +signal Initialised : integer := 0; +signal LBE : std_logic_vector(3 downto 0) := 4x"F"; begin -- Initial @@ -184,7 +187,8 @@ begin VPTicks); Burst <= std_logic_vector(to_unsigned(VPRW, 32)(BLKHIBIT downto BLKLOBIT)); - BE <= std_logic_vector(to_unsigned(VPRW, 32)(BEHIBIT downto BELOBIT)); + BE <= std_logic_vector(to_unsigned(VPRW, 32)(BEFIRSTHIBIT downto BEFIRSTLOBIT)); + LBE <= std_logic_vector(to_unsigned(VPRW, 32)(BELASTHIBIT downto BELASTLOBIT)); WE <= to_unsigned(VPRW, 32)(WEbit); RD <= to_unsigned(VPRW, 32)(RDbit); Addr <= std_logic_vector(to_signed(VPAddr, 32)); @@ -194,6 +198,11 @@ begin -- If new BlkCount is non-zero, setup burst transfer if BlkCount /= 0 then BurstFirst <= '1'; + + -- If a single word transfer, set the last flag + if BlkCount = 1 then + BurstLast <= '1'; + end if; -- On writes, override VPDataOut to get from burst access task $VAccess at index 0 if to_unsigned(VPRW, 32)(WEbit) = '1' then @@ -226,6 +235,9 @@ begin if BlkCount = 1 then BurstLast <= '1'; + BE <= LBE; + else + BE <= x"F"; end if; -- When bursting, reassert non-delta VPTicks value to break out of loop. diff --git a/python/modules/pyvproc.py b/python/modules/pyvproc.py index d6dbbd3..e4963a3 100644 --- a/python/modules/pyvproc.py +++ b/python/modules/pyvproc.py @@ -51,7 +51,7 @@ class PyVProcClass : def write (self, addr, data, delta = 0) : self.__processIrq() self.api.PyWrite(addr, data, delta, self.node) - + # API method to write a word def writeBE (self, addr, data, be, delta = 0) : self.__processIrq() @@ -61,7 +61,7 @@ class PyVProcClass : def read (self, addr, delta = 0) : self.__processIrq() return self.api.PyRead(addr, delta, self.node) - + # API method to read a word as unsigned value def uread (self, addr, delta = 0) : self.__processIrq() @@ -72,12 +72,17 @@ class PyVProcClass : for i in range(ticks) : self.__processIrq() self.api.PyTick(1, self.node) - + # API method to do a burst write def burstWrite(self, addr, data, length) : self.__processIrq() self.api.PyBurstWrite(addr, (c_int * len(data))(*data), length, self.node) - + + # API method to do a burst write with byte enables + def burstWriteBE(self, addr, data, length, fbe, lbe) : + self.__processIrq() + self.api.PyBurstWrite(addr, (c_int * len(data))(*data), length, fbe, lbe, self.node) + # API method to do a burst read def burstRead(self, addr, length) : self.__processIrq() @@ -91,18 +96,18 @@ class PyVProcClass : # API method to register a vectored interrupt callback def regIrq(self, irqCb) : self.__irqcb = irqCb - + def __processIrq (self) : while True : irq = (c_int * 1)(0) count = self.api.PyFetchIrq(irq, self.node) - + if count : if self.__irqcb != None : self.__irqcb(c_uint32(irq[0]).value) else : break - + def VPrint(self, printstr) : bytestring = printstr.encode('utf-8') self.api.PyPrint(c_char_p(bytestring)) diff --git a/python/src/PythonVProc.c b/python/src/PythonVProc.c index 0783b50..304724b 100644 --- a/python/src/PythonVProc.c +++ b/python/src/PythonVProc.c @@ -28,6 +28,7 @@ static wfunc_p Vwrite; static wbefunc_p VwriteBE; static rfunc_p Vread; static wbfunc_p VburstWrite; +static wbbefunc_p VburstWriteBE; static rbfunc_p VburstRead; static tkfunc_p Vtick; static regirqfunc_p VregIrqPy; @@ -75,6 +76,12 @@ static int BindToApiFuncs(void) fprintf(stderr, "***ERROR: failed to find symbol VBurstWrite\n"); return 1; } + + if ((VburstWriteBE = (wbbefunc_p)dlsym(hdl, "VBurstWriteBE")) == NULL) + { + fprintf(stderr, "***ERROR: failed to find symbol VBurstWriteBE\n"); + return 1; + } if ((VburstRead = (rbfunc_p)dlsym(hdl, "VBurstRead")) == NULL) { @@ -254,6 +261,15 @@ uint32_t PyBurstWrite (const uint32_t addr, void *data, const uint32_t len, cons return VburstWrite(addr, data, len, node); } +// ------------------------------------------------------------ +// VBurstWriteBE wrapper function for Python +// ------------------------------------------------------------ + +uint32_t PyBurstWriteBE (const uint32_t addr, void *data, const uint32_t len, uint32_t fbe, uint32_t lbe, const uint32_t node) +{ + return VburstWrite(addr, data, len, node); +} + // ------------------------------------------------------------ // VBurstRead wrapper function for Python // ------------------------------------------------------------ diff --git a/python/src/PythonVProc.h b/python/src/PythonVProc.h index b35cc96..67657e6 100644 --- a/python/src/PythonVProc.h +++ b/python/src/PythonVProc.h @@ -36,6 +36,7 @@ typedef int (*wfunc_p) (const unsigned, const unsigned, const int, con typedef int (*wbefunc_p) (const unsigned, 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 (*wbbefunc_p) (const unsigned, void *, const unsigned, const unsigned, 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); @@ -49,6 +50,7 @@ uint32_t PyWriteBE (const uint32_t addr, const uint32_t data, const uint3 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 PyBurstWriteBE (const uint32_t addr, void *data, const uint32_t len, const uint32_t fbe, const uint32_t lbe, 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); diff --git a/test/usercode/VUserMain1.cpp b/test/usercode/VUserMain1.cpp index 58e400f..f108d64 100644 --- a/test/usercode/VUserMain1.cpp +++ b/test/usercode/VUserMain1.cpp @@ -204,6 +204,7 @@ extern "C" void VUserMain1() { wbuf[idx] = 0x00010000 + idx; } + vp1.burstWrite(addr, wbuf, 8); VPrint("Node %d: burst wrote 8 words from addr %08x\n", node, addr); @@ -221,6 +222,34 @@ extern "C" void VUserMain1() } VPrint("Node %d: burst read 8 words from addr %08x\n", node, addr); + + // ------------------------------------------- + // Write offset burst data to memory + + addr = 0xa1000032; + + for (int idx = 0; idx < 11; idx++) + { + ((uint8_t*)wbuf)[idx] = idx + 0x10; + } + + vp1.tick(1); + vp1.burstWriteBytes(addr, wbuf, 11); + VPrint("Node %d: burst wrote 11 bytes from addr %08x\n", node, addr); + + vp1.tick(2); + vp1.burstReadBytes(addr, rbuf, 11); + + for (int idx = 0; idx < 11; idx++) + { + if (((uint8_t*)rbuf)[idx] != ((uint8_t*)wbuf)[idx]) + { + VPrint("***Error: burst data byte miscompare in node %d (%08x v %08x at index %d)\n", node, ((uint8_t*)rbuf)[idx], ((uint8_t*)wbuf)[idx]); + SLEEP; + } + } + + VPrint("Node %d: burst read 11 bytes from addr %08x\n", node, addr); // Wait a bit and then stop the simulation vp1.tick(10); diff --git a/vprocdefs.vh b/vprocdefs.vh index 7d62b11..38af065 100644 --- a/vprocdefs.vh +++ b/vprocdefs.vh @@ -30,6 +30,7 @@ `define RDBIT 1 `define BLKBITS 13:2 `define BEBITS 17:14 +`define LBEBITS 21:18 `define DELTACYCLE -1 `define DONTCARE 0