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

📄 linuxwrapper.h

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

typedef struct {
    clock_t   time;
    U32       location;
    char      file[INT_LOCK_FILE_LENGTH_MAX];
} IntLockVar_t;

extern IntLockVar_t IntLockInVar[];
extern IntLockVar_t IntLockOutVar[];
extern U32 IntLockPrint;

#endif

#ifdef MODULE

#define SPIN_LOCK_DEPTH_MAX 15

extern spinlock_t    SpinIntLock;
extern U32           SpinIntFlagsIndex;
extern unsigned long SpinIntFlagsTab[];

#ifdef DEBUG_LOCK

extern U32 IntLockInIndex;
extern U32 IntLockOutIndex;
extern int IntLockI, IntLockJ;
extern unsigned long SpinIntFlags;
extern pid_t SpinIntPid;
extern int IntLockPrintSignal;

#define interrupt_lock() \
    spin_lock_irqsave(&SpinIntLock, SpinIntFlags);\
    if (IntLockInIndex < (INT_LOCK_INDEX_MAX)) \
    { \
        IntLockInVar[IntLockInIndex].time = time_now(); \
        IntLockInVar[IntLockInIndex].location = __LINE__ ;\
        strcpy(IntLockInVar[IntLockInIndex].file, __FILE__);\
        IntLockInIndex++; \
        if (in_interrupt()) \
        {\
            /* We are in interrupt context. 'current' is not valid. Setting SpinIntPid to NULL */ \
        	SpinIntPid = 0; \
        }\
        else \
        { \
    	    SpinIntPid = current->pids->nr; \
    	}\
    } \
    else \
    { \
        /*printk("Max in index reached \n");  */       \
        IntLockPrint = 1; \
    }
#else
    #define interrupt_lock() spin_lock_irqsave(&SpinIntLock, SpinIntFlagsTab[SpinIntFlagsIndex++]);
/*    #define interrupt_lock() local_irq_disable()*/
#endif /* DEBUG_LOCK */

#ifdef DEBUG_LOCK
#define interrupt_unlock() \
    if (IntLockOutIndex < (INT_LOCK_INDEX_MAX)) \
    { \
        IntLockOutVar[IntLockOutIndex].time = time_now();\
        IntLockOutVar[IntLockOutIndex].location = __LINE__ ;\
        strcpy(IntLockOutVar[IntLockOutIndex].file, __FILE__);\
        IntLockOutIndex++;\
    }\
    else\
    {\
        /*printk("Max out index reached \n");  */\
        IntLockPrint = 1;\
    }\
    spin_unlock_irqrestore(&SpinIntLock, SpinIntFlags);\
    if ((IntLockPrint) && (!IntLockPrintSignal))\
    {\
        printk("Table ready\n");\
        IntLockPrintSignal=1;\
    }
#else
   #define interrupt_unlock()   spin_unlock_irqrestore(&SpinIntLock, SpinIntFlagsTab[--SpinIntFlagsIndex]);
   /*#define interrupt_unlock()   local_irq_enable()*/
#endif        

#else
    #define interrupt_lock() 
    #define interrupt_unlock() 
#endif /* MODULE */
   
/* Semaphores functions */
int semaphore_init_fifo(semaphore_t *sem, int count);
int semaphore_wait(semaphore_t *sem);
int semaphore_wait_timeout(semaphore_t *sem, clock_t *timeout);
int semaphore_signal(semaphore_t *sem);
int semaphore_delete (semaphore_t* Semaphore);
int semaphore_init_fifo_timeout(semaphore_t *sem, int count);

int           semaphore_init_priority(semaphore_t *sem, int count);
semaphore_t * semaphore_create_fifo(int count);
semaphore_t * semaphore_create_fifo_timeout(int count);
semaphore_t * semaphore_create_priority(int count);

/* LM: Requested by audio */
typedef semaphore_t mutex_t;
#define mutex_create_fifo() semaphore_create_fifo(1)
#define mutex_create_priority() semaphore_create_priority(1)
#define mutex_delete(mutex) semaphore_delete(mutex)
#define mutex_init_fifo(mutex) semaphore_init_fifo(mutex,1)
#define mutex_lock(mutex) semaphore_wait(mutex)
#define mutex_release(mutex) semaphore_signal(mutex)


/* Race condition functions */
#ifdef MODULE
/* Already defined in <linux/sched.h> */
#else
void task_lock(void);
void task_unlock(void);
#endif  /* !MODULE */


/* Time functions */
#ifdef MODULE
    /* Jiffies */
#define STLINUX_GetClocksPerSecond()      (HZ)
#else
    /* In user mode, it is up to us to define a base here. Let's set it to ms */
#define STLINUX_GetClocksPerSecond()      (1000)
#endif

#define MILLISECOND_TO_TICKS(v)          (((unsigned int) STLINUX_GetClocksPerSecond()*((unsigned int)(v)))/1000)
int task_delay(int ticks);

#if defined MODULE
int task_delay_until(clock_t timeout);
#endif


/* Context functions */
task_context_t task_context(task_t **task, int* level);


/* Messages functions */

void message_init_queue_timeout(message_queue_t* MessageQueue,
                                void* memory, size_t ElementSize,
                                unsigned int NoElements);
void message_init_queue(message_queue_t* MessageQueue,
                        void* memory, size_t ElementSize,
                        unsigned int NoElements);
message_queue_t * message_create_queue_timeout(size_t ElementSize, unsigned int NoElements);
void message_delete_queue(message_queue_t* MessageQueue);
int message_claim_timeout(message_queue_t *queue, clock_t * time_end_p);
int message_claim(message_queue_t * MessageQueue);
void message_release (message_queue_t* MessageQueue, void* Message);
int message_send(message_queue_t *queue, void *message);
void *message_receive (message_queue_t* MessageQueue);
void *message_receive_timeout (message_queue_t* MessageQueue, clock_t * ticks);

/* Clock functions */
clock_t      time_now (void);
clock_t      time_minus (clock_t Time1, clock_t Time2);
clock_t      time_plus (clock_t Time1, clock_t Time2);

#if defined(MODULE)
int          time_after_STAPI (clock_t Time1, clock_t Time2);

#else

struct timeval  Clockt2Timeval(clock_t clock);
clock_t         get_time_convert(struct timeval *tv);
clock_t		 get_time_now (void);
int          time_after (clock_t Time1, clock_t Time2);
void         task_delay_until (unsigned int ExitTime);
#endif


/* STSYS functions */

#ifdef MODULE

#define STSYS_ReadRegDev8(Address_p)  readb(Address_p)
#define STSYS_ReadRegMem8(Address_p)  readb(Address_p)
#define STSYS_ReadRegDev16LE(address) readw(address)
#define STSYS_ReadRegDev32LE(address) readl(address)
#define STSYS_ReadRegMem32LE(address) readl(address)

#define STSYS_WriteRegDev8(Address_p, value)  writel((u8)value, (void*)Address_p)
#define STSYS_WriteRegMem8(Address, value)    writel((u8)value, (u32)Address)
#define STSYS_WriteRegDev16LE(Address_p, value)   writel((u16)value, (void*)Address_p)
#define STSYS_WriteRegDev32LE(Address_p, value)  writel((u32)value, (void*)Address_p)
#define STSYS_WriteRegMem32LE(Address, value)   writel((u32)value, (u32)Address)

#define STSYS_SetRegMask32LE(address, mask) \
    STSYS_WriteRegDev32LE(address, STSYS_ReadRegDev32LE(address) | (mask) )

#define STSYS_ClearRegMask32LE(address, mask) \
    STSYS_WriteRegDev32LE(address, STSYS_ReadRegDev32LE(address) & ~(mask) )

/* the while(0) in the macro below must not be removed (even if apparently useless) */
/* this has been added for compilation aspect */
#define STSYS_memcpy_fromio(dest, source, num)    \
do {   \
    memcpy_fromio((dest), (u32)(source), (num));    \
    rmb();                               \
} while(0)

#define STSYS_ReadRegMemUncached8(Address_p)             STSYS_ReadRegDev8((void *)(((U32)(Address_p) & MASK_STBUS_FROM_ST40) | REGION2))
#define STSYS_WriteRegMemUncached8(Address_p, Value)     STSYS_WriteRegDev8((void *)(((U32)(Address_p) & MASK_STBUS_FROM_ST40) | REGION2), (Value))
#define STSYS_ReadRegMemUncached16LE(Address_p)          STSYS_ReadRegDev16LE((void *)(((U32)(Address_p) & MASK_STBUS_FROM_ST40) | REGION2))
#define STSYS_WriteRegMemUncached16LE(Address_p, Value)  STSYS_WriteRegDev16LE((void *)(((U32)(Address_p) & MASK_STBUS_FROM_ST40) | REGION2), (Value))
#define STSYS_ReadRegMemUncached16BE(Address_p)          STSYS_ReadRegDev16BE((void *)(((U32)(Address_p) & MASK_STBUS_FROM_ST40) | REGION2))
#define STSYS_WriteRegMemUncached16BE(Address_p, Value)  STSYS_WriteRegDev16BE((void *)(((U32)(Address_p) & MASK_STBUS_FROM_ST40) | REGION2), (Value))
#define STSYS_ReadRegMemUncached32LE(Address_p)          STSYS_ReadRegDev32LE((void *)(((U32)(Address_p) & MASK_STBUS_FROM_ST40) | REGION2))
#define STSYS_WriteRegMemUncached32LE(Address_p, Value)  STSYS_WriteRegDev32LE((void *)(((U32)(Address_p) & MASK_STBUS_FROM_ST40) | REGION2), (Value))
#define STSYS_ReadRegMemUncached32BE(Address_p)          STSYS_ReadRegDev32BE((void *)(((U32)(Address_p) & MASK_STBUS_FROM_ST40) | REGION2))
#define STSYS_WriteRegMemUncached32BE(Address_p, Value)  STSYS_WriteRegDev32BE((void *)(((U32)(Address_p) & MASK_STBUS_FROM_ST40) | REGION2), (Value))

#endif

/**********************************************************/
/*                  Kernel Functions                      */
/**********************************************************/
#ifdef MODULE
int STLINUX_sched_setscheduler(pid_t pid, int policy, const struct sched_param *p);
#endif

/**********************************************************/
/*                  STLINUX_task                          */
/**********************************************************/

#ifdef MODULE
ST_ErrorCode_t  STLINUX_TaskCreate (void (*Function)(void* Param),
                                    void* Param,
                                    struct semaphore * sem_p,
                                    int     Priority,
                                    BOOL    RealTime,
                                    const char* Name);
void STLINUX_TaskAskEnd (BOOL * EndFlag_p, semaphore_t * sem_p);
void STLINUX_TaskWaitEnd (struct semaphore * sem_p);
void STLINUX_TaskStartUp (char * const ThreadName);
void STLINUX_TaskEndUp (struct semaphore * sem_p);
#endif



/**********************************************************/
/*                 DEVICES REGISTRATION                   */
/**********************************************************/
#ifdef MODULE
int STLINUX_DeviceRegister(struct file_operations *stdevice_fops,
                         U32                     nbdevices,
                         char                   *DeviceName,
                         unsigned int           *DeviceMajor_p,
                         struct cdev            **stdevice_cdev,
                         struct class_simple    **stdevice_class);
int STLINUX_DeviceUnregister(U32                     nbdevices,
                           char                   *DeviceName,
                           unsigned int            DeviceMajor,
                           struct cdev            *stdevice_cdev,
                           struct class_simple    *stdevice_class);
#endif



/* *****************  Random procedure ***************** */
#ifdef MODULE
unsigned long rand(void);
#endif




/**********************************************************/
/*                   REGISTERS MAPPING                    */
/**********************************************************/
#ifdef MODULE
void * STLINUX_MapRegion(void * Address_p, U32 Width, char * RegionName);
void   STLINUX_UnmapRegion(void * MappedAddress_p, U32 Width);
#endif

#endif  /* __H_LINUXWRAPPER */


/* End of File */

⌨️ 快捷键说明

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