forked from ElTangas/jtag2updi
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathUPDI_hi_lvl.cpp
101 lines (90 loc) · 2.77 KB
/
UPDI_hi_lvl.cpp
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
/*
* UPDI_hi_lvl.cpp
*
* Created: 15-02-2018 23:08:39
* Author: JMR_2
*/
#include "UPDI_hi_lvl.h"
#include "dbg.h"
bool UPDI::CPU_reset(){
#if defined(DEBUG_RESET)
DBG::updi_reset();
#endif
// Request reset
UPDI::stcs(UPDI::reg::ASI_Reset_Request, UPDI::RESET_ON);
// Release reset (System remains in reset state until released)
UPDI::stcs(UPDI::reg::ASI_Reset_Request, UPDI::RESET_OFF);
// Wait for the reset process to end.
// Either NVMPROG, UROWPROG or BOOTDONE bit will be set in the ASI_SYS_STATUS UPDI register.
// This indicates reset is complete.
#ifndef DISABLE_TARGET_TIMEOUT
uint8_t timeoutcount=0;
while ( UPDI::CPU_mode<0x0E>() == 0 && timeoutcount<2) //if it takes 200ms to come back after we release reset... it's never going to!
{
if (SYS::checkTimeouts() & WAIT_FOR_TARGET) {
SYS::clearTimeouts();
timeoutcount++;
}
}
#else
while ( UPDI::CPU_mode<0x0E>() == 0 );
#endif
#if defined(DEBUG_RESET) && !defined(DEBUG_LDCS)
//if LDCS is defined, it will pick this up
#ifndef DISABLE_TARGET_TIMEOUT
if(timeoutcount) {
DBG::debug('T',timeoutcount);
}
#endif
DBG::updi_post_reset(UPDI::CPU_mode<0xFF>());
#endif
#ifndef DISABLE_TARGET_TIMEOUT
return (timeoutcount<2); //if we didn't timeout and give up trying to bring it out of reset, return true
#else
return 1;
#endif
}
void UPDI::CPU_reset_on(){
#if defined(DEBUG_RESET)
DBG::updi_reset_on();
#endif
// Request reset
UPDI::stcs(UPDI::reg::ASI_Reset_Request, UPDI::RESET_ON);
// System remains in reset state until released
}
bool UPDI::CPU_reset_off(){
#if defined(DEBUG_RESET)
DBG::updi_reset_off();
#endif
// Release reset (System remains in reset state until released)
UPDI::stcs(UPDI::reg::ASI_Reset_Request, UPDI::RESET_OFF);
// Wait for the reset process to end.
// Either NVMPROG, UROWPROG or BOOTDONE bit will be set in the ASI_SYS_STATUS UPDI register.
// This indicates reset is complete.
#ifndef DISABLE_TARGET_TIMEOUT
uint8_t timeoutcount=0;
while ( UPDI::CPU_mode<0x0E>() == 0 && timeoutcount<2) //if it takes 200ms to come back after we release reset... it's never going to!
{
if (SYS::checkTimeouts() & WAIT_FOR_TARGET) {
SYS::clearTimeouts();
timeoutcount++;
}
}
#else
while ( UPDI::CPU_mode<0x0E>() == 0 );
#endif
#if defined(DEBUG_RESET) && !defined(DEBUG_LDCS)
//if LDCS is defined, it will pick this up
#ifndef DISABLE_TARGET_TIMEOUT
if(timeoutcount) {
DBG::debug('T',timeoutcount);
}
#endif
DBG::updi_post_reset(UPDI::CPU_mode<0xFF>());
#endif
#ifndef DISABLE_TARGET_TIMEOUT
return (timeoutcount<2); //if we didn't timeout and give up trying to bring it out of reset, return true
#else
return 1;
#endif
}