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

📄 smsc_environment.h

📁 由smsc公司改进的lwip2.1.1基于嵌入式系统的TCP/ip协议栈
💻 H
字号:
/*
 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
 * All rights reserved. 
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
 *
 * This file is part of the lwIP TCP/IP stack.
 * 
 * Author: Adam Dunkels <adam@sics.se>
 *
 */
/*****************************************************************************
* Modifications of this software Copyright(C) 2008, Standard Microsystems Corporation
*   All Rights Reserved.
*   The modifications to this program code are proprietary to SMSC and may not be copied,
*   distributed, or used without a license to do so.  Such license may have
*   Limited or Restricted Rights. Please refer to the license for further
*   clarification.
******************************************************************************
* FILE: smsc_environment.h
* PURPOSE: 
*    This file declares the functions/macros that are used to create an
*    environment wrapper to shield the network stack from the specifices of
*    the platform, and OS. 
* This file is included by
*    Network_Stack/Source/utilities/smsc_system.h
* See smsc_system.h for descriptions on how to implement required features.
*****************************************************************************/

#ifndef SMSC_ENVIRONMENT_H
#define SMSC_ENVIRONMENT_H

#include "custom_options.h"

/*****************************************************************************
* This file should include any header files that are necessary to make
* the platform specific environment complete.
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#ifndef LINUX_LOOPBACK_DEMO
#include <ostime.h>
#include <interrup.h>
#include <semaphor.h>
#include <message.h>
#include <task.h>
#include <mutex.h>
#endif /* !LINUX_LOOPBACK_DEMO */
#include <time.h>
#ifdef LINUX_LOOPBACK_DEMO
#include <asm/param.h>
#include <time.h>
#include <pthread.h>
#endif /* LINUX_LOOPBACK_DEMO */

/*****************************************************************************
* The following types are used in the SMSC Network stack
* u8_t is an unsigned 8 bit integer
* s8_t is a signed 8 bit integer
* u16_t is an unsigned 16 bit integer
* s16_t is a signed 16 bit integer
* u32_t is an unsigned 32 bit integer
* s32_t is a signed 32 bit integer
* mem_ptr_t is an unsigned integer who bit width is the same as a pointer (void *)
* NOTE:
*   mem_size_t is not currently used and may be deprecated in the future.
*****************************************************************************/
typedef unsigned   char    u8_t;
typedef signed     char    s8_t;
typedef unsigned   short   u16_t;
typedef signed     short   s16_t;
typedef unsigned   long    u32_t;
typedef signed     long    s32_t;

typedef u32_t mem_ptr_t;
typedef u16_t mem_size_t;

/*****************************************************************************
* The following are format strings which are associated with specific types
* U16_F is a format string that specifies a 16 bit unsigned integer
* S16_F is a format string that specifies a 16 bit signed integer
* X16_F is a format string that specifies a 16 bit integer in hexidecimal form
* U32_F is a format string that specifies a 32 bit unsigned integer
* S32_F is a format string that specifies a 32 bit signed integer
* X32_F is a format string that specifies a 32 bit integer in hexidecimal form* 
*****************************************************************************/
#define U16_F "hu"
#define S16_F "hd"
#define X16_F "hX"
#define U32_F "lu"
#define S32_F "ld"
#define X32_F "lX"

/*****************************************************************************
* ENDIAN_SETTING should be set to BIG_ENDIAN if the platform is big endian
*    should be set to LITTLE_ENDIAN if the platform is little endian.
*****************************************************************************/
#define ENDIAN_SETTING	LITTLE_ENDIAN

/*****************************************************************************
* MACRO: SMSC_PLATFORM_MESSAGE
* DESCRIPTION:
*    prints a message to a diagnostic output console.
* PARAMETERS:
*    message, this takes the form of standard printf parameters
*        example is 
*            ("I am %d old",myAge)
* RETURN VALUE
*     None.
*****************************************************************************/
#define SMSC_PLATFORM_MESSAGE(message)	do {printf message;} while(0)

/*****************************************************************************
* MACRO: SMSC_PLATFORM_HALT_MESSAGE
* DESCRIPTION:
*     This behaves the same as SMSC_PLATFORM_MESSAGE except that after
*     printing the message the system halts and does not continue program
*     execution. This macro should never return.
* PARAMETERS:
*    message, this takes the form of standard printf parameters
*        example is 
*            ("I am %d old",myAge)
* RETURN VALUE
*     This macro should never return.
*****************************************************************************/
#define SMSC_PLATFORM_HALT_MESSAGE(message)	do {printf message;fflush(NULL);abort();} while(0)

/*****************************************************************************
* TYPE: smsc_clock_t
* DESCRIPTION:
*    This type is used for storing time values that can used in
*    smsc_time_now, smsc_time_plus, smsc_time_minus, smsc_time_after,
*    smsc_tick_to_sec, smsc_sec_to_tick
*    smsc_tick_to_msec, smsc_msec_to_tick
*    smsc_tick_to_usec, smsc_usec_to_tick
*****************************************************************************/
typedef unsigned long smsc_clock_t;

/*****************************************************************************
* FUNCTION: smsc_time_now
* RETURN VALUE:
*     returns a smsc_clock_t that represents the present time.
*****************************************************************************/
#define smsc_time_now() 		((smsc_clock_t)linux_time_now())

