EmbeddedRelated.com
Forums

XGate thread using SCI running under simulator, not on the target

Started by jpdi March 4, 2008
Hello,

I'm trying to do some thread for XGate.

The first thread I wrote, using RTI, is now OK, so I can see it running
under simulator AND on my target processor.

The second, using SCI1,

- runs under simulator : I can see interrupt, immediately when I put a
character in SCI1DRL then generate xmit interrupt, and XGate thread executed

- but not on the target : thread never executed

Before trying with XGate, I used S12 interrupts, and my soft was OK.

Now, because of these difficulties to startup XGate, I dramatically simplify
the program :

Into main function :

void main (void)

{ unsigned char c;

// some initialisations, used in an other program

c = 'A';

for (;;)

{ SCI1DRL = c; // send char

SCI1CR2 |= 0x88; // enable SCI xmit and interrupts

c++;

}

}

Now, the thread SCI1, with the pointer to the original datas (not use now)

interrupt void XGATE_SCI1_thread (TSci1Datas *ptr)

{ unsigned char status, tempo;

status = SCI1SR1; // read SCI1 status

tempo = SCI1BDL; // dummy read (usefull ?)

if (status & 0x80) // if xmit buffer empty

{ SCI1CR2 &= 0x3f; // inhibe xmit interrupts

}

}

Anybody can help me ?

Thanks !

Best regards.

Joel
Joel,

I don't know why code working in simulator doesn't work in target, but you
oversimplified your minimal program. XGATE setup is missing, interrupt
controller setup is missing, XGATE interrupt vector table is missing.

BTW XGATE V2 threads are uninterruptable. No new XGATE thread can be started
until XGATE becomes idle. Make sure you exit from your other threads and
clear corresponding interrupt flags or interrupt masks. For example if you
have just RTI thread, then verify that it doesn't loop forever, else your
SCI thread won't ever start.

Edward

----- Original Message -----
From: "jpdi"
To: <6...>
Sent: Tuesday, March 04, 2008 9:39 PM
Subject: [68HC12] XGate thread using SCI running under simulator, not on the
target
> Hello,
>
> I'm trying to do some thread for XGate.
>
> The first thread I wrote, using RTI, is now OK, so I can see it running
> under simulator AND on my target processor.
>
> The second, using SCI1,
>
> - runs under simulator : I can see interrupt, immediately when I put a
> character in SCI1DRL then generate xmit interrupt, and XGate thread
> executed
>
> - but not on the target : thread never executed
>
> Before trying with XGate, I used S12 interrupts, and my soft was OK.
>
> Now, because of these difficulties to startup XGate, I dramatically
> simplify
> the program :
>
> Into main function :
>
> void main (void)
>
> { unsigned char c;
>
> // some initialisations, used in an other program
>
> c = 'A';
>
> for (;;)
>
> { SCI1DRL = c; // send char
>
> SCI1CR2 |= 0x88; // enable SCI xmit and interrupts
>
> c++;
>
> }
>
> }
>
> Now, the thread SCI1, with the pointer to the original datas (not use now)
>
> interrupt void XGATE_SCI1_thread (TSci1Datas *ptr)
>
> { unsigned char status, tempo;
>
> status = SCI1SR1; // read SCI1 status
>
> tempo = SCI1BDL; // dummy read (usefull ?)
>
> if (status & 0x80) // if xmit buffer empty
>
> { SCI1CR2 &= 0x3f; // inhibe xmit interrupts
>
> }
>
> }
>
> Anybody can help me ?
>
> Thanks !
>
> Best regards.
>
> Joel
>
>
>
Sure, Edward, I oversimplified !!! In order to avoid too big mail on the
mailing list.



For the moment, under CodeWarrior, after running successful XGate with RTI,
I cancelled RTI thread, replacing it with SCI thread... So, I think
SetupXGATE is ok ?

Below the code I use, less simplified !

For the moment, I dont understand why program run under CodeWarriors
Simulator and not on the target

I analysed macro ROUTE_INTERRUPT



With all my thanks.



Joel





//*******************************************************************

// Define size of xmit and receive buffers

#define SCI1_TAILLE_BUFFER_EMISSION 256

#define SCI1_TAILLE_BUFFER_RECEPTION 256



typedef struct TSci1_Emission // offset for access to the
structures member

