view gsm-fw/gpf/osl/os_sem_fl.c @ 444:caeff442faf1

os_sem_fl.c: os_ResetSemaphore() done
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 23 Jun 2014 01:10:51 +0000
parents 42f9e12a9ced
children 9eeeef3ff7db
line wrap: on
line source

/*
 * This C module is a reconstruction based on the disassembly of
 * os_sem.obj in frame_na7_db_fl.lib from the Leonardo package.
 */

/* set of included headers from COFF symtab: */
#include <stdio.h>
#include <string.h>
#include "gpfconf.h"	/* FreeCalypso addition */
#include "../../nucleus/nucleus.h"
#include "typedefs.h"
#include "os.h"
#include "gdi.h"
#include "os_types.h"
#include "os_glob.h"

extern T_OS_SEM_TABLE_ENTRY SemTable[];

static NU_SEMAPHORE SemSemCB;

static int
os_GetSemaphoreEntry(USHORT Index, OS_HANDLE *Handle)
{
	static USHORT Idx;

	if (Index == FIRST_ENTRY)
		Idx = 0;
	if (Index == FIRST_ENTRY || Index == NEXT_ENTRY) {
		for (;;) {
			Idx++;
			if (Idx > MaxSemaphores)
				return(OS_ERROR);
			if (SemTable[Idx].Name[0])
				break;
		}
	} else
		Idx = Index;
	if (Idx > MaxSemaphores)
		return(OS_ERROR);
	if (SemTable[Idx].Name[0]) {
		*Handle = Idx;
		return(OS_OK);
	} else
		return(OS_ERROR);
}

GLOBAL LONG
os_SemaphoreInformation(USHORT Index, char *Buffer)
{
	OS_HANDLE Handle;
	OPTION SuspendType;
	UNSIGNED Current, TasksWaiting;
	NU_TASK *First;
	CHAR Name[NU_MAX_NAME];

	if (os_GetSemaphoreEntry(Index, &Handle) < 0)
		return(OS_ERROR);
	if (NU_Semaphore_Information(&SemTable[Handle].SemCB, Name, &Current,
				     &SuspendType, &TasksWaiting, &First)
			!= NU_SUCCESS)
		return(OS_ERROR);
	sprintf(Buffer, "Semname:%s Count:%ld Suspend:%d Waiting:%ld", Name,
		Current, SuspendType, TasksWaiting);
	return(OS_OK);
}

GLOBAL LONG
os_SemInit(void)
{
	USHORT i;

	if (NU_Create_Semaphore(&SemSemCB, "SEMSEM", 1, NU_PRIORITY)
			!= NU_SUCCESS)
		return(OS_ERROR);
	for (i = 1; i <= MaxSemaphores; i++)
		bzero(&SemTable[i], sizeof(T_OS_SEM_TABLE_ENTRY));
	return(OS_OK);
}

GLOBAL LONG
os_ResetSemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle,
		  USHORT init_counter)
{
	STATUS sts;

	sts = NU_Obtain_Semaphore(&SemSemCB, NU_SUSPEND);
	if (!SemTable[SemHandle].Name[0]) {
error_out:	if (sts == NU_SUCCESS)
			NU_Release_Semaphore(&SemSemCB);
		return(OS_ERROR);
	}
	if (NU_Reset_Semaphore(&SemTable[SemHandle].SemCB, init_counter)
			!= NU_SUCCESS)
		goto error_out;
	if (sts == NU_SUCCESS)
		NU_Release_Semaphore(&SemSemCB);
	return(OS_OK);
}