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

📄 os.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
字号:
/*****************************************************************************

* os.c - os extensions for running under WIN32

*

* portions Copyright (c) 2001 by Cognizant Pty Ltd.

*

* The authors hereby grant permission to use, copy, modify, distribute,

* and license this software and its documentation for any purpose, provided

* that existing copyright notices are retained in all copies and that this

* notice and the following disclaimer are included verbatim in any 

* distributions. No written agreement, license, or royalty fee is required

* for any of the authorized uses.

*

* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR

* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES

* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 

* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,

* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT

* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF

* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*

******************************************************************************

* REVISION HISTORY (please don't use tabs!)

*

*(yyyy-mm-dd)

* 2001-05-12 Robert Dickenson <odin@pnc.com.au>, Cognizant Pty Ltd.

*            Original file.

*

*****************************************************************************

*/

#include <stdio.h>



#include "os.h"

#include "nettimer.h"

#include "trace.h"

#include "devio.h"





char dbuffer[1024];

char *dbuf;



int asy_fd = 0;

int g_lastSem = NET_SEM_START;



unsigned long OSSemCreate( unsigned int value )
{

#ifndef SIM_ON_PC

	if (g_lastSem>= SMPH_NUM) return NULL;

	if (value == 1) 

		{

		g_sSmphcb[g_lastSem].ubSmphCnt = 1;

		g_sSmphcb[g_lastSem].ubSmphMax = 1;

		}

	else {

		g_sSmphcb[g_lastSem].ubSmphCnt = value;

		g_sSmphcb[g_lastSem].ubSmphMax = MAXSEM;

		}

	g_lastSem++;

    return g_lastSem-1;
#else
	
	if( ini_sem( g_lastSem, MAXSEM, (unsigned short)value ) != E_OK )
		return 0;

	g_lastSem++;
	return g_lastSem-1;
#endif

}

void OSSemFree( void )
{
	g_lastSem = NET_SEM_START;
}

void OSSemPend( unsigned long semid, unsigned int timeout, unsigned char* err)

{
	*err = twai_sem( semid, timeout*32 );
/*    //T_TSKCB*    pTskcb;                               已经修改

	if (!pevent) return ;

    if(pevent->ubSmphCnt == 0) 

    {

        if (timeout == TMO_POL)

        {

            return ;

        }



        // wait status



        g_pCurTsk->ubStatus |= TTS_WAI;  

        g_pCurTsk->ubWaitStat |= TTW_SEM;

        

        vfnDelAddMember((T_NODE*)pevent, (T_NODE*)g_pCurTsk);

        

        // set time out

        if(timeout != TMO_FEVR) {

        	timeout *= 32;

            g_pCurTsk->utime = g_sSysTime.utime;

            if (g_sSysTime.ltime > g_sSysTime.ltime + timeout)

                g_pCurTsk->utime +=  1;

            g_pCurTsk->ltime = g_sSysTime.ltime + timeout;

            vfnAddTimer((T_NODE*)&(g_pCurTsk->pNxtTmoTsk));

        }



        int_dispatch();         // dispatch & disable interrupt

        return;                 // return value is E_OK or E_RLWAI

        

    } else {

        pevent->ubSmphCnt--;

    }
*/

}



void OSSemPost( unsigned long semid )

{
	sig_sem( semid );

 /*   T_TSKCB*    pTskcb;

	if (!pevent) return ;

    if(pevent->pNxtTsk != (UW*)pevent) {      // exist semaphore wait task

        pTskcb = (T_TSKCB*)pevent->pNxtTsk;



        pTskcb->ubStatus &= ~TTS_WAI;

        pTskcb->ubWaitStat &= ~TTW_SEM;



        if(pTskcb->ubIntinfo == 0)          // interrupt information

        {

            ((T_SAVEDREG_MIN*)pTskcb->uwSP)->returnvalue = E_OK;

        }

            

        // clear time out task link

        vfnDelInitMember((T_NODE*)&(pTskcb->pNxtTmoTsk));



        vfnDelAddMember((T_NODE*)&g_sReadyQueue[pTskcb->bPriority], 

                       (T_NODE*)pTskcb);

        int_dispatch();         // dispatch & disable interrupt

    } 

    else 

    {

        pevent->ubSmphCnt++;

    }
*/
}





int asy_write(int fd, char *buf, int len)

{

	return nWrite(fd, buf, len);

}

/**********************************************************************************************/

int asy_readch(int fd, int timeout)

{

	char 	c;

	unsigned long clock;

	unsigned long tout;



	if (timeout <= 0) {

		while(1) {

			if (SysReadDev(fd, &c, 1,-1) ==1)

				return (unsigned char)c;

			}

		}

	else {

		clock = readclock();

		tout = timeout + clock;

		while(1) {

			clock = readclock();

			if (clock < tout) {

				if (SysReadDev(fd, &c, 1,-1) == 1) 

					return (unsigned char)c;

				}

			else return -1;

			}

		}

}

/******************************************************************************************************/

int OSTaskDel(int prio)

{

if (prio == -1) ext_tsk();

//del current task, it is at running state, impossable waiting for a semp

return 0;

}



/* 

 * Get the system task in ticks 

 */

unsigned long OSTimeGet()

{

	return readclock();

}





////////////////////////////////////////////////////////////////////////////////



void sleep(unsigned int ms)

{

	tslp_tsk(ms);

}



void delay(int ms)

{

	long timeout;

	long curtime;

	

	timeout = readclock() + ms/TICKSPERSEC;

	while (1) {

		curtime = readclock();

		if (curtime >= timeout) 

			break;

		}

}



void netpanic(char * msg)

{

    //printf(msg);

    //exit(1);

}





/*-------- time management --------*/

int clk_stat()

{

    return 0;

}



// Time diff in ms, between system time in ms and time in ms

long diffTime(unsigned long time)

{

	long sub;

	sub = (long)(time - mtime());

    return sub;

}



void msleep(unsigned long time)

{

	sleep(time+1);

}



// Get system time in ms

unsigned long mtime()

{

    unsigned long clock;

    clock = readclock();

    return (clock*MSPERTICK);

}



// Time diff in jiffys, between system time in jiffys and time in jiffys

// !!!NOTICE!!!

// If time is newer than system time this functions returns a value > 0

// If time is older than system time this functions returns a value < 0 (NEGATIVE VALUE)

long diffJTime(unsigned long time)

{

	unsigned long clock;

	clock = readclock();

    return (time - clock);

}



// Get system time in jiffys, which is a system clock tick 

unsigned long jiffyTime()

{

    return readclock();

}



int gettime(struct tm * time)   /* standard ANSI C */

{

    return 0;

}





⌨️ 快捷键说明

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