|
|
|
Re: Creating a buffer in .cfg [message #3147 is a reply to message #2609] |
Thu, 07 May 2009 19:54 |
Eclipse User |
|
|
|
Originally posted by: bob.biosbob.biz
assigning target pointer-values in the meta-domain attempts to mirror
the semantics of C in the following sense: "specific" pointer-values
(eg., of type 'Attr*') can be assigned to "generic" pointer-variables of
type 'Ptr' *without* a cast; but also, generic pointer-values of type
'Ptr' can be assigned to specific pointer-values *without* a cast as
well. [FYI -- C++ only allows specific => generic, which seems a little
more typesafe]. needless to say, direct assignment of one specific kind
of pointer to a *different* specific kind of is prohibited; some sort of
cast is required.
in this case, there are several different ways obj.attrs can be assigned
-- other than, of course, supplying a "specific" value of type 'Attrs*'.
as in C -- where you can write (Attrs*)(0x1234) -- you can use the
$addr(0x1234) operator to produce a "generic" pointer-value that can
then bev assigned to obj.attrs; the generated package/cfg/*.c file will
actually insert the (Attrs*) cast within the static initializer.
more elaborate, you can use the $addrof operator to obtain a "generic"
pointer to an element of an aggregate object -- either an element of an
array or else a field of a struct. this corresponds to static
initializers of the form '&arr[12]' or '&str.fld'. in the example here,
you can assign directly assign obj.attrs = Buffers.buf.$addror(0); note
that this value *could* have first assigned to 'sharedAddr', though this
step is really not necessary.
finally, you can use the $externPtr(symbol) operator to yield a
"generic" pointer value corresponding to this symbol....
here's a litte test Mod i put together....
module Mod {
struct Attrs {
Int x;
};
config Ptr sharedAddr;
config Attrs* attrs;
config Char buffer[length];
int main( int argc, char* argv[] );
}
in my .cfg script i then wrote....
var Mod = xdc.useModule('Mod');
Mod.buffer.length = 1024;
Mod.sharedAddr = Mod.buffer.$addrof(0);
Mod.attrs = Mod.sharedAddr;
Mod.attrs = Mod.buffer.$addrof(0); // same effect
Mod.attrs = $externPtr('myAttrs'); // global var
Mod.attrs = $addr(1234); // hard addr
Todd Mullanix wrote:
> I have a HeapFoo module that has an instance configuration parameter
> that is an address (sharedAddr) and an Instance_State field attrs
>
> HeapFoo.xdc
> ===========
> instance:
> config Ptr sharedAddr = null;
> ...
> internal
> struct Instance_State {
> Attrs *attrs;
> ...
>
> I have the following line assignment in the instance$static$init:
> HeapFoo.xs
> ==========
> instance$static$init() {
> ..
> obj.attrs = $addr(params.sharedAddr);
> ..
>
> I want to test this on multiple targets/platforms, so I have a Buffers
> module:
> Buffers.xdc ===========
> module Buffers
> {
> config Char buf[length];
> }
>
>
> I create a buffer and assign it to sharedAddr
> testHeapFoo.cfg
> ===============
> Buffers = xdc.useModule('ti.sdo.ipc.testsHeaps.Buffers');
> var buf = Buffers.buf;
> buf.length = 1024;
> ..
> heapParams.sharedAddr = buf;
>
>
> The 1024 char buffer does get created (looked in the mapfile). But I'm
> getting an build error. It is complaining about the obj.attrs =
> $addr(params.sharedAddr); line
> "js: "/ti/sdo/ipc/HeapFoo.xs", line 98: Cannot convert
> ti.sdo.ipc.testsHeaps.Buffers/buf to java.lang.Long"
>
> I also tried heapParams.sharedAddr = buf.$addrof(0);
>
> "js: "ti/sdo/ipc/HeapFoo.xs", line 98: Cannot convert
> ti.sdo.ipc.testsHeaps.Buffers/buf/0.0 to java.lang.Long
>
> I also tried changing the buf type in Buffers.xdc to Long...same thing.
> Ideally, I'd like to just have a global variable in my testHeapFoo.c
> file and reference that in the testHeapFoo.cfg file, but I don't think
> that is possible.
>
> Ideas? Did I just mess something up, or am I going down the wrong path.
>
> Thanks,
> Todd
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.05073 seconds