-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.c
112 lines (99 loc) · 3.02 KB
/
error.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**@file error.c
*
* @date Nov 6, 2018
* @author Craig Hesling
*/
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/Types.h>
#include <xdc/runtime/Timestamp.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/family/arm/m3/Hwi.h>
#include <driverlib/cpu.h> // CPUcpsid
#include "io.h"
#include "error.h"
/**
* This function is referenced from @ref rtos.cfg as an exception hook function.
* It's role is to optionally reset the MCU if JTAG is not present.
*
* rtos.cfg:
* m3Hwi.enableException = true;
* m3Hwi.excHookFunc = "&ExceptionHandle";
* The m3Hwi.excHandlerFunc must be unset or
* set to Hwi.excHandlerMax or Hwi.excHandlerMin .
*
* Note that the after the call to this function BIOS_exit(0) is executed.
* So, the handlers for a bios exit must be considered also.
*
* See Hwi.xdc, Hwi.xs, and Hwi.c for more information.
* They are in the sysbios/family/arm/m3 directory
*
* @param excContext
*/
Void ExceptionHandle(Hwi_ExcContext *excContext) {
#ifdef RESET_ON_ERROR
if (!jtag_ispowered()) {
hardreset();
}
#endif
}
/**
* This function is called when BIOS_exit has been called.
* It's role is to optionally reset the MCU if JTAG is not present.
*
* This function should be registered in the rtos.cfg
* as System.exitFxn.
*
* @param stat The status code given to BIOS_exit or BIOS_abort
*/
Void ExitHandler(Int stat) {
#ifdef RESET_ON_ERROR
if (!jtag_ispowered()) {
hardreset();
}
#endif
// Disable CPU interrupts
CPUcpsid();
// Loop forever
for (;;) ;
}
/**
* This function is called when BIOS_abort (maybe System_abort("")) has been called.
* It's role is to optionally reset the MCU if JTAG is not present.
*
* This function be registered in the rtos.cfg
* as System.abortFxn .
*
*/
Void AbortHandler() {
ExitHandler(-1);
}
/**
* Get the current timestamp
* @param[out] time The
*/
void TimestampNow(Types_Timestamp64 *time) {
Timestamp_get64(time);
}
/**
* Return the number of nanoseconds between before and after timestamps
* If an overflow is reported, the output nanoseconds value should be considered incorrect.
*
*
* @param[out] nanoseconds The output number of nanoseconds
* @param[in] before The earlier time we should consider for the difference
* @param[in] after The later time we should consider for the difference
* @return True if no overflow occurred. False if an overflow occurred.
*/
bool TimestampDiffNs(uint64_t *nanoseconds, Types_Timestamp64 *before, Types_Timestamp64 *after) {
/// @note The overflow return value does not currently work.
/// @todo Implement the part by part multi and addition to check for overflows
Types_FreqHz freq;
Timestamp_getFreq(&freq);
uint64_t before64 = ((uint64_t)(before->hi))<<32 | ((uint64_t)(before->lo));
uint64_t after64 = ((uint64_t)(after->hi))<<32 | ((uint64_t)(after->lo));
uint64_t freq64 = ((uint64_t)(freq.hi))<<32 | ((uint64_t)(freq.lo));
*nanoseconds = ((after64-before64) * 1e9) / freq64;
return true;
}