mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
Refactored auto-reset methods.
This commit is contained in:
parent
c5a346a509
commit
d4efbf730e
@ -19,6 +19,10 @@
|
||||
#include <Arduino.h>
|
||||
#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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Reset.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -59,6 +60,8 @@ void delayMicroseconds( uint32_t dwUs )
|
||||
*/
|
||||
void SysTick_Handler( void )
|
||||
{
|
||||
tickReset();
|
||||
|
||||
// Increment tick count each ms
|
||||
TimeTick_Increment() ;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user