Lines Matching full:ctx

29 static void adc_context_start_sampling(struct adc_context *ctx);
30 static void adc_context_update_buffer_pointer(struct adc_context *ctx,
38 static void adc_context_enable_timer(struct adc_context *ctx);
39 static void adc_context_disable_timer(struct adc_context *ctx);
48 static void adc_context_on_complete(struct adc_context *ctx, int status);
92 static inline void adc_context_init(struct adc_context *ctx) in adc_context_init() argument
95 k_timer_init(&ctx->timer, adc_context_on_timer_expired, NULL); in adc_context_init()
97 k_sem_init(&ctx->lock, 0, 1); in adc_context_init()
98 k_sem_init(&ctx->sync, 0, 1); in adc_context_init()
101 static inline void adc_context_request_next_sampling(struct adc_context *ctx) in adc_context_request_next_sampling() argument
103 if (atomic_inc(&ctx->sampling_requested) == 0) { in adc_context_request_next_sampling()
104 adc_context_start_sampling(ctx); in adc_context_request_next_sampling()
113 ctx->status = -EBUSY; in adc_context_request_next_sampling()
118 static inline void adc_context_enable_timer(struct adc_context *ctx) in adc_context_enable_timer() argument
120 k_timer_start(&ctx->timer, K_NO_WAIT, K_USEC(ctx->options.interval_us)); in adc_context_enable_timer()
123 static inline void adc_context_disable_timer(struct adc_context *ctx) in adc_context_disable_timer() argument
125 k_timer_stop(&ctx->timer); in adc_context_disable_timer()
130 struct adc_context *ctx = in adc_context_on_timer_expired() local
133 adc_context_request_next_sampling(ctx); in adc_context_on_timer_expired()
137 static inline void adc_context_lock(struct adc_context *ctx, in adc_context_lock() argument
141 k_sem_take(&ctx->lock, K_FOREVER); in adc_context_lock()
144 ctx->asynchronous = asynchronous; in adc_context_lock()
145 ctx->signal = signal; in adc_context_lock()
149 static inline void adc_context_release(struct adc_context *ctx, int status) in adc_context_release() argument
152 if (ctx->asynchronous && (status == 0)) { in adc_context_release()
157 k_sem_give(&ctx->lock); in adc_context_release()
160 static inline void adc_context_unlock_unconditionally(struct adc_context *ctx) in adc_context_unlock_unconditionally() argument
162 if (!k_sem_count_get(&ctx->lock)) { in adc_context_unlock_unconditionally()
163 k_sem_give(&ctx->lock); in adc_context_unlock_unconditionally()
167 static inline int adc_context_wait_for_completion(struct adc_context *ctx) in adc_context_wait_for_completion() argument
170 if (ctx->asynchronous) { in adc_context_wait_for_completion()
175 int status = k_sem_take(&ctx->sync, ADC_CONTEXT_WAIT_FOR_COMPLETION_TIMEOUT); in adc_context_wait_for_completion()
178 ctx->status = status; in adc_context_wait_for_completion()
181 return ctx->status; in adc_context_wait_for_completion()
184 static inline void adc_context_complete(struct adc_context *ctx, int status) in adc_context_complete() argument
187 adc_context_on_complete(ctx, status); in adc_context_complete()
191 if (ctx->asynchronous) { in adc_context_complete()
192 if (ctx->signal) { in adc_context_complete()
193 k_poll_signal_raise(ctx->signal, status); in adc_context_complete()
196 k_sem_give(&ctx->lock); in adc_context_complete()
207 ctx->status = status; in adc_context_complete()
209 k_sem_give(&ctx->sync); in adc_context_complete()
212 static inline void adc_context_start_read(struct adc_context *ctx, in adc_context_start_read() argument
215 ctx->sequence = *sequence; in adc_context_start_read()
216 ctx->status = 0; in adc_context_start_read()
219 ctx->options = *sequence->options; in adc_context_start_read()
220 ctx->sequence.options = &ctx->options; in adc_context_start_read()
221 ctx->sampling_index = 0U; in adc_context_start_read()
223 if (ctx->options.interval_us != 0U) { in adc_context_start_read()
224 atomic_set(&ctx->sampling_requested, 0); in adc_context_start_read()
225 adc_context_enable_timer(ctx); in adc_context_start_read()
230 adc_context_start_sampling(ctx); in adc_context_start_read()
238 static inline void adc_context_on_sampling_done(struct adc_context *ctx, in adc_context_on_sampling_done() argument
241 if (ctx->sequence.options) { in adc_context_on_sampling_done()
242 adc_sequence_callback callback = ctx->options.callback; in adc_context_on_sampling_done()
249 &ctx->sequence, in adc_context_on_sampling_done()
250 ctx->sampling_index); in adc_context_on_sampling_done()
263 if (ctx->sampling_index < in adc_context_on_sampling_done()
264 ctx->options.extra_samplings) { in adc_context_on_sampling_done()
265 ++ctx->sampling_index; in adc_context_on_sampling_done()
272 adc_context_update_buffer_pointer(ctx, repeat); in adc_context_on_sampling_done()
279 if (ctx->options.interval_us == 0U) { in adc_context_on_sampling_done()
280 adc_context_start_sampling(ctx); in adc_context_on_sampling_done()
281 } else if (atomic_dec(&ctx->sampling_requested) > 1) { in adc_context_on_sampling_done()
282 adc_context_start_sampling(ctx); in adc_context_on_sampling_done()
288 if (ctx->options.interval_us != 0U) { in adc_context_on_sampling_done()
289 adc_context_disable_timer(ctx); in adc_context_on_sampling_done()
293 adc_context_complete(ctx, 0); in adc_context_on_sampling_done()