4 #include "fm_typedef.h"
8 * Base structure of fm object
10 #define FM_NAME_MAX 20
12 fm_s8 name[FM_NAME_MAX+1]; // name of fm object
13 fm_u8 type; // type of fm object
14 fm_u8 flag; // flag of fm object
17 //struct fm_list *list; // list node of fm object
31 fm_s32 (*input)(struct fm_fifo *thiz, void *item);
32 fm_s32 (*output)(struct fm_fifo *thiz, void *item);
33 fm_bool (*is_full)(struct fm_fifo *thiz);
34 fm_bool (*is_empty)(struct fm_fifo *thiz);
35 fm_s32 (*get_total_len)(struct fm_fifo *thiz);
36 fm_s32 (*get_valid_len)(struct fm_fifo *thiz);
37 fm_s32 (*reset)(struct fm_fifo *thiz);
40 extern struct fm_fifo* fm_fifo_init(struct fm_fifo* fifo, void *buf, const fm_s8 *name, fm_s32 item_size, fm_s32 item_num);
42 extern struct fm_fifo* fm_fifo_create(const fm_s8 *name, fm_s32 item_size, fm_s32 item_num);
44 extern fm_s32 fm_fifo_release(struct fm_fifo *fifo);
46 #define FM_FIFO_INPUT(fifop, item) \
48 fm_s32 __ret = (fm_s32)0; \
49 if(fifop && (fifop)->input){ \
50 __ret = (fifop)->input(fifop, item); \
55 #define FM_FIFO_OUTPUT(fifop, item) \
57 fm_s32 __ret = (fm_s32)0; \
58 if(fifop && (fifop)->output){ \
59 __ret = (fifop)->output(fifop, item); \
64 #define FM_FIFO_IS_FULL(fifop) \
66 fm_bool __ret = fm_false; \
67 if(fifop && (fifop)->is_full){ \
68 __ret = (fifop)->is_full(fifop); \
73 #define FM_FIFO_IS_EMPTY(fifop) \
75 fm_bool __ret = fm_false; \
76 if(fifop && (fifop)->is_empty){ \
77 __ret = (fifop)->is_empty(fifop); \
82 #define FM_FIFO_RESET(fifop) \
84 fm_s32 __ret = (fm_s32)0; \
85 if(fifop && (fifop)->reset){ \
86 __ret = (fifop)->reset(fifop); \
91 #define FM_FIFO_GET_TOTAL_LEN(fifop) \
93 fm_s32 __ret = (fm_s32)0; \
94 if(fifop && (fifop)->get_total_len){ \
95 __ret = (fifop)->get_total_len(fifop); \
100 #define FM_FIFO_GET_VALID_LEN(fifop) \
102 fm_s32 __ret = (fm_s32)0; \
103 if(fifop && (fifop)->get_valid_len){ \
104 __ret = (fifop)->get_valid_len(fifop); \
111 * FM asynchronous information mechanism
113 struct fm_flag_event {
115 fm_s8 name[FM_NAME_MAX+1];
118 volatile fm_u32 flag;
121 fm_u32(*send)(struct fm_flag_event* thiz, fm_u32 mask);
122 fm_s32(*wait)(struct fm_flag_event* thiz, fm_u32 mask);
123 long(*wait_timeout)(struct fm_flag_event* thiz, fm_u32 mask, long timeout);
124 fm_u32(*clr)(struct fm_flag_event* thiz, fm_u32 mask);
125 fm_u32(*get)(struct fm_flag_event* thiz);
126 fm_u32(*rst)(struct fm_flag_event* thiz);
129 extern struct fm_flag_event* fm_flag_event_create(const fm_s8 *name);
131 extern fm_s32 fm_flag_event_get(struct fm_flag_event *thiz);
133 extern fm_s32 fm_flag_event_put(struct fm_flag_event *thiz);
135 #define FM_EVENT_SEND(eventp, mask) \
137 fm_u32 __ret = (fm_u32)0; \
138 if(eventp && (eventp)->send){ \
139 __ret = (eventp)->send(eventp, mask); \
144 #define FM_EVENT_WAIT(eventp, mask) \
146 fm_s32 __ret = (fm_s32)0; \
147 if(eventp && (eventp)->wait){ \
148 __ret = (eventp)->wait(eventp, mask); \
153 #define FM_EVENT_WAIT_TIMEOUT(eventp, mask, timeout) \
155 long __ret = (long)0; \
156 if(eventp && (eventp)->wait_timeout){ \
157 __ret = (eventp)->wait_timeout(eventp, mask, timeout); \
162 #define FM_EVENT_GET(eventp) \
164 fm_u32 __ret = (fm_u32)0; \
165 if(eventp && (eventp)->get){ \
166 __ret = (eventp)->get(eventp); \
171 #define FM_EVENT_RESET(eventp) \
173 fm_u32 __ret = (fm_u32)0; \
174 if(eventp && (eventp)->rst){ \
175 __ret = (eventp)->rst(eventp); \
180 #define FM_EVENT_CLR(eventp, mask) \
182 fm_u32 __ret = (fm_u32)0; \
183 if(eventp && (eventp)->clr){ \
184 __ret = (eventp)->clr(eventp, mask); \
193 fm_s8 name[FM_NAME_MAX+1];
198 fm_s32(*lock)(struct fm_lock* thiz);
199 fm_s32(*trylock)(struct fm_lock *thiz,fm_s32 retryCnt);
200 fm_s32(*unlock)(struct fm_lock* thiz);
203 extern struct fm_lock* fm_lock_create(const fm_s8 *name);
205 extern fm_s32 fm_lock_get(struct fm_lock *thiz);
207 extern fm_s32 fm_lock_put(struct fm_lock *thiz);
209 extern struct fm_lock* fm_spin_lock_create(const fm_s8 *name);
211 extern fm_s32 fm_spin_lock_get(struct fm_lock *thiz);
213 extern fm_s32 fm_spin_lock_put(struct fm_lock *thiz);
217 fm_s32 __ret = (fm_s32)0; \
218 if(a && (a)->lock){ \
219 __ret = (a)->lock(a); \
224 #define FM_UNLOCK(a) \
236 FM_TIMER_CTRL_GET_TIME = 0,
237 FM_TIMER_CTRL_SET_TIME = 1,
241 #define FM_TIMER_FLAG_ACTIVATED (1<<0)
245 fm_s8 name[FM_NAME_MAX+1];
246 void *priv; // platform detail impliment
248 fm_s32 flag; // timer active/inactive
249 void (*timeout_func)(unsigned long data); // timeout function
250 unsigned long data; // timeout function's parameter
251 signed long timeout_ms; // timeout tick
253 volatile fm_u32 count;
254 volatile fm_u8 tx_pwr_ctrl_en;
255 volatile fm_u8 tx_rtc_ctrl_en;
256 volatile fm_u8 tx_desense_en;
259 fm_s32(*init)(struct fm_timer *thiz, void (*timeout)(unsigned long data), unsigned long data, signed long time, fm_s32 flag);
260 fm_s32(*start)(struct fm_timer *thiz);
261 fm_s32(*update)(struct fm_timer *thiz);
262 fm_s32(*stop)(struct fm_timer *thiz);
263 fm_s32(*control)(struct fm_timer *thiz, enum fm_timer_ctrl cmd, void* arg);
266 extern struct fm_timer* fm_timer_create(const fm_s8 *name);
268 extern fm_s32 fm_timer_get(struct fm_timer *thiz);
270 extern fm_s32 fm_timer_put(struct fm_timer *thiz);
273 * FM work thread mechanism
277 fm_s8 name[FM_NAME_MAX+1];
280 void (*work_func)(unsigned long data);
283 fm_s32(*init)(struct fm_work *thiz, void (*work_func)(unsigned long data), unsigned long data);
286 extern struct fm_work* fm_work_create(const fm_s8 *name);
288 extern fm_s32 fm_work_get(struct fm_work *thiz);
290 extern fm_s32 fm_work_put(struct fm_work *thiz);
293 struct fm_workthread {
295 fm_s8 name[FM_NAME_MAX+1];
299 fm_s32(*add_work)(struct fm_workthread *thiz, struct fm_work *work);
302 extern struct fm_workthread* fm_workthread_create(const fm_s8* name);
304 extern fm_s32 fm_workthread_get(struct fm_workthread *thiz);
306 extern fm_s32 fm_workthread_put(struct fm_workthread *thiz);
308 #endif //__FM_UTILS_H__