Skip to content

Commit

Permalink
FIX: the underlaying bug on deviceside code. The SSPCLOCK wasn't rese…
Browse files Browse the repository at this point in the history
…t to zero sometimes. More specific, TC2 wasn't reset cause all sorts of timing issues for the device side randomly. Like 'hf mf mifare', like iclass, like 'hf mf sim' etc etc.
  • Loading branch information
iceman1001 committed Aug 24, 2016
1 parent a1ab594 commit 63a1d80
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions armsrc/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,9 @@ void StartCountSspClk() {
| AT91C_TC_WAVE // Waveform Mode
| AT91C_TC_WAVESEL_UP; // just count

AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN; // enable TC0
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN; // enable TC1
AT91C_BASE_TC2->TC_CCR = AT91C_TC_CLKEN; // enable TC2
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // enable and reset TC0
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // enable and reset TC1
AT91C_BASE_TC2->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // enable and reset TC2

// synchronize the counter with the ssp_frame signal.
// Note: FPGA must be in any iso14443 mode, otherwise the frame signal would not be present
Expand All @@ -420,7 +420,13 @@ void StartCountSspClk() {

// The high word of the counter (TC2) will not reset until the low word (TC0) overflows.
// Therefore need to wait quite some time before we can use the counter.
while (AT91C_BASE_TC0->TC_CV < 0xFFF0);
while (AT91C_BASE_TC2->TC_CV >= 1);
}
void ResetSspClk(void) {
//enable clock of timer and software trigger
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
AT91C_BASE_TC1->TC_CCR = AT91C_TC_SWTRG;
AT91C_BASE_TC2->TC_CCR = AT91C_TC_SWTRG;
}

uint32_t RAMFUNC GetCountSspClk(){
Expand Down

0 comments on commit 63a1d80

Please sign in to comment.