📄 smsc_environment.c
字号:
/*
* 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.c
*/
#include "smsc_environment.h"
/* Debug bits */
#define DEBUG_TRACE_BIT (0x10)
#define DEBUG_NOTICE_BIT (0x20)
#define DEBUG_WARNING_BIT (0x40)
#ifndef SMSC_TRACE_ENABLED
#define SMSC_TRACE_ENABLED (1)
#endif
#ifndef SMSC_NOTICE_ENABLED
#define SMSC_NOTICE_ENABLED (1)
#endif
#ifndef SMSC_WARNING_ENABLED
#define SMSC_WARNING_ENABLED (1)
#endif
#ifndef SMSC_ERROR_ENABLED
#define SMSC_ERROR_ENABLED (1)
#endif
/* Debug Utilities */
/* SMSC_TRACE is used for informational purposes only,
it may be useful during debugging but is usually too
noisy to keep it enabled all the time.
'condition' is usually filled in with an individual module
debug enable switch, but it could also be used to specify a runtime
condition that activates the message. */
#if (SMSC_TRACE_ENABLED)
#define SMSC_TRACE(condition,message) \
do { \
if((condition)&(1|DEBUG_TRACE_BIT)) { \
SMSC_PLATFORM_MESSAGE((" TRACE: ")); \
SMSC_PLATFORM_MESSAGE(message); \
SMSC_PLATFORM_MESSAGE(("\n")); \
} \
} while(0)
#define SMSC_PRINT(condition,message) \
do { \
if((condition)&(1|DEBUG_TRACE_BIT)) { \
SMSC_PLATFORM_MESSAGE(message); \
} \
} while(0)
#else
#define SMSC_TRACE(condition,message)
#define SMSC_PRINT(condition,message)
#endif
/* SMSC_NOTICE is intended to be used only when an error is detected
and fully handled and recoverable. (example is dropping packets)
'condition' is usually filled in with an individual module
debug enable switch, but it could also be used to specify a runtime
condition that activates the message. */
#if (SMSC_NOTICE_ENABLED)
#define SMSC_NOTICE(condition,message) \
do { \
if((condition)&(1|DEBUG_NOTICE_BIT)) { \
SMSC_PLATFORM_MESSAGE((" NOTICE: ")); \
SMSC_PLATFORM_MESSAGE(message); \
SMSC_PLATFORM_MESSAGE(("\n")); \
} \
} while(0)
#else
#define SMSC_NOTICE(condition,message)
#endif
/* SMSC_WARNING is intended to be used only when an error is detected
and but may not be handled or recoverable. (example is how to handle unknown codes)
'condition' is usually filled in with an individual module
debug enable switch, but it could also be used to specify a runtime
condition that activates the message. */
#if (SMSC_WARNING_ENABLED)
#define SMSC_WARNING(condition,message) \
do { \
if((condition)&(1|DEBUG_WARNING_BIT)) { \
SMSC_PLATFORM_MESSAGE(("WARNING: ")); \
SMSC_PLATFORM_MESSAGE(message); \
SMSC_PLATFORM_MESSAGE(("\n")); \
} \
} while(0)
#else
#define SMSC_WARNING(condition,message)
#endif
/* SMSC_ERROR is to be used only when a fatal unrecoverable error has
accured. It contains a halt command to prevent further corruption.
SMSC_ASSERT is similar to SMSC_ERROR in that both can be used to notify
of a fatal error. SMSC_ASSERT allow the user to provide a condition
which if false will trigger the error. If the error is triggered an
halt command will prevent further execution.
Neither SMSC_ERROR or SMSC_ASSERT can be enabled on a per module based.
If they are enabled they are enabled for all modules.
*/
#if (SMSC_ERROR_ENABLED)
#define SMSC_ERROR(message) \
do { \
SMSC_PLATFORM_MESSAGE(("!ERROR!: ")); \
SMSC_PLATFORM_MESSAGE(message); \
SMSC_PLATFORM_HALT_MESSAGE( \
("\n!ERROR!: file=%s, line=%d\n", \
__FILE__,__LINE__)); \
} while(0)
#define SMSC_ASSERT(condition) \
do { \
if(!(condition)) { \
SMSC_PLATFORM_HALT_MESSAGE( \
("ASSERTION FAILURE: file=%s, line=%d\n", \
__FILE__, __LINE__)); \
} \
} while(0)
/*
* The following macros help by verifying you have a valid structure pointer
* This is especially useful when void pointers are used to pass structures
* around. These macros can be used to make sure a structure has been
* initialized and make sure it is the correct structure.
*/
#define DECLARE_SIGNATURE u32_t mSignature;
#define ASSIGN_SIGNATURE(structure_pointer,signature) \
do { \
(structure_pointer)->mSignature=((u32_t)signature); \
}while(0)
#define CHECK_SIGNATURE(structure_pointer,signature) \
do { \
if((structure_pointer)->mSignature!=((u32_t)signature)) { \
SMSC_PLATFORM_HALT_MESSAGE( \
("SIGNATURE_FAILURE: file=%s, line=%d\n", \
__FILE__, __LINE__)); \
} \
} while(0)
#define CLEAR_SIGNATURE(structure_pointer) \
do { \
(structure_pointer)->mSignature=(u32_t)0); \
} while(0)
#else /* SMSC_ERROR_ENABLED */
#define SMSC_ERROR(message)
#define SMSC_ASSERT(condition)
#define DECLARE_SIGNATURE
#define ASSIGN_SIGNATURE(structure_pointer,signature)
#define CHECK_SIGNATURE(structure_pointer,signature)
#define CLEAR_SIGNATURE(structure_pointer)
#endif /* SMSC_ERROR_ENABLED */
void smsc_initialize(void)
{
/* platform specific initialization if any*/
}
void smsc_disable_interrupts(void)
{
SMSC_ERROR(("smsc_disable_interrupts are not implemented"));
}
void smsc_enable_interrupts(void)
{
SMSC_ERROR(("smsc_enable_interrupts are not implemented"));
}
/* linux optimised checksum routine. void * is always 32-bit aligned on this platform. */
u16_t smsc_chksum_linux(void *dataptr, int len)
{
u16_t *ps = dataptr;
u32_t sum = 0;
/* Add the bulk of the data */
while(len>31) { /* This loop can be further optimized for the platform */
sum += *ps++;
sum += *ps++;
sum += *ps++;
sum += *ps++;
sum += *ps++;
sum += *ps++;
sum += *ps++;
sum += *ps++;
sum += *ps++;
sum += *ps++;
sum += *ps++;
sum += *ps++;
sum += *ps++;
sum += *ps++;
sum += *ps++;
sum += *ps++;
len-=32;
}
while (len > 1) {
sum += *ps++;
len -= 2;
}
/* Consume left-over byte, if any */
if (len > 0)
{
u16_t t = 0;
((u8_t *)&t)[0] = *(u8_t *)ps;
sum += t;
}
/* Fold 32-bit sum to 16 bits */
while (sum >> 16)
{
sum = (sum & 0xffff) + (sum >> 16);
}
/*SMSC_TRACE(IPV4_DEBUG, ("smsc_chksum_linux(): 0x%4x", (u16_t)sum));*/
return (u16_t)sum;
}
/* Time related functions */
#define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
/* Returns the current time in jiffies */
smsc_clock_t linux_time_now()
{
struct timeval tv;
u32_t sec = tv.tv_sec;
u32_t usec = tv.tv_usec;
gettimeofday(&tv,NULL);
if (sec >= (MAX_JIFFY_OFFSET / HZ))
return MAX_JIFFY_OFFSET;
usec += 1000000L / HZ - 1;
usec /= 1000000L / HZ;
return HZ * sec + usec;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -