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

📄 skyeye_mach_mcf5249.c

📁 skyeye的开源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        //TRACE("Posting interrupt Number=%d, Vector=%d\n", number, vector);        /* Post an interrupt */        if(!(io->imr & mask )) {		/* check if exist pending interrupt */                if(io->ipr & mask) {                        //TRACE("Already pending, not playing with registers further.\n");                        return;                }		exception_post(level, &mcf5249_iack_func);		io->ipr |= mask;		return;	}}static void interrupt_withdraw(short number){	short mask = (0x1 << number);	mcf5249_io_t * io = &mcf5249_io;	int icr_level = ICR_LEVEL(io->icr[number - 8]);	if(!(io->imr & mask )) {                //TRACE("Withdrawing interrupt Number=%d\n", number);                if(! (io->ipr & mask) ) {                        /* This interrupt isn't pending, there's no                         * need to withdraw it further */                        //TRACE("Interrupt wasn't pending, no need to withdraw.\n");                        return;                }                /* Set us not pending */                io->ipr &= ~mask;		exception_withdraw(icr_level);		//TRACE("Done.\n");                return;        }//      TRACE("NOT Withdrawn, the interrupt is unmasked in the IMR\n");        return;}void mcf5249_io_do_cycle(){	int i;	for(i = 0; i < 2; i++){		//mcf5249_timer_t * timer = &mcf5249_io.timer[i];		/* check if timer is enbaled */		if(mcf5249_io.timer[i].tmr & 0x1){			mcf5249_io.timer[i].tcn++;			/* check if reference interrupt is enabled */			if((mcf5249_io.timer[i].tcn == mcf5249_io.timer[i].trr) && (mcf5249_io.timer[i].tmr & 0x10))			{							//printf("KSDBG:tcn=0x%x,trr=0x%x\n", mcf5249_io.timer[i].tcn, mcf5249_io.timer[i].trr);				/* set REF bit in TER */				mcf5249_io.timer[i].ter |= 0x2;				interrupt_assert(9 + i);					/* check if in restart mode */				if(mcf5249_io.timer[i].tmr & 0x8)					mcf5249_io.timer[i].tcn = 0x0;			}		}	}	if(1){                /* UART FIFO full interrupt enabled */                struct timeval tv;                unsigned char buf;                tv.tv_sec = 0;                tv.tv_usec = 0;                if(skyeye_uart_read(-1, &buf, 1, &tv, NULL) > 0){                        mcf5249_io.uart[0].urb = buf;                        /* set RXRDY bit in UISR */                        mcf5249_io.uart[0].uisr |= 0x2;                }		/* set TXRDY bit in UISR */                mcf5249_io.uart[0].uisr |= 0x1;	}		/* check if UART Transmitter ready interrupt enabled */	if(!(mcf5249_io.ipr & 0xc)){		if((mcf5249_io.uart[0].uimr & mcf5249_io.uart[0].uisr))			interrupt_assert(0xc);	}}static char cs_module_read(unsigned int *result, short size, int offset){	int index = offset - 0x80;	int reg_no;	if(index >= 0 && index <=8){		reg_no = index / 4;		index = 0;	}	if(index >= 0xc && index <= 0x16){                reg_no = (index - 0xc)/ 4;                index = 1;        }	if(index >= 0x18 && index <= 0x22){		reg_no = (index - 0x18)/4;		index = 2;	}	if(index >= 0x24 && index <= 0x2e){		reg_no = (index - 0x24);		index = 3;	}	switch(reg_no){		case CSAR:			*result = mcf5249_io.cs_module[index].csar;			return 1;		case CSMR:			*result = mcf5249_io.cs_module[index].csmr;			return 1;		case CSCR:			*result = mcf5249_io.cs_module[index].cscr;			return 1;		default:			fprintf(stderr,"Error adress in %s,offset=0x%x\n",__FUNCTION__,offset);                        skyeye_exit(-1);                        return 0;	}}static char cs_module_write(short size, int offset, unsigned int value){	int index = offset - 0x80;	int reg_no;	if(index >= 0 && index <=8){		reg_no = index / 4;		index = 0;	}	if(index >= 0xc && index <= 0x16){                reg_no = (index - 0xc)/ 4;                index = 1;        }	if(index >= 0x18 && index <= 0x22){		reg_no = (index - 0x18)/4;		index = 2;	}	if(index >= 0x24 && index <= 0x2e){		reg_no = (index - 0x24);		index = 3;	}	switch(reg_no){		case CSAR:			mcf5249_io.cs_module[index].csar = value;			return 1;		case CSMR:			mcf5249_io.cs_module[index].csmr = value;			return 1;		case CSCR:			mcf5249_io.cs_module[index].cscr = value;			return 1;		default:			fprintf(stderr,"Error adress in %s,offset=0x%x\n",__FUNCTION__,offset);                        skyeye_exit(-1);                        return 0;	}}static char timer_read(unsigned int *result, short size, int offset){	int index = (offset - 0x140) / 0x40;	offset = offset - 0x140 - (index * 0x40);	//printf("DBG: in %s, offset = 0x%x, value=0x%x\n", __FUNCTION__, offset, value);	switch(offset){		case 0x0:			*result = mcf5249_io.timer[index].tmr;			return 1;		case 0x4:			*result = mcf5249_io.timer[index].trr;			return 1;		case 0x8:			*result = mcf5249_io.timer[index].tcr;			return 1;		case 0xc:			*result = mcf5249_io.timer[index].tcn;			return 1;		case 0x11:			/* write one to clear the corresponding bit */			*result = mcf5249_io.timer[index].ter;			/* clear the corresponding bit in ipr */			//mcf5249_io.ipr &=  ~(0x1 << 9);			interrupt_withdraw(index + 9);			return 1;		default:			fprintf(stderr,"Error adress in %s,offset=0x%x\n",__FUNCTION__,offset);                        skyeye_exit(-1);                        return 0;	}}static char timer_write(short size, int offset, unsigned int value){	int index = (offset - 0x140) / 0x40;	offset = offset - 0x140 - (index * 0x40);	//printf("DBG: in %s, offset = 0x%x, value=0x%x\n", __FUNCTION__, offset, value);	switch(offset){		case 0x0:			mcf5249_io.timer[index].tmr = value;			return 1;		case 0x4:			mcf5249_io.timer[index].trr = value;			return 1;		case 0x8:			mcf5249_io.timer[index].tcr = value;			return 1;		case 0xc:			mcf5249_io.timer[index].tcn = value;			return 1;		case 0x11:			/* write one to clear the corresponding bit */			mcf5249_io.timer[index].ter &= ~(value & 0x3);			/* clear the corresponding bit in ipr */			//mcf5249_io.ipr &=  ~(0x1 << 9);			interrupt_withdraw(index + 9);			return 1;		default:			fprintf(stderr,"Error adress in %s,offset=0x%x\n",__FUNCTION__,offset);                        skyeye_exit(-1);                        return 0;	}}static char uart_read(unsigned int *result, short size, int offset){	int index;        if(offset >= 0x1C0 && offset <= 0x1FC){                index = 0;                offset = offset - 0x1C0;        }        if(offset >= 0x200 && offset <= 0x23C){                index = 1;                offset = offset - 0x200;        }	/*	extern struct _memory_core memory_core;	if(offset != 0x4)                printf("DBG: in %s, offset = 0x%x,PC=0x%x\n", __FUNCTION__, offset, memory_core.pc);	*/        switch(offset){		case 0x0:			*result = mcf5249_io.uart[index].umr1;			break;		case 0x4:			*result = mcf5249_io.uart[index].usr;			break;		case 0xC:			*result = mcf5249_io.uart[index].urb;			/* set FFULL bit in USR is zero */			mcf5249_io.uart[index].usr &= ~0x2;			/* set RxRDY bit in USR is zero */			mcf5249_io.uart[index].usr &= ~0x1;			/* check RXIRQ bit in UMR1 */			//if(mcf5249_io.uart[index].umr1 & 0x40)			mcf5249_io.uart[index].uisr &= ~0x2;			break;			case 0x10:			*result = mcf5249_io.uart[index].uipcr;			break;		case 0x14:			*result = mcf5249_io.uart[index].uisr;				mcf5249_io.uart[index].uisr = 0x0;			interrupt_withdraw(12);			break;		case 0x18:			*result = mcf5249_io.uart[index].ubg1;			break;		case 0x1C:			*result = mcf5249_io.uart[index].ubg2;			break;		case 0x30:			*result = mcf5249_io.uart[index].uivr;			break;		case 0x34:			*result = mcf5249_io.uart[index].uip;			break;		default:                        fprintf(stderr,"Error adress in %s,offset=0x%x\n",__FUNCTION__,offset);                        skyeye_exit(-1);                        return 0;	}	return 1;}static char uart_write(short size, int offset, unsigned int value){	int index, cmd;	char tmp;	if(offset >= 0x1C0 && offset <= 0x1FC){		index = 0;		offset = offset - 0x1C0;	}	if(offset >= 0x200 && offset <= 0x23C){		index = 1;		offset = offset - 0x200;	}	/*	if(offset != 0xc)		printf("DBG: in %s, offset = 0x%x, value=0x%x\n", __FUNCTION__, offset, value);	*/	switch(offset){		case 0x0:			mcf5249_io.uart[index].umr1 = value;			break;		case 0x4:			mcf5249_io.uart[index].ucsr = value;			break;		case 0x8:			mcf5249_io.uart[index].ucr = value;			if((value & 0x3) == 0x1) /* Receiver enable */				;			if(((value >> 2) & 0x3) == 0x1) /* Transmitter enable */				/* set TXRDY bit and TXEMP bit in usr */	                        mcf5249_io.uart[index].usr |= 0xc;			cmd = (value >> 4) & 0x7;			if (cmd == 0x4) /* Reset error status */				mcf5249_io.uart[index].usr &= 0xf;			break;		case 0xc:			mcf5249_io.uart[index].utb = value;			tmp = value & 0xff;			skyeye_uart_write(-1, &tmp, 1, NULL);			/* set TXRDY bit and TXEMP bit in usr */			mcf5249_io.uart[index].usr |= 0xc;			/* set TXRDY bit in usr */			mcf5249_io.uart[index].uisr |= 0x1;			break;		case 0x10:			mcf5249_io.uart[index].uacr = value;			break;		case 0x14:			mcf5249_io.uart[index].uimr = value;			break;		case 0x18:			mcf5249_io.uart[index].ubg1 = value;			break;		case 0x1C:			mcf5249_io.uart[index].ubg2 = value;			break;		case 0x30:			mcf5249_io.uart[index].uivr = value;			break;		case 0x38:			mcf5249_io.uart[index].uop1 = value;			break;		case 0x3C:			mcf5249_io.uart[index].uop0 = value;			break;		default:                        fprintf(stderr,"Error adress in %s,offset=0x%x\n",__FUNCTION__,offset);                        skyeye_exit(-1);                        return 0;	}	return 1;}void mcf5249_mach_init(void * state, machine_config_t * mach){	struct _memory_core * core = (struct _memory_core *)state;	machine_config_t * this_mach = mach;	core->mbar_read = mcf5249_mbar_read;	core->mbar_write = mcf5249_mbar_write;	core->mbar2_read = mcf5249_mbar2_read;	core->mbar2_write = mcf5249_mbar2_write;	/* init io  value */	/* init mach */	if (!this_mach) {		exit (-1);	}        this_mach->mach_io_do_cycle = mcf5249_io_do_cycle;/*	this_mach->mach_io_read_byte = mcf5249_io_read_byte;        this_mach->mach_io_read_halfword = mcf5249_io_read_halfword;        this_mach->mach_io_read_word = mcf5249_io_read_word;        this_mach->mach_io_write_byte = mcf5249_io_write_byte;        this_mach->mach_io_write_halfword = mcf5249_io_write_halfword;        this_mach->mach_io_write_word = mcf5249_io_write_word;        this_mach->mach_io_do_cycle = mcf5249_io_do_cycle;        this_mach->mach_set_intr = mcf5249_set_int;*/}

⌨️ 快捷键说明

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