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

📄 sw-uart-asm.s

📁 AVR Devolpment Board
💻 S
字号:

/* Name: sw-uart.S * Project: AVR USB driver for CDC interface on USB1.1 * Author: Osamu Tamura * Creation Date: 2006-05-12 * Tabsize: 4 * Copyright: (c) 2006 by Recursion Co., Ltd. * License: Proprietary, free under certain conditions. See Documentation. *//*General Description:    This module implements the assembler part of the USB-CDC driver.Note: This module violates the rule that interrupts must not be disabled forlonger than a couple of instructions (see usbdrv.h). Running UART interrupthandlers with sei as the first instruction is not possible because it wouldrecurse immediately (the cause of the interrupt has not been removed). Ifwe collect the data and then call sei(), we win little. We therefore decideto violate the rule. The effect on USB operation is, that packages may belost. This is equivalent to a package being dropped due to a CRC error. Thehost will therefore retry the transfer after a timeout. It is therefore verylikely that no effect is seen at the application layer.*/
#include "iarcompat.h"#ifndef __IAR_SYSTEMS_ASM__    /* configs for io.h */#   define __SFR_OFFSET 0#   define _VECTOR(N)   __vector_ ## N   /* io.h does not define this for asm */#   include <avr/io.h> /* for CPU I/O register definitions and vectors */#endif  /* __IAR_SYSTEMS_ASM__ */#include "usbdrv.h" /* for common defs */#include "uart.h"
#if !UART_CFG_HAVE_USART
/* register names */#define x1      r16#define x2      r17/* Some assembler dependent definitions and declarations: */#ifdef __IAR_SYSTEMS_ASM__#   define nop2     rjmp    $+2 /* jump to next instruction */#   define XL       r26#   define XH       r27#   define YL       r28#   define YH       r29#   define ZL       r30#   define ZH       r31#   define lo8(x)   LOW(x)#   define hi8(x)   ((x)>>8)    /* not HIGH to allow XLINK to make a proper range check */    extern  rx_data
#   ifndef IVT_BASE_ADDRESS#       define IVT_BASE_ADDRESS 0#   endif    ASEG    ORG     PCINT0_vect + IVT_BASE_ADDRESS    rjmp    SIG_PIN_CHANGE    ORG     TIM1_COMPA_vect + IVT_BASE_ADDRESS    rjmp    SIG_OUTPUT_COMPARE1A    ORG     TIM0_COMPA_vect + IVT_BASE_ADDRESS    rjmp    SIG_OUTPUT_COMPARE0A    RSEG    CODE#else /* __IAR_SYSTEMS_ASM__ */    .text
    .global SIG_PIN_CHANGE    .type   SIG_PIN_CHANGE, @function    .global SIG_OUTPUT_COMPARE1A    .type   SIG_OUTPUT_COMPARE1A, @function    .global SIG_OUTPUT_COMPARE0A    .type   SIG_OUTPUT_COMPARE0A, @function
#endif /* __IAR_SYSTEMS_ASM__ */
; ######################## RS-232C functions ########################
SIG_PIN_CHANGE:    out     GPIOR0, x1      ;1

    in      x1, DT1A        ;1  1st bit sampling delay
    out     TCNT1, x1       ;1
    ldi     x1, 9           ;1  set rx_bitcounter = 9
    out     OCR1C, x1       ;1
    ldi     x1, 7           ;1  start timer
    out     TCCR1, x1       ;1

    ldi     x1, (1<<USB_INTR_ENABLE_BIT)  ;1
    out     USB_INTR_ENABLE, x1  ;1   stop pin change interrupt

    in      x1, GPIOR0      ;1
    reti                    ;4   {14,14}


SIG_OUTPUT_COMPARE1A:    out     GPIOR0, x1      ;1
    in      x1, SREG        ;1    out     GPIOR1, x1      ;1

    in      x1, OCR1C       ;1  rx_bitcounter--
    dec     x1              ;1
    out     OCR1C, x1       ;1
    breq    tm1_stopbit     ;1/2

    in      x1, OCR1B       ;1
    lsr     x1              ;1  data shift
#if UART_CFG_INVERT
    sbis    UART_PIN, UART_CFG_RXD         ;1/2
#else
    sbic    UART_PIN, UART_CFG_RXD         ;1/2
#endif
    ori     x1, 0x80        ;1
    out     OCR1B, x1       ;1

    out     GPIOR2, x2      ;1
    in      x1, TCNT1       ;1
    in      x2, OCR1A       ;1
    sub     x1, x2          ;1
    out     TCNT1, x1       ;1

    in      x2, GPIOR2      ;1
    in      x1, GPIOR1      ;1
    out     SREG, x1        ;1    in      x1, GPIOR0      ;1
    reti                    ;4

tm1_stopbit:
    out     TCCR1, x1       ;1  stop timer1

    out     DT1B, x1        ;1  rx_data ready flag
    in      x1, OCR1B       ;1
    out     EEDR, x1        ;1  rx_data

    ldi     x1, (1<<PCIF)   ;1
    out     GIFR, x1        ;1
    ldi     x1, (1<<USB_INTR_ENABLE_BIT)|(1<<PCIE)  ;1
    out     USB_INTR_ENABLE, x1  ;1   enable pin change interrupt

    in      x1, GPIOR1      ;1
    out     SREG, x1        ;1    in      x1, GPIOR0      ;1
    reti                    ;4   {23,25}


SIG_OUTPUT_COMPARE0A:    out     GPIOR0, x1      ;1
    in      x1, SREG        ;1    out     GPIOR1, x1      ;1

    in      x1, EEARL       ;1  tx_bitcounter--
    dec     x1              ;1
    breq    tm0_end         ;1/2

    out     EEARL, x1       ;1

    in      x1, OCR0B       ;1
    sec                     ;1
    ror     x1              ;1
    out     OCR0B, x1       ;1
    brcs    tm0_stopbit     ;1/2

#if UART_CFG_INVERT
    sbi     UART_CFG_PORT, UART_CFG_TXD        ;2
#else
    cbi     UART_CFG_PORT, UART_CFG_TXD        ;2
#endif
    in      x1, GPIOR1      ;1
    out     SREG, x1        ;1    in      x1, GPIOR0      ;1
    reti                    ;4

tm0_stopbit:
#if UART_CFG_INVERT
    cbi     UART_CFG_PORT, UART_CFG_TXD        ;2
#else
    sbi     UART_CFG_PORT, UART_CFG_TXD        ;2
#endif
    in      x1, GPIOR1      ;1
    out     SREG, x1        ;1    in      x1, GPIOR0      ;1
    reti                    ;4

tm0_end:
    out     TCCR0B, x1      ;1  stop timer0

    in      x1, GPIOR1      ;1
    out     SREG, x1        ;1    in      x1, GPIOR0      ;1
    reti                    ;4   {15,22}

#endif		/* UART_CFG_HAVE_USART	*/

⌨️ 快捷键说明

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