blob: 2832645ccacf1a5b067512e96220553d6f8776c4 [file] [log] [blame]
Benjamin Walsh456c6da2016-09-02 18:55:39 -04001/*
2 * Copyright (c) 2010-2012, 2014-2015 Wind River Systems, Inc.
3 *
David B. Kinderac74d8b2017-01-18 17:01:01 -08004 * SPDX-License-Identifier: Apache-2.0
Benjamin Walsh456c6da2016-09-02 18:55:39 -04005 */
6
7/**
8 * @file
Anas Nashifdc3d73b2016-12-19 20:25:56 -05009 * @brief Architecture-independent private kernel APIs
Benjamin Walsh456c6da2016-09-02 18:55:39 -040010 *
Anas Nashifdc3d73b2016-12-19 20:25:56 -050011 * This file contains private kernel APIs that are not architecture-specific.
Benjamin Walsh456c6da2016-09-02 18:55:39 -040012 */
13
14#ifndef _NANO_INTERNAL__H_
15#define _NANO_INTERNAL__H_
16
Andrew Boie73abd322017-04-04 13:19:13 -070017#include <kernel.h>
18
Benjamin Walsh456c6da2016-09-02 18:55:39 -040019#define K_NUM_PRIORITIES \
20 (CONFIG_NUM_COOP_PRIORITIES + CONFIG_NUM_PREEMPT_PRIORITIES + 1)
Benjamin Walsh456c6da2016-09-02 18:55:39 -040021
Benjamin Walsh358a53c2016-11-18 15:35:05 -050022#define K_NUM_PRIO_BITMAPS ((K_NUM_PRIORITIES + 31) >> 5)
23
Benjamin Walsh456c6da2016-09-02 18:55:39 -040024#ifndef _ASMLANGUAGE
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/* Early boot functions */
31
32void _bss_zero(void);
33#ifdef CONFIG_XIP
34void _data_copy(void);
35#else
36static inline void _data_copy(void)
37{
38 /* Do nothing */
39}
40#endif
41FUNC_NORETURN void _Cstart(void);
42
Andrew Boie1e06ffc2017-09-11 09:30:04 -070043extern FUNC_NORETURN void _thread_entry(k_thread_entry_t entry,
44 void *p1, void *p2, void *p3);
Benjamin Walsh456c6da2016-09-02 18:55:39 -040045
Andrew Boie507852a2017-07-25 18:47:07 -070046extern void _new_thread(struct k_thread *thread, k_thread_stack_t pStack,
Andrew Boie1e06ffc2017-09-11 09:30:04 -070047 size_t stackSize, k_thread_entry_t entry,
Benjamin Walsh456c6da2016-09-02 18:55:39 -040048 void *p1, void *p2, void *p3,
Kumar Gala5742a502017-04-21 11:41:26 -050049 int prio, unsigned int options);
Benjamin Walsh456c6da2016-09-02 18:55:39 -040050
51/* context switching and scheduling-related routines */
52
Ramesh Thomas62eea122017-04-06 15:30:27 -070053extern unsigned int __swap(unsigned int key);
54
Andrew Boieae1a75b2017-06-07 09:33:16 -070055#ifdef CONFIG_TIMESLICING
Ramesh Thomas89ffd442017-02-05 19:37:19 -080056extern void _update_time_slice_before_swap(void);
Andrew Boieae1a75b2017-06-07 09:33:16 -070057#endif
Benjamin Walsh456c6da2016-09-02 18:55:39 -040058
Andrew Boieae1a75b2017-06-07 09:33:16 -070059#ifdef CONFIG_STACK_SENTINEL
60extern void _check_stack_sentinel(void);
61#endif
62
63static inline unsigned int _Swap(unsigned int key)
Ramesh Thomas89ffd442017-02-05 19:37:19 -080064{
Andrew Boieae1a75b2017-06-07 09:33:16 -070065
66#ifdef CONFIG_STACK_SENTINEL
67 _check_stack_sentinel();
68#endif
69#ifdef CONFIG_TIMESLICING
Ramesh Thomas89ffd442017-02-05 19:37:19 -080070 _update_time_slice_before_swap();
Andrew Boieae1a75b2017-06-07 09:33:16 -070071#endif
72
Ramesh Thomas89ffd442017-02-05 19:37:19 -080073 return __swap(key);
74}
75
Benjamin Walsh456c6da2016-09-02 18:55:39 -040076/* set and clear essential fiber/task flag */
77
78extern void _thread_essential_set(void);
79extern void _thread_essential_clear(void);
80
81/* clean up when a thread is aborted */
82
83#if defined(CONFIG_THREAD_MONITOR)
Benjamin Walshf6ca7de2016-11-08 10:36:50 -050084extern void _thread_monitor_exit(struct k_thread *thread);
Benjamin Walsh456c6da2016-09-02 18:55:39 -040085#else
Benjamin Walshf6ca7de2016-11-08 10:36:50 -050086#define _thread_monitor_exit(thread) \
Benjamin Walsh456c6da2016-09-02 18:55:39 -040087 do {/* nothing */ \
88 } while (0)
89#endif /* CONFIG_THREAD_MONITOR */
90
Benjamin Walsh456c6da2016-09-02 18:55:39 -040091#ifdef __cplusplus
92}
93#endif
94
95#endif /* _ASMLANGUAGE */
96
97#endif /* _NANO_INTERNAL__H_ */