Skip to content
Snippets Groups Projects
Commit 0f610440 authored by Aljoscha Wißfeld's avatar Aljoscha Wißfeld
Browse files

Merge branch 'master' of gitlab.cs.hs-rm.de:CaroloCup/remoteproc-shm

parents 1fd43013 53271d9f
No related branches found
No related tags found
1 merge request!7Multithreads enabled
Makefile 100644 → 100755
File mode changed from 100644 to 100755
all: mem_dump shm_test
mem_dump: mem_dump.o
gcc -Wall mem_dump.o -o mem_dump
shm_test: shm_test.o
gcc -Wall shm_test.o -o shm_test
mem_dump.o: mem_dump.c
gcc -c -Wall mem_dump.c
shm_test.o: shm_test.c
gcc -c -Wall shm_test.c
clean:
rm mem_dump shm_test *.o
/**
* Title: Test application
*
* Author: Alexander Wilhelm
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#define SIZE 32
int main(void) {
int ret;
int fd;
char buf[32];
//void *shm;
uint8_t *shm;
unsigned long offset[] = {0x95800000, 0x99000000, 0x9d100000, 0x9f000000, 0xac000000, 0xfe400000, 0xfe600000, 0xb2049000};
fd = open("/dev/mem", O_RDWR);
if (fd < 0) {
printf("OPEN ERROR: %d\n", fd);
}
printf("FD opened: %d\n", fd);
for (int i = 0; i < 8; i++) {
shm = mmap(NULL, sizeof(buf), PROT_READ, MAP_SHARED, fd, offset[i]);
printf("/dev/mem mmaped: %x\n", shm);
printf("OFFSET: %x\n", offset[i]);
for (int i = 0; i < SIZE; i++) {
printf("%02x ", shm[i]);
}
printf(" ");
for (int i = 0; i < SIZE; i++) {
printf("%c ", shm[i]);
}
printf("\n");
munmap(shm, sizeof(buf));
}
/*
for (int i = 0; i < 250000; i++) {
printf("%x: ", offset);
lseek(fd, offset, SEEK_SET);
ret = read(fd, buf, 32);
for (int j = 0; j < 32; j++) {
printf("%c ", buf[j]);
}
printf("\n");
offset += 32;
}
*/
for (int i = 0; i < 7; i++) {
printf("%x: ", offset[i]);
lseek(fd, offset[i], SEEK_SET);
read(fd, buf, SIZE);
for (int j = 0; j < SIZE; j++) {
printf("%x ", buf[j]);
}
printf("\n");
}
if (close(fd) != 0) {
printf("CLOSE ERROR: %d\n", fd);
}
printf("FD closed: %d\n", fd);
return 0;
}
/**
* Title: Test application for Remoteproc-SHM-Driver
*
* Author: Alexander Wilhelm
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#define RPROC_FILE "/dev/rproc-shm0"
#define MESSAGE "Hello world"
int main(void) {
int ret;
int fd;
char *string = MESSAGE;
char buf[16];
char *shm;
fd = open(RPROC_FILE, O_RDWR);
if (fd < 0) {
printf("OPEN ERROR: %d\n", fd);
}
printf("FD opened: %d\n", fd);
shm = mmap(NULL, sizeof(buf), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
printf("SHM POINTER: %p\n", shm);
shm[0] = 'A';
shm[1] = 'B';
shm[2] = 'C';
shm[3] = 'D';
shm[4] = 'E';
msync(shm, sizeof(buf), MS_SYNC);
printf("ABC written\n");
printf("SHM: %c%c%c%c%c\n", shm[0], shm[1], shm[2], shm[3], shm[4]);
ret = read(fd, buf, 5);
printf("%d read\n", ret);
printf("Message: %c%c%c%c%c\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
printf("SHM POINTER: %p\n", shm);
shm[0] = 'V';
shm[1] = 'W';
shm[2] = 'X';
shm[3] = 'Y';
shm[4] = 'Z';
msync(shm, sizeof(buf), MS_SYNC);
printf("ABC written\n");
printf("SHM: %c%c%c%c%c\n", shm[0], shm[1], shm[2], shm[3], shm[4]);
lseek(fd, 0, SEEK_SET);
ret = read(fd, buf, 5);
printf("%d read\n", ret);
printf("Message: %c%c%c%c%c\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
/*
ret = write(fd, string, 12);
printf("%d written\n", ret);
lseek(fd, 0, SEEK_SET);
ret = read(fd, &buf, 12);
printf("%d read; Message: %s\n", ret, buf);
*/
ret = munmap(shm, sizeof(buf));
if (ret < 0) {
printf("munmap Error: %d", ret);
}
if (close(fd) != 0) {
printf("CLOSE ERROR: %d\n", fd);
}
printf("FD closed: %d\n", fd);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment