//ypublic.h
#ifndef __Y_PUBLIC__
#define __Y_PUBLIC__
#include <linux/ioport.h>
#include <linux/timer.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/cdev.h>
#include <linux/security.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <asm/io.h>
#include <asm/system.h>
#include <asm/uaccess.h>
#include <asm/delay.h>
#include <asm/io.h>
#include <asm/irq.h>
#define SETB(n) (1<<(n))
#define CLRB(n) (~ SETB(n))
#define SETN(v,n) (v<<n)
#define ARRAYSIZE(ar) (sizeof(ar)/sizeof(ar[0]))
//#define MS(n) (HZ*(n)/1000)
#define PI 3.1415927
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long
#define byte uchar
typedef unsigned int reg;
//io
#define Y2440_IO_IN 0
#define Y2440_IO_OUT 1
#define Y2440_IO_EINT 2
#define Y2440_IO_OUT_H 1
#define Y2440_IO_OUT_L 0
#define GPABASE 0x56000000 //0
#define GPBBASE 0x56000010 //1
#define GPCBASE 0x56000020 //2
#define GPDBASE 0x56000030 //3
#define GPEDASE 0x56000040 //4
#define GPFBASE 0x56000050 //5
#define GPGBASE 0x56000060 //6
#define GPHBASE 0x56000070 //7
#define WTBASE 0x53000000
#define CLOCKBASE 0x4C000000
#define SETNB(v,d,n,w) \
({\
unsigned long rs;\
unsigned int v1=v;\
unsigned int d1=d;\
unsigned int n1=n;\
unsigned int w1=w;\
rs=0xffffffff;\
rs=rs<<(32-n1-w1);\
rs=rs>>(32-w1);\
rs=~(rs<<n1);\
rs=d&rs|(v1<<n1);\
rs;\
})
#define ADCBASE 0x58000000
typedef struct _ADCREG{
reg ADCCON;
reg ADCTSC;
reg ADCDLY;
reg ADCDAT0;
reg ADCDAT1;
reg ADCUPDN;
}ADCREG,*PADCREG;
typedef struct _ADCREG t_adcregs;
typedef struct _ADCREG* t_adcregs_p;
typedef struct _GPREG{
reg GPCON;
reg GPDAT;
reg GPUP; //invalid for GPA
}GPREG,*PGPREG;
typedef struct _GPREG t_gpregs;
typedef struct _GPREG* t_gpregs_p;
typedef struct _t_clockreg{
reg LOCKTIME;
reg MPLLCON;
reg UPLLCON;
reg CLKCON;
reg CLKSLOW;
reg CLKDIVN;
reg CAMDIVN;
}t_clockreg,*t_clockreg_p;
#define Y_FIFO_SIZE 128
typedef struct _t_fifo{
uint data[Y_FIFO_SIZE];
uint *head;
uint *last;
uint size;
}t_fifo,*t_fifo_p;
typedef struct _t_wtreg{
reg WTCON;
reg WTDAT;
reg WTCNT;
}t_wtreg,*t_wtreg_p;
uint setNB(uint v,uint d,uint n,uint w)
{
uint rs;
rs=0xffffffff;
rs=rs<<(32-n-w);
rs=rs>>(32-w);
rs=~(rs<<n);
rs=(d&rs)|(v<<n);
return rs;
}
static void* yioremap(ulong start,ulong n,char name[])
{
if(request_mem_region(start,n,name)==NULL)return NULL;
return ioremap(start,n);
}
static void yiounmap(ulong start_ph,void* start_vir,ulong n)
{
iounmap(start_vir);
release_mem_region(start_ph,n);
}
static ulong fortimems(ulong ms)
{
return (jiffies+HZ*ms/1000);
}
#define GPREG_INIT(base) yioremap(base,sizeof(GPREG),"gpio")
#define MS(n) fortimems(n)
void fifo_init(t_fifo_p pobj)
{
pobj->last=pobj->head=pobj->data;
pobj->size=0;
}
bool fifo_push(t_fifo_p p,uint v)
{
uint *tmp=p->head;
if(tmp==p->data)tmp=p->data+Y_FIFO_SIZE-1;
else tmp--;
if(tmp==p->last)return false;//over buffer
*tmp=v;
p->head=tmp;
p->size++;
return true;
}
uint fifo_pop(t_fifo_p p)
{
uint *tmp=p->last;
if(tmp==p->head)return 0;
if(tmp==p->data)tmp=p->data+Y_FIFO_SIZE-1;
else tmp--;
p->last=tmp;
p->size--;
return *tmp;
}
void fifo_flush(t_fifo_p p,int n)
{
while(n--)
{
if(p->head==p->last)return;
else if(p->head==(p->data+Y_FIFO_SIZE-1))p->head=p->data;
else p->head++;
p->size--;
}
}
#endif //__Y_PUBLIC__
|