<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:clearspace="http://www.jivesoftware.com/xmlns/clearspace/rss" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>RenesasRulz Home: Message List - Variables getting mixed up.</title>
    <link>http://www.renesasrulz.com/community/forum/r8c-tiny?view=discussions</link>
    <description>Most recent forum messages</description>
    <language>en</language>
    <pubDate>Wed, 03 Mar 2010 16:32:32 GMT</pubDate>
    <generator>Jive SBS 3.0.7 (http://jivesoftware.com/products/clearspace/)</generator>
    <dc:date>2010-03-03T16:32:32Z</dc:date>
    <dc:language>en</dc:language>
    <item>
      <title>Re: Variables getting mixed up.</title>
      <link>http://www.renesasrulz.com/message/8250?tstart=0#8250</link>
      <description>&lt;!-- [DocumentBodyStart:ace8945c-5779-4e05-a940-15b573a4393a] --&gt;&lt;div class='jive-rendered-content'&gt;&lt;p&gt;Thank you for the replies.&amp;#160; Does this explain why my "address" variable is getting overwritten?&amp;#160; In this case PARAMETER_BLOCK_SIZE = 10 and system_parameters is based on a struct with 9 elements. FrankL's suggestion was correct in regards to the loop execution and it also corrects the address overwrite problem.&amp;#160; Setting compiler optimization to 03 fixed my issue but FrankL's suggestion fixes the issue as well.&amp;#160; Thanks again.&lt;/p&gt;&lt;/div&gt;&lt;!-- [DocumentBodyEnd:ace8945c-5779-4e05-a940-15b573a4393a] --&gt;</description>
      <pubDate>Wed, 03 Mar 2010 16:32:32 GMT</pubDate>
      <author>renesas@renesas.hosted.jivesoftware.com</author>
      <guid>http://www.renesasrulz.com/message/8250?tstart=0#8250</guid>
      <dc:date>2010-03-03T16:32:32Z</dc:date>
      <clearspace:dateToText>6 months, 1 week ago</clearspace:dateToText>
      <clearspace:objectType>0</clearspace:objectType>
    </item>
    <item>
      <title>Re: Variables getting mixed up.</title>
      <link>http://www.renesasrulz.com/message/8200?tstart=0#8200</link>
      <description>&lt;!-- [DocumentBodyStart:73182c77-4c40-4566-86ae-325b5e959c59] --&gt;&lt;div class='jive-rendered-content'&gt;&lt;p&gt;Quite simple, you overwrite i with an array access.&lt;/p&gt;&lt;p&gt;An array goes from array[0] to array[SIZE-1].&lt;/p&gt;&lt;p&gt;In your loop you count i up to [SIZE-1]. And then you write to i+1, which is array[SIZE]. This is one element beyond the array boundary and overwrites i.&lt;/p&gt;&lt;/div&gt;&lt;!-- [DocumentBodyEnd:73182c77-4c40-4566-86ae-325b5e959c59] --&gt;</description>
      <pubDate>Wed, 03 Mar 2010 08:03:32 GMT</pubDate>
      <author>renesas@renesas.hosted.jivesoftware.com</author>
      <guid>http://www.renesasrulz.com/message/8200?tstart=0#8200</guid>
      <dc:date>2010-03-03T08:03:32Z</dc:date>
      <clearspace:dateToText>6 months, 1 week ago</clearspace:dateToText>
      <clearspace:replyCount>1</clearspace:replyCount>
      <clearspace:objectType>0</clearspace:objectType>
    </item>
    <item>
      <title>Re: Variables getting mixed up.</title>
      <link>http://www.renesasrulz.com/message/8234?tstart=0#8234</link>
      <description>&lt;!-- [DocumentBodyStart:ea191eb0-1065-4f39-8dd1-7b8392d08f85] --&gt;&lt;div class='jive-rendered-content'&gt;&lt;p&gt;What is the value for PARAMETER_BLOCK_SIZE and what type/size of structure is "system_parameters.data_byte[i]"&lt;/p&gt;&lt;p style="min-height: 8pt; height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I think what happens is that you write past the data_buffer memory and overwrite i.&lt;/p&gt;&lt;p style="min-height: 8pt; height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;If you shift the definition of i and data_buffer and initialize i to 0 you might not see the problem... in that case you still will have a problem (and will need to fix it) with writing past the data_buffer variable but you wont have the infinite loop and you will know how to fix the problem.&lt;/p&gt;&lt;/div&gt;&lt;!-- [DocumentBodyEnd:ea191eb0-1065-4f39-8dd1-7b8392d08f85] --&gt;</description>
      <pubDate>Wed, 03 Mar 2010 05:32:49 GMT</pubDate>
      <author>renesas@renesas.hosted.jivesoftware.com</author>
      <guid>http://www.renesasrulz.com/message/8234?tstart=0#8234</guid>
      <dc:date>2010-03-03T05:32:49Z</dc:date>
      <clearspace:dateToText>6 months, 1 week ago</clearspace:dateToText>
      <clearspace:objectType>0</clearspace:objectType>
    </item>
    <item>
      <title>Variables getting mixed up.</title>
      <link>http://www.renesasrulz.com/message/8198?tstart=0#8198</link>
      <description>&lt;!-- [DocumentBodyStart:6f2d1525-14c7-4bef-b9a1-a08dca402e41] --&gt;&lt;div class='jive-rendered-content'&gt;&lt;p&gt;I have a function that writes a block of data flash based on an indexing scheme.&amp;#160; I am testing using the emulator and I have had an issue with the address variable taking on the value of a generic counter variable.&amp;#160; This causes the FlashWrite operation to point at the wrong location.&amp;#160; I looked at the register window and I see that A0 holds the address value just before entering the for loop below.&amp;#160; When i is incremented the A0 value (and thereby the address) is cleared and takes on the value of i ( which is in R0).&amp;#160; If I step iterate the loop I see both A0 and R0 increment together with the same value and when i reaches the comparison value it gets cleared and goes back into the loop (not intended).&amp;#160; The emulator never exits the loop.&amp;#160; What is going on here?&lt;/p&gt;&lt;p style="min-height: 8pt; height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;p&gt;unsigned char epp_write_parameters (void)&lt;/p&gt;&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; unsigned char status = 9;&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; unsigned short block_addr;&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; unsigned char block_index;&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; unsigned short address = 0;&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; unsigned char data_buffer[PARAMETER_BLOCK_SIZE];&lt;span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; unsigned char i = 0;&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; unsigned char temp_data = 0;&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; unsigned char *p_data = &amp;amp;temp_data;&lt;/p&gt;&lt;p style="min-height: 8pt; height: 8pt; padding: 0px;"&gt;&lt;span&gt; &lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt;&lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //Find the previously written block.&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; block_addr = epp_get_address(PARAMETERS);&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; block_index&lt;span&gt; &lt;/span&gt;= *(unsigned char*)block_addr;&lt;/p&gt;&lt;p style="min-height: 8pt; height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="min-height: 8pt; height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //Load data portion of the buffer with the parameter data.&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; for(i = 0; i &amp;lt;= (PARAMETER_BLOCK_SIZE - 1); i++)&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; data_buffer[i + 1] = system_parameters.data_byte[i];&lt;span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt; &lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;&lt;/p&gt;&lt;p style="min-height: 8pt; height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;..... (extra lines left out)&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p style="min-height: 8pt; height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Thanks.&lt;/p&gt;&lt;/div&gt;&lt;!-- [DocumentBodyEnd:6f2d1525-14c7-4bef-b9a1-a08dca402e41] --&gt;</description>
      <pubDate>Wed, 03 Mar 2010 01:22:04 GMT</pubDate>
      <author>renesas@renesas.hosted.jivesoftware.com</author>
      <guid>http://www.renesasrulz.com/message/8198?tstart=0#8198</guid>
      <dc:date>2010-03-03T01:22:04Z</dc:date>
      <clearspace:dateToText>6 months, 1 week ago</clearspace:dateToText>
      <clearspace:replyCount>3</clearspace:replyCount>
      <clearspace:objectType>0</clearspace:objectType>
    </item>
  </channel>
</rss>