{ Byte *wr, *rd; // 0, 2 write and read pointers

Word dispo; // 4 nbre of bytes available
in the buffer

} TSci1_Emission;





typedef struct TSci1_Reception

{ Byte *wr, *rd; // 6, 8 write and read pointers

Word nb_octets; // 10 nbre of bytes received
in the buffer

Byte ovf; // 12 overflow

Byte pour_parite; // 13 for parity of the
structure's size

} TSci1_Reception;





typedef struct TSci1Datas // structure organized to facilitate later
assembly

{ TSci1_Emission emission;

TSci1_Reception reception;

Byte xmit_buffer[SCI1_TAILLE_BUFFER_EMISSION];

Byte rec_buffer[SCI1_TAILLE_BUFFER_RECEPTION];

} TSci1Datas;





//*******************************************************************

// In main file

#define ROUTE_INTERRUPT(vec_adr,cfdata) \

INT_CFADDR = (vec_adr) & 0xF0; \

INT_CFDATA_ARR[((vec_adr) & 0x0F) >> 1]= (cfdata)





#define S12_SCI1_VECTOR 0xD4 // S12 vector for SCI1 :
0xffd4



void main(void)

{ int perdu, cptr;

char s[40];



SCI1_Init (38400, 6);

DDRA = 0xff; // port A en sortie

PORTA = 0x80; // valide sortie RS-485

SetupXGATE();

cptr = 0;

for (;;)

{ cptr++;

perdu = sprintf (s, "%6d", cptr);

SCI1_puts (s);

// Some delay of about 1 sec, using simply loop

}

}



void SetupXGATE (void)

{ // Init XGATE vector block and set the XGVBR register to start address

XGVBR= (unsigned int)(void*__far)(XGATE_VectorTable -
XGATE_VECTOR_OFFSET);



// Dourne interruptions pour XGATE

ROUTE_INTERRUPT (S12_SCI1_VECTOR, 0x81);



// Valide XGATE mode et interruptions

XGMCTL= 0x8181;

}



void SCI1_Init (Word baud, Byte sysclk)

{ // / // calculation for Baudrate

// Some inits

SCI1CR1 = 0x00;

SCI1SR2 = 0x80; // alternative register set

SCI1ASR1 = 0x83; // clear alternative status

SCI1ACR1 = 0x00; // disable interrupts on active
edge, bit error, break

SCI1ACR2 = 0x00; //

SCI1SR2 = 0x00; // normal register set

(void) SCI1SR1; // reset interrupt request flags



SCI1CR2 = 0x00;

SCI1BDH = diviseur.c[0]; // baudrate

SCI1BDL = diviseur.c[1];



SCI1CR2 = 0x2c; // TE | RE | RIE ==> enable
xmit/receive, interrupt on receive only

}





//*******************************************************************

// In XGate file

// SCI1 management with XGate

interrupt void XGATE_SCI1_thread (TSci1Datas *ptr)

{ Byte status;

status = SCI1SR1; // read status...

if (status & 0x0f) // errors ?

{ // /

}



// Interrupt on xmit empty

if (status & 0x80) // TDRE : 0x80 ;
Transmit Data Register Empty

{ if (ptr->emission.rd != ptr->emission.wr)

{ SCI1DRL = *ptr->emission.rd; // send current char

ptr->emission.rd++; // prepare next char

if (ptr->emission.rd >= &ptr->xmit_buffer[SCI1_TAILLE_BUFFER_EMISSION])

ptr->emission.rd = &ptr->xmit_buffer[0];

}

else // nothing to xmit

{ SCI1CR2 &= 0x3f; // stop interrupt

}

}



// Interrupt on receive full

if (status & 0x20) // RDRF 0x20 :
Receive data register full

{ // /

}

}



interrupt void XGATE_ErrorHandler_thread (int dataptr)

{ dataptr++; // in order to avoid warning by compiler

asm BRK;

}



// A part of Threads Table, only SCI1 thread is set

#pragma CONST_SEG XGATE_VECTORS

