⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 飞思卡尔XGATE Training-4(XGATE_SCI_FRAME_EXTRACTION)
💻 C
字号:
#include <hidef.h>      /* common defines and macros */
#include <MC9S12XEP100.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xep100"
#include <string.h>
#include "xgate.h"
#include "myTypes.h"

void SetupXGATE(void);
void SetupSCI(void);
void SetupClock(void);
void SendString(unsigned char *string);


#define ROUTE_INTERRUPT(vec_adr, cfdata)                \
  INT_CFADDR= (vec_adr) & 0xF0;                         \
  INT_CFDATA_ARR[((vec_adr) & 0x0F) >> 1]= (cfdata)

#define SOFTWARETRIGGER0_VEC  0x72 /* vector address= 2 * channel id */
#define SCI0_VEC  0xD6 /* vector address= $xxD6 */

#pragma DATA_SEG SHARED_DATA
volatile tMyStruct mystruct;
volatile tSendBuffer SendBuffer;
#pragma DATA_SEG DEFAULT

/***************************************************************************/
void main(void)
{
  SetupClock();
  SetupSCI();
  SetupXGATE();
  SendBuffer.availability=1; 
  EnableInterrupts;
   
  SendString("      ******* Welcome to Lab4 *******\r\n");
  SendString("Please enter a Frame with appropiate separators\r\n");
  SendString("\n>");

  for(;;){};
 
}

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

void SetupXGATE(void)
{
  //initialize vector table
  XGVBR= (unsigned int)(void*__far)(XGATE_VectorTable - XGATE_VECTOR_OFFSET);

  // route SCI interrupt to Xgate
  ROUTE_INTERRUPT(SCI0_VEC, 0x81); /* RQST=1 and PRIO=1 */
  
  //enable Xgate
  XGMCTL= 0xFBC1; /* XGE | XGFRZ | XGIE */
}

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

void SetupSCI(void)
{
  
  //PC Baud Rate is 4800
  //Set Baud Rate. IREN bit = 0, formula is: 
  //SCI0BD_Register_value=busClock/(16 * BaudRate);
  //For the DEMOXEP100, RESET default busclock is equal to crystal frequency value = 4 Mhz
  //4000000/(16*9600)=26=0x1A; 
  
  SCI0BD =0x001A;
  //Enable transmitter
  SCI0CR2_TE = 1;
  //Enable receiver
  SCI0CR2_RE = 1;
  
  //Enable receiver full interrupt flag
  SCI0CR2_RIE=1;
    
  //Enable trasceiver data register empty interrtupt 
  //this will trigger one first interrupt. 
  SCI0CR2_TIE=0;
  }
/***************************************************************************/  

void SetupClock(void)
{
//CLKSEL_PLLSEL=1;
//while(CLKSEL_PLLSEL==0); //wait for PLLSEL bit to go high.

//With PLL selected, and all other clock register values in their default RESET state :
//Fbus=Fpll/2 = 2*Fosc/2. => Fbus=Fosc, and the crystal in the demo board is a 4Mhz. 
//So, Fbus= 4Mhz. 

}

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

void SendString(unsigned char *string)
{
//Wait for buffer to be available from a
//from previous SendString task
while(SendBuffer.availability==0){};

//Try to grab semaphore 0 one first time
XGSEM = 0x0101;
//wait until semaphore available
while (!XGSEM_XGSEM & 0x0001)
{
XGSEM = 0x0101;
}

SendBuffer.availability=0;
(void)strcpy(SendBuffer.buffer,string);
SendBuffer.size=strlen(string);
SendBuffer.index=0;
SCI0CR2_TIE = 1;

//release semaphore
XGSEM = 0x0100;
}
/***************************************************************************/  

#pragma CODE_SEG NON_BANKED

/*This is the CPU interrupt generated by the XGATE when an SCI frame has been extracted 
  and ready for the CPU*/
interrupt void CPU_SCI_Interrupt(void)
{
SendString("Frame Received and extracted\n\r>");            
//Clear the xgate channel flag! 
XGIF1_XGIF_6B=1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -