Sonochan II 0.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
generic_driver.h
Go to the documentation of this file.
1
19 #ifndef _GENERIC_DRIVER_H_
20 #define _GENERIC_DRIVER_H_
21
22
23 //================================| Includes |=================================
24 #include <inttypes.h>
25 #include <stdio.h> // Some architectures have there defined "uint" type
26
27 // Include only if architecture is AVR8
28 #ifdef __AVR_ARCH__
29 #include <avr/pgmspace.h>
30 #endif
31 //===============================| Definitions |===============================
38 #define GD_MAX_STRING_SIZE 80
39
40 //===============================| Structures |================================
41 #ifndef GD_RES_CODE_DEFINED
42
43 #define GD_RES_CODE_DEFINED
44
47 typedef enum{
48 GD_SUCCESS = 0,
49 GD_FAIL = 1,
50 GD_INCORRECT_PARAMETER = 2,
51 GD_INCORRECT_CMD_ID = 3,
52 GD_CMD_ID_NOT_EQUAL_IN_FLASH = 4,
53 GD_INCORRECT_DEVICE_ID = 5
54 } GD_RES_CODE;
55 #endif
56
64 typedef enum{
65 void_type = 0,
66
67 char_type = 1,
68
69 int_type = 2,
70 int8_type = 3,
71 int16_type = 4,
72 int32_type = 5,
73
74 uint_type = 6,
75 uint8_type = 7,
76 uint16_type = 8,
77 uint32_type = 9,
78
79 float_type = 10,
80
81 group_type = 11,
82 } GD_DATA_TYPE;
83
84
94 typedef union{
95 char data_char;
96
97 int data_int; // Process as 32 bit. If not it is Your problem
98 int8_t data_int8;
99 int16_t data_int16;
100 int32_t data_int32;
101
102 #ifndef uint // For case, that uint is not defined
103 #define uint unsigned int
104 #endif
105 uint data_uint; // Process as 32 bit. If not it is Your problem
106 uint8_t data_uint8;
107 uint16_t data_uint16;
108 uint32_t data_uint32;
109
110 float data_float;
111 } GD_DATA_VALUE;
112
120 typedef struct{
121 uint16_t i_cmd_id; // Command ID
122 char c_name[GD_MAX_STRING_SIZE]; // Function name
123 char c_descriptor[GD_MAX_STRING_SIZE]; // Descriptor
124 GD_DATA_TYPE e_in_data_type; // Select input data type
125 GD_DATA_VALUE u_in_min_value; // Minimal input value
126 GD_DATA_VALUE u_in_max_value; // Maximal input value
127
128 GD_DATA_TYPE e_out_data_type; // Select output data type
129 GD_DATA_VALUE u_out_min_value; // Minimal output value
130 GD_DATA_VALUE u_out_max_value; // Maximal output value
131 GD_DATA_VALUE *p_out_value; // Pointer to actual (output) value
132
133 GD_RES_CODE (*p_funtion)(void); // Pointer to function
134 }gd_config_struct;
135
136
149 typedef struct{
150 // Maximal command ID - never should exceed 0xFFFE !!!
151 uint16_t i_max_cmd_ID;
152
153 // Description of device
154 char c_description[GD_MAX_STRING_SIZE];
155
156 gd_config_struct* p_config_table; // Pointer to configuration table
157 uint8_t i_serial; // Serial number
158 }gd_metadata;
159
160 //=================================| Macros |==================================
161 // If AVR8 architecture
162 #ifdef __AVR_ARCH__
163 #define gd_read_byte_ro_mem(p_address) pgm_read_byte(p_address)
164 #define gd_read_word_ro_mem(p_address) pgm_read_word(p_address)
165 #define gd_read_dword_ro_mem(p_address) pgm_read_dword(p_address)
166 #else // Else different architecture
167 #define gd_read_byte_ro_mem(p_address) *(p_address)
168 #define gd_read_word_ro_mem(p_address) *(p_address)
169 #define gd_read_dword_ro_mem(p_address) *(p_address)
170 #endif
171
172 // Create pointer according to pointer size (architecture)
173 #define GD_POINTER_TO_FUNCTION \
174 switch(sizeof(p_size)) \
175 { \
176 case 1: \
177 p_func = (void*) gd_read_byte_ro_mem(&p_flash->p_funtion); \
178 break; \
179 case 2: \
180 p_func = (void*) gd_read_word_ro_mem(&p_flash->p_funtion); \
181 break; \
182 case 4: \
183 p_func = (void*) gd_read_dword_ro_mem(&p_flash->p_funtion); \
184 break; \
185 default: \
186 while(1); \
187 }
188
189 //============================| Global variables |=============================
190 extern volatile GD_DATA_VALUE gd_void_value;
191
192 //===========================| Function prototypes |===========================
193 GD_RES_CODE gd_get_setting(const gd_metadata *p_metadata,
194 uint16_t i_cmd_ID,
195 gd_config_struct *p_config_table);
196
197 GD_RES_CODE gd_set_setting(const gd_metadata *p_metadata,
198 uint16_t i_cmd_ID,
199 GD_DATA_VALUE i_data);
200
201 GD_RES_CODE gd_void_function(void);
202 #endif