portkern.c
来自「ertfs文件系统里面既有完整ucos程序」· C语言 代码 · 共 643 行 · 第 1/2 页
C
643 行
{
#if (defined(PLUS))
return(NU_Retrieve_Clock());
#elif (defined(UCOS))
return(OSTimeGet());
#elif (defined(POLLOS))
#if (IS_386_PM)
// warning Phoney implementation of gettick to compile library in unspecified 386 environment
static dword tick = 0;
tick += 1;
#elif(MC68K)
// Return MARKMARK - This is phoney need a real clock ISR
dword tick = timer_tick++;
#else
dword tick;
// _bios_timeofday(_TIME_GETCLOCK, (long *)&tick);
#endif
return((dword)tick);
#else
#error - implement ks_get_ticks for your kernel
#endif
}
// ********************************************************************
// ks_ticks_p_sec(void) - ticks per second
//
// Returns number of ticks per second
//
word ks_ticks_p_sec(void)
{
return(18);
}
// ks_msec_p_tick() - milliseconds per tick
//
// Returns number of milliseconds per tick
//
word ks_msec_p_tick() /*__fn__*/
{
return(55);
}
// ********************************************************************
// ks_sleep() - sleep number of ticks
//
// Seeps number of ticks specified. If ticks is 0, task yields.
//
// Returns nothing
//
void ks_sleep(word no_ticks)
{
#if (defined(PLUS))
NU_Sleep(no_ticks);
#elif (defined(UCOS))
OSTimeDly(no_ticks);
#elif (defined(POLLOS))
int dummy = 0;
/* test a signal that will never be set */
pollos_test(&dummy, no_ticks);
#else
#error define ks_sleep for your kernel
#endif
}
SYSTEM_USER user_table[NUM_USERS];
void init_user_table(void)
{
tc_memset((PFBYTE)user_table, 0, sizeof(user_table));
}
PSYSTEM_USER get_system_user(void)
{
int i;
#if (defined(PLUS))
NU_TASK *t;
t = NU_Current_Task_Pointer();
#elif (defined(UCOS))
byte t;
t = OSTCBCur->OSTCBPrio;
#elif (defined(POLLOS))
int t;
t = 1;
#else
#error - Get current task id for you kernel and match against user table
#endif
for (i = 0; i < NUM_USERS; i++)
{
if (t == user_table[i].task_handle)
return(&user_table[i]);
}
/* Didn't find one.. so assign one from between 1 and n */
for (i = 1; i < NUM_USERS; i++)
{
if (!user_table[i].task_handle)
{
return_it:
tc_memset((PFBYTE)&user_table[i], 0, sizeof(user_table[i]));
user_table[i].task_handle = t;
return(&user_table[i]);
}
}
/* We are out of user structures so use element 0 */
i = 0;
goto return_it;
}
void pc_free_user(void) /*__fn__*/
{
int i;
PSYSTEM_USER s;
s = get_system_user();
if (s)
{
for (i = 0; i < NDRIVES; i++)
{
if (s->lcwd[i])
{
pc_freeobj((DROBJ *) s->lcwd[i]);
s->lcwd[i] = 0;
}
}
tc_memset((PFBYTE)s, 0, sizeof(*s));
}
}
/* pc_free_all_users() - Run down the user list releasing drive resources
*
* This routine is called by RTFS when it closes a drive.
* The routine must release the current directory object for that drive
* for each user. If a user does not have a CWD for the drive it should
* not call pc_freeobj.
*
* In the reference port we cycle through our array of user structures
* to provide the enumeration. Other implementations are equally valid.
*/
void pc_free_all_users(int driveno) /*__fn__*/
{
int i;
for (i = 0; i < NUM_USERS; i++)
{
#if (NUM_USERS == 1)
if (user_table[i].lcwd[driveno])
#else
if (user_table[i].task_handle && user_table[i].lcwd[driveno])
#endif
{
pc_freeobj((DROBJ *)user_table[i].lcwd[driveno]);
user_table[i].lcwd[driveno] = 0;
}
}
}
// int set_errno() - set errno for the calling task
//
// Saves errno for the calling task in array based on callers taskid.
//
// Returns -1
//
int set_errno(int error) /*__fn__*/
{
get_system_user()->rtfs_errno = error;
return(-1);
}
// ********************************************************************
// int get_errno() - get errno for the calling task
//
// Returns errno for the calling task in array based on callers taskid.
//
int get_errno(void) /*__fn__*/
{
return(get_system_user()->rtfs_errno);
}
/* Miscelaneous functions */
void pc_report_error(int error_number) /*__fn__*/
{
tm_printf_2("Error %d\n", error_number);
}
void ks_restore_vectors(void);
#if (defined(UCOS))
extern UWORD OldSP;
extern UWORD OldBP;
extern void /*interrupt*/ (*OldTickISR)(void);
#endif
void aos_exit(void)
{
// Only include interrupt code if we need it
tm_printf("Exitting and restoring interrupt vectors\n");
#if (USE_ATA)
ks_restore_vectors();
#endif
#if (defined(PLUS))
DOS_Exit(0);
#elif (defined(UCOS))
//setvect(0x08, OldTickISR);
//_BP = OldBP; /* Restore old SP and BP */
//_SP = OldSP;
//exit(0);
#elif (POLLOS)
//exit(0);
#else // no exit is provided; loop forever
#error implement aos_exit
#endif
}
/*
*****************************************************************************
PC_GETSYSDATE - Get the current system time and date (USER SUPPLIED)
Summary
#include <pcdisk.h>
DATESTR *pc_getsysdate(pd)
DATESTR *pd; put result here
Description
When the system needs to date stamp a file it will call this routine
to get the current time and date. YOU must modify the shipped routine
to support your hardware's time and date routines. If you don't modify
this routine the file date on all files will be the same.
The source for this routine is in file pc_udate.c and is self explanatory.
NOTE: Be sure to retain the property of returning its argument. The
package depends on it.
Returns
The argument it was passed. A structure containing date and time info.
Example:
#include <pcdisk.h>
DATESTR crdate;
Load the inode copy name,ext,attr,cluster, size,datetime
pc_init_inode( pobj->finode, filename, fileext,
attr, cluster, 0L ,pc_getsysdate(&crdate) );
*****************************************************************************
*/
#if (RTFS_WRITE)
/* get date and time from the host system */
DATESTR *pc_getsysdate(DATESTR *pd) /*__fn__*/
{
word year; /* relative to 1980 */
word month; /* 1 - 12 */
word day; /* 1 - 31 */
word hour;
word minute;
word sec; /* Note: seconds are 2 second/per. ie 3 == 6 seconds */
#if (0)
/* This code will work if yoiu have ANSI time functions. otherwise get
rid of it and look below where the time is wired to 3/28/8.
You may modify that code to work in your environment. */
struct tm *timeptr;
time_t timer;
time(&timer);
timeptr = localtime(&timer);
hour = (word) timeptr->tm_hour;
minute = (word) timeptr->tm_min;
sec = (word) (timeptr->tm_sec/2);
/* Date comes back relative to 1900 (eg 93). The pc wants it relative to
1980. so subtract 80 */
year = (word) (timeptr->tm_year-80);
month = (word) (timeptr->tm_mon+1);
day = (word) timeptr->tm_mday;
#else
/* This code is useless but very generic */
/* Hardwire for now */
/* 7:37:28 PM */
hour = 19;
minute = 37;
sec = 14;
/* 3-28-88 */
year = 8; /* relative to 1980 */
month = 3; /* 1 - 12 */
day = 28; /* 1 - 31 */
#endif
pd->time = (word) ( (hour << 11) | (minute << 5) | sec);
pd->date = (word) ( (year << 9) | (month << 5) | day);
return (pd);
}
#endif // RTFS_WRITE
int phys_to_virtual(PFBYTE * virt, unsigned long phys)
{
#if (FLAT_ADDRESSING)
*virt = (PFBYTE) phys;
#else
/* Straight real mode versions */
/* Take the address of a pointer, (virt) and a physical address
(0xd0000) and map in 64 k */
/* Real mode version */
phys = phys << 12; /* C0000 ==> C000 0000 */
*virt = (PFBYTE) phys;
#endif
return(1);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?