📄 port.h
字号:
/*
* Copyright (c) 2004-2006, Dennis Kuschel.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/**
* @file port.h
* @brief port configuration file
* @author Dennis Kuschel
*
* This file is originally from the pico]OS realtime operating system
* (http://picoos.sourceforge.net).
*
* CVS-ID $Id: port.h,v 1.8 2006/03/14 18:39:27 dkuschel Exp $
*/
#ifndef _PORT_H
#define _PORT_H
/*---------------------------------------------------------------------------
* ARCHITECTURE / CPU SPECIFIC SETTINGS
*-------------------------------------------------------------------------*/
/** @defgroup arch Architecture / CPU Specific Settings
* @ingroup configp
* @{
*/
/** Machine variable type.
* This define is set to the variable type that best
* matches the target architecture. For example, define this
* to @e char if the architecture has 8 bit, or to
* @e int / @e long for a 32 bit architecture.
* Note that the variable must fit into a single
* memory cell of the target architecture.
* (For a 32 bit architecture you can define MVAR_t to
* @e char, @e short or @e int / @e long, whereas
* at a 8 bit architecure you can only define it to @e char).
* This define is responsible for the maximum count of tasks
* the operating system can manage. For example:
* @e char = 8 bit, 8 * 8 = 64 tasks;
* @e long = 32 bit, 32 * 32 = 1024 tasks.
*/
#define MVAR_t char
/** Machine variable width.
* This define tells the Operating System how much
* bits can be stored in the machine variable type ::MVAR_t.
* Some compilers support the sizeof(MVAR_t)-macro at this
* position, but some others don't. For example, set
* this define to 8 (bits) if ::MVAR_t is defined to @e char.
*/
#define MVAR_BITS 8 /* = (sizeof(MVAR_t) * 8) */
/** Integer variable type used for memory pointers.
* This define must be set to an integer type that has the
* same bit width like a memory pointer (e.g. void*) on
* the target architecture. On a 32bit architecture you
* would usually define this to @e long, for a 8 bit
* architecture @e short would be sufficient.
*/
#define MPTR_t long
/** Required memory alignment on the target CPU.
* To reach maximum speed, some architecures need correctly
* aligned memory patterns. Set this define to the memory
* alignment (in bytes) your architecture requires.
* Note that this value must be a power of 2.
* If your architecture does not require memory alignment,
* set this value to 0 or 1.
*/
#define POSCFG_ALIGNMENT 2
/** Interruptable interrupt service routines.
* This define must be set to 1 (=enabled) when an
* interrupt service routine is interruptable on the machine.
* E.g. some PowerPCs support critical interrupts that can
* interrupt currently running noncritical interrupts.
* If your machine configuration does not support interruptable ISRs,
* you can set this define to 0 to save some execution time in ISRs.
*/
#define POSCFG_ISR_INTERRUPTABLE 0
/** Set the mechanism of stack memory handling.
* There are three types of stack memory handling defined.<br>
*
* <b>Type 0 </b><br>
* The stack memory is allocated by the user and a pointer
* to the stack memory is passed to the functions
* ::posTaskCreate, ::posInit and ::p_pos_initTask.<br>
*
* <b>Type 1 </b><br>
* The stack memory will be allocated by the platform port when a
* new task is created. The memory will be freed when the task is
* destroyed. The functions ::posTaskCreate, ::posInit and ::p_pos_initTask
* are called with a parameter that specifies the stack size.
* The function ::p_pos_freeStack is used to free the stack memory
* again when the task is destroyed.<br>
*
* <b>Type 2 </b><br>
* Like type 1, but the size of the stack is fixed.
* The functions ::posTaskCreate, ::posInit and ::p_pos_initTask do
* not take any stack parameters.<br>
*
* @note the functions ::posTaskCreate, ::posInit and ::p_pos_initTask
* have different prototypes for each stack handling type.
*/
#define POSCFG_TASKSTACKTYPE 0
/** Enable call to function ::p_pos_initArch.
* When this define is set to 1, the operating system will call
* the user supplied function ::p_pos_initArch to initialize
* the architecture specific portion of the operating system.
*/
#define POSCFG_CALLINITARCH 1
/** Enable dynamic memory.
* If this define is set to 1, the memory for internal data structures
* is allocated dynamically at startup. The define ::POS_MEM_ALLOC must
* be set to a memory allocation function that shall be used. Otherwise,
* when this define is set to 0, the memory is allocated statically.
*/
#define POSCFG_DYNAMIC_MEMORY 0
/** Dynamic memory management.
* If this define is set to 1, the system will refill its volume of
* system structures for tasks, events, timers and messages when the
* user requests more structures than the amount that was preallocated
* (see defines ::POSCFG_MAX_TASKS, ::POSCFG_MAX_EVENTS,
* ::POSCFG_MAX_MESSAGES and ::POSCFG_MAX_TIMER ). To be able to use
* this feature, you must also set the define ::POSCFG_DYNAMIC_MEMORY to 1.
* But attention: The define ::POS_MEM_ALLOC must be set to a memory
* allocation function <b>that is thread save</b>. Please set the define
* ::POS_MEM_ALLOC to ::nosMemAlloc to use the nano layer memory allocator.
*/
#define POSCFG_DYNAMIC_REFILL 0
/** Define optional memory allocation function.
* If ::POSCFG_DYNAMIC_MEMORY is set to 1, this definition must be set
* to a memory allocation function such as "malloc". The memory allocation
* function may not be reentrant when ::POSCFG_DYNAMIC_REFILL is set to 0,
* since the multitasking system is not yet started when the function is
* called.
*/
#define POS_MEM_ALLOC(bytes) nosMemAlloc(bytes)
/** @} */
/*---------------------------------------------------------------------------
* LOCKING (DISABLE INTERRUPTS IN CRITICAL SECTIONS)
*-------------------------------------------------------------------------*/
/** @defgroup lock Disable / Enable Interrupts
* @ingroup configp
* The operating system must be able to disable the interrupts on the
* processor for a short time to get exclusive access to internal data
* structures. There are three possible ways to solve this:<br>
*
* 1) Most processors have assembler commands that directly allow
* disabling and enabling interrupts. When the operating system needs
* to get exclusive access to any data, it will disable interrupts,
* access the data and enable interrupts again. The disadvantage of
* this simple way is that if the processor had disabled interrupts
* before the OS entered the critical section, the OS will reenable the
* interrupts again after it left the critical section regardless if
* interrupts were disabled before.<br>
*
* 2) A better way is to save the current processor state before disabling
* interrupts. Much processors support a "push flags to stack" OP-Code
* for this purpose. When the operating system enters a critical section,
* it will push the processor flags to the stack and disables the interrupts.
* Then, when the operating system will left the critical section again,
* it simply restores the old processor state by popping the last
* processor state from the stack. If interrupts where enabled before,
* it just became enabled now.<br>
*
* 3) There are some processors which have no OP-code for directly pushing
* the processor flags (=PSW, Processor Status Word) directly to the stack.
* For this processors, you can define a local variable which will hold
* the original PSW when the operating system enters the critical section.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -