XGATE Question

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
2,184件の閲覧回数
roberthiebert
Senior Contributor I

MC9S12XEP100. I would like to do some code experiments using XGATE, coding in absolute assembler. Is this even possible using Code Warrior 5.9.0 Special Edition Build 5294?

Regards,

Robert Hiebert

0 件の賞賛
返信
1 解決策
369件の閲覧回数
roberthiebert
Senior Contributor I

Well, despite my best efforts I have been unsuccessful in writing any XGATE code in absolute assembler. However, I have made some progress in writing one in relocatable assembler, which I am attaching.

The next step is to take some code I have written in absolute assembler and try to convert it to relocatable and add XGATE to it. So far I'm not getting very far with that, but at least I do have some working XGATE code now.

Thanks go to Ladislav for his assistance.

Regards,

Robert

元の投稿で解決策を見る

0 件の賞賛
返信
16 返答(返信)
1,278件の閲覧回数
lama
NXP TechSupport
NXP TechSupport

Hi,

OK, another example I created now (based on c project, disassembled and ported to the asm project), just to know whether I have not forgotten.

…not RTI but two PITs generate periods. One at CPU (PIT1) and another one at XGATE (PIT0). Both modules use a shared 8bit variable XGATE_diodes which is modified in PIT interrupts and access to this variable is controlled by semaphores.

It shows you, I think everything. I have also used different addressing styles .. once with register definition and once with direct number…just an example.

 

..as I expressed myself many times....in this case I would not us asm programming at xgate. much simpler is C coding which also automatically solves many issues you can hit.

Boht projects ASM and C are attached.

Best regards,

Ladislav

0 件の賞賛
返信
1,269件の閲覧回数
roberthiebert
Senior Contributor I

Hi Ladislav,

Your help is much appreciated, thanks very much. I would code in "C" if I could, but I don't speak the language. I have tried to learn it by myself, but it is way too obscure for me. I like assembler because I can observe the registers and memory with the debugger. It makes sense to me. My programs aren't huge, and I'm the only one creating them. That's why I prefer absolute assembler.

Anyway, I will study your attachments and see what I can do with them. Again, many thanks.

Regards,

Robert

0 件の賞賛
返信
1,261件の閲覧回数
roberthiebert
Senior Contributor I

Hi Ladislav,

I am able to run your .asm code on my board if I switch to USBDM, but I get the following messages. They do not stop me from making or running the program:

*************

 The following access path in target "standard" of project "XP100-PIT_XGATE_SEMAPHORES-ASM-C52.mcp" cannot be found:

(Project)..\XP100-PIT_XGATE_SEMAPHORES-ASM-C51

Could not find "XP100-PIT_XGATE_SEMAPHORES-ASM-C51.mcp" in target "Standard" 

********

I am able to set break points and step through source code in the source1 window. I would like to set break points and step through the XGATE code, but it doesn't appear in the source2 window. Is there a setting I am missing to be able t do this?

Regards,

Robert 

0 件の賞賛
返信
1,248件の閲覧回数
lama
NXP TechSupport
NXP TechSupport

Hi,

a) The cleaned project is attached on original place. Older one was removed. There was no problem from functionality point of view also with older one just some things were accidentally added.

Now it should be ok. 

b) press right mouse button while pointer is on empty window, open source file, select xgate.dbg and break point into the PIT0_Handler.

lama_0-1753958435119.png

lama_1-1753958496130.png

You can see after run it stops in xgate

lama_3-1753958636639.png

as well as in cpu 

 

lama_4-1753958695092.png

 

Best regards,

Ladislav

 

0 件の賞賛
返信
769件の閲覧回数
roberthiebert
Senior Contributor I

Hi Ladislav,

Things have been too busy around here for me to spend much time on my project, but I am finally able to get back to it. I have been studying the code you sent, me as well as the example that I can create with Code Warrior. Essentially it is the Fibo Calculation program in relocatable assembler with XGATE added in RAM.

I believe I have a pretty good understanding of how it works, but one thing puzzles me.

When I step through the code and follow the registers and memory, the "CopyToRam" macro doesn't quite make sense to me. PPAGE is $FE, GPAGE is $7F and RPAGE is $F8.

I expected the XGATE code in Flash to start at logical address $7F8000, and be copied to RAM  at logical address $F81100. But, in fact, the XGATE code starts at logical address $FE8000, and it copies quite nicely to the expected RAM address.

What am I missing here?

Regards,

Robert 

0 件の賞賛
返信
695件の閲覧回数
lama
NXP TechSupport
NXP TechSupport

Hi,

Once upon a time, I sent you a memory map. You should now understand which core uses which addressing mode and how it accesses data and code.

CPU runs on PPAGE_OFFSET, but data is usually read/written using GPAGE_offset to simplify access.

XGATE can run from either flash or RAM. Before it can run from RAM, it must be copied from flash to the corresponding memory space. If you want XGATE to run from flash, you need to configure this during project creation-then no copying is required.

