⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 synchronization.h

📁 嵌入式操作系统EOS(Embedded OperatingSystem)是一种用途广泛的系统软件
💻 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 _SYNCHRONIZATION
#define _SYNCHRONIZATION

#include "general_definitions.h"
//#include "queue.h"
#include "priority_queue.h"

typedef enum
{
	eMutexNotAllocated = 0,
	eMutexLocked,
	eMutexUnlocked
} mutex_state ;

typedef enum
{
	eSemaphoreNotAllocated = 0,
	eSemaphoreLocked,
	eSemaphoreUnlocked
} semaphore_state ;

typedef struct
{
	int16s					id ;
	int16s					owner ;
	mutex_state				state ;
	// a counter that makes sure that if a mutex is locked 'x' times by a task, it must be unlocked 'x' times by that task before the lock is released
 	// note that a different task can decrement this counter to possibly force a lock release
	int16s					refCnt ;
	priority_queue_info		blocked_tasks ;
	//queue_info		blocked_tasks ;
} mutex_info ;

typedef struct
{
	int8u			lockBit ; // 1 is locked, 0 unlocked. must be the first element in the structure!
	int16s			id ;
	int16s			owner ;
	semaphore_state	state ;
	int16s			refCnt ;
	int16s			maxRef ;
	priority_queue_info		blocked_tasks ;
	int16s			max_locks_allowed ;
} semaphore_info ;

//ILVL(PSW): The four-bit Interrupt Level field (ILVL) specifies the priority of the current CPU
//activity. The interrupt level is updated by hardware on entry into an interrupt service
//routine, but it can also be modified via software to prevent other interrupts from being
//acknowledged. If an interrupt level 15 has been assigned to the CPU, it has the highest
//possible priority; thus, the current CPU operation cannot be interrupted except by
//hardware traps or external non-maskable interrupts.*/
#define REFUSE_INTERRUPT_CONTEXT \
if ((PSW & 0xF000) > 0 ) \
{\
	software_error("%s %s %d", resolve_system_message(ERR_SYSTEM_CALL_AT_INTERRUPT_CONTEXT), __FILE__, __LINE__ ) ;\
}

// module interface starts here

// mutex
int16s 	rtos_mutex_lock(int16s) ;
int16s 	rtos_mutex_unlock(int16s) ;
int16s 	rtos_allocate_mutex() ;
int16s 	rtos_deallocate_mutex(int16s) ;
int16s	rtos_is_mutex_locked(int16s) ;
int16s	rtos_mutex_get_owner(int16s) ;
int16s 	rtos_mutex_set_blocked_task_priority(int16s, int16s, int8u) ;

// semaphore
int16s 	rtos_semaphore_lock(int16s) ;
int16s 	rtos_semaphore_unlock(int16s) ;
int32s 	rtos_allocate_semaphore(int16s) ;
int32s 	rtos_deallocate_semaphore(int16s) ;
int16s	rtos_is_semaphore_locked(int16s) ;
int16s	rtos_get_semaphore_ref_count(int16s) ;
int16s 	rtos_semaphore_set_blocked_task_priority(int16s, int16s, int8u) ;

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -