File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,19 @@ static serial_t *tx_callback_obj[UART_NUM];
104
104
105
105
static serial_t serial_debug = { .uart = NP , .index = UART_NUM };
106
106
107
+ /* Aim of the function is to get serial_s pointer using huart pointer */
108
+ /* Highly inspired from magical linux kernel's "container_of" */
109
+ serial_t * get_serial_obj (UART_HandleTypeDef * huart )
110
+ {
111
+ struct serial_s * obj_s ;
112
+ serial_t * obj ;
113
+
114
+ obj_s = (struct serial_s * )((char * )huart - offsetof(struct serial_s , handle ));
115
+ obj = (serial_t * )((char * )obj_s - offsetof(serial_t , uart ));
116
+
117
+ return (obj );
118
+ }
119
+
107
120
/**
108
121
* @brief Function called to initialize the uart interface
109
122
* @param obj : pointer to serial_t structure
Original file line number Diff line number Diff line change @@ -53,6 +53,11 @@ extern "C" {
53
53
typedef struct serial_s serial_t ;
54
54
55
55
struct serial_s {
56
+ /* The 1st 2 members USART_TypeDef *uart
57
+ * and UART_HandleTypeDef handle should
58
+ * be kept as the first members of this struct
59
+ * to have get_serial_obj() function work as expected
60
+ */
56
61
USART_TypeDef * uart ;
57
62
UART_HandleTypeDef handle ;
58
63
uint32_t baudrate ;
You can’t perform that action at this time.
0 commit comments