<?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>topic Re: My first scheduler..... ugggh in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/My-first-scheduler-ugggh/m-p/174521#M6056</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks kef. &amp;nbsp;I updated the tasks to run forever with for(;&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I still get a Trigger A occured in the command window of the debugger. Any ideas?&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 16 Oct 2011 08:06:12 GMT</pubDate>
    <dc:creator>techsound</dc:creator>
    <dc:date>2011-10-16T08:06:12Z</dc:date>
    <item>
      <title>My first scheduler..... ugggh</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/My-first-scheduler-ugggh/m-p/174519#M6054</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey all.&amp;nbsp; I've been a casual programmer for a couple of years and have done alright but I'm taking a class on embedded microprocessors and we're learning about real time systems. We're learning about schedulers and it is so confusing. If you all know of a couple of good tutorials please let me know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to write a scheduler which will set up two threads. Each thread will require 500 ms to complete. My code will compile but I get an illegal breakpoint or Trigger A occured error message.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#include &amp;lt;hidef.h&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* common defines and macros */&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;#include &amp;lt;MC9S12C128.h&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* derivative information */&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;#pragma LINK_INFO DERIVATIVE "mc9s12c128"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;void Task1(void){&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; //DO SOMETHING&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;void Task2(void){&amp;nbsp; //non real time&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; //DO SOMETHING&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;struct TCB{&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; unsigned char *StackPt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Stack Pointer&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; unsigned char MoreStack[91];//100 bytes if stack&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; unsigned char InitialReg[7];//initial CCR,B,A,X,Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; void (*InitialPC)(void);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;};&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;typedef struct TCB TCBType;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;TCBType *RunPt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#define TheTask1 &amp;amp;sys[0] //real time&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;#define TheTask2 &amp;amp;sys[1] //non real time&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;TCBType sys[2]={&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;{ TheTask1.InitialReg[0],{ 0},{0x40,0,0,0,0,0,0},Task1},&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;{ TheTask2.InitialReg[0],{ 0},{0x40,0,0,0,0,0,0},Task2}&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;};&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;struct Node{&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; struct Node *Next;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; TCBType *ThreadPt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; unsigned short TimeSlice;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;};&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;typedef struct Node NodeType;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NodeType *NodePt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;NodeType Schedule[2]={&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;{ &amp;amp;Schedule[1], TheTask1, 500},&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;{ &amp;amp;Schedule[0], TheTask2, 500}&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;};&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;void OS_Sleep(void){ //all this does is run non real time task&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;asm swi&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;interrupt 4 void swiISR(void){&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; asm ldx RunPt&amp;nbsp;&amp;nbsp; //cooperative multitasking&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; asm sts 0,X&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //thread goes to sleep when it's done&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; RunPt = TheTask2;&amp;nbsp; //none real time thread&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; asm ldx RunPt&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; asm lds 0,x&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;interrupt 11 void threadSwitchISR(void){&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;asm ldx RunPt&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;asm sts 0,x&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;NodePt = NodePt-&amp;gt;Next;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;RunPt = NodePt-&amp;gt;ThreadPt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;TC3 = TC3+NodePt-&amp;gt;TimeSlice;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;TFLG1 = 0x08;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;asm ldx RunPt&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;asm lds 0,x&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;void main(void) {&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NodePt = &amp;amp;Schedule[0];&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;RunPt = NodePt-&amp;gt;ThreadPt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;TIOS |= 0x08;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;TSCR1 = 0x80;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;TSCR2 = 0x02;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;TIE |= 0x08;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;TC3 = TCNT+NodePt-&amp;gt;TimeSlice;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;TFLG1 = 0x08;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;asm ldx RunPt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;asm lds 0,x;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;asm rti&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Oct 2011 03:25:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/My-first-scheduler-ugggh/m-p/174519#M6054</guid>
      <dc:creator>techsound</dc:creator>
      <dc:date>2011-10-15T03:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: My first scheduler..... ugggh</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/My-first-scheduler-ugggh/m-p/174520#M6055</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your implementation all task routines have to&amp;nbsp;never exit. You need to add for(;&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;{} loops there. Some schedulers allow tasks to end when done.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Oct 2011 19:30:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/My-first-scheduler-ugggh/m-p/174520#M6055</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2011-10-15T19:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: My first scheduler..... ugggh</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/My-first-scheduler-ugggh/m-p/174521#M6056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks kef. &amp;nbsp;I updated the tasks to run forever with for(;&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I still get a Trigger A occured in the command window of the debugger. Any ideas?&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Oct 2011 08:06:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/My-first-scheduler-ugggh/m-p/174521#M6056</guid>
      <dc:creator>techsound</dc:creator>
      <dc:date>2011-10-16T08:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: My first scheduler..... ugggh</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/My-first-scheduler-ugggh/m-p/174522#M6057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you using banked memory model? You scheduler is not compatible with this model, since task switching should include save/restore of PPAGE register, which doesn't seem to take place. But it should work even with banked model, while code is small and all tasks are placed in the same&amp;nbsp;PPAGE.&lt;/P&gt;&lt;P&gt;But if it was banked memory model, then I wonder how didn't you receive linkers fixup overflow messages, because I don't see #pragma CODE_SEG NON_BANKED around your service routines.&lt;/P&gt;&lt;P&gt;So try small memory model.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What debugger connection are you using? BDM or maybe serial monitor? If second,&amp;nbsp;and if interrupts are enabled by serial monitor already at entry to main(), then try rearranging you main() lines from&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TIE |= 0x08;&lt;BR /&gt;TC3 = TCNT+NodePt-&amp;gt;TimeSlice;&lt;BR /&gt;TFLG1 = 0x08;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TC3 = TCNT+NodePt-&amp;gt;TimeSlice;&lt;BR /&gt;TFLG1 = 0x08;&lt;BR /&gt;TIE |= 0x08;&lt;/P&gt;&lt;P&gt;And you are not using S12X, but S12C128, right? Because it is not compatible with S12X.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Oct 2011 13:25:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/My-first-scheduler-ugggh/m-p/174522#M6057</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2011-10-16T13:25:46Z</dc:date>
    </item>
  </channel>
</rss>

