From a2738af0062bc71054e765477a0135f2fa4edfa1 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Wed, 20 May 2015 13:58:39 +0000 Subject: [PATCH] 86duino One GPIO demo. git-svn-id: svn://kolibrios.org@5558 a494cfbc-eb01-0410-851d-a64ba20cac60 --- drivers/gpio/86duino-gpio.asm | 179 ++++++++++++++++++++++++++++++++++ programs/demos/gpio/gpio.asm | 176 +++++++++++++++++++++++++++++++++ 2 files changed, 355 insertions(+) create mode 100644 drivers/gpio/86duino-gpio.asm create mode 100644 programs/demos/gpio/gpio.asm diff --git a/drivers/gpio/86duino-gpio.asm b/drivers/gpio/86duino-gpio.asm new file mode 100644 index 0000000000..0f8bdf6678 --- /dev/null +++ b/drivers/gpio/86duino-gpio.asm @@ -0,0 +1,179 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; +;; Distributed under terms of the GNU General Public License ;; +;; ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;driver sceletone + +format PE DLL native 0.05 +entry START + + DEBUG = 1 + __DEBUG__ = 1 + __DEBUG_LEVEL__ = 1 ; 1 = verbose, 2 = errors only + + + API_VERSION = 0 ;debug + + STRIDE = 4 ;size of row in devices table + + SRV_GETVERSION = 0 + +section '.flat' code readable writable executable + +include 'proc32.inc' +include 'struct.inc' +include 'macros.inc' +include 'peimport.inc' +include 'fdo.inc' + +proc START c, state:dword, cmdline:dword + + cmp [state], 1 + jne .exit +.entry: + + push esi + DEBUGF 1,"Loading vortex86EX GPIO driver\n" + call detect + pop esi + test eax, eax + jz .fail + +; Set crossbar base address register in southbridge + invoke PciWrite16, [bus], [dev], 64h, 0x0A00 or 1 + +; Set GPIO base address register in southbridge + invoke PciWrite16, [bus], [dev], 62h, 0xF100 or 1 + +; Enable GPIO0-9 + mov dx, 0xf100 + mov eax, 0x000001ff + out dx, eax + + mov ecx, 10 + mov dx, 0xf104 + mov ax, 0xf200 + .gpio_init: +; Set GPIO data port base address + out dx, ax + add ax, 2 + add dx, 2 +; Set GPIO direction base address + out dx, ax + add ax, 2 + add dx, 2 +; loop + dec ecx + jnz .gpio_init + +; Set GPIO0 pin 0 as output + mov al, 0x01 + mov dx, 0xf202 + out dx, al + +; Set GPIO4 pin 0 as output + mov al, 0x01 + mov dx, 0xf212 + out dx, al + + invoke RegService, my_service, service_proc + ret +.fail: +.exit: + xor eax, eax + ret +endp + +proc service_proc stdcall, ioctl:dword + + mov ebx, [ioctl] + mov eax, [ebx+IOCTL.io_code] + cmp eax, SRV_GETVERSION + jne @F + + mov eax, [ebx+IOCTL.output] + cmp [ebx+IOCTL.out_size], 4 + jne .fail + mov dword [eax], API_VERSION + xor eax, eax + ret +@@: + cmp eax, 1 ; read GPIO P0 + jne @f + mov dx, 0xf200 + in al, dx + ret +@@: + cmp eax, 2 ; write GPIO P0 + jne @f + + mov eax, [ebx + IOCTL.input] + mov dx, 0xf200 + out dx, al + xor eax, eax + ret +@@: +.fail: + or eax, -1 + ret +endp + + +proc detect + push ebx + invoke GetPCIList + mov ebx, eax +.next_dev: + mov eax, [eax+PCIDEV.fd] + cmp eax, ebx + jz .err + mov edx, [eax+PCIDEV.vendor_device_id] + + mov esi, devices +@@: + cmp dword [esi], 0 + jz .next_dev + cmp edx, [esi] + jz .found + + add esi, STRIDE + jmp @B + +.found: + movzx ebx, [eax+PCIDEV.devfn] + mov [dev], ebx + movzx ebx, [eax+PCIDEV.bus] + mov [bus], ebx + xor eax, eax + inc eax + pop ebx + ret +.err: + DEBUGF 1,"Could not find vortex86EX south bridge!\n" + xor eax, eax + pop ebx + ret +endp + +DEVICE_ID = 6011h +VENDOR_ID = 17F3h + +;all initialized data place here + +align 4 +devices dd (DEVICE_ID shl 16)+VENDOR_ID + dd 0 ;terminator + +my_service db '86DUINO-GPIO',0 ;max 16 chars include zero + +include_debug_strings ; All data wich FDO uses will be included here + +dev dd ? +bus dd ? + +align 4 +data fixups +end data diff --git a/programs/demos/gpio/gpio.asm b/programs/demos/gpio/gpio.asm new file mode 100644 index 0000000000..e1a060936d --- /dev/null +++ b/programs/demos/gpio/gpio.asm @@ -0,0 +1,176 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; +; 86DUINO GPIO DEMO APPLICATION ; +; ; +; Compile with FASM ; +; ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +format binary as "" ; Binary file format without extension + +use32 ; Tell compiler to use 32 bit instructions + +org 0x0 ; the base address of code, always 0x0 + +; The header + +db 'MENUET01' +dd 0x01 +dd START +dd I_END +dd 0x100000 +dd 0x7fff0 +dd 0, 0 + +; The code area + +include '../../macros.inc' + +START: ; start of execution + + mcall 68, 16, drv_name ; load the driver + mov [IOCTL.handle], eax + + call draw_window ; draw the window + +; After the window is drawn, it's practical to have the main loop. +; Events are distributed from here. + +event_wait: + mov eax, 10 ; function 10 : wait until event + mcall ; event type is returned in eax + + cmp eax, 1 ; Event redraw request ? + je red ; Expl.: there has been activity on screen and + ; parts of the applications has to be redrawn. + + cmp eax, 2 ; Event key in buffer ? + je key ; Expl.: User has pressed a key while the + ; app is at the top of the window stack. + + cmp eax, 3 ; Event button in buffer ? + je button ; Expl.: User has pressed one of the + ; applications buttons. + + jmp event_wait + +; The next section reads the event and processes data. + +red: ; Redraw event handler + call draw_window ; We call the window_draw function and + jmp event_wait ; jump back to event_wait + +key: ; Keypress event handler + mov eax, 2 ; The key is returned in ah. The key must be + mcall ; read and cleared from the system queue. + + cmp ah, 'q' + jne @f + call read_gpio0 + or al, 1 ; Set bit 0 + call write_gpio0 + jmp event_wait + @@: + cmp ah, 'w' + jne @f + call read_gpio0 + and al, not 1 ; Clear bit 0 + call write_gpio0 + jmp event_wait + + @@: + jmp event_wait ; Just read the key, ignore it and jump to event_wait. + +button: ; Buttonpress event handler + mov eax,17 ; The button number defined in window_draw + mcall ; is returned to ah. + + cmp ah,1 ; button id=1 ? + jne noclose + mov eax,-1 ; Function -1 : close this program + mcall + +noclose: + jmp event_wait ; This is for ignored events, useful at development + +; ********************************************* +; ****** WINDOW DEFINITIONS AND DRAW ******** +; ********************************************* +; +; The static window parts are drawn in this function. The window canvas can +; be accessed later from any parts of this code (thread) for displaying +; processes or recorded data, for example. +; +; The static parts *must* be placed within the fn 12 , ebx = 1 and ebx = 2. + +draw_window: + mov eax, 12 ; function 12: tell os about windowdraw + mov ebx, 1 ; 1, start of draw + mcall + + mov eax, 0 ; function 0 : define and draw window + mov ebx, 100 * 65536 + 300 ; [x start] *65536 + [x size] + mov ecx, 100 * 65536 + 120 ; [y start] *65536 + [y size] + mov edx, 0x14ffffff ; color of work area RRGGBB + ; 0x02000000 = window type 4 (fixed size, skinned window) + mov esi, 0x808899ff ; color of grab bar RRGGBB + ; 0x80000000 = color glide + mov edi, title + mcall + + mov ebx, 25 * 65536 + 35 ; draw info text with function 4 + mov ecx, 0x224466 + mov edx, text + mov esi, 40 + mov eax, 4 + + .newline: ; text from the DATA AREA + mcall + add ebx, 10 + add edx, 40 + cmp byte[edx], 0 + jne .newline + + mov eax, 12 ; function 12:tell os about windowdraw + mov ebx, 2 ; 2, end of draw + mcall + + ret + +; Read GPIO0 port to AL register +read_gpio0: + mov [IOCTL.io_code], 1 + mcall 68, 17, IOCTL + ret + +; Write AL register to GPIO0 port +write_gpio0: + mov [IOCTL.io_code], 2 + mov [IOCTL.input], eax + mcall 68, 17, IOCTL + ret + +; ********************************************* +; ************* DATA AREA ***************** +; ********************************************* +; +; Data can be freely mixed with code to any parts of the image. +; Only the header information is required at the beginning of the image. + +text db "This is an 86DUINO GPIO demo program " + db " " + db "press q/w to toggle GPIO 0 pin 0 ", 0 + +title db "86Duino Example application", 0 + +drv_name db '86DUINO-GPIO', 0 + +IOCTL: + .handle dd ? + .io_code dd ? + .input dd ? + .inp_size dd ? + .output dd ? + .out_size dd ? + +I_END: \ No newline at end of file