1 /* 2 * Copyright 2023-2024 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef _OSA_ZEPHYR_H_ 9 #define _OSA_ZEPHYR_H_ 10 11 #include <zephyr/kernel.h> 12 13 //#define CONFIG_MEM_POOLS 1 14 15 //#include <mem_pool_config.h> 16 17 /*** Timer Management ***/ 18 19 struct timer_data; 20 21 typedef struct timer_data *os_timer_t; 22 typedef os_timer_t osa_timer_arg_t; 23 typedef int osa_timer_tick; 24 25 /** OS Timer data structure 26 */ 27 struct timer_data 28 { 29 void (*callback)(osa_timer_arg_t); 30 void *user_arg; 31 int period; 32 int reload_options; 33 struct k_timer timer; 34 struct k_work work; 35 }; 36 37 /** 38 * OS Timer Activate Options 39 */ 40 typedef enum osa_timer_activation 41 { 42 /** Start the timer on creation. */ 43 OSA_TIMER_AUTO_ACTIVATE, 44 /** Do not start the timer on creation. */ 45 OSA_TIMER_NO_ACTIVATE, 46 } osa_timer_activate_t; 47 48 /*! @brief Converts milliseconds to ticks*/ 49 #define MSEC_TO_TICK(msec) k_ms_to_ticks_floor32(msec) 50 51 OSA_TicksGet(void)52static inline unsigned OSA_TicksGet(void) 53 { 54 return sys_clock_tick_get(); 55 56 } 57 OSA_MsecToTicks(uint32_t msecs)58static inline uint32_t OSA_MsecToTicks(uint32_t msecs) 59 { 60 return k_ms_to_ticks_floor32(msecs); 61 } 62 OSA_TicksToMsec(unsigned long ticks)63static inline unsigned long OSA_TicksToMsec(unsigned long ticks) 64 { 65 return k_ticks_to_ms_floor32(ticks); 66 } 67 OSA_LockSchedule(void)68static inline void OSA_LockSchedule(void) 69 { 70 k_sched_lock(); 71 } 72 OSA_UnlockSchedule(void)73static inline void OSA_UnlockSchedule(void) 74 { 75 k_sched_unlock(); 76 } 77 OSA_IsISR()78static inline bool OSA_IsISR() 79 { 80 return k_is_in_isr(); 81 } 82 /** 83 * \def os_get_runtime_stats(__buff__) 84 * 85 * Get ASCII formatted run time statistics 86 * 87 * Please ensure that your buffer is big enough for the formatted data to 88 * fit. Failing to do this may cause memory data corruption. 89 */ 90 #define OSA_GetRuntimeStats(__buff__) 91 92 /** 93 * \def os_get_task_list(__buff__) 94 * 95 * Get ASCII formatted task list 96 * 97 * Please ensure that your buffer is big enough for the formatted data to 98 * fit. Failing to do this may cause memory data corruption. 99 */ 100 101 #define OSA_GetTaskList(__buff__) 102 103 #endif /* ! _OSA_ZEPHYR_H_ */ 104