What I suggest is always to introduce code in each module by correct memory placement…

For example

#pragma  CODE_SEG  DEFAULT

#pragma  DATA_SEG  DEFAULT

 

#pragma CODE_SEG XGATE_CODE_FLASH

#pragma DATA_SEG SHARED_DATA

#pragma DATA_SEG XGATE_DATA

 

For the copying process (if used-I'm not going to check it), I would recommend using GLD/GST instructions to easily access the global memory space. As shown in the memory map, only part of the RAM is accessible for data using 16-bit addressing (from the CPU's perspective). To write to the part of RAM that is not visible via 16-bit addressing, you must use GPAGE or RPAGE addressing modes. However, when XGATE is running, it sees the entire RAM using 16-bit addressing.

Of course, even if the code runs from flash, there can still be a copyToRam function that initializes variables for both the CPU and XGATE.

I strongly suggest always using a simulator or debugger for testing to better understand the behavior. It's essential to test different addresses-meaning within the same address space but using different addressing modes-in the memory window to verify whether the same content is visible across them.

Frankly, I am currently creating my hobby project at XDT512 and also have to debug a lot to be sure whether everything is where it is expected to be and result are as expected. Also warnings are important to read. I put display function to xgate a call them by swi from cpu. In order to avoid mistakes I always use integers as variables (xgate can make issue with arrays, structures because char is not good variable for it). I had also had to create conversion functions for pointers .. can be seen in conversion.c. As well as I used specific approach to init input parameters passing to xgate from cpu…you can see for example LCDcSetup(….), I call at CPU,  which fill specific structure which is then used by void LCDxSetup(tUI setup) after the data set is prepared in the module lcd_comman_wrappers.c and the xgate is launched by SWI after data preparing. Of course there could be some amount of shared data prepared and different approach used but this is the way I used to pass parameters to the xgate functions from cpu.

I do not want to confuse or scare you. I want only to say the more combinations and expectation the more issues and more complex tasks to solve. After initial effort everything will be more easy and clear. Everything can be done easily or complex. I had LCD module for cpu and wanted to put it as easy as possible to xgate and I used this solution. It can be seen as useless because XGATE was intended to be used for small fast task. In this case I wanted to offoad cpu from long sending data tasks.

Currently I also have some bugs in it but going step by step and this is what I suggest also to you.

The S12X device are so simply that you can fully delete all files generated by compiler and simply load stack as a first instruction of you code and then to have everything under your control.

Best regards,

Ladislav

0 件の賞賛
返信
682件の閲覧回数
roberthiebert
Senior Contributor I

Hi Ladislav,

That is a large composition, and being written in "C" it is completely beyond me.

I do have the AN 2734, HCS12X Family Memory Organization, but I don't see XGATE mentioned in there. Of course, the MC9S12XEP100RMV1 02/20/13 does include the XGATE memory map. I'll study them both some more and see if things become clearer to me.

If I could, could we go back to a question I asked earlier in this thread, (7/21/25). I noticed in the reference manual at 10.9.2 there is the code example (Transmit "Hello World!" on SCI). That would indicate to me that it is possible to write code that utilizes XGATE in absolute assembler. But when I try to run the code on Code Warrior, it chokes and tells me that "CPU S12X" is not a hc12 instruction.

What do I have to do to be able to run this code?

Regards,

Robert

0 件の賞賛
返信
370件の閲覧回数
roberthiebert
Senior Contributor I

Well, despite my best efforts I have been unsuccessful in writing any XGATE code in absolute assembler. However, I have made some progress in writing one in relocatable assembler, which I am attaching.

The next step is to take some code I have written in absolute assembler and try to convert it to relocatable and add XGATE to it. So far I'm not getting very far with that, but at least I do have some working XGATE code now.

Thanks go to Ladislav for his assistance.

Regards,

Robert

0 件の賞賛
返信
2,162件の閲覧回数
lama
NXP TechSupport
NXP TechSupport

Hi,

I do not know any person working in absolute assembly especially with XGATE. There is possibility to create a relocatable assembly project with multicore (CPU+XGATE).
Some info ca be found in the installation folder of the CW - file Assembler_XGATE.pdf... for example in my PC ..

c:\Program Files (x86)\Freescale\CWS12v5.2\Help\pdf\

 

Best regards,

Ladislav

0 件の賞賛
返信
1,981件の閲覧回数
roberthiebert
Senior Contributor I

Hi Ladislav,

I have been studying the XGATE Assembler Manual .PDF, found where you indicated it would be, but I'm afraid the explanations there are not clear to me. 

Reading through the MC9S12XEP100RMV1 manual, (again and again), I did come across something that indicated to me that writing code for the S12X CPU and XGATE in absolute assembler is possible. It is in Section 10.9.2 of the manual and is entitled Code Example (Transmits "Hello World" on SCI).

However, when I tried to run it with Code Warrior it choked right away. The first error was that "CPU S12X" was not a hc12 instruction or directive.

What do I have to do to run this program?  

0 件の賞賛
返信
1,946件の閲覧回数
roberthiebert
Senior Contributor I

Hi Ladislav,

Yes, I have that tried it but with no success. Perhaps I was just transferring too much of my code at once. I'll try it again and go real slow. Thanks.

Regards,

Robert

0 件の賞賛
返信
1,959件の閲覧回数
lama
NXP TechSupport
NXP TechSupport

Hi,

have you tried to create a new project which crates a default structure with sw trigger example. It also presents shared variables processing (not semaphores). When you have this you can extend it with your code. But, I suggest to go step by step and review everything. 

Best regards,

Ladislav

0 件の賞賛
返信
1,760件の閲覧回数
roberthiebert
Senior Contributor I

I'm not getting very far with this. I created the new sample project with relocatable assembler and XGATE as you suggested. When I run it and stop it again, I can see that the counter has been updated as well as the Fibo result. When stopped I can see that XGATE R1, R2, R7, PC, MCTL, CHIP and VBR have changed, or at least some have.

When I step through the main.asm code I can follow it along and see the numbers and registers update, but at no point do I see where it runs the XGATE code.

It looks like all the XGATE code does is update the counter when the software interrupt is triggered, but I don't see what initiates that software interrupt for XGATE.

0 件の賞賛
返信
1,576件の閲覧回数
lama
NXP TechSupport
NXP TechSupport

Hi,

 

 

The SWI is only enabled in the example so I suggest you to set breakpoint

lama_0-1753690010218.png

 

And select XGATE window (see in the picture it is darker blue) then press run. Each time the interrupt is finished and when it goes to the interrupt machine it is evaluated as a pending interrupt so it is launched again.

lama_1-1753690010218.png

 

 

…. And able to see all changes

lama_2-1753690010226.png

 

… after few steps ….

 

lama_3-1753690010228.png

 

 

Only to show small example of different approach  … I am currently playing (hobby activity ) with moving LCD driver to XGATE…but in C. I use SW trigger to launch service routine for LCD like this… for example…

I have definition..

 #define SET_SW_TRIG_LCD     XGSWT=(0x0101 << SWI_LCD)   // SWI_LCD is 0 … SWI_0 is selected

 #define REL_SW_TRIG_LCD     XGSWT=(0x0100 << SWI_LCD)

 

Then I have HD44780.c which prepares shared data and launches LCD service routine by SWI.
tUC LCDcOutTextLC(tUC line, tUC col, tSC *str) {

    if(LCD_IS_BUSY) return C_LCD_IS_BUSY;

    xgateCmdBlock.func_id = LCD_OUT_TEXT_LC;

    xgateCmdBlock.params.lineColText.line = line;

    xgateCmdBlock.params.lineColText.col = col;

    xgateCmdBlock.params.lineColText.str = str;

    SET_SW_TRIG_LCD;                                       <<<<<<<<<<<<<<<< here I start  LCD service

}

… and in the xgate.cxgate I release it to be prepared for next action …. The XGSWT value is also used as a flag for LCD busy

 

interrupt void SoftwareTrigger0_Handler(void)

{

  LCDxCommandExecution();

  REL_SW_TRIG_LCD;                             // release SW trigger 0

}

The code is translated as follows…  ( XGSWT = (0x0100 << 0) ; )

 

   12:    REL_SW_TRIG_LCD;                             // release SW trigger 0

  0008 f200             LDL        R2,#0

  000a aa01             ORH        R2,#1

  000c f300             LDL        R3,#%XGATE_8(_XGSWT)

  000e ab00             ORH        R3,#%XGATE_8_H(_XGSWT)

  0010 5a60             STW        R2,(R3,#0)

 

 

 

Best regards,

Ladislav

0 件の賞賛
返信
1,463件の閲覧回数
roberthiebert
Senior Contributor I

Hi Ladislav,

I had taken a couple of days to study the code in depth, step through it, and note the states of the relevant registers and variables at each step. I determined that the variable  XGATE_Counter is located at address $2100:2101, variable Counter is at address $2102:2103 and variable FiboRes it at address $2104:2105.

I followed your instructions to step through the XGATE code and watched the RAM memory. Then it dawned on me that I didn't fully understand how this code is supposed to work. I assumed that XGATE was used to update Counter, but that doesn't appear to be the case. All it does is increment XGATE_Counter, which has nothing to do with calculating the Fibonacci number.

Assuming this is correct, it has been quite a learning experience, but I'm still stumped on how I can use XGATE.

I would like to start by using it in a short routine using RTI to establish some time rates and set some flags so the program can use them in the main loop for different routines. Is there some example code available that might help me get closer to this goal?

Thanks,

Regards,

Robert

0 件の賞賛
返信
2,146件の閲覧回数
roberthiebert
Senior Contributor I

Thanks Ladislav. I'll see if I can find my answer there.

Regards,

Robert

0 件の賞賛
返信