1 /* 2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 */ 4 5 #ifndef WORK_H 6 #define WORK_H 7 8 #if defined(__cplusplus) 9 extern "C" 10 { 11 #endif 12 13 #include "ble_os.h" 14 15 struct k_work_q { 16 struct k_queue queue; 17 }; 18 19 int k_work_q_start(); 20 21 enum { 22 K_WORK_STATE_PENDING, 23 }; 24 struct k_work; 25 /* work define*/ 26 typedef void (*k_work_handler_t)(struct k_work *work); 27 28 struct k_work { 29 void *_reserved; 30 k_work_handler_t handler; 31 atomic_t flags[1]; 32 uint32_t start_ms; 33 uint32_t timeout; 34 int index; 35 }; 36 37 #define _K_WORK_INITIALIZER(work_handler) \ 38 { \ 39 ._reserved = NULL, \ 40 .handler = work_handler, \ 41 .flags = { 0 } \ 42 } 43 44 #define K_WORK_INITIALIZER DEPRECATED_MACRO _K_WORK_INITIALIZER 45 46 int k_work_init(struct k_work *work, k_work_handler_t handler); 47 void k_work_submit(struct k_work *work); 48 49 50 /*delay work define*/ 51 struct k_delayed_work { 52 struct k_work work; 53 }; 54 55 void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler); 56 int k_delayed_work_submit(struct k_delayed_work *work, uint32_t delay); 57 int k_delayed_work_cancel(struct k_delayed_work *work); 58 int k_delayed_work_remaining_get(struct k_delayed_work *work); 59 60 #ifdef __cplusplus 61 } 62 #endif 63 64 #endif /* WORK_H */ 65 66