/*****************************************************************************
* FUNCTION: smsc_time_plus
* DESCRIPTION:
*    Adds two time values and returns the result. The caller
*    ensures that one of the times is a time offset or a relative time value.
*    It is not legal to add two absolute time values since the origin is not
*    defined by this specification. So this function can be used to add an 
*    absolute time to a relative time, or it can be used to add a relative 
*    time to a relative time.
* PARAMETERS:
*    smsc_clock_t t1, represents one of the time values to add.
*    smsc_clock_t t2, represents one of the time values to add.
* RETURN VALUE:
*    returns a smsc_clock_t that represents the sum of the two time values.
*****************************************************************************/
#define linux_time_plus(t1,t2)  ((t2) + (t1))
#define smsc_time_plus(t1,t2)	((smsc_clock_t)linux_time_plus((smsc_clock_t)(t1),(smsc_clock_t)(t2)))

/*****************************************************************************
* FUNCTION: smsc_time_minus
* DESCRIPTION:
*    Subtracts one time value from another time value. This is usually used
*    to figure a relative time value from two absolute time values.
* PARAMETERS:
*    smsc_clock_t t1, represents t1 of (t1-t2)
*    smsc_clock_t t2, represents t2 of (t1-t2)
* RETURN VALUE:
*    returns a smsc_clock_t that represents (t1-t2). Or in other words it
*       returns a relative time whose origin is t2.
*****************************************************************************/
#define linux_time_minus(t1,t2) ((t1) - (t2))
#define smsc_time_minus(t1,t2)	((smsc_clock_t)linux_time_minus((smsc_clock_t)(t1),(smsc_clock_t)(t2)))

/*****************************************************************************
* FUNCTION: smsc_time_after
* DESCRIPTION:
*    Determine the relative time order between two time values. The two time
*    values can be assumed to be based around the same origin.
* PARAMETERS:
*    smsc_clock_t t1, represents a time value
*    smsc_clock_t t2, represents a time value
* RETURN VALUE:
*    returns 1 if t1 is after t2.
*    returns 0 if t1 is before or equal to t2
*****************************************************************************/
#define linux_time_after(t1,t2) ((long)(t2) - (long)(t1) < 0)
#define smsc_time_after(t1,t2)	((smsc_clock_t)linux_time_after((smsc_clock_t)(t1),(smsc_clock_t)(t2)))

/*****************************************************************************
* The following functions/macros are used to translate the units of 
* smsc_clock_t into or from the units of seconds, milliseconds, and microseconds
* 
* smsc_tick_to_sec, translates a smsc_clock_t into the number of seconds.
* smsc_sec_to_tick, translates a number of seconds into a smsc_clock_t
* smsc_tick_to_msec, translates a smsc_clock_t into the number of milliseconds.
* smsc_msec_to_tick, translates a number of milliseconds into a smsc_clock_t
* smsc_tick_to_usec, translates a smsc_clock_t into the number of microseconds.
* smsc_usec_to_tick, translates a number of microseconds into a smsc_clock_t
*****************************************************************************/
#define smsc_tick_to_sec(tick)  ((u32_t)((((u32_t)(tick))) / ((u32_t)HZ)))
#define smsc_sec_to_tick(sec)   ((smsc_clock_t)((sec) * HZ))
#define smsc_tick_to_msec(tick) ((u32_t)((((u32_t)(tick)) * ((u32_t)1000)) / ((u32_t)HZ)))
#define smsc_msec_to_tick(msec) ((smsc_clock_t)((msec) * HZ / 1000))
#define smsc_tick_to_usec(tick) ((u32_t)((tick) * 1000000 / HZ))
#define smsc_usec_to_tick(usec) ((smsc_clock_t)((usec) * HZ / 1000000))

/*****************************************************************************
* The following delay macros are used to wait a specified time period.
* It is not required that they release the CPU to other threads. They may 
* just spin until the specified time has expired. However they may be
* implemented to release the CPU to other threads if that seems useful.
*
* smsc_mdelay, waits a specified number of milliseconds
* smsc_udelay, waits a specified number of microseconds
*****************************************************************************/
#define smsc_mdelay(msec)	usleep(msec * 1000)
#define smsc_udelay(usec)	usleep(usec)

/*****************************************************************************
* The following functions are used for interrupt synchronization function
*
* smsc_disable_interrupts requires that all interrupts are disabled
* smsc_enable interrupts requires that all interrupts are enabled
*****************************************************************************/
void smsc_disable_interrupts(void);
void smsc_enable_interrupts(void);

/*****************************************************************************
* FUNCTION: smsc_initialize
* DESCRIPTION:
*    This is the first function to be called in the entire SMSC Network Stack.
*    It is required to handle any platform specified initialization that is
*    necessary to make sure all the other functions work properly.
*****************************************************************************/
void smsc_initialize(void);
int st_c1_Init(void);


/*****************************************************************************
* FUNCTION: SMSC_IPCHECKSUM
* DESCRIPTION:
*    This function handles data checksuming according to the IP specification.
* PARAMETERS:
*    void * dataptr, this is a pointer to the buffer that should be checksummed
*    int len, this is the length of the buffer that should be checksummed
* RETURN VALUE:
*    Returns the IP check sum as a u16_t
*****************************************************************************/
#define SMSC_IPCHECKSUM smsc_chksum_linux
u16_t smsc_chksum_linux(void *dataptr, int len);

#endif /* ENVIRONMENT_H */

⌨️ 快捷键说明

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