File size: 1,237 Bytes
8be366a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Userspace c library Example to measure delay between two 4 byte writes but this time includes cycles taken to calculate the delay
 *
 * Copyright (C) 2015 Apaar Gupta
 * This file is licensed under the terms of the GNU General Public License
 * version 2.  This program is licensed "as is" without any warranty of any
 * kind, whether express or implied.
 */

#include "pru_bridge.h"
#include "pru_defs.h"

static inline u32 read_PIEP_COUNT(void)
{
    return PIEP_COUNT;
}

int main()
{


    /* configure timer */
	PIEP_GLOBAL_CFG = GLOBAL_CFG_CNT_ENABLE	|
			  GLOBAL_CFG_DEFAULT_INC(1) |
			  GLOBAL_CFG_CMP_INC(1);
	PIEP_CMP_STATUS = CMD_STATUS_CMP_HIT(1);
	PIEP_CMP_CFG |= CMP_CFG_CMP_EN(1);

	int current = 0,last = 0,delay = 0;

    while(check_init() != 1);

    uint8_t check_flag = 0;         //getting the pru to wait until we are ready to read
    while(check_flag == 0)
    {
        read_buffer(1,&check_flag,1);
    }

    while(1)
    {
        //if(check_index(0))           //checking if the buffer is full or not
        //{
            current = read_PIEP_COUNT();
            delay = current - last;
            write_buffer(0,(uint8_t*)(&delay),4);
            last = current;
        //}
    }

return 0;
}