| Author | beginning argument ( Replies received: 4 ) |
| diamond |
Posted 17-06-2008 at 13:22   |

Registered on : 04-23-2004
From Italy
Messages : 5
OFF-Line
|
I would like to share with you the procedure for executing code in RAM.
When you have to put one or more functions in RAM, you have to put them in a separate .c file (i.e. 'RAM_routines.c') and modify the linker file using -ic Segment Control Option.
For example, if you want to put the routines in RAM starting from the address 0x100, you have to use the following line:
# RAM routines:
+seg .text -b 0x100 -n .my_routines -ic Debug\RAM_routines.o
You are now storing the code in Flash and, before calling the routines, you have to copy it to RAM using the function
_fctcpy('m');
where m is first character of segment named my_routines.
For further information you can refer to Cosmic 'CXSTM8_UserGuide' sections
'Using The Linker'-->'Moveable Code'
Ciao
|
|
|
Profile
Quote
|
| bassinux |
Posted 18-11-2008 at 13:04   |

Registered on : 11-15-2009
Messages : 10
OFF-Line
|
Hello Diamond,
Thank you very much for this information, and I would like to ask you if there is another method to execute code from RAM without using a special functions of cosmic, so to have a portable code.
thanks
|
|
|
Profile
Quote
|
| diamond |
Posted 25-11-2008 at 00:11   |

Registered on : 04-23-2004
From Italy
Messages : 5
OFF-Line
|
There is another way, but it is not automatic and it is for sure less elegant... but if you want to be compiler indipendent is the only way I see.
You have anyway to put the code that you want in RAM in separate file and compile with the option:
# RAM routines:
+seg .text -b 0x100 -n .my_routines
In this way you have your s19 containing the routine that you want to have in RAM; see below example starting from 0x100:
...........
S12301009D81A600C65005A8F0C750054C721C505B721D505CC7F600C7F601C7F602C7F691
S10C01200355FF7C500A20DC8029
...........
Removing the motorola formats, i.e. in the first line
S - Indicates that this is Motorola
1 - 1 means this is a data record
23 - Number of bytes to follow
0100 - Starting address
you can see the bytes that have to be put in RAM.
Now you have to remove from the project the file to put in RAM, but you have to define an array containing the bytes to put in RAM
u8 RAM_array [] = {
0x9D, 0x81, 0xA6, 0x00, 0xC6, 0x50, 0x05, 0xA8, 0xF0, 0xC7, 0x50, 0x05, 0x4C, 0x72, 0x1C, 0x50,
0x5B, 0x72, 0x1D, 0x50, 0x5C, 0xC7, 0xF6, 0x00, 0xC7, 0xF6, 0x01, 0xC7, 0xF6, 0x02, 0xC7, 0xF6,
0x91, 0x03, 0x55, 0xFF, 0x7C, 0x50, 0x0A, 0x20, 0xDC, 0x80, 0x29
};
After in the main you have to insert a for loop that copy RAM_array in the location that you want.
I hope it is clear... (?)
Write me in case!
Ciao,
Olga
|
|
|
Profile
Quote
|
| bassinux |
Posted 26-11-2008 at 12:06   |

Registered on : 11-15-2009
Messages : 10
OFF-Line
|
Hi,
Thank you Diamond, I want to add that in order to call this routine from RAM, for example if the Array is copied starting from 0x100
this code must be insert :
#asm
call $100
#endasm
is it correct which I wrote
|
|
|
Profile
Quote
|
| diamond |
Posted 26-11-2008 at 15:14   |

Registered on : 04-23-2004
From Italy
Messages : 5
OFF-Line
|
Yes, correct!
Ciao
|
|
|
Profile
Quote
|
|  |
|
|