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

📄 main.c

📁 CAN 网关原代码,汽车电子中的总线网关
💻 C
字号:
/* include files */
#include "peripherals.h"
#include "xgate_vectors.h"
#include "gateway_data_dims.h"
#include "gateway.h"
#include "load_meas.h"

/******************************************************************************
Function Name	:	PLLStartup
Engineer		:	r27624
Date			:	26/9/2001
Arguments		:	freq: 
Return			:	
Notes			:	Ref Clock is assumed to be 1MHz
******************************************************************************/
//#define REFDV 15					/* 16 MHz crystal */
#define REFDV 3					/* 4 MHz crystal */
void PLLStartup(tU08 freq) {
									/* switch to OSCCLK */
	CRG.clksel.byte = 0;
 	CRG.pllctl.byte = CME   |		/* clock monitor enabled */
  				  		    PLLON |		/* PLL on */
	  			     			AUTO	|		/* automatic bandwidth control enabled */
		  		      		SCME;			/* self clock mode enabled */
	if(freq != 0) {
	  								/* configure PLL */
										/* fref = fosc / (REFDV+1) */
	  CRG.refdv.byte = REFDV;
									/* fvco = 2*fref*(SYNR+1) */
	  CRG.synr.byte = freq - 1;
									/* wait for lock FOR EVER! */
	  while(CRG.crgflg.bit.lock != SET);
		if(CRG.crgflg.bit.lock == SET) {
									/* switch to PLLCLK */
			CRG.clksel.byte |= PLLSEL;
  	}
	}
}

/******************************************************************************
Function Name	:	Xgate_Init
Engineer		:	r27624	
Date			:	24/02/2004
Parameters		:	None
Returns			:	None
Notes			:	
******************************************************************************/
void Xgate_Init(void) {
  XGATE.xgvbr = (int)((void*__far)XGATEVectorTable)-0x00c0;	  /* initialise Xgate vector base */
  XGATE.xgmctl = 0xff00 | XGE | XGFRZ | XGIE;					/* interrupt enable, enable Xgate, stop Xgate in freeze mode */
}

/******************************************************************************
Function Name	:	Int_Init
Engineer		:	r27624	
Date			:	24/02/2004
Parameters		:	None
Returns			:	None
Notes			:	 
******************************************************************************/
void Int_Init(void) {
  /* load measurement */
  SetIntPrio(0x6F, RQST|3);             /* ECT overflow */
  SetIntPrio(0x39-LM_INIT_SWX, RQST|1); /* initialisation */
	asm(cli);
}

/******************************************************************************
Function Name	:	main
Engineer		:	r54430	
Date			:	24/03/2004
Parameters		:	None
Returns			:	None
Notes			:	 
******************************************************************************/
void main(void) {
	PLLStartup(40);	    /* 40MHz */
	Xgate_Init();
	Int_Init();
  #if (defined(DO_LM))
    LM_INIT();        /* initialise load measurement */
  #endif
  GatewayInit(40000); /* initialise the gateway */
	while(1);
}

⌨️ 快捷键说明

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