VSF Documented
vsf_arch_abstraction.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_ARCH_ABSTRACTION_H__
19#define __VSF_ARCH_ABSTRACTION_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "hal/vsf_hal_cfg.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/*============================ MACROS ========================================*/
31
32#ifndef __LITTLE_ENDIAN
33# define __LITTLE_ENDIAN 1234
34#endif
35#ifndef __BIG_ENDIAN
36# define __BIG_ENDIAN 4321
37#endif
38
41#define VSF_SYSTIMER_IMPL_NONE 0
42#define VSF_SYSTIMER_IMPL_REQUEST_RESPONSE 1
43#define VSF_SYSTIMER_IMPL_WITH_NORMAL_TIMER 2
44#define VSF_SYSTIMER_IMPL_WITH_COMP_TIMER 3
45#define VSF_SYSTIMER_IMPL_TICK_MODE 4
47
48/*============================ MACROFIED FUNCTIONS ===========================*/
49
50#ifndef VSF_ARCH_ASSERT
51# define VSF_ARCH_ASSERT(...) VSF_ASSERT(__VA_ARGS__)
52#endif
53
54/*============================ TYPES =========================================*/
55
56/*\note generic prototypes MUST be defined before including the arch header. */
57typedef void vsf_irq_handler_t(void *p);
59
61typedef struct vsf_protect_region_t {
63 void (*leave)(vsf_protect_t orig);
65
71};
72
73/*============================ GLOBAL VARIABLES ==============================*/
74
77
78/*============================ LOCAL VARIABLES ===============================*/
79
80#ifdef __cplusplus
81}
82#endif
83
84/*============================ INCLUDES ======================================*/
85
86#if !defined(VSF_ARCH_HEADER)
88# if defined(__RTOS__)
89# define VSF_ARCH_HEADER "./rtos/rtos_generic.h"
90# elif defined(__CPU_GENERIC__)
91# if defined(__MACOS__)
92# define VSF_ARCH_HEADER "./generic/macos/macos_generic.h"
93# elif defined(__LINUX__)
94# define VSF_ARCH_HEADER "./generic/linux/linux_generic.h"
95# else
96# error not supported generic arch
97# endif
98# elif (defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M') || __TARGET_PROFILE_M
99# define VSF_ARCH_HEADER "./arm/cortex-m/cortex_m_generic.h"
100# elif defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'A' || __TARGET_PROFILE_A
101# define VSF_ARCH_HEADER "./arm/cortex-a/cortex_a_generic.h"
102# elif defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'R' || __TARGET_PROFILE_R
103# define VSF_ARCH_HEADER "./arm/cortex-r/cortex_r_generic.h"
104// check __WIN__ before __LINUX__ because some software(like SDL2) will define __LINUX__
105# elif (defined(__CPU_X86__) || defined(__CPU_X64__)) && defined(__WIN__)
106# define VSF_ARCH_HEADER "./x86/win/win_generic.h"
107# elif (defined(__CPU_X86__) || defined(__CPU_X64__) || defined(__CPU_WEBASSEMBLY__)) && defined(__LINUX__)
108# define VSF_ARCH_HEADER "./generic/linux/linux_generic.h"
109# elif defined(__CPU_MCS51__)
110# define VSF_ARCH_HEADER "./mcs51/mcs51_generic.h"
111# elif defined(__CPU_RV__) || defined(__CPU_RISCV__)
112# define VSF_ARCH_HEADER "./rv/rv_generic.h"
113# elif defined(__CPU_ARM9__)
114# define VSF_ARCH_HEADER "./arm/arm9/arm9_generic.h"
115# else
116# warning no supported architecture found, use default arch template!
117# define VSF_ARCH_HEADER "./template/template_generic.h"
118# endif
119#endif
120#include VSF_ARCH_HEADER
121
122#ifdef __cplusplus
123extern "C" {
124#endif
125
126/*============================ MACROS ========================================*/
127
128#ifndef VSF_ARCH_SWI_NUM
129# define VSF_ARCH_SWI_NUM 0
130#endif
131#ifndef VSF_DEV_SWI_NUM
132# define VSF_DEV_SWI_NUM 0
133#endif
134
135#ifndef __BYTE_ORDER
136# error "__BYTE_ORDER MUST be defined in arch"
137#endif
138
139#define VSF_SWI_NUM (VSF_ARCH_SWI_NUM + VSF_DEV_SWI_NUM)
140
141#define ___constant_swab16(__x) ((uint16_t)( \
142 (((uint16_t)(__x) & (uint16_t)0x00FFU) << 8) | \
143 (((uint16_t)(__x) & (uint16_t)0xFF00U) >> 8)))
144
145#define ___constant_swab32(__x) ((uint32_t)( \
146 (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
147 (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
148 (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
149 (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24)))
150
151#define ___constant_swab64(__x) ((uint64_t)( \
152 (((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
153 (((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
154 (((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
155 (((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
156 (((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
157 (((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
158 (((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
159 (((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56)))
160
161#define bswap16 bswap_16
162#define bswap32 bswap_32
163#define bswap64 bswap_64
164#if __BYTE_ORDER == __BIG_ENDIAN
165# ifndef htobe16
166# define htobe16
167# endif
168# ifndef htole16
169# define htole16 bswap_16
170# endif
171# ifndef be16toh
172# define be16toh
173# endif
174# ifndef le16toh
175# define le16toh bswap_16
176# endif
177# ifndef htobe32
178# define htobe32
179# endif
180# ifndef htole32
181# define htole32 bswap_32
182# endif
183# ifndef be32toh
184# define be32toh
185# endif
186# ifndef le32toh
187# define le32toh bswap_32
188# endif
189# ifndef htobe64
190# define htobe64
191# endif
192# ifndef htole64
193# define htole64 bswap_64
194# endif
195# ifndef be64toh
196# define be64toh
197# endif
198# ifndef le64toh
199# define le64toh bswap_64
200# endif
201
202# define cpu_to_le16 bswap_16
203# define cpu_to_le32 bswap_32
204# define cpu_to_le64 bswap_64
205# define le16_to_cpu bswap_16
206# define le32_to_cpu bswap_32
207# define le64_to_cpu bswap_64
208# define cpu_to_be16
209# define cpu_to_be32
210# define cpu_to_be64
211# define be16_to_cpu
212# define be32_to_cpu
213# define be64_to_cpu
214
215# define __constant_cpu_to_le16 ___constant_swab16
216# define __constant_le16_to_cpu ___constant_swab16
217# define __constant_cpu_to_le32 ___constant_swab32
218# define __constant_le32_to_cpu ___constant_swab32
219# define __constant_cpu_to_le64 ___constant_swab64
220# define __constant_le64_to_cpu ___constant_swab64
221# define __constant_cpu_to_be16
222# define __constant_be16_to_cpu
223# define __constant_cpu_to_be32
224# define __constant_be32_to_cpu
225# define __constant_cpu_to_be64
226# define __constant_be64_to_cpu
227#else
228# ifndef htobe16
229# define htobe16 bswap_16
230# endif
231# ifndef htole16
232# define htole16
233# endif
234# ifndef be16toh
235# define be16toh bswap_16
236# endif
237# ifndef le16toh
238# define le16toh
239# endif
240# ifndef htobe32
241# define htobe32 bswap_32
242# endif
243# ifndef htole32
244# define htole32
245# endif
246# ifndef be32toh
247# define be32toh bswap_32
248# endif
249# ifndef le32toh
250# define le32toh
251# endif
252# ifndef htobe64
253# define htobe64 bswap_64
254# endif
255# ifndef htole64
256# define htole64
257# endif
258# ifndef be64toh
259# define be64toh bswap_64
260# endif
261# ifndef le64toh
262# define le64toh
263# endif
264
265# define cpu_to_le16
266# define cpu_to_le32
267# define cpu_to_le64
268# define le16_to_cpu
269# define le32_to_cpu
270# define le64_to_cpu
271# define cpu_to_be16 bswap_16
272# define cpu_to_be32 bswap_32
273# define cpu_to_be64 bswap_64
274# define be16_to_cpu bswap_16
275# define be32_to_cpu bswap_32
276# define be64_to_cpu bswap_64
277
278# define __constant_cpu_to_le16
279# define __constant_le16_to_cpu
280# define __constant_cpu_to_le32
281# define __constant_le32_to_cpu
282# define __constant_cpu_to_le64
283# define __constant_le64_to_cpu
284# define __constant_cpu_to_be16 ___constant_swab16
285# define __constant_be16_to_cpu ___constant_swab16
286# define __constant_cpu_to_be32 ___constant_swab32
287# define __constant_be32_to_cpu ___constant_swab32
288# define __constant_cpu_to_be64 ___constant_swab64
289# define __constant_be64_to_cpu ___constant_swab64
290#endif
291
292#define DECLARE_ENDIAN_FUNC(__bitlen) \
293extern uint_fast##__bitlen##_t cpu_to_le##__bitlen##p(uint##__bitlen##_t *); \
294extern uint_fast##__bitlen##_t cpu_to_be##__bitlen##p(uint##__bitlen##_t *); \
295extern uint_fast##__bitlen##_t le##__bitlen##_to_cpup(uint##__bitlen##_t *); \
296extern uint_fast##__bitlen##_t be##__bitlen##_to_cpup(uint##__bitlen##_t *); \
297extern void cpu_to_le##__bitlen##s(uint##__bitlen##_t *); \
298extern void cpu_to_be##__bitlen##s(uint##__bitlen##_t *); \
299extern void le##__bitlen##_to_cpus(uint##__bitlen##_t *); \
300extern void be##__bitlen##_to_cpus(uint##__bitlen##_t *); \
301extern uint_fast##__bitlen##_t get_unaligned_cpu##__bitlen(const void *); \
302extern uint_fast##__bitlen##_t get_unaligned_le##__bitlen(const void *); \
303extern uint_fast##__bitlen##_t get_unaligned_be##__bitlen(const void *); \
304extern void put_unaligned_cpu##__bitlen(uint_fast##__bitlen##_t, void *); \
305extern void put_unaligned_le##__bitlen(uint_fast##__bitlen##_t, void *); \
306extern void put_unaligned_be##__bitlen(uint_fast##__bitlen##_t, void *);
307
308#define __vsf_protect_region(__region) \
309 for (vsf_protect_t VSF_MACRO_SAFE_NAME(protect_status), \
310 VSF_MACRO_SAFE_NAME(local_cnt) = 1; \
311 (((__region) != NULL) && VSF_MACRO_SAFE_NAME(local_cnt)--) ? \
312 ((VSF_MACRO_SAFE_NAME(protect_status) = (__region)->enter()), true) : false;\
313 (__region)->leave(VSF_MACRO_SAFE_NAME(protect_status)))
314#define vsf_protect_region(__region) __vsf_protect_region(__region)
315#define vsf_protect_region_exit(__region) continue
316
317#define vsf_protect_region_simple(__region, ...) \
318 do { \
319 if (__region != NULL) { \
320 vsf_protect_t VSF_MACRO_SAFE_NAME(protect_status) = (__region)->enter();\
321 __VA_ARGS__; \
322 (__region)->leave(VSF_MACRO_SAFE_NAME(protect_status)); \
323 } \
324 } while (0);
325
330// Usage:
331// __vsf_interrupt_safe(code)
332#ifndef __vsf_interrupt_safe
333# if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__cplusplus)
334# define __vsf_interrupt_safe(__code) \
335 { \
336 vsf_gint_state_t VSF_MACRO_SAFE_NAME(gint_state) = vsf_disable_interrupt();\
337 __code; \
338 vsf_set_interrupt(VSF_MACRO_SAFE_NAME(gint_state)); \
339 }
340# else
341# define __vsf_interrupt_safe(...) \
342 { \
343 vsf_gint_state_t VSF_MACRO_SAFE_NAME(gint_state) = vsf_disable_interrupt();\
344 __VA_ARGS__; \
345 vsf_set_interrupt(VSF_MACRO_SAFE_NAME(gint_state)); \
346 }
347# endif
348#endif
349
350// Usage:
351// vsf_interrupt_safe() {
352// code
353// }
354#ifndef vsf_interrupt_safe
355# define vsf_interrupt_safe() vsf_protect_region(&vsf_protect_region_int)
356#endif
357
358
359// Usage:
360// vsf_interrupt_safe_simple(
361// code
362// )
363#ifndef vsf_interrupt_safe_simple
364
365# define vsf_interrupt_safe_simple(...) \
366 vsf_protect_region_simple(&vsf_protect_region_int, __VA_ARGS__)
367
368#endif
369
370
371#define vsf_protect_interrupt() vsf_disable_interrupt()
372#define vsf_unprotect_interrupt(__state) vsf_set_interrupt(__state)
373#define vsf_protect_none() (0)
374#define vsf_unprotect_none(__state) VSF_UNUSED_PARAM(__state)
375
376#define vsf_protect_int vsf_protect_interrupt
377#define vsf_unprotect_int vsf_unprotect_interrupt
378
379#define __vsf_protect(__type) vsf_protect_##__type
380#define __vsf_unprotect(__type) vsf_unprotect_##__type
381#define vsf_protect(__type) __vsf_protect(__type)
382#define vsf_unprotect(__type) __vsf_unprotect(__type)
383
384// atom
385
386#ifndef vsf_atom64_op
387# define vsf_atom64_op(__ptr, ...) \
388 ({ \
389 vsf_protect_t VSF_MACRO_SAFE_NAME(orig) = vsf_protect_int(); \
390 int64_t _ = (*(int64_t *)(__ptr)); \
391 *(int64_t *)(__ptr) = (__VA_ARGS__); \
392 vsf_unprotect_int(VSF_MACRO_SAFE_NAME(orig)); \
393 _; \
394 })
395#endif
396
397#ifndef vsf_atom32_op
398# define vsf_atom32_op(__ptr, ...) \
399 ({ \
400 vsf_protect_t VSF_MACRO_SAFE_NAME(orig) = vsf_protect_int(); \
401 int32_t _ = (*(int32_t *)(__ptr)); \
402 *(int32_t *)(__ptr) = (__VA_ARGS__); \
403 vsf_unprotect_int(VSF_MACRO_SAFE_NAME(orig)); \
404 _; \
405 })
406#endif
407
408#ifndef vsf_atom16_op
409# define vsf_atom16_op(__ptr, ...) \
410 ({ \
411 vsf_protect_t VSF_MACRO_SAFE_NAME(orig) = vsf_protect_int(); \
412 int16_t _ = (*(int16_t *)(__ptr)); \
413 *(int16_t *)(__ptr) = (__VA_ARGS__); \
414 vsf_unprotect_int(VSF_MACRO_SAFE_NAME(orig)); \
415 _; \
416 })
417#endif
418
419#ifndef vsf_atom8_op
420# define vsf_atom8_op(__ptr, ...) \
421 ({ \
422 vsf_protect_t VSF_MACRO_SAFE_NAME(orig) = vsf_protect_int(); \
423 int8_t _ = (*(int8_t *)(__ptr)); \
424 *(int8_t *)(__ptr) = (__VA_ARGS__); \
425 vsf_unprotect_int(VSF_MACRO_SAFE_NAME(orig)); \
426 _; \
427 })
428#endif
429
430#ifndef vsf_atom_add
431# define vsf_atom_add(__bitlen, __ptr, __value) \
432 VSF_MCONNECT(vsf_atom, __bitlen, _op)((__ptr), _ + (__value))
433#endif
434#ifndef vsf_atom_dec
435# define vsf_atom_dec(__bitlen, __ptr, __value) \
436 vsf_atom_add(__bitlen, (__ptr), - (__value))
437#endif
438#ifndef vsf_atom_or
439# define vsf_atom_or(__bitlen, __ptr, __value) \
440 VSF_MCONNECT(vsf_atom, __bitlen, _op)((__ptr), _ | (__value))
441#endif
442#ifndef vsf_atom_and
443# define vsf_atom_and(__bitlen, __ptr, __value) \
444 VSF_MCONNECT(vsf_atom, __bitlen, _op)((__ptr), _ & (__value))
445#endif
446#ifndef vsf_atom_xor
447# define vsf_atom_xor(__bitlen, __ptr, __value) \
448 VSF_MCONNECT(vsf_atom, __bitlen, _op)((__ptr), _ ^ (__value))
449#endif
450#ifndef vsf_atom_xchg
451# define vsf_atom_xchg(__bitlen, __ptr, __new_value) \
452 VSF_MCONNECT(vsf_atom, __bitlen, _op)((__ptr), (__new_value))
453#endif
454
455// host invoke
456#define vsf_arch_host_invoke_ctx_t(__name) VSF_MCONNECT(__name, _ctx_t)
457#define declare_vsf_arch_host_invoke(__name) \
458 typedef struct vsf_arch_host_invoke_ctx_t(__name) \
459 vsf_arch_host_invoke_ctx_t(__name); \
460 typedef struct VSF_MCONNECT(__name, _t) VSF_MCONNECT(__name, _t); \
461 extern void VSF_MCONNECT(__name, _callback_t) \
462 (vsf_arch_host_invoke_ctx_t(__name) *ctx); \
463 extern VSF_MCONNECT(__name, _t) VSF_MCONNECT(__name, _instance);
464#define dcl_vsf_arch_host_invoke declare_vsf_arch_host_invoke
465#define define_vsf_arch_host_invoke(__name, ...) \
466 typedef struct vsf_arch_host_invoke_ctx_t(__name) { \
467 int __dummy; \
468 __VA_ARGS__ \
469 } vsf_arch_host_invoke_ctx_t(__name); \
470 typedef struct VSF_MCONNECT(__name, _t) { \
471 implement(vsf_arch_irq_thread_t); \
472 vsf_arch_irq_request_t request; \
473 vsf_eda_t *caller; \
474 vsf_arch_host_invoke_ctx_t(__name) ctx; \
475 } VSF_MCONNECT(__name, _t);
476#define def_vsf_arch_host_invoke define_vsf_arch_host_invoke
477#define implement_vsf_arch_host_invoke(__name) \
478 VSF_MCONNECT(__name, _t) VSF_MCONNECT(__name, _instance); \
479 extern void VSF_MCONNECT(__name, _callback_t) \
480 (vsf_arch_host_invoke_ctx_t(__name) *ctx); \
481 static void VSF_MCONNECT(__name, _thread)(void *arg) \
482 { \
483 vsf_eda_t *caller; \
484 VSF_MCONNECT(__name, _t) *ctx = arg; \
485 __vsf_arch_irq_set_background(&ctx->use_as__vsf_arch_irq_thread_t); \
486 while (1) { \
487 __vsf_arch_irq_request_pend(&ctx->request); \
488 VSF_MCONNECT(__name, _callback_t)(&ctx->ctx); \
489 \
490 __vsf_arch_irq_start(&ctx->use_as__vsf_arch_irq_thread_t); \
491 caller = ctx->caller; \
492 if (caller != NULL) { \
493 ctx->caller = NULL; \
494 vsf_eda_post_evt(caller, VSF_EVT_USER); \
495 } \
496 __vsf_arch_irq_end(&ctx->use_as__vsf_arch_irq_thread_t, false); \
497 } \
498 } \
499 void VSF_MCONNECT(__name, _callback_t)(vsf_arch_host_invoke_ctx_t(__name) *_)
500#define imp_vsf_arch_host_invoke implement_vsf_arch_host_invoke
501#define initialize_vsf_arch_host_invoke(__name, __priority) \
502 do { \
503 memset(&VSF_MCONNECT(__name, _instance), 0, \
504 sizeof(VSF_MCONNECT(__name, _t))); \
505 __vsf_arch_irq_request_init(&VSF_MCONNECT(__name, _instance).request);\
506 __vsf_arch_irq_init( \
507 &VSF_MCONNECT(__name, _instance).use_as__vsf_arch_irq_thread_t,\
508 VSF_STR(__name), VSF_MCONNECT(__name, _thread), (__priority));\
509 } while (0)
510#define init_vsf_arch_host_invoke initialize_vsf_arch_host_invoke
511#define vsf_arch_host_invoke_nb(__name, __eda_ptr, __ctx_ptr) \
512 do { \
513 VSF_MCONNECT(__name, _instance).ctx = *(__ctx_ptr); \
514 VSF_MCONNECT(__name, _instance).caller = (__eda_ptr); \
515 __vsf_arch_irq_request_send(&VSF_MCONNECT(__name, _instance).request);\
516 } while (0)
517#define vsf_arch_host_invoke_get_result_nb(__name, __ctx_ptr) \
518 do { \
519 *(__ctx_ptr) = VSF_MCONNECT(__name, _instance).ctx; \
520 } while (0)
521#define vsf_arch_host_invoke_in_thread(__name, __ctx_ptr) \
522 do { \
523 vsf_eda_t VSF_MACRO_SAFE_NAME(eda) = vsf_eda_get_cur(); \
524 VSF_ARCH_ASSERT(VSF_MACRO_SAFE_NAME(eda) != NULL); \
525 vsf_arch_host_invoke_nb(__name, VSF_MACRO_SAFE_NAME(eda), (__ctx_ptr));\
526 vsf_thread_wfe(VSF_EVT_USER); \
527 vsf_arch_host_invoke_get_result_nb(__name, __ctx_ptr); \
528 } while (0)
529
530/*============================ PROTOTYPES ====================================*/
531
532#if VSF_ARCH_PROVIDE_HEAP == ENABLED
534extern void * vsf_arch_heap_realloc(void *buffer, uint_fast32_t size);
535extern void vsf_arch_heap_free(void *buffer);
536extern unsigned int vsf_arch_heap_alignment(void);
537extern uint_fast32_t vsf_arch_heap_size(void *buffer);
538# if VSF_ARCH_HEAP_HAS_STATISTICS == ENABLED
544# endif
545#endif
546
547/*----------------------------------------------------------------------------*
548 * Architecture Infrastructure *
549 *----------------------------------------------------------------------------*/
550
551#ifndef VSF_FFS32
552// returns the first bits(start from 0) which is '1'
553// if all bits are 0s, -1 is returned
555#endif
556
557#ifndef VSF_FFZ32
559#endif
560
561#ifndef VSF_MSB32
563#endif
564
565#ifndef VSF_CLZ32
567#endif
568
569#if VSF_APPLET_USE_ARCH == ENABLED
570typedef struct vsf_arch_vplt_t {
572
577# ifndef __VSF_APPLET__
579# endif
580#endif
581
582#if defined(__VSF_APPLET__) && (defined(__VSF_APPLET_LIB__) || defined(__VSF_APPLET_ARCH_LIB__))\
583 && VSF_APPLET_CFG_ABI_PATCH != ENABLED && VSF_APPLET_USE_ARCH == ENABLED
584
585#ifndef VSF_APPLET_ARCH_VPLT
586# define VSF_APPLET_ARCH_VPLT \
587 ((vsf_arch_vplt_t *)(((vsf_vplt_t *)vsf_vplt((void *)0))->arch_vplt))
588#endif
589
590#define VSF_APPLET_ARCH_ENTRY(__NAME) \
591 VSF_APPLET_VPLT_ENTRY_FUNC_ENTRY(VSF_APPLET_ARCH_VPLT, __NAME)
592#define VSF_APPLET_ARCH_IMP(...) \
593 VSF_APPLET_VPLT_ENTRY_FUNC_IMP(VSF_APPLET_ARCH_VPLT, __VA_ARGS__)
594
595VSF_APPLET_ARCH_IMP(bswap_16, uint_fast16_t, uint_fast16_t value) {
597 return VSF_APPLET_ARCH_ENTRY(bswap_16)(value);
598}
599VSF_APPLET_ARCH_IMP(bswap_32, uint_fast32_t, uint_fast32_t value) {
601 return VSF_APPLET_ARCH_ENTRY(bswap_32)(value);
602}
603VSF_APPLET_ARCH_IMP(bswap_64, uint_fast64_t, uint_fast64_t value) {
605 return VSF_APPLET_ARCH_ENTRY(bswap_64)(value);
606}
607
608#else
609
612#ifdef UINT64_MAX
613extern uint_fast64_t bswap_64(uint_fast64_t);
614#endif
615
618#ifdef UINT64_MAX
620#endif
621
622#endif
623
624/*----------------------------------------------------------------------------*
625 * SWI *
626 *----------------------------------------------------------------------------*/
627
629 vsf_arch_prio_t priority,
630 vsf_swi_handler_t *handler,
631 void *param);
632extern void vsf_swi_trigger(uint_fast8_t idx);
633
637extern void vsf_arch_swi_trigger(uint_fast8_t idx);
638
639/*----------------------------------------------------------------------------*
640 * System Timer *
641 *----------------------------------------------------------------------------*/
642
643#ifdef VSF_SYSTIMER_CFG_IMPL_MODE
644extern vsf_err_t vsf_systimer_start(void);
647extern void vsf_systimer_set_idle(void);
649extern void vsf_systimer_prio_set(vsf_arch_prio_t priority);
650extern uint32_t vsf_systimer_get_freq(void);
651
656#endif
657
658
659/*----------------------------------------------------------------------------*
660 * Interrupt *
661 *----------------------------------------------------------------------------*/
662
665
666extern int vsf_get_interrupt_id(void);
671
672// Use dedicated arch related APIs instead of vsf_irq_XXX APIs below.
673// vsf_irq_XXX APIs are only used when there is no dedicated arch,
674// eg: embassy-vsf support in Windows/Unix-Like systems implemented by hal_distbus.
675
676extern void vsf_irq_enable(int irqn);
677extern void vsf_irq_disable(int irqn);
678extern bool vsf_irq_is_enabled(int irqn);
679extern void vsf_irq_pend(int irqn);
680extern void vsf_irq_unpend(int irqn);
681extern bool vsf_irq_is_pending(int irqn);
682extern void vsf_irq_set_priority(int irqn, uint32_t priority);
683extern uint32_t vsf_irq_get_priority(int irqn);
684
685extern void vsf_arch_sleep(uint_fast32_t mode);
686extern void vsf_arch_reset(void);
687extern void vsf_arch_shutdown(void);
688// vsf_arch_main is only used in some special arch, eg: wasm
689// and normally used with VSF_ARCH_ENTRY_NO_PENDING
690extern void vsf_arch_main(void);
691
692#ifdef __cplusplus
693}
694#endif
695
696#endif
697/* EOF */
vsf_err_t
Definition __type.h:42
uint_fast8_t uintalu_t
Definition type.h:88
bool
Definition type.h:60
vsf_arch_prio_t
Definition cortex_a_generic.h:85
uint64_t vsf_systimer_tick_t
Definition cortex_a_generic.h:70
void vsf_systimer_prio_set(vsf_arch_prio_t priority)
Definition cortex_m_generic.c:244
vsf_systimer_tick_t vsf_systimer_get(void)
Definition linux_generic.c:402
void vsf_systimer_set_idle(void)
Definition linux_generic.c:398
vsf_systimer_tick_t vsf_systimer_tick_to_us(vsf_systimer_tick_t tick)
Definition linux_generic.c:445
bool vsf_systimer_is_due(vsf_systimer_tick_t due)
Definition linux_generic.c:430
vsf_systimer_tick_t vsf_systimer_ms_to_tick(uint_fast32_t time_ms)
Definition linux_generic.c:440
vsf_systimer_tick_t vsf_systimer_us_to_tick(uint_fast32_t time_us)
Definition linux_generic.c:435
vsf_systimer_tick_t vsf_systimer_tick_to_ms(vsf_systimer_tick_t tick)
Definition linux_generic.c:450
vsf_err_t vsf_systimer_start(void)
Definition linux_generic.c:390
bool vsf_systimer_set(vsf_systimer_tick_t due)
Definition linux_generic.c:409
uint32_t uintptr_t
Definition stdint.h:38
unsigned char uint_fast8_t
Definition stdint.h:23
unsigned uint32_t
Definition stdint.h:9
unsigned int uint_fast32_t
Definition stdint.h:27
unsigned short uint_fast16_t
Definition stdint.h:25
unsigned long long uint_fast64_t
Definition stdint.h:29
char int_fast8_t
Definition stdint.h:22
Definition vsf_arch_abstraction.h:539
uint32_t used_size
Definition vsf_arch_abstraction.h:541
uint32_t all_size
Definition vsf_arch_abstraction.h:540
Definition vsf_arch_abstraction.h:67
vsf_arch_text_region_t * next
Definition vsf_arch_abstraction.h:68
uintptr_t size
Definition vsf_arch_abstraction.h:70
uintptr_t start
Definition vsf_arch_abstraction.h:69
Definition vsf_arch_abstraction.h:570
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(bswap_64)
vsf_vplt_info_t info
Definition vsf_arch_abstraction.h:571
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(bswap_16)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(bswap_32)
Definition vsf_arch_abstraction.h:61
void(* leave)(vsf_protect_t orig)
Definition vsf_arch_abstraction.h:63
vsf_protect_t(* enter)(void)
Definition vsf_arch_abstraction.h:62
Definition vsf_cfg.h:95
uint_fast32_t bswap_32(uint_fast32_t)
Definition cortex_a_generic.c:160
vsf_err_t vsf_swi_init(uint_fast8_t idx, vsf_arch_prio_t priority, vsf_swi_handler_t *handler, void *param)
Definition vsf_arch_abstraction.c:511
const vsf_protect_region_t vsf_protect_region_int
Definition vsf_arch_abstraction.c:191
uint_fast8_t vsf_clz32(uint_fast32_t)
Definition vsf_arch_abstraction.c:343
bool vsf_irq_is_pending(int irqn)
Definition cortex_m_generic.c:142
uintalu_t vsf_protect_t
Definition vsf_arch_abstraction.h:60
int_fast8_t vsf_ffs32(uint_fast32_t)
Definition vsf_arch_abstraction.c:412
const vsf_protect_region_t vsf_protect_region_none
Definition vsf_arch_abstraction.c:196
void vsf_arch_shutdown(void)
Definition cortex_m_generic.c:461
void vsf_arch_heap_free(void *buffer)
Definition linux_generic.c:566
unsigned int vsf_arch_heap_alignment(void)
Definition linux_generic.c:572
void vsf_arch_reset(void)
Definition cortex_m_generic.c:455
#define DECLARE_ENDIAN_FUNC(__bitlen)
Definition vsf_arch_abstraction.h:292
void * vsf_arch_heap_malloc(uint_fast32_t size, uint_fast32_t alignment)
Definition linux_generic.c:518
void vsf_irq_pend(int irqn)
Definition cortex_m_generic.c:130
uint32_t vsf_irq_get_priority(int irqn)
Definition cortex_m_generic.c:154
vsf_gint_state_t vsf_disable_interrupt(void)
Definition arm9_generic.c:176
vsf_irq_handler_t vsf_swi_handler_t
Definition vsf_arch_abstraction.h:58
vsf_arch_prio_t vsf_get_base_priority(void)
Definition cortex_m_generic.c:321
void vsf_irq_unpend(int irqn)
Definition cortex_m_generic.c:136
vsf_gint_state_t vsf_get_interrupt(void)
Definition arm9_generic.c:164
void vsf_irq_enable(int irqn)
Definition cortex_m_generic.c:112
void vsf_arch_main(void)
void * vsf_arch_heap_realloc(void *buffer, uint_fast32_t size)
Definition linux_generic.c:541
bool vsf_irq_is_enabled(int irqn)
Definition cortex_m_generic.c:124
void vsf_swi_trigger(uint_fast8_t idx)
Definition vsf_arch_abstraction.c:469
void vsf_irq_handler_t(void *p)
Definition vsf_arch_abstraction.h:57
void vsf_arch_heap_statistics(vsf_arch_heap_statistics_t *statistics)
Definition win_generic.c:1265
void vsf_arch_sleep(uint_fast32_t mode)
Definition cortex_m_generic.c:439
__VSF_VPLT_DECORATOR__ vsf_arch_vplt_t vsf_arch_vplt
Definition vsf_arch_abstraction.c:1100
void vsf_arch_swi_trigger(uint_fast8_t idx)
trigger a software interrupt !
Definition cortex_m_generic.c:301
uint_fast16_t bswap_16(uint_fast16_t)
Definition cortex_a_generic.c:155
void vsf_irq_set_priority(int irqn, uint32_t priority)
Definition cortex_m_generic.c:148
vsf_gint_state_t vsf_enable_interrupt(void)
Definition arm9_generic.c:181
uint_fast32_t vsf_arch_heap_size(void *buffer)
Definition linux_generic.c:577
vsf_arch_prio_t vsf_set_base_priority(vsf_arch_prio_t priority)
Definition cortex_m_generic.c:326
int_fast8_t vsf_msb32(uint_fast32_t)
Definition vsf_arch_abstraction.c:378
void vsf_irq_disable(int irqn)
Definition cortex_m_generic.c:118
int vsf_get_interrupt_id(void)
Definition cortex_m_generic.c:429
vsf_gint_state_t vsf_set_interrupt(vsf_gint_state_t level)
Definition arm9_generic.c:169
int_fast8_t vsf_ffz32(uint_fast32_t)
Definition vsf_arch_abstraction.c:447
vk_av_control_value_t value
Definition vsf_audio.h:171
#define __VSF_VPLT_DECORATOR__
Definition vsf_cfg.h:93
#define VSF_APPLET_VPLT_ENTRY_FUNC_TRACE()
Definition vsf_cfg.h:165
uint_fast32_t alignment
Definition vsf_heap.h:163
uint32_t size
Definition vsf_memfs.h:50
Generated from commit: vsfteam/vsf@66670f8