DSPRelated.com
Forums

access to XSP, XSSP from c code, (I/O memory)

Started by grze...@woodanddouglas.co.uk September 23, 2008
Hi all

It is my first post in c55 group and I would like to say hello everyone!

I have one problem, how to get value of register XSP/XSSP from c code?
I could not find anything in CSL library, I know that XSP is under address 0x4E, but how to get value of that memory?

I need this to measure consumption of stack, protection of stack overflow etc. But maybe there is somewhere ready library?

Kind Regards
/Greg
Greg-

> It is my first post in c55 group and I would like to say hello everyone!
>
> I have one problem, how to get value of register XSP/XSSP from c code?
> I could not find anything in CSL library, I know that XSP is under
> address 0x4E, but how to get value of that memory?
>
> I need this to measure consumption of stack, protection of stack
> overflow etc. But maybe there is somewhere ready library?

Typically the codegen tools support register keywords, so you could try something
like:

extern cregister volatile unsigned int XSP;
volatile unsigned int XSP_reg;

XSP_reg = XSP;

This works on C6x, for example registers such as CSR, IER, etc. Not sure about C55x.

If that doesn't work, you can try this:

#define XSP 0x4E

XSP_reg = *(volatile unsigned int *)XSP;

-Jeff
Greg-

> > It is my first post in c55 group and I would like to say hello everyone!
> >
> > I have one problem, how to get value of register XSP/XSSP from c code?
> > I could not find anything in CSL library, I know that XSP is under
> > address 0x4E, but how to get value of that memory?
> >
> > I need this to measure consumption of stack, protection of stack
> > overflow etc. But maybe there is somewhere ready library?
>
> Typically the codegen tools support register keywords, so you could try something
> like:
>
> extern cregister volatile unsigned int XSP;
> volatile unsigned int XSP_reg;
>
> XSP_reg = XSP;
>
> This works on C6x, for example registers such as CSR, IER, etc. Not sure about C55x.
>
> If that doesn't work, you can try this:
>
> #define XSP 0x4E
>
> XSP_reg = *(volatile unsigned int *)XSP;
>
> -Jeff
>
> <<--- Cat quote here
>
> Hi, thank you for answer.
> Both method do not works.
> I tried second method of course before I posted, but obviously do not works because:
>
> From spru371f:
> "I/O space is separate from data/program space and is available only for
> accessing registers of the peripherals on the DSP."
> In first I had compiler error (CCS 3.1):
>
> unrecognized cregister name 'XSP'
> extern cregister volatile unsigned int XSP;
>
> any include files or simply not supported? I can not find this 'cregister'
> in documentation.
>
> Any hints?

Why didn't you mention I/O space in your first post? That would be just a little bit
significant. Suggest to try this:

XSP_reg = *(ioport volatile unsigned int *)XSP;

-Jeff
Greg-

> > > It is my first post in c55 group and I would like to say hello everyone!
> > >
> > > I have one problem, how to get value of register XSP/XSSP from c code?
> > > I could not find anything in CSL library, I know that XSP is under
> > > address 0x4E, but how to get value of that memory?
> > >
> > > I need this to measure consumption of stack, protection of stack
> > > overflow etc. But maybe there is somewhere ready library?
> >
> > Typically the codegen tools support register keywords, so you could try something
> > like:
> >
> > extern cregister volatile unsigned int XSP;
> > volatile unsigned int XSP_reg;
> >
> > XSP_reg = XSP;
> >
> > This works on C6x, for example registers such as CSR, IER, etc. Not sure about C55x.
> >
> > If that doesn't work, you can try this:
> >
> > #define XSP 0x4E
> >
> > XSP_reg = *(volatile unsigned int *)XSP;
> >
> > -Jeff
> >
> > <<--- Cat quote here
> >
> > Hi, thank you for answer.
> > Both method do not works.
> > I tried second method of course before I posted, but obviously do not works because:
> >
> > From spru371f:
> > "I/O space is separate from data/program space and is available only for
> > accessing registers of the peripherals on the DSP."
> > In first I had compiler error (CCS 3.1):
> >
> > unrecognized cregister name 'XSP'
> > extern cregister volatile unsigned int XSP;
> >
> > any include files or simply not supported? I can not find this 'cregister'
> > in documentation.
> >
> > Any hints?
>
> Why didn't you mention I/O space in your first post? That would be just a little bit
> significant. Suggest to try this:
>
> XSP_reg = *(ioport volatile unsigned int *)XSP;
>
> -Jeff
>
> Thank You Jeff
>
> Of course ioport... but XSP is not in ioport space but simply mapped in
> data space, I am sorry, I did not understand first time documentation
> and mix I/O and CPU Memory-Mapped Registers SPRS166J page 105.
>
> Of course this
>
> XSP_reg = *(volatile unsigned int *) 0x004E;
>
> Works but ... gave me 0x0000 and I though this is not working, but SP
> is on address 0x004D and:
>
> XSP_reg = *(volatile unsigned int *) 0x004D;
>
> is OK.

