-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial code for software and interrupt timers
- Loading branch information
1 parent
925be6a
commit 3f3899b
Showing
5 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "interrupt_timer.h" | ||
|
||
volatile uint36 times[65536]; | ||
uint16 count = 0; | ||
|
||
uint1 intrLast = 0; | ||
uint1 intr = 0; | ||
uint32 command = 0; | ||
|
||
|
||
void interrupt_timer(volatile uint32 *commandIn, volatile uint1 *intrIn, volatile uint36 *timeIn, uint32 *timeOutHigh, uint32 *timeOutLow, uint32 *countOut) { | ||
#pragma HLS INTERFACE s_axilite port=commandIn bundle=BUS_A | ||
#pragma HLS INTERFACE s_axilite port=timeOutHigh bundle=BUS_A | ||
#pragma HLS INTERFACE s_axilite port=timeOutLow bundle=BUS_A | ||
#pragma HLS INTERFACE s_axilite port=countOut bundle=BUS_A | ||
#pragma HLS INTERFACE ap_ctrl_none port=return | ||
|
||
intr = *intrIn; | ||
command = *commandIn; | ||
|
||
if (command == 0 && intrLast == 0 && intr == 1) { | ||
times[count] = *timeIn; | ||
count++; | ||
} | ||
else if (command <= 65536) { | ||
uint16 item = command - 1; | ||
uint36 time = times[item]; | ||
*timeOutHigh = time >> 32; | ||
*timeOutLow = time & 0xFFFFFFFF; | ||
} | ||
else if (command == 0xFFFFFFFF) { | ||
count = 0; | ||
for (uint17 i = 0; i < 65536; i++) { | ||
times[i] = 0; | ||
} | ||
} | ||
|
||
intrLast = intr; | ||
*countOut = count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef __INTERRUPT_TIMER_H_ | ||
#define __INTERRUPT_TIMER_H_ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <ap_int.h> | ||
|
||
typedef ap_uint<1> uint1; | ||
typedef ap_uint<16> uint16; | ||
typedef ap_uint<17> uint17; | ||
typedef ap_uint<32> uint32; | ||
typedef ap_uint<36> uint36; | ||
|
||
void interrupt_timer(volatile uint32 *commandIn, volatile uint1 *intrIn, volatile uint36 *timeIn, uint32 *timeOutHigh, uint32 *timeOutLow, uint32 *countOut); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "profile_timer.h" | ||
|
||
typedef struct { | ||
uint36 time; | ||
uint32 tag; | ||
} timeStamp; | ||
|
||
volatile timeStamp times[65536]; | ||
uint16 count = 0; | ||
|
||
|
||
void profile_timer(uint32 *commandIn, uint32 *tagIn, uint36 *timeIn, uint32 *tagOut, uint32 *timeOutHigh, uint32 *timeOutLow, uint32 *countOut) { | ||
#pragma HLS INTERFACE s_axilite port=commandIn bundle=BUS_A | ||
#pragma HLS INTERFACE s_axilite port=tagIn bundle=BUS_A | ||
#pragma HLS INTERFACE s_axilite port=tagOut bundle=BUS_A | ||
#pragma HLS INTERFACE s_axilite port=timeOutHigh bundle=BUS_A | ||
#pragma HLS INTERFACE s_axilite port=timeOutLow bundle=BUS_A | ||
#pragma HLS INTERFACE s_axilite port=countOut bundle=BUS_A | ||
#pragma HLS INTERFACE s_axilite port=return bundle=BUS_A | ||
|
||
if (*commandIn == 0 && *tagIn != 0) { | ||
times[count].time = *timeIn; | ||
times[count].tag = *tagIn; | ||
count++; | ||
} | ||
else if (*commandIn <= 65536) { | ||
uint16 item = *commandIn - 1; | ||
*tagOut = times[item].tag; | ||
uint36 time = times[item].time; | ||
*timeOutHigh = time >> 32; | ||
*timeOutLow = time & 0xFFFFFFFF; | ||
} | ||
else if (*commandIn == 0xFFFFFFFF) { | ||
count = 0; | ||
for (uint17 i = 0; i < 65536; i++) { | ||
times[i].time = 0; | ||
times[i].tag = 0; | ||
} | ||
} | ||
|
||
*countOut = count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef __PROFILE_TIMER_H_ | ||
#define __PROFILE_TIMER_H_ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <ap_int.h> | ||
|
||
typedef ap_uint<1> uint1; | ||
typedef ap_uint<16> uint16; | ||
typedef ap_uint<17> uint17; | ||
typedef ap_uint<32> uint32; | ||
typedef ap_uint<36> uint36; | ||
|
||
void profile_timer(uint32 *commandIn, uint32 *tagIn, uint36 *timeIn, uint32 *tagOut, uint32 *timeOutHigh, uint32 *timeOutLow, uint32 *countOut); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "profile_timer.h" | ||
|
||
typedef struct { | ||
unsigned int time; | ||
unsigned int tag; | ||
} timeStamp; | ||
|
||
static timeStamp times[256]; | ||
|
||
int main() { | ||
|
||
uint32 commandIn = 0; | ||
uint32 tagIn = 0; | ||
uint32 timeIn = 0; | ||
uint32 tagOut = 0; | ||
uint32 timeOut = 0; | ||
|
||
// Clear timer | ||
commandIn = 0xFFFFFFFF; | ||
profile_timer(&commandIn, &tagIn, &timeIn, &tagOut, &timeOut); | ||
|
||
// Tag 0x001 at time 0x00000123 three times | ||
timeIn = 0x00000123; | ||
tagIn = 0x001; | ||
commandIn = 0; | ||
profile_timer(&commandIn, &tagIn, &timeIn, &tagOut, &timeOut); | ||
profile_timer(&commandIn, &tagIn, &timeIn, &tagOut, &timeOut); | ||
profile_timer(&commandIn, &tagIn, &timeIn, &tagOut, &timeOut); | ||
|
||
for (int i = 0; i < 256; i++) { | ||
commandIn = i + 1; | ||
profile_timer(&commandIn, &tagIn, &timeIn, &tagOut, &timeOut); | ||
times[i].time = timeOut; | ||
times[i].tag = tagOut; | ||
} | ||
|
||
// Print out the times... | ||
for (int i = 0; i < 256; i++) { | ||
printf("%3d: 0x%03x = 0x%08x\n", i+1, times[i].tag, times[i].time); | ||
// if (times[i].tag == 0 && times[i].time == 0) | ||
// break; | ||
} | ||
|
||
return 0; | ||
} |