1 /*
2  * Copyright (C) 2015-2018 Alibaba Group Holding Limited
3  */
4 
5 #ifndef AUXILIARY_H
6 #define AUXILIARY_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <ulog/ulog.h>
13 
14 #define MODBUS_MOUDLE "modbusm"
15 /* forward declaration */
16 typedef enum mb_status mb_status_t;
17 typedef struct mb_handler mb_handler_t;
18 
19 #define MB_CRITICAL_ALLOC() CPSR_ALLOC()
20 #define MB_CRITICAL_ENTER() RHINO_CRITICAL_ENTER()
21 #define MB_CRITICAL_EXIT()  RHINO_CRITICAL_EXIT()
22 
23 #define MB_MUTEX_T             kmutex_t
24 #define MB_MUTEX_CREATE(mutex) mb_mutex_create(mutex)
25 #define MB_MUTEX_LOCK(mutex)   mb_mutex_lock(mutex)
26 #define MB_MUTEX_UNLOCK(mutex) mb_mutex_unlock(mutex)
27 #define MB_MUTEX_DEL(mutex)    mb_mutex_del(mutex)
28 
29 #ifndef htobe16
30 #define htobe16(X) (((X >> 8) & 0x00ff) | ((X << 8) & 0xff00))
31 #endif
32 
33 #ifndef betoh16
34 #define betoh16(X) (((X >> 8) & 0x00ff) | ((X << 8) & 0xff00))
35 #endif
36 
37 uint8_t *status_to_string(mb_status_t status);
38 
39 mb_handler_t *mb_alloc_handler();
40 void mb_free_handler(mb_handler_t *handler);
41 
42 mb_status_t mb_mutex_create(MB_MUTEX_T *mutex);
43 mb_status_t mb_mutex_lock(MB_MUTEX_T *mutex);
44 mb_status_t mb_mutex_unlock(MB_MUTEX_T *mutex);
45 mb_status_t mb_mutex_del(MB_MUTEX_T *mutex);
46 
47 #ifdef __cplusplus
48 }
49 #endif
50 
51 #endif /* AUXILIARY_H */
52