Skip to content

Commit

Permalink
axis.h is updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
shtaxxx committed Mar 9, 2016
1 parent e5a56aa commit 6c1ef75
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
15 changes: 7 additions & 8 deletions lib/axis.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <fcntl.h>

int fd_axis [NUM_AXIS];
volatile int* axis_ptr [NUM_AXIS];
volatile void* axis_ptr [NUM_AXIS];

void uio_name(char* uio, int i)
{
Expand All @@ -27,25 +27,24 @@ void axis_open()
int i;
for(i=0; i<NUM_AXIS; i++){
char uio [1024] = "/dev/uio";
uio_name(uio, i+1);
/* "/dev/uio0" is reserved for other purpose */
uio_name(uio, i);
fd_axis[i] = open(uio, O_RDWR);
if(fd_axis[i] < 1){
printf("Invalid UIO device file: '%s'\n", uio);
exit(1);
}
axis_ptr[i] = (volatile int*) mmap(NULL, AXIS_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd_axis[i], 0);
axis_ptr[i] = (volatile void*) mmap(NULL, AXIS_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd_axis[i], 0);
}
}

void axis_write_4b(unsigned int id, unsigned int data)
void axis_write_4b(unsigned int id, unsigned int offset, unsigned int data)
{
*axis_ptr[id] = (volatile unsigned int) data;
*(volatile unsigned int*)(axis_ptr[id] + offset) = data;
}

void axis_read_4b(unsigned int id, unsigned int* data)
void axis_read_4b(unsigned int id, unsigned int offset, unsigned int* data)
{
volatile unsigned int r = *axis_ptr[id];
volatile unsigned int r = *(volatile unsigned int*)(axis_ptr[id] + offset);
*data = r;
}

Expand Down
4 changes: 2 additions & 2 deletions sample/axis_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ int main(int argc, char** argv)

unsigned int value = atoi(argv[1]);

axis_write_4b(2, value);
axis_write_4b(2, 0, value);
printf("write: %d\n", value);

axis_read_4b(2, &value);
axis_read_4b(2, 8, &value);
printf("read: %d\n", value);

axis_close();
Expand Down
7 changes: 4 additions & 3 deletions sample/mem_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <sys/mman.h>
#include <fcntl.h>

#define GPIO_OFFSET (0x43c10000)

int main(int argc, char** argv)
{
if(argc < 2){
Expand All @@ -19,15 +21,14 @@ int main(int argc, char** argv)
return -1;
}

volatile int* ptr = (volatile int*) mmap(NULL, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
volatile int* gpio = (volatile int*)((void*) ptr + 0x43c10000);
volatile int* gpio = (volatile int*) mmap(NULL, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_OFFSET);

unsigned int value = atoi(argv[1]);

*gpio = value;
printf("write: %d\n", value);

value = *gpio;
value = *(gpio + 2);
printf("read: %d\n", value);

return 0;
Expand Down
33 changes: 33 additions & 0 deletions sample/uio_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <sys/mman.h>
#include <fcntl.h>

int main(int argc, char** argv)
{
if(argc < 2){
printf("Usage: ./a.out value\n");
return 0;
}

int fd = open("/dev/uio2", O_RDWR);
if(fd < 0){
printf("cannot open /dev/uio2\n");
return -1;
}

volatile int* gpio = (volatile int*) mmap(NULL, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

unsigned int value = atoi(argv[1]);

*gpio = value;
printf("write: %d\n", value);

value = *(gpio + 2);
printf("read: %d\n", value);

return 0;
}

0 comments on commit 6c1ef75

Please sign in to comment.