Hi,
I'm not sure should I post this to 16-bit microcontrollers area, or here...
Anyway, I am trying to use XGATE to handle the I/O with the SCI module as per app note AN3144. The MCU that I'm programming is M9S12XEP100 and ultimately I am trying to exchange data trough RS-232 between my PC and the evaluation board.
However, I am not able to get the XGATE/SCI to operate even with the Full Chip Simulation of CodeWarrior. Nor am I able to do it with the real chip.
What happens is that the XGATE executes only once the SCI_Thread() interrupt handler, and then just has BRK instructions. Still, I think that there should be at least one '*' character transferred to the terminal window. But the terminal wondow doesn't even appear.
Is there a way to get the XGATE to repeat the SCI_Thread() interrupt handler? And how do I open the terminal window?
Here are the main.c and xgate.cxgate source files (I deleted some of the unused interrupt vectors on xgate.cxgate to keep the text under the 20 000 character limit):
main.c
#include <hidef.h> /* common defines and macros */
#include "MC9S12XEP100.h" /* derivative-specific definitions */
#pragma LINK_INFO DERIVATIVE "mc9s12xep100"
#include <string.h>
#include "xgate.h"
#pragma push
/* this variable definition is to demonstrate how to share data between XGATE and S12X */
#pragma DATA_SEG SHARED_DATA
volatile int shared_counter; /* volatile because both cores are accessing it. */
/* Two stacks in XGATE core3 */
#pragma DATA_SEG XGATE_STK_L
word XGATE_STACK_L[1];
#pragma DATA_SEG XGATE_STK_H
word XGATE_STACK_H[1];
#pragma pop
#define ROUTE_INTERRUPT(vec_adr, cfdata) \
INT_CFADDR= (vec_adr) & 0xF0; \
INT_CFDATA_ARR[((vec_adr) & 0x0F) >> 1]= (cfdata)
#define SCI0_VEC 0xD6 // vector address= 2 * channel id Channel 6B - SCI0
static void SetupXGATE(void) {
/* initialize the XGATE vector block and
set the XGVBR register to its start address */
XGVBR= (unsigned int)(void*__far)(XGATE_VectorTable - XGATE_VECTOR_OFFSET);
/* switch SCI0 interrupt to XGATE */
ROUTE_INTERRUPT(SCI0_VEC, 0x81); /* RQST=1 and PRIO=1 */
/* when changing your derivative to non-core3 one please remove next five lines */
XGISPSEL= 1;
XGISP31= (unsigned int)(void*__far)(XGATE_STACK_L + 1);
XGISPSEL= 2;
XGISP74= (unsigned int)(void*__far)(XGATE_STACK_H + 1);
XGISPSEL= 0;
/* enable XGATE mode and interrupts */
XGMCTL= 0xFBC1; /* XGE | XGFRZ | XGIE */
/* force execution of software trigger 0 handler */
// XGSWT= 0x0101;
}
void SetupIO(void) {
//We want to have 9 600 baud rate:
//f_BUS = 4 MHz
//SCI Baud Rate = f_BUS /(16*SBR)
//=>SBR = 26 = 0x1A => SCI Baud Rate = 9615 (0.156 % error)
SCI0BDH = 0x00;
SCI0BDL = 0x1A;
//SCI0CR1 = SCI0CR1_PE_MASK;
SCI0CR2 = (SCI0CR2_TE_MASK);
SCI0CR2 = SCI0CR2_TIE_MASK;
}
void main(void) {
/* put your own code here */
EnableInterrupts;
SetupXGATE();
SetupIO();
for(; {
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
xgate.cxgate:
#include <hidef.h> /* common defines and macros */
#include "xgate.h"
#include "MC9S12XEP100.h"
// put your handler variables here
typedef struct {
int counter;
} MyDataType;
static MyDataType MyData= {
0
};
// interrupt handler
interrupt void SoftwareTrigger0_Handler(MyDataType* __restrict pData) {
// put your own code here
pData->counter++;
if (pData->counter > 100) {
pData->counter= 0;
shared_counter++;
}
}
//interrupt handler for SCI0
interrupt void SCI_Thread(void) {
SCI0SR1;
SCI0DRL = '*';
}
// interrupt handler for all others
interrupt void ErrorHandler(int dataptr) {
int chanNum= dataptr;
asm BRK;
}
#pragma CONST_SEG XGATE_VECTORS /* assign the vector table in separate segment for dedicated placement in linker parameter file */
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 */
{ErrorHandler, 0x09}, // Channel 09 - Reserved
...
{ErrorHandler, 0x38}, // Channel 38 - XGATE Software Trigger 1
{(XGATE_Function)SoftwareTrigger0_Handler, (int)&MyData}, // Channel 39 - XGATE Software Trigger 0
{ErrorHandler, 0x3A}, // Channel 3A - Periodic Interrupt Timer
...
{ErrorHandler, 0x6A}, // Channel 6A - SCI1
{(XGATE_Function)SCI_Thread, 0x6B}, // Channel 6B - SCI0
{ErrorHandler, 0x6C}, // Channel 6C - SPI0
....
{ErrorHandler, 0x79}, // Channel 79 - IRQ
};
Best Regards,
Timo
Solved! Go to Solution.
What happens is that you keep SCI transmitter disabled:
SCI0CR2 = (SCI0CR2_TE_MASK);
SCI0CR2 = SCI0CR2_TIE_MASK;
What happens is that you keep SCI transmitter disabled:
SCI0CR2 = (SCI0CR2_TE_MASK);
SCI0CR2 = SCI0CR2_TIE_MASK;
Thanks, that is true!
However, fixing that did not fix the problem... Still the same situation except the trasmitter is on according to the control bit.
The XGATE goes to BRK instruction after xgate.cgate line: SCI0DRL = '*';
BR,
Timo
It is quite weird. I made test project with your code fragments pasted in. It works in simulator and certainly should work in MCU.
Actually I got the SCI working with the evaluation board and the serial port with my code. But, still CodeWarrior won't open the terminal window when I try to do a Full Chip simulation, which is quite strange. With your code the terminal window opens.
Thanks for the help!
You can opern terminal window using Component->Open menu in debugger. To make terminal window opening automatically you need to save debugger window layout. To do so use Window->Layout->Store manu and overwrite C_Layout.hwl