mirror of https://gerrit.osmocom.org/simtrace2
Timer counter functions, Makefile adjusted
This commit is contained in:
parent
4e4682c785
commit
531d10b403
|
@ -142,9 +142,9 @@ VPATH += src_board src_sam3s cmsis $(USB_PATHS) simtrace
|
|||
# Objects built from C source files
|
||||
C_CMSIS = core_cm3.o
|
||||
C_LOWLEVEL = board_cstartup_gnu.o board_lowlevel.o syscalls.o exceptions.o
|
||||
C_LIBLEVEL = spi.o pio.o pmc.o usart.o pio_it.o pio_capture.o uart_console.o iso7816_4.o wdt.o led.o
|
||||
C_LIBLEVEL = spi.o pio.o pmc.o usart.o pio_it.o pio_capture.o uart_console.o iso7816_4.o wdt.o led.o tc.o
|
||||
C_CCID = cciddriver.o USBD.o USBDDriver.o USBD_HAL.o USBRequests.o USBDCallbacks.o USBDescriptors.o USBDDriverCallbacks.o
|
||||
C_SIMTRACE = simtrace_iso7816.o usb.o ccid.o sniffer.o phone.o
|
||||
C_SIMTRACE = simtrace_iso7816.o usb.o ccid.o sniffer.o phone.o tc_etu.o
|
||||
C_APPLEVEL = main.o
|
||||
C_OBJECTS = $(C_CMSIS) $(C_LOWLEVEL) $(C_LIBLEVEL) $(C_APPLEVEL) $(C_CCID) $(C_SIMTRACE)
|
||||
|
||||
|
|
|
@ -59,4 +59,8 @@ extern void CCID_run( void );
|
|||
extern void Phone_run( void );
|
||||
extern void MITM_run( void );
|
||||
|
||||
/* Timer helper function */
|
||||
void Timer_Init( void );
|
||||
void TC0_Counter_Reset( void );
|
||||
|
||||
#endif /* SIMTRACE_H */
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
/* SimTrace TC (Timer / Clock) support code
|
||||
* (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Headers
|
||||
*------------------------------------------------------------------------------*/
|
||||
#include "board.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
//FIXME:
|
||||
static const Pin pTC[] = {PIO_PA4B_TCLK0, PIO_PA0B_TIOA0, PIO_PA1B_TIOB0};
|
||||
|
||||
/** Global timestamp in milliseconds since start of application */
|
||||
volatile uint32_t dwTimeStamp = 0;
|
||||
uint8_t timeout_occured = 0;
|
||||
|
||||
// FIXME: Do I need the function?:
|
||||
/**
|
||||
* \brief Handler for Sytem Tick interrupt.
|
||||
*
|
||||
* Process System Tick Event
|
||||
* Increments the timestamp counter.
|
||||
*/
|
||||
void SysTick_Handler( void )
|
||||
{
|
||||
dwTimeStamp ++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TC0_IrqHandler( void )
|
||||
{
|
||||
volatile uint32_t dummy;
|
||||
/* Clear status bit to acknowledge interrupt */
|
||||
dummy = TC0->TC_CHANNEL[ 0 ].TC_SR;
|
||||
|
||||
TRACE_DEBUG("++++ TC0_IrqHandler");
|
||||
timeout_occured++;
|
||||
}
|
||||
|
||||
|
||||
void TC0_Counter_Reset( void )
|
||||
{
|
||||
TC0->TC_CHANNEL[ 0 ].TC_CCR = TC_CCR_SWTRG ;
|
||||
}
|
||||
|
||||
/* == Timeouts ==
|
||||
* One symbol is about 2ms --> Timeout = BUFLEN * 2ms ?
|
||||
* For BUFLEN = 64 that is 7.8 Hz
|
||||
*/
|
||||
void Timer_Init()
|
||||
{
|
||||
uint32_t div;
|
||||
uint32_t tcclks;
|
||||
|
||||
/** Enable peripheral clock. */
|
||||
PMC_EnablePeripheral(ID_TC0);
|
||||
|
||||
/** Configure TC for a 8Hz frequency and trigger on RC compare. */
|
||||
TC_FindMckDivisor( 1, BOARD_MCK, &div, &tcclks, BOARD_MCK );
|
||||
TRACE_INFO("Chosen div, tcclk: %d, %d", div, tcclks);
|
||||
/* TC_CMR: TC Channel Mode Register: Capture Mode */
|
||||
/* CPCTRG: RC Compare resets the counter and starts the counter clock. */
|
||||
TC_Configure( TC0, 0, tcclks | TC_CMR_CPCTRG );
|
||||
/* TC_RC: TC Register C: contains the Register C value in real time. */
|
||||
TC0->TC_CHANNEL[ 0 ].TC_RC = ( BOARD_MCK / div ) / 4;
|
||||
|
||||
/* Configure and enable interrupt on RC compare */
|
||||
NVIC_EnableIRQ( (IRQn_Type)ID_TC0 );
|
||||
|
||||
TC0->TC_CHANNEL[ 0 ].TC_IER = TC_IER_CPCS; /* CPCS: RC Compare */
|
||||
TC_Start( TC0, 0 );
|
||||
|
||||
return;
|
||||
|
||||
/*** From here on we have code based on old simtrace code */
|
||||
|
||||
/* Cfg PA4(TCLK0), PA0(TIOA0), PA1(TIOB0) */
|
||||
|
||||
PIO_Configure( pTC, PIO_LISTSIZE( pTC ) );
|
||||
|
||||
|
||||
|
||||
// FIXME:
|
||||
// PIO_ConfigureIt( &pinPhoneRST, ISR_PhoneRST ) ;
|
||||
// PIO_EnableIt( &pinPhoneRST ) ;
|
||||
|
||||
/* enable interrupts for Compare-C and External Trigger */
|
||||
TC0->TC_CHANNEL[0].TC_IER = TC_IER_CPCS | TC_IER_ETRGS;
|
||||
|
||||
//...
|
||||
/* Enable master clock for TC0 */
|
||||
// TC0->TC_CHANNEL[0].TC_CCR
|
||||
|
||||
/* Reset to start timers */
|
||||
//...
|
||||
}
|
Loading…
Reference in New Issue