Ok... seems like it's working then, great! XSP would only be non-zero if your stack
is located above 64k in data mem.

-Jeff
> It is my first post in c55 group and I would like to say hello everyone!
>
> I have one problem, how to get value of register XSP/XSSP from c code?
> I could not find anything in CSL library, I know that XSP is under
> address 0x4E, but how to get value of that memory?
>
> I need this to measure consumption of stack, protection of stack
> overflow etc. But maybe there is somewhere ready library?

Typically the codegen tools support register keywords, so you could try something
like:

extern cregister volatile unsigned int XSP;
volatile unsigned int XSP_reg;

XSP_reg = XSP;

This works on C6x, for example registers such as CSR, IER, etc. Not sure about C55x.

If that doesn't work, you can try this:

#define XSP 0x4E

XSP_reg = *(volatile unsigned int *)XSP;

-Jeff
<<--- Cat quote here

Hi, thank you for answer.
Both method do not works.
I tried second method of course before I posted, but obviously do not works because:

>From spru371f:
"I/O space is separate from data/program space and is available only for
accessing registers of the peripherals on the DSP."
In first I had compiler error (CCS 3.1):
unrecognized cregister name 'XSP'
extern cregister volatile unsigned int XSP;
any include files or simply not supported? I can not find this 'cregister' in documentation.

Any hints?

Kind Regards
//greg
> > It is my first post in c55 group and I would like to say hello everyone!
> >
> > I have one problem, how to get value of register XSP/XSSP from c code?
> > I could not find anything in CSL library, I know that XSP is under
> > address 0x4E, but how to get value of that memory?
> >
> > I need this to measure consumption of stack, protection of stack
> > overflow etc. But maybe there is somewhere ready library?
>
> Typically the codegen tools support register keywords, so you could try something
> like:
>
> extern cregister volatile unsigned int XSP;
> volatile unsigned int XSP_reg;
>
> XSP_reg = XSP;
>
> This works on C6x, for example registers such as CSR, IER, etc. Not sure about C55x.
>
> If that doesn't work, you can try this:
>
> #define XSP 0x4E
>
> XSP_reg = *(volatile unsigned int *)XSP;
>
> -Jeff
>
> <<--- Cat quote here
>
> Hi, thank you for answer.
> Both method do not works.
> I tried second method of course before I posted, but obviously do not works because:
>
> From spru371f:
> "I/O space is separate from data/program space and is available only for
> accessing registers of the peripherals on the DSP."
> In first I had compiler error (CCS 3.1):
>
> unrecognized cregister name 'XSP'
> extern cregister volatile unsigned int XSP;
>
> any include files or simply not supported? I can not find this 'cregister'
> in documentation.
>
> Any hints?

Why didn't you mention I/O space in your first post? That would be just a little bit
significant. Suggest to try this:

XSP_reg = *(ioport volatile unsigned int *)XSP;

-Jeff
Thank You Jeff

Of course ioport... but XSP is not in ioport space but simply mapped in data space, I am sorry, I did not understand first time documentation and mix I/O and CPU Memory-Mapped Registers SPRS166J page 105.

Of course this

XSP_reg = *(volatile unsigned int *) 0x004E;

Works but ... gave me 0x0000 and I though this is not working, but SP is on address 0x004D and:

XSP_reg = *(volatile unsigned int *) 0x004D;

is OK.

Thank You for your time and I am sorry for my mistake.

Kind Regards