コード例 #1
0
ファイル: hwctrl.c プロジェクト: iruka-/ATMEL_AVR
void spi_xmit (BYTE td)
{
	BYTE a;
	BYTE spicmd[2];
	int n = 8;


	switch (PortType) {
		case TY_COMM :
			do {
				a = ((td & 0x80) ? C_MOSI : 0);		/* MOSI(TD) = data */
				_outp(COM_LCR, a);
				iodly();							/* delay */
				_outp(COM_MCR, C_SCK);				/* SCK(RS) = "H" */
				iodly();							/* delay */
				_outp(COM_MCR, 0);					/* SCK(RS) = "L" */
				td <<= 1;
			} while (--n);
			break;

		case TY_VCOM :
			do {
				if(td & 0x80) {						/* MOSI(TD) = data */
					if(!sig_break) {
						EscapeCommFunction(hComm, SETBREAK);
						sig_break = TRUE;
					}
				} else {
					if(sig_break) {
						EscapeCommFunction(hComm, CLRBREAK);
						sig_break = FALSE;
					}
				}
				iodly();							/* delay */
				EscapeCommFunction(hComm, SETRTS);	/* SCK(RS) = "H" */
				iodly();							/* delay */
				EscapeCommFunction(hComm, CLRRTS);	/* SCK(RS) = "L" */
				td <<= 1;
			} while (--n);
			break;

		case TY_BRIDGE :
			spicmd[0] = spicmd[1] = td;
			n = (td == FLAG) ? 2 : 1;
			send_bridge(spicmd, n);					/* Send data exchange command */
			break;

		case TY_AVRSP :
			do {
				a = ((td & 0x80) ? B_ENA | B_MOSI : B_ENA);	/* MOSI(D1) = data, SCK(D0) = "L" */
				_outp(LPT_DAT, a);
				iodly();									/* delay */
				_outp(LPT_DAT, a | B_SCK);					/* SCK(D0) = "H" */
				iodly();									/* delay */
				td <<= 1;
			} while (--n);
			_outp(LPT_DAT, a);								/* SCK(D0) = "L" */
			break;

		case TY_STK200 :
			do {
				a = ((td & 0x80) ? BS_MOSI : 0);	/* MOSI(D5) = data, SCK(D4) = "L" */
				_outp(LPT_DAT, a);
				iodly();							/* delay */
				_outp(LPT_DAT, a | BS_SCK);			/* SCK(D4) = "H" */
				iodly();							/* delay */
				td <<= 1;
			} while (--n);
			_outp(LPT_DAT, a);						/* SCK(D4) = "L" */
			break;

		case TY_XILINX :
			do {
				a = ((td & 0x80) ? BX_DIS2 | BX_MOSI : BX_DIS2); /* MOSI(D0) = data, SCK(D1) = "L" */
				_outp(LPT_DAT, a);
				iodly();									/* delay */
				_outp(LPT_DAT, a | BX_SCK);					/* SCK(D1) = "H" */
				iodly();									/* delay */
				td <<= 1;
			} while (--n);
			_outp(LPT_DAT, a);								/* SCK(D1) = "L" */
			break;

		case TY_LATTICE :
			do {
				a = ((td & 0x80) ? BL_MOSI : 0);	/* MOSI(D0) = data, SCK(D1) = "L" */
				_outp(LPT_DAT, a);
				iodly();							/* delay */
				_outp(LPT_DAT, a | BL_SCK);			/* SCK(D1) = "H" */
				iodly();							/* delay */
				td <<= 1;
			} while (--n);
			_outp(LPT_DAT, a);						/* SCK(D1) = "L" */
			break;

		case TY_ALTERA :
			do {
				a = ((td & 0x80) ? BA_MOSI : 0);	/* MOSI(D6) = data, SCK(D0) = "L" */
				_outp(LPT_DAT, a);
				iodly();							/* delay */
				_outp(LPT_DAT, a | BA_SCK);			/* SCK(D0) = "H" */
				iodly();							/* delay */
				td <<= 1;
			} while (--n);
			_outp(LPT_DAT, a);						/* SCK(D0) = "L" */
			break;
	}

}
コード例 #2
0
ファイル: hwctrl.c プロジェクト: iruka-/ATMEL_AVR
void spi_clk ()
{
	BYTE spicmd[2] = { FLAG, SPI_SCK };


	switch (PortType) {
#if AVRSPX
		case TY_HIDASP :
			{
				char cmd[]={0,0,0,0};
				hidasp_cmd(cmd,NULL);
			}
			break;
#endif
		case TY_COMM :
			iodly();
			_outp(COM_MCR, C_SCK);		/* SCK = "H" */
			iodly();
			_outp(COM_MCR, 0);			/* SCK = "L" */
			break;

		case TY_VCOM :
			iodly();
			EscapeCommFunction(hComm, SETRTS);
			iodly();
			EscapeCommFunction(hComm, CLRRTS);
			break;

		case TY_BRIDGE :
			send_bridge(spicmd, 2);
			break;

		case TY_AVRSP :
			iodly();
			_outp(LPT_DAT, B_ENA|B_SCK);
			iodly();
			_outp(LPT_DAT, B_ENA);
			break;

		case TY_STK200 :
			iodly();
			_outp(LPT_DAT, BS_SCK);
			iodly();
			_outp(LPT_DAT, 0);
			break;

		case TY_XILINX :
			iodly();
			_outp(LPT_DAT, BX_DIS2|BX_SCK);
			iodly();
			_outp(LPT_DAT, BX_DIS2);
			break;

		case TY_LATTICE :
			iodly();
			_outp(LPT_DAT, BL_SCK);
			iodly();
			_outp(LPT_DAT, 0);
			break;

		case TY_ALTERA :
			_outp(LPT_DAT, BA_SCK);
			iodly();
			_outp(LPT_DAT, 0);
			break;
	}

}
コード例 #3
0
ファイル: hwctrl.c プロジェクト: iruka-/ATMEL_AVR
BYTE spi_rcvr (BYTE mode)
{
	BYTE rd = 0;
	BYTE spicmd[2] = { FLAG, SPI_RCVZ };
	int n = 8;


	switch (PortType) {
		case TY_COMM :
			_outp(COM_LCR, 0);						/* MOSI(TD) = "L" */
			iodly();
			do {
				rd <<= 1;							/* Read MISO(DR) */
				if(_inp(COM_MSR) & C_MISO) rd++;
				_outp(COM_MCR, C_SCK);				/* SCK(RS) = "H" */
				iodly();							/* delay */
				_outp(COM_MCR, 0);					/* SCK(RS) = "L" */
				iodly();							/* delay */
			} while (--n);
			if(mode == RM_ASYNC)
				fifo_put(rd);
			break;

		case TY_VCOM :
			if(!sig_break) {
				EscapeCommFunction(hComm, CLRBREAK);/* MOSI(TD) = "L" */
				sig_break = FALSE;
			}
			iodly();
			do {
				rd <<= 1;							/* Read MISO(DR) */
				GetCommModemStatus(hComm, &ModemStat);
				if(ModemStat & MS_DSR_ON) rd++;
				EscapeCommFunction(hComm, SETRTS);	/* SCK(RS) = "H" */
				iodly();							/* delay */
				EscapeCommFunction(hComm, CLRRTS);	/* SCK(RS) = "L" */
				iodly();							/* delay */
			} while (--n);
			if(mode == RM_ASYNC)
				fifo_put(rd);
			break;

		case TY_BRIDGE :
			send_bridge(spicmd, 2);					/* Send SPI_RCVZ command */
			if(mode == RM_SYNC) {
				if(!read_bridge(&rd, 1))			/* Get a read data from pipeline */
					rd = 0xFF;
			}
			break;

		case TY_AVRSP :
			_outp(LPT_DAT, B_ENA);					/* MOSI(D0) = "L" */
			iodly();
			do {
				rd <<= 1;							/* Read MISO(BUSY) */
				if((_inp(LPT_STA) & S_BUSY) == 0) rd++;
				_outp(LPT_DAT, B_ENA | B_SCK);		/* SCK(D1) = "H" */
				iodly();							/* delay */
				_outp(LPT_DAT, B_ENA);				/* SCK(D1) = "L" */
				iodly();							/* delay */
			} while (--n);
			if(mode == RM_ASYNC)
				fifo_put(rd);
			break;

		case TY_STK200 :
			_outp(LPT_DAT, 0);						/* MOSI(D5) = "L" */
			iodly();
			do {
				rd <<= 1;							/* Read MISO(ACK) */
				if(_inp(LPT_STA) & S_ACK) rd++;
				_outp(LPT_DAT, BS_SCK);				/* SCK(D4) = "H" */
				iodly();							/* delay */
				_outp(LPT_DAT, 0);					/* SCK(D4) = "L" */
				iodly();							/* delay */
			} while (--n);
			if(mode == RM_ASYNC)
				fifo_put(rd);
			break;

		case TY_XILINX :
			_outp(LPT_DAT, BX_DIS2);				/* MOSI(D0) = "L" */
			iodly();
			do {
				rd <<= 1;							/* Read MISO(SEL) */
				if(_inp(LPT_STA) & S_SEL) rd++;
				_outp(LPT_DAT, BX_DIS2 | BX_SCK);	/* SCK(D1) = "H" */
				iodly();							/* delay */
				_outp(LPT_DAT, BX_DIS2);			/* SCK(D1) = "L" */
				iodly();							/* delay */
			} while (--n);
			if(mode == RM_ASYNC)
				fifo_put(rd);
			break;

		case TY_LATTICE :
			_outp(LPT_DAT, 0);						/* MOSI(D0) = "L" */
			iodly();
			do {
				rd <<= 1;							/* Read MISO(ACK) */
				if(_inp(LPT_STA) & S_ACK) rd++;
				_outp(LPT_DAT, BL_SCK);				/* SCK(D1) = "H" */
				iodly();							/* delay */
				_outp(LPT_DAT, 0);					/* SCK(D1) = "L" */
				iodly();							/* delay */
			} while (--n);
			if(mode == RM_ASYNC)
				fifo_put(rd);
			break;

		case TY_ALTERA :
			_outp(LPT_DAT, 0);						/* MOSI(D6) = "L" */
			iodly();
			do {
				rd <<= 1;							/* Read MISO(BUSY) */
				if((_inp(LPT_STA) & S_BUSY) == 0) rd++;
				_outp(LPT_DAT, BA_SCK);				/* SCK(D0) = "H" */
				iodly();							/* delay */
				_outp(LPT_DAT, 0);					/* SCK(D0) = "L" */
				iodly();							/* delay */
			} while (--n);
			if(mode == RM_ASYNC)
				fifo_put(rd);
			break;
	}

	return(rd);
}
コード例 #4
0
ファイル: hwctrl.c プロジェクト: iruka-/ATMEL_AVR
void spi_reset ()
{
	BYTE spicmd[2] = { FLAG, SPI_RESET };


	switch (PortType) {
#if AVRSPX
		case TY_HIDASP :
			delay_ms(10);	/* Add by senshu 2008/10/12 14:02:01 */
			{
				unsigned char dat[]={0,0,0,0};
				hidasp_cmd(dat,NULL);
			}
			break;
#endif
		case TY_COMM :
			_outp(COM_MCR, 0);		/* RESET,SCK = "L" */
			delay_ms(10);			/* 10msec */
			_outp(COM_MCR, C_RES);	/* RESET = "H" */
			iodly(); iodly();		/* delay */
			_outp(COM_MCR, 0);		/* RESET = "L" */
			break;

		case TY_VCOM :
			EscapeCommFunction(hComm, CLRDTR);
			EscapeCommFunction(hComm, CLRRTS);
			delay_ms(10);
			EscapeCommFunction(hComm, SETDTR);
			iodly(); iodly();
			EscapeCommFunction(hComm, CLRDTR);
			break;

		case TY_BRIDGE :
			delay_ms(10);
			send_bridge(spicmd, 2);
			break;

		case TY_AVRSP :
			_outp(LPT_DAT, B_ENA);
			delay_ms(10);
			_outp(LPT_DAT, B_ENA|B_RES);
			iodly(); iodly();
			_outp(LPT_DAT, B_ENA);
			break;

		case TY_STK200 :
			_outp(LPT_DAT, 0);
			delay_ms(10);
			_outp(LPT_DAT, BS_RES);
			iodly(); iodly();
			_outp(LPT_DAT, 0);
			break;

		case TY_XILINX :
			_outp(LPT_DAT, BX_DIS2);
			delay_ms(10);
			_outp(LPT_DAT, BX_DIS2|BX_RES);
			iodly(); iodly();
			_outp(LPT_DAT, BX_DIS2);
			break;

		case TY_LATTICE :
			_outp(LPT_DAT, 0);
			delay_ms(10);
			_outp(LPT_DAT, BL_RES);
			iodly(); iodly();
			_outp(LPT_DAT, 0);
			break;

		case TY_ALTERA :
			_outp(LPT_DAT, 0);
			delay_ms(10);
			_outp(LPT_DAT, BA_RES);
			iodly(); iodly();
			_outp(LPT_DAT, 0);
			break;

	}
	RcvrFifo.Rp = 0;					/* Flush FIFO */
	RcvrFifo.Wp = 0;
	RcvrFifo.Ctr = 0;
	delay_ms(30);						/* 30msec */
}
コード例 #5
0
ファイル: hwctrl.c プロジェクト: BackupTheBerlios/rundfunker
void spi_reset ()
{
	BYTE spicmd[2] = { FLAG, SPI_RESET };


	switch (PortType) {
		case TY_COMM :
			_outp(COM_MCR, 0);		/* RESET,SCK = "L" */
			delay_ms(10);			/* 10msec */
			_outp(COM_MCR, C_RES);	/* RESET = "H" */
			iodly(); iodly();		/* delay */
			_outp(COM_MCR, 0);		/* RESET = "L" */
			break;

		case TY_VCOM :
			EscapeCommFunction(hComm, CLRDTR);
			EscapeCommFunction(hComm, CLRRTS);
			delay_ms(10);
			EscapeCommFunction(hComm, SETDTR);
			iodly(); iodly();
			EscapeCommFunction(hComm, CLRDTR);
			break;

		case TY_BRIDGE :
			delay_ms(10);
			send_bridge(spicmd, 2);
			break;

		case TY_AVRSP :
			_outp(LPT_DAT, B_ENA);
			delay_ms(10);
			_outp(LPT_DAT, B_ENA|B_RES);
			iodly(); iodly();
			_outp(LPT_DAT, B_ENA);
			break;

		case TY_STK200 :
			_outp(LPT_DAT, 0);
			delay_ms(10);
			_outp(LPT_DAT, BS_RES);
			iodly(); iodly();
			_outp(LPT_DAT, 0);
			break;

		case TY_XILINX :
			_outp(LPT_DAT, BX_DIS2);
			delay_ms(10);
			_outp(LPT_DAT, BX_DIS2|BX_RES);
			iodly(); iodly();
			_outp(LPT_DAT, BX_DIS2);
			break;

		case TY_LATTICE :
			_outp(LPT_DAT, 0);
			delay_ms(10);
			_outp(LPT_DAT, BL_RES);
			iodly(); iodly();
			_outp(LPT_DAT, 0);
			break;

		case TY_ALTERA :
			_outp(LPT_DAT, 0);
			delay_ms(10);
			_outp(LPT_DAT, BA_RES);
			iodly(); iodly();
			_outp(LPT_DAT, 0);
			break;

	}
	RcvrFifo.Rp = 0;					/* Flush FIFO */
	RcvrFifo.Wp = 0;
	RcvrFifo.Ctr = 0;
	delay_ms(30);						/* 30msec */
}