HP85 GPIB Disk Emulator  1.0
HP85GPIBDiskEmulator
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
i2c.h
Go to the documentation of this file.
1 
17 #ifndef _I2C_H
18 #define _I2C_H
19 
20 #include "user_config.h"
21 #include <util/twi.h>
22 
23 
24 // NOTE: TW_MR_ARB_LOST == TW_MT_ARB_LOST
25 #define TW_ARB_LOST TW_MT_ARB_LOST
26 
27 // 16 I2C send/receive buffered operations
28 #define I2C_OPS 16
29 // 10ms timeout per transaction
30 #define I2C_TIMEOUT 10
31 
32 #define I2C_OP_TIMEOUT _BV(0)
33 #define I2C_OP_LEN _BV(1)
34 #define I2C_OP_ERROR _BV(2)
35 #define I2C_TW_MT_SLA_NACK _BV(3)
36 #define I2C_TW_MR_SLA_NACK _BV(4)
37 #define I2C_TW_MT_DATA_NACK _BV(5)
38 #define I2C_BUS_ERROR _BV(6)
39 
40 typedef struct
41 {
42  uint8_t address;
43  uint8_t enable;
44  uint8_t done;
45  uint8_t flags;
46  uint16_t timeout;
47  int8_t len;
48  int8_t ind;
49  uint8_t *buf;
50 } i2c_op_t;
51 
52 typedef struct {
53  uint8_t enable;
54  int8_t ind;
55  uint8_t done;
56  uint8_t error;
57 } i2c_task_t;
58 
61 typedef int8_t (*i2c_callback_t)(void);
62 
64 extern i2c_op_t i2c;
65 
67 
69 extern i2c_task_t i2c_task;
70 
73 
74 
75 
76 /* i2c.c */
77 uint8_t i2c_check_op ( int8_t index );
78 void i2c_task_init ( void );
79 void i2c_task_free_ops ( void );
80 i2c_op_t *i2c_task_op_add ( uint8_t address , uint8_t mode , uint8_t *buf , uint8_t len );
81 int8_t i2c_task_next_op ( void );
82 void i2c_task_run ( void );
83 void i2c_init ( uint32_t speed );
84 int8_t i2c_ok ( void );
85 int8_t i2c_done ( void );
86 int8_t i2c_task_done ( void );
87 uint8_t i2c_fn ( uint8_t address , uint8_t mode , uint8_t *buf , uint8_t len );
88 void i2c_send_start ( void );
89 void i2c_send_stop ( void );
90 void i2c_timer ( void );
91 // int ISR ( int TWI_vect );
92 void i2c_print_error ( i2c_op_t *o );
93 void i2c_display_task_errors ( void );
94 
95 #endif
i2c_op_t::buf
uint8_t * buf
Definition: i2c.h:49
i2c_task_free_ops
void i2c_task_free_ops(void)
Free all allocated memory for i2c_[] pointers NOTE: We ASSUME all i2c_task_op[].buf are statically al...
Definition: i2c.c:92
i2c_print_error
void i2c_print_error(i2c_op_t *o)
Display Errors for i2c_task_op[index].
Definition: i2c.c:660
i2c_ok
int8_t i2c_ok(void)
check if I2C trasnaction detected an error
Definition: i2c.c:369
i2c_task_init
void i2c_task_init(void)
Initialize I2C task op list NOTE: We ASSUME all i2c_task_op[].buf are statically allocated.
Definition: i2c.c:69
i2c_task_t
Definition: i2c.h:52
i2c_callback
i2c_callback_t i2c_callback
Definition: i2c.c:28
i2c_task_t::done
uint8_t done
Definition: i2c.h:55
i2c_task_done
int8_t i2c_task_done(void)
Are all i2c_task_op[] pointers done sending/receiving ?
Definition: i2c.c:390
I2C_OPS
#define I2C_OPS
Definition: i2c.h:28
i2c
i2c_op_t i2c
I2C interrupt state registers.
Definition: i2c.c:22
i2c_task_t::ind
int8_t ind
Definition: i2c.h:54
i2c_op_t::enable
uint8_t enable
Definition: i2c.h:43
i2c_op_t::timeout
uint16_t timeout
Definition: i2c.h:46
i2c_timer
void i2c_timer(void)
I2C timer task - check for I2C operation timeouts.
Definition: i2c.c:503
i2c_op_t::ind
int8_t ind
Definition: i2c.h:48
i2c_op_t::address
uint8_t address
Definition: i2c.h:42
i2c_init
void i2c_init(uint32_t speed)
I2C initialize Clear all i2c_task_op[] pointers and disables I2C tasks.
Definition: i2c.c:316
i2c_task_op
i2c_op_t * i2c_task_op[I2C_OPS]
I2C task list.
Definition: i2c.c:33
user_config.h
Master Include for FatFs, RTC, Timers AVR8 - Part of HP85 disk emulator.
i2c_task_run
void i2c_task_run(void)
Run all valid i2c_task_op[] tasks.
Definition: i2c.c:225
i2c_callback_t
int8_t(* i2c_callback_t)(void)
Definition: i2c.h:61
i2c_check_op
uint8_t i2c_check_op(int8_t index)
Check if I2C structure pointer is valid.
Definition: i2c.c:40
i2c_task_t::error
uint8_t error
Definition: i2c.h:56
i2c_display_task_errors
void i2c_display_task_errors(void)
Display any task errors.
Definition: i2c.c:684
i2c_op_t::flags
uint8_t flags
Definition: i2c.h:45
i2c_op_t
Definition: i2c.h:40
i2c_task
i2c_task_t i2c_task
I2C task state.
Definition: i2c.c:31
i2c_op_t::done
uint8_t done
Definition: i2c.h:44
i2c_send_start
void i2c_send_start(void)
Send I2C START and enable interrupts.
Definition: i2c.c:451
i2c_op_t::len
int8_t len
Definition: i2c.h:47
i2c_task_t::enable
uint8_t enable
Definition: i2c.h:53
i2c_task_op_add
i2c_op_t * i2c_task_op_add(uint8_t address, uint8_t mode, uint8_t *buf, uint8_t len)
I2C setup new OP but do not run it yet.
Definition: i2c.c:135
i2c_fn
uint8_t i2c_fn(uint8_t address, uint8_t mode, uint8_t *buf, uint8_t len)
I2C setup new OP but do not run it yet.
Definition: i2c.c:407
i2c_send_stop
void i2c_send_stop(void)
Send I2C STOP and disable interrupts.
Definition: i2c.c:468
i2c_task_next_op
int8_t i2c_task_next_op(void)
I2C task ISR callback function.
Definition: i2c.c:163
i2c_done
int8_t i2c_done(void)
Is i2c structure done sending/receiving ?
Definition: i2c.c:379