2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 * os_utils.h - system layer function declare
26 /* building ***************************************************/
28 #if MQX_USE_UNCACHED_MEM && PSP_HAS_DATA_CACHE
29 #define PCM_mem_alloc_uncached(n) _mem_alloc_system_uncached(n)
30 #define PCM_mem_alloc_uncached_zero(n) _mem_alloc_system_zero_uncached(n)
31 #define PCM_mem_alloc_uncached_align(n,a) _mem_alloc_align_uncached(n,a)
33 #define PCM_mem_alloc_uncached(n) _mem_alloc_system(n)
34 #define PCM_mem_alloc_uncached_zero(n) _mem_alloc_system_zero(n)
35 #define PCM_mem_alloc_uncached_align(n,a) _mem_alloc_align(n,a)
36 #endif /* PSP_HAS_DATA_CACHE */
38 #define PCM_mem_alloc(n) _mem_alloc_system(n)
39 #define PCM_mem_alloc_zero(n) _mem_alloc_system_zero(n)
40 #define PCM_mem_alloc_align(n,a) _mem_alloc_align(n,a)
42 #define PCM_mem_free(ptr) _mem_free(ptr)
43 #define PCM_mem_zero(ptr,n) _mem_zero(ptr,n)
44 #define PCM_mem_copy(src,dst,n) _mem_copy(src,dst,n)
46 #define os_memcpy memcpy
47 #define os_memset memset
48 #define os_malloc malloc
50 #define os_zalloc PCM_mem_alloc_zero
53 #define PCM_lock() sco_pcm_lock()
54 #define PCM_unlock() sco_pcm_unlock()
56 #define snd_pcm_stream_lock_irq(substream) \
62 #define snd_pcm_stream_unlock_irq(substream) \
68 #define snd_pcm_stream_lock_irqsave(substream, flags) \
74 #define snd_pcm_stream_unlock_irqrestore(runtime, flags) \
81 #define __stringify_1(x...) #x
82 #define __stringify(x...) __stringify_1(x)
84 #define halt() do { for(;;); } while (0)
85 #define ASSERT(x) do { if (!(x)) { dbgPrintf("%s:%d ASSERT failed: %s\n", __FILE__, __LINE__, #x); halt(); } } while (0)
88 #define snd_BUG_ON(cond) \
90 if(cond) printf(1, __FILE__, __LINE__, "BUG? (%s)\n", __stringify(cond)); \
93 static inline int snd_BUG_ON(int cond
)
95 if(cond
) printf("BUG? in file %s:%d \n", __FILE__
, __LINE__
);
100 /* If you are writing a driver, please use dev_dbg instead */
101 #if defined(OS_DEBUG)
102 #define pr_debug(fmt, ...) \
103 printf(pr_fmt(fmt), ##__VA_ARGS__)
104 #define pr_warning(fmt, ...) \
105 printf(pr_fmt(fmt), ##__VA_ARGS__)
106 #define pr_warn pr_warning
107 #define os_printf(fmt, ...) \
108 printf(pr_fmt(fmt), ##__VA_ARGS__)
110 #define pr_debug(fmt, ...)
111 #define pr_warning(fmt, ...)
113 #define os_printf(fmt, ...)
117 #define pr_fmt(fmt) fmt
120 #define pr_err(fmt, ...) \
121 printf(pr_fmt(fmt), ##__VA_ARGS__)
123 #define USHRT_MAX ((u16)(~0U))
124 #define SHRT_MAX ((s16)(USHRT_MAX>>1))
125 #define SHRT_MIN ((s16)(-SHRT_MAX - 1))
126 #define INT_MAX ((int)(~0U>>1))
127 #define INT_MIN (-INT_MAX - 1)
128 #define UINT_MAX (~0U)
129 #define LONG_MAX ((long)(~0UL>>1))
130 #define LONG_MIN (-LONG_MAX - 1)
131 #define ULONG_MAX (~0UL)
132 #define LLONG_MAX ((long long)(~0ULL>>1))
133 #define LLONG_MIN (-LLONG_MAX - 1)
134 #define ULLONG_MAX (~0ULL)
137 #define min(x, y) (x < y ? x : y)
140 #define max(x, y) (x > y ? x : y)
143 #define ULONG_MAX (~0UL)
144 #define LONG_MAX ((long)(~0UL>>1))
145 /* building ***************************************************/
147 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) /*+ __must_be_array(arr)*/)
149 /* critial , mutex */
150 //#define OS_DEFINE_MUTEX
151 #define os_mutex_init
152 #define os_mutex_lock
153 #define os_mutex_unlock
156 #define writeb(v,a) (*(volatile unsigned char __force *)(a) = (v))
157 #define writew(v,a) (*(volatile unsigned short __force *)(a) = (v))
158 #define writel(v,a) (*(volatile unsigned int __force *)(a) = (v))
160 #define readb(a) (*(volatile unsigned char __force *)(a))
161 #define readw(a) (*(volatile unsigned short __force *)(a))
162 #define readl(a) (*(volatile unsigned int __force *)(a))
164 /* ticks implement move to soc-codec */
166 #define os_msleep sco_msleep
167 #define os_get_ticks_interval // sco_get_ticks_interval
169 static inline uint8_t ffs(unsigned int val
)
172 for(i
= 0; i
< 32; i
++) {
183 /* for sgtl5000 internal power */
184 static inline uint16_t clamp(uint16_t val
,uint16_t min
,uint16_t max
)
186 uint16_t __val
= (val
);
187 uint16_t __min
= (min
);
188 uint16_t __max
= (max
);
189 __val
= __val
< __min
? __min
: __val
;
190 return (__val
> __max
? __max
: __val
);
193 static inline unsigned int ld2(uint32_t v
)
218 #endif /* OS_UTILS_H */