From d4efbf730e726aabaa4df4d2e248420d3ca9dd25 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 11 Sep 2012 23:24:00 +0200 Subject: [PATCH] Refactored auto-reset methods. --- hardware/arduino/sam/cores/arduino/Reset.cpp | 16 ++++++++++++---- hardware/arduino/sam/cores/arduino/Reset.h | 19 ++++++++++--------- .../arduino/sam/cores/arduino/USB/CDC.cpp | 4 ++-- .../arduino/sam/cores/arduino/USB/USBCore.cpp | 14 ++++++-------- hardware/arduino/sam/cores/arduino/wiring.c | 9 ++++++--- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/hardware/arduino/sam/cores/arduino/Reset.cpp b/hardware/arduino/sam/cores/arduino/Reset.cpp index bae2a9227..6336427c6 100644 --- a/hardware/arduino/sam/cores/arduino/Reset.cpp +++ b/hardware/arduino/sam/cores/arduino/Reset.cpp @@ -19,6 +19,10 @@ #include #include "Reset.h" +#ifdef __cplusplus +extern "C" { +#endif + __attribute__ ((long_call, section (".ramfunc"))) void banzai() { // Disable all interrupts @@ -51,15 +55,17 @@ void banzai() { while (true); } -void ResetClass::initiate(int _ticks) { +static int ticks = -1; + +void initiateReset(int _ticks) { ticks = _ticks; } -void ResetClass::cancel() { +void cancelReset() { ticks = -1; } -void ResetClass::tick() { +void tickReset() { if (ticks == -1) return; ticks--; @@ -67,4 +73,6 @@ void ResetClass::tick() { banzai(); } -int ResetClass::ticks = -1; +#ifdef __cplusplus +} +#endif diff --git a/hardware/arduino/sam/cores/arduino/Reset.h b/hardware/arduino/sam/cores/arduino/Reset.h index 8d0e363cb..373f6d174 100644 --- a/hardware/arduino/sam/cores/arduino/Reset.h +++ b/hardware/arduino/sam/cores/arduino/Reset.h @@ -19,15 +19,16 @@ #ifndef RESET_H #define RESET_H -class ResetClass { -public: - static void initiate(int _ticks); - static void cancel(); - static void tick(); -private: - static int ticks; -}; +#ifdef __cplusplus +extern "C" { +#endif -extern ResetClass Reset; +void initiateReset(int ms); +void tickReset(); +void cancelReset(); + +#ifdef __cplusplus +} +#endif #endif diff --git a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp index 508c4d2dd..40714c9ab 100644 --- a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp @@ -134,9 +134,9 @@ bool WEAK CDC_Setup(Setup& setup) { // We check DTR state to determine if host port is open (bit 0 of lineState). if ((_usbLineInfo.lineState & 0x01) == 0) - Reset.initiate(240); + initiateReset(250); else - Reset.cancel(); + cancelReset(); } return true; } diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp index d993aefa6..3d1ebccfd 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp @@ -186,7 +186,7 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len) if (!_usbConfiguration) { - printf("pb conf\n\r"); + TRACE_CORE(printf("pb conf\n\r");) return -1; } @@ -472,8 +472,8 @@ static void Test_Mode_Support( uint8_t wIndex ) //patterns, jitter, and any other dynamic waveform specifications. //The test packet is made up by concatenating the following strings. //(Note: For J/K NRZI data, and for NRZ data, the bit on the left is the first one - //transmitted. “S” indicates that a bit stuff occurs, which inserts an “extra” NRZI data bit. - //“* N” is used to indicate N occurrences of a string of bits or symbols.) + //transmitted. "S" indicates that a bit stuff occurs, which inserts an "extra" NRZI data bit. + //"* N" is used to indicate N occurrences of a string of bits or symbols.) //A port in Test_Packet mode must send this packet repetitively. The inter-packet timing //must be no less than the minimum allowable inter-packet gap as defined in Section 7.1.18 and //no greater than 125 us. @@ -508,7 +508,7 @@ static void Test_Mode_Support( uint8_t wIndex ) case 1: //Test mode Test_J: - //Upon command, a port’s transceiver must enter the high-speed J state and remain in that + //Upon command, a port's transceiver must enter the high-speed J state and remain in that //state until the exit action is taken. This enables the testing of the high output drive //level on the D+ line. // Send a ZLP @@ -519,7 +519,7 @@ static void Test_Mode_Support( uint8_t wIndex ) case 2: //Test mode Test_K: - //Upon command, a port’s transceiver must enter the high-speed K state and remain in + //Upon command, a port's transceiver must enter the high-speed K state and remain in //that state until the exit action is taken. This enables the testing of the high output drive //level on the D- line. // Send a ZLP @@ -530,7 +530,7 @@ static void Test_Mode_Support( uint8_t wIndex ) case 3: //Test mode Test_SE0_NAK: - //Upon command, a port’s transceiver must enter the high-speed receive mode + //Upon command, a port's transceiver must enter the high-speed receive mode //and remain in that mode until the exit action is taken. This enables the testing //of output impedance, low level output voltage, and loading characteristics. //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 ) // Endpoint 0 interrupt static void USB_ISR(void) { - Reset.tick(); - // printf("ISR=0x%X\n\r", UOTGHS->UOTGHS_DEVISR); // jcb // if( iii++ > 1500 ) while(1); // jcb // End of bus reset diff --git a/hardware/arduino/sam/cores/arduino/wiring.c b/hardware/arduino/sam/cores/arduino/wiring.c index 93bbda5bb..5de053a1e 100644 --- a/hardware/arduino/sam/cores/arduino/wiring.c +++ b/hardware/arduino/sam/cores/arduino/wiring.c @@ -17,6 +17,7 @@ */ #include "Arduino.h" +#include "Reset.h" #ifdef __cplusplus extern "C" { @@ -46,7 +47,7 @@ void delay( uint32_t dwMs ) void delayMicroseconds( uint32_t dwUs ) { - uint32_t dwStartMicros=micros() ; + uint32_t dwStartMicros=micros() ; while ( (micros() - dwStartMicros) < dwUs ) { @@ -59,8 +60,10 @@ void delayMicroseconds( uint32_t dwUs ) */ void SysTick_Handler( void ) { - // Increment tick count each ms - TimeTick_Increment() ; + tickReset(); + + // Increment tick count each ms + TimeTick_Increment() ; } #if defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */