1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-06 01:08:25 +01:00

Refactored auto-reset methods.

This commit is contained in:
Cristian Maglie 2012-09-11 23:24:00 +02:00
parent c5a346a509
commit d4efbf730e
5 changed files with 36 additions and 26 deletions

View File

@ -19,6 +19,10 @@
#include <Arduino.h> #include <Arduino.h>
#include "Reset.h" #include "Reset.h"
#ifdef __cplusplus
extern "C" {
#endif
__attribute__ ((long_call, section (".ramfunc"))) __attribute__ ((long_call, section (".ramfunc")))
void banzai() { void banzai() {
// Disable all interrupts // Disable all interrupts
@ -51,15 +55,17 @@ void banzai() {
while (true); while (true);
} }
void ResetClass::initiate(int _ticks) { static int ticks = -1;
void initiateReset(int _ticks) {
ticks = _ticks; ticks = _ticks;
} }
void ResetClass::cancel() { void cancelReset() {
ticks = -1; ticks = -1;
} }
void ResetClass::tick() { void tickReset() {
if (ticks == -1) if (ticks == -1)
return; return;
ticks--; ticks--;
@ -67,4 +73,6 @@ void ResetClass::tick() {
banzai(); banzai();
} }
int ResetClass::ticks = -1; #ifdef __cplusplus
}
#endif

View File

@ -19,15 +19,16 @@
#ifndef RESET_H #ifndef RESET_H
#define RESET_H #define RESET_H
class ResetClass { #ifdef __cplusplus
public: extern "C" {
static void initiate(int _ticks); #endif
static void cancel();
static void tick();
private:
static int ticks;
};
extern ResetClass Reset; void initiateReset(int ms);
void tickReset();
void cancelReset();
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -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). // We check DTR state to determine if host port is open (bit 0 of lineState).
if ((_usbLineInfo.lineState & 0x01) == 0) if ((_usbLineInfo.lineState & 0x01) == 0)
Reset.initiate(240); initiateReset(250);
else else
Reset.cancel(); cancelReset();
} }
return true; return true;
} }

View File

@ -186,7 +186,7 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len)
if (!_usbConfiguration) if (!_usbConfiguration)
{ {
printf("pb conf\n\r"); TRACE_CORE(printf("pb conf\n\r");)
return -1; return -1;
} }
@ -472,8 +472,8 @@ static void Test_Mode_Support( uint8_t wIndex )
//patterns, jitter, and any other dynamic waveform specifications. //patterns, jitter, and any other dynamic waveform specifications.
//The test packet is made up by concatenating the following strings. //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 //(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. //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.) //"* 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 //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 //must be no less than the minimum allowable inter-packet gap as defined in Section 7.1.18 and
//no greater than 125 us. //no greater than 125 us.
@ -508,7 +508,7 @@ static void Test_Mode_Support( uint8_t wIndex )
case 1: case 1:
//Test mode Test_J: //Test mode Test_J:
//Upon command, a ports 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 //state until the exit action is taken. This enables the testing of the high output drive
//level on the D+ line. //level on the D+ line.
// Send a ZLP // Send a ZLP
@ -519,7 +519,7 @@ static void Test_Mode_Support( uint8_t wIndex )
case 2: case 2:
//Test mode Test_K: //Test mode Test_K:
//Upon command, a ports 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 //that state until the exit action is taken. This enables the testing of the high output drive
//level on the D- line. //level on the D- line.
// Send a ZLP // Send a ZLP
@ -530,7 +530,7 @@ static void Test_Mode_Support( uint8_t wIndex )
case 3: case 3:
//Test mode Test_SE0_NAK: //Test mode Test_SE0_NAK:
//Upon command, a ports 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 //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. //of output impedance, low level output voltage, and loading characteristics.
//In addition, while in this mode, upstream facing ports (and only upstream facing ports) //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 // Endpoint 0 interrupt
static void USB_ISR(void) static void USB_ISR(void)
{ {
Reset.tick();
// printf("ISR=0x%X\n\r", UOTGHS->UOTGHS_DEVISR); // jcb // printf("ISR=0x%X\n\r", UOTGHS->UOTGHS_DEVISR); // jcb
// if( iii++ > 1500 ) while(1); // jcb // if( iii++ > 1500 ) while(1); // jcb
// End of bus reset // End of bus reset

View File

@ -17,6 +17,7 @@
*/ */
#include "Arduino.h" #include "Arduino.h"
#include "Reset.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -59,6 +60,8 @@ void delayMicroseconds( uint32_t dwUs )
*/ */
void SysTick_Handler( void ) void SysTick_Handler( void )
{ {
tickReset();
// Increment tick count each ms // Increment tick count each ms
TimeTick_Increment() ; TimeTick_Increment() ;
} }