; ==== ISUAL Flight Software -- Univ of California, Berkeley, SSL ==== ; CDI.a -- Command Data Interface routines ; ; Revision History: ; 18-Dec-2002 - SPG - ISUAL Flight Software rev 7.3 ; First Official Release ; 31-dec-2002 ; Removed debug.i ; Command Data Interface functions ; ; commands are one byte of command-code ; and 16 bits (2 bytes) of data ; (total of 24 bits) ; The interface is serial, output-only ; One CDI transfer requires 13 microseconds. ; ; These functions have to be able to run ; either within an Interrupt Service Routine (ISR) ; or disable interrupts first. include cdi.i include ioports.i ; ; CDI_INIT: ret ; ; Send Command ; A - command code ; HL - =points to= 2 bytes of data CDI_SEND: push psw push b mov b,a ; preserve Opcode ; test for running in an ISR rim ani 08h ; b3 is Interrupt-Enable flag jz isr_send ; not running in an ISR ; disable interrupts di call x_send ; do the "send" code ei ; interrupts back on jmp xit ; Running in an ISR isr_send: call x_send jmp xit ; Common "send" code x_send: ; make sure CDI is "done" wait: in STATUS6_I ani 04h ; port 06, bit 2: 1=CDI done jz wait ; send data: low, high inx h mov a,M ; low out CDI_DAT_LO_O dcx h ; (now HL is back where it was) mov a,M ; high out CDI_DAT_HI_O mov a,b ; operation out CDI_CMD_O ; start the transfer ; don't wait for done ret ; Send CDI with data in HL ; A - command code ; HL - =contains= the 2 bytes of data CDI_AHL: push psw push b mov b,a ; preserve Op ; test for running in an ISR rim ani 08h ; b3 is Interrupt-Enable flag jz isr_ahl ; not running in an ISR ; disable interrupts di call x_ahl ; do the "send" code ei ; interrupts back on jmp xit ; Running in ISR isr_ahl: call x_ahl jmp xit ; Common AHL code x_ahl: ; make sure CDI is "done" waita: in STATUS6_I ani 04h ; port 06, bit 2: 1=CDI done jz waita mov a,l ; low data byte out CDI_DAT_LO_O mov a,h ; high data byte out CDI_DAT_HI_O mov a,b ; operation out CDI_CMD_O ; start the transfer ; don't wait for done ret ; ====Do a Readback==== ; A - command code ; HL - where to store 2 bytes of data CDI_READBACK: push psw push b mov b,a ; preserve Opcode ; test for running in an ISR rim ani 08h ; b3 is Interrupt-Enable flag jz isr_rb ; not running in an ISR ; disable interrupts di call x_rb ; do the "readback" code ei ; interrupts back on jmp xit ; Running in ISR isr_rb: call x_rb jmp xit ; common "readback" code x_rb: ; make sure CDI is "done" waitr: in STATUS6_I ani 04h ; bit 2: 1=CDI done jz waitr ; start the transfer mov a,b ; operation out CDI_CMD_O ; start the transfer ; wait for done (to see the readback) waitr2: in STATUS6_I ani 04h jz waitr2 ; get the readback data inx h ; point to low byte storage in CDI_DAT_LO_I ; readback Low mov M,a dcx h ; point to high byte storage in CDI_DAT_HI_I ; readback High mov M,a ; (now HL is back where it was) ret ; exit xit: pop b pop psw ret