打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
LINUX2.6.26.6内核下双口RAM的驱动函数测试成功!

驱动程序: 

#include <linux/fs.h>
//#include <linux/iobuf.h>
#include <linux/major.h>
#include <linux/blkdev.h>
#include <linux/capability.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>
#include <asm/hardware.h>
//#include <asm/arch/AT91RM9200.h>
#include <asm/arch/at91rm9200.h>
//#include <asm/arch/lib_AT91RM9200.h>
#include <linux/vmalloc.h>
#include <linux/delay.h>

#include <linux/kernel.h>
#include <linux/init.h>
//#include <linux/config.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/ioport.h>
#include <linux/sched.h>
#include <asm/io.h>
#include <asm/arch/gpio.h>
#include <linux/delay.h>

MODULE_LICENSE("GPL");

#define IOPORT_MAJOR 221 //定义主设备号
#define IOWRITE         1
#define IOREAD          2
#define DRAM_LEN        0X2000 //8k WORD
#define DA_BASE  0X30000000


typedef char ioport_device_t;
static ioport_device_t dram_devices[257];

unsigned short sincode60[]={2048,2064,2081,2097,2114,2131,2147,2164,2180,2197,
2214,2230,2247,2263,2280,2296,2313,2329,2345,2362,
2378,2394,2411,2427,2443,2459,2475,2491,2507,2523,
2539,2555,2571,2587,2602,2618,2633,2649,2664,2680,
2695,2711,2726,2741,2756,2771,2786,2801,2815,2830,
2845,2859,2874,2888,2902,2917,2931,2945,2959,2973,
2986,3000,3014,3027,3040,3054,3067,3080,3093,3106,
3118,3131,3144,3156,3168,3180,3192,3204,3216,3228,
3240,3251,3262,3274,3285,3296,3307,3317,3328,3338,
3349,3359,3369,3379,3389,3399,3408,3417,3427,3436,
3445,3454,3462,3471,3479,3488,3496,3504,3512,3519,
3527,3534,3541,3549,3555,3562,3569,3575,3582,3588,
3594,3600,3605,3611,3616,3621,3627,3631,3636,3641,
3645,3649,3654,3657,3661,3665,3668,3672,3675,3678,
3680,3683,3686,3688,3690,3692,3694,3695,3697,3698,
3699,3700,3701,3702,3702,3702,3702,3702,3702,3702,
3701,3701,3700,3699,3697,3696,3695,3693,3691,3689,
3687,3684,3682,3679,3676,3673,3670,3667,3663,3659,
3656,3652,3647,3643,3639,3634,3629,3624,3619,3614,
3608,3603,3597,3591,3585,3579,3572,3566,3559,3552,
3545,3538,3531,3523,3515,3508,3500,3492,3484,3475,
3467,3458,3449,3440,3431,3422,3413,3403,3394,3384,
3374,3364,3354,3344,3333,3323,3312,3301,3290,3279,
3268,3257,3245,3234,3222,3210,3198,3186,3174,3162,
3150,3137,3125,3112,3099,3086,3073,3060,3047,3034,
3020,3007,2993,2979,2966,2952,2938,2924,2910,2895,
2881,2867,2852,2838,2823,2808,2793,2778,2763,2748,
2733,2718,2703,2688,2672,2657,2641,2626,2610,2594,
2579,2563,2547,2531,2515,2499,2483,2467,2451,2435,
2419,2402,2386,2370,2354,2337,2321,2304,2288,2271,
2255,2238,2222,2205,2189,2172,2156,2139,2122,2106,
2089,2072,2056,2039,2023,2006,1989,1973,1956,1939,
1923,1906,1890,1873,1857,1840,1824,1807,1791,1774,
1758,1741,1725,1709,1693,1676,1660,1644,1628,1612,
1596,1580,1564,1548,1532,1516,1501,1485,1469,1454,
1438,1423,1407,1392,1377,1362,1347,1332,1317,1302,
1287,1272,1257,1243,1228,1214,1200,1185,1171,1157,
1143,1129,1116,1102,1088,1075,1061,1048,1035,1022,
1009,996,983,970,958,945,933,921,909,897,
885,873,861,850,838,827,816,805,794,783,
772,762,751,741,731,721,711,701,692,682,
673,664,655,646,637,628,620,611,603,595,
587,580,572,564,557,550,543,536,529,523,
516,510,504,498,492,487,481,476,471,466,
461,456,452,448,443,439,436,432,428,425,
422,419,416,413,411,408,406,404,402,400,
399,398,396,395,394,394,393,393,393,393,
393,393,393,394,395,396,397,398,400,401,
403,405,407,409,412,415,417,420,423,427,
430,434,438,441,446,450,454,459,464,468,
474,479,484,490,495,501,507,513,520,526,
533,540,546,554,561,568,576,583,591,599,
607,616,624,633,641,650,659,668,678,687,
696,706,716,726,736,746,757,767,778,788,
799,810,821,833,844,855,867,879,891,903,
915,927,939,951,964,977,989,1002,1015,1028,
1041,1055,1068,1081,1095,1109,1122,1136,1150,1164,
1178,1193,1207,1221,1236,1250,1265,1280,1294,1309,
1324,1339,1354,1369,1384,1400,1415,1431,1446,1462,
1477,1493,1508,1524,1540,1556,1572,1588,1604,1620,
1636,1652,1668,1684,1701,1717,1733,1750,1766,1782,
1799,1815,1832,1848,1865,1881,1898,1915,1931,1948,
1964,1981,1998,2014,2031
};
unsigned short sincode50[]={
614,606,598,590,582,574,567,560,552,545,
538,532,525,519,512,506,500,494,489,483,
478,473,468,463,458,453,449,445,441,437,
433,430,426,423,420,417,414,411,409,407,
405,403,401,399,398,397,396,395,394,393,
393,393,393,393,393,393,394,395,395,396,
398,399,401,402,404,406,409,411,414,416,
419,422,426,429,433,436,440,444,448,453,
457,462,467,472,477,482,488,493,499,505,
511,518,524,531,537,544,551,558,566,573,
581,589,597,605,613,621,630,638,647,656,
665,674,684,693,703,713,723,733,743,753,
764,774,785,796,807,818,829,840,852,863,
875,887,899,911,923,935,947,960,972,985,
998,1011,1024,1037,1050,1064,1077,1090,1104,1118,
1132,1146,1160,1174,1188,1202,1216,1231,1245,1260,
1275,1289,1304,1319,1334,1349,1364,1379,1395,1410,
1425,1441,1456,1472,1488,1503,1519,1535,1551,1566,
1582,1598,1614,1631,1647,1663,1679,1695,1712,1728,
1744,1761,1777,1793,1810,1826,1843,1859,1876,1892,
1909,1926,1942,1959,1975,1992,2009,2025,2042,2059,
2075,2092,2108,2125,2142,2158,2175,2192,2208,2225,
2241,2258,2274,2291,2307,2324,2340,2356,2373,2389,
2405,2421,2438,2454,2470,2486,2502,2518,2534,2550,
2566,2581,2597,2613,2628,2644,2659,2675,2690,2705,
2721,2736,2751,2766,2781,2796,2811,2825,2840,2855,
2869,2883,2898,2912,2926,2940,2954,2968,2982,2995,
3009,3023,3036,3049,3062,3075,3088,3101,3114,3127,
3139,3152,3164,3176,3188,3200,3212,3224,3236,3247,
3259,3270,3281,3292,3303,3314,3324,3335,3345,3356,
3366,3376,3386,3395,3405,3414,3424,3433,3442,3451,
3460,3468,3477,3485,3493,3501,3509,3517,3524,3532,
3539,3546,3553,3560,3567,3573,3580,3586,3592,3598,
3603,3609,3615,3620,3625,3630,3635,3639,3644,3648,
3652,3656,3660,3664,3667,3671,3674,3677,3680,3682,
3685,3687,3689,3691,3693,3695,3696,3698,3699,3700,
3701,3701,3702,3702,3702,3702,3702,3702,3702,3701,
3700,3699,3698,3697,3695,3693,3692,3690,3687,3685,
3683,3680,3677,3674,3671,3668,3664,3661,3657,3653,
3649,3644,3640,3635,3631,3626,3621,3615,3610,3604,
3599,3593,3587,3581,3574,3568,3561,3554,3547,3540,
3533,3526,3518,3510,3502,3494,3486,3478,3470,3461,
3452,3443,3434,3425,3416,3407,3397,3387,3377,3367,
3357,3347,3337,3326,3316,3305,3294,3283,3272,3261,
3249,3238,3226,3214,3202,3190,3178,3166,3154,3141,
3129,3116,3104,3091,3078,3065,3051,3038,3025,3011,
2998,2984,2970,2956,2942,2928,2914,2900,2886,2871,
2857,2842,2828,2813,2798,2783,2768,2753,2738,2723,
2708,2693,2677,2662,2646,2631,2615,2600,2584,2568,
2552,2536,2521,2505,2489,2472,2456,2440,2424,2408,
2392,2375,2359,2343,2326,2310,2293,2277,2260,2244,
2227,2211,2194,2178,2161,2144,2128,2111,2095,2078,
2061,2045,2028,2011,1995,1978,1962,1945,1928,1912,
1895,1879,1862,1846,1829,1813,1796,1780,1763,1747,
1731,1714,1698,1682,1666,1649,1633,1617,1601,1585,
1569,1553,1537,1522,1506,1490,1475,1459,1443,1428,
1413,1397,1382,1367,1352,1337,1322,1307,1292,1277,
1262,1248,1233,1219,1204,1190,1176,1162,1148,1134,
1120,1106,1093,1079,1066,1052,1039,1026,1013,1000,
987,975,962,949,937,925,913,901,889,877,
865,853,842,831,819,808,797,787,776,765,
755,744,734,724,714,705,695,685,676,667,
658,649,640,631,623
};
unsigned short sincode40[]={
3481,3472,3464,3455,3446,3437,3428,3419,3410,3400,
3390,3381,3371,3361,3351,3340,3330,3319,3308,3298,
3287,3276,3264,3253,3242,3230,3218,3206,3194,3182,
3170,3158,3146,3133,3120,3108,3095,3082,3069,3056,
3043,3029,3016,3002,2989,2975,2961,2947,2933,2919,
2905,2891,2876,2862,2847,2833,2818,2803,2788,2773,
2758,2743,2728,2713,2698,2682,2667,2652,2636,2620,
2605,2589,2573,2558,2542,2526,2510,2494,2478,2462,
2446,2429,2413,2397,2381,2364,2348,2332,2315,2299,
2282,2266,2249,2233,2216,2200,2183,2167,2150,2133,
2117,2100,2084,2067,2050,2034,2017,2000,1984,1967,
1951,1934,1917,1901,1884,1868,1851,1835,1818,1802,
1785,1769,1752,1736,1720,1703,1687,1671,1655,1639,
1623,1606,1590,1574,1559,1543,1527,1511,1495,1480,
1464,1449,1433,1418,1402,1387,1372,1357,1342,1327,
1312,1297,1282,1267,1253,1238,1224,1209,1195,1181,
1167,1153,1139,1125,1111,1097,1084,1070,1057,1044,
1030,1017,1004,991,979,966,954,941,929,917,
905,893,881,869,857,846,834,823,812,801,
790,779,769,758,748,738,728,718,708,698,
688,679,670,661,652,643,634,625,617,609,
601,593,585,577,569,562,555,548,541,534,
527,521,514,508,502,496,491,485,480,474,
469,464,460,455,451,446,442,438,434,431,
427,424,421,418,415,412,410,408,405,403,
402,400,398,397,396,395,394,393,393,393,
393,393,393,393,394,394,395,396,397,399,
400,402,404,406,408,410,413,415,418,421,
424,428,431,435,439,443,447,451,456,460,
465,470,475,480,486,492,497,503,509,515,
522,528,535,542,549,556,563,571,578,586,
594,602,610,618,627,635,644,653,662,671,
681,690,700,709,719,729,739,750,760,771,
781,792,803,814,825,836,848,859,871,883,
895,907,919,931,943,956,968,981,994,1007,
1020,1033,1046,1059,1072,1086,1100,1113,1127,1141,
1155,1169,1183,1197,1212,1226,1240,1255,1270,1284,
1299,1314,1329,1344,1359,1374,1390,1405,1420,1436,
1451,1467,1482,1498,1514,1529,1545,1561,1577,1593,
1609,1625,1641,1657,1674,1690,1706,1722,1739,1755,
1771,1788,1804,1821,1837,1854,1870,1887,1903,1920,
1937,1953,1970,1987,2003,2020,2036,2053,2070,2086,
2103,2120,2136,2153,2169,2186,2203,2219,2236,2252,
2269,2285,2302,2318,2334,2351,2367,2383,2400,2416,
2432,2448,2464,2481,2497,2513,2529,2544,2560,2576,
2592,2607,2623,2639,2654,2670,2685,2700,2716,2731,
2746,2761,2776,2791,2806,2820,2835,2850,2864,2879,
2893,2907,2921,2935,2949,2963,2977,2991,3005,3018,
3031,3045,3058,3071,3084,3097,3110,3123,3135,3148,
3160,3172,3184,3196,3208,3220,3232,3243,3255,3266,
3277,3288,3299,3310,3321,3331,3342,3352,3362,3372,
3382,3392,3402,3411,3421,3430,3439,3448,3457,3465,
3474,3482,3490,3498,3506,3514,3522,3529,3537,3544,
3551,3558,3564,3571,3577,3584,3590,3596,3602,3607,
3613,3618,3623,3628,3633,3638,3642,3647,3651,3655,
3659,3662,3666,3669,3673,3676,3679,3681,3684,3686,
3689,3691,3693,3694,3696,3697,3699,3700,3700,3701,
3702,3702,3702,3702,3702,3702,3702,3701,3700,3699,
3698,3697,3696,3694,3692,3690,3688,3686,3684,3681,
3678,3675,3672,3669,3665,3662,3658,3654,3650,3646,
3642,3637,3632,3627,3622,3617,3612,3606,3601,3595,
3589,3583,3576,3570,3563,3557,3550,3543,3535,3528,
3521,3513,3505,3497,3489
};

unsigned short node=sizeof(sincode50)/sizeof(unsigned short);

static int  dram_open(struct inode *inode,struct file *filp)
{
        unsigned short minor,i;
 void __iomem *pt=NULL;
        minor = MINOR(inode->i_rdev);
        dram_devices[minor]++;
 //init dram
 pt=ioremap(DA_BASE,DRAM_LEN+1);
 if(pt==NULL){
  printk("Failed to remap register bloack!/n");
  return -ENOMEM;
 }
 for(i=0;i<DRAM_LEN;i++){
  writew(0x00,pt);
  pt++;
 }
 //iounmap(DA_BASE); 
        return 0;
}

static int  dram_release(struct inode *inode,struct file *filp)
{
        int minor;
        minor = MINOR(inode->i_rdev);
        if(dram_devices[minor])
                dram_devices[minor]--;
 //iounmap(DA_BASE);
        return 0;
}

static int  dram_ctl_ioctl(struct inode *inode, struct file *filp,

unsigned int command, unsigned long arg)
{
        int err = 0;
 int i=0;
        int minor = MINOR(inode->i_rdev);
 void __iomem *pt;
      
        switch(command)
        {
        case 1:
  pt=ioremap(DA_BASE,DRAM_LEN+1 );
  if(pt==NULL){
   printk("Failed to remap register bloack!/n");
   return -ENOMEM;
  }
  for(i=0;i<DRAM_LEN;i++){
   writew(0x800,pt);
   pt++;
  }
  printk("DA half output!/n");
  //iounmap(DA_BASE);
                break;
        case 2:
  pt=ioremap(DA_BASE,DRAM_LEN+1);
  if(pt==NULL){
   printk("Failed to remap register bloack!/n");
   return -ENOMEM;
  }
  for(i=0;i<DRAM_LEN;i++){
   writew(0xfff,pt);
   pt++;
  }
  printk("DA full output!/n");
  //iounmap(DA_BASE);
                break;
}

        return err;
}

static ssize_t dram_read(struct file *f,char *buf,int size,loff_t *off)
{
 printk("in read function!/n");
 return 0;
}
static ssize_t dram_write(struct file *f,const char *buf, int size,loff_t *off)
{
 void __iomem *pt;
 int i=0;
/* pt=ioremap(DA_BASE,DRAM_LEN+1);
 if(size>DRAM_LEN){
  printk("Write DRAM out of size!"); 
   return -EFAULT;
 }
 if(copy_from_user(pt,buf,size)) return -EFAULT;
*/
  pt=ioremap(DA_BASE,DRAM_LEN+1);
  if(pt==NULL){
   printk("Failed to remap register bloack!/n");
   return -ENOMEM;
  }
  for(i=0;i<node;i++){
   writew(sincode60[i],pt);
   pt+=2;
   writew(sincode50[i],pt);
   pt+=2;
   writew(sincode40[i],pt);
   pt+=2;
  }
 return 0;
}

static struct file_operations dram_ctl_fops={
    owner:              THIS_MODULE,
        ioctl:          dram_ctl_ioctl,
        open:           dram_open,
        release:        dram_release,
 write:  dram_write,
 read:   dram_read,
 
};

static int __init dram_init(void)
{
        register_chrdev(IOPORT_MAJOR ,"dram_driver",&dram_ctl_fops);
        return 0;
}

