HP85 GPIB Disk Emulator  1.0
HP85GPIBDiskEmulator
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gpib.h
Go to the documentation of this file.
1 
19 #ifndef _GPIB_H_
20 #define _GPIB_H_
21 
22 #include "user_config.h"
23 #include "hal.h"
24 #include "gpib_hal.h"
25 #include "posix.h"
26 
27 #define GPIB_BUS_SETTLE_DELAY 2
28 //#define GPIB_BUS_SETTLE_DELAY 5
30 #define HTIMEOUT (500000L / GPIB_TASK_TIC_US)
31 
33 #define EOI_FLAG 0x0100
34 #define SRQ_FLAG 0x0200
35 #define ATN_FLAG 0x0400
36 #define REN_FLAG 0x0800
37 #define IFC_FLAG 0x1000
38 
40 #define PP_FLAG 0x2000
41 #define TIMEOUT_FLAG 0x4000
42 #define BUS_ERROR_FLAG 0x8000
43 
45 #define DAV_FLAG 0x2000
46 #define NRFD_FLAG 0x4000
47 #define NDAC_FLAG 0x8000
48 
49 #define ERROR_MASK (IFC_FLAG | TIMEOUT_FLAG | BUS_ERROR_FLAG)
50 #define CONTROL_MASK (EOI_FLAG | SRQ_FLAG | ATN_FLAG | REN_FLAG)
51 
52 #define DATA_MASK 0x00ff
53 #define CMD_MASK 0x007f
54 #define STATUS_MASK 0xff00
55 
57 enum
58 {
59  TRACE_DISABLE, // normal read
60  TRACE_READ, // trace read
61  TRACE_BUS // trace bus handshake
62 };
63 
65 #define TRACE_ALL 1 /* trace all bus states durring a read */
66 #define NO_TRACE 0 /* do not trace bus states durring a read */
67 
68 enum
69 {
79 };
80 
81 enum
82 {
93 };
94 
95 enum
96 {
99 };
100 
101 #define GPIB_IOBUFF_LEN 512 /* Max length of RX/TX GPIB string */
102 extern uint8_t gpib_iobuff[GPIB_IOBUFF_LEN];
103 
104 extern int debuglevel;
105 
106 extern uint8_t talk31;
107 extern uint8_t talking;
108 extern uint8_t talking_last;
109 extern uint8_t listening;
110 extern uint8_t listening_last;
111 extern uint8_t spoll;
112 extern uint16_t current,lastcmd;
113 extern uint8_t secondary;
114 extern uint8_t device;
115 
116 
117 /* gpib.c */
118 void gpib_timer_elapsed_begin ( void );
119 void gpib_timer_reset ( void );
120 void gpib_timer_elapsed_end ( char *msg );
121 void gpib_timer_task ( void );
122 void gpib_timeout_set ( uint32_t time );
123 uint8_t gpib_timeout_test ( void );
124 void gpib_bus_init ( void );
125 void gpib_rx_init ( uint8_t busy );
126 void gpib_tx_init ( void );
127 void gpib_state_init ( void );
128 void gpib_enable_PPR ( int bit );
129 void gpib_disable_PPR ( int bit );
130 uint8_t gpib_detect_PP ( void );
131 uint16_t gpib_unread ( uint16_t ch );
132 uint8_t gpib_bus_read ( void );
133 uint16_t gpib_control_pin_read ( void );
134 uint16_t gpib_handshake_pin_read ( void );
135 uint16_t gpib_write_byte ( uint16_t ch );
136 uint16_t gpib_read_byte ( int trace );
137 void gpib_decode_header ( FILE *fo );
138 void gpib_trace_display ( uint16_t status , int trace_state );
139 void gpib_decode ( uint16_t ch );
140 int gpib_read_str ( uint8_t *buf , int size , uint16_t *status );
141 int gpib_write_str ( uint8_t *buf , int size , uint16_t *status );
142 
143 #endif // GPIB_H_
GPIB_TX_PUT_DATA
@ GPIB_TX_PUT_DATA
Definition: gpib.h:85
GPIB_RX_DAV_IS_HI
@ GPIB_RX_DAV_IS_HI
Definition: gpib.h:75
gpib_write_str
int gpib_write_str(uint8_t *buf, int size, uint16_t *status)
Send string to GPIB BUS - controlled by status flags.
Definition: gpib.c:1396
GPIB_PP_DETECTED
@ GPIB_PP_DETECTED
Definition: gpib.h:98
GPIB_TX_WAIT_FOR_NDAC_HI
@ GPIB_TX_WAIT_FOR_NDAC_HI
Definition: gpib.h:88
secondary
uint8_t secondary
gpib secondary
Definition: gpib.c:100
GPIB_TX_WAIT_FOR_NRFD_OR_NDAC_LOW
@ GPIB_TX_WAIT_FOR_NRFD_OR_NDAC_LOW
Definition: gpib.h:84
gpib_handshake_pin_read
uint16_t gpib_handshake_pin_read(void)
Read GPIB handshake lines only FIXME: V2 boards can only read pins enabled for read by the SN75162 FI...
Definition: gpib.c:601
GPIB_PP_IDLE
@ GPIB_PP_IDLE
Definition: gpib.h:97
hal.h
talking
uint8_t talking
gpib talk address
Definition: gpib.c:85
gpib_tx_init
void gpib_tx_init(void)
Initialize GPIB Bus control lines for WRITE.
Definition: gpib.c:364
GPIB_TX_WAIT_FOR_NRFD_HI
@ GPIB_TX_WAIT_FOR_NRFD_HI
Definition: gpib.h:86
gpib_read_byte
uint16_t gpib_read_byte(int trace)
read 1 byte and control line status from GPIB BUS
Definition: gpib.c:875
gpib_timeout_test
uint8_t gpib_timeout_test(void)
Test GPIB timeout timer for timeout condition.
Definition: gpib.c:220
GPIB_RX_ERROR
@ GPIB_RX_ERROR
Definition: gpib.h:77
GPIB_TX_SET_DAV_LOW
@ GPIB_TX_SET_DAV_LOW
Definition: gpib.h:87
gpib_timer_elapsed_end
void gpib_timer_elapsed_end(char *msg)
Display user message and time delta since gpib_timer_elapsed_begin() call.
Definition: gpib.c:164
gpib_decode_header
void gpib_decode_header(FILE *fo)
Displays help for gpib_decode() function.
Definition: gpib.c:1082
current
uint16_t current
Definition: gpib.c:97
gpib_unread
uint16_t gpib_unread(uint16_t ch)
GPIB ungets one character and all status states.
Definition: gpib.c:544
GPIB_IOBUFF_LEN
#define GPIB_IOBUFF_LEN
Definition: gpib.h:101
GPIB_RX_WAIT_FOR_DAV_LOW
@ GPIB_RX_WAIT_FOR_DAV_LOW
Definition: gpib.h:71
GPIB_RX_DONE
@ GPIB_RX_DONE
Definition: gpib.h:78
__file
FILE type structure.
Definition: posix.h:158
GPIB_RX_WAIT_FOR_DAV_HI
@ GPIB_RX_WAIT_FOR_DAV_HI
Definition: gpib.h:74
gpib_trace_display
void gpib_trace_display(uint16_t status, int trace_state)
decode/display all control flags and data on the GPIB BUS
Definition: gpib.c:1135
spoll
uint8_t spoll
gpib serial poll status
Definition: gpib.c:95
TRACE_BUS
@ TRACE_BUS
Definition: gpib.h:61
GPIB_TX_START
@ GPIB_TX_START
Definition: gpib.h:83
GPIB_TX_ERROR
@ GPIB_TX_ERROR
Definition: gpib.h:91
GPIB_RX_FINISH
@ GPIB_RX_FINISH
Definition: gpib.h:76
gpib_bus_init
void gpib_bus_init(void)
Initialize/Release GPIB Bus control lines Used for Power ON, Reset or IFC LOW reset conditions.
Definition: gpib.c:229
time
MEMSPACE time_t time(time_t *t)
Return second from epoch - POSIX function.
Definition: time.c:843
device
uint8_t device
talking_last
uint8_t talking_last
gpib last talk address
Definition: gpib.c:87
gpib_iobuff
uint8_t gpib_iobuff[GPIB_IOBUFF_LEN]
common IO buffer for gpib_read_str() and gpib_write_str()
Definition: gpib.c:77
listening
uint8_t listening
gpib listen address
Definition: gpib.c:90
GPIB_TX_FINISH
@ GPIB_TX_FINISH
Definition: gpib.h:90
gpib_control_pin_read
uint16_t gpib_control_pin_read(void)
Read GPIB control lines only FIXME V2 boards can only read pins enabled for read by the SN75162 FIXME...
Definition: gpib.c:580
gpib_bus_read
uint8_t gpib_bus_read(void)
Read GPIB data BUS only.
Definition: gpib.c:562
talk31
uint8_t talk31
gpib_timer_reset
void gpib_timer_reset(void)
Reset elapsed and timeout timers Elapses and Timeout Timers.
Definition: gpib.c:150
TRACE_DISABLE
@ TRACE_DISABLE
Definition: gpib.h:59
gpib_state_init
void gpib_state_init(void)
Reset GPIB states and related variables.
Definition: gpib.c:389
GPIB_TX_SET_DAV_HI
@ GPIB_TX_SET_DAV_HI
Definition: gpib.h:89
listening_last
uint8_t listening_last
gpib last listen address
Definition: gpib.c:92
GPIB_RX_DAV_IS_LOW
@ GPIB_RX_DAV_IS_LOW
Definition: gpib.h:72
lastcmd
uint16_t lastcmd
Definition: gpib.h:112
GPIB_RX_WAIT_FOR_NDAC_HI
@ GPIB_RX_WAIT_FOR_NDAC_HI
Definition: gpib.h:73
TRACE_READ
@ TRACE_READ
Definition: gpib.h:60
gpib_timer_elapsed_begin
void gpib_timer_elapsed_begin(void)
Start measuring time - used with hpib_timer_elapsed_end()
Definition: gpib.c:133
GPIB_TX_DONE
@ GPIB_TX_DONE
Definition: gpib.h:92
gpib_timer_task
void gpib_timer_task(void)
Main GPIB timer task called by low level interrup hander.
Definition: gpib.c:190
gpib_disable_PPR
void gpib_disable_PPR(int bit)
Disable PPR (Parallel Poll Response) for a device.
Definition: gpib.c:436
gpib_hal.h
GPIB emulator hardwware layer for HP85 disk emulator project for AVR.
posix.h
POSIX wrapper for FatFS.
debuglevel
int debuglevel
Debug flag - used to log GPIB and emulator messages.
Definition: gpib_task.c:33
gpib_decode
void gpib_decode(uint16_t ch)
Calls gpib_decode_str() and dosplays the result.
Definition: gpib.c:1266
gpib_timeout_set
void gpib_timeout_set(uint32_t time)
Set GPIB timeout timer in units of GPIB_TASK_TIC_US.
Definition: gpib.c:207
gpib_detect_PP
uint8_t gpib_detect_PP(void)
Attempt to detect the Parallel Poll Reposnse state Used only for debugging - it is unlikely that we w...
Definition: gpib.c:469
gpib_enable_PPR
void gpib_enable_PPR(int bit)
Definition: gpib.c:416
gpib_rx_init
void gpib_rx_init(uint8_t busy)
Initialize GPIB Bus control lines for READ.
Definition: gpib.c:307
GPIB_RX_START
@ GPIB_RX_START
Definition: gpib.h:70
gpib_write_byte
uint16_t gpib_write_byte(uint16_t ch)
Send 1 byte and control line states to GPIB BUS.
Definition: gpib.c:655
gpib_read_str
int gpib_read_str(uint8_t *buf, int size, uint16_t *status)
Read string from GPIB BUS - controlled by status flags.
Definition: gpib.c:1307