Chisel poke() print format - scala

Is it possible to configure the print format of poke() function in Chisel test class ?
I want to 'poke()' an unsigned long (64bits) int and Chisel print it like a signed long int when I launch this code:
poke(c.io.masterwrite.wdata, 0xbebecacacafedecaL)
The result :
POKE AvlMasterWrite.io_masterwrite_wdata <- -0x4141353535012136
I can't add the letter 'U' like in C to force unsigned :
0xbebecacacafedecaUL
That doesn't compile.

The following should work:
import java.math._
poke (c.io.masterwrite.wdata, new BigInteger("bebecacacafedeca", 16)
The input port c.io.masterwrite.wdata should be of type UInt and 64-bit long.

Related

In DPI-C, How to map data type to reg or wire

I am writing a CRC16 function in C to use in System Verilog.
Requirement as below:
Output of CRC16 has 16 bits
Input of CRC16 has bigger than 72 bits
The difficulty is that I don't know whether DPI-C can support map data type with reg/wire in System Verilog to C or not ?
how many maximum length of reg/wire can support to use DPI-C.
Can anybody help me ?
Stay with compatible types across the language boundaries. For output use shortint For input, use an array of byte in SystemVerilog which maps to array of char in C.
Dpi support has provision for any bit width, converting packed arrays into c-arrays. The question is: what are you going to do with 72-bit data at c side?
But, svBitVecVal for two-state bits and svLogicVecVal for four-stat logics could be used at 'c' side to retrieve values. Look at H.7.6/7 of lrm for more info.
Here is an example from lrm H.10.2 for 4-state data (logic):
SystemVerilog:
typedef struct {int x; int y;} pair;
import "DPI-C" function void f1(input int i1, pair i2, output logic [63:0] o3);
C:
void f1(const int i1, const pair *i2, svLogicVecVal* o3)
{
int tab[8];
printf("%d\n", i1);
o3[0].aval = i2->x;
o3[0].bval = 0;
o3[1].aval = i2->y;
o3[1].b = 0;
...
}

Casting an int to Uint8 in Dart

I am using the ffi and tyed_data Dart libraries and keep running into an error with this line of code,
Uint8 START_OF_HEADER = 1 as Uint8;
My error:
type 'int' is not a subtype of type 'Uint8' in type cast
What am I doing wrong here? Another strange thing is that I can write this line of code using these libraries and my IDE will compile and not throw an error, that is until you use that line of code. I'm using Intellij version 2019.2.4
You are trying to create an instance of a Uint8 in Dart, but that's not possible - that type is just a marker.
/// [Uint8] is not constructible in the Dart code and serves purely as marker in
/// type signatures.
You'll just use those markers in the typedefs, for example to describe a C function taking two signed 32 bit ints and returning signed 32 bit int:
typedef native_sum_func = Int32 Function(Int32 a, Int32 b);
this will be paired with an equivalent Dart-like typedef
typedef NativeSum = int Function(int a, int b);
Dart ffi is responsible for converting a and b from Dart ints into 32 bit C ints and for converting the return value back to a Dart int.
Note that you can create a pointer to these C types, for example Pointer<Uint8> using the allocate method from package:ffi.

C programming on IAR- timestamp Conversion to readable format

I am using Z-stack-CC2530-2.5 for developing Zigbee-based application. I've come across a timestmap conversion problem.
I am using osal_ConvertUTCTime method to convert a uint32 timestamp value to timestampStruct as follows:
osal_ConvertUTCTime(& timestampStruct, timestamp);
The Struct is defined as follows:
typedef struct{
uint8 seconds;
uint8 min;
uint8 hour;
uint8 day;
uint8 month;
uint16 year;
} UTCTimeStruct
My Question:
How to convert the Struct's content to be written on the UART port in a human readable format ?
Example:
HalUARTWrite (Port0, timestampStruct, len) // Output: 22/1/2013 12:05:45
Thank you.
I do not have the prototype of the function HalUartWrite at the moment, but I googled it and someone used it as this:
HalUARTWrite(DEBUG_UART_PORT, "12345", 6);
so I guess the second argument must be a pointer to char. You can't just pass a struct UTCTimeStruct variable into the second argument. If you just need to output the raw data to the serial port. You need to cast the struct into char * in order to make the compiler happy. But generally, this is bad practice. This might not be a problem in your case as you work in a 8-bit processor that all the struct fields are either a char or a short. In general, if you cast a struct into a char * and print it out, due to struct padding, you get a lot of nonsense characters between your struct fields.
OK. A bit off topic. Back to your question, you need to convert the struct into a friendly string yourself. Because you know your output string is of format "22/1/2013 12:05:45" which has fixed length, you can simply declare a char[] of that length. And manually fill in the numbers by bit-manipulating the uint32 timestamp value. After that, you can pass the char[] into the second argument and the exact length into the third argument.

OpenCL convert uint4 to unsigned int

How do I convert uint4 type to unsigned int ? I am reading an image in the kernel using readimageui(). This returns uint4 type.
In the host code I tried using a buffer of type cl_uint4 when reading back results into the destination buffer but that didn't work out.

How to unpack (64-bit) unsigned long in 64-bit Perl?

I'm trying to unpack an unsigned long value that is passed from a C program to a Perl script via SysV::IPC.
It is known that the value is correct (I made a test which sends the same value into two queues, one read by Perl and the second by the C application), and all predecessing values are read correctly (used q instead of i! to work with 64-bit integers).
It is also known that PHP had something similar in bugs (search for "unsigned long on 64 bit machines") (seems to be similar:
Pack / unpack a 64-bit int on 64-bit architecture in PHP)
Arguments tested so far:
..Q ( = some value that is larger than expected)
..L ( = 0)
..L! ( = large value)
..l ( = 0)
..l! ( = large value)
..lN! ( = 0)
..N, ..N! ( = 0)
use bigint; use bignum; -- no effect.
Details:
sizeof(unsigned long) = 8;
Data::Dumper->new([$thatstring])->Useqq(1)->Dump(); a lot of null bytes along some meaningful..
byteorder='12345678';
Solution:
- x4Q with padding four bytes.
Unpacking using Q in the template works out of the box if you have 64-bit Perl:
The TEMPLATE is a sequence of characters that give the order
and type of values, as follows:
...
q A signed quad (64-bit) value.
Q An unsigned quad value.
(Quads are available only if your system supports 64-bit
integer values _and_ if Perl has been compiled to support those.
Causes a fatal error otherwise.)
For a more robust solution, unpack the value into an 8-byte string and use the Math::Int64 module to convert it to an integer:
use Math::Int64 qw( :native_if_available int64 );
...
$string_value = unpack("A8", $longint_from_the_C_program);
# one of these two functions will work, depending on your system's endian-ness
$int_value = Math::Int64::native_to_int64($string_value);
$int_value = Math::Int64::net_to_int64($string_value);
The solution was simple: added x4Q to skip four bytes before actual value; need to more visually think of padding/alignment..