<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>S12 / MagniV Microcontrollers中的主题 Re: RingBuffer on S12X</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180573#M6541</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just found out that the programm works when I declare my structs locally inside my main()... unfortunately this is not an option for me because I have to change them inside my ISR later on &lt;SPAN class="lia-unicode-emoji" title=":confused_face:"&gt;&lt;LI-EMOJI id="lia_confused-face" title=":confused_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in NoICE I've looked a little closer on the memoryadresses and discovered that, declaring the buffer globally, it is beeing stored from 0x0000 to 0x000E. Am I wrong or is my code trying to write to the controller's registers??&lt;/P&gt;&lt;P&gt;I thought the compiler had to take care of the correct initialization of variables. Don't know if it helps, but my map-file looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
Area                               Addr   Size   Decimal Bytes (Attributes)--------------------------------   ----   ----   ------- ----- ------------                            text   4000   0155 =    341. bytes (rel,con,rom)       Addr  Global Symbol      -----  --------------------------------       4000  __start       4028  _exit       402A  _reset_buffer       402A  __text_start       404D  _increment_buffer       4069  _get_buffer       40AB  _put_buffer       410D  _isempty_buffer       4122  _main       4150  __HC12Setup       4155  __text_endArea                               Addr   Size   Decimal Bytes (Attributes)--------------------------------   ----   ----   ------- ----- ------------                             bss   0800   0012 =     18. bytes (rel,con,rom)       Addr  Global Symbol      -----  --------------------------------       0800  __bss_start       0800  _pr1000_SCI0       0802  _pr1000_buffer       0812  __bss_end&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1"&gt;sorry for the triplepost, but post editing seems to be allowed only a few minutes after sending a post.&lt;/FONT&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Oct 2020 09:30:28 GMT</pubDate>
    <dc:creator>Cow2k</dc:creator>
    <dc:date>2020-10-29T09:30:28Z</dc:date>
    <item>
      <title>RingBuffer on S12X</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180569#M6537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello everybody,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to µC programming. my first project includes working with the SCI interface. for this purpose I wanted to use a ringbuffer, to which my SCI-ISR write every received byte.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the ISR itself works fine but my ringbuffer seems to be corrupt. I've already slightly rewrote the code so I can test it on the PC where everything goes without errors.&amp;nbsp;&lt;/P&gt;&lt;P&gt;but when I execute the code on the µC (MC9S12XDT512), there are some pretty strange things going on. here is the code I wrote:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
/* Includes */
#define TRUE&amp;nbsp; 1
#define FALSE 0

/* HEADER HAPTIC */
#define BUFFERSIZE 10


struct ringBuffer
{
 unsigned int elementCount;
 unsigned int posRead; 
 unsigned int posWrite;
 unsigned char stack[BUFFERSIZE];
};


struct knobDevice
{
 struct ringBuffer *buffer;
};

struct knobDevice pr1000_SCI0;
struct ringBuffer pr1000_buffer;



/* FUNCTIONS HAPTIC */
void reset_buffer(struct ringBuffer * buffer){
buffer-&amp;gt;posRead=0;
buffer-&amp;gt;posWrite=0;
buffer-&amp;gt;elementCount=0;
}

unsigned int increment_buffer(unsigned int i)
{
 //this is used to "increment" the read&amp;amp;write position of a ringbuffer, when it touches BUFFERSIZE we reset to 0
 return (i+1)==BUFFERSIZE ? 0 : i+1;
}

unsigned char get_buffer(struct ringBuffer * buffer)
{
 //empty buffer has to be handled before function call!
 unsigned int posRead;
 posRead=buffer-&amp;gt;posRead;
 buffer-&amp;gt;posRead=increment_buffer(buffer-&amp;gt;posRead);
 buffer-&amp;gt;elementCount--;
 return buffer-&amp;gt;stack[posRead];
}

void put_buffer(struct ringBuffer * buffer, unsigned char storeThis)
{
 //when buffer is full, we overwrite it from the beginning
 buffer-&amp;gt;stack[buffer-&amp;gt;posWrite]=storeThis;
 buffer-&amp;gt;posWrite=increment_buffer(buffer-&amp;gt;posWrite);
 if(buffer-&amp;gt;elementCount&amp;lt;BUFFERSIZE)
 {
&amp;nbsp; //only increment elementcount if we didn't overwrite existing data
&amp;nbsp; buffer-&amp;gt;elementCount++;
 }else
 {
&amp;nbsp; //buffer is overwritten, increment posRead so we don't get the just inserted data when reading next time
&amp;nbsp; buffer-&amp;gt;posRead=increment_buffer(buffer-&amp;gt;posRead);
 }
}

unsigned char isempty_buffer(struct ringBuffer * buffer)
{
 if(buffer-&amp;gt;elementCount&amp;gt;0)
 {

&amp;nbsp; return FALSE;
 }else{
 return TRUE;
}
}






void main(void){
unsigned char i;

 pr1000_SCI0.buffer= &amp;amp;pr1000_buffer;
 reset_buffer(pr1000_SCI0.buffer);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(1){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(i=0;i&amp;lt;5;i++){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put_buffer(pr1000_SCI0.buffer, i);}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I use ICC for compiling and NoICE for debugging.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when I run the code and watch the buffer, right after doing the "reset_buffer", the buffer.elementCount=0xFF00 and the buffer's stack is 00,00,00,1F,00,00,00,D0,00,3F&lt;/P&gt;&lt;P&gt;&amp;nbsp;also I am only able to modify a few of my buffer variables from within NoICE...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what am I doing wrong? I guess there are some memory issues so my variables are stored in a wrong area or something. unfortunately I have no idea how to verify my guess.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd really appreciate some hints here &lt;A href="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank"&gt;&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;&lt;P&gt;markus&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:30:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180569#M6537</guid>
      <dc:creator>Cow2k</dc:creator>
      <dc:date>2020-10-29T09:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: RingBuffer on S12X</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180570#M6538</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Where are the volatile variables and the ISR itself? Where are the semaphores protecting the ring buffer from getting corrupted when the ISR access it at the same time as the main() program?&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 May 2009 20:47:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180570#M6538</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2009-05-12T20:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: RingBuffer on S12X</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180571#M6539</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;well, in this version I do not make use of the IRS as I wanted to make sure the buffer itself is working,&lt;/P&gt;&lt;P&gt;which it doesn't &lt;IMG alt=":smileysad:" class="emoticon emoticon-smileysad" id="smileysad" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-sad.gif" title="Smiley Sad" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 May 2009 13:36:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180571#M6539</guid>
      <dc:creator>Cow2k</dc:creator>
      <dc:date>2009-05-13T13:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: RingBuffer on S12X</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180572#M6540</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;I've attached a picture of what my buffer variables look like right after calling the reset_buffer() function.&amp;nbsp; As you can see, the "elementCount" can not be set to zero... My guess is, that this is out of the same reason for which the storing of new elements in the buffer doesn't work properly. What's also to be seen in the screenshot, is that particular parts of the stack are initially not zero but some other values (always the same...)&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by Cow2k on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-05-13&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;08:13 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 May 2009 14:10:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180572#M6540</guid>
      <dc:creator>Cow2k</dc:creator>
      <dc:date>2009-05-13T14:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: RingBuffer on S12X</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180573#M6541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just found out that the programm works when I declare my structs locally inside my main()... unfortunately this is not an option for me because I have to change them inside my ISR later on &lt;SPAN class="lia-unicode-emoji" title=":confused_face:"&gt;&lt;LI-EMOJI id="lia_confused-face" title=":confused_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in NoICE I've looked a little closer on the memoryadresses and discovered that, declaring the buffer globally, it is beeing stored from 0x0000 to 0x000E. Am I wrong or is my code trying to write to the controller's registers??&lt;/P&gt;&lt;P&gt;I thought the compiler had to take care of the correct initialization of variables. Don't know if it helps, but my map-file looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
Area                               Addr   Size   Decimal Bytes (Attributes)--------------------------------   ----   ----   ------- ----- ------------                            text   4000   0155 =    341. bytes (rel,con,rom)       Addr  Global Symbol      -----  --------------------------------       4000  __start       4028  _exit       402A  _reset_buffer       402A  __text_start       404D  _increment_buffer       4069  _get_buffer       40AB  _put_buffer       410D  _isempty_buffer       4122  _main       4150  __HC12Setup       4155  __text_endArea                               Addr   Size   Decimal Bytes (Attributes)--------------------------------   ----   ----   ------- ----- ------------                             bss   0800   0012 =     18. bytes (rel,con,rom)       Addr  Global Symbol      -----  --------------------------------       0800  __bss_start       0800  _pr1000_SCI0       0802  _pr1000_buffer       0812  __bss_end&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1"&gt;sorry for the triplepost, but post editing seems to be allowed only a few minutes after sending a post.&lt;/FONT&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:30:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180573#M6541</guid>
      <dc:creator>Cow2k</dc:creator>
      <dc:date>2020-10-29T09:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: RingBuffer on S12X</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180574#M6542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks like you put your&amp;nbsp;variables to EEPROM. In project settings please verify that you don't mix&lt;/P&gt;&lt;P&gt;MC9S12D512 device with MC9S12XD512. These have different memory maps. If your ICC version doesn't have XD512 in device list, then you should use Custom target and set data memory to 0x1000, stack pointer to 0x4000. If you are using Expanded Memory, then also please verify that it is set to 0x380000.0x3FFFFF. Also using NoICe, please don't mix D512 with XD512.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 May 2009 20:24:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180574#M6542</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2009-05-13T20:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: RingBuffer on S12X</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180575#M6543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks alot!&lt;/P&gt;&lt;P&gt;I've simply selected the only available S12X in my compiler, which is a S12XD&lt;SPAN&gt;&lt;STRONG&gt;P&lt;/STRONG&gt;&lt;/SPAN&gt; but I use a S12XD&lt;SPAN&gt;T&lt;/SPAN&gt;. By following your advise with the custom target I've got everything working now &lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 May 2009 21:52:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/RingBuffer-on-S12X/m-p/180575#M6543</guid>
      <dc:creator>Cow2k</dc:creator>
      <dc:date>2009-05-13T21:52:02Z</dc:date>
    </item>
  </channel>
</rss>

