#ifndef _X_SERIAL_BUS_H #define _X_SERIAL_BUS_H // òàéìàóò îæèäàíèß âûïîëåíèß êîìàíäû #define TIME_OUT_SERIAL_BUS 1000 //10000 // max 65535 #define CMD_SERIAL_BUS_READ 0x0000 #define CMD_SERIAL_BUS_WRITE 0x8000 #define SB_ERROR_REPEATS 7 typedef union { unsigned int all; struct { unsigned int data_ready:1; unsigned int trans_compl:1; unsigned int error:1; unsigned int write_error:1; unsigned int read_error:2; unsigned int error_timeout:1; unsigned int count_hold_bus:3; unsigned int rezerv:6; } bit; } X_SERIAL_BUS_flags; typedef struct { X_SERIAL_BUS_flags flags; // ôëàãè unsigned int slave_addr; // íîìåð ïåðèô.ïëàòû unsigned int reg_addr; // àäðåñ âíóòðåííåãî ðåãèñòðà â ïåðèô.ïëàòå unsigned int write_data; // äàííûå äëß çàïèñè unsigned int read_data; // ïðî÷èòàííûå äàííûå unsigned int count_timer; // âíóòðåííèé ñ÷ò÷èê îæèäàíèß âûïîëíåíèß êîìàíäû unsigned int error_count_read; // îáùåå êîëè÷-âî îøèáîê ÷òåíèß unsigned int error_count_write; // îáùåå êîëè÷-âî îøèáîê çàïèñè unsigned int error_count_hold; // îáùåå êîëè÷-âî îøèáîê çàõâàòà øèíû unsigned int ok_count_read; // îáùåå êîëè÷-âî óñïåùíûõ ÷òåíèé unsigned int ok_count_write; // îáùåå êîëè÷-âî óñïåøíûõ çàïèñåé int (*read)(); // Pointer to read function int (*write)(); // Pointer to write function void (*check)(); // Pointer to check function void (*init)(); // Pointer to init function void (*clear_stat)(); // Pointer to init function }X_SERIAL_BUS; typedef X_SERIAL_BUS *X_SERIAL_BUS_handle; #define X_SERIAL_BUS_DEFAULTS { 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ (int (*)(Uint32))x_serial_bus_read,\ (int (*)(Uint32))x_serial_bus_write,\ (void (*)(Uint32))x_serial_bus_check,\ (void (*)(Uint32))x_serial_bus_init,\ (void (*)(Uint32))x_serial_bus_clear_stat_error\ } int x_serial_bus_read(X_SERIAL_BUS_handle); int x_serial_bus_write(X_SERIAL_BUS_handle); void x_serial_bus_check(X_SERIAL_BUS_handle); void x_serial_bus_init(X_SERIAL_BUS_handle); void x_serial_bus_clear_stat_error(X_SERIAL_BUS_handle); void xPeriphReadyCheck(void); extern X_SERIAL_BUS x_serial_bus_project; #endif // end _X_SERIAL_BUS_H