Root/Examples/ehw4/src/test/xburst.c

1#include <stdio.h>
2#include <stdlib.h>
3#include "fcntl.h"
4#include <sys/mman.h>
5#include <xburst.h>
6#include "jz47xx_gpio.h"
7#include <jz47xx_mmap.h>
8
9#define CS2_PORT JZ_GPIO_PORT_B
10#define CS2_PIN 26
11
12int periph_map(off_t offset)
13{
14int basemem, baseperiph;
15    basemem = open("/dev/mem", (O_RDWR | O_SYNC)); //abrir dispositivo memoria para mapear dir del periferico
16    if(basemem == -1)
17    {
18        printf("Error to open /dev/mem \n");
19        return -1;
20    }
21    baseperiph = (int )mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, basemem, offset);// & ~MAP_MASK);
22    if (baseperiph == -1)
23    {
24        printf ("Cannot mmap.\n");
25        return -1;
26    }
27return baseperiph;
28}
29
30
31int main(){
32int i, j;
33int basemem, base_periferico, *ConfigRegsBase_ptr;
34void *peripheral1_ptr;
35void *pio;
36
37printf("Xburst Test...");
38
39basemem = open("/dev/mem", (O_RDWR | O_SYNC)); //abrir dispositivo memoria para mapear dir del periferico
40if(basemem == -1)
41{
42    printf("Error al abrir /dev/mem \n");
43    return -1;
44}
45
46pio = jz_gpio_map(CS2_PORT);
47jz_gpio_as_func (pio, CS2_PIN, 0);
48
49ConfigRegsBase_ptr = (int *)periph_map(CONFIG_REGS_BASE);// + SACR2_OFFSET/sizeof(int);//SMCR2_OFFSET/sizeof(int);
50printf("\n%0x ", *(ConfigRegsBase_ptr + SMCR2_OFFSET/sizeof(int)));
51munmap(ConfigRegsBase_ptr, MAP_SIZE);
52
53peripheral1_ptr = (int *)periph_map(0x14000000);
54
55for(i = 0; i < 0xfff; i=i+4){
56    j = rand();
57// *(int *)(peripheral1_ptr + i) = j;
58// if(j != *(int *)(peripheral1_ptr + i)){
59// printf("\nError at %0x offset:%i\n", (int *)(peripheral1_ptr + i), i); exit(0);
60// }
61    printf("\nReg %i: write:%0x read:%0x", i, j, *(int *)(peripheral1_ptr + i) );
62}
63printf("\nPassed Test\n");
64munmap(peripheral1_ptr, MAP_SIZE);
65
66//munmap(base_periferico, MAP_SIZE);
67close(basemem);
68exit(0);
69}
70
71

Archive Download this file

Branches:
master



interactive