Skip to content

Commit

Permalink
c-code from Pavel for measuring the 1-pps deviation of the 125 MHz AD…
Browse files Browse the repository at this point in the history
…C clock
  • Loading branch information
PA7T committed Sep 1, 2017
1 parent 1828167 commit b84c051
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
Binary file added measure-corr
Binary file not shown.
20 changes: 20 additions & 0 deletions src/measure-corr/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2014-present Pavel Demin

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 changes: 10 additions & 0 deletions src/measure-corr/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CFLAGS = -O3 -march=armv7-a -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard -ffast-math -fsingle-precision-constant -mvectorize-with-neon-quad

all: measure-corr

measure-corr: measure-corr.c
gcc $(CFLAGS) -o $@ $^ -lm -lconfig
cp measure-corr ../../

clean:
rm measure-corr
Binary file added src/measure-corr/measure-corr
Binary file not shown.
63 changes: 63 additions & 0 deletions src/measure-corr/measure-corr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>

int main(int argc, char *argv[])
{
int fd, i;
char *end;
volatile void *cfg, *sts;
volatile uint32_t *fifo;
volatile uint8_t *rst;
volatile uint16_t *cntr;
long number;
uint32_t buffer;

errno = 0;
number = (argc == 2) ? strtol(argv[1], &end, 10) : -1;
if(errno != 0 || end == argv[1] || number < 1 || number > 30)
{
fprintf(stderr, "Usage: measure-corr [1-30]\n");
return EXIT_FAILURE;
}

if((fd = open("/dev/mem", O_RDWR)) < 0)
{
perror("open");
return EXIT_FAILURE;
}

sts = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40000000);
cfg = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40001000);
fifo = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x4000C000);

rst = (uint8_t *)(cfg + 3);
cntr = (uint16_t *)(sts + 28);

*rst &= ~1;
*rst |= 1;

sleep(number + 1);

if(*cntr < number)
{
fprintf(stderr, "Not enough PPS pulses.\n");
return EXIT_FAILURE;
}

buffer = 0;

for(i = 0; i < number; ++i)
{
buffer += *fifo + 1;
}

printf("%.2f\n", (125.0e6 * number / buffer - 1.0) * 1.0e6);

return EXIT_SUCCESS;
}

0 comments on commit b84c051

Please sign in to comment.