const XGATE_TableEntry XGATE_VectorTable[] = {

// Channel # = Vector address / 2

// channel 0..8 are not used, first used must match macro
XGATE_VECTOR_OFFSET in xgate.h

{XGATE_ErrorHandler_thread, 0x09}, // Channel 09 -
Reserved

// /

{XGATE_ErrorHandler_thread, 0x69}, // Channel 69 -
ATD0



//{XGATE_ErrorHandler_thread, 0x6A}, // Channel 6A -
SCI1

{(XGATE_PtrFunction) XGATE_SCI1_thread, (int)&_sci1_datas}, // Channel
6A - SCI1

{XGATE_ErrorHandler_thread, 0x6B}, // Channel 6B -
SCI0



// /

{XGATE_ErrorHandler_thread, 0x78}, // Channel 78 -
Real Time Interrupt

{XGATE_ErrorHandler_thread, 0x79}, // Channel 79 - IRQ

};







> -----Message d'origine-----

> De : 6... [mailto:6...] De la part de

> Edward Karpicz

> Envoy: mercredi 5 mars 2008 07:52

> : 6...

> Objet : Re: [68HC12] XGate thread using SCI running under simulator, not

> on the target

>

> Joel,

>

> I don't know why code working in simulator doesn't work in target, but you

> oversimplified your minimal program. XGATE setup is missing, interrupt

> controller setup is missing, XGATE interrupt vector table is missing.

>

> BTW XGATE V2 threads are uninterruptable. No new XGATE thread can be

> started

> until XGATE becomes idle. Make sure you exit from your other threads and

> clear corresponding interrupt flags or interrupt masks. For example if you

> have just RTI thread, then verify that it doesn't loop forever, else your

> SCI thread won't ever start.

>

> Edward

>







Joel,

Maybe it's another simplification, but in your SCI init routine you are
enabling RIE interrupt and in your SCI handler I see only transmitters code.
RDRF flag isn't handled, it's read but isn't cleared by reading SCI1DRL.
Anyway I just tried it as is, except that I enabled TDRE interrupt. XGATE
SCI1 ISR got triggered. So problem must be somewhere else.

Also

1) You init SCI1 first and enable RIE interrupt, then you route interrupts
to XGATE. SCI char shouldn't arrive in the time between when you enable RIE
and when you route SCI1 interrupts to XGATE. But I wonder what would happen
if RIE would get pending at this time? I'm not sure if it is OK to switch
routing of specific interrupt while it is pending and unmasked. I'd better
swap in main() SetupXGATE() and SCI1Init(), so that routing is done before
interrupt is enabled.

2) XGMCTL= 0x8181; //You enable XGATE interrupt here (XGIE). It sounds
confusing, but it's a S12X interrupt :-). Imagine for a moment that XGATE
can't run any code and it's something simple like key wakeup pin peripheral
module. It has its own interrupt XGIE and you handle this interrupt using
S12X.
In fact XGATE has a lot of XGIF flags. There's a special XGATE instruction
SIF, that is used to set XGIF flags. XGATE code executes SIF (set interrupt
flags), XGIF flag gets set and XGIE interrupt becoms pending. So do you have
S12X handler for this interrupt? If not then you shouldn't set XGIE, I
guess.
Regards,

Edward

