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

📄 objcore.cpp

📁 基于Nuleus操作系统和s3c4510的编写的EFC。已经包含了该EFC的设计说明。这是个实际产品的代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Return Value:
//		pointer of the HISR been created if successful, otherwise NULL
// Remarks:
//		create a High-Level Interrupt Service Routine (HISR).
NU_HISR* CRTObject::CreateHISR(LPCSTR lpszName, PFNHISR pfnHISR, 
							   DWORD dwStackSize, OPTION oPriority)
{
	ASSERT(lpszName);
	ASSERT(pfnHISR);

	NU_HISR *pHISR = NULL;

	// check if the HISR of this name has been created before in DEBUG 
	//   version.
	ASSERT(!m_mapHISRs.Lookup(lpszName, pHISR));	// Check existing

	pHISR = new NU_HISR;
	ASSERT(pHISR);

	BYTE *puMem = new BYTE[dwStackSize];
	ASSERT(puMem);

	HISRCALLBACK<CRTObject> *pCallback = new HISRCALLBACK<CRTObject>;
	ASSERT(pCallback);
	pCallback->pThis = this;
	pCallback->pfnHISR = pfnHISR;
	if (NU_Create_HISR(pHISR, (LPSTR)lpszName, HISRProc, oPriority, puMem,
		dwStackSize) != NU_SUCCESS)
	{//failed to create HISR
		delete pHISR;
		pHISR = NULL;
		delete[] puMem;
		delete pCallback;
		ASSERT(FALSE);
	}
	else
	{
		((TC_HCB*)pHISR)->tc_app_reserved_1 = (DWORD)pCallback;
		m_mapHISRs.SetAt(lpszName, pHISR);
	}
	return pHISR;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszName		name of the mailbox been created.
//		oSuspendType	NU_FIFO/NU_PRIORITY
// Return Value:
//		pointer of the Mailbox been created if successful, otherwise NULL
// Remarks:
//		create an application mailbox
NU_MAILBOX* CRTObject::CreateMailbox(LPCSTR lpszName, OPTION oSuspendType)
{
	ASSERT(lpszName);
	
	NU_MAILBOX *pMailbox = NULL;
	
	// check if the Mailbox of this name has been created before in DEBUG 
	//   version.
	ASSERT(!m_mapMailboxes.Lookup(lpszName, pMailbox));	// Check existing
	
	pMailbox = new NU_MAILBOX;
	ASSERT(pMailbox);
	if (NU_Create_Mailbox(pMailbox, (LPSTR)lpszName, oSuspendType) != NU_SUCCESS)
	{
		delete pMailbox;
		pMailbox = NULL;
		ASSERT(FALSE);
	}
	else
	{
		m_mapMailboxes.SetAt(lpszName, pMailbox);
	}
	return pMailbox;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszName		name of the pipe will been created
//		dwPipeSize		total number of bytes in the pipe
//		oMessageType	the type of the messsage managed by the pipe
//						NU_FIXED_SIZE/NU_VARIABLE_SIZE
//		dwMessageSize	size of each message in bytes
//		oSuspendType	sepcify how task suspend on the pipe.(NU_FIFO/NU_PRIORITY)
// Return Value:
//		pointer of the pipe been created if successful, otherwise NULL
// Remarks:
//		create an application pipe.
NU_PIPE* CRTObject::CreatePipe(LPCSTR lpszName, DWORD dwPipeSize, 
				OPTION oMessageType, DWORD dwMessageSize, OPTION oSuspendType)
{
	ASSERT(lpszName);
	NU_PIPE *pPipe = NULL;
	
	// check if the pipe of this name has been created before in DEBUG 
	//   version.
	ASSERT(!m_mapPipes.Lookup(lpszName, pPipe)); // Check exists

	pPipe = new NU_PIPE;
	ASSERT(pPipe);
	
	BYTE *puMem = new BYTE[dwPipeSize * dwMessageSize];
	ASSERT(puMem);
	
	if (NU_Create_Pipe(pPipe, (LPSTR)lpszName, puMem, dwPipeSize,
		oMessageType, dwMessageSize, oSuspendType) != NU_SUCCESS)
	{// failed to create pipe
		delete pPipe;
		pPipe = NULL;
		delete[] puMem;
		ASSERT(FALSE);
	}
	else
	{
		m_mapPipes.SetAt(lpszName, pPipe);
	}
	return pPipe;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszName	The name of the task been found.
// Remarks:
//		Find the task by the name
NU_TASK* CRTObject::FindTask(LPCSTR lpszName) const
{
	ASSERT(lpszName);
	
	NU_TASK *pTask = NULL;
	
	m_mapTasks.Lookup(lpszName, pTask);
	return pTask;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszName	The name of the timer been found.
// Remarks:
//		Find the timer by the name
NU_TIMER* CRTObject::FindTimer(LPCSTR lpszName) const
{
	ASSERT(lpszName);
	
	NU_TIMER *pTimer = NULL;
	
	m_mapTimers.Lookup(lpszName, pTimer);
	return pTimer;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszName	The name of the driver been found.
// Remarks:
//		Find the I/O driver by the name of the driver
NU_DRIVER* CRTObject::FindDriver(LPCSTR lpszName) const
{
	ASSERT(lpszName);

	NU_DRIVER *pDriver = NULL;

	m_mapDrivers.Lookup(lpszName, pDriver);
	return pDriver;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszName	The name of the queue been found.
// Remarks:
//		Find the queue by the name of the queue
NU_QUEUE* CRTObject::FindQueue(LPCSTR lpszName) const
{
	ASSERT(lpszName);

	NU_QUEUE *pQueue = NULL;

	m_mapQueues.Lookup(lpszName, pQueue);
	return pQueue;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszName	The name of the event group been found.
// Remarks:
//		Find the event group by the name of the event group
NU_EVENT_GROUP* CRTObject::FindEventGroup(LPCSTR lpszName) const
{
	ASSERT(lpszName);
	
	NU_EVENT_GROUP *pEventGroup = NULL;

	m_mapEventGroups.Lookup(lpszName, pEventGroup);
	return pEventGroup;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszName	The name of the semaphore been found.
// Remarks:
//		Find the semaphore by the name
NU_SEMAPHORE* CRTObject::FindSemaphore(LPCSTR lpszName) const
{
	ASSERT(lpszName);
	
	NU_SEMAPHORE *pSemaphore = NULL;

	m_mapSemaphores.Lookup(lpszName, pSemaphore);
	return pSemaphore;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszName	The name of the HISR been found.
// Remarks:
//		Find the HISR by the name
NU_HISR* CRTObject::FindHISR(LPCSTR lpszName) const
{
	ASSERT(lpszName);
	NU_HISR *pHISR = NULL;
	m_mapHISRs.Lookup(lpszName, pHISR);
	return pHISR;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszName	The name of the Mailbox been found.
// Remarks:
//		Find the Mailbox by name
NU_MAILBOX* CRTObject::FindMailbox(LPCSTR lpszName) const
{
	ASSERT(lpszName);
	NU_MAILBOX *pMailbox = NULL;
	m_mapMailboxes.Lookup(lpszName, pMailbox);
	return pMailbox;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszName	The name of the pipe been found.
// Remarks:
//		Find the pipe by name
NU_PIPE* CRTObject::FindPipe(LPCSTR lpszName) const
{
	ASSERT(lpszName);
	NU_PIPE *pPipe = NULL;
	m_mapPipes.Lookup(lpszName, pPipe);
	return pPipe;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszTaskName	name of the task been deleted
// Return Value:
//		TRUE if successful, otherwise FALSE.
// Remarks:
//		Deletes a previously created application task.  
//		Note that the specified task must be either in a finished or terminated 
//		state prior to calling this service.  
BOOL CRTObject::DeleteTask(LPCSTR lpszTaskName)
{
	BOOL bRetVal = FALSE;
	ASSERT(lpszTaskName);
	NU_TASK *pTask = NULL;
	if (m_mapTasks.Lookup(lpszTaskName, pTask))
	{
		ASSERT(pTask);
		if (pTask != NU_Current_Task_Pointer())
		{
			VERIFY(NU_Terminate_Task(pTask) == NU_SUCCESS);
		}
		if (NU_Delete_Task(pTask) == NU_SUCCESS)
		{// free memory occupied by the task.
			delete[] (BYTE*)((TC_TCB*)pTask)->tc_stack_start;
			delete pTask;			
			bRetVal = m_mapTasks.RemoveKey(lpszTaskName);
		}
		ASSERT(bRetVal);
	}
	return bRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszTimerName	name of the timer been deleted
// Return Value:
//		TRUE if successful, otherwise FALSE.
// Remarks:
//		Deletes a previously created application timer.  
BOOL CRTObject::DeleteTimer(LPCSTR lpszTimerName)
{
	BOOL bRetVal = FALSE;
	ASSERT(lpszTimerName);
	NU_TIMER *pTimer = NULL;
	if (m_mapTimers.Lookup(lpszTimerName, pTimer))
	{
		ASSERT(pTimer);

		VERIFY(NU_Control_Timer(pTimer, NU_DISABLE_TIMER) == NU_SUCCESS);

		if (NU_Delete_Timer(pTimer) == NU_SUCCESS)
		{
			// free callback parameter block.
			delete (TIMERCALLBACK<CRTObject>*)((TM_APP_TCB*)pTimer)->tm_expiration_id;
			delete pTimer;
			bRetVal = m_mapTimers.RemoveKey(lpszTimerName);
		}
		ASSERT(bRetVal);
	}
	return bRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszDriverName	name of the driver been deleted
// Return Value:
//		TRUE if successful, otherwise FALSE.
// Remarks:
//		Deletes a previously created application driver.  
//		Note all usage of the specified driver must be complete prior to 
//		calling this service.
BOOL CRTObject::DeleteDriver(LPCSTR lpszDriverName)
{
	BOOL bRetVal = FALSE;
	ASSERT(lpszDriverName);
	NU_DRIVER *pDriver = NULL;
	if (m_mapDrivers.Lookup(lpszDriverName, pDriver))
	{
		ASSERT(pDriver);
		if (NU_Delete_Driver(pDriver) == NU_SUCCESS)
		{// free memory occupied by driver
			delete pDriver;
			bRetVal = m_mapDrivers.RemoveKey(lpszDriverName);
		}
		ASSERT(bRetVal);
	}
	return bRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszQueueName	name of the queue been deleted
// Return Value:
//		TRUE if successful, otherwise FALSE.
// Remarks:
//		Deletes a previously created application queue.  
//		Note all usage of the specified driver must be complete prior to 
//		calling this service.
BOOL CRTObject::DeleteQueue(LPCSTR lpszQueueName)
{
	BOOL bRetVal = FALSE;
	ASSERT(lpszQueueName);
	NU_QUEUE *pQueue = NULL;
	if (m_mapQueues.Lookup(lpszQueueName, pQueue))
	{
		ASSERT(pQueue);
		if (NU_Delete_Queue(pQueue) == NU_SUCCESS)
		{// free memory
			delete[] (BYTE*)((QU_QCB*)pQueue)->qu_start;
			delete pQueue;
			bRetVal = m_mapQueues.RemoveKey(lpszQueueName);
		}
		ASSERT(bRetVal);
	}
	return bRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszEventGroupName	name of the event group been deleted
// Return Value:
//		TRUE if successful, otherwise FALSE.
// Remarks:
//		Deletes a previously created application event group.  
BOOL CRTObject::DeleteEventGroup(LPCSTR lpszEventGroupName)
{
	BOOL bRetVal = FALSE;
	ASSERT(lpszEventGroupName);
	NU_EVENT_GROUP *pEventGroup = NULL;
	if (m_mapEventGroups.Lookup(lpszEventGroupName, pEventGroup))
	{
		ASSERT(pEventGroup);
		if (NU_Delete_Event_Group(pEventGroup) == NU_SUCCESS)
		{// free memory
			delete pEventGroup;
			bRetVal = m_mapEventGroups.RemoveKey(lpszEventGroupName);
		}
		ASSERT(bRetVal);
	}
	return bRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszSemaphoreName	name of the event group been deleted
// Return Value:
//		TRUE if successful, otherwise FALSE.
// Remarks:
//		Deletes a previously created application sempahore.  
BOOL CRTObject::DeleteSemaphore(LPCSTR lpszSemaphoreName)
{
	BOOL bRetVal = FALSE;
	ASSERT(lpszSemaphoreName);
	NU_SEMAPHORE *pSemaphore = NULL;
	if (m_mapSemaphores.Lookup(lpszSemaphoreName, pSemaphore))
	{
		ASSERT(pSemaphore);
		if (NU_Delete_Semaphore(pSemaphore) == NU_SUCCESS)
		{// free memory
			delete pSemaphore;
			bRetVal = m_mapSemaphores.RemoveKey(lpszSemaphoreName);
		}
		ASSERT(bRetVal);
	}
	return bRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszHISRName	name of the HISR been deleted
// Return Value:
//		TRUE if successful, otherwise FALSE.
// Remarks:
//		Deletes a previously created application HISR.  
BOOL CRTObject::DeleteHISR(LPCSTR lpszHISRName)
{
	BOOL bRetVal = FALSE;
	ASSERT(lpszHISRName);
	NU_HISR *pHISR = NULL;
	if (m_mapHISRs.Lookup(lpszHISRName, pHISR))
	{
		ASSERT(pHISR);
		if (NU_Delete_HISR(pHISR) == NU_SUCCESS)
		{// free memory occupied by the HISR
			delete[] (BYTE*)((TC_HCB*)pHISR)->tc_stack_start;
			delete (HISRCALLBACK<CRTObject>*)((TC_HCB*)pHISR)->tc_app_reserved_1;
			delete pHISR;
			bRetVal = m_mapHISRs.RemoveKey(lpszHISRName);
		}
		ASSERT(bRetVal);
	}
	return bRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszMailboxName		name of the Mailbox been deleted
// Return Value:
//		TRUE if successful, otherwise FALSE.
// Remarks:
//		Deletes a previously created application Mailbox.  
BOOL CRTObject::DeleteMailbox(LPCSTR lpszMailboxName)
{
	BOOL bRetVal = FALSE;
	ASSERT(lpszMailboxName);
	NU_MAILBOX* pMailbox = NULL;
	if (m_mapMailboxes.Lookup(lpszMailboxName, pMailbox))
	{
		ASSERT(pMailbox);
		if (NU_Delete_Mailbox(pMailbox) == NU_SUCCESS)
		{// free memory
			delete pMailbox;
			bRetVal = m_mapMailboxes.RemoveKey(lpszMailboxName);
		}
		ASSERT(bRetVal);
	}
	return bRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszMailboxName		name of the pipe been deleted
// Return Value:
//		TRUE if successful, otherwise FALSE.
// Remarks:
//		Deletes a previously created application pipe.  
BOOL CRTObject::DeletePipe(LPCSTR lpszPipeName)
{
	BOOL bRetVal = FALSE;
	ASSERT(lpszPipeName);
	NU_PIPE *pPipe = NULL;
	if (m_mapPipes.Lookup(lpszPipeName, pPipe))
	{
		ASSERT(pPipe);
		if (NU_Delete_Pipe(pPipe) == NU_SUCCESS)
		{// free memory
			delete[] (BYTE*)((PI_PCB*)pPipe)->pi_start;
			delete pPipe;
			bRetVal = m_mapPipes.RemoveKey(lpszPipeName);
		}
		ASSERT(bRetVal);
	}
	return bRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		nIDEvent	Specifies the identifier of the timer.
// Remarks:
//		The framework calls this member function after each interval specified 
//		in the CreateTimer function used to install a timer.
void CRTObject::OnTimer(UINT nIDEvent)
{
	UNUSED_ALWAYS(nIDEvent);
}

⌨️ 快捷键说明

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