static void __exit dram_exit(void)
{
        unregister_chrdev(IOPORT_MAJOR,"dram_driver");

}

module_init(dram_init);
module_exit(dram_exit);

 

Makefile文件:

# Makefile2.6
ifneq ($(KERNELRELEASE),)
#kbuild syntax. dependency relationship of files and target modules are listed here.
#obj-m +=hello.o
#obj-m :=gpio_driver.o
obj-m :=dram_driver.o
else
PWD :=$(shell pwd)
KEVER ?=$(shell uname -r)
#KDIR :=/home/wfg/linux-2.6.26.3/$(KEVER)/build
#KDIR :=/home/wfg/linux-2.6.26.3
KDIR :=/home/wuyan/download/linux-2.6.26
default:
 #$(MAKE) -C $(KDIR) M=$(PWD)
 make -C $(KDIR) M=$(PWD) modules
clean:
 rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions *.order *symvers
endif

测试程序:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/time.h>
#define DEVICE_DRAM                "/dev/dram_driver"

#define IOWRITE                1
#define IOCLEAR                2

unsigned short sincode60[]={2048,2064,2081,2097,2114,2131,2147,2164,2180,2197,
2214,2230,2247,2263,2280,2296,2313,2329,2345,2362,
2378,2394,2411,2427,2443,2459,2475,2491,2507,2523,
2539,2555,2571,2587,2602,2618,2633,2649,2664,2680,
2695,2711,2726,2741,2756,2771,2786,2801,2815,2830,
2845,2859,2874,2888,2902,2917,2931,2945,2959,2973,
2986,3000,3014,3027,3040,3054,3067,3080,3093,3106,
3118,3131,3144,3156,3168,3180,3192,3204,3216,3228,
3240,3251,3262,3274,3285,3296,3307,3317,3328,3338,
3349,3359,3369,3379,3389,3399,3408,3417,3427,3436,
3445,3454,3462,3471,3479,3488,3496,3504,3512,3519,
3527,3534,3541,3549,3555,3562,3569,3575,3582,3588,
3594,3600,3605,3611,3616,3621,3627,3631,3636,3641,
3645,3649,3654,3657,3661,3665,3668,3672,3675,3678,
3680,3683,3686,3688,3690,3692,3694,3695,3697,3698,
3699,3700,3701,3702,3702,3702,3702,3702,3702,3702,
3701,3701,3700,3699,3697,3696,3695,3693,3691,3689,
3687,3684,3682,3679,3676,3673,3670,3667,3663,3659,
3656,3652,3647,3643,3639,3634,3629,3624,3619,3614,
3608,3603,3597,3591,3585,3579,3572,3566,3559,3552,
3545,3538,3531,3523,3515,3508,3500,3492,3484,3475,
3467,3458,3449,3440,3431,3422,3413,3403,3394,3384,
3374,3364,3354,3344,3333,3323,3312,3301,3290,3279,
3268,3257,3245,3234,3222,3210,3198,3186,3174,3162,
3150,3137,3125,3112,3099,3086,3073,3060,3047,3034,
3020,3007,2993,2979,2966,2952,2938,2924,2910,2895,
2881,2867,2852,2838,2823,2808,2793,2778,2763,2748,
2733,2718,2703,2688,2672,2657,2641,2626,2610,2594,
2579,2563,2547,2531,2515,2499,2483,2467,2451,2435,
2419,2402,2386,2370,2354,2337,2321,2304,2288,2271,
2255,2238,2222,2205,2189,2172,2156,2139,2122,2106,
2089,2072,2056,2039,2023,2006,1989,1973,1956,1939,
1923,1906,1890,1873,1857,1840,1824,1807,1791,1774,
1758,1741,1725,1709,1693,1676,1660,1644,1628,1612,
1596,1580,1564,1548,1532,1516,1501,1485,1469,1454,
1438,1423,1407,1392,1377,1362,1347,1332,1317,1302,
1287,1272,1257,1243,1228,1214,1200,1185,1171,1157,
1143,1129,1116,1102,1088,1075,1061,1048,1035,1022,
1009,996,983,970,958,945,933,921,909,897,
885,873,861,850,838,827,816,805,794,783,
772,762,751,741,731,721,711,701,692,682,
673,664,655,646,637,628,620,611,603,595,
587,580,572,564,557,550,543,536,529,523,
516,510,504,498,492,487,481,476,471,466,
461,456,452,448,443,439,436,432,428,425,
422,419,416,413,411,408,406,404,402,400,
399,398,396,395,394,394,393,393,393,393,
393,393,393,394,395,396,397,398,400,401,
403,405,407,409,412,415,417,420,423,427,
430,434,438,441,446,450,454,459,464,468,
474,479,484,490,495,501,507,513,520,526,
533,540,546,554,561,568,576,583,591,599,
607,616,624,633,641,650,659,668,678,687,
696,706,716,726,736,746,757,767,778,788,
799,810,821,833,844,855,867,879,891,903,
915,927,939,951,964,977,989,1002,1015,1028,
1041,1055,1068,1081,1095,1109,1122,1136,1150,1164,
1178,1193,1207,1221,1236,1250,1265,1280,1294,1309,
1324,1339,1354,1369,1384,1400,1415,1431,1446,1462,
1477,1493,1508,1524,1540,1556,1572,1588,1604,1620,
1636,1652,1668,1684,1701,1717,1733,1750,1766,1782,
1799,1815,1832,1848,1865,1881,1898,1915,1931,1948,
1964,1981,1998,2014,2031
};
unsigned short sincode50[]={
614,606,598,590,582,574,567,560,552,545,
538,532,525,519,512,506,500,494,489,483,
478,473,468,463,458,453,449,445,441,437,
433,430,426,423,420,417,414,411,409,407,
405,403,401,399,398,397,396,395,394,393,
393,393,393,393,393,393,394,395,395,396,
398,399,401,402,404,406,409,411,414,416,
419,422,426,429,433,436,440,444,448,453,
457,462,467,472,477,482,488,493,499,505,
511,518,524,531,537,544,551,558,566,573,
581,589,597,605,613,621,630,638,647,656,
665,674,684,693,703,713,723,733,743,753,
764,774,785,796,807,818,829,840,852,863,
875,887,899,911,923,935,947,960,972,985,
998,1011,1024,1037,1050,1064,1077,1090,1104,1118,
1132,1146,1160,1174,1188,1202,1216,1231,1245,1260,
1275,1289,1304,1319,1334,1349,1364,1379,1395,1410,
1425,1441,1456,1472,1488,1503,1519,1535,1551,1566,
1582,1598,1614,1631,1647,1663,1679,1695,1712,1728,
1744,1761,1777,1793,1810,1826,1843,1859,1876,1892,
1909,1926,1942,1959,1975,1992,2009,2025,2042,2059,
2075,2092,2108,2125,2142,2158,2175,2192,2208,2225,
2241,2258,2274,2291,2307,2324,2340,2356,2373,2389,
2405,2421,2438,2454,2470,2486,2502,2518,2534,2550,
2566,2581,2597,2613,2628,2644,2659,2675,2690,2705,
2721,2736,2751,2766,2781,2796,2811,2825,2840,2855,
2869,2883,2898,2912,2926,2940,2954,2968,2982,2995,
3009,3023,3036,3049,3062,3075,3088,3101,3114,3127,
3139,3152,3164,3176,3188,3200,3212,3224,3236,3247,
3259,3270,3281,3292,3303,3314,3324,3335,3345,3356,
3366,3376,3386,3395,3405,3414,3424,3433,3442,3451,
3460,3468,3477,3485,3493,3501,3509,3517,3524,3532,
3539,3546,3553,3560,3567,3573,3580,3586,3592,3598,
3603,3609,3615,3620,3625,3630,3635,3639,3644,3648,
3652,3656,3660,3664,3667,3671,3674,3677,3680,3682,
3685,3687,3689,3691,3693,3695,3696,3698,3699,3700,
3701,3701,3702,3702,3702,3702,3702,3702,3702,3701,
3700,3699,3698,3697,3695,3693,3692,3690,3687,3685,
3683,3680,3677,3674,3671,3668,3664,3661,3657,3653,
3649,3644,3640,3635,3631,3626,3621,3615,3610,3604,
3599,3593,3587,3581,3574,3568,3561,3554,3547,3540,
3533,3526,3518,3510,3502,3494,3486,3478,3470,3461,
3452,3443,3434,3425,3416,3407,3397,3387,3377,3367,
3357,3347,3337,3326,3316,3305,3294,3283,3272,3261,
3249,3238,3226,3214,3202,3190,3178,3166,3154,3141,
3129,3116,3104,3091,3078,3065,3051,3038,3025,3011,
2998,2984,2970,2956,2942,2928,2914,2900,2886,2871,
2857,2842,2828,2813,2798,2783,2768,2753,2738,2723,
2708,2693,2677,2662,2646,2631,2615,2600,2584,2568,
2552,2536,2521,2505,2489,2472,2456,2440,2424,2408,
2392,2375,2359,2343,2326,2310,2293,2277,2260,2244,
2227,2211,2194,2178,2161,2144,2128,2111,2095,2078,
2061,2045,2028,2011,1995,1978,1962,1945,1928,1912,
1895,1879,1862,1846,1829,1813,1796,1780,1763,1747,
1731,1714,1698,1682,1666,1649,1633,1617,1601,1585,
1569,1553,1537,1522,1506,1490,1475,1459,1443,1428,
1413,1397,1382,1367,1352,1337,1322,1307,1292,1277,
1262,1248,1233,1219,1204,1190,1176,1162,1148,1134,
1120,1106,1093,1079,1066,1052,1039,1026,1013,1000,
987,975,962,949,937,925,913,901,889,877,
865,853,842,831,819,808,797,787,776,765,
755,744,734,724,714,705,695,685,676,667,
658,649,640,631,623
};
unsigned short sincode40[]={
3481,3472,3464,3455,3446,3437,3428,3419,3410,3400,
3390,3381,3371,3361,3351,3340,3330,3319,3308,3298,
3287,3276,3264,3253,3242,3230,3218,3206,3194,3182,
3170,3158,3146,3133,3120,3108,3095,3082,3069,3056,
3043,3029,3016,3002,2989,2975,2961,2947,2933,2919,
2905,2891,2876,2862,2847,2833,2818,2803,2788,2773,
2758,2743,2728,2713,2698,2682,2667,2652,2636,2620,
2605,2589,2573,2558,2542,2526,2510,2494,2478,2462,
2446,2429,2413,2397,2381,2364,2348,2332,2315,2299,
2282,2266,2249,2233,2216,2200,2183,2167,2150,2133,
2117,2100,2084,2067,2050,2034,2017,2000,1984,1967,
1951,1934,1917,1901,1884,1868,1851,1835,1818,1802,
1785,1769,1752,1736,1720,1703,1687,1671,1655,1639,
1623,1606,1590,1574,1559,1543,1527,1511,1495,1480,
1464,1449,1433,1418,1402,1387,1372,1357,1342,1327,
1312,1297,1282,1267,1253,1238,1224,1209,1195,1181,
1167,1153,1139,1125,1111,1097,1084,1070,1057,1044,
1030,1017,1004,991,979,966,954,941,929,917,
905,893,881,869,857,846,834,823,812,801,
790,779,769,758,748,738,728,718,708,698,
688,679,670,661,652,643,634,625,617,609,
601,593,585,577,569,562,555,548,541,534,
527,521,514,508,502,496,491,485,480,474,
469,464,460,455,451,446,442,438,434,431,
427,424,421,418,415,412,410,408,405,403,
402,400,398,397,396,395,394,393,393,393,
393,393,393,393,394,394,395,396,397,399,
400,402,404,406,408,410,413,415,418,421,
424,428,431,435,439,443,447,451,456,460,
465,470,475,480,486,492,497,503,509,515,
522,528,535,542,549,556,563,571,578,586,
594,602,610,618,627,635,644,653,662,671,
681,690,700,709,719,729,739,750,760,771,
781,792,803,814,825,836,848,859,871,883,
895,907,919,931,943,956,968,981,994,1007,
1020,1033,1046,1059,1072,1086,1100,1113,1127,1141,
1155,1169,1183,1197,1212,1226,1240,1255,1270,1284,
1299,1314,1329,1344,1359,1374,1390,1405,1420,1436,
1451,1467,1482,1498,1514,1529,1545,1561,1577,1593,
1609,1625,1641,1657,1674,1690,1706,1722,1739,1755,
1771,1788,1804,1821,1837,1854,1870,1887,1903,1920,
1937,1953,1970,1987,2003,2020,2036,2053,2070,2086,
2103,2120,2136,2153,2169,2186,2203,2219,2236,2252,
2269,2285,2302,2318,2334,2351,2367,2383,2400,2416,
2432,2448,2464,2481,2497,2513,2529,2544,2560,2576,
2592,2607,2623,2639,2654,2670,2685,2700,2716,2731,
2746,2761,2776,2791,2806,2820,2835,2850,2864,2879,
2893,2907,2921,2935,2949,2963,2977,2991,3005,3018,
3031,3045,3058,3071,3084,3097,3110,3123,3135,3148,
3160,3172,3184,3196,3208,3220,3232,3243,3255,3266,
3277,3288,3299,3310,3321,3331,3342,3352,3362,3372,
3382,3392,3402,3411,3421,3430,3439,3448,3457,3465,
3474,3482,3490,3498,3506,3514,3522,3529,3537,3544,
3551,3558,3564,3571,3577,3584,3590,3596,3602,3607,
3613,3618,3623,3628,3633,3638,3642,3647,3651,3655,
3659,3662,3666,3669,3673,3676,3679,3681,3684,3686,
3689,3691,3693,3694,3696,3697,3699,3700,3700,3701,
3702,3702,3702,3702,3702,3702,3702,3701,3700,3699,
3698,3697,3696,3694,3692,3690,3688,3686,3684,3681,
3678,3675,3672,3669,3665,3662,3658,3654,3650,3646,
3642,3637,3632,3627,3622,3617,3612,3606,3601,3595,
3589,3583,3576,3570,3563,3557,3550,3543,3535,3528,
3521,3513,3505,3497,3489
};

