OpenCores
URL https://opencores.org/ocsvn/timestamp/timestamp/trunk

Subversion Repositories timestamp

[/] [timestamp/] [trunk/] [tstamp_linux/] [tstamp_lnx.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 robotron
/**
2
 ** timestamp APU HW under Linux
3
 **/
4
 
5
#include <inttypes.h>
6
#include <sys/mman.h>
7
#include <sys/types.h>
8
#include <sys/stat.h>
9
#include <fcntl.h>
10
#include <stdio.h>
11
 
12
/******/
13
/* ex xpseudo_asm_gcc.h: */
14
#define UDI0FCM_IMM_GPR_GPR(a, b, c)                    \
15
  __asm__ __volatile__("udi0fcm " #a ",%0,%1" : : "r"(b), "r"(c))
16
/******/
17
 
18
#define UDI_TSTAMP(id) __asm__ __volatile__("udi0fcm 0,%0,%0" : : "r"(id))
19
 
20
void *map_bram(uint32_t addr, uint32_t len) {
21
  int fd;
22
  unsigned long page_size;
23
  void *mem;
24
 
25
  if ((fd = open("/dev/mem", O_RDWR|O_SYNC)) < 0) {
26
    perror("open /dev/mem");
27
    return NULL;
28
  }
29
 
30
  page_size = getpagesize();
31
  mem = mmap(NULL, len, PROT_WRITE|PROT_READ,
32
             MAP_SHARED, fd, addr & ~(page_size-1));
33
  mem += addr & (page_size-1);
34
 
35
  return mem;
36
}
37
 
38
int main() {
39
  uint32_t *bram = map_bram(0xcc000000, 0x1000);
40
  char c;
41
  int a, b, i;
42
 
43
  for (i = 0; i < 0x400; i++)
44
    bram[i] = 0;
45
 
46
  printf("Go!\r\n");
47
  for (;;) {
48
    c = getchar();
49
    UDI_TSTAMP(1);
50
    UDI_TSTAMP(0xdeadbeef);
51
 
52
    for (i = 0; i < 0x400; i += 2)
53
      if (bram[i] != 0)
54
        printf("%02x: (0x%08x) 0x%08x\r\n", i/2, bram[i], bram[i+1]);
55
 
56
    printf("--\r\n");
57
  }
58
 
59
  return 0;
60
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.