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

📄 portkern.c

📁 ertfs文件系统里面既有完整ucos程序
💻 C
📖 第 1 页 / 共 3 页
字号:
            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();

#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 || USE_FLOPPY || INCLUDE_PCMCIA)
    ks_restore_vectors();
#endif
#if (defined(PLUS))
    DOS_Exit(0);
#elif (defined(RTPX))
    os_exit();
#elif (defined(CMXRM))
    cmx_end();
#elif (defined(CMXD860))
    for(;;);
#elif (defined(UCOS))
   setvect(0x08, OldTickISR);
   _BP = OldBP;                                   /* Restore old SP and BP                    */
   _SP = OldSP;
   exit(0);
#elif (__PSOS__)
    while(1);   
#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)

#if (DOS)
#include <time.h>
#endif

/* 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


#if (USE_FLOPPY)
// ********************************************************************

/*
* Name:
*    os_floppy_type()                Return the hardware drive number
*
* Summary:
*    byte os_floppy_type(word driveno)
*
* Inputs:
*   None
*  
* Returns:
*   DT_NONE No drive 
*   DT_360  360 K 5.25" drive
*   DT_12   1.2 M 5.25" drive
*   DT_720  720 K 3.50" drive
*   DT_144  1.44M 3.50" drive
*   DT_288  2.88M 3.50" drive
*
*   Nothing
* 
* Description:
*   Returns the drive type at driveno.
*
*
* Porting considerations:
*   On the PC AT the drive types are stored in CMOS RAM. We return these
*   values. On a non AT platforms you need to find an alternate method.
*/

/* AT specific code. */
static byte read_cmos(word address)                  /* __fn__ */
{
    OUTBYTE(0x70,(word) (address | 0x80));
    return((byte)INBYTE(0x71));
}

byte os_floppy_type(int driveno)                             /*__fn__*/
{
byte utemp;
    /* Read the CMOS */
    utemp = read_cmos(0x90);
    if (driveno)
        return((byte)(utemp&0x0f));
    else
        return((byte) (utemp >> 4));
}

#endif      // USE_FLOPPY

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);
}

#if (SDS && MC68360)
/* SDS C IO functions to support the SDS io library's printf getc etc */
//#define SMC1TERM  1 - Do this
//#define SMC2TERM  0
//#define SMC1UART  0
//#define SMC2UART  0

void *const stderr = 0; /* Bogus file handles so it will link */
void *const stdin  = 0;
void *const stdout = 0;
int is_open = 0;
void    smc_term_open(void);    /* init data structures before using */
int     smc_term_send( void *buf, int length ); /* transmit a buffer if UART is available */
char    smc_term_getc(void); /* receive a character if one is available */

int fgetc(FILE *device)
{
char c;
    if (!is_open++)
        smc_term_open();   /* in ETH360.c */
    c = 0;
    do
    {
        c = smc_term_getc();
    } while (!c);
    return((int) c);
}

int gets(char *p)
{
char c;
    *p = 0;
    for (;;)
    {
        c = (char) fgetc(0);
        *p = 0;
        fputc((int) c, 0); // echo
        if (c == '\r' || c == '\n')
            return(1);
        *p++ = c;
    }
}


int fputc(int c, FILE *device)
{
int i;
char ch;
    ch = (char) c;
    if (!is_open++)
        smc_term_open();   /* in ETH360.c */
    if (c == '\n')
        fputc((int) '\r', 0);

    for (i = 0; i < 10000; i++)
        if (smc_term_send( &ch, 1) != -1)
            break; /* transmit a buffer if UART is available */
    return(c);
}

#endif



#if (CMXD860)

/*  Implementation module : chario.c

    Copyright 1998 Diab Data AB, Sweden

    Description :
    Dummy routines for character IO to be replaced by user.
    __inchar() returns a raw character 0-255.
        -1 if end-of file.
        -2 if no character available.
    __outchar(c) outputs a raw character 0-255.
    __inedit() returns an edited character:
        It waits until a character is available.
        It returns EOF (-1) after carrige return to force
        read() to return.
        It converts '\r' to '\n'.
        It outputs character read through __outedit(c)
    __outedit(c) outputs an edited character 0-255.
        It converts NL (10) to CR-LF (13-10)

*/
int is_open = 0;
int __inchar()
{
char c;
    if (!is_open++)
        smc_term_open();   /* in ETH860.c */
    c = smc_term_getc();   /* receive a character if one is available */
    if (!c)
        return(-2);
    return((int) c);
}

int __outchar(int c, int last)
{
int i;
char ch;

    if (!is_open++)
        smc_term_open();   /* in ETH860.c */
    ch = (char) c;
    for (i = 0; i < 10000; i++)
        if (smc_term_send( &ch, 1) == 0)
            break; /* transmit a buffer if UART is available */
}

/* Read a character from port. Echoes the character.        */
/* Waits until character is available               */
/* CR (13) is converted to NL (10)              */
/* Returns EOF after each CR to interupt read           */

int __inedit()
{
    int c;
    static int last_was_cr;
    
    if (!is_open++)
        smc_term_open();   /* in ETH860.c */
    /* give EOF to force 'read' to return after <CR>    */
    if (last_was_cr) {
        last_was_cr = 0;
        return -1;
    }
    
    /* read character from port, return character (0-255)   */
    /* return -1 when end of file reached */

    while((c = __inchar()) == -2) ;
    
    /* if <CR> return '\n' + give end of file next time */
    if (c == '\r' || c == '\n') {
        c = '\n';
        last_was_cr = 1;
    }

    /* echo character to out port   */
#ifndef DONT_ECHO
    if (c >= 0) __outedit(c, 1);
#endif

    return c;
}


/* Write a character to a port. Converts NL to CR-LF    */

int __outedit(int c, int last)
{
    /* write character to port  */

    /* special handling of \n: echo CR-LF   */
    if (c == '\n') __outchar('\r',0);

    /* write actual character */
    __outchar(c,last);
#ifdef DS90_TEST
    {
        char cc = c;
        os_write(1,&cc,1);
    }
#endif
    
    return 0;
}

#endif



⌨️ 快捷键说明

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