?login_element?

Subversion Repositories NedoOS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.     module Uart
  2. ; This driver works with 16c550 uart that's support AFE
  3. ;AT+UART_CUR=38400,8,1,0,0
  4. ;AT+CWMODE_DEF=1
  5. ;AT+CWJAP_DEF="Kulich","password"
  6. ;
  7.  
  8. ; Internal port constants
  9. RBR_THR equ #F8
  10. IER             equ     #F9
  11. IIR_FCR equ     #FA
  12. LCR             equ     #FB
  13. MCR             equ     #FC
  14. LSR             equ     #FD
  15. MSR             equ     #FE
  16. SR              equ     #FF
  17.  
  18.     macro outp port, value
  19.         di
  20.         ld b, port
  21.         ld c, #EF
  22.     ld a, value
  23.         out (port), a
  24.         ei
  25.         endm
  26.  
  27.  
  28.  
  29. init:
  30.         push bc
  31.     outp MCR,     #0d   // Assert RTS
  32.     outp IIR_FCR, #87   // Enable fifo 8 level, and clear it
  33.     outp LCR,     #83   // 8n1, DLAB=1
  34.     outp RBR_THR, #03   // 115200 (divider 1-115200, 3 - 38400)
  35.     outp IER,     #00   // (divider 0). Divider is 16 bit, so we get (#0002 divider)
  36.     outp LCR,     #03   // 8n1, DLAB=0
  37.     outp IER,     #00   // Disable int
  38.     outp MCR,     #2f   // Enable AFE
  39.         pop bc
  40.     ret
  41.    
  42. ; Flag C <- Data available
  43. isAvailable:
  44.         ld bc, #FDEF
  45.         in a, (c)
  46.     rrca
  47.     ret
  48.  
  49. ; Blocking read
  50. ; A <- Byte
  51. read:
  52.         di
  53.     ld bc, #FDEF
  54.         in a, (c)
  55.     rrca
  56.     jr nc, read
  57.     ld bc, #F8EF
  58.         in a, (c)
  59.         ei     
  60.     ret
  61.  
  62. ; A -> byte to send
  63.  
  64. write:
  65.         di
  66.     push af
  67. .wait
  68.     ld bc, #FDEF
  69.         in a, (c)
  70.     and #20
  71.     jr z, .wait
  72.     pop af
  73.  
  74.         ld bc,#F8EF
  75.         out (c),a      
  76.         ei
  77.     ret
  78.  
  79.     endmodule