Dear support
I have written now my corrected program for an application Servo Drive with the serial port interface and the PIT (PC timer).
I have use the inpout32.dll library.
My program compile fine, but if I running then crashes it and display WinXP priv errors.
What can I do for my problem ?
/* Application program (console apps) Auto_Servo_Drive.eba */
$USE "inpout32.lib"
DECLARE IMPORT, Inp32(PortAddr : WORD), WORD
DECLARE IMPORT, Out32(PortAddr : WORD, PortData : WORD)
DECLARE EXTERN _sscanf(STRING buf, STRING format,...),INT
DECLARE EXTERN sprintf(POINTER p, POINTER p, ...), INT
DECLARE Test()
DECLARE Sturing()
DECLARE Impulsgenerator(impuls_width : INT)
DECLARE ROUND(DOUBLE d, INT n), DOUBLE
DECLARE FRAC(DOUBLE d), DOUBLE
CONST BA = 0x2F8
/* Servosturing */
/* Hoofdprogramma */
OPENCONSOLE
DEF setup_tijd : DOUBLE
DEF ch : CHAR
Test()
DO
Sturing()
UNTIL INKEY$ <> ""
CLOSECONSOLE
SUB Test()
DEF high, low : CHAR
DEF m : WORD
_asm
cli
_endasm
Out32 (0x43, 0x34) /* Timer 0, Mode 2 */
Out32 (0x40, 0x00) /* Timer 0, low reset */
Out32 (0x40, 0x00) /* Timer 0, high reset */
FOR m = 1 TO 1000 : NEXT m /* tijdsmeting */
Out32 (0x43, 0x04) /* Timer 0, bevriezen */
low = Inp32(0x40) /* Timer 0, uitlezen */
high = Inp32(0x40)
_asm
sti
_endasm
setup_tijd = -(low + 256 * high) / 1000
PRINT USING("Cyclusduur: #####.###", setup_tijd)
PRINT
RETURN
ENDSUB
SUB Impulsgenerator(impuls_width : INT)
DEF on_time : WORD
DEF off_time : WORD
DEF getal : WORD
DEF teller : WORD
on_time = ROUND(impuls_width / setup_tijd, 2)
off_time = ROUND(10000 /setup_tijd, 2)
_asm
sti
_endasm
FOR getal = 1 TO 50
Out32 ((BA + 0x04), 0x01) /* DTR = 1 */
FOR teller = 1 TO on_time : NEXT teller /* Impulstijd */
Out32 ((BA + 0x04), 0x00) /* DTR = 0 */
FOR teller = 1 TO off_time : NEXT teller /* Pauzetijd */
NEXT getal
_asm
sti
_endasm
ENDSUB
SUB Sturing()
DEF n : INT
FOR n = 1 TO 10
ImpulsGenerator(1000 + n * 100)
NEXT n
ENDSUB
SUB ROUND(DOUBLE d, INT n),DOUBLE
SETPRECISION(n)
RETURN VAL(STR$(d))
ENDSUB
SUB FRAC(DOUBLE d),DOUBLE
RETURN d - INT(d)
ENDSUB
Compiler & Linking Repport
=================
Compiling...
servo_sturing.eba
No Errors
Linking...
Emergence Linker v1.11 Copyright ÂÃ,© 2006 Ionic Wind Software
Generating E:\Program Files\EBDev\EBCodeArch\Electronics\servo_sturing.exe
Build completed
Debug Repport
==========
Starting debug session...
Loading DLL: ntdll.dll
Loading DLL: E:\WINDOWS\system32\kernel32.dll
Loading DLL: E:\WINDOWS\system32\GDI32.DLL
Loading DLL: E:\WINDOWS\system32\USER32.dll
Loading DLL: E:\WINDOWS\system32\INPOUT32.DLL
Loading DLL: E:\WINDOWS\system32\ADVAPI32.dll
Loading DLL: E:\WINDOWS\system32\RPCRT4.dll
Loading DLL: E:\WINDOWS\system32\Secur32.dll
Loading DLL: E:\WINDOWS\system32\CRTDLL.DLL
Loading DLL: E:\WINDOWS\system32\IMM32.DLL
First chance exception: Address 0x004080B9 Attempt to execute Privileged Instruction
Final chance exception: Address 0x004080B9 Attempt to execute Privileged Instruction
Was that the cause if the program fails ?
_asm cli _endasm
_asm sti _endasm
Of that I addressed the PIT ?
I don't know what it is
Kind regards
Stephane
Thanks for the functions : ROUND() and FRAC()
You can't use the instructions cli and sti on Windows NT based systems from user level code. Only from ring 0 code, the OS itself and device drivers.
Also 'in' and 'out' will fail as a privileged instruction on all NT based OS's (NT, XP, Vista) unless running as a device driver.
You may be able to get input/output to ports working from your application using this:
http://beyondlogic.org/porttalk/porttalk.htm
Paul.