📄 pro_man.c
字号:
/**********************************************************************/
/* */
/* File name: pro_man.c */
/* */
/* Since: 2004-Sept-20 */
/* */
/* Version: PICos18 v2.09 */
/* Copyright (C) 2003, 2004, 2005 Pragmatec. */
/* */
/* Author: Designed by Pragmatec S.A.R.L. www.pragmatec.net */
/* MONTAGNE Xavier [XM] xavier.montagne@pragmatec.net */
/* */
/* Purpose: The process manager is in charge of changing or giving */
/* the state of the different tasks, and also of starting */
/* or stopping the kernel. */
/* */
/* Distribution: This file is part of PICos18. */
/* PICos18 is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 2, or (at your option) */
/* any later version. */
/* */
/* PICos18 is distributed in the hope that it will be */
/* useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or FITNESS FOR A */
/* PARTICULAR PURPOSE. See the GNU General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with gpsim; see the file */
/* COPYING.txt. If not, write to the Free Software */
/* Foundation, 59 Temple Place - Suite 330, */
/* Boston, MA 02111-1307, USA. */
/* */
/* > A special exception to the GPL can be applied should */
/* you wish to distribute a combined work that includes */
/* PICos18, without being obliged to provide the source */
/* code for any proprietary components. */
/* */
/* History: */
/* 2004/09/20 [XM] Create this file. */
/* 2006/01/18 [XM] Removed the temp variables (JohnG improvment). */
/* 2006/07/31 [XM] Fixed bug in TerminateTask (MASK_ID<->MASK_STATE).*/
/* */
/**********************************************************************/
#include "device.h"
/**********************************************************************
* Shared variables defined in other section.
**********************************************************************/
extern char id_tsk_run;
extern char kernelState;
extern void _kernel(void);
extern void _restore_start_adr(void);
extern void _restore_now(void);
/**********************************************************************
* Functions declared in other sections.
**********************************************************************/
#ifdef SHUTDOWNHOOK
extern void ShutdownHook(StatusType Error);
#endif
#ifdef ERRORHOOK
extern void ErrorHook(StatusType Error);
#endif
extern Resource Resource_list[];
extern unsigned char RESOURCENUMBER;
unsigned char FSR1H_MAIN;
unsigned char FSR1L_MAIN;
unsigned char appmode;
unsigned char stack_low, stack_high;
/**********************************************************************
* RAM area of the stack field of a task.
**********************************************************************/
#pragma udata STACK_RAM=0x00A0
TaskType tsk_1_state_ID;
TaskType tsk_2_state_ID;
TaskType tsk_3_state_ID;
TaskType tsk_4_state_ID;
TaskType tsk_5_state_ID;
TaskType tsk_6_state_ID;
TaskType tsk_7_state_ID;
TaskType tsk_8_state_ID;
TaskType tsk_9_state_ID;
TaskType tsk_10_state_ID;
TaskType tsk_11_state_ID;
TaskType tsk_12_state_ID;
TaskType tsk_13_state_ID;
TaskType tsk_14_state_ID;
TaskType tsk_15_state_ID;
TaskType tsk_16_state_ID;
/**********************************************************************
* RAM area of the state field of the task.
**********************************************************************/
#pragma udata STATE_RAM=0x00B0
TaskType tsk_1_activ_prio;
TaskType tsk_2_activ_prio;
TaskType tsk_3_activ_prio;
TaskType tsk_4_activ_prio;
TaskType tsk_5_activ_prio;
TaskType tsk_6_activ_prio;
TaskType tsk_7_activ_prio;
TaskType tsk_8_activ_prio;
TaskType tsk_9_activ_prio;
TaskType tsk_10_activ_prio;
TaskType tsk_11_activ_prio;
TaskType tsk_12_activ_prio;
TaskType tsk_13_activ_prio;
TaskType tsk_14_activ_prio;
TaskType tsk_15_activ_prio;
TaskType tsk_16_activ_prio;
/**********************************************************************
* ROM area of the process manager.
**********************************************************************/
#pragma code KERNEL_ROM
/**********************************************************************
* Modify the priority of a task.
* Not mandatory by OSEK standart.
*
* @param new_prio IN New value of the task priority
* @param TaskID IN ID of the task
* @return Status E_OK if the task ID is correct
* E_OS_ID otherwise
**********************************************************************/
StatusType SetPriority (unsigned char new_prio, TaskType TaskID)
{
unsigned char i;
TaskRefType ptr_task;
ptr_task = (TaskRefType)&tsk_1_state_ID;
for (i = 0; i < MAX_TASK_NB; i++)
{
if ( (*ptr_task & MASK_PRIO) == TaskID )
{
ptr_task = &tsk_1_activ_prio + i;
*ptr_task = *ptr_task & MASK_ACTIV;
*ptr_task += new_prio;
return (E_OK);
}
ptr_task++;
}
return (E_OS_ID);
}
/**********************************************************************
* Modify the priority of a task.
* Not mandatory by OSEK standart.
*
* @param new_prio IN New value of the task priority
* @param TaskID IN ID of the task
* @return Status E_OK if the task ID is correct
* E_OS_ID otherwise
**********************************************************************/
StatusType GetPriority (unsigned char *the_prio, TaskType TaskID)
{
unsigned char i;
TaskRefType ptr_task;
ptr_task = (TaskRefType)&tsk_1_state_ID;
for (i = 0; i < MAX_TASK_NB; i++)
{
if ( (*ptr_task & MASK_ID) == TaskID )
{
ptr_task = &tsk_1_activ_prio + i;
*the_prio = *ptr_task & MASK_PRIO;
return (E_OK);
}
ptr_task++;
}
return (E_OS_ID);
}
/**********************************************************************
* Set id_tsk_run into TaskID or INVALID_TASK (0x10) if the ID is out
* of range.
*
* @param TaskID IN Reference of the task
* @return status Always E_OK
**********************************************************************/
StatusType GetTaskID (TaskRefType TaskID)
{
if ( (id_tsk_run >= 0) && (id_tsk_run < MAX_TASK_NB) )
*TaskID = (TaskType)id_tsk_run;
else
*TaskID = (TaskType)INVALID_TASK;
return (E_OK);
}
/**********************************************************************
* Copy a byte into a buffer.
*
* @param TaksID IN ID of the task
* @param State OUT Reference of the task state
* @return Status E_OK if the task ID is correct
* E_OS_ID otherwise
**********************************************************************/
StatusType GetTaskState (TaskType TaskID, TaskStateRefType State)
{
unsigned char i;
TaskRefType ptr_task;
ptr_task = (TaskRefType)&tsk_1_state_ID;
for (i = 0; i < MAX_TASK_NB; i++)
{
if ( (*ptr_task & MASK_ID) == TaskID )
{
*State = (TaskStateType)(*ptr_task & MASK_STATE);
return (E_OK);
}
ptr_task++;
}
return (E_OS_ID);
}
/**********************************************************************
* Set the task to the READY state and call the scheduler to jump to
* another task if necessary.
*
* @param TaskID IN ID of the task
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -