X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fkern%2Fproc.h;h=45949e8e3ef166f0bebc3b62bb014a15c8444ba1;hb=a826f128ef56409cf87f60a0748bae388ccf42de;hp=7ac632ec1fb7fd3702d1dd4e8f20babfde3160f5;hpb=71743c2a5a8bf9dbf66a945fd9656baed0d16329;p=bertos.git diff --git a/bertos/kern/proc.h b/bertos/kern/proc.h index 7ac632ec..45949e8e 100644 --- a/bertos/kern/proc.h +++ b/bertos/kern/proc.h @@ -30,14 +30,15 @@ * Copyright 1999, 2000, 2001, 2008 Bernie Innocenti * --> * - * \brief Bertos Kernel core (Process scheduler). + * \brief BeRTOS Kernel core (Process scheduler). * * \version $Id$ * \author Bernie Innocenti * * $WIZ$ module_name = "kernel" * $WIZ$ module_configuration = "bertos/cfg/cfg_proc.h" - * $WIZ$ module_depends = "switch_ctx" + * $WIZ$ module_depends = "switch_ctx", "coop" + * $WIZ$ module_supports = "not atmega103" */ #ifndef KERN_PROC_H @@ -55,13 +56,52 @@ #include // cpu_stack_t #include // CPU_SAVED_REGS_CNT +/* + * Define stack for one process. + * + * This macro define a static stack for one process and do + * check if given stack size is enough to run process. + */ +#define PROC_DEFINE_STACK(name, size) \ + STATIC_ASSERT(size >= CONFIG_KERN_MINSTACKSIZE); \ + cpu_stack_t name[size / sizeof(cpu_stack_t)]; \ + /* * Forward declaration. The definition of struct Process is private to the * scheduler and hidden in proc_p.h. */ struct Process; +/** + * Initialize the process subsystem (kernel). + * It must be called before using any process related function. + */ void proc_init(void); + +/** + * Create a new named process and schedules it for execution. + * + * When defining the stacksize take into account that you may want at least: + * \li save all the registers for each nested function call; + * \li have memory for the struct Process, which is positioned at the bottom + * of the stack; + * \li have some memory for temporary variables inside called functions. + * + * The value given by CONFIG_KERN_MINSTACKSIZE is rather safe to use in the first place. + * + * \note The function + * \code + * proc_new(entry, data, stacksize, stack) + * \endcode + * is a more convenient way to create a process, as you don't have to specify + * the name. + * + * \param name Name of the process (currently unused). + * \param entry Function that the process will execute. + * \param data Pointer to user data. + * \param stacksize Length of the stack. + * \param stack Pointer to the memory area to be used as a stack. + */ struct Process *proc_new_with_name(const char *name, void (*entry)(void), iptr_t data, size_t stacksize, cpu_stack_t *stack); #if !CONFIG_KERN_MONITOR @@ -70,11 +110,33 @@ struct Process *proc_new_with_name(const char *name, void (*entry)(void), iptr_t #define proc_new(entry,data,size,stack) proc_new_with_name(#entry,(entry),(data),(size),(stack)) #endif +/** + * Terminate the execution of the current process. + */ void proc_exit(void); + +/** + * Co-operative context switch. + * + * The process that calls this function will release the CPU before its cpu quantum + * expires, the scheduler will run to select the next process that will take control + * of the processor. + * \note This function is available only if CONFIG_KERN is enabled + * \sa cpu_relax(), which is the recommended method to release the cpu. + */ void proc_yield(void); + void proc_rename(struct Process *proc, const char *name); const char *proc_name(struct Process *proc); const char *proc_currentName(void); + +/** + * Return a pointer to the user data of the current process. + * + * To obtain user data, just call this function inside the process. Remember to cast + * the returned pointer to the correct type. + * \return Pointer to the user data of the current process. + */ iptr_t proc_currentUserData(void); int proc_testSetup(void); @@ -226,10 +288,10 @@ INLINE bool proc_allowed(void) * stack. * * The actual size computed by the default formula is: - * AVR: 102 - * i386: 156 - * ARM: 164 - * x86_64: 184 + * \li AVR: 102 + * \li i386: 156 + * \li ARM: 164 + * \li x86_64: 184 * * Note that on most 16bit architectures, interrupts will also * run on the stack of the currently running process. Nested