diff options
author | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2011-03-09 17:32:01 +0100 |
---|---|---|
committer | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2011-03-09 17:32:01 +0100 |
commit | 134e2cc87d524bbb63c2e73dc1bb1fd8c0449ae1 (patch) | |
tree | 5f43a328cd43745ff3f2db4d864b2db4b81c35fd | |
parent | a008b10d8488ef905a43de00ee5c8efd03b03ed6 (diff) | |
download | ipecamera-134e2cc87d524bbb63c2e73dc1bb1fd8c0449ae1.tar.gz ipecamera-134e2cc87d524bbb63c2e73dc1bb1fd8c0449ae1.tar.bz2 ipecamera-134e2cc87d524bbb63c2e73dc1bb1fd8c0449ae1.tar.xz ipecamera-134e2cc87d524bbb63c2e73dc1bb1fd8c0449ae1.zip |
Provide single header for library
-rw-r--r-- | cli.c | 2 | ||||
-rw-r--r-- | default.h | 2 | ||||
-rw-r--r-- | ipecamera.h | 2 | ||||
-rw-r--r-- | pci.c | 2 | ||||
-rw-r--r-- | pci.h | 126 | ||||
-rw-r--r-- | pcilib.h | 126 |
6 files changed, 131 insertions, 129 deletions
@@ -20,7 +20,7 @@ #include "pci.h" #include "ipecamera.h" #include "tools.h" - +#include "kernel.h" /* defines */ #define MAX_KBUF 14 @@ -1,7 +1,7 @@ #ifndef _PCILIB_DEFAULT_H #define _PCILIB_DEFAULT_H -#include "pci.h" +#include "pcilib.h" int pcilib_default_read(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, uint8_t bits, pcilib_register_value_t *value); int pcilib_default_write(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, uint8_t bits, pcilib_register_value_t value); diff --git a/ipecamera.h b/ipecamera.h index 8929b85..9061dea 100644 --- a/ipecamera.h +++ b/ipecamera.h @@ -3,7 +3,7 @@ #include <stdio.h> -#include "pci.h" +#include "pcilib.h" #define IPECAMERA_REGISTER_SPACE 0xfeaffc00 #define IPECAMERA_REGISTER_WRITE (IPECAMERA_REGISTER_SPACE + 0) @@ -13,8 +13,6 @@ #include <errno.h> #include <assert.h> -#include "driver/pciDriver.h" - #include "kernel.h" #include "tools.h" @@ -1,110 +1,14 @@ #ifndef _PCITOOL_PCI_H #define _PCITOOL_PCI_H -#define PCILIB_MAX_BANKS 6 #define PCILIB_REGISTER_TIMEOUT 10000 /**< us */ -#include <stdint.h> - #include "driver/pciDriver.h" -#include "kernel.h" - - -#define pcilib_memcpy pcilib_memcpy32 -#define pcilib_datacpy pcilib_datacpy32 - -typedef struct pcilib_s pcilib_t; - -typedef uint8_t pcilib_bar_t; /**< Type holding the PCI Bar number */ -typedef uint8_t pcilib_register_t; /**< Type holding the register ID within the Bank */ -typedef uint8_t pcilib_register_addr_t; /**< Type holding the register ID within the Bank */ -typedef uint8_t pcilib_register_bank_t; /**< Type holding the register bank number */ -typedef uint8_t pcilib_register_bank_addr_t; /**< Type holding the register bank number */ -typedef uint8_t pcilib_register_size_t; /**< Type holding the size in bits of the register */ -typedef uint32_t pcilib_register_value_t; /**< Type holding the register value */ - -typedef enum { - PCILIB_LITTLE_ENDIAN = 0, - PCILIB_BIG_ENDIAN -} pcilib_endianess_t; - -typedef enum { - PCILIB_MODEL_DETECT, - PCILIB_MODEL_PCI, - PCILIB_MODEL_IPECAMERA -} pcilib_model_t; - -typedef enum { - PCILIB_REGISTER_R = 1, - PCILIB_REGISTER_W = 2, - PCILIB_REGISTER_RW = 3 -} pcilib_register_mode_t; - - -typedef enum { - PCILIB_DEFAULT_PROTOCOL, - IPECAMERA_REGISTER_PROTOCOL -} pcilib_register_protocol_t; - -#define PCILIB_BAR_DETECT ((pcilib_bar_t)-1) -#define PCILIB_REGISTER_INVALID ((pcilib_register_t)-1) -#define PCILIB_ADDRESS_INVALID ((uintptr_t)-1) -#define PCILIB_REGISTER_BANK_INVALID ((pcilib_register_bank_t)-1) -#define PCILIB_REGISTER_BANK0 0 -#define PCILIB_REGISTER_BANK1 1 -#define PCILIB_REGISTER_BANK2 2 -#define PCILIB_REGISTER_BANK3 3 - -typedef struct { - pcilib_register_bank_addr_t addr; - size_t size; - - pcilib_register_protocol_t protocol; - - uintptr_t read_addr; - uintptr_t write_addr; - uint8_t raw_endianess; - - uint8_t access; - uint8_t endianess; - - const char *name; - const char *description; -} pcilib_register_bank_description_t; -typedef struct { - pcilib_register_addr_t addr; - pcilib_register_size_t bits; - pcilib_register_value_t defvalue; - pcilib_register_mode_t mode; +#include "pcilib.h" - pcilib_register_bank_t bank; - - const char *name; - const char *description; -} pcilib_register_description_t; -/** - * Default mappings - */ -typedef struct { - uintptr_t start; - uintptr_t end; - pcilib_register_bank_t bank; -} pcilib_register_range_t; - -typedef struct { - int (*read)(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, uint8_t bits, pcilib_register_value_t *value); - int (*write)(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, uint8_t bits, pcilib_register_value_t value); -} pcilib_protocol_description_t; - -#include "ipecamera.h" - -typedef struct { - pcilib_register_description_t *registers; - pcilib_register_bank_description_t *banks; - pcilib_register_range_t *ranges; -} pcilib_model_description_t; +const pci_board_info *pcilib_get_board_info(pcilib_t *ctx); #ifdef _PCILIB_PCI_C # include "ipecamera.h" @@ -129,30 +33,4 @@ extern pcilib_model_description_t pcilib_model[]; extern pcilib_protocol_description_t pcilib_protocol[]; #endif /* _PCILIB_PCI_C */ -int pcilib_set_error_handler(void (*err)(const char *msg, ...)); - - -pcilib_t *pcilib_open(const char *device, pcilib_model_t model); -void pcilib_close(pcilib_t *ctx); - -const pci_board_info *pcilib_get_board_info(pcilib_t *ctx); -pcilib_model_t pcilib_get_model(pcilib_t *ctx); - -void *pcilib_map_bar(pcilib_t *ctx, pcilib_bar_t bar); -void pcilib_unmap_bar(pcilib_t *ctx, pcilib_bar_t bar, void *data); -char *pcilib_resolve_register_address(pcilib_t *ctx, uintptr_t addr); - -pcilib_register_bank_t pcilib_find_bank(pcilib_t *ctx, const char *bank); -pcilib_register_t pcilib_find_register(pcilib_t *ctx, const char *bank, const char *reg); - -int pcilib_read(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr, size_t size, void *buf); -int pcilib_write(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr, size_t size, void *buf); - -int pcilib_read_register_space(pcilib_t *ctx, const char *bank, pcilib_register_addr_t addr, size_t n, pcilib_register_value_t *buf); -int pcilib_write_register_space(pcilib_t *ctx, const char *bank, pcilib_register_addr_t addr, size_t n, pcilib_register_value_t *buf); -int pcilib_read_register_by_id(pcilib_t *ctx, pcilib_register_t reg, pcilib_register_value_t *value); -int pcilib_write_register_by_id(pcilib_t *ctx, pcilib_register_t reg, pcilib_register_value_t value); -int pcilib_read_register(pcilib_t *ctx, const char *bank, const char *regname, pcilib_register_value_t *value); -int pcilib_write_register(pcilib_t *ctx, const char *bank, const char *regname, pcilib_register_value_t value); - #endif /* _PCITOOL_PCI_H */ diff --git a/pcilib.h b/pcilib.h new file mode 100644 index 0000000..7541c80 --- /dev/null +++ b/pcilib.h @@ -0,0 +1,126 @@ +#ifndef _PCITOOL_PCILIB_H +#define _PCITOOL_PCILIB_H + +#define PCILIB_MAX_BANKS 6 + +#include <stdint.h> + +#define pcilib_memcpy pcilib_memcpy32 +#define pcilib_datacpy pcilib_datacpy32 + +typedef struct pcilib_s pcilib_t; + +typedef uint8_t pcilib_bar_t; /**< Type holding the PCI Bar number */ +typedef uint8_t pcilib_register_t; /**< Type holding the register ID within the Bank */ +typedef uint8_t pcilib_register_addr_t; /**< Type holding the register ID within the Bank */ +typedef uint8_t pcilib_register_bank_t; /**< Type holding the register bank number */ +typedef uint8_t pcilib_register_bank_addr_t; /**< Type holding the register bank number */ +typedef uint8_t pcilib_register_size_t; /**< Type holding the size in bits of the register */ +typedef uint32_t pcilib_register_value_t; /**< Type holding the register value */ + +typedef enum { + PCILIB_LITTLE_ENDIAN = 0, + PCILIB_BIG_ENDIAN +} pcilib_endianess_t; + +typedef enum { + PCILIB_MODEL_DETECT, + PCILIB_MODEL_PCI, + PCILIB_MODEL_IPECAMERA +} pcilib_model_t; + +typedef enum { + PCILIB_REGISTER_R = 1, + PCILIB_REGISTER_W = 2, + PCILIB_REGISTER_RW = 3 +} pcilib_register_mode_t; + + +typedef enum { + PCILIB_DEFAULT_PROTOCOL, + IPECAMERA_REGISTER_PROTOCOL +} pcilib_register_protocol_t; + +#define PCILIB_BAR_DETECT ((pcilib_bar_t)-1) +#define PCILIB_REGISTER_INVALID ((pcilib_register_t)-1) +#define PCILIB_ADDRESS_INVALID ((uintptr_t)-1) +#define PCILIB_REGISTER_BANK_INVALID ((pcilib_register_bank_t)-1) +#define PCILIB_REGISTER_BANK0 0 +#define PCILIB_REGISTER_BANK1 1 +#define PCILIB_REGISTER_BANK2 2 +#define PCILIB_REGISTER_BANK3 3 + +typedef struct { + pcilib_register_bank_addr_t addr; + size_t size; + + pcilib_register_protocol_t protocol; + + uintptr_t read_addr; + uintptr_t write_addr; + uint8_t raw_endianess; + + uint8_t access; + uint8_t endianess; + + const char *name; + const char *description; +} pcilib_register_bank_description_t; + +typedef struct { + pcilib_register_addr_t addr; + pcilib_register_size_t bits; + pcilib_register_value_t defvalue; + pcilib_register_mode_t mode; + + pcilib_register_bank_t bank; + + const char *name; + const char *description; +} pcilib_register_description_t; + +/** + * Default mappings + */ +typedef struct { + uintptr_t start; + uintptr_t end; + pcilib_register_bank_t bank; +} pcilib_register_range_t; + +typedef struct { + int (*read)(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, uint8_t bits, pcilib_register_value_t *value); + int (*write)(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, uint8_t bits, pcilib_register_value_t value); +} pcilib_protocol_description_t; + +typedef struct { + pcilib_register_description_t *registers; + pcilib_register_bank_description_t *banks; + pcilib_register_range_t *ranges; +} pcilib_model_description_t; + +int pcilib_set_error_handler(void (*err)(const char *msg, ...)); + +pcilib_model_t pcilib_get_model(pcilib_t *ctx); + +pcilib_t *pcilib_open(const char *device, pcilib_model_t model); +void pcilib_close(pcilib_t *ctx); + +void *pcilib_map_bar(pcilib_t *ctx, pcilib_bar_t bar); +void pcilib_unmap_bar(pcilib_t *ctx, pcilib_bar_t bar, void *data); +char *pcilib_resolve_register_address(pcilib_t *ctx, uintptr_t addr); + +pcilib_register_bank_t pcilib_find_bank(pcilib_t *ctx, const char *bank); +pcilib_register_t pcilib_find_register(pcilib_t *ctx, const char *bank, const char *reg); + +int pcilib_read(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr, size_t size, void *buf); +int pcilib_write(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr, size_t size, void *buf); + +int pcilib_read_register_space(pcilib_t *ctx, const char *bank, pcilib_register_addr_t addr, size_t n, pcilib_register_value_t *buf); +int pcilib_write_register_space(pcilib_t *ctx, const char *bank, pcilib_register_addr_t addr, size_t n, pcilib_register_value_t *buf); +int pcilib_read_register_by_id(pcilib_t *ctx, pcilib_register_t reg, pcilib_register_value_t *value); +int pcilib_write_register_by_id(pcilib_t *ctx, pcilib_register_t reg, pcilib_register_value_t value); +int pcilib_read_register(pcilib_t *ctx, const char *bank, const char *regname, pcilib_register_value_t *value); +int pcilib_write_register(pcilib_t *ctx, const char *bank, const char *regname, pcilib_register_value_t value); + +#endif /* _PCITOOL_PCILIB_H */ |