----- Original Message -----
From: "jpdi"
To: <6...>
Sent: Wednesday, March 05, 2008 3:36 PM
Subject: RE: [68HC12] XGate thread using SCI running under simulator, not on
the target
> Sure, Edward, I oversimplified !!! In order to avoid too big mail on the
> mailing list.
>
> For the moment, under CodeWarrior, after running successful XGate with
> RTI,
> I cancelled RTI thread, replacing it with SCI thread... So, I think
> SetupXGATE is ok ?
>
> Below the code I use, less simplified !
>
> For the moment, I don't understand why program run under CodeWarrior's
> Simulator and not on the target.
>
> I analysed macro ROUTE_INTERRUPT.
>
> With all my thanks.
>
> Joel
>
> //*******************************************************************
>
> // Define size of xmit and receive buffers
>
> #define SCI1_TAILLE_BUFFER_EMISSION 256
>
> #define SCI1_TAILLE_BUFFER_RECEPTION 256
>
> typedef struct TSci1_Emission // offset for access to the
> structure's member
>
> { Byte *wr, *rd; // 0, 2 write and read pointers
>
> Word dispo; // 4 nbre of bytes available
> in the buffer
>
> } TSci1_Emission;
>
> typedef struct TSci1_Reception
>
> { Byte *wr, *rd; // 6, 8 write and read pointers
>
> Word nb_octets; // 10 nbre of bytes received
> in the buffer
>
> Byte ovf; // 12 overflow
>
> Byte pour_parite; // 13 for parity of the
> structure's size
>
> } TSci1_Reception;
>
> typedef struct TSci1Datas // structure organized to facilitate later
> assembly
>
> { TSci1_Emission emission;
>
> TSci1_Reception reception;
>
> Byte xmit_buffer[SCI1_TAILLE_BUFFER_EMISSION];
>
> Byte rec_buffer[SCI1_TAILLE_BUFFER_RECEPTION];
>
> } TSci1Datas;
>
> //*******************************************************************
>
> // In "main" file
>
> #define ROUTE_INTERRUPT(vec_adr,cfdata) \
>
> INT_CFADDR = (vec_adr) & 0xF0; \
>
> INT_CFDATA_ARR[((vec_adr) & 0x0F) >> 1]= (cfdata)
>
> #define S12_SCI1_VECTOR 0xD4 // S12 vector for SCI1 :
> 0xffd4
>
> void main(void)
>
> { int perdu, cptr;
>
> char s[40];
>
> SCI1_Init (38400, 6);
>
> DDRA = 0xff; // port A en sortie
>
> PORTA = 0x80; // valide sortie RS-485
>
> SetupXGATE();
>
> cptr = 0;
>
> for (;;)
>
> { cptr++;
>
> perdu = sprintf (s, "%6d", cptr);
>
> SCI1_puts (s);
>
> // Some delay of about 1 sec, using simply loop
>
> }
>
> }
>
> void SetupXGATE (void)
>
> { // Init XGATE vector block and set the XGVBR register to start
> address
>
> XGVBR= (unsigned int)(void*__far)(XGATE_VectorTable -
> XGATE_VECTOR_OFFSET);
>
> // Dourne interruptions pour XGATE
>
> ROUTE_INTERRUPT (S12_SCI1_VECTOR, 0x81);
>
> // Valide XGATE mode et interruptions
>
> XGMCTL= 0x8181;
>
> }
>
> void SCI1_Init (Word baud, Byte sysclk)
>
> { // ./. // calculation for Baudrate
>
> // Some inits
>
> SCI1CR1 = 0x00;
>
> SCI1SR2 = 0x80; // alternative register set
>
> SCI1ASR1 = 0x83; // clear alternative status
>
> SCI1ACR1 = 0x00; // disable interrupts on active
> edge, bit error, break
>
> SCI1ACR2 = 0x00; //
>
> SCI1SR2 = 0x00; // normal register set
>
> (void) SCI1SR1; // reset interrupt request flags
>
> SCI1CR2 = 0x00;
>
> SCI1BDH = diviseur.c[0]; // baudrate
>
> SCI1BDL = diviseur.c[1];
>
> SCI1CR2 = 0x2c; // TE | RE | RIE ==> enable
> xmit/receive, interrupt on receive only
>
> }
>
> //*******************************************************************
>
> // In "XGate" file
>
> // SCI1 management with XGate
>
> interrupt void XGATE_SCI1_thread (TSci1Datas *ptr)
>
> { Byte status;
>
> status = SCI1SR1; // read status...
>
> if (status & 0x0f) // errors ?
>
> { // ./.
>
> }
>
> // Interrupt on xmit empty
>
> if (status & 0x80) // TDRE : 0x80 ;
> Transmit Data Register Empty
>
> { if (ptr->emission.rd != ptr->emission.wr)
>
> { SCI1DRL = *ptr->emission.rd; // send current char
>
> ptr->emission.rd++; // prepare next char
>
> if (ptr->emission.rd >= &ptr->xmit_buffer[SCI1_TAILLE_BUFFER_EMISSION])
>
> ptr->emission.rd = &ptr->xmit_buffer[0];
>
> }
>
> else // nothing to xmit
>
> { SCI1CR2 &= 0x3f; // stop interrupt
>
> }
>
> }
>
> // Interrupt on receive full
>
> if (status & 0x20) // RDRF 0x20 :
> Receive data register full
>
> { // ./.
>
> }
>
> }
>
> interrupt void XGATE_ErrorHandler_thread (int dataptr)
>
> { dataptr++; // in order to avoid warning by compiler
>
> asm BRK;
>
> }
>
> // A part of Threads Table, only SCI1 thread is set
>
> #pragma CONST_SEG XGATE_VECTORS
>
> const XGATE_TableEntry XGATE_VectorTable[] = {
>
> // Channel # = Vector address / 2
>
> // channel 0..8 are not used, first used must match macro
> XGATE_VECTOR_OFFSET in xgate.h
>
> {XGATE_ErrorHandler_thread, 0x09}, // Channel 09 -
> Reserved
>
> // ./.
>
> {XGATE_ErrorHandler_thread, 0x69}, // Channel 69 -
> ATD0
>
> //{XGATE_ErrorHandler_thread, 0x6A}, // Channel 6A -
> SCI1
>
> {(XGATE_PtrFunction) XGATE_SCI1_thread, (int)&_sci1_datas}, //
> Channel
> 6A - SCI1
>
> {XGATE_ErrorHandler_thread, 0x6B}, // Channel 6B -
> SCI0
>
> // ./.
>
> {XGATE_ErrorHandler_thread, 0x78}, // Channel 78 -
> Real Time Interrupt
>
> {XGATE_ErrorHandler_thread, 0x79}, // Channel 79 -
> IRQ
>
> };
>
>> -----Message d'origine-----
>
>> De : 6... [mailto:6...] De la part de
>
>> Edward Karpicz
>
>> Envoy: mercredi 5 mars 2008 07:52
>
>> : 6...
>
>> Objet : Re: [68HC12] XGate thread using SCI running under simulator, not
>
>> on the target
>
>>> Joel,
>
>>> I don't know why code working in simulator doesn't work in target, but
>> you
>
>> oversimplified your minimal program. XGATE setup is missing, interrupt
>
>> controller setup is missing, XGATE interrupt vector table is missing.
>
>>> BTW XGATE V2 threads are uninterruptable. No new XGATE thread can be
>
>> started
>
>> until XGATE becomes idle. Make sure you exit from your other threads and
>
>> clear corresponding interrupt flags or interrupt masks. For example if
>> you
>
>> have just RTI thread, then verify that it doesn't loop forever, else your
>
>> SCI thread won't ever start.
>
>>> Edward
>
>>
>
Thank you, Edward, for your tracks.
I'll work on them in a couple of days.
I found too sample program on Freescale site (Application Note 3144), just
about SCI and XGate.
Now, I've some food to eat !

