📄 portkern.c
字号:
//
// portkern.c
//
// EBS - ERTFS
//
// Copyright EBS Inc , 1993,1994,1995
// All rights reserved.
// This code may not be redistributed in source or linkable object form
// without the consent of its author.
//
//
// Module description:
// This file contains subroutines that are kernel specific.
// See also portkern.h
//
// This is for ERTFS_STAND_ALONE only. Not used in RTIP enviroment
#include <pcdisk.h>
// ********************************************************************
// ENABLE/DISABLE INTERRUPTS
// ********************************************************************
/* enable interrupts inside an interrupt service routine */
void ks_enable(void) /*__fn__*/
{
#if (defined(__BORLANDC__) || defined(_MSC_VER) )
__asm sti
#elif (CMXD860)
#define ENABLE8XX() __asm (" mtspr 80, 0 "); /* EIE reg (505 & 800 core specific) writing anything to this reg sets EE & RI */
ENABLE8XX() // defined in eth860.h
#elif (MC68K)
#if (SDS)
asm( " AndI #~0700h,SR" );
#elif (MRI)
asm( " AndI #$f8ff,SR" );
#else
#error: Implement ks_enable for your compiler in portkern.c
#endif
#elif (__PSOS__)
#error Must implement ks_enable for PSOS in PORTKERN.C
#elif (NOSTRIP)
#error Must implement ks_enable in PORTKERN.C
#endif
}
void ks_disable(void)
{
#if (defined(__BORLANDC__) || defined(_MSC_VER) )
__asm cli
#elif (CMXD860)
#define DISABLE8XX() __asm (" mtspr 81, 0 "); /* EID reg (505 & 800 core specific) writing anything to this reg clears EE & sets RI */
DISABLE8XX() // defined in eth860.h
#elif (MC68K)
#if (SDS)
asm(" OrI #0700h,SR");
#elif (MRI)
asm(" OrI #0700h,SR");
#else
#error Must implement ks_disable
#endif
#elif (__PSOS__)
#error Must implement ks_disable for PSOS in PORTKERN.C
#elif (NOSTRIP)
#error Implement ks_disable for your CPU in PORTKERN.C
#endif
}
/* Declare semaphores */
#if (defined(PLUS))
NU_SEMAPHORE fs_drivesem[NDRIVES];
NU_SEMAPHORE fs_iosem[NDRIVES];
NU_SEMAPHORE fs_critsem;
#elif (defined(RTPX))
MUTEX fs_drivesem[NDRIVES];
MUTEX fs_iosem[NDRIVES];
MUTEX fs_critsem;
#elif (defined(CMX))
byte fs_drivesem[NDRIVES];
byte fs_iosem[NDRIVES];
byte fs_critsem;
#elif (defined(UCOS))
OS_EVENT *fs_drivesem[NDRIVES];
OS_EVENT *fs_iosem[NDRIVES];
OS_EVENT *fs_critsem;
#elif (defined(POLLOS))
/* POLLOS DOESN'T NEED SEMAPHORES */
#elif (defined(__PSOS__))
ULONG fs_drivesem[NDRIVES];
ULONG fs_iosem[NDRIVES];
ULONG fs_critsem;
#elif (NOSTRIP)
#error Please declare semaphores for your kernel
#endif
/* Declare signals */
#if (defined(PLUS))
NU_SEMAPHORE floppy_signal;
NU_SEMAPHORE ide_signal[N_ATA_CONTROLLERS];
#elif (defined(RTPX))
SEMAPHORE floppy_signal;
SEMAPHORE ide_signal[N_ATA_CONTROLLERS];
#elif (defined(CMX))
byte floppy_signal;
byte ide_signal[N_ATA_CONTROLLERS];
#elif (defined(UCOS))
OS_EVENT *floppy_signal;
OS_EVENT *ide_signal[N_ATA_CONTROLLERS];
#elif (defined(POLLOS))
/* POLLOS USES Simple counters for signals */
int floppy_signal;
int ide_signal[N_ATA_CONTROLLERS];
#elif (defined(RTPX))
ULONG floppy_signal;
ULONG ide_signal[N_ATA_CONTROLLERS];
#elif (NOSTRIP)
#error Please declare counting semaphores for your kernel
#endif
#if (USE_FLOPPY)
#if (defined(PLUS))
/* Define a timer task that polls and shuts off the floppy motor */
void fl_motor_off(void);
#define TIMER_STACK_SIZE 1024
char timer_stack[TIMER_STACK_SIZE];
NU_TASK timer_task;
void KS_FAR tc_timer(dword arg)
{
while (1)
{
ks_sleep(ks_ticks_p_sec());
// Allow the floppy driver to shut off the motor if it needs to
fl_motor_off();
}
}
#elif (defined(RTPX)||NOSTRIP)
/* Define a timer task that polls and shuts off the floppy motor */
void fl_motor_off(void);
2define TIMER_STACK_SIZE 1024
char timer_stack[TIMER_STACK_SIZE];
TASK timer_task;
void KS_FAR tc_timer(dword arg)
{
while (1)
{
ks_sleep(ks_ticks_p_sec());
// Allow the floppy driver to shut off the motor if it needs to
fl_motor_off();
}
}
#elif (defined(CMX))
/* Define a timer task that polls and shuts off the floppy motor */
void fl_motor_off(void);
#define TIMER_STACK_SIZE 1024
byte timer_stack[TIMER_STACK_SIZE];
byte timer_task;
void tc_timer(void)
{
while (1)
{
ks_sleep(ks_ticks_p_sec());
// Allow the floppy driver to shut off the motor if it needs to
fl_motor_off();
}
}
#elif (defined(UCOS))
/* Define a timer task that polls and shuts off the floppy motor */
void fl_motor_off(void);
#define TIMER_STACK_SIZE 1024
#define UCOS_TIMER_PRIO 10
char timer_stack[TIMER_STACK_SIZE];
void tc_timer(void *p)
{
while (1)
{
ks_sleep(ks_ticks_p_sec());
// Allow the floppy driver to shut off the motor if it needs to
fl_motor_off();
}
}
#elif (defined(__PSOS__))
/* Define a timer task that polls and shuts off the floppy motor */
void fl_motor_off(void);
#define TIMER_STACK_SIZE 1024
#define UCOS_TIMER_PRIO 10
char timer_stack[TIMER_STACK_SIZE];
void tc_timer(void)
{
while (1)
{
ks_sleep(ks_ticks_p_sec());
// Allow the floppy driver to shut off the motor if it needs to
fl_motor_off();
}
}
#elif (defined(POLLOS))
#else
#error - define a background task that calls fl_motor_off every second
#endif
#endif
/* Resource initialization routine. This is a non-reentrant routine that is
called by _pc_memory_init() which is in turn called by the check mem
macros at the entry to the API calls.
This routine creates the signals and semaphores required by the
file system and starts a timer task running to control the floppy
motor
*/
#if (defined(CMX))
static byte cmx_sig_to_alloc = C_MAX_SEMAPHORES;
static byte cmx_rsrc_to_alloc = C_MAX_RESOURCES;
#endif
void init_user_table(void);
BOOLEAN ks_resource_init(void) /*__fn__*/
{
#if (!defined(POLLOS))
int i;
#endif
// Build RTFS Semaphores if the file system is included;
// one per drive for accessing the fat and finodes
// one per drive to keep IO single threaded.
// NOTE: Since two logical drives can share the same
// interface at run time we calculate which semaphore to
// wait on when before we access the controller.
#if (defined(PLUS))
for (i = 0; i < NDRIVES; i++)
{
if (NU_Create_Semaphore(&fs_drivesem[i], "DRVSEM", 1, NU_FIFO) != NU_SUCCESS)
return(FALSE);
if (NU_Create_Semaphore(&fs_iosem[i], "IOSEM", 1, NU_FIFO) != NU_SUCCESS)
return(FALSE);
}
// Semaphores for exclusive access to the buffer pool and other
// critical regions..
if (NU_Create_Semaphore(&fs_critsem, "CRTSEM", 1, NU_FIFO) != NU_SUCCESS)
return(FALSE);
#elif (defined(RTPX))
for (i = 0; i < NDRIVES; i++)
{
fs_drivesem[i]=px_mutex_alloc();
if (!fs_drivesem[i])
return(FALSE);
fs_iosem[i]=px_mutex_alloc();
if (!fs_iosem[i])
return(FALSE);
}
// Semaphores for exclusive access to the buffer pool and other
// critical regions..
fs_critsem=px_mutex_alloc();
if (!fs_critsem)
return(FALSE);
#elif (defined(CMX))
for (i = 0; i < NDRIVES; i++)
{
fs_drivesem[i]= --cmx_rsrc_to_alloc;
if (!fs_drivesem[i])
return(FALSE);
fs_iosem[i]= --cmx_rsrc_to_alloc;
if (!fs_iosem[i])
return(FALSE);
}
// Semaphores for exclusive access to the buffer pool and other
// critical regions..
fs_critsem= --cmx_rsrc_to_alloc;
if (!fs_critsem)
return(FALSE);
#elif (defined(UCOS))
for (i = 0; i < NDRIVES; i++)
{
fs_drivesem[i]=OSSemCreate(1);
if (!fs_drivesem[i])
return(FALSE);
fs_iosem[i]=OSSemCreate(1);
if (!fs_iosem[i])
return(FALSE);
}
// Semaphores for exclusive access to the buffer pool and other
// critical regions..
fs_critsem=OSSemCreate(1);
if (!fs_critsem)
return(FALSE);
#elif (defined(__PSOS__))
for (i = 0; i < NDRIVES; i++)
{
if (sm_create("HACK", 1,SM_GLOBAL|SM_PRIOR, &fs_drivesem[i] ) != 0)
return(FALSE);
if (sm_create("HACK", 1,SM_GLOBAL|SM_PRIOR, &fs_iosem[i] ) != 0)
return(FALSE);
}
// Semaphores for exclusive access to the buffer pool and other
// critical regions..
if (sm_create("HACK", 1,SM_GLOBAL|SM_PRIOR, &fs_icritsem) != 0)
return(FALSE);
#elif (defined(POLLOS))
/* POLLOS DOESN'T NEED SEMAPHORES */
#else
#error Please initialize semaphores for your kernel
#endif
// Build RTFS Interrupt signals if the file system is included
#if (USE_ATA)
#if (defined(PLUS))
if (NU_Create_Semaphore(&ide_signal[0], "IDESIG", 0, NU_FIFO) != NU_SUCCESS)
return(FALSE);
if (NU_Create_Semaphore(&ide_signal[1], "IDESIG", 0, NU_FIFO) != NU_SUCCESS)
return(FALSE);
#elif (defined(RTPX))
ide_signal[0] = px_semaphore_alloc(0);
if (!ide_signal[0])
return(FALSE);
ide_signal[1] = px_semaphore_alloc(0);
if (!ide_signal[1])
return(FALSE);
#elif (defined(CMX))
#define CHKSIG(X) (!X || (K_Semaphore_Create(X,0) != K_OK))
ide_signal[0] = --cmx_sig_to_alloc;
if (!CHKSIG(ide_signal[0]))
return(FALSE);
ide_signal[1] = --cmx_sig_to_alloc;
if (!CHKSIG(ide_signal[1]))
return(FALSE);
#elif (defined(UCOS))
ide_signal[0] = OSSemCreate(0);
if (!ide_signal[0])
return(FALSE);
ide_signal[1] = OSSemCreate(0);
if (!ide_signal[1])
return(FALSE);
#elif (defined(__PSOS__))
#define KS_SIGNAL_BUILD(X) if (sm_create("HAC2", 0,SM_GLOBAL|SM_PRIOR, &(X) ) != 0) return(FALSE);
KS_SIGNAL_BUILD(ide_signal[0])
KS_SIGNAL_BUILD(ide_signal[1])
#elif (defined(POLLOS))
/* POLLOS USES Simple counters for signals */
ide_signal[0] = 0;
ide_signal[1] = 0;
#else
#error Please initialize ide counting semaphores for your kernel
#endif
#endif
#if (USE_FLOPPY)
#if (defined(PLUS))
if (NU_Create_Semaphore(&floppy_signal, "FLPSIG", 0, NU_FIFO) != NU_SUCCESS)
return(FALSE);
#elif (defined(RTPX))
floppy_signal = px_semaphore_alloc(0);
if (!floppy_signal)
return(FALSE);
#elif (defined(CMX))
floppy_signal = --cmx_sig_to_alloc;
if (!CHKSIG(floppy_signal))
return(FALSE);
#elif (defined(UCOS))
floppy_signal = OSSemCreate(0);
if (!floppy_signal)
return(FALSE);
#elif (defined(__PSOS__))
KS_SIGNAL_BUILD(floppy_signal)
#elif (defined(POLLOS))
/* POLLOS USES Simple counters for signals */
floppy_signal = 0;
#else
#error Please initialize floppy counting semaphore for your kernel
#endif
#endif
#if (USE_FLOPPY)
#if (defined(PLUS))
// start the timer task
if (NU_Create_Task(&timer_task,
"TIMER",
tc_timer,
0, 0, /* argc, argv */
timer_stack, /* stack */
TIMER_STACK_SIZE, /* stack size */
(OPTION)10, /* priority */
(OPTION)0, /* time slice */
(OPTION)NU_PREEMPT, (OPTION)NU_START) != NU_SUCCESS)
return(FALSE); // failure
#elif (defined(RTPX))
// start the timer task
timer_task =
px_task_create("TIMER", tc_timer,
10,
TRUE, TIMER_STACK_SIZE,
timer_stack);
if (!timer_task)
return(FALSE); // failure
#elif (defined(CMX))
if (!K_Task_Create_Stack((byte)10, &timer_task, tc_timer,
(word32 *)(&timer_stack[TIMER_STACK_SIZE-4])) != K_OK)
return(FALSE); // failure
if (K_Task_Start(timer_task) != K_OK)
return(FALSE);
#elif (defined(UCOS))
if (OSTaskCreate(tc_timer, (void *) 0,
&timer_stack[TIMER_STACK_SIZE-2],
UCOS_TIMER_PRIO) != OS_NO_ERR)
{
tm_printf("Spawn of timer task failed. change priority ?\n");
return(FALSE);
}
#elif (defined(__PSOS__))
#error - Spawn timer task for PSOS here
#elif (defined(POLLOS))
// Need to make the system timer shuts off the floppy motor
#else
#error - define a background task that calls fl_motor_off every second
#endif
#endif
/* Initialize a user table */
init_user_table();
return(TRUE);
}
/* Claim and release semaphores. These are called by macros defied in
portkern.h
*/
void ks_claim_logdrive(int driveno)
{
#if (defined(PLUS))
NU_Obtain_Semaphore(&fs_drivesem[driveno],NU_SUSPEND);
#elif (defined(RTPX))
px_mutex_wait(fs_drivesem[driveno], RTPX_INF);
#elif (defined(CMX))
K_I_Resource_Common(fs_drivesem[driveno],0,0);
#elif (defined(UCOS))
byte err;
OSSemPend(fs_drivesem[driveno], 0, &err);
#elif (defined(__PSOS__))
sm_p(fs_drivesem[driveno],SM_WAIT, 0);
#elif (defined(POLLOS))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -