?? os.h
字號:
/*********************************************************************************************************
** Mini OS
** The Real-Time Kernel For Avr Atmega8/16 CPU
**
** (c) Copyright 2004-2004, wanghong
** All Rights Reserved
**
** V1.20
**
**
** Filename: os.h
** Created by: wanghong
** Date: 2004.09.05
** Description: Mini OS for Avr Atmega8/16 CPU
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Date:
** Description:
**
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#ifndef _OS_H_
#define _OS_H_
#include "..\os\os_config.h"
#include <iom8v.h>
#include <macros.h>
#include <string.h>
/*-- to disable/enable the maskable interrupts --*/
#define OS_ENTER_CRITICAL() do {CLI();}while(0)
#define OS_EXIT_CRITICAL() do {SEI();}while(0)
#define NULL (void *)0
//; bit-mapped signal definitions
#define BIT0 (1<<0)
#define BIT1 (1<<1)
#define BIT2 (1<<2)
#define BIT3 (1<<3)
#define BIT4 (1<<4)
#define BIT5 (1<<5)
#define BIT6 (1<<6)
#define BIT7 (1<<7)
#define BIT8 (1<<8)
#define BIT9 (1<<9)
#define BIT10 (1<<10)
#define BIT11 (1<<11)
#define BIT12 (1<<12)
#define BIT13 (1<<13)
#define BIT14 (1<<14)
#define BIT15 (1<<15)
//; byte mask definitions
#define K_SIG 1 // wait for signal
#define K_TMO 2 // wait for time out
#define EVENT_SIG 4 // signal event
#define EVENT_TMO 8 // time out or interval time out event
#define K_READY 16 // flag indicates task status: 1, task ready, 0, task is not ready
#define K_ACTIVE 32 // flag indicates task status: 1, task actived, 0, task has not been created
#define K_MSG 64 // wait for message
#define EVENT_MSG 64 // message received event
#define K_IVL 128 // not a task state bit; only used in os_wait
#define NOT_OK 128 // parameter err
#define EVENT_NONE 0 // no event
//; error macros definitions
#define ERR_NONE 0 // ok
#define ERR_MSG_NONE -1 // no message err
#define ERR_MSG_OVF -2 // message pool overflow
#define ERR_MSG_GENERAL -3 // task busy or can not receive message
typedef unsigned int SIGNAL_TYPE;
//; data structure define for task status
typedef struct {
unsigned int waitsig :1; // wait for signal
unsigned int waitto :1; // wait for time out
unsigned int sigflag :1; // signal flag
unsigned int toflag :1; // time out flag
unsigned int ready :1; // task ready(wait for running)
unsigned int active :1; // task active(enable with os_create_task)
unsigned int waitmsg :1; // wait for message, can not be clear once set to '1'
unsigned int rdy :1; // RDY flag
}OS_TASK_STATUS;
//; data structure define for message
typedef struct {
unsigned char task_id; // notify task id
unsigned char msg[3]; // message data
}OS_MSG;
/**********************************************************
* os_create_task: starts the defined task function using
* the task number specified by task_id. The task is
* marked as ready and is ready to execute
*
* @param task_id: task id
* @param ptask_entry: task entry address
* @return 0: task create successfully,
* 0xff: task could not be started or if no task
* was defined using the specified task number
**********************************************************/
unsigned char os_create_task (unsigned char task_id, void (*task_entry)(void));
/**********************************************************
* os_wait: halts the current task and waits for one or
* several events such as a time interval, a time-out, a message,
* or a bit-mapped signal from another task or interrupt.
*
* @param typ: event or events to wait for and can be any
* combination of the following manifest constants:
* (K_TMO, K_SIG, K_MSG).
* @param timeout: the number of timer ticks to wait for an
* interval event (K_IVL) or a time-out event (K_TMO).
* @param dummy: not used.
*
* @return EVENT_SIG: A signal was received.
* EVENT_MSG: A message was received.
* EVENT_TMO: A time-out has completed or an interval
* has expired.
* NOT_OK: The value of the typ argument is invalid.
**********************************************************/
unsigned char os_wait (unsigned char typ, unsigned char timeout, unsigned int dummy);
/**********************************************************
* isr_send_signal: sends a bit-mapped signal to task task_id. If the
* specified task is already waiting for a signal, this
* function call readies the task for execution. Otherwise,
* the signal is stored in the signal flag of the task.
* The isr_send_signal function may be called only from interrupt service routine.
*
* @param task_id: task id
* @param signal: bit-mapped signal
* @return 0: if successful,
* 0xff: signal invalid or the specified task does not exist.
**********************************************************/
//#pragma NO_OVERLAP
unsigned char isr_send_signal (unsigned char task_id, SIGNAL_TYPE signal);
/**********************************************************
* os_send_signal: sends a bit-mapped signal to task task_id. If the
* specified task is already waiting for a signal, this
* function call readies the task for execution. Otherwise,
* the signal is stored in the signal flag of the task.
* The os_send_signal function may be called only from task functions.
*
* @param task_id: task id
* @param signal: bit-mapped signal
* @return 0: if successful,
* 0xff: signal invalid or the specified task does not exist.
**********************************************************/
unsigned char os_send_signal (unsigned char task_id, SIGNAL_TYPE signal);
/**********************************************************
* os_get_signal: get a bit-mapped signal of the current task.
* This function may be called only from task functions.
*
* @param none
* @return: bit-mapped signal
* 0: no signal or the specified task does not exist.
**********************************************************/
SIGNAL_TYPE os_get_signal (void);
/**********************************************************
* os_clear_signal: clear a bit-mapped signal of the current task.
* This function may be called only from task functions.
*
* @param signal: bit-mapped signal
* @return 0: if successful,
* 0xff: the specified task does not exist.
**********************************************************/
unsigned char os_clear_signal (SIGNAL_TYPE signal);
/**********************************************************
* isr_send_message: send a message to a specific task.
* This function may be called only from interrupt service routine.
*
* @param task_id: the specified task to receive the message.
* @param msg_data: data to be sent. msg_data lenght must be 3 bytes.
* @return 0: if successful,
* !0: error code.
**********************************************************/
//#pragma NO_OVERLAP
unsigned char isr_send_message (unsigned char task_id, unsigned char *msg_data);
/**********************************************************
* os_send_message: send a message to a specific task.
* This function may be called only from task functions.
*
* @param task_id: the specified task to receive the message.
* @param msg_data: data to be sent. msg_data lenght must be 3 bytes.
* @return 0: if successful,
* !0: error code.
**********************************************************/
unsigned char os_send_message (unsigned char task_id, unsigned char *msg_data);
#if OS_MSG_PRIORITY_EN
/**********************************************************
* os_send_message_front: send a message to a specific task. The message is posted at
* the front instead of the end of the queue, using os_send_message_front()
* allows you to send 'priority' messages.
* This function may be called only from task functions.
*
* @param task_id: the specified task to receive the message.
* @param msg_data: data to be sent. msg_data lenght must be 3 bytes.
* @return 0: if successful,
* !0: error code.
**********************************************************/
unsigned char os_send_message_front (unsigned char task_id, unsigned char *msg_data);
#else
#define os_send_message_front(task_id, msg_data) os_send_message(task_id, msg_data)
#endif
/**********************************************************
* os_get_message: get a message to task's message queue.
* This function may be called only from task functions.
*
* @param msg_buf: the buffer to receive the message. buffer lenght must be 3 bytes.
* @return >=0: number of unread msg still in the task's message queue,
* -1: no message.
**********************************************************/
char os_get_message (unsigned char *msg_buf);
/**********************************************************
* os_running_task_id: determines the task id of the task currently executing.
*
* @param none
* @return 0: function returns the task ID of the task currently executing.
* This value is a number in the range 0-15.
**********************************************************/
unsigned char os_running_task_id (void);
/**********************************************************
* os_switch_task: The os_switch_task function allows a task to give up
* the CPU and allow another task run. If the task calling os_switch_task
* is the only task ready for execution it resumes running immediately.
*
* @param none
* @return none
**********************************************************/
unsigned char os_switch_task (void);
/**********************************************************
* os_reset_interval: The os_reset_interval function is used to correct timer
* problems that occur when the os_wait function is used to wait for
* K_IVL and K_SIG events simultaneously. In such a case, if a signal
* (K_SIG) event causes os_wait to exit, the interval timer is not adjusted
* and subsequent calls to os_wait to wait for an interval may not delay
* for the required time period. The os_reset_interval allows you to reset
* the interval timer in such an event.
*
* @param ticks: number of timer ticks
* @return none
**********************************************************/
void os_reset_interval (unsigned char ticks);
/**********************************************************
* os_time_get: This function is used by your application to obtain the current value of the 32-bit
* counter which keeps track of the number of clock ticks.
*
* @param none
* @return: The current value of os_time.
**********************************************************/
unsigned long os_time_get (void);
/**********************************************************
* os_time_set: This function sets the 32-bit counter which keeps track of the number of clock ticks.
*
* @param ticks: specifies the new value that os_time needs to take.
* @return: none.
**********************************************************/
void os_time_set (unsigned long ticks);
#if OS_STK_CHK_EN
/*********************************************************************************************************
* STACK CHECKING
*
* os_get_stack_usage: This function is called to get the max usage of system stack.
*
* @param: prio, not used
* @return: the max usage of stack in %
*********************************************************************************************************/
unsigned char os_get_stack_usage (unsigned char prio);
#endif
/**********************************************************
* os_init: os startup routine, init for Mini OS
*
* @param none
* @return none
**********************************************************/
void os_init (void);
#if OS_CPU_HOOKS_EN
/*********************************************************************************************************
* TASK SWITCH HOOK
*
* os_task_sw_hook: This function is called when a task switch is performed. This allows you to perform other
* operations during a context switch.
*
* @param: none
* @return: none
*
*********************************************************************************************************/
void os_task_sw_hook (void);
/*********************************************************************************************************
* STATISTIC TASK HOOK
*
* os_task_stat_hook: This function is called every second by Mini OS's statistics task. This allows your
* application to add functionality to the statistics task.
*
* @param: none
* @return: none
*********************************************************************************************************/
void os_task_stat_hook (void);
/*********************************************************************************************************
* TICK HOOK
*
* os_time_tick_hook: This function is called every tick.
*
* @param: none
* @return: none
*
* Note(s): 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************/
void os_time_tick_hook (void);
#endif
#endif
/************************************************
* @ os.h v1.0 log @
*
* Revision 1.0.0.0 Wanghong 2004/09/05
* create file
*
* Revision 1.2.0.0 Wanghong 2005/12/17
* added bit-mapped signal interface function prototype,
* added os message interface prototype.
*
***********************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -