Skip to content

Commit d4efbf7

Browse files
committed
Refactored auto-reset methods.
1 parent c5a346a commit d4efbf7

File tree

5 files changed

+37
-27
lines changed

5 files changed

+37
-27
lines changed

hardware/arduino/sam/cores/arduino/Reset.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include <Arduino.h>
2020
#include "Reset.h"
2121

22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
2226
__attribute__ ((long_call, section (".ramfunc")))
2327
void banzai() {
2428
// Disable all interrupts
@@ -51,20 +55,24 @@ void banzai() {
5155
while (true);
5256
}
5357

54-
void ResetClass::initiate(int _ticks) {
58+
static int ticks = -1;
59+
60+
void initiateReset(int _ticks) {
5561
ticks = _ticks;
5662
}
5763

58-
void ResetClass::cancel() {
64+
void cancelReset() {
5965
ticks = -1;
6066
}
6167

62-
void ResetClass::tick() {
68+
void tickReset() {
6369
if (ticks == -1)
6470
return;
6571
ticks--;
6672
if (ticks == 0)
6773
banzai();
6874
}
6975

70-
int ResetClass::ticks = -1;
76+
#ifdef __cplusplus
77+
}
78+
#endif

hardware/arduino/sam/cores/arduino/Reset.h

+11-10
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@
1919
#ifndef RESET_H
2020
#define RESET_H
2121

22-
class ResetClass {
23-
public:
24-
static void initiate(int _ticks);
25-
static void cancel();
26-
static void tick();
27-
private:
28-
static int ticks;
29-
};
30-
31-
extern ResetClass Reset;
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
void initiateReset(int ms);
27+
void tickReset();
28+
void cancelReset();
29+
30+
#ifdef __cplusplus
31+
}
32+
#endif
3233

3334
#endif

hardware/arduino/sam/cores/arduino/USB/CDC.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ bool WEAK CDC_Setup(Setup& setup)
134134
{
135135
// We check DTR state to determine if host port is open (bit 0 of lineState).
136136
if ((_usbLineInfo.lineState & 0x01) == 0)
137-
Reset.initiate(240);
137+
initiateReset(250);
138138
else
139-
Reset.cancel();
139+
cancelReset();
140140
}
141141
return true;
142142
}

hardware/arduino/sam/cores/arduino/USB/USBCore.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len)
186186

187187
if (!_usbConfiguration)
188188
{
189-
printf("pb conf\n\r");
189+
TRACE_CORE(printf("pb conf\n\r");)
190190
return -1;
191191
}
192192

@@ -472,8 +472,8 @@ static void Test_Mode_Support( uint8_t wIndex )
472472
//patterns, jitter, and any other dynamic waveform specifications.
473473
//The test packet is made up by concatenating the following strings.
474474
//(Note: For J/K NRZI data, and for NRZ data, the bit on the left is the first one
475-
//transmitted. “S” indicates that a bit stuff occurs, which inserts an “extra” NRZI data bit.
476-
//“* N” is used to indicate N occurrences of a string of bits or symbols.)
475+
//transmitted. "S" indicates that a bit stuff occurs, which inserts an "extra" NRZI data bit.
476+
//"* N" is used to indicate N occurrences of a string of bits or symbols.)
477477
//A port in Test_Packet mode must send this packet repetitively. The inter-packet timing
478478
//must be no less than the minimum allowable inter-packet gap as defined in Section 7.1.18 and
479479
//no greater than 125 us.
@@ -508,7 +508,7 @@ static void Test_Mode_Support( uint8_t wIndex )
508508

509509
case 1:
510510
//Test mode Test_J:
511-
//Upon command, a port’s transceiver must enter the high-speed J state and remain in that
511+
//Upon command, a port's transceiver must enter the high-speed J state and remain in that
512512
//state until the exit action is taken. This enables the testing of the high output drive
513513
//level on the D+ line.
514514
// Send a ZLP
@@ -519,7 +519,7 @@ static void Test_Mode_Support( uint8_t wIndex )
519519

520520
case 2:
521521
//Test mode Test_K:
522-
//Upon command, a port’s transceiver must enter the high-speed K state and remain in
522+
//Upon command, a port's transceiver must enter the high-speed K state and remain in
523523
//that state until the exit action is taken. This enables the testing of the high output drive
524524
//level on the D- line.
525525
// Send a ZLP
@@ -530,7 +530,7 @@ static void Test_Mode_Support( uint8_t wIndex )
530530

531531
case 3:
532532
//Test mode Test_SE0_NAK:
533-
//Upon command, a port’s transceiver must enter the high-speed receive mode
533+
//Upon command, a port's transceiver must enter the high-speed receive mode
534534
//and remain in that mode until the exit action is taken. This enables the testing
535535
//of output impedance, low level output voltage, and loading characteristics.
536536
//In addition, while in this mode, upstream facing ports (and only upstream facing ports)
@@ -571,8 +571,6 @@ static void Test_Mode_Support( uint8_t wIndex )
571571
// Endpoint 0 interrupt
572572
static void USB_ISR(void)
573573
{
574-
Reset.tick();
575-
576574
// printf("ISR=0x%X\n\r", UOTGHS->UOTGHS_DEVISR); // jcb
577575
// if( iii++ > 1500 ) while(1); // jcb
578576
// End of bus reset

hardware/arduino/sam/cores/arduino/wiring.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include "Arduino.h"
20+
#include "Reset.h"
2021

2122
#ifdef __cplusplus
2223
extern "C" {
@@ -46,7 +47,7 @@ void delay( uint32_t dwMs )
4647

4748
void delayMicroseconds( uint32_t dwUs )
4849
{
49-
uint32_t dwStartMicros=micros() ;
50+
uint32_t dwStartMicros=micros() ;
5051

5152
while ( (micros() - dwStartMicros) < dwUs )
5253
{
@@ -59,8 +60,10 @@ void delayMicroseconds( uint32_t dwUs )
5960
*/
6061
void SysTick_Handler( void )
6162
{
62-
// Increment tick count each ms
63-
TimeTick_Increment() ;
63+
tickReset();
64+
65+
// Increment tick count each ms
66+
TimeTick_Increment() ;
6467
}
6568

6669
#if defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */

0 commit comments

Comments
 (0)