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

📄 linuxwrapper.h

📁 stos Linux 源码示范程序。 可以移植到其他平台
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef __H_LINUXWRAPPER
#define __H_LINUXWRAPPER

#ifdef MODULE
#include <linux/config.h>

/* next line to check */
#include <linux/module.h>
#include <linux/kernel.h> /* Needed for KERN_ALERT */
#include <linux/init.h>   /* Needed for the macros */
/* end to check */

#include <linux/types.h>
#include <linux/fs.h>
#include <linux/mm.h>    /* for verify_area */
#include <linux/errno.h> /* for -EBUSY */

#include <asm/io.h>       /* for ioremap */
#include <asm/atomic.h>
#include <linux/ioport.h> /* for ..._mem_region */

#include <linux/spinlock.h>

#include <linux/time.h>
#include <linux/delay.h>

#include <asm/irq.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/interrupt.h>

#include <linux/wait.h>
#include <linux/poll.h>

#include <linux/slab.h>
#include <linux/vmalloc.h>

#include <linux/netdevice.h>    /* ??? SET_MODULE_OWNER ??? */
#include <linux/cdev.h>         /* cdev_alloc */

#include <asm/param.h>
#include <asm/current.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>

#include "stcommon.h"

#else   /* MODULE */

#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <sys/poll.h>
#include <stdarg.h>
#include <errno.h>

#include <stdio.h>
#include <unistd.h>

#endif  /* MODULE */

#include <linux/version.h>

#include "stddefs.h"
#include "stcommon.h"
#include "linuxcommon.h"

/* This is *only* okay because we never de-reference it. It'll need to
 * be fixed if we ever do.
 */
#define TIMEOUT_INFINITY    ((void *)NULL)
#define TIMEOUT_IMMEDIATE   ((clock_t *)-1)

/* To be adjusted */
#define MAX_USER_PRIORITY    99
#define MIN_USER_PRIORITY    0

/* Avoiding debug.h... */
#define DEBUG_NOT_CONNECTED 0

/* defining debug functions */
#define debugopen(x,y)				(long int)fileno(fopen(x,y))
#define debugread(x,y,z)			read((int)x,y,z)
#define debugwrite(x,y,z)			write((int)x,y,z)
#define debugclose(x)				close((int)x)

/* Parhaps this should go in a separate debug header file. */
#ifdef MODULE
#ifdef STAPI_ASSERT_DISABLED
#define assert(expr)
#else
#define assert(expr) \
        if(unlikely(!(expr))) {                                   \
        printk(KERN_ERR "Assertion failed! %s,%s,%s,line=%d\n", \
        #expr,__FILE__,__FUNCTION__,__LINE__);          \
        }
#endif
#endif

/* For register access */
#define REGION2 					0xa0000000
#define REGION4 					0xe0000000
#define MASK_STBUS_FROM_ST40		0x1fffffff

/* Linux specific directories */
#define STAPI_DEVICE_DIRECTORY              "/dev/stapi/"       /* Devices directory */
#define STAPI_STAT_DIRECTORY                "STAPI"             /* Statistics directory (root is /proc directory) */

/* Setting Linux paging values*/
#define LINUX_PAGE_SIZE         0x1000
#define LINUX_PAGE_ALIGNMENT    0x1000


/* ***************** */
/* partial limits.h  */
/* ***************** */

#define CHAR_BIT 8
#define SCHAR_MAX 127
#define UCHAR_MAX 255

#ifdef __SIGNED_CHAR__
#define CHAR_MIN (-128)
#define CHAR_MAX 127
#else
#define CHAR_MIN 0
#define CHAR_MAX 255
#endif

#define MB_LEN_MAX 1

#define SHRT_MIN  (~0x7fff)
#define SHRT_MAX  0x7fff
#define USHRT_MAX 65535U




/* *************** */
/* Partial sttbx.h */
/* *************** */
#ifndef STTBX_INPUT
#define STTBX_INPUT
#endif

#define STTBX_Report(x)     STTBX_Report_arg x
#ifdef MODULE
#ifdef STTBX_PRINT
#define STTBX_Print(x)		printk x
#else
#define STTBX_Print(x)      { }
#endif
#define STTBX_REPORT_NL		printk("\n");

#else   /* MODULE */

#ifdef STTBX_PRINT
#define STTBX_Print(x)		printf x
#else
#define STTBX_Print(x)      { }
#endif
#define STTBX_REPORT_NL		printf("\n");

#endif  /* MODULE */



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



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

/* Defines the levels of the report (type of message) */
typedef enum STTBX_ReportLevel_e
{                                   /* Use the given level to indicate: */
    STTBX_REPORT_LEVEL_FATAL = 0,   /* Imminent non recoverable system failure */
    STTBX_REPORT_LEVEL_ERROR,       /* Serious error, though recoverable */
    STTBX_REPORT_LEVEL_WARNING,     /* Warnings of unusual occurences */
    STTBX_REPORT_LEVEL_ENTER_LEAVE_FN, /* Entrance or exit of a function, and parameter display */
    STTBX_REPORT_LEVEL_INFO,        /* Status and other information - normal though */
    STTBX_REPORT_LEVEL_USER1,       /* User specific */
    STTBX_REPORT_LEVEL_USER2,       /* User specific */

    /* Keep as last one (Internal use only) */
    STTBX_NB_OF_REPORT_LEVEL        /* Last element has a value corresponding to the number of elements by default ! */
} STTBX_ReportLevel_t;

void STTBX_Report_arg(const STTBX_ReportLevel_t ReportLevel, const char *const Format_p, ...);

#ifndef STTBX_REPORT_LEVEL_MAX
#define STTBX_REPORT_LEVEL_MAX      STTBX_REPORT_LEVEL_ENTER_LEAVE_FN
#endif


/* *************** */
#ifndef PARTITION_T
#define PARTITION_T
typedef int partition_t;
#endif

#ifndef ST_PARTITION_T
#define ST_PARTITION_T
typedef int ST_Partition_t;
#endif

#ifdef MODULE
#define memory_allocate(partition, amount)      vmalloc(amount)
#define memory_deallocate(partition, ptr)       vfree(ptr)
void *  memory_reallocate (partition_t* Partition, void* Block, size_t Requested, size_t OldSize);
void*   memory_allocate_clear(partition_t* Partition, size_t nelem, size_t elsize);
#else   /* MODULE */

#define memory_allocate(partition, amount)      malloc(amount)
#define memory_deallocate(partition, ptr)       free(ptr)
#define memory_reallocate(partition, ptr, size) realloc(ptr, size)
#endif  /* MODULE */

typedef BOOL boolean;
#define false	FALSE
#define true	TRUE

typedef clock_t osclock_t;

#ifdef MODULE

typedef struct semaphore_s
{
    wait_queue_head_t   wait_queue;
    atomic_t            Count;
} semaphore_t;


#define OS21_SUCCESS     0
#define OS21_FAILURE    -1
#else   /* MODULE */

typedef pthread_mutex_t semaphore_t;
typedef pthread_t   task_t;

#endif  /* MODULE */

#define MESSAGE_MEMSIZE_QUEUE(size,nb) ((nb)*(size))

typedef struct
{
    semaphore_t	  * MsgSemaphore_p;
    semaphore_t	  * ClaimSemaphore_p;
    int				Index;
} message_queue_t;


typedef int tdesc_t;            /* Unused */
typedef int task_flags_t;       /* Unused */
typedef int task_context_t;
#define task_context_task       0
#define task_context_interrupt  1


/* Input functions */
void STTBX_InputChar(char * result);
BOOL STTBX_InputPollChar(char* buffer);
int STTBX_InputStr( char* answer, int size );



#ifdef MODULE
static DECLARE_MUTEX_LOCKED(thread_trick_sem);
static DECLARE_MUTEX_LOCKED(thread_inj_sem);
static DECLARE_MUTEX_LOCKED(thread_vin_sem);
#endif

#ifdef DEBUG_LOCK

/* interrupt_lock / interrupt_unlock */
#define INT_LOCK_INDEX_MAX          (1024)
#define INT_LOCK_FILE_LENGTH_MAX    (80)

⌨️ 快捷键说明

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