<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Porting source code from C51 to ARMC</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/29996/porting-source-code-from-c51-to-armc</link><description> 
I have a program in C51 that I waned to port to ARMC specifically
the Cortex_M3 namely LPC17xx micros, however the locating of the
variables is not happening correctly, namely: 

 
In C51, the memory areas; bdata, idata, xdata, code. 

 
Attempting</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Porting source code from C51 to ARMC</title><link>https://community.arm.com/thread/136689?ContentTypeID=1</link><pubDate>Mon, 23 Jan 2012 22:49:27 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6ff82414-84a2-49cb-91a5-fbfd3f3b94a3</guid><dc:creator>Mike Kleshov</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;Regarding the Bit type of the C51, I completely agree with
&amp;quot;Per&amp;quot; that a structure of 32 bit integers is perfectly acceptable,
and in my case (porting from C51 to ARMC) functionally
identical/equivalent.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
I believe replacing &lt;b&gt;bit&lt;/b&gt; with &lt;b&gt;bool&lt;/b&gt; should be
functionally identical, and simpler, and within the realm of standard
C (C99 at least.)&lt;/p&gt;

&lt;p&gt;
As for &lt;b&gt;idata&lt;/b&gt; and &lt;b&gt;xdata&lt;/b&gt;, just drop these (as you
did.) They don&amp;#39;t make sense on an ARM, and they will do you no
good.&lt;/p&gt;

&lt;p&gt;
As for &lt;b&gt;code&lt;/b&gt;, replacing it with &lt;b&gt;const&lt;/b&gt; is correct.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Porting source code from C51 to ARMC</title><link>https://community.arm.com/thread/127340?ContentTypeID=1</link><pubDate>Mon, 23 Jan 2012 16:07:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ecced289-11b4-49a4-a680-ae6c6423e6af</guid><dc:creator>Eduardo Tavares</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thanks &amp;quot;Mike&amp;quot; and &amp;quot;Per&amp;quot; for all your suggestions and comments.
Sorry for being so brief in the original post, below I will go into a
little more detail.&lt;/p&gt;

&lt;p&gt;
Regarding the &lt;b&gt;Bit&lt;/b&gt; type of the C51, I completely agree with
&amp;quot;Per&amp;quot; that a structure of 32 bit integers is perfectly acceptable,
and in my case (porting from C51 to ARMC) functionally
identical/equivalent.&lt;/p&gt;

&lt;p&gt;
For all those coming from the same direction as I, perhaps a
little refresher is in order, namely:&lt;/p&gt;

&lt;p&gt;
In C51 bit variables are declared as such:&lt;/p&gt;

&lt;p&gt;
bit bdata Genbit0; // Bit 0&lt;br /&gt;
bit bdata Genbit1; // Bit 1&lt;/p&gt;

&lt;p&gt;
In ARMC (with bit banding), this may be done in the following
manner:&lt;/p&gt;

&lt;p&gt;
typedef struct&lt;br /&gt;
{ uint8_t Genbit0 : 1; // Bit 0 uint8_t Genbit1 : 1; // Bit 1 . . .
uint8_t Genbit31 : 1; // Bit 31&lt;br /&gt;
} GPBB&lt;/p&gt;

&lt;p&gt;
GPBB bb __attribute__((at(0x20000000))); // declare the variable
the start of the SRAM Area&lt;/p&gt;

&lt;p&gt;
In a function setting or clearing a bit is simply done in this
manner:&lt;br /&gt;
void foo (void)&lt;br /&gt;
{ bb.Genbit0 = 1; //Set the bit bb.Genbit1 = 0; //Clear the bit&lt;/p&gt;

&lt;p&gt;
}&lt;/p&gt;

&lt;p&gt;
In C51 indirectly addressed and External RAM variables are
declared as such:&lt;/p&gt;

&lt;pre&gt;
 char idata byte_var1;   // var 1
char idata byte_Var2;   // var 2

int xdata word_1;   // integer 1
int xdata word_2;   // integer 2
&lt;/pre&gt;

&lt;p&gt;
In ARMC this is done in the following manner:&lt;/p&gt;

&lt;pre&gt;
 static int8_t byte_var1;   // byte_var1
static int8_t byte_var2;   // byte_var2

static int16_t word_1;   // integer 1
static int16_t word_2;   // integer 2
&lt;/pre&gt;