Best regards.
Joel
> -----Message d'origine-----
> De: 6... [mailto:6...] De la part de
> Edward Karpicz
> Envoy mercredi 5 mars 2008 22:22
> : 6...
> Objet: Re: [68HC12] XGate thread using SCI running under simulator, not
> on the target
>
> Joel,
>
> Maybe it's another simplification, but in your SCI init routine you are
> enabling RIE interrupt and in your SCI handler I see only transmitters
> code.
> RDRF flag isn't handled, it's read but isn't cleared by reading SCI1DRL.
> Anyway I just tried it as is, except that I enabled TDRE interrupt. XGATE
> SCI1 ISR got triggered. So problem must be somewhere else.
>
> Also
>
> 1) You init SCI1 first and enable RIE interrupt, then you route interrupts
> to XGATE. SCI char shouldn't arrive in the time between when you enable
> RIE
> and when you route SCI1 interrupts to XGATE. But I wonder what would
> happen
> if RIE would get pending at this time? I'm not sure if it is OK to switch
> routing of specific interrupt while it is pending and unmasked. I'd better
> swap in main() SetupXGATE() and SCI1Init(), so that routing is done before
> interrupt is enabled.
>
> 2) XGMCTL= 0x8181; //You enable XGATE interrupt here (XGIE). It sounds
> confusing, but it's a S12X interrupt :-). Imagine for a moment that XGATE
> can't run any code and it's something simple like key wakeup pin
> peripheral
> module. It has its own interrupt XGIE and you handle this interrupt using
> S12X.
> In fact XGATE has a lot of XGIF flags. There's a special XGATE instruction
> SIF, that is used to set XGIF flags. XGATE code executes SIF (set
> interrupt
> flags), XGIF flag gets set and XGIE interrupt becoms pending. So do you
> have
> S12X handler for this interrupt? If not then you shouldn't set XGIE, I
> guess.
>
>
> Regards,
>
> Edward
>