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

📄 usb_to_232.lss

📁 采用atmel公司的mega8芯片设计的USB cdc类
💻 LSS
📖 第 1 页 / 共 5 页
字号:
    /*    usb -> rs232c:  transmit char    */
    usbDisableAllRequests();
    for( ; len; len-- ) 
	{
        uartTxBufAppend(*data++);
 1ea:	11 96       	adiw	r26, 0x01	; 1

void usbFunctionWriteOut( uchar *data, uchar len )
{
    /*    usb -> rs232c:  transmit char    */
    usbDisableAllRequests();
    for( ; len; len-- ) 
 1ec:	61 50       	subi	r22, 0x01	; 1
 1ee:	66 23       	and	r22, r22
 1f0:	59 f7       	brne	.-42     	; 0x1c8 <usbFunctionWriteOut+0xa>
	{
        uartTxBufAppend(*data++);
    }
}
 1f2:	08 95       	ret

000001f4 <usbcdc_init>:
static void hardwareInit(void)
{
uchar    i, j;

    /* activate pull-ups except on USB lines */
    USB_CFG_IOPORT   = (uchar)~((1<<USB_CFG_DMINUS_BIT)|(1<<USB_CFG_DPLUS_BIT));
 1f4:	8c ef       	ldi	r24, 0xFC	; 252
 1f6:	88 bb       	out	0x18, r24	; 24
    /* all pins input except USB (-> USB reset) */
#ifdef USB_CFG_PULLUP_IOPORT    /* use usbDeviceConnect()/usbDeviceDisconnect() if available */
    USBDDR    = 0;    /* we do RESET by deactivating pullup */
    usbDeviceDisconnect();
#else
    USBDDR    = (1<<USB_CFG_DMINUS_BIT)|(1<<USB_CFG_DPLUS_BIT);
 1f8:	83 e0       	ldi	r24, 0x03	; 3
 1fa:	87 bb       	out	0x17, r24	; 23
        while(--i);      /* delay >10ms for USB reset */
    }
#ifdef USB_CFG_PULLUP_IOPORT
    usbDeviceConnect();
#else
    USBDDR    = 0;      /*  remove USB reset condition */
 1fc:	17 ba       	out	0x17, r1	; 23
/* default: 9600 bps, 8n1 */
#endif

static inline void resetUart(void)
{
    irptr    = 0;
 1fe:	10 92 ec 00 	sts	0x00EC, r1
    iwptr    = 0;
 202:	10 92 a9 00 	sts	0x00A9, r1
    urptr    = 0;
 206:	10 92 ea 00 	sts	0x00EA, r1
    uwptr    = 0;
 20a:	10 92 eb 00 	sts	0x00EB, r1
}

void usbcdc_init()
{
    hardwareInit();
    usbInit();
 20e:	58 d2       	rcall	.+1200   	; 0x6c0 <usbInit>
    sendEmptyFrame = 1;
 210:	81 e0       	ldi	r24, 0x01	; 1
 212:	80 93 88 00 	sts	0x0088, r24
}
 216:	08 95       	ret

00000218 <usbcdc_poll>:
#endif
    resetUart();
}

void usbcdc_poll()
{
 218:	1f 93       	push	r17
        uchar bytesRead, *data;

        usbPoll();
 21a:	b2 d2       	rcall	.+1380   	; 0x780 <usbPoll>

        /*    usb -> rs232c:  ready to receive?    */
        if( usbAllRequestsAreDisabled() && uartTxBytesFree()>=8 )
 21c:	80 91 16 01 	lds	r24, 0x0116
 220:	87 ff       	sbrs	r24, 7
 222:	0b c0       	rjmp	.+22     	; 0x23a <usbcdc_poll+0x22>
/* The following function returns the amount of bytes available in the TX
 * buffer before we have an overflow.
 */
static inline uchar uartTxBytesFree(void)
{
    return (irptr - uwptr - 1) & TX_MASK;
 224:	80 91 ec 00 	lds	r24, 0x00EC
 228:	90 91 eb 00 	lds	r25, 0x00EB
        uchar bytesRead, *data;

        usbPoll();

        /*    usb -> rs232c:  ready to receive?    */
        if( usbAllRequestsAreDisabled() && uartTxBytesFree()>=8 )
 22c:	81 50       	subi	r24, 0x01	; 1
 22e:	89 1b       	sub	r24, r25
 230:	8f 73       	andi	r24, 0x3F	; 63
 232:	88 30       	cpi	r24, 0x08	; 8
 234:	10 f0       	brcs	.+4      	; 0x23a <usbcdc_poll+0x22>
		{
            usbEnableAllRequests();
 236:	10 92 16 01 	sts	0x0116, r1
        }
        /*    rs232c -> usb:  transmit char        */
        if( usbInterruptIsReady() ) 
 23a:	80 91 69 00 	lds	r24, 0x0069
 23e:	8f 3f       	cpi	r24, 0xFF	; 255
 240:	71 f5       	brne	.+92     	; 0x29e <usbcdc_poll+0x86>
/* The following function sets *ptr to the current read position and returns
 * the number of bytes which can currently be read from this read position.
 */
static inline uchar uartRxBytesAvailable(uchar **ptr)
{
    *ptr = &rx_buf[urptr];
 242:	20 91 ea 00 	lds	r18, 0x00EA
    if(iwptr >= urptr){
 246:	90 91 a9 00 	lds	r25, 0x00A9
 24a:	80 91 ea 00 	lds	r24, 0x00EA
 24e:	98 17       	cp	r25, r24
 250:	28 f0       	brcs	.+10     	; 0x25c <usbcdc_poll+0x44>
        return iwptr - urptr;
 252:	10 91 a9 00 	lds	r17, 0x00A9
 256:	80 91 ea 00 	lds	r24, 0x00EA
 25a:	03 c0       	rjmp	.+6      	; 0x262 <usbcdc_poll+0x4a>
    }else{  /* buffer end is between read and write pointer, return continuous range */
        return RX_SIZE - urptr;
 25c:	80 91 ea 00 	lds	r24, 0x00EA
 260:	10 e2       	ldi	r17, 0x20	; 32
 262:	18 1b       	sub	r17, r24
            /* We limit the transaction size to 7 instead of 8 to indicate that
             * this is the last transaction in the transfer. Otherwise the host
             * would try to read more transactions which we would answer with NAK
             * instead of a terminating zero sized block.
             */
            if(bytesRead >= 8) 
 264:	18 30       	cpi	r17, 0x08	; 8
 266:	10 f0       	brcs	.+4      	; 0x26c <usbcdc_poll+0x54>
 268:	18 e0       	ldi	r17, 0x08	; 8
 26a:	02 c0       	rjmp	.+4      	; 0x270 <usbcdc_poll+0x58>
			{
                bytesRead = 8;
            }
	    	if (bytesRead > 0) 
 26c:	11 23       	and	r17, r17
 26e:	69 f0       	breq	.+26     	; 0x28a <usbcdc_poll+0x72>
			{
            	usbSetInterrupt(data, bytesRead);
 270:	82 2f       	mov	r24, r18
 272:	90 e0       	ldi	r25, 0x00	; 0
 274:	87 57       	subi	r24, 0x77	; 119
 276:	9f 4f       	sbci	r25, 0xFF	; 255
 278:	61 2f       	mov	r22, r17
 27a:	59 d2       	rcall	.+1202   	; 0x72e <usbSetInterrupt>
/* The following function must be called after uartRxBytesAvailable() to
 * remove the bytes from the receiver buffer.
 */
static inline void  uartRxDidReadBytes(uchar numBytes)
{
    urptr = (urptr + numBytes) & RX_MASK;
 27c:	80 91 ea 00 	lds	r24, 0x00EA
 280:	81 0f       	add	r24, r17
 282:	8f 71       	andi	r24, 0x1F	; 31
 284:	80 93 ea 00 	sts	0x00EA, r24
 288:	08 c0       	rjmp	.+16     	; 0x29a <usbcdc_poll+0x82>
	    	if (bytesRead > 0) 
			{
            	usbSetInterrupt(data, bytesRead);
            	uartRxDidReadBytes(bytesRead);
            } 
			else if (sendEmptyFrame) 
 28a:	80 91 88 00 	lds	r24, 0x0088
 28e:	88 23       	and	r24, r24
 290:	21 f0       	breq	.+8      	; 0x29a <usbcdc_poll+0x82>
			{
            	usbSetInterrupt(0, 0);
 292:	80 e0       	ldi	r24, 0x00	; 0
 294:	90 e0       	ldi	r25, 0x00	; 0
 296:	60 e0       	ldi	r22, 0x00	; 0
 298:	4a d2       	rcall	.+1172   	; 0x72e <usbSetInterrupt>
	    	}
	    	sendEmptyFrame = bytesRead;
 29a:	10 93 88 00 	sts	0x0088, r17
                usbSetInterrupt3(serialStateData, 2);
            }
            intr3Status--;
        }
#endif
}
 29e:	1f 91       	pop	r17
 2a0:	08 95       	ret

000002a2 <usbcdc_getc>:
	rx_buf[iwptr] = data;
	iwptr = next;
}

char usbcdc_getc(void) 
{
 2a2:	1f 93       	push	r17
	char ch;
	uint8_t next = (irptr+1) & TX_MASK;
 2a4:	10 91 ec 00 	lds	r17, 0x00EC
 2a8:	02 c0       	rjmp	.+4      	; 0x2ae <usbcdc_getc+0xc>
	
	while (irptr == uwptr) 
	{
		wdt_reset();
 2aa:	a8 95       	wdr
		usbcdc_poll();
 2ac:	b5 df       	rcall	.-150    	; 0x218 <usbcdc_poll>
char usbcdc_getc(void) 
{
	char ch;
	uint8_t next = (irptr+1) & TX_MASK;
	
	while (irptr == uwptr) 
 2ae:	90 91 ec 00 	lds	r25, 0x00EC
 2b2:	80 91 eb 00 	lds	r24, 0x00EB
 2b6:	98 17       	cp	r25, r24
 2b8:	c1 f3       	breq	.-16     	; 0x2aa <usbcdc_getc+0x8>
	{
		wdt_reset();
		usbcdc_poll();
	}
	ch = tx_buf[irptr];
 2ba:	e0 91 ec 00 	lds	r30, 0x00EC
 2be:	f0 e0       	ldi	r31, 0x00	; 0
 2c0:	e6 55       	subi	r30, 0x56	; 86
 2c2:	ff 4f       	sbci	r31, 0xFF	; 255
 2c4:	80 81       	ld	r24, Z
}

char usbcdc_getc(void) 
{
	char ch;
	uint8_t next = (irptr+1) & TX_MASK;
 2c6:	1f 5f       	subi	r17, 0xFF	; 255
 2c8:	1f 73       	andi	r17, 0x3F	; 63
	{
		wdt_reset();
		usbcdc_poll();
	}
	ch = tx_buf[irptr];
	irptr = next;
 2ca:	10 93 ec 00 	sts	0x00EC, r17
	return ch;
}
 2ce:	1f 91       	pop	r17
 2d0:	08 95       	ret

000002d2 <usbcdc_putc>:
        }
#endif
}

void usbcdc_putc(char data) 
{
 2d2:	0f 93       	push	r16
 2d4:	1f 93       	push	r17
 2d6:	08 2f       	mov	r16, r24
	uint8_t next = (iwptr+1) & RX_MASK;
 2d8:	10 91 a9 00 	lds	r17, 0x00A9
 2dc:	1f 5f       	subi	r17, 0xFF	; 255
 2de:	1f 71       	andi	r17, 0x1F	; 31
 2e0:	01 c0       	rjmp	.+2      	; 0x2e4 <usbcdc_putc+0x12>
	while (next == urptr) 
	{
		usbcdc_poll();
 2e2:	9a df       	rcall	.-204    	; 0x218 <usbcdc_poll>
}

void usbcdc_putc(char data) 
{
	uint8_t next = (iwptr+1) & RX_MASK;
	while (next == urptr) 
 2e4:	80 91 ea 00 	lds	r24, 0x00EA
 2e8:	18 17       	cp	r17, r24
 2ea:	d9 f3       	breq	.-10     	; 0x2e2 <usbcdc_putc+0x10>
	{
		usbcdc_poll();
	}
	rx_buf[iwptr] = data;
 2ec:	e0 91 a9 00 	lds	r30, 0x00A9
 2f0:	f0 e0       	ldi	r31, 0x00	; 0
 2f2:	e7 57       	subi	r30, 0x77	; 119
 2f4:	ff 4f       	sbci	r31, 0xFF	; 255
 2f6:	00 83       	st	Z, r16
	iwptr = next;
 2f8:	10 93 a9 00 	sts	0x00A9, r17
}
 2fc:	1f 91       	pop	r17
 2fe:	0f 91       	pop	r16
 300:	08 95       	ret

00000302 <usbFunctionWrite>:
    baud.bytes[2] = data[2];
    baud.bytes[3] = data[3];

    //resetUart();
#else
    usbTxPacketCnt1 = 1;    /* enforce DATA0 token for next transfer */
 302:	21 e0       	ldi	r18, 0x01	; 1
 304:	20 93 15 01 	sts	0x0115, r18
    //iwptr = urptr;
    //irptr = uwptr;
    sendEmptyFrame = 1;
 308:	20 93 88 00 	sts	0x0088, r18
    memcpy(modeBuffer, data, 7);
 30c:	a0 e6       	ldi	r26, 0x60	; 96
 30e:	b0 e0       	ldi	r27, 0x00	; 0
 310:	fc 01       	movw	r30, r24
 312:	87 e0       	ldi	r24, 0x07	; 7
 314:	01 90       	ld	r0, Z+
 316:	0d 92       	st	X+, r0
 318:	81 50       	subi	r24, 0x01	; 1
 31a:	e1 f7       	brne	.-8      	; 0x314 <usbFunctionWrite+0x12>
#endif

    return 1;
}
 31c:	81 e0       	ldi	r24, 0x01	; 1
 31e:	08 95       	ret

00000320 <usbFunctionRead>:
    data[3] = baud.bytes[3];
    data[4] = stopbit;
    data[5] = parity;
    data[6] = databit;
#else
    memcpy(data, modeBuffer, 7);
 320:	dc 01       	movw	r26, r24
 322:	e0 e6       	ldi	r30, 0x60	; 96
 324:	f0 e0       	ldi	r31, 0x00	; 0
 326:	87 e0       	ldi	r24, 0x07	; 7
 328:	01 90       	ld	r0, Z+
 32a:	0d 92       	st	X+, r0
 32c:	81 50       	subi	r24, 0x01	; 1
 32e:	e1 f7       	brne	.-8      	; 0x328 <usbFunctionRead+0x8>
#endif

    return 7;
}
 330:	87 e0       	ldi	r24, 0x07	; 7
 332:	08 95       	ret

00000334 <__vector_1>:
 334:	0f 93       	push	r16
 336:	0f b7       	in	r16, 0x3f	; 63
 338:	0f 93       	push	r16

0000033a <waitForJ>:
 33a:	b0 9b       	sbis	0x16, 0	; 22
 33c:	fe cf       	rjmp	.-4      	; 0x33a <waitForJ>
 33e:	b0 9b       	sbis	0x16, 0	; 22
 340:	06 c0       	rjmp	.+12     	; 0x34e <foundK>
 342:	b0 9b       	sbis	0x16, 0	; 22
 344:	04 c0       	rjmp	.+8      	; 0x34e <foundK>
 346:	b0 9b       	sbis	0x16, 0	; 22
 348:	02 c0       	rjmp	.+4      	; 0x34e <foundK>
 34a:	00 00       	nop
 34c:	00 c0       	rjmp	.+0      	; 0x34e <foundK>

0000034e <foundK>:
 34e:	1f 93       	push	r17
 350:	3f 93       	push	r19

⌨️ 快捷键说明

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