unsigned short node=sizeof(sincode50)/sizeof(unsigned short);
unsigned short data[3000];
unsigned short data1[10];
int main()
{
        int fd;
        int val=-1,i=0;
 unsigned short *pt=NULL;
      
        if( (fd=open(DEVICE_DRAM,O_RDWR)) < 0 )
        {
                perror("can not open device");
                exit(1);
        }
 printf("open device success!DA point is %d/n",node);
 
       for(i=0;i<3000;i++) data[i]=0;
 pt=data;
 for(i=0;i<node;i++){
  *pt++=sincode60[i];
  *pt++=sincode50[i];
  *pt++=sincode40[i];
 }
 write(fd,data,3*node);
        while(1)
        {
             printf("0:quit,1:half,2:full,3:write,4:read/n");
                scanf("%d",&val);
              
                if(val==1)
                        ioctl(fd,1,0);
                else if(val==2)
                        ioctl(fd,2,0);
  else if(val==3)
                        write(fd,data,3*node);
  else if(val==4)
                        read(fd,data1,3);
                else if(val==0)
                  {
                        close(fd);
                        exit(1);
                }  
        }
}

重新生成JFFS2文件系统,下载到板子中

root@WK:ls
aImage20008000  dram_test       mnt             tmp
aImage_old      etc             proc            usr
bin             example         root            var
boot            home            sbin
dev             lib             sys
root@WK:insmod dram_driver
root@WK:lsmod
dram_driver 6401 0 - Live 0xbf000000

root@WK:mknod /dev/dram_driver c 221 1
root@WK:./dram_test
open device success!DA point is 625
0:quit,1:half,2:full,3:write,4:read

成功输出了三相正玄波信号!

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Linux驱动开发入门
十一、Linux驱动程序开发(2) - 字符设备驱动(1)
linux内核ioctl网络控制框架实现分析
linux 延时函数
S3C2440 spi驱动简单测试 - 简单生活 - 博客园
Linux下第一个原创LED驱动全攻略
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服