&lt;p&gt;
However here (in ARMC) you have no direct control of memory area,
all variables go into RAM.&lt;/p&gt;

&lt;p&gt;
Finally in C51 declaring and locating variables is code is done in
this manner:&lt;/p&gt;

&lt;pre&gt;
 char code VersionInfo[] = &amp;quot;VERSION: 1.0.0&amp;quot;;
&lt;/pre&gt;

&lt;p&gt;
Attempting to declare and locate in ARMC in this manner:&lt;/p&gt;

&lt;pre&gt;
 const uint8_t VersionInfo[] = &amp;quot;VERSION: 1.0.0&amp;quot;;
&lt;/pre&gt;

&lt;p&gt;
Looking at the MAP file I find the following to support my
conclusions:&lt;/p&gt;

&lt;pre&gt;
      .
      .
    sqrt                        0x0000e989   Thumb Code    76  sqrt.o(i.sqrt)
    VersionInfo                 0x0000e9d4   Data          15  main.o(.constdata)
      .
      .
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
That is, I expected (and intended) that &amp;quot;VersionInfo&amp;quot; be in the Thumb
Code area (as it was in C51 code).&lt;/p&gt;

&lt;p&gt;
Any suggestions will be appreciated!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Porting source code from C51 to ARMC</title><link>https://community.arm.com/thread/119598?ContentTypeID=1</link><pubDate>Mon, 23 Jan 2012 00:40:28 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b497bc7a-3fa9-40b7-a534-c3a1ff36cf6d</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
It is, but you can still write programs that looks like you have
bit variables using the Cortex memory controller extensions. That you
have a struct of 32-bit integers representing the individual bits
doesn&amp;#39;t really matter when you can write P0.pin3 = 1 without the
compiler having to perform and/or operations hidden in the
background. Or you can declare your gpio0_pin3 if you don&amp;#39;t want to
use a struct. So in the end, you do get very close to the bit
variables of Keil C51.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Porting source code from C51 to ARMC</title><link>https://community.arm.com/thread/105653?ContentTypeID=1</link><pubDate>Sun, 22 Jan 2012 22:04:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:560d3c65-607c-4203-bb5a-8e1262f00756</guid><dc:creator>Mike Kleshov</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;But ARM did include language extensions just to &amp;quot;help
out&amp;quot;.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Yes, but the &lt;b&gt;bit&lt;/b&gt; type of the C51 is something completely
different.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Porting source code from C51 to ARMC</title><link>https://community.arm.com/thread/91396?ContentTypeID=1</link><pubDate>Sun, 22 Jan 2012 14:46:00 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4b5e74ce-a0bf-402b-8ad7-bd0b0cee9dad</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Mike - note that the Cortex do have bitbanding support - an
aliased memory region where each 32-bit integer corresponds to one
bit of a GPIO or registers. So you can write and read an integer and
actually write or read a single bit. It&amp;#39;s a feature of the memory
controller of the processor, so it can be done with zero language
extensions. But ARM did include language extensions just to &amp;quot;help
out&amp;quot;.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Porting source code from C51 to ARMC</title><link>https://community.arm.com/thread/60280?ContentTypeID=1</link><pubDate>Sun, 22 Jan 2012 12:55:51 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8b16e4b4-5220-4a74-89ef-4f6d77515cd4</guid><dc:creator>Mike Kleshov</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;In C51, the memory areas; bdata, idata, xdata, code.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
That&amp;#39;s C51-specific. How is this relevant?&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;Attempting to use &amp;quot;const&amp;quot; for lookup tables that were in ROM
does NOT place the variables in ROM (as expected) but in RAM.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
That&amp;#39;s news to me. You&amp;#39;ll have to provide a specific example.&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;For bit variables I have typedef&amp;#39;ed a structure and added the
&amp;quot;__attribute__((bitband))&amp;quot; to use bit banding (that is one
way).&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
I&amp;#39;m not sure you can establish a direct mapping this way. Bit
banding is a a related, but a different concept. Bit variables are an
extension of the language that allows to have access to bit
addressing capabilities of the 8051 CPU. It can lead to more
efficient code in some situations on a 8051. With an ARM CPU, this is
irrelevant. Besides, those extensions are not supported on ARM
compilers, so a simple __attribute__ won&amp;#39;t help, in all
likelihood.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>