<?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>LPC2368 UART register sizes in lpc23xx.h file?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/24053/lpc2368-uart-register-sizes-in-lpc23xx-h-file</link><description> 
I have a question about the lpc23xx.h file version 1.04 

 
I was wondering why some of the UART registers were defined as
unsigned long, when they appear to only be 8 bits (unsigned
char)? 
For example, the RBR, THR, DLL, DLM, FCR, LCR, LSR, SCR and</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: LPC2368 UART register sizes in lpc23xx.h file?</title><link>https://community.arm.com/thread/135436?ContentTypeID=1</link><pubDate>Wed, 02 Jul 2008 23:46:04 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:20728568-8065-4e1d-9041-7032ea67f23d</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
It is quite common that the developer selects the int or unsigned
int data types. So it isn&amp;#39;t an unreasonable assumption that the SFR
can be accessed with 32-bit accesses. The chip designer have designed
the chip to allow such accesses.&lt;/p&gt;

&lt;p&gt;
Anyway: The most general solution is to define two sets of
definitions to access these registers, just as the GPIO ports has
8-bit, 16-bit and 32-bit access methods.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LPC2368 UART register sizes in lpc23xx.h file?</title><link>https://community.arm.com/thread/124776?ContentTypeID=1</link><pubDate>Wed, 02 Jul 2008 23:01:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ad7a4407-4c6f-4a54-937b-ac4e0d823c28</guid><dc:creator>Robert &amp;#160;</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;I think you might be confused...&lt;/i&gt;&lt;br /&gt;
Not really, I have just overlooked that in the second case unsigned
char was used.&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;If I left the REC_DATA(U0RBR) definition as unsigned long and
used a variable that was an unsigned long, i would be back down to
one (LDR - load 32 bit word from memory) instruction, but this would
be less efficient memory wise (just wasted 3 bytes).&lt;/i&gt;&lt;br /&gt;
Not always true regarding memory usage. When variables are local they
are located in registers (or stack) and since they are 32-bit anyway
there is no real wasted memory.&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;So, back to my original question, why keep the 8 bit UART
registers defined as unsigned long?&lt;/i&gt;&lt;br /&gt;
Since 32-bit is native size it should generate more efficient code
but as you have tried out this is not always the case. So using 8-bit
definitions might be better.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LPC2368 UART register sizes in lpc23xx.h file?</title><link>https://community.arm.com/thread/114084?ContentTypeID=1</link><pubDate>Wed, 02 Jul 2008 08:05:18 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:dea85495-e553-4dea-9dbf-872a77b26c0d</guid><dc:creator>Ken VanDeWater</dc:creator><description>&lt;p&gt;&lt;p&gt;
I think you might be confused...&lt;br /&gt;
In the first case (when REC_DATA is unsigned long) the compiler
generates two instructions whether or not I use the cast (the cast is
assumed by the compiler since I&amp;#39;m loading an unsigned long into an
unsigned char variable).&lt;br /&gt;
In the second case, I changed the definition of REC_DATA(U0RBR) from
unsigned long to unsigned char which matches the variable I was
using. This allowed the compiler to only use one (LDRB- load register
byte value) instruction which is obviously more efficient (speed
wise).&lt;br /&gt;
If I left the REC_DATA(U0RBR) definition as unsigned long and used a
variable that was an unsigned long, i would be back down to one (LDR
- load 32 bit word from memory) instruction, but this would be less
efficient memory wise (just wasted 3 bytes).&lt;br /&gt;
So, back to my original question, why keep the 8 bit UART registers
defined as unsigned long?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LPC2368 UART register sizes in lpc23xx.h file?</title><link>https://community.arm.com/thread/102906?ContentTypeID=1</link><pubDate>Wed, 02 Jul 2008 07:34:52 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:95cd1b5b-fc0d-46bb-bb68-15dcb05d614e</guid><dc:creator>Robert &amp;#160;</dc:creator><description>&lt;p&gt;&lt;p&gt;
The second case generates only one instruction (no cast is
required) and this is the best way to use it (when REC_DATA is
unsigned long).&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LPC2368 UART register sizes in lpc23xx.h file?</title><link>https://community.arm.com/thread/76446?ContentTypeID=1</link><pubDate>Wed, 02 Jul 2008 06:14:35 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3fb70912-3193-4b71-9d0f-5ed5a5e7ad24</guid><dc:creator>Ken VanDeWater</dc:creator><description>&lt;p&gt;&lt;p&gt;
That&amp;#39;s what I thought at first, but I&amp;#39;m not so sure...&lt;br /&gt;
For example:&lt;/p&gt;

&lt;p&gt;
recData is unsigned char, REC_DATA (U0RBR) is unsigned
long&lt;/p&gt;

&lt;pre&gt;
  305:         recData = (unsigned char)REC_DATA;
0x00000500  E5900000  LDR       R0,[R0]
0x00000504  E20060FF  AND       R6,R0,#0x000000FF
&lt;/pre&gt;

&lt;p&gt;
recData is unsigned char, REC_DATA (U0RBR) is unsigned
char&lt;/p&gt;

&lt;pre&gt;
   305:         recData = REC_DATA;
0x00000500  E5D06000  LDRB      R6,[R0]
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LPC2368 UART register sizes in lpc23xx.h file?</title><link>https://community.arm.com/thread/51928?ContentTypeID=1</link><pubDate>Tue, 01 Jul 2008 22:22:04 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ca4579c8-db6b-4122-b3b5-98016260fdcc</guid><dc:creator>Robert &amp;#160;</dc:creator><description>&lt;p&gt;&lt;p&gt;
It&amp;#39;s not a typo.&lt;/p&gt;

&lt;p&gt;
LPC23xx is an 32-bit ARM device and using 32-bit registers
generates the best code. This is the reason why UART registers are
defined as unsigned long.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>