📄 isrs.h
字号:
/*
** Copyright (C) 2006 Tamir Michael
**
** This program 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 of the License, or
** (at your option) any later version.
**
** This program 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 this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _ISRS
#define _ISRS
#include "rtos_services.h"
#include "system_messages.h"
#include <XC167.h>
extern int16s g_vector_to_task_index[NUM_INTERRUPTS] ;
extern int16s g_force_switch_to_task_interrupt_occurred ;
extern task_info g_tcb[MAX_TASKS] ; // TCB - task control block. this is a global.
extern prio_array *s_primary_ready_to_run_tasks ;
// this macro register to a certain interrupt by generating the ISR. after the interrupt has occured, it forces
// a context switch to that task.
static void isr_service(unsigned short a_vector)
{
PSW_IEN = 0 ; // nested interrupts are not supported at this time. this ISR uses
// global data and in addition to that, if the scheduler interrupt this ISR before it
// is completed, the program is unlikely to resume correctly.
if (g_vector_to_task_index[a_vector - 0x10] != ERR_TASK_NOT_FOUND)
{
g_force_switch_to_task_interrupt_occurred = g_vector_to_task_index[a_vector - 0x10] ;
g_vector_to_task_index[a_vector - 0x10] = ERR_TASK_NOT_FOUND ;
g_tcb[g_force_switch_to_task_interrupt_occurred].prior_to_context_switch_callback_when_interrupted() ;
if (g_tcb[g_force_switch_to_task_interrupt_occurred].immediate_switch_to_waiting_task_when_interrupted == 1)
{
CC1_T0IC_IR = 1 ;
}
else
{
queue_enqueue(&s_primary_ready_to_run_tasks->priority_queues[g_tcb[g_force_switch_to_task_interrupt_occurred].priority], g_force_switch_to_task_interrupt_occurred) ;
s_primary_ready_to_run_tasks->priority_bitmap |= 1<<g_tcb[g_force_switch_to_task_interrupt_occurred].priority ;
g_tcb[g_force_switch_to_task_interrupt_occurred].status = eTaskReady ;
}
}
else
{
}
PSW_IEN = 1 ;
}
// WAR STORY
// due to the nature of the interrupt system, the 'RETI' instruction for this ISR shall be executed only after
// the 'RETI' for the context switch. but there is danger that before the 'rtos_interrupt_wait'ing task reads data
// from shared memory/CAN interface and so on, that data shall in invalidated by a new interrupt. that is why
// 'prior_to_context_switch_callback_when_interrupted' can be used to save incoming data from a device before
// any RETI occurs (while the ISR is running) so that the developer has an oppertunity to prevent data loss due to
// a consequent interrupt arriving before his task was able to handle the previous one.
// 'immediate_switch_to_waiting_task_when_interrupted' will invoke a forced context switch to the task that waits for the interrupt.
// if it is not set, only the callback will be called and the task, declared ready to run, will be run ASAP.
// note that it is tested whether there is no mapping to a task index - because maybe the task was deleted in the
// mean time(after calling 'rtos_interrupt_wait')
// the embedded function call reduces ROM footprint (as this is a macro) in exchange
// for a small performance penalty.
#define ISR(a_vector)\
void ISR##a_vector() interrupt a_vector\
{\
isr_service(a_vector) ;\
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -