86Duino demo: reading ADC0

git-svn-id: svn://kolibrios.org@6878 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2017-03-17 19:30:51 +00:00
parent ce35591444
commit bfd672d9a4
2 changed files with 112 additions and 36 deletions

View File

@ -1,12 +1,10 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2015-2017. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;driver sceletone
format PE DLL native 0.05 format PE DLL native 0.05
entry START entry START
@ -23,11 +21,15 @@ entry START
section '.flat' code readable writable executable section '.flat' code readable writable executable
include 'proc32.inc' include '../proc32.inc'
include 'struct.inc' include '../struct.inc'
include 'macros.inc' include '../macros.inc'
include 'peimport.inc' include '../peimport.inc'
include 'fdo.inc' include '../fdo.inc'
GPIO_PORT_CONFIG_ADDR = 0xF100
GPIO_DATA_ADDR = 0xF200
ADC_ADDR = 0xFE00
proc START c, state:dword, cmdline:dword proc START c, state:dword, cmdline:dword
@ -43,19 +45,59 @@ proc START c, state:dword, cmdline:dword
jz .fail jz .fail
; Set crossbar base address register in southbridge ; Set crossbar base address register in southbridge
invoke PciWrite16, [bus], [dev], 64h, 0x0A00 or 1 invoke PciWrite16, [bus], [dev], 0x64, 0x0A00 or 1
; Set GPIO base address register in southbridge ; Set GPIO base address register in southbridge
invoke PciWrite16, [bus], [dev], 62h, 0xF100 or 1 invoke PciWrite16, [bus], [dev], 0x62, GPIO_PORT_CONFIG_ADDR or 1
DEBUGF 1,"Setting up ADC\n"
; Enable ADC
invoke PciRead32, [bus], [dev], 0xBC
and eax, not (1 shl 28)
invoke PciWrite32, [bus], [dev], 0xBC, eax
DEBUGF 1,"1\n"
; Set ADC base address
mov ebx, [dev]
inc ebx
invoke PciRead16, [bus], ebx, 0xDE
or ax, 0x02
invoke PciWrite16, [bus], ebx, 0xDE, eax
invoke PciWrite32, [bus], ebx, 0xE0, 0x00500000 or ADC_ADDR
DEBUGF 1,"2\n"
; set up ADC
mov dx, ADC_ADDR + 1
xor al, al
out dx, al
DEBUGF 1,"3\n"
; Empty FIFO
@@:
mov dx, ADC_ADDR + 2 ; Status register
in al, dx
test al, 0x01 ; FIFO ready
jz @f
mov dx, ADC_ADDR + 4
in ax, dx
jmp @r
@@:
DEBUGF 1,"4\n"
; Enable GPIO0-9 ; Enable GPIO0-9
mov dx, 0xf100 mov dx, GPIO_PORT_CONFIG_ADDR + 0 ; General-Purpose I/O Data & Direction Decode Enable
mov eax, 0x000001ff mov eax, 0x000001ff
out dx, eax out dx, eax
mov ecx, 10 mov ecx, 10 ; 10 GPIO ports total
mov dx, 0xf104 mov dx, GPIO_PORT_CONFIG_ADDR + 4 ; General-Purpose I/O Port0 Data & Direction Decode Address
mov ax, 0xf200 mov ax, GPIO_DATA_ADDR
.gpio_init: .gpio_init:
; Set GPIO data port base address ; Set GPIO data port base address
out dx, ax out dx, ax
@ -71,18 +113,13 @@ proc START c, state:dword, cmdline:dword
; Set GPIO0 pin 0 as output ; Set GPIO0 pin 0 as output
mov al, 0x01 mov al, 0x01
mov dx, 0xf202 mov dx, GPIO_DATA_ADDR + 0*4 + 2
out dx, al
; Set GPIO4 pin 0 as output
mov al, 0x01
mov dx, 0xf212
out dx, al out dx, al
invoke RegService, my_service, service_proc invoke RegService, my_service, service_proc
ret ret
.fail: .fail:
.exit: .exit:
xor eax, eax xor eax, eax
ret ret
endp endp
@ -100,23 +137,49 @@ proc service_proc stdcall, ioctl:dword
mov dword [eax], API_VERSION mov dword [eax], API_VERSION
xor eax, eax xor eax, eax
ret ret
@@: @@:
cmp eax, 1 ; read GPIO P0 cmp eax, 1 ; read GPIO P0
jne @f jne .no_gpioread
mov dx, 0xf200 mov dx, GPIO_DATA_ADDR + 0x00
in al, dx in al, dx
ret ret
@@: .no_gpioread:
cmp eax, 2 ; write GPIO P0 cmp eax, 2 ; write GPIO P0
jne @f jne .no_gpiowrite
mov eax, [ebx + IOCTL.input] mov eax, [ebx + IOCTL.input]
mov dx, 0xf200 mov dx, GPIO_DATA_ADDR + 0x00
out dx, al out dx, al
xor eax, eax xor eax, eax
ret ret
@@: .no_gpiowrite:
.fail: cmp eax, 3 ; read ADC channel 0
jne .no_adcread
mov dx, ADC_ADDR + 1
mov al, 1 shl 3 ; Power down ADC
out dx, al
mov dx, ADC_ADDR + 0 ; AUX channel select register
mov al, 1 shl 0 ; Enable AUX0 scan
out dx, al
mov dx, ADC_ADDR + 1
mov al, 1 shl 0 ; Single shot, no interrupts, start
out dx, al
mov dx, ADC_ADDR + 2
@@:
in al, dx
test al, 1 shl 0 ; data ready?
jz @r
mov dx, ADC_ADDR + 4
in ax, dx ; read the data and return to user call
DEBUGF 1, "ADC read: 0x%x\n", eax:4
ret
.no_adcread:
.fail:
or eax, -1 or eax, -1
ret ret
endp endp
@ -126,14 +189,14 @@ proc detect
push ebx push ebx
invoke GetPCIList invoke GetPCIList
mov ebx, eax mov ebx, eax
.next_dev: .next_dev:
mov eax, [eax+PCIDEV.fd] mov eax, [eax+PCIDEV.fd]
cmp eax, ebx cmp eax, ebx
jz .err jz .err
mov edx, [eax+PCIDEV.vendor_device_id] mov edx, [eax+PCIDEV.vendor_device_id]
mov esi, devices mov esi, devices
@@: @@:
cmp dword [esi], 0 cmp dword [esi], 0
jz .next_dev jz .next_dev
cmp edx, [esi] cmp edx, [esi]
@ -142,7 +205,7 @@ proc detect
add esi, STRIDE add esi, STRIDE
jmp @B jmp @B
.found: .found:
movzx ebx, [eax+PCIDEV.devfn] movzx ebx, [eax+PCIDEV.devfn]
mov [dev], ebx mov [dev], ebx
movzx ebx, [eax+PCIDEV.bus] movzx ebx, [eax+PCIDEV.bus]
@ -151,7 +214,7 @@ proc detect
inc eax inc eax
pop ebx pop ebx
ret ret
.err: .err:
DEBUGF 1,"Could not find vortex86EX south bridge!\n" DEBUGF 1,"Could not find vortex86EX south bridge!\n"
xor eax, eax xor eax, eax
pop ebx pop ebx

View File

@ -77,7 +77,13 @@ key: ; Keypress event handler
and al, not 1 ; Clear bit 0 and al, not 1 ; Clear bit 0
call write_gpio0 call write_gpio0
jmp event_wait jmp event_wait
@@:
cmp ah, 'e'
jne @f
call read_adc0
mov ecx, eax
mcall 47, 0x00040100,,25 shl 16 + 25, 0x40000000, 0x00ffffff ; 4 digits hex number in ecx
jmp event_wait
@@: @@:
jmp event_wait ; Just read the key, ignore it and jump to event_wait. jmp event_wait ; Just read the key, ignore it and jump to event_wait.
@ -150,6 +156,12 @@ write_gpio0:
mcall 68, 17, IOCTL mcall 68, 17, IOCTL
ret ret
; Read ADC0
read_adc0:
mov [IOCTL.io_code], 3
mcall 68, 17, IOCTL
ret
; ********************************************* ; *********************************************
; ************* DATA AREA ***************** ; ************* DATA AREA *****************
; ********************************************* ; *********************************************
@ -159,7 +171,8 @@ write_gpio0:
text db "This is an 86DUINO GPIO demo program " text db "This is an 86DUINO GPIO demo program "
db " " db " "
db "press q/w to toggle GPIO 0 pin 0 ", 0 db "press q/w to toggle GPIO 0 pin 0 "
db "or e to read ADC0 channel ", 0
title db "86Duino Example application", 0 title db "86Duino Example application", 0