mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-16 21:28:33 +03:00
replace leading spaces with tabs
Change-Id: I86783eba0827b58303b10310e9f6b9625e1a27f1
This commit is contained in:
@@ -152,7 +152,7 @@ extern int main(void)
|
|||||||
|
|
||||||
EEFC_ReadUniqueID(g_unique_id);
|
EEFC_ReadUniqueID(g_unique_id);
|
||||||
|
|
||||||
printf("\n\r\n\r"
|
printf("\n\r\n\r"
|
||||||
"=============================================================================\n\r"
|
"=============================================================================\n\r"
|
||||||
"SIMtrace2 firmware " GIT_VERSION " (C) 2010-2016 by Harald Welte\n\r"
|
"SIMtrace2 firmware " GIT_VERSION " (C) 2010-2016 by Harald Welte\n\r"
|
||||||
"=============================================================================\n\r");
|
"=============================================================================\n\r");
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ extern int main(void)
|
|||||||
|
|
||||||
EEFC_ReadUniqueID(g_unique_id);
|
EEFC_ReadUniqueID(g_unique_id);
|
||||||
|
|
||||||
printf("\n\r\n\r"
|
printf("\n\r\n\r"
|
||||||
"=============================================================================\n\r"
|
"=============================================================================\n\r"
|
||||||
"SIMtrace2 firmware " GIT_VERSION " (C) 2010-2016 by Harald Welte\n\r"
|
"SIMtrace2 firmware " GIT_VERSION " (C) 2010-2016 by Harald Welte\n\r"
|
||||||
"=============================================================================\n\r");
|
"=============================================================================\n\r");
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ extern int main(void)
|
|||||||
|
|
||||||
EEFC_ReadUniqueID(g_unique_id);
|
EEFC_ReadUniqueID(g_unique_id);
|
||||||
|
|
||||||
printf("\r\n\r\n"
|
printf("\r\n\r\n"
|
||||||
"=============================================================================\r\n"
|
"=============================================================================\r\n"
|
||||||
"SIMtrace2 firmware " GIT_REVISION " (C) 2010-2017 by Harald Welte\r\n"
|
"SIMtrace2 firmware " GIT_REVISION " (C) 2010-2017 by Harald Welte\r\n"
|
||||||
"=============================================================================\r\n");
|
"=============================================================================\r\n");
|
||||||
|
|||||||
@@ -71,59 +71,59 @@ void ResetException( void ) ;
|
|||||||
__attribute__((section(".vectors")))
|
__attribute__((section(".vectors")))
|
||||||
IntFunc exception_table[] = {
|
IntFunc exception_table[] = {
|
||||||
|
|
||||||
/* Configure Initial Stack Pointer, using linker-generated symbols */
|
/* Configure Initial Stack Pointer, using linker-generated symbols */
|
||||||
(IntFunc)(&pdwStack[STACK_SIZE-1]),
|
(IntFunc)(&pdwStack[STACK_SIZE-1]),
|
||||||
ResetException,
|
ResetException,
|
||||||
|
|
||||||
NMI_Handler,
|
NMI_Handler,
|
||||||
HardFault_Handler,
|
HardFault_Handler,
|
||||||
MemManage_Handler,
|
MemManage_Handler,
|
||||||
BusFault_Handler,
|
BusFault_Handler,
|
||||||
UsageFault_Handler,
|
UsageFault_Handler,
|
||||||
0, 0, 0, 0, /* Reserved */
|
0, 0, 0, 0, /* Reserved */
|
||||||
SVC_Handler,
|
SVC_Handler,
|
||||||
DebugMon_Handler,
|
DebugMon_Handler,
|
||||||
0, /* Reserved */
|
0, /* Reserved */
|
||||||
PendSV_Handler,
|
PendSV_Handler,
|
||||||
SysTick_Handler,
|
SysTick_Handler,
|
||||||
|
|
||||||
/* Configurable interrupts */
|
/* Configurable interrupts */
|
||||||
SUPC_IrqHandler, /* 0 Supply Controller */
|
SUPC_IrqHandler, /* 0 Supply Controller */
|
||||||
RSTC_IrqHandler, /* 1 Reset Controller */
|
RSTC_IrqHandler, /* 1 Reset Controller */
|
||||||
RTC_IrqHandler, /* 2 Real Time Clock */
|
RTC_IrqHandler, /* 2 Real Time Clock */
|
||||||
RTT_IrqHandler, /* 3 Real Time Timer */
|
RTT_IrqHandler, /* 3 Real Time Timer */
|
||||||
WDT_IrqHandler, /* 4 Watchdog Timer */
|
WDT_IrqHandler, /* 4 Watchdog Timer */
|
||||||
PMC_IrqHandler, /* 5 PMC */
|
PMC_IrqHandler, /* 5 PMC */
|
||||||
EEFC_IrqHandler, /* 6 EEFC */
|
EEFC_IrqHandler, /* 6 EEFC */
|
||||||
IrqHandlerNotUsed, /* 7 Reserved */
|
IrqHandlerNotUsed, /* 7 Reserved */
|
||||||
UART0_IrqHandler, /* 8 UART0 */
|
UART0_IrqHandler, /* 8 UART0 */
|
||||||
UART1_IrqHandler, /* 9 UART1 */
|
UART1_IrqHandler, /* 9 UART1 */
|
||||||
SMC_IrqHandler, /* 10 SMC */
|
SMC_IrqHandler, /* 10 SMC */
|
||||||
PIOA_IrqHandler, /* 11 Parallel IO Controller A */
|
PIOA_IrqHandler, /* 11 Parallel IO Controller A */
|
||||||
PIOB_IrqHandler, /* 12 Parallel IO Controller B */
|
PIOB_IrqHandler, /* 12 Parallel IO Controller B */
|
||||||
PIOC_IrqHandler, /* 13 Parallel IO Controller C */
|
PIOC_IrqHandler, /* 13 Parallel IO Controller C */
|
||||||
USART0_IrqHandler, /* 14 USART 0 */
|
USART0_IrqHandler, /* 14 USART 0 */
|
||||||
USART1_IrqHandler, /* 15 USART 1 */
|
USART1_IrqHandler, /* 15 USART 1 */
|
||||||
IrqHandlerNotUsed, /* 16 Reserved */
|
IrqHandlerNotUsed, /* 16 Reserved */
|
||||||
IrqHandlerNotUsed, /* 17 Reserved */
|
IrqHandlerNotUsed, /* 17 Reserved */
|
||||||
MCI_IrqHandler, /* 18 MCI */
|
MCI_IrqHandler, /* 18 MCI */
|
||||||
TWI0_IrqHandler, /* 19 TWI 0 */
|
TWI0_IrqHandler, /* 19 TWI 0 */
|
||||||
TWI1_IrqHandler, /* 20 TWI 1 */
|
TWI1_IrqHandler, /* 20 TWI 1 */
|
||||||
SPI_IrqHandler, /* 21 SPI */
|
SPI_IrqHandler, /* 21 SPI */
|
||||||
SSC_IrqHandler, /* 22 SSC */
|
SSC_IrqHandler, /* 22 SSC */
|
||||||
TC0_IrqHandler, /* 23 Timer Counter 0 */
|
TC0_IrqHandler, /* 23 Timer Counter 0 */
|
||||||
TC1_IrqHandler, /* 24 Timer Counter 1 */
|
TC1_IrqHandler, /* 24 Timer Counter 1 */
|
||||||
TC2_IrqHandler, /* 25 Timer Counter 2 */
|
TC2_IrqHandler, /* 25 Timer Counter 2 */
|
||||||
TC3_IrqHandler, /* 26 Timer Counter 3 */
|
TC3_IrqHandler, /* 26 Timer Counter 3 */
|
||||||
TC4_IrqHandler, /* 27 Timer Counter 4 */
|
TC4_IrqHandler, /* 27 Timer Counter 4 */
|
||||||
TC5_IrqHandler, /* 28 Timer Counter 5 */
|
TC5_IrqHandler, /* 28 Timer Counter 5 */
|
||||||
ADC_IrqHandler, /* 29 ADC controller */
|
ADC_IrqHandler, /* 29 ADC controller */
|
||||||
DAC_IrqHandler, /* 30 DAC controller */
|
DAC_IrqHandler, /* 30 DAC controller */
|
||||||
PWM_IrqHandler, /* 31 PWM */
|
PWM_IrqHandler, /* 31 PWM */
|
||||||
CRCCU_IrqHandler, /* 32 CRC Calculation Unit */
|
CRCCU_IrqHandler, /* 32 CRC Calculation Unit */
|
||||||
ACC_IrqHandler, /* 33 Analog Comparator */
|
ACC_IrqHandler, /* 33 Analog Comparator */
|
||||||
USBD_IrqHandler, /* 34 USB Device Port */
|
USBD_IrqHandler, /* 34 USB Device Port */
|
||||||
IrqHandlerNotUsed /* 35 not used */
|
IrqHandlerNotUsed /* 35 not used */
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(BOARD_USB_DFU) && defined(APPLICATION_dfu)
|
#if defined(BOARD_USB_DFU) && defined(APPLICATION_dfu)
|
||||||
@@ -153,56 +153,56 @@ static void BootIntoApp(void)
|
|||||||
*/
|
*/
|
||||||
void ResetException( void )
|
void ResetException( void )
|
||||||
{
|
{
|
||||||
uint32_t *pSrc, *pDest ;
|
uint32_t *pSrc, *pDest ;
|
||||||
|
|
||||||
/* Low level Initialize */
|
/* Low level Initialize */
|
||||||
LowLevelInit() ;
|
LowLevelInit() ;
|
||||||
|
|
||||||
|
|
||||||
#if defined(BOARD_USB_DFU) && defined(APPLICATION_dfu)
|
#if defined(BOARD_USB_DFU) && defined(APPLICATION_dfu)
|
||||||
if (!USBDFU_OverrideEnterDFU()) {
|
if (!USBDFU_OverrideEnterDFU()) {
|
||||||
UART_Exit();
|
UART_Exit();
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
BootIntoApp();
|
BootIntoApp();
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
while ( 1 ) ;
|
while ( 1 ) ;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Initialize the relocate segment */
|
/* Initialize the relocate segment */
|
||||||
pSrc = &_etext ;
|
pSrc = &_etext ;
|
||||||
pDest = &_srelocate ;
|
pDest = &_srelocate ;
|
||||||
|
|
||||||
if ( pSrc != pDest )
|
if ( pSrc != pDest )
|
||||||
{
|
{
|
||||||
for ( ; pDest < &_erelocate ; )
|
for ( ; pDest < &_erelocate ; )
|
||||||
{
|
{
|
||||||
*pDest++ = *pSrc++ ;
|
*pDest++ = *pSrc++ ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear the zero segment */
|
/* Clear the zero segment */
|
||||||
for ( pDest = &_szero ; pDest < &_ezero ; )
|
for ( pDest = &_szero ; pDest < &_ezero ; )
|
||||||
{
|
{
|
||||||
*pDest++ = 0;
|
*pDest++ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the vector table base address */
|
/* Set the vector table base address */
|
||||||
pSrc = (uint32_t *)&_sfixed;
|
pSrc = (uint32_t *)&_sfixed;
|
||||||
SCB->VTOR = ( (uint32_t)pSrc & SCB_VTOR_TBLOFF_Msk ) ;
|
SCB->VTOR = ( (uint32_t)pSrc & SCB_VTOR_TBLOFF_Msk ) ;
|
||||||
|
|
||||||
if ( ((uint32_t)pSrc >= IRAM_ADDR) && ((uint32_t)pSrc < IRAM_ADDR+IRAM_SIZE) )
|
if ( ((uint32_t)pSrc >= IRAM_ADDR) && ((uint32_t)pSrc < IRAM_ADDR+IRAM_SIZE) )
|
||||||
{
|
{
|
||||||
SCB->VTOR |= 1 << SCB_VTOR_TBLBASE_Pos ;
|
SCB->VTOR |= 1 << SCB_VTOR_TBLBASE_Pos ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* App should have disabled interrupts during the transition */
|
/* App should have disabled interrupts during the transition */
|
||||||
__enable_irq();
|
__enable_irq();
|
||||||
|
|
||||||
/* Branch to main function */
|
/* Branch to main function */
|
||||||
main() ;
|
main() ;
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
while ( 1 ) ;
|
while ( 1 ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,15 +50,15 @@
|
|||||||
#if (BOARD_MAINOSC == 18432000)
|
#if (BOARD_MAINOSC == 18432000)
|
||||||
/* Clock settings at 48MHz for 18 MHz crystal */
|
/* Clock settings at 48MHz for 18 MHz crystal */
|
||||||
#define BOARD_PLLAR (CKGR_PLLAR_STUCKTO1 \
|
#define BOARD_PLLAR (CKGR_PLLAR_STUCKTO1 \
|
||||||
| CKGR_PLLAR_MULA(13-1) \
|
| CKGR_PLLAR_MULA(13-1) \
|
||||||
| CKGR_PLLAR_PLLACOUNT(0x1) \
|
| CKGR_PLLAR_PLLACOUNT(0x1) \
|
||||||
| CKGR_PLLAR_DIVA(5))
|
| CKGR_PLLAR_DIVA(5))
|
||||||
#elif (BOARD_MAINOSC == 12000000)
|
#elif (BOARD_MAINOSC == 12000000)
|
||||||
/* QMod has 12 MHz clock, so multply by 8 (96 MHz) and divide by 2 */
|
/* QMod has 12 MHz clock, so multply by 8 (96 MHz) and divide by 2 */
|
||||||
#define BOARD_PLLAR (CKGR_PLLAR_STUCKTO1 \
|
#define BOARD_PLLAR (CKGR_PLLAR_STUCKTO1 \
|
||||||
| CKGR_PLLAR_MULA(8-1) \
|
| CKGR_PLLAR_MULA(8-1) \
|
||||||
| CKGR_PLLAR_PLLACOUNT(0x1) \
|
| CKGR_PLLAR_PLLACOUNT(0x1) \
|
||||||
| CKGR_PLLAR_DIVA(2))
|
| CKGR_PLLAR_DIVA(2))
|
||||||
#else
|
#else
|
||||||
#error "Please define PLLA config for your MAINOSC frequency"
|
#error "Please define PLLA config for your MAINOSC frequency"
|
||||||
#endif /* MAINOSC */
|
#endif /* MAINOSC */
|
||||||
@@ -66,19 +66,19 @@
|
|||||||
#if (BOARD_MAINOSC == 18432000)
|
#if (BOARD_MAINOSC == 18432000)
|
||||||
/* Clock settings at 64MHz for 18 MHz crystal: 64.512 MHz */
|
/* Clock settings at 64MHz for 18 MHz crystal: 64.512 MHz */
|
||||||
#define BOARD_PLLAR (CKGR_PLLAR_STUCKTO1 \
|
#define BOARD_PLLAR (CKGR_PLLAR_STUCKTO1 \
|
||||||
| CKGR_PLLAR_MULA(7-1) \
|
| CKGR_PLLAR_MULA(7-1) \
|
||||||
| CKGR_PLLAR_PLLACOUNT(0x1) \
|
| CKGR_PLLAR_PLLACOUNT(0x1) \
|
||||||
| CKGR_PLLAR_DIVA(2))
|
| CKGR_PLLAR_DIVA(2))
|
||||||
#elif (BOARD_MAINOSC == 12000000)
|
#elif (BOARD_MAINOSC == 12000000)
|
||||||
/* QMod has 12 MHz clock, so multply by 10 / div by 2: 60 MHz */
|
/* QMod has 12 MHz clock, so multply by 10 / div by 2: 60 MHz */
|
||||||
#define BOARD_PLLAR (CKGR_PLLAR_STUCKTO1 \
|
#define BOARD_PLLAR (CKGR_PLLAR_STUCKTO1 \
|
||||||
| CKGR_PLLAR_MULA(10-1) \
|
| CKGR_PLLAR_MULA(10-1) \
|
||||||
| CKGR_PLLAR_PLLACOUNT(0x1) \
|
| CKGR_PLLAR_PLLACOUNT(0x1) \
|
||||||
| CKGR_PLLAR_DIVA(2))
|
| CKGR_PLLAR_DIVA(2))
|
||||||
#error "Please define PLLA config for your MAINOSC frequency"
|
#error "Please define PLLA config for your MAINOSC frequency"
|
||||||
#endif /* MAINOSC */
|
#endif /* MAINOSC */
|
||||||
#else
|
#else
|
||||||
#error "No PLL settings for current BOARD_MCK."
|
#error "No PLL settings for current BOARD_MCK."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (BOARD_MAINOSC == 12000000)
|
#if (BOARD_MAINOSC == 12000000)
|
||||||
@@ -117,85 +117,85 @@ static void _ConfigureUsbClock(void)
|
|||||||
*/
|
*/
|
||||||
extern WEAK void LowLevelInit( void )
|
extern WEAK void LowLevelInit( void )
|
||||||
{
|
{
|
||||||
uint32_t timeout = 0;
|
uint32_t timeout = 0;
|
||||||
|
|
||||||
/* Configure the Supply Monitor to reset the CPU in case VDDIO is
|
/* Configure the Supply Monitor to reset the CPU in case VDDIO is
|
||||||
* lower than 3.0V. As we run the board on 3.3V, any lower voltage
|
* lower than 3.0V. As we run the board on 3.3V, any lower voltage
|
||||||
* might be some kind of leakage that creeps in some way, but is not
|
* might be some kind of leakage that creeps in some way, but is not
|
||||||
* the "official" power supply */
|
* the "official" power supply */
|
||||||
SUPC->SUPC_SMMR = SUPC_SMMR_SMTH_3_0V | SUPC_SMMR_SMSMPL_CSM |
|
SUPC->SUPC_SMMR = SUPC_SMMR_SMTH_3_0V | SUPC_SMMR_SMSMPL_CSM |
|
||||||
SUPC_SMMR_SMRSTEN_ENABLE;
|
SUPC_SMMR_SMRSTEN_ENABLE;
|
||||||
|
|
||||||
/* enable both LED and green LED */
|
/* enable both LED and green LED */
|
||||||
PIOA->PIO_PER |= PIO_LED_RED | PIO_LED_GREEN;
|
PIOA->PIO_PER |= PIO_LED_RED | PIO_LED_GREEN;
|
||||||
PIOA->PIO_OER |= PIO_LED_RED | PIO_LED_GREEN;
|
PIOA->PIO_OER |= PIO_LED_RED | PIO_LED_GREEN;
|
||||||
PIOA->PIO_CODR |= PIO_LED_RED | PIO_LED_GREEN;
|
PIOA->PIO_CODR |= PIO_LED_RED | PIO_LED_GREEN;
|
||||||
|
|
||||||
/* Set 3 FWS for Embedded Flash Access */
|
/* Set 3 FWS for Embedded Flash Access */
|
||||||
EFC->EEFC_FMR = EEFC_FMR_FWS(3);
|
EFC->EEFC_FMR = EEFC_FMR_FWS(3);
|
||||||
|
|
||||||
/* Select external slow clock */
|
/* Select external slow clock */
|
||||||
/* if ((SUPC->SUPC_SR & SUPC_SR_OSCSEL) != SUPC_SR_OSCSEL_CRYST)
|
/* if ((SUPC->SUPC_SR & SUPC_SR_OSCSEL) != SUPC_SR_OSCSEL_CRYST)
|
||||||
{
|
{
|
||||||
SUPC->SUPC_CR = (uint32_t)(SUPC_CR_XTALSEL_CRYSTAL_SEL | SUPC_CR_KEY(0xA5));
|
SUPC->SUPC_CR = (uint32_t)(SUPC_CR_XTALSEL_CRYSTAL_SEL | SUPC_CR_KEY(0xA5));
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
while (!(SUPC->SUPC_SR & SUPC_SR_OSCSEL_CRYST) );
|
while (!(SUPC->SUPC_SR & SUPC_SR_OSCSEL_CRYST) );
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef qmod
|
#ifndef qmod
|
||||||
/* Initialize main oscillator */
|
/* Initialize main oscillator */
|
||||||
if ( !(PMC->CKGR_MOR & CKGR_MOR_MOSCSEL) )
|
if ( !(PMC->CKGR_MOR & CKGR_MOR_MOSCSEL) )
|
||||||
{
|
{
|
||||||
PMC->CKGR_MOR = CKGR_MOR_KEY(0x37) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN;
|
PMC->CKGR_MOR = CKGR_MOR_KEY(0x37) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN;
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
while (!(PMC->PMC_SR & PMC_SR_MOSCXTS) && (timeout++ < CLOCK_TIMEOUT));
|
while (!(PMC->PMC_SR & PMC_SR_MOSCXTS) && (timeout++ < CLOCK_TIMEOUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Switch to 3-20MHz Xtal oscillator */
|
/* Switch to 3-20MHz Xtal oscillator */
|
||||||
PIOB->PIO_PDR = (1 << 8) | (1 << 9);
|
PIOB->PIO_PDR = (1 << 8) | (1 << 9);
|
||||||
PIOB->PIO_PUDR = (1 << 8) | (1 << 9);
|
PIOB->PIO_PUDR = (1 << 8) | (1 << 9);
|
||||||
PIOB->PIO_PPDDR = (1 << 8) | (1 << 9);
|
PIOB->PIO_PPDDR = (1 << 8) | (1 << 9);
|
||||||
PMC->CKGR_MOR = CKGR_MOR_KEY(0x37) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN | CKGR_MOR_MOSCSEL;
|
PMC->CKGR_MOR = CKGR_MOR_KEY(0x37) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN | CKGR_MOR_MOSCSEL;
|
||||||
/* wait for Main XTAL oscillator stabilization */
|
/* wait for Main XTAL oscillator stabilization */
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
while (!(PMC->PMC_SR & PMC_SR_MOSCSELS) && (timeout++ < CLOCK_TIMEOUT));
|
while (!(PMC->PMC_SR & PMC_SR_MOSCSELS) && (timeout++ < CLOCK_TIMEOUT));
|
||||||
#else
|
#else
|
||||||
/* QMOD has external 12MHz clock source */
|
/* QMOD has external 12MHz clock source */
|
||||||
PIOB->PIO_PDR = (1 << 9);
|
PIOB->PIO_PDR = (1 << 9);
|
||||||
PIOB->PIO_PUDR = (1 << 9);
|
PIOB->PIO_PUDR = (1 << 9);
|
||||||
PIOB->PIO_PPDDR = (1 << 9);
|
PIOB->PIO_PPDDR = (1 << 9);
|
||||||
PMC->CKGR_MOR = CKGR_MOR_KEY(0x37) | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTBY| CKGR_MOR_MOSCSEL;
|
PMC->CKGR_MOR = CKGR_MOR_KEY(0x37) | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTBY| CKGR_MOR_MOSCSEL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* disable the red LED after main clock initialization */
|
/* disable the red LED after main clock initialization */
|
||||||
PIOA->PIO_SODR = PIO_LED_RED;
|
PIOA->PIO_SODR = PIO_LED_RED;
|
||||||
|
|
||||||
/* "switch" to main clock as master clock source (should already be the case */
|
/* "switch" to main clock as master clock source (should already be the case */
|
||||||
PMC->PMC_MCKR = (PMC->PMC_MCKR & ~(uint32_t)PMC_MCKR_CSS_Msk) | PMC_MCKR_CSS_MAIN_CLK;
|
PMC->PMC_MCKR = (PMC->PMC_MCKR & ~(uint32_t)PMC_MCKR_CSS_Msk) | PMC_MCKR_CSS_MAIN_CLK;
|
||||||
/* wait for master clock to be ready */
|
/* wait for master clock to be ready */
|
||||||
for ( timeout = 0; !(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT) ; );
|
for ( timeout = 0; !(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT) ; );
|
||||||
|
|
||||||
/* Initialize PLLA */
|
/* Initialize PLLA */
|
||||||
PMC->CKGR_PLLAR = BOARD_PLLAR;
|
PMC->CKGR_PLLAR = BOARD_PLLAR;
|
||||||
/* Wait for PLLA to lock */
|
/* Wait for PLLA to lock */
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
while (!(PMC->PMC_SR & PMC_SR_LOCKA) && (timeout++ < CLOCK_TIMEOUT));
|
while (!(PMC->PMC_SR & PMC_SR_LOCKA) && (timeout++ < CLOCK_TIMEOUT));
|
||||||
|
|
||||||
/* Switch to main clock (again ?!?) */
|
/* Switch to main clock (again ?!?) */
|
||||||
PMC->PMC_MCKR = (BOARD_MCKR & ~PMC_MCKR_CSS_Msk) | PMC_MCKR_CSS_MAIN_CLK;
|
PMC->PMC_MCKR = (BOARD_MCKR & ~PMC_MCKR_CSS_Msk) | PMC_MCKR_CSS_MAIN_CLK;
|
||||||
/* wait for master clock to be ready */
|
/* wait for master clock to be ready */
|
||||||
for ( timeout = 0; !(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT) ; );
|
for ( timeout = 0; !(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT) ; );
|
||||||
|
|
||||||
/* switch to PLLA as master clock source */
|
/* switch to PLLA as master clock source */
|
||||||
PMC->PMC_MCKR = BOARD_MCKR ;
|
PMC->PMC_MCKR = BOARD_MCKR ;
|
||||||
/* wait for master clock to be ready */
|
/* wait for master clock to be ready */
|
||||||
for ( timeout = 0; !(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT) ; );
|
for ( timeout = 0; !(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT) ; );
|
||||||
|
|
||||||
/* Configure SysTick for 1ms */
|
/* Configure SysTick for 1ms */
|
||||||
SysTick_Config(BOARD_MCK/1000);
|
SysTick_Config(BOARD_MCK/1000);
|
||||||
|
|
||||||
_ConfigureUsbClock();
|
_ConfigureUsbClock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SysTick based delay function */
|
/* SysTick based delay function */
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ static void led_set(enum led led, int on)
|
|||||||
ASSERT(led < PIO_LISTSIZE(pinsLeds));
|
ASSERT(led < PIO_LISTSIZE(pinsLeds));
|
||||||
|
|
||||||
if (on)
|
if (on)
|
||||||
PIO_Clear(&pinsLeds[led]);
|
PIO_Clear(&pinsLeds[led]);
|
||||||
else
|
else
|
||||||
PIO_Set(&pinsLeds[led]);
|
PIO_Set(&pinsLeds[led]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* LED blinking code */
|
/* LED blinking code */
|
||||||
|
|||||||
@@ -66,41 +66,41 @@ static ringbuf uart_tx_buffer;
|
|||||||
*/
|
*/
|
||||||
extern void UART_Configure( uint32_t baudrate, uint32_t masterClock)
|
extern void UART_Configure( uint32_t baudrate, uint32_t masterClock)
|
||||||
{
|
{
|
||||||
const Pin pPins[] = CONSOLE_PINS;
|
const Pin pPins[] = CONSOLE_PINS;
|
||||||
Uart *pUart = CONSOLE_UART;
|
Uart *pUart = CONSOLE_UART;
|
||||||
|
|
||||||
/* Configure PIO */
|
/* Configure PIO */
|
||||||
PIO_Configure(pPins, PIO_LISTSIZE(pPins));
|
PIO_Configure(pPins, PIO_LISTSIZE(pPins));
|
||||||
|
|
||||||
/* Configure PMC */
|
/* Configure PMC */
|
||||||
PMC->PMC_PCER0 = 1 << CONSOLE_ID;
|
PMC->PMC_PCER0 = 1 << CONSOLE_ID;
|
||||||
|
|
||||||
/* Reset and disable receiver & transmitter */
|
/* Reset and disable receiver & transmitter */
|
||||||
pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX
|
pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX
|
||||||
| UART_CR_RXDIS | UART_CR_TXDIS;
|
| UART_CR_RXDIS | UART_CR_TXDIS;
|
||||||
|
|
||||||
/* Configure mode */
|
/* Configure mode */
|
||||||
pUart->UART_MR = UART_MR_PAR_NO;
|
pUart->UART_MR = UART_MR_PAR_NO;
|
||||||
|
|
||||||
/* Configure baudrate */
|
/* Configure baudrate */
|
||||||
/* Asynchronous, no oversampling */
|
/* Asynchronous, no oversampling */
|
||||||
pUart->UART_BRGR = (masterClock / baudrate) / 16;
|
pUart->UART_BRGR = (masterClock / baudrate) / 16;
|
||||||
|
|
||||||
/* Disable PDC channel */
|
/* Disable PDC channel */
|
||||||
pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
|
pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
|
||||||
|
|
||||||
/* Reset transmit ring buffer */
|
/* Reset transmit ring buffer */
|
||||||
rbuf_reset(&uart_tx_buffer);
|
rbuf_reset(&uart_tx_buffer);
|
||||||
|
|
||||||
/* Enable TX interrupts */
|
/* Enable TX interrupts */
|
||||||
pUart->UART_IER = UART_IER_TXRDY;
|
pUart->UART_IER = UART_IER_TXRDY;
|
||||||
NVIC_EnableIRQ(CONSOLE_IRQ);
|
NVIC_EnableIRQ(CONSOLE_IRQ);
|
||||||
|
|
||||||
/* Enable receiver and transmitter */
|
/* Enable receiver and transmitter */
|
||||||
pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
|
pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
|
||||||
|
|
||||||
/* Remember the configuration is complete */
|
/* Remember the configuration is complete */
|
||||||
_ucIsConsoleInitialized=1 ;
|
_ucIsConsoleInitialized=1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,22 +140,22 @@ void CONSOLE_ISR(void)
|
|||||||
*/
|
*/
|
||||||
extern void UART_PutChar( uint8_t c )
|
extern void UART_PutChar( uint8_t c )
|
||||||
{
|
{
|
||||||
Uart *pUart = CONSOLE_UART ;
|
Uart *pUart = CONSOLE_UART ;
|
||||||
|
|
||||||
/* Initialize console is not already done */
|
/* Initialize console is not already done */
|
||||||
if ( !_ucIsConsoleInitialized )
|
if ( !_ucIsConsoleInitialized )
|
||||||
{
|
{
|
||||||
UART_Configure(CONSOLE_BAUDRATE, BOARD_MCK);
|
UART_Configure(CONSOLE_BAUDRATE, BOARD_MCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only store input if buffer is not full, else drop it */
|
/* Only store input if buffer is not full, else drop it */
|
||||||
if (!rbuf_is_full(&uart_tx_buffer)) {
|
if (!rbuf_is_full(&uart_tx_buffer)) {
|
||||||
rbuf_write(&uart_tx_buffer, c);
|
rbuf_write(&uart_tx_buffer, c);
|
||||||
if (!(pUart->UART_IMR & UART_IMR_TXRDY)) {
|
if (!(pUart->UART_IMR & UART_IMR_TXRDY)) {
|
||||||
pUart->UART_IER = UART_IER_TXRDY;
|
pUart->UART_IER = UART_IER_TXRDY;
|
||||||
CONSOLE_ISR();
|
CONSOLE_ISR();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -166,17 +166,17 @@ extern void UART_PutChar( uint8_t c )
|
|||||||
*/
|
*/
|
||||||
extern uint32_t UART_GetChar( void )
|
extern uint32_t UART_GetChar( void )
|
||||||
{
|
{
|
||||||
Uart *pUart = CONSOLE_UART ;
|
Uart *pUart = CONSOLE_UART ;
|
||||||
|
|
||||||
if ( !_ucIsConsoleInitialized )
|
if ( !_ucIsConsoleInitialized )
|
||||||
{
|
{
|
||||||
UART_Configure(CONSOLE_BAUDRATE, BOARD_MCK);
|
UART_Configure(CONSOLE_BAUDRATE, BOARD_MCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( (pUart->UART_SR & UART_SR_RXRDY) == 0 )
|
while ( (pUart->UART_SR & UART_SR_RXRDY) == 0 )
|
||||||
WDT_Restart(WDT);
|
WDT_Restart(WDT);
|
||||||
|
|
||||||
return pUart->UART_RHR ;
|
return pUart->UART_RHR ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -186,14 +186,14 @@ extern uint32_t UART_GetChar( void )
|
|||||||
*/
|
*/
|
||||||
extern uint32_t UART_IsRxReady( void )
|
extern uint32_t UART_IsRxReady( void )
|
||||||
{
|
{
|
||||||
Uart *pUart = CONSOLE_UART;
|
Uart *pUart = CONSOLE_UART;
|
||||||
|
|
||||||
if ( !_ucIsConsoleInitialized )
|
if ( !_ucIsConsoleInitialized )
|
||||||
{
|
{
|
||||||
UART_Configure( CONSOLE_BAUDRATE, BOARD_MCK ) ;
|
UART_Configure( CONSOLE_BAUDRATE, BOARD_MCK ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (pUart->UART_SR & UART_SR_RXRDY) > 0 ;
|
return (pUart->UART_SR & UART_SR_RXRDY) > 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -204,14 +204,14 @@ extern uint32_t UART_IsRxReady( void )
|
|||||||
*/
|
*/
|
||||||
extern void UART_DumpFrame( uint8_t* pucFrame, uint32_t dwSize )
|
extern void UART_DumpFrame( uint8_t* pucFrame, uint32_t dwSize )
|
||||||
{
|
{
|
||||||
uint32_t dw ;
|
uint32_t dw ;
|
||||||
|
|
||||||
for ( dw=0 ; dw < dwSize ; dw++ )
|
for ( dw=0 ; dw < dwSize ; dw++ )
|
||||||
{
|
{
|
||||||
printf( "%02X ", pucFrame[dw] ) ;
|
printf( "%02X ", pucFrame[dw] ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf( "\n\r" ) ;
|
printf( "\n\r" ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -223,62 +223,62 @@ extern void UART_DumpFrame( uint8_t* pucFrame, uint32_t dwSize )
|
|||||||
*/
|
*/
|
||||||
extern void UART_DumpMemory( uint8_t* pucBuffer, uint32_t dwSize, uint32_t dwAddress )
|
extern void UART_DumpMemory( uint8_t* pucBuffer, uint32_t dwSize, uint32_t dwAddress )
|
||||||
{
|
{
|
||||||
uint32_t i ;
|
uint32_t i ;
|
||||||
uint32_t j ;
|
uint32_t j ;
|
||||||
uint32_t dwLastLineStart ;
|
uint32_t dwLastLineStart ;
|
||||||
uint8_t* pucTmp ;
|
uint8_t* pucTmp ;
|
||||||
|
|
||||||
for ( i=0 ; i < (dwSize / 16) ; i++ )
|
for ( i=0 ; i < (dwSize / 16) ; i++ )
|
||||||
{
|
{
|
||||||
printf( "0x%08X: ", (unsigned int)(dwAddress + (i*16)) ) ;
|
printf( "0x%08X: ", (unsigned int)(dwAddress + (i*16)) ) ;
|
||||||
pucTmp = (uint8_t*)&pucBuffer[i*16] ;
|
pucTmp = (uint8_t*)&pucBuffer[i*16] ;
|
||||||
|
|
||||||
for ( j=0 ; j < 4 ; j++ )
|
for ( j=0 ; j < 4 ; j++ )
|
||||||
{
|
{
|
||||||
printf( "%02X%02X%02X%02X ", pucTmp[0], pucTmp[1], pucTmp[2], pucTmp[3] ) ;
|
printf( "%02X%02X%02X%02X ", pucTmp[0], pucTmp[1], pucTmp[2], pucTmp[3] ) ;
|
||||||
pucTmp += 4 ;
|
pucTmp += 4 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
pucTmp=(uint8_t*)&pucBuffer[i*16] ;
|
pucTmp=(uint8_t*)&pucBuffer[i*16] ;
|
||||||
|
|
||||||
for ( j=0 ; j < 16 ; j++ )
|
for ( j=0 ; j < 16 ; j++ )
|
||||||
{
|
{
|
||||||
UART_PutChar( *pucTmp++ ) ;
|
UART_PutChar( *pucTmp++ ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf( "\n\r" ) ;
|
printf( "\n\r" ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (dwSize%16) != 0 )
|
if ( (dwSize%16) != 0 )
|
||||||
{
|
{
|
||||||
dwLastLineStart=dwSize - (dwSize%16) ;
|
dwLastLineStart=dwSize - (dwSize%16) ;
|
||||||
|
|
||||||
printf( "0x%08X: ", (unsigned int)(dwAddress + dwLastLineStart) ) ;
|
printf( "0x%08X: ", (unsigned int)(dwAddress + dwLastLineStart) ) ;
|
||||||
for ( j=dwLastLineStart ; j < dwLastLineStart+16 ; j++ )
|
for ( j=dwLastLineStart ; j < dwLastLineStart+16 ; j++ )
|
||||||
{
|
{
|
||||||
if ( (j!=dwLastLineStart) && (j%4 == 0) )
|
if ( (j!=dwLastLineStart) && (j%4 == 0) )
|
||||||
{
|
{
|
||||||
printf( " " ) ;
|
printf( " " ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( j < dwSize )
|
if ( j < dwSize )
|
||||||
{
|
{
|
||||||
printf( "%02X", pucBuffer[j] ) ;
|
printf( "%02X", pucBuffer[j] ) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf(" ") ;
|
printf(" ") ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf( " " ) ;
|
printf( " " ) ;
|
||||||
for ( j=dwLastLineStart ; j < dwSize ; j++ )
|
for ( j=dwLastLineStart ; j < dwSize ; j++ )
|
||||||
{
|
{
|
||||||
UART_PutChar( pucBuffer[j] ) ;
|
UART_PutChar( pucBuffer[j] ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf( "\n\r" ) ;
|
printf( "\n\r" ) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -288,46 +288,46 @@ extern void UART_DumpMemory( uint8_t* pucBuffer, uint32_t dwSize, uint32_t dwAdd
|
|||||||
*/
|
*/
|
||||||
extern uint32_t UART_GetInteger( uint32_t* pdwValue )
|
extern uint32_t UART_GetInteger( uint32_t* pdwValue )
|
||||||
{
|
{
|
||||||
uint8_t ucKey ;
|
uint8_t ucKey ;
|
||||||
uint8_t ucNbNb=0 ;
|
uint8_t ucNbNb=0 ;
|
||||||
uint32_t dwValue=0 ;
|
uint32_t dwValue=0 ;
|
||||||
|
|
||||||
while ( 1 )
|
while ( 1 )
|
||||||
{
|
{
|
||||||
ucKey=UART_GetChar() ;
|
ucKey=UART_GetChar() ;
|
||||||
UART_PutChar( ucKey ) ;
|
UART_PutChar( ucKey ) ;
|
||||||
|
|
||||||
if ( ucKey >= '0' && ucKey <= '9' )
|
if ( ucKey >= '0' && ucKey <= '9' )
|
||||||
{
|
{
|
||||||
dwValue = (dwValue * 10) + (ucKey - '0');
|
dwValue = (dwValue * 10) + (ucKey - '0');
|
||||||
ucNbNb++ ;
|
ucNbNb++ ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( ucKey == 0x0D || ucKey == ' ' )
|
if ( ucKey == 0x0D || ucKey == ' ' )
|
||||||
{
|
{
|
||||||
if ( ucNbNb == 0 )
|
if ( ucNbNb == 0 )
|
||||||
{
|
{
|
||||||
printf( "\n\rWrite a number and press ENTER or SPACE!\n\r" ) ;
|
printf( "\n\rWrite a number and press ENTER or SPACE!\n\r" ) ;
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf( "\n\r" ) ;
|
printf( "\n\r" ) ;
|
||||||
*pdwValue=dwValue ;
|
*pdwValue=dwValue ;
|
||||||
|
|
||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf( "\n\r'%c' not a number!\n\r", ucKey ) ;
|
printf( "\n\r'%c' not a number!\n\r", ucKey ) ;
|
||||||
|
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WDT_Restart(WDT);
|
WDT_Restart(WDT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -339,25 +339,25 @@ extern uint32_t UART_GetInteger( uint32_t* pdwValue )
|
|||||||
*/
|
*/
|
||||||
extern uint32_t UART_GetIntegerMinMax( uint32_t* pdwValue, uint32_t dwMin, uint32_t dwMax )
|
extern uint32_t UART_GetIntegerMinMax( uint32_t* pdwValue, uint32_t dwMin, uint32_t dwMax )
|
||||||
{
|
{
|
||||||
uint32_t dwValue=0 ;
|
uint32_t dwValue=0 ;
|
||||||
|
|
||||||
if ( UART_GetInteger( &dwValue ) == 0 )
|
if ( UART_GetInteger( &dwValue ) == 0 )
|
||||||
{
|
{
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( dwValue < dwMin || dwValue > dwMax )
|
if ( dwValue < dwMin || dwValue > dwMax )
|
||||||
{
|
{
|
||||||
printf( "\n\rThe number have to be between %d and %d\n\r", (int)dwMin, (int)dwMax ) ;
|
printf( "\n\rThe number have to be between %d and %d\n\r", (int)dwMin, (int)dwMax ) ;
|
||||||
|
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf( "\n\r" ) ;
|
printf( "\n\r" ) ;
|
||||||
|
|
||||||
*pdwValue = dwValue ;
|
*pdwValue = dwValue ;
|
||||||
|
|
||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -367,45 +367,45 @@ extern uint32_t UART_GetIntegerMinMax( uint32_t* pdwValue, uint32_t dwMin, uint3
|
|||||||
*/
|
*/
|
||||||
extern uint32_t UART_GetHexa32( uint32_t* pdwValue )
|
extern uint32_t UART_GetHexa32( uint32_t* pdwValue )
|
||||||
{
|
{
|
||||||
uint8_t ucKey ;
|
uint8_t ucKey ;
|
||||||
uint32_t dw = 0 ;
|
uint32_t dw = 0 ;
|
||||||
uint32_t dwValue = 0 ;
|
uint32_t dwValue = 0 ;
|
||||||
|
|
||||||
for ( dw=0 ; dw < 8 ; dw++ )
|
for ( dw=0 ; dw < 8 ; dw++ )
|
||||||
{
|
{
|
||||||
ucKey = UART_GetChar() ;
|
ucKey = UART_GetChar() ;
|
||||||
UART_PutChar( ucKey ) ;
|
UART_PutChar( ucKey ) ;
|
||||||
|
|
||||||
if ( ucKey >= '0' && ucKey <= '9' )
|
if ( ucKey >= '0' && ucKey <= '9' )
|
||||||
{
|
{
|
||||||
dwValue = (dwValue * 16) + (ucKey - '0') ;
|
dwValue = (dwValue * 16) + (ucKey - '0') ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( ucKey >= 'A' && ucKey <= 'F' )
|
if ( ucKey >= 'A' && ucKey <= 'F' )
|
||||||
{
|
{
|
||||||
dwValue = (dwValue * 16) + (ucKey - 'A' + 10) ;
|
dwValue = (dwValue * 16) + (ucKey - 'A' + 10) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( ucKey >= 'a' && ucKey <= 'f' )
|
if ( ucKey >= 'a' && ucKey <= 'f' )
|
||||||
{
|
{
|
||||||
dwValue = (dwValue * 16) + (ucKey - 'a' + 10) ;
|
dwValue = (dwValue * 16) + (ucKey - 'a' + 10) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf( "\n\rIt is not a hexa character!\n\r" ) ;
|
printf( "\n\rIt is not a hexa character!\n\r" ) ;
|
||||||
|
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n\r" ) ;
|
printf("\n\r" ) ;
|
||||||
*pdwValue = dwValue ;
|
*pdwValue = dwValue ;
|
||||||
|
|
||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined __ICCARM__ /* IAR Ewarm 5.41+ */
|
#if defined __ICCARM__ /* IAR Ewarm 5.41+ */
|
||||||
@@ -418,9 +418,9 @@ extern uint32_t UART_GetHexa32( uint32_t* pdwValue )
|
|||||||
*/
|
*/
|
||||||
extern WEAK signed int putchar( signed int c )
|
extern WEAK signed int putchar( signed int c )
|
||||||
{
|
{
|
||||||
UART_PutChar( c ) ;
|
UART_PutChar( c ) ;
|
||||||
|
|
||||||
return c ;
|
return c ;
|
||||||
}
|
}
|
||||||
#endif // defined __ICCARM__
|
#endif // defined __ICCARM__
|
||||||
|
|
||||||
|
|||||||
@@ -65,41 +65,41 @@
|
|||||||
// Definitions
|
// Definitions
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#if defined(NOASSERT)
|
#if defined(NOASSERT)
|
||||||
#define ASSERT(...)
|
#define ASSERT(...)
|
||||||
#define SANITY_CHECK(...)
|
#define SANITY_CHECK(...)
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if (TRACE_LEVEL == 0)
|
#if (TRACE_LEVEL == 0)
|
||||||
/// Checks that the given condition is true,
|
/// Checks that the given condition is true,
|
||||||
/// otherwise stops the program execution.
|
/// otherwise stops the program execution.
|
||||||
/// \param condition Condition to verify.
|
/// \param condition Condition to verify.
|
||||||
#define ASSERT(condition) { \
|
#define ASSERT(condition) { \
|
||||||
if (!(condition)) { \
|
if (!(condition)) { \
|
||||||
while (1); \
|
while (1); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Performs the same duty as the ASSERT() macro
|
/// Performs the same duty as the ASSERT() macro
|
||||||
/// \param condition Condition to verify.
|
/// \param condition Condition to verify.
|
||||||
#define SANITY_CHECK(condition) ASSERT(condition, ...)
|
#define SANITY_CHECK(condition) ASSERT(condition, ...)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
/// Checks that the given condition is true, otherwise displays an error
|
/// Checks that the given condition is true, otherwise displays an error
|
||||||
/// message and stops the program execution.
|
/// message and stops the program execution.
|
||||||
/// \param condition Condition to verify.
|
/// \param condition Condition to verify.
|
||||||
#define ASSERT(condition) { \
|
#define ASSERT(condition) { \
|
||||||
if (!(condition)) { \
|
if (!(condition)) { \
|
||||||
printf("-F- ASSERT: %s %s:%d\n\r", #condition, __BASE_FILE__, __LINE__); \
|
printf("-F- ASSERT: %s %s:%d\n\r", #condition, __BASE_FILE__, __LINE__); \
|
||||||
while (1); \
|
while (1); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define SANITY_ERROR "Sanity check failed at %s:%d\n\r"
|
#define SANITY_ERROR "Sanity check failed at %s:%d\n\r"
|
||||||
|
|
||||||
/// Performs the same duty as the ASSERT() macro, except a default error
|
/// Performs the same duty as the ASSERT() macro, except a default error
|
||||||
/// message is output if the condition is false.
|
/// message is output if the condition is false.
|
||||||
/// \param condition Condition to verify.
|
/// \param condition Condition to verify.
|
||||||
#define SANITY_CHECK(condition) ASSERT(condition, SANITY_ERROR, __FILE__, __LINE__)
|
#define SANITY_CHECK(condition) ASSERT(condition, SANITY_ERROR, __FILE__, __LINE__)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -145,129 +145,129 @@ typedef struct
|
|||||||
/// 6.1.11.2 PIN Verification Data Structure
|
/// 6.1.11.2 PIN Verification Data Structure
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/// Number of seconds.
|
/// Number of seconds.
|
||||||
unsigned char bTimerOut;
|
unsigned char bTimerOut;
|
||||||
/// Several parameters for the PIN format options
|
/// Several parameters for the PIN format options
|
||||||
unsigned char bmFormatString;
|
unsigned char bmFormatString;
|
||||||
/// Define the length of the PIN to present in the APDU command
|
/// Define the length of the PIN to present in the APDU command
|
||||||
unsigned char bmPINBlockString;
|
unsigned char bmPINBlockString;
|
||||||
/// Allows the length PIN insertion in the APDU command
|
/// Allows the length PIN insertion in the APDU command
|
||||||
unsigned char bmPINLengthFormat;
|
unsigned char bmPINLengthFormat;
|
||||||
/// Minimum PIN size in digit and Maximum PIN size in digit
|
/// Minimum PIN size in digit and Maximum PIN size in digit
|
||||||
unsigned char wPINMaxExtraDigit;
|
unsigned char wPINMaxExtraDigit;
|
||||||
/// The value is a bit wise OR operation.
|
/// The value is a bit wise OR operation.
|
||||||
unsigned char bEntryValidationCondition;
|
unsigned char bEntryValidationCondition;
|
||||||
/// Number of messages to display for the PIN modify command
|
/// Number of messages to display for the PIN modify command
|
||||||
unsigned char bNumberMessage;
|
unsigned char bNumberMessage;
|
||||||
/// Language used to display the messages.
|
/// Language used to display the messages.
|
||||||
unsigned char wLangId;
|
unsigned char wLangId;
|
||||||
/// Message index in the Reader message table
|
/// Message index in the Reader message table
|
||||||
unsigned char bMsgIndex;
|
unsigned char bMsgIndex;
|
||||||
/// T=1 I-block prologue field to use
|
/// T=1 I-block prologue field to use
|
||||||
unsigned char bTeoPrologue[3];
|
unsigned char bTeoPrologue[3];
|
||||||
/// APDU to send to the ICC
|
/// APDU to send to the ICC
|
||||||
unsigned char abPINApdu[255];
|
unsigned char abPINApdu[255];
|
||||||
}__attribute__ ((packed)) S_ccid_PIN_Verification;
|
}__attribute__ ((packed)) S_ccid_PIN_Verification;
|
||||||
|
|
||||||
|
|
||||||
/// 6.1.11.7 PIN Modification Data Structure
|
/// 6.1.11.7 PIN Modification Data Structure
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/// Number of seconds. If 00h then CCID default value is used.
|
/// Number of seconds. If 00h then CCID default value is used.
|
||||||
unsigned char bTimeOut;
|
unsigned char bTimeOut;
|
||||||
/// Several parameters for the PIN format options (defined in § 6.1.11.4)
|
/// Several parameters for the PIN format options (defined in § 6.1.11.4)
|
||||||
unsigned char bmFormatString4;
|
unsigned char bmFormatString4;
|
||||||
/// Define the length of the PIN to present in the APDU command
|
/// Define the length of the PIN to present in the APDU command
|
||||||
unsigned char bmPINBlockString;
|
unsigned char bmPINBlockString;
|
||||||
/// Allows the length PIN insertion in the APDU command (defined in § 6.1.11.6)
|
/// Allows the length PIN insertion in the APDU command (defined in § 6.1.11.6)
|
||||||
unsigned char bmPinLengthFormat;
|
unsigned char bmPinLengthFormat;
|
||||||
/// Insertion position offset in byte for the current PIN
|
/// Insertion position offset in byte for the current PIN
|
||||||
unsigned char bInsertionOffsetOld;
|
unsigned char bInsertionOffsetOld;
|
||||||
/// Insertion position offset in byte for the new PIN
|
/// Insertion position offset in byte for the new PIN
|
||||||
unsigned char bInsertionOffsetNew;
|
unsigned char bInsertionOffsetNew;
|
||||||
/// XXYYh
|
/// XXYYh
|
||||||
/// XX: Minimum PIN size in digit
|
/// XX: Minimum PIN size in digit
|
||||||
/// YY: Maximum PIN size in digit
|
/// YY: Maximum PIN size in digit
|
||||||
unsigned char wPINMaxExtraDigit;
|
unsigned char wPINMaxExtraDigit;
|
||||||
/// 00h,01h,02h,03h
|
/// 00h,01h,02h,03h
|
||||||
/// Indicates if a confirmation is requested before acceptance of a new PIN (meaning that the user has to enter this new PIN twice before it is accepted)
|
/// Indicates if a confirmation is requested before acceptance of a new PIN (meaning that the user has to enter this new PIN twice before it is accepted)
|
||||||
/// Indicates if the current PIN must be entered and set in the same APDU field of not.
|
/// Indicates if the current PIN must be entered and set in the same APDU field of not.
|
||||||
unsigned char bConfirmPIN;
|
unsigned char bConfirmPIN;
|
||||||
/// The value is a bit wise OR operation.
|
/// The value is a bit wise OR operation.
|
||||||
/// 01h Max size reached
|
/// 01h Max size reached
|
||||||
/// 02h Validation key pressed
|
/// 02h Validation key pressed
|
||||||
/// 04h Timeout occurred
|
/// 04h Timeout occurred
|
||||||
unsigned char bEntryValidationCondition;
|
unsigned char bEntryValidationCondition;
|
||||||
/// 00h,01h,02h,03h,or FFh
|
/// 00h,01h,02h,03h,or FFh
|
||||||
/// Number of messages to display for the PIN modify command.
|
/// Number of messages to display for the PIN modify command.
|
||||||
unsigned char bNumberMessage;
|
unsigned char bNumberMessage;
|
||||||
/// Language used to display the messages. The 16 bit
|
/// Language used to display the messages. The 16 bit
|
||||||
unsigned char wLangId;
|
unsigned char wLangId;
|
||||||
/// Message index in the Reader message table (should be 00h or 01h).
|
/// Message index in the Reader message table (should be 00h or 01h).
|
||||||
unsigned char bMsgIndex1;
|
unsigned char bMsgIndex1;
|
||||||
/// Message index in the Reader message table (should be 01h or 02h).
|
/// Message index in the Reader message table (should be 01h or 02h).
|
||||||
unsigned char bMsgIndex2;
|
unsigned char bMsgIndex2;
|
||||||
/// Message index in the Reader message table (should be 02h).
|
/// Message index in the Reader message table (should be 02h).
|
||||||
unsigned char bMsgIndex3;
|
unsigned char bMsgIndex3;
|
||||||
/// T=1 I-block prologue field to use. Significant only if protocol in use is T=1.
|
/// T=1 I-block prologue field to use. Significant only if protocol in use is T=1.
|
||||||
unsigned char bTeoPrologue[3];
|
unsigned char bTeoPrologue[3];
|
||||||
/// Byte array APDU to send to the ICC
|
/// Byte array APDU to send to the ICC
|
||||||
unsigned char abPINApdu[255];
|
unsigned char abPINApdu[255];
|
||||||
}__attribute__ ((packed)) S_ccid_PIN_Modification;
|
}__attribute__ ((packed)) S_ccid_PIN_Modification;
|
||||||
|
|
||||||
/// Protocol Data Structure for Protocol T=0 (bProtocolNum=0, dwLength=00000005h)
|
/// Protocol Data Structure for Protocol T=0 (bProtocolNum=0, dwLength=00000005h)
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/// B7-4 – FI – Index into the table 7 in ISO/IEC 7816-3:1997 selecting a
|
/// B7-4 – FI – Index into the table 7 in ISO/IEC 7816-3:1997 selecting a
|
||||||
/// clock rate conversion factor
|
/// clock rate conversion factor
|
||||||
/// B3-0 – DI - Index into the table 8 in ISO/IEC 7816-3:1997 selecting a
|
/// B3-0 – DI - Index into the table 8 in ISO/IEC 7816-3:1997 selecting a
|
||||||
/// baud rate conversion factor
|
/// baud rate conversion factor
|
||||||
unsigned char bmFindexDindex;
|
unsigned char bmFindexDindex;
|
||||||
/// For T=0 ,B0 – 0b, B7-2 – 000000b
|
/// For T=0 ,B0 – 0b, B7-2 – 000000b
|
||||||
/// B1 – Convention used (b1=0 for direct, b1=1 for inverse)
|
/// B1 – Convention used (b1=0 for direct, b1=1 for inverse)
|
||||||
unsigned char bmTCCKST0; // 0 to 2
|
unsigned char bmTCCKST0; // 0 to 2
|
||||||
/// Extra Guardtime between two characters. Add 0 to 254 etu to the normal
|
/// Extra Guardtime between two characters. Add 0 to 254 etu to the normal
|
||||||
/// guardtime of 12etu. FFh is the same as 00h.
|
/// guardtime of 12etu. FFh is the same as 00h.
|
||||||
unsigned char bGuardTimeT0; // 0 to FF
|
unsigned char bGuardTimeT0; // 0 to FF
|
||||||
/// WI for T=0 used to define WWT
|
/// WI for T=0 used to define WWT
|
||||||
unsigned char bWaitingIntegerT0; // 0 to FF
|
unsigned char bWaitingIntegerT0; // 0 to FF
|
||||||
/// ICC Clock Stop Support
|
/// ICC Clock Stop Support
|
||||||
/// 00 = Stopping the Clock is not allowed
|
/// 00 = Stopping the Clock is not allowed
|
||||||
/// 01 = Stop with Clock signal Low
|
/// 01 = Stop with Clock signal Low
|
||||||
/// 02 = Stop with Clock signal High
|
/// 02 = Stop with Clock signal High
|
||||||
/// 03 = Stop with Clock either High or Low
|
/// 03 = Stop with Clock either High or Low
|
||||||
unsigned char bClockStop; // 0 to 3
|
unsigned char bClockStop; // 0 to 3
|
||||||
} __attribute__ ((packed)) S_ccid_protocol_t0;
|
} __attribute__ ((packed)) S_ccid_protocol_t0;
|
||||||
|
|
||||||
|
|
||||||
/// Protocol Data Structure for Protocol T=1 (bProtocolNum=1, dwLength=00000007h)
|
/// Protocol Data Structure for Protocol T=1 (bProtocolNum=1, dwLength=00000007h)
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/// B7-4 – FI – Index into the table 7 in ISO/IEC 7816-3:1997 selecting a
|
/// B7-4 – FI – Index into the table 7 in ISO/IEC 7816-3:1997 selecting a
|
||||||
/// clock rate conversion factor
|
/// clock rate conversion factor
|
||||||
/// B3-0 – DI - Index into the table 8 in ISO/IEC 7816-3:1997 selecting a
|
/// B3-0 – DI - Index into the table 8 in ISO/IEC 7816-3:1997 selecting a
|
||||||
/// baud rate conversion factor
|
/// baud rate conversion factor
|
||||||
unsigned char bmFindexDindex;
|
unsigned char bmFindexDindex;
|
||||||
/// For T=1, B7-2 – 000100b
|
/// For T=1, B7-2 – 000100b
|
||||||
/// B0 – Checksum type (b0=0 for LRC, b0=1 for CRC
|
/// B0 – Checksum type (b0=0 for LRC, b0=1 for CRC
|
||||||
/// B1 – Convention used (b1=0 for direct, b1=1 for inverse)
|
/// B1 – Convention used (b1=0 for direct, b1=1 for inverse)
|
||||||
unsigned char bmTCCKST1; // 10h, 11h, 12h, 13h
|
unsigned char bmTCCKST1; // 10h, 11h, 12h, 13h
|
||||||
/// Extra Guardtime (0 to 254 etu between two characters).
|
/// Extra Guardtime (0 to 254 etu between two characters).
|
||||||
/// If value is FFh, then guardtime is reduced by 1.
|
/// If value is FFh, then guardtime is reduced by 1.
|
||||||
unsigned char bGuardTimeT1; // 0 to FF
|
unsigned char bGuardTimeT1; // 0 to FF
|
||||||
/// B7-4 = BWI
|
/// B7-4 = BWI
|
||||||
/// B3-0 = CWI
|
/// B3-0 = CWI
|
||||||
unsigned char bmWaitingIntegersT1; // 0 to 9
|
unsigned char bmWaitingIntegersT1; // 0 to 9
|
||||||
/// ICC Clock Stop Support
|
/// ICC Clock Stop Support
|
||||||
/// 00 = Stopping the Clock is not allowed
|
/// 00 = Stopping the Clock is not allowed
|
||||||
/// 01 = Stop with Clock signal Low
|
/// 01 = Stop with Clock signal Low
|
||||||
/// 02 = Stop with Clock signal High
|
/// 02 = Stop with Clock signal High
|
||||||
/// 03 = Stop with Clock either High or Low
|
/// 03 = Stop with Clock either High or Low
|
||||||
unsigned char bClockStop; // 0 to 3
|
unsigned char bClockStop; // 0 to 3
|
||||||
/// Size of negotiated IFSC
|
/// Size of negotiated IFSC
|
||||||
unsigned char bIFSC; // 0 to FE
|
unsigned char bIFSC; // 0 to FE
|
||||||
/// Nad value used by CCID
|
/// Nad value used by CCID
|
||||||
unsigned char bNadValue; // 0 to FF
|
unsigned char bNadValue; // 0 to FF
|
||||||
} __attribute__ ((packed)) S_ccid_protocol_t1;
|
} __attribute__ ((packed)) S_ccid_protocol_t1;
|
||||||
|
|
||||||
|
|
||||||
@@ -357,8 +357,8 @@ typedef struct
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
extern unsigned char RDRtoPCHardwareError( unsigned char bSlot,
|
extern unsigned char RDRtoPCHardwareError( unsigned char bSlot,
|
||||||
unsigned char bSeq,
|
unsigned char bSeq,
|
||||||
unsigned char bHardwareErrorCode );
|
unsigned char bHardwareErrorCode );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#if !defined(NOAUTOCALLBACK)
|
#if !defined(NOAUTOCALLBACK)
|
||||||
@@ -368,13 +368,13 @@ extern void USBDCallbacks_RequestReceived(const USBGenericRequest *request);
|
|||||||
extern void CCID_SmartCardRequest( void );
|
extern void CCID_SmartCardRequest( void );
|
||||||
extern void CCIDDriver_Initialize( void );
|
extern void CCIDDriver_Initialize( void );
|
||||||
extern unsigned char CCID_Read(void *pBuffer,
|
extern unsigned char CCID_Read(void *pBuffer,
|
||||||
unsigned int dLength,
|
unsigned int dLength,
|
||||||
TransferCallback fCallback,
|
TransferCallback fCallback,
|
||||||
void *pArgument);
|
void *pArgument);
|
||||||
extern unsigned char CCID_Write(void *pBuffer,
|
extern unsigned char CCID_Write(void *pBuffer,
|
||||||
unsigned int dLength,
|
unsigned int dLength,
|
||||||
TransferCallback fCallback,
|
TransferCallback fCallback,
|
||||||
void *pArgument);
|
void *pArgument);
|
||||||
extern unsigned char CCID_Insertion( void );
|
extern unsigned char CCID_Insertion( void );
|
||||||
extern unsigned char CCID_Removal( void );
|
extern unsigned char CCID_Removal( void );
|
||||||
|
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ extern uint32_t ISO7816_GetChar( uint8_t *pCharToReceive, Usart_info *usart);
|
|||||||
|
|
||||||
extern void ISO7816_IccPowerOff(void);
|
extern void ISO7816_IccPowerOff(void);
|
||||||
extern uint32_t ISO7816_XfrBlockTPDU_T0(const uint8_t *pAPDU,
|
extern uint32_t ISO7816_XfrBlockTPDU_T0(const uint8_t *pAPDU,
|
||||||
uint8_t *pMessage,
|
uint8_t *pMessage,
|
||||||
uint16_t wLength,
|
uint16_t wLength,
|
||||||
uint16_t *retlen);
|
uint16_t *retlen);
|
||||||
extern void ISO7816_Escape( void );
|
extern void ISO7816_Escape( void );
|
||||||
extern void ISO7816_RestartClock(void);
|
extern void ISO7816_RestartClock(void);
|
||||||
extern void ISO7816_StopClock( void );
|
extern void ISO7816_StopClock( void );
|
||||||
|
|||||||
@@ -65,19 +65,19 @@ enum confNum {
|
|||||||
/// device using the CCID driver.
|
/// device using the CCID driver.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
/// Configuration descriptor
|
/// Configuration descriptor
|
||||||
USBConfigurationDescriptor configuration;
|
USBConfigurationDescriptor configuration;
|
||||||
/// Interface descriptor
|
/// Interface descriptor
|
||||||
USBInterfaceDescriptor interface;
|
USBInterfaceDescriptor interface;
|
||||||
/// CCID descriptor
|
/// CCID descriptor
|
||||||
CCIDDescriptor ccid;
|
CCIDDescriptor ccid;
|
||||||
/// Bulk OUT endpoint descriptor
|
/// Bulk OUT endpoint descriptor
|
||||||
USBEndpointDescriptor bulkOut;
|
USBEndpointDescriptor bulkOut;
|
||||||
/// Bulk IN endpoint descriptor
|
/// Bulk IN endpoint descriptor
|
||||||
USBEndpointDescriptor bulkIn;
|
USBEndpointDescriptor bulkIn;
|
||||||
/// Interrupt OUT endpoint descriptor
|
/// Interrupt OUT endpoint descriptor
|
||||||
USBEndpointDescriptor interruptIn;
|
USBEndpointDescriptor interruptIn;
|
||||||
DFURT_IF_DESCRIPTOR_STRUCT
|
DFURT_IF_DESCRIPTOR_STRUCT
|
||||||
} __attribute__ ((packed)) CCIDDriverConfigurationDescriptors;
|
} __attribute__ ((packed)) CCIDDriverConfigurationDescriptors;
|
||||||
|
|
||||||
extern const USBConfigurationDescriptor *configurationDescriptorsArr[];
|
extern const USBConfigurationDescriptor *configurationDescriptorsArr[];
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -76,45 +76,45 @@ struct Usart_info usart_sim = {.base = USART_SIM, .id = ID_USART_SIM, .state = U
|
|||||||
*/
|
*/
|
||||||
uint32_t ISO7816_GetChar( uint8_t *pCharToReceive, Usart_info *usart)
|
uint32_t ISO7816_GetChar( uint8_t *pCharToReceive, Usart_info *usart)
|
||||||
{
|
{
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
uint32_t timeout=0;
|
uint32_t timeout=0;
|
||||||
|
|
||||||
Usart *us_base = usart->base;
|
Usart *us_base = usart->base;
|
||||||
uint32_t us_id = usart->id;
|
uint32_t us_id = usart->id;
|
||||||
|
|
||||||
if( usart->state == USART_SEND ) {
|
if( usart->state == USART_SEND ) {
|
||||||
while((us_base->US_CSR & US_CSR_TXEMPTY) == 0) {}
|
while((us_base->US_CSR & US_CSR_TXEMPTY) == 0) {}
|
||||||
us_base->US_CR = US_CR_RSTSTA | US_CR_RSTIT | US_CR_RSTNACK;
|
us_base->US_CR = US_CR_RSTSTA | US_CR_RSTIT | US_CR_RSTNACK;
|
||||||
usart->state = USART_RCV;
|
usart->state = USART_RCV;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait USART ready for reception */
|
/* Wait USART ready for reception */
|
||||||
while( ((us_base->US_CSR & US_CSR_RXRDY) == 0) ) {
|
while( ((us_base->US_CSR & US_CSR_RXRDY) == 0) ) {
|
||||||
WDT_Restart(WDT);
|
WDT_Restart(WDT);
|
||||||
if(timeout++ > 12000 * (BOARD_MCK/1000000)) {
|
if(timeout++ > 12000 * (BOARD_MCK/1000000)) {
|
||||||
TRACE_WARNING("TimeOut\n\r");
|
TRACE_WARNING("TimeOut\n\r");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* At least one complete character has been received and US_RHR has not yet been read. */
|
/* At least one complete character has been received and US_RHR has not yet been read. */
|
||||||
|
|
||||||
/* Get a char */
|
/* Get a char */
|
||||||
*pCharToReceive = ((us_base->US_RHR) & 0xFF);
|
*pCharToReceive = ((us_base->US_RHR) & 0xFF);
|
||||||
|
|
||||||
status = (us_base->US_CSR&(US_CSR_OVRE|US_CSR_FRAME|
|
status = (us_base->US_CSR&(US_CSR_OVRE|US_CSR_FRAME|
|
||||||
US_CSR_PARE|US_CSR_TIMEOUT|US_CSR_NACK|
|
US_CSR_PARE|US_CSR_TIMEOUT|US_CSR_NACK|
|
||||||
(1<<10)));
|
(1<<10)));
|
||||||
|
|
||||||
if (status != 0 ) {
|
if (status != 0 ) {
|
||||||
TRACE_DEBUG("R:0x%" PRIX32 "\n\r", status);
|
TRACE_DEBUG("R:0x%" PRIX32 "\n\r", status);
|
||||||
TRACE_DEBUG("R:0x%" PRIX32 "\n\r", us_base->US_CSR);
|
TRACE_DEBUG("R:0x%" PRIX32 "\n\r", us_base->US_CSR);
|
||||||
TRACE_DEBUG("Nb:0x%" PRIX32 "\n\r", us_base->US_NER );
|
TRACE_DEBUG("Nb:0x%" PRIX32 "\n\r", us_base->US_NER );
|
||||||
us_base->US_CR = US_CR_RSTSTA;
|
us_base->US_CR = US_CR_RSTSTA;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return status */
|
/* Return status */
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -125,50 +125,50 @@ uint32_t ISO7816_GetChar( uint8_t *pCharToReceive, Usart_info *usart)
|
|||||||
*/
|
*/
|
||||||
uint32_t ISO7816_SendChar( uint8_t CharToSend, Usart_info *usart )
|
uint32_t ISO7816_SendChar( uint8_t CharToSend, Usart_info *usart )
|
||||||
{
|
{
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
|
|
||||||
Usart *us_base = usart->base;
|
Usart *us_base = usart->base;
|
||||||
uint32_t us_id = usart->id;
|
uint32_t us_id = usart->id;
|
||||||
|
|
||||||
if( usart->state == USART_RCV ) {
|
if( usart->state == USART_RCV ) {
|
||||||
us_base->US_CR = US_CR_RSTSTA | US_CR_RSTIT | US_CR_RSTNACK;
|
us_base->US_CR = US_CR_RSTSTA | US_CR_RSTIT | US_CR_RSTNACK;
|
||||||
usart->state = USART_SEND;
|
usart->state = USART_SEND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait USART ready for transmit */
|
/* Wait USART ready for transmit */
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while((us_base->US_CSR & (US_CSR_TXRDY)) == 0) {
|
while((us_base->US_CSR & (US_CSR_TXRDY)) == 0) {
|
||||||
i++;
|
i++;
|
||||||
if (!(i%1000000)) {
|
if (!(i%1000000)) {
|
||||||
printf("s: %x ", us_base->US_CSR);
|
printf("s: %x ", us_base->US_CSR);
|
||||||
printf("s: %x\r\n", us_base->US_RHR & 0xFF);
|
printf("s: %x\r\n", us_base->US_RHR & 0xFF);
|
||||||
us_base->US_CR = US_CR_RSTTX;
|
us_base->US_CR = US_CR_RSTTX;
|
||||||
us_base->US_CR = US_CR_RSTRX;
|
us_base->US_CR = US_CR_RSTRX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* There is no character in the US_THR */
|
/* There is no character in the US_THR */
|
||||||
|
|
||||||
/* Transmit a char */
|
/* Transmit a char */
|
||||||
us_base->US_THR = CharToSend;
|
us_base->US_THR = CharToSend;
|
||||||
|
|
||||||
TRACE_ERROR("Sx%02X\r\n", CharToSend);
|
TRACE_ERROR("Sx%02X\r\n", CharToSend);
|
||||||
|
|
||||||
status = (us_base->US_CSR&(US_CSR_OVRE|US_CSR_FRAME|
|
status = (us_base->US_CSR&(US_CSR_OVRE|US_CSR_FRAME|
|
||||||
US_CSR_PARE|US_CSR_TIMEOUT|US_CSR_NACK|
|
US_CSR_PARE|US_CSR_TIMEOUT|US_CSR_NACK|
|
||||||
(1<<10)));
|
(1<<10)));
|
||||||
|
|
||||||
if (status != 0 ) {
|
if (status != 0 ) {
|
||||||
TRACE_INFO("******* status: 0x%" PRIX32 " (Overrun: %" PRIX32
|
TRACE_INFO("******* status: 0x%" PRIX32 " (Overrun: %" PRIX32
|
||||||
", NACK: %" PRIX32 ", Timeout: %" PRIX32 ", underrun: %" PRIX32 ")\n\r",
|
", NACK: %" PRIX32 ", Timeout: %" PRIX32 ", underrun: %" PRIX32 ")\n\r",
|
||||||
status, ((status & US_CSR_OVRE)>> 5), ((status & US_CSR_NACK) >> 13),
|
status, ((status & US_CSR_OVRE)>> 5), ((status & US_CSR_NACK) >> 13),
|
||||||
((status & US_CSR_TIMEOUT) >> 8), ((status & (1 << 10)) >> 10));
|
((status & US_CSR_TIMEOUT) >> 8), ((status & (1 << 10)) >> 10));
|
||||||
TRACE_INFO("E (USART CSR reg):0x%" PRIX32 "\n\r", us_base->US_CSR);
|
TRACE_INFO("E (USART CSR reg):0x%" PRIX32 "\n\r", us_base->US_CSR);
|
||||||
TRACE_INFO("Nb (Number of errors):0x%" PRIX32 "\n\r", us_base->US_NER );
|
TRACE_INFO("Nb (Number of errors):0x%" PRIX32 "\n\r", us_base->US_NER );
|
||||||
us_base->US_CR = US_CR_RSTSTA;
|
us_base->US_CR = US_CR_RSTSTA;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return status */
|
/* Return status */
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -177,10 +177,10 @@ uint32_t ISO7816_SendChar( uint8_t CharToSend, Usart_info *usart )
|
|||||||
*/
|
*/
|
||||||
static void ISO7816_IccPowerOn( void )
|
static void ISO7816_IccPowerOn( void )
|
||||||
{
|
{
|
||||||
/* Set RESET Master Card */
|
/* Set RESET Master Card */
|
||||||
if (st_pinIso7816RstMC) {
|
if (st_pinIso7816RstMC) {
|
||||||
PIO_Set(st_pinIso7816RstMC);
|
PIO_Set(st_pinIso7816RstMC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
@@ -192,10 +192,10 @@ static void ISO7816_IccPowerOn( void )
|
|||||||
*/
|
*/
|
||||||
void ISO7816_IccPowerOff( void )
|
void ISO7816_IccPowerOff( void )
|
||||||
{
|
{
|
||||||
/* Clear RESET Master Card */
|
/* Clear RESET Master Card */
|
||||||
if (st_pinIso7816RstMC) {
|
if (st_pinIso7816RstMC) {
|
||||||
PIO_Clear(st_pinIso7816RstMC);
|
PIO_Clear(st_pinIso7816RstMC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -207,159 +207,159 @@ void ISO7816_IccPowerOff( void )
|
|||||||
* \return 0 on success, content of US_CSR otherwise
|
* \return 0 on success, content of US_CSR otherwise
|
||||||
*/
|
*/
|
||||||
uint32_t ISO7816_XfrBlockTPDU_T0(const uint8_t *pAPDU,
|
uint32_t ISO7816_XfrBlockTPDU_T0(const uint8_t *pAPDU,
|
||||||
uint8_t *pMessage,
|
uint8_t *pMessage,
|
||||||
uint16_t wLength,
|
uint16_t wLength,
|
||||||
uint16_t *retlen )
|
uint16_t *retlen )
|
||||||
{
|
{
|
||||||
uint16_t NeNc;
|
uint16_t NeNc;
|
||||||
uint16_t indexApdu = 4;
|
uint16_t indexApdu = 4;
|
||||||
uint16_t indexMsg = 0;
|
uint16_t indexMsg = 0;
|
||||||
uint8_t SW1 = 0;
|
uint8_t SW1 = 0;
|
||||||
uint8_t procByte;
|
uint8_t procByte;
|
||||||
uint8_t cmdCase;
|
uint8_t cmdCase;
|
||||||
uint32_t status = 0;
|
uint32_t status = 0;
|
||||||
|
|
||||||
TRACE_INFO("pAPDU[0]=0x%X\n\r",pAPDU[0]);
|
TRACE_INFO("pAPDU[0]=0x%X\n\r",pAPDU[0]);
|
||||||
TRACE_INFO("pAPDU[1]=0x%X\n\r",pAPDU[1]);
|
TRACE_INFO("pAPDU[1]=0x%X\n\r",pAPDU[1]);
|
||||||
TRACE_INFO("pAPDU[2]=0x%X\n\r",pAPDU[2]);
|
TRACE_INFO("pAPDU[2]=0x%X\n\r",pAPDU[2]);
|
||||||
TRACE_INFO("pAPDU[3]=0x%X\n\r",pAPDU[3]);
|
TRACE_INFO("pAPDU[3]=0x%X\n\r",pAPDU[3]);
|
||||||
TRACE_INFO("pAPDU[4]=0x%X\n\r",pAPDU[4]);
|
TRACE_INFO("pAPDU[4]=0x%X\n\r",pAPDU[4]);
|
||||||
TRACE_INFO("pAPDU[5]=0x%X\n\r",pAPDU[5]);
|
TRACE_INFO("pAPDU[5]=0x%X\n\r",pAPDU[5]);
|
||||||
TRACE_INFO("wlength=%d\n\r",wLength);
|
TRACE_INFO("wlength=%d\n\r",wLength);
|
||||||
|
|
||||||
ISO7816_SendChar( pAPDU[0], &usart_sim ); /* CLA */
|
ISO7816_SendChar( pAPDU[0], &usart_sim ); /* CLA */
|
||||||
ISO7816_SendChar( pAPDU[1], &usart_sim ); /* INS */
|
ISO7816_SendChar( pAPDU[1], &usart_sim ); /* INS */
|
||||||
ISO7816_SendChar( pAPDU[2], &usart_sim ); /* P1 */
|
ISO7816_SendChar( pAPDU[2], &usart_sim ); /* P1 */
|
||||||
ISO7816_SendChar( pAPDU[3], &usart_sim ); /* P2 */
|
ISO7816_SendChar( pAPDU[3], &usart_sim ); /* P2 */
|
||||||
ISO7816_SendChar( pAPDU[4], &usart_sim ); /* P3 */
|
ISO7816_SendChar( pAPDU[4], &usart_sim ); /* P3 */
|
||||||
|
|
||||||
/* Handle the four structures of command APDU */
|
/* Handle the four structures of command APDU */
|
||||||
indexApdu = 5;
|
indexApdu = 5;
|
||||||
|
|
||||||
if( wLength == 4 ) {
|
if( wLength == 4 ) {
|
||||||
cmdCase = CASE1;
|
cmdCase = CASE1;
|
||||||
NeNc = 0;
|
NeNc = 0;
|
||||||
}
|
}
|
||||||
else if( wLength == 5) {
|
else if( wLength == 5) {
|
||||||
cmdCase = CASE2;
|
cmdCase = CASE2;
|
||||||
NeNc = pAPDU[4]; /* C5 */
|
NeNc = pAPDU[4]; /* C5 */
|
||||||
if (NeNc == 0) {
|
if (NeNc == 0) {
|
||||||
NeNc = 256;
|
NeNc = 256;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( wLength == 6) {
|
else if( wLength == 6) {
|
||||||
NeNc = pAPDU[4]; /* C5 */
|
NeNc = pAPDU[4]; /* C5 */
|
||||||
cmdCase = CASE3;
|
cmdCase = CASE3;
|
||||||
}
|
}
|
||||||
else if( wLength == 7) {
|
else if( wLength == 7) {
|
||||||
NeNc = pAPDU[4]; /* C5 */
|
NeNc = pAPDU[4]; /* C5 */
|
||||||
if( NeNc == 0 ) {
|
if( NeNc == 0 ) {
|
||||||
cmdCase = CASE2;
|
cmdCase = CASE2;
|
||||||
NeNc = (pAPDU[5]<<8)+pAPDU[6];
|
NeNc = (pAPDU[5]<<8)+pAPDU[6];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cmdCase = CASE3;
|
cmdCase = CASE3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
NeNc = pAPDU[4]; /* C5 */
|
NeNc = pAPDU[4]; /* C5 */
|
||||||
if( NeNc == 0 ) {
|
if( NeNc == 0 ) {
|
||||||
cmdCase = CASE3;
|
cmdCase = CASE3;
|
||||||
NeNc = (pAPDU[5]<<8)+pAPDU[6];
|
NeNc = (pAPDU[5]<<8)+pAPDU[6];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cmdCase = CASE3;
|
cmdCase = CASE3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE_DEBUG("CASE=0x%X NeNc=0x%X\n\r", cmdCase, NeNc);
|
TRACE_DEBUG("CASE=0x%X NeNc=0x%X\n\r", cmdCase, NeNc);
|
||||||
|
|
||||||
/* Handle Procedure Bytes */
|
/* Handle Procedure Bytes */
|
||||||
do {
|
do {
|
||||||
status = ISO7816_GetChar(&procByte, &usart_sim);
|
status = ISO7816_GetChar(&procByte, &usart_sim);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
TRACE_INFO("procByte: 0x%X\n\r", procByte);
|
TRACE_INFO("procByte: 0x%X\n\r", procByte);
|
||||||
/* Handle NULL */
|
/* Handle NULL */
|
||||||
if ( procByte == ISO_NULL_VAL ) {
|
if ( procByte == ISO_NULL_VAL ) {
|
||||||
TRACE_INFO("INS\n\r");
|
TRACE_INFO("INS\n\r");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Handle SW1 */
|
/* Handle SW1 */
|
||||||
else if ( ((procByte & 0xF0) ==0x60) || ((procByte & 0xF0) ==0x90) ) {
|
else if ( ((procByte & 0xF0) ==0x60) || ((procByte & 0xF0) ==0x90) ) {
|
||||||
TRACE_INFO("SW1\n\r");
|
TRACE_INFO("SW1\n\r");
|
||||||
SW1 = 1;
|
SW1 = 1;
|
||||||
}
|
}
|
||||||
/* Handle INS */
|
/* Handle INS */
|
||||||
else if ( pAPDU[1] == procByte) {
|
else if ( pAPDU[1] == procByte) {
|
||||||
TRACE_INFO("HdlINS\n\r");
|
TRACE_INFO("HdlINS\n\r");
|
||||||
if (cmdCase == CASE2) {
|
if (cmdCase == CASE2) {
|
||||||
/* receive data from card */
|
/* receive data from card */
|
||||||
do {
|
do {
|
||||||
status = ISO7816_GetChar(&pMessage[indexMsg++], &usart_sim);
|
status = ISO7816_GetChar(&pMessage[indexMsg++], &usart_sim);
|
||||||
} while(( 0 != --NeNc) && (status == 0) );
|
} while(( 0 != --NeNc) && (status == 0) );
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Send data */
|
/* Send data */
|
||||||
do {
|
do {
|
||||||
TRACE_INFO("Send %X", pAPDU[indexApdu]);
|
TRACE_INFO("Send %X", pAPDU[indexApdu]);
|
||||||
ISO7816_SendChar(pAPDU[indexApdu++], &usart_sim);
|
ISO7816_SendChar(pAPDU[indexApdu++], &usart_sim);
|
||||||
} while( 0 != --NeNc );
|
} while( 0 != --NeNc );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Handle INS ^ 0xff */
|
/* Handle INS ^ 0xff */
|
||||||
else
|
else
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||||
if ( pAPDU[1] == (procByte ^ 0xff)) {
|
if ( pAPDU[1] == (procByte ^ 0xff)) {
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
TRACE_INFO("HdlINS+\n\r");
|
TRACE_INFO("HdlINS+\n\r");
|
||||||
if (cmdCase == CASE2) {
|
if (cmdCase == CASE2) {
|
||||||
/* receive data from card */
|
/* receive data from card */
|
||||||
status = ISO7816_GetChar(&pMessage[indexMsg++], &usart_sim);
|
status = ISO7816_GetChar(&pMessage[indexMsg++], &usart_sim);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
TRACE_INFO("Rcv: 0x%X\n\r", pMessage[indexMsg-1]);
|
TRACE_INFO("Rcv: 0x%X\n\r", pMessage[indexMsg-1]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
status = ISO7816_SendChar(pAPDU[indexApdu++], &usart_sim);
|
status = ISO7816_SendChar(pAPDU[indexApdu++], &usart_sim);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NeNc--;
|
NeNc--;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* ?? */
|
/* ?? */
|
||||||
TRACE_INFO("procByte=0x%X\n\r", procByte);
|
TRACE_INFO("procByte=0x%X\n\r", procByte);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (NeNc != 0);
|
} while (NeNc != 0);
|
||||||
|
|
||||||
/* Status Bytes */
|
/* Status Bytes */
|
||||||
if (SW1 == 0) {
|
if (SW1 == 0) {
|
||||||
status = ISO7816_GetChar(&pMessage[indexMsg++], &usart_sim); /* SW1 */
|
status = ISO7816_GetChar(&pMessage[indexMsg++], &usart_sim); /* SW1 */
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pMessage[indexMsg++] = procByte;
|
pMessage[indexMsg++] = procByte;
|
||||||
}
|
}
|
||||||
status = ISO7816_GetChar(&pMessage[indexMsg++], &usart_sim); /* SW2 */
|
status = ISO7816_GetChar(&pMessage[indexMsg++], &usart_sim); /* SW2 */
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE_WARNING("SW1=0x%X, SW2=0x%X\n\r", pMessage[indexMsg-2], pMessage[indexMsg-1]);
|
TRACE_WARNING("SW1=0x%X, SW2=0x%X\n\r", pMessage[indexMsg-2], pMessage[indexMsg-1]);
|
||||||
|
|
||||||
*retlen = indexMsg;
|
*retlen = indexMsg;
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,7 +368,7 @@ uint32_t ISO7816_XfrBlockTPDU_T0(const uint8_t *pAPDU,
|
|||||||
*/
|
*/
|
||||||
void ISO7816_Escape( void )
|
void ISO7816_Escape( void )
|
||||||
{
|
{
|
||||||
TRACE_DEBUG("For user, if needed\n\r");
|
TRACE_DEBUG("For user, if needed\n\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -376,8 +376,8 @@ void ISO7816_Escape( void )
|
|||||||
*/
|
*/
|
||||||
void ISO7816_RestartClock( void )
|
void ISO7816_RestartClock( void )
|
||||||
{
|
{
|
||||||
TRACE_DEBUG("ISO7816_RestartClock\n\r");
|
TRACE_DEBUG("ISO7816_RestartClock\n\r");
|
||||||
USART_SIM->US_BRGR = 13;
|
USART_SIM->US_BRGR = 13;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -385,8 +385,8 @@ void ISO7816_RestartClock( void )
|
|||||||
*/
|
*/
|
||||||
void ISO7816_StopClock( void )
|
void ISO7816_StopClock( void )
|
||||||
{
|
{
|
||||||
TRACE_DEBUG("ISO7816_StopClock\n\r");
|
TRACE_DEBUG("ISO7816_StopClock\n\r");
|
||||||
USART_SIM->US_BRGR = 0;
|
USART_SIM->US_BRGR = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -394,8 +394,8 @@ void ISO7816_StopClock( void )
|
|||||||
*/
|
*/
|
||||||
void ISO7816_toAPDU( void )
|
void ISO7816_toAPDU( void )
|
||||||
{
|
{
|
||||||
TRACE_DEBUG("ISO7816_toAPDU\n\r");
|
TRACE_DEBUG("ISO7816_toAPDU\n\r");
|
||||||
TRACE_DEBUG("Not supported at this time\n\r");
|
TRACE_DEBUG("Not supported at this time\n\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -406,64 +406,64 @@ void ISO7816_toAPDU( void )
|
|||||||
*/
|
*/
|
||||||
uint32_t ISO7816_Datablock_ATR( uint8_t* pAtr, uint8_t* pLength )
|
uint32_t ISO7816_Datablock_ATR( uint8_t* pAtr, uint8_t* pLength )
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t j;
|
uint32_t j;
|
||||||
uint32_t y;
|
uint32_t y;
|
||||||
uint32_t status = 0;
|
uint32_t status = 0;
|
||||||
|
|
||||||
*pLength = 0;
|
*pLength = 0;
|
||||||
|
|
||||||
/* Read ATR TS */
|
/* Read ATR TS */
|
||||||
// FIXME: There should always be a check for the GetChar return value..0 means timeout
|
// FIXME: There should always be a check for the GetChar return value..0 means timeout
|
||||||
status = ISO7816_GetChar(&pAtr[0], &usart_sim);
|
status = ISO7816_GetChar(&pAtr[0], &usart_sim);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read ATR T0 */
|
/* Read ATR T0 */
|
||||||
status = ISO7816_GetChar(&pAtr[1], &usart_sim);
|
status = ISO7816_GetChar(&pAtr[1], &usart_sim);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
y = pAtr[1] & 0xF0;
|
y = pAtr[1] & 0xF0;
|
||||||
i = 2;
|
i = 2;
|
||||||
|
|
||||||
/* Read ATR Ti */
|
/* Read ATR Ti */
|
||||||
while (y && (status == 0)) {
|
while (y && (status == 0)) {
|
||||||
|
|
||||||
if (y & 0x10) { /* TA[i] */
|
if (y & 0x10) { /* TA[i] */
|
||||||
status = ISO7816_GetChar(&pAtr[i++], &usart_sim);
|
status = ISO7816_GetChar(&pAtr[i++], &usart_sim);
|
||||||
}
|
}
|
||||||
if (y & 0x20) { /* TB[i] */
|
if (y & 0x20) { /* TB[i] */
|
||||||
status = ISO7816_GetChar(&pAtr[i++], &usart_sim);
|
status = ISO7816_GetChar(&pAtr[i++], &usart_sim);
|
||||||
}
|
}
|
||||||
if (y & 0x40) { /* TC[i] */
|
if (y & 0x40) { /* TC[i] */
|
||||||
status = ISO7816_GetChar(&pAtr[i++], &usart_sim);
|
status = ISO7816_GetChar(&pAtr[i++], &usart_sim);
|
||||||
}
|
}
|
||||||
if (y & 0x80) { /* TD[i] */
|
if (y & 0x80) { /* TD[i] */
|
||||||
status = ISO7816_GetChar(&pAtr[i], &usart_sim);
|
status = ISO7816_GetChar(&pAtr[i], &usart_sim);
|
||||||
y = pAtr[i++] & 0xF0;
|
y = pAtr[i++] & 0xF0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
y = 0;
|
y = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Historical Bytes */
|
/* Historical Bytes */
|
||||||
y = pAtr[1] & 0x0F;
|
y = pAtr[1] & 0x0F;
|
||||||
for( j=0; (j < y) && (status == 0); j++ ) {
|
for( j=0; (j < y) && (status == 0); j++ ) {
|
||||||
status = ISO7816_GetChar(&pAtr[i++], &usart_sim);
|
status = ISO7816_GetChar(&pAtr[i++], &usart_sim);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pLength = i;
|
*pLength = i;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -473,18 +473,18 @@ uint32_t ISO7816_Datablock_ATR( uint8_t* pAtr, uint8_t* pLength )
|
|||||||
*/
|
*/
|
||||||
void ISO7816_SetDataRateandClockFrequency( uint32_t dwClockFrequency, uint32_t dwDataRate )
|
void ISO7816_SetDataRateandClockFrequency( uint32_t dwClockFrequency, uint32_t dwDataRate )
|
||||||
{
|
{
|
||||||
uint8_t ClockFrequency;
|
uint8_t ClockFrequency;
|
||||||
|
|
||||||
/* Define the baud rate divisor register */
|
/* Define the baud rate divisor register */
|
||||||
/* CD = MCK / SCK */
|
/* CD = MCK / SCK */
|
||||||
/* SCK = FIDI x BAUD = 372 x 9600 */
|
/* SCK = FIDI x BAUD = 372 x 9600 */
|
||||||
/* BOARD_MCK */
|
/* BOARD_MCK */
|
||||||
/* CD = MCK/(FIDI x BAUD) = 48000000 / (372x9600) = 13 */
|
/* CD = MCK/(FIDI x BAUD) = 48000000 / (372x9600) = 13 */
|
||||||
USART_SIM->US_BRGR = BOARD_MCK / (dwClockFrequency*1000);
|
USART_SIM->US_BRGR = BOARD_MCK / (dwClockFrequency*1000);
|
||||||
|
|
||||||
ClockFrequency = BOARD_MCK / USART_SIM->US_BRGR;
|
ClockFrequency = BOARD_MCK / USART_SIM->US_BRGR;
|
||||||
|
|
||||||
USART_SIM->US_FIDI = (ClockFrequency)/dwDataRate;
|
USART_SIM->US_FIDI = (ClockFrequency)/dwDataRate;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -494,10 +494,10 @@ void ISO7816_SetDataRateandClockFrequency( uint32_t dwClockFrequency, uint32_t d
|
|||||||
*/
|
*/
|
||||||
uint8_t ISO7816_StatusReset( void )
|
uint8_t ISO7816_StatusReset( void )
|
||||||
{
|
{
|
||||||
if (st_pinIso7816RstMC) {
|
if (st_pinIso7816RstMC) {
|
||||||
return PIO_Get(st_pinIso7816RstMC);
|
return PIO_Get(st_pinIso7816RstMC);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -505,16 +505,16 @@ uint8_t ISO7816_StatusReset( void )
|
|||||||
*/
|
*/
|
||||||
void ISO7816_cold_reset( void )
|
void ISO7816_cold_reset( void )
|
||||||
{
|
{
|
||||||
volatile uint32_t i;
|
volatile uint32_t i;
|
||||||
|
|
||||||
/* tb: wait ??? cycles*/
|
/* tb: wait ??? cycles*/
|
||||||
for( i=0; i<(400*(BOARD_MCK/1000000)); i++ ) {
|
for( i=0; i<(400*(BOARD_MCK/1000000)); i++ ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
USART_SIM->US_RHR;
|
USART_SIM->US_RHR;
|
||||||
USART_SIM->US_CR = US_CR_RSTSTA | US_CR_RSTIT | US_CR_RSTNACK;
|
USART_SIM->US_CR = US_CR_RSTSTA | US_CR_RSTIT | US_CR_RSTNACK;
|
||||||
|
|
||||||
ISO7816_IccPowerOn();
|
ISO7816_IccPowerOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -522,20 +522,20 @@ void ISO7816_cold_reset( void )
|
|||||||
*/
|
*/
|
||||||
void ISO7816_warm_reset( void )
|
void ISO7816_warm_reset( void )
|
||||||
{
|
{
|
||||||
volatile uint32_t i;
|
volatile uint32_t i;
|
||||||
|
|
||||||
// Clears Reset
|
// Clears Reset
|
||||||
ISO7816_IccPowerOff();
|
ISO7816_IccPowerOff();
|
||||||
|
|
||||||
/* tb: wait ??? cycles */
|
/* tb: wait ??? cycles */
|
||||||
for( i=0; i<(400*(BOARD_MCK/1000000)); i++ ) {
|
for( i=0; i<(400*(BOARD_MCK/1000000)); i++ ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
USART_SIM->US_RHR;
|
USART_SIM->US_RHR;
|
||||||
USART_SIM->US_CR = US_CR_RSTSTA | US_CR_RSTIT | US_CR_RSTNACK;
|
USART_SIM->US_CR = US_CR_RSTSTA | US_CR_RSTIT | US_CR_RSTNACK;
|
||||||
|
|
||||||
// Sets Reset
|
// Sets Reset
|
||||||
ISO7816_IccPowerOn();
|
ISO7816_IccPowerOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -544,99 +544,99 @@ void ISO7816_warm_reset( void )
|
|||||||
*/
|
*/
|
||||||
void ISO7816_Decode_ATR( uint8_t* pAtr )
|
void ISO7816_Decode_ATR( uint8_t* pAtr )
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t j;
|
uint32_t j;
|
||||||
uint32_t y;
|
uint32_t y;
|
||||||
uint8_t offset;
|
uint8_t offset;
|
||||||
|
|
||||||
printf("\n\r");
|
printf("\n\r");
|
||||||
printf("ATR: Answer To Reset:\n\r");
|
printf("ATR: Answer To Reset:\n\r");
|
||||||
printf("TS = 0x%X Initial character ",pAtr[0]);
|
printf("TS = 0x%X Initial character ",pAtr[0]);
|
||||||
if( pAtr[0] == 0x3B ) {
|
if( pAtr[0] == 0x3B ) {
|
||||||
|
|
||||||
printf("Direct Convention\n\r");
|
printf("Direct Convention\n\r");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if( pAtr[0] == 0x3F ) {
|
if( pAtr[0] == 0x3F ) {
|
||||||
|
|
||||||
printf("Inverse Convention\n\r");
|
printf("Inverse Convention\n\r");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("BAD Convention\n\r");
|
printf("BAD Convention\n\r");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("T0 = 0x%X Format caracter\n\r",pAtr[1]);
|
printf("T0 = 0x%X Format caracter\n\r",pAtr[1]);
|
||||||
printf(" Number of historical bytes: K = %d\n\r", pAtr[1]&0x0F);
|
printf(" Number of historical bytes: K = %d\n\r", pAtr[1]&0x0F);
|
||||||
printf(" Presence further interface byte:\n\r");
|
printf(" Presence further interface byte:\n\r");
|
||||||
if( pAtr[1]&0x80 ) {
|
if( pAtr[1]&0x80 ) {
|
||||||
printf("TA ");
|
printf("TA ");
|
||||||
}
|
}
|
||||||
if( pAtr[1]&0x40 ) {
|
if( pAtr[1]&0x40 ) {
|
||||||
printf("TB ");
|
printf("TB ");
|
||||||
}
|
}
|
||||||
if( pAtr[1]&0x20 ) {
|
if( pAtr[1]&0x20 ) {
|
||||||
printf("TC ");
|
printf("TC ");
|
||||||
}
|
}
|
||||||
if( pAtr[1]&0x10 ) {
|
if( pAtr[1]&0x10 ) {
|
||||||
printf("TD ");
|
printf("TD ");
|
||||||
}
|
}
|
||||||
if( pAtr[1] != 0 ) {
|
if( pAtr[1] != 0 ) {
|
||||||
printf(" present\n\r");
|
printf(" present\n\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 2;
|
i = 2;
|
||||||
y = pAtr[1] & 0xF0;
|
y = pAtr[1] & 0xF0;
|
||||||
|
|
||||||
/* Read ATR Ti */
|
/* Read ATR Ti */
|
||||||
offset = 1;
|
offset = 1;
|
||||||
while (y) {
|
while (y) {
|
||||||
|
|
||||||
if (y & 0x10) { /* TA[i] */
|
if (y & 0x10) { /* TA[i] */
|
||||||
printf("TA[%d] = 0x%X ", offset, pAtr[i]);
|
printf("TA[%d] = 0x%X ", offset, pAtr[i]);
|
||||||
if( offset == 1 ) {
|
if( offset == 1 ) {
|
||||||
printf("FI = %d ", (pAtr[i]>>8));
|
printf("FI = %d ", (pAtr[i]>>8));
|
||||||
printf("DI = %d", (pAtr[i]&0x0F));
|
printf("DI = %d", (pAtr[i]&0x0F));
|
||||||
}
|
}
|
||||||
printf("\n\r");
|
printf("\n\r");
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (y & 0x20) { /* TB[i] */
|
if (y & 0x20) { /* TB[i] */
|
||||||
printf("TB[%d] = 0x%X\n\r", offset, pAtr[i]);
|
printf("TB[%d] = 0x%X\n\r", offset, pAtr[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (y & 0x40) { /* TC[i] */
|
if (y & 0x40) { /* TC[i] */
|
||||||
printf("TC[%d] = 0x%X ", offset, pAtr[i]);
|
printf("TC[%d] = 0x%X ", offset, pAtr[i]);
|
||||||
if( offset == 1 ) {
|
if( offset == 1 ) {
|
||||||
printf("Extra Guard Time: N = %d", pAtr[i]);
|
printf("Extra Guard Time: N = %d", pAtr[i]);
|
||||||
}
|
}
|
||||||
printf("\n\r");
|
printf("\n\r");
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (y & 0x80) { /* TD[i] */
|
if (y & 0x80) { /* TD[i] */
|
||||||
printf("TD[%d] = 0x%X\n\r", offset, pAtr[i]);
|
printf("TD[%d] = 0x%X\n\r", offset, pAtr[i]);
|
||||||
y = pAtr[i++] & 0xF0;
|
y = pAtr[i++] & 0xF0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
y = 0;
|
y = 0;
|
||||||
}
|
}
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Historical Bytes */
|
/* Historical Bytes */
|
||||||
printf("Historical bytes:\n\r");
|
printf("Historical bytes:\n\r");
|
||||||
y = pAtr[1] & 0x0F;
|
y = pAtr[1] & 0x0F;
|
||||||
for( j=0; j < y; j++ ) {
|
for( j=0; j < y; j++ ) {
|
||||||
printf(" 0x%X", pAtr[i]);
|
printf(" 0x%X", pAtr[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
printf("\n\r\n\r");
|
printf("\n\r\n\r");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ISO7816_Set_Reset_Pin(const Pin *pPinIso7816RstMC) {
|
void ISO7816_Set_Reset_Pin(const Pin *pPinIso7816RstMC) {
|
||||||
/* Pin ISO7816 initialize */
|
/* Pin ISO7816 initialize */
|
||||||
st_pinIso7816RstMC = (Pin *)pPinIso7816RstMC;
|
st_pinIso7816RstMC = (Pin *)pPinIso7816RstMC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initializes a ISO driver
|
/** Initializes a ISO driver
|
||||||
@@ -644,46 +644,46 @@ void ISO7816_Set_Reset_Pin(const Pin *pPinIso7816RstMC) {
|
|||||||
*/
|
*/
|
||||||
void ISO7816_Init( Usart_info *usart, bool master_clock )
|
void ISO7816_Init( Usart_info *usart, bool master_clock )
|
||||||
{
|
{
|
||||||
uint32_t clk;
|
uint32_t clk;
|
||||||
TRACE_DEBUG("ISO_Init\n\r");
|
TRACE_DEBUG("ISO_Init\n\r");
|
||||||
|
|
||||||
Usart *us_base = usart->base;
|
Usart *us_base = usart->base;
|
||||||
uint32_t us_id = usart->id;
|
uint32_t us_id = usart->id;
|
||||||
|
|
||||||
if (master_clock == true) {
|
if (master_clock == true) {
|
||||||
clk = US_MR_USCLKS_MCK;
|
clk = US_MR_USCLKS_MCK;
|
||||||
} else {
|
} else {
|
||||||
clk = US_MR_USCLKS_SCK;
|
clk = US_MR_USCLKS_SCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
USART_Configure( us_base,
|
USART_Configure( us_base,
|
||||||
US_MR_USART_MODE_IS07816_T_0
|
US_MR_USART_MODE_IS07816_T_0
|
||||||
| clk
|
| clk
|
||||||
| US_MR_NBSTOP_1_BIT
|
| US_MR_NBSTOP_1_BIT
|
||||||
| US_MR_PAR_EVEN
|
| US_MR_PAR_EVEN
|
||||||
| US_MR_CHRL_8_BIT
|
| US_MR_CHRL_8_BIT
|
||||||
| US_MR_CLKO
|
| US_MR_CLKO
|
||||||
| US_MR_INACK /* Inhibit errors */
|
| US_MR_INACK /* Inhibit errors */
|
||||||
| (3<<24), /* MAX_ITERATION */
|
| (3<<24), /* MAX_ITERATION */
|
||||||
1,
|
1,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
/* Disable interrupts */
|
/* Disable interrupts */
|
||||||
us_base->US_IDR = (uint32_t) -1;
|
us_base->US_IDR = (uint32_t) -1;
|
||||||
|
|
||||||
/* Configure USART */
|
/* Configure USART */
|
||||||
PMC_EnablePeripheral(us_id);
|
PMC_EnablePeripheral(us_id);
|
||||||
|
|
||||||
us_base->US_FIDI = 372; /* by default */
|
us_base->US_FIDI = 372; /* by default */
|
||||||
/* Define the baud rate divisor register */
|
/* Define the baud rate divisor register */
|
||||||
/* CD = MCK / SCK */
|
/* CD = MCK / SCK */
|
||||||
/* SCK = FIDI x BAUD = 372 x 9600 */
|
/* SCK = FIDI x BAUD = 372 x 9600 */
|
||||||
/* BOARD_MCK */
|
/* BOARD_MCK */
|
||||||
/* CD = MCK/(FIDI x BAUD) = 48000000 / (372x9600) = 13 */
|
/* CD = MCK/(FIDI x BAUD) = 48000000 / (372x9600) = 13 */
|
||||||
if (master_clock == true) {
|
if (master_clock == true) {
|
||||||
us_base->US_BRGR = BOARD_MCK / (372*9600);
|
us_base->US_BRGR = BOARD_MCK / (372*9600);
|
||||||
} else {
|
} else {
|
||||||
us_base->US_BRGR = US_BRGR_CD(1);
|
us_base->US_BRGR = US_BRGR_CD(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ static void usart_irq_rx(uint8_t inst_num)
|
|||||||
csr = usart->US_CSR & usart->US_IMR;
|
csr = usart->US_CSR & usart->US_IMR;
|
||||||
|
|
||||||
if (csr & US_CSR_RXRDY) {
|
if (csr & US_CSR_RXRDY) {
|
||||||
byte = (usart->US_RHR) & 0xFF;
|
byte = (usart->US_RHR) & 0xFF;
|
||||||
if (rbuf_write(&ci->rb, byte) < 0)
|
if (rbuf_write(&ci->rb, byte) < 0)
|
||||||
TRACE_ERROR("rbuf overrun\r\n");
|
TRACE_ERROR("rbuf overrun\r\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,11 +84,11 @@ static const Pin pinSmartCard = SMARTCARD_CONNECT_PIN;
|
|||||||
static void ISR_PioSmartCard(const Pin * pPin)
|
static void ISR_PioSmartCard(const Pin * pPin)
|
||||||
{
|
{
|
||||||
/* FIXME: why is pinSmartCard.pio->PIO_ISR the wrong number?
|
/* FIXME: why is pinSmartCard.pio->PIO_ISR the wrong number?
|
||||||
printf("+++++ Trying to check for pending interrupts (PIO ISR: 0x%X)\n\r", pinSmartCard.pio->PIO_ISR);
|
printf("+++++ Trying to check for pending interrupts (PIO ISR: 0x%X)\n\r", pinSmartCard.pio->PIO_ISR);
|
||||||
printf("+++++ Mask: 0x%X\n\r", pinSmartCard.mask);
|
printf("+++++ Mask: 0x%X\n\r", pinSmartCard.mask);
|
||||||
Output:
|
Output:
|
||||||
+++++ Trying to check for pending interrupts (PIO ISR: 0x400)) = 1<<10
|
+++++ Trying to check for pending interrupts (PIO ISR: 0x400)) = 1<<10
|
||||||
+++++ Mask: 0x100 = 1<<8
|
+++++ Mask: 0x100 = 1<<8
|
||||||
*/
|
*/
|
||||||
// PA10 is DTXD, which is the debug uart transmit pin
|
// PA10 is DTXD, which is the debug uart transmit pin
|
||||||
|
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ FILE* const stderr = NULL;
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int PutChar(char *pStr, char c)
|
signed int PutChar(char *pStr, char c)
|
||||||
{
|
{
|
||||||
*pStr = c;
|
*pStr = c;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -89,15 +89,15 @@ signed int PutChar(char *pStr, char c)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int PutString(char *pStr, const char *pSource)
|
signed int PutString(char *pStr, const char *pSource)
|
||||||
{
|
{
|
||||||
signed int num = 0;
|
signed int num = 0;
|
||||||
|
|
||||||
while (*pSource != 0) {
|
while (*pSource != 0) {
|
||||||
|
|
||||||
*pStr++ = *pSource++;
|
*pStr++ = *pSource++;
|
||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -110,38 +110,38 @@ signed int PutString(char *pStr, const char *pSource)
|
|||||||
// \param value Integer value.
|
// \param value Integer value.
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int PutUnsignedInt(
|
signed int PutUnsignedInt(
|
||||||
char *pStr,
|
char *pStr,
|
||||||
char fill,
|
char fill,
|
||||||
signed int width,
|
signed int width,
|
||||||
unsigned int value)
|
unsigned int value)
|
||||||
{
|
{
|
||||||
signed int num = 0;
|
signed int num = 0;
|
||||||
|
|
||||||
// Take current digit into account when calculating width
|
// Take current digit into account when calculating width
|
||||||
width--;
|
width--;
|
||||||
|
|
||||||
// Recursively write upper digits
|
// Recursively write upper digits
|
||||||
if ((value / 10) > 0) {
|
if ((value / 10) > 0) {
|
||||||
|
|
||||||
num = PutUnsignedInt(pStr, fill, width, value / 10);
|
num = PutUnsignedInt(pStr, fill, width, value / 10);
|
||||||
pStr += num;
|
pStr += num;
|
||||||
}
|
}
|
||||||
// Write filler characters
|
// Write filler characters
|
||||||
else {
|
else {
|
||||||
|
|
||||||
while (width > 0) {
|
while (width > 0) {
|
||||||
|
|
||||||
PutChar(pStr, fill);
|
PutChar(pStr, fill);
|
||||||
pStr++;
|
pStr++;
|
||||||
num++;
|
num++;
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write lower digit
|
// Write lower digit
|
||||||
num += PutChar(pStr, (value % 10) + '0');
|
num += PutChar(pStr, (value % 10) + '0');
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -154,69 +154,69 @@ signed int PutUnsignedInt(
|
|||||||
// \param value Signed integer value.
|
// \param value Signed integer value.
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int PutSignedInt(
|
signed int PutSignedInt(
|
||||||
char *pStr,
|
char *pStr,
|
||||||
char fill,
|
char fill,
|
||||||
signed int width,
|
signed int width,
|
||||||
signed int value)
|
signed int value)
|
||||||
{
|
{
|
||||||
signed int num = 0;
|
signed int num = 0;
|
||||||
unsigned int absolute;
|
unsigned int absolute;
|
||||||
|
|
||||||
// Compute absolute value
|
// Compute absolute value
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
|
|
||||||
absolute = -value;
|
absolute = -value;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
absolute = value;
|
absolute = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take current digit into account when calculating width
|
// Take current digit into account when calculating width
|
||||||
width--;
|
width--;
|
||||||
|
|
||||||
// Recursively write upper digits
|
// Recursively write upper digits
|
||||||
if ((absolute / 10) > 0) {
|
if ((absolute / 10) > 0) {
|
||||||
|
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
|
|
||||||
num = PutSignedInt(pStr, fill, width, -(absolute / 10));
|
num = PutSignedInt(pStr, fill, width, -(absolute / 10));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
num = PutSignedInt(pStr, fill, width, absolute / 10);
|
num = PutSignedInt(pStr, fill, width, absolute / 10);
|
||||||
}
|
}
|
||||||
pStr += num;
|
pStr += num;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
// Reserve space for sign
|
// Reserve space for sign
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
|
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write filler characters
|
// Write filler characters
|
||||||
while (width > 0) {
|
while (width > 0) {
|
||||||
|
|
||||||
PutChar(pStr, fill);
|
PutChar(pStr, fill);
|
||||||
pStr++;
|
pStr++;
|
||||||
num++;
|
num++;
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write sign
|
// Write sign
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
|
|
||||||
num += PutChar(pStr, '-');
|
num += PutChar(pStr, '-');
|
||||||
pStr++;
|
pStr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write lower digit
|
// Write lower digit
|
||||||
num += PutChar(pStr, (absolute % 10) + '0');
|
num += PutChar(pStr, (absolute % 10) + '0');
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -230,51 +230,51 @@ signed int PutSignedInt(
|
|||||||
// \param value Hexadecimal value.
|
// \param value Hexadecimal value.
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int PutHexa(
|
signed int PutHexa(
|
||||||
char *pStr,
|
char *pStr,
|
||||||
char fill,
|
char fill,
|
||||||
signed int width,
|
signed int width,
|
||||||
unsigned char maj,
|
unsigned char maj,
|
||||||
unsigned int value)
|
unsigned int value)
|
||||||
{
|
{
|
||||||
signed int num = 0;
|
signed int num = 0;
|
||||||
|
|
||||||
// Decrement width
|
// Decrement width
|
||||||
width--;
|
width--;
|
||||||
|
|
||||||
// Recursively output upper digits
|
// Recursively output upper digits
|
||||||
if ((value >> 4) > 0) {
|
if ((value >> 4) > 0) {
|
||||||
|
|
||||||
num += PutHexa(pStr, fill, width, maj, value >> 4);
|
num += PutHexa(pStr, fill, width, maj, value >> 4);
|
||||||
pStr += num;
|
pStr += num;
|
||||||
}
|
}
|
||||||
// Write filler chars
|
// Write filler chars
|
||||||
else {
|
else {
|
||||||
|
|
||||||
while (width > 0) {
|
while (width > 0) {
|
||||||
|
|
||||||
PutChar(pStr, fill);
|
PutChar(pStr, fill);
|
||||||
pStr++;
|
pStr++;
|
||||||
num++;
|
num++;
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write current digit
|
// Write current digit
|
||||||
if ((value & 0xF) < 10) {
|
if ((value & 0xF) < 10) {
|
||||||
|
|
||||||
PutChar(pStr, (value & 0xF) + '0');
|
PutChar(pStr, (value & 0xF) + '0');
|
||||||
}
|
}
|
||||||
else if (maj) {
|
else if (maj) {
|
||||||
|
|
||||||
PutChar(pStr, (value & 0xF) - 10 + 'A');
|
PutChar(pStr, (value & 0xF) - 10 + 'A');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
PutChar(pStr, (value & 0xF) - 10 + 'a');
|
PutChar(pStr, (value & 0xF) - 10 + 'a');
|
||||||
}
|
}
|
||||||
num++;
|
num++;
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -292,91 +292,91 @@ signed int PutHexa(
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int vsnprintf(char *pStr, size_t length, const char *pFormat, va_list ap)
|
signed int vsnprintf(char *pStr, size_t length, const char *pFormat, va_list ap)
|
||||||
{
|
{
|
||||||
char fill;
|
char fill;
|
||||||
unsigned char width;
|
unsigned char width;
|
||||||
signed int num = 0;
|
signed int num = 0;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
// Clear the string
|
// Clear the string
|
||||||
if (pStr) {
|
if (pStr) {
|
||||||
|
|
||||||
*pStr = 0;
|
*pStr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Phase string
|
// Phase string
|
||||||
while (*pFormat != 0 && size < length) {
|
while (*pFormat != 0 && size < length) {
|
||||||
|
|
||||||
// Normal character
|
// Normal character
|
||||||
if (*pFormat != '%') {
|
if (*pFormat != '%') {
|
||||||
|
|
||||||
*pStr++ = *pFormat++;
|
*pStr++ = *pFormat++;
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
// Escaped '%'
|
// Escaped '%'
|
||||||
else if (*(pFormat+1) == '%') {
|
else if (*(pFormat+1) == '%') {
|
||||||
|
|
||||||
*pStr++ = '%';
|
*pStr++ = '%';
|
||||||
pFormat += 2;
|
pFormat += 2;
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
// Token delimiter
|
// Token delimiter
|
||||||
else {
|
else {
|
||||||
|
|
||||||
fill = ' ';
|
fill = ' ';
|
||||||
width = 0;
|
width = 0;
|
||||||
pFormat++;
|
pFormat++;
|
||||||
|
|
||||||
// Parse filler
|
// Parse filler
|
||||||
if (*pFormat == '0') {
|
if (*pFormat == '0') {
|
||||||
|
|
||||||
fill = '0';
|
fill = '0';
|
||||||
pFormat++;
|
pFormat++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse width
|
// Parse width
|
||||||
while ((*pFormat >= '0') && (*pFormat <= '9')) {
|
while ((*pFormat >= '0') && (*pFormat <= '9')) {
|
||||||
|
|
||||||
width = (width*10) + *pFormat-'0';
|
width = (width*10) + *pFormat-'0';
|
||||||
pFormat++;
|
pFormat++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there is enough space
|
// Check if there is enough space
|
||||||
if (size + width > length) {
|
if (size + width > length) {
|
||||||
|
|
||||||
width = length - size;
|
width = length - size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse type
|
// Parse type
|
||||||
switch (*pFormat) {
|
switch (*pFormat) {
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'i': num = PutSignedInt(pStr, fill, width, va_arg(ap, signed int)); break;
|
case 'i': num = PutSignedInt(pStr, fill, width, va_arg(ap, signed int)); break;
|
||||||
case 'u': num = PutUnsignedInt(pStr, fill, width, va_arg(ap, unsigned int)); break;
|
case 'u': num = PutUnsignedInt(pStr, fill, width, va_arg(ap, unsigned int)); break;
|
||||||
case 'x': num = PutHexa(pStr, fill, width, 0, va_arg(ap, unsigned int)); break;
|
case 'x': num = PutHexa(pStr, fill, width, 0, va_arg(ap, unsigned int)); break;
|
||||||
case 'X': num = PutHexa(pStr, fill, width, 1, va_arg(ap, unsigned int)); break;
|
case 'X': num = PutHexa(pStr, fill, width, 1, va_arg(ap, unsigned int)); break;
|
||||||
case 's': num = PutString(pStr, va_arg(ap, char *)); break;
|
case 's': num = PutString(pStr, va_arg(ap, char *)); break;
|
||||||
case 'c': num = PutChar(pStr, va_arg(ap, unsigned int)); break;
|
case 'c': num = PutChar(pStr, va_arg(ap, unsigned int)); break;
|
||||||
default:
|
default:
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
pFormat++;
|
pFormat++;
|
||||||
pStr += num;
|
pStr += num;
|
||||||
size += num;
|
size += num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NULL-terminated (final \0 is not counted)
|
// NULL-terminated (final \0 is not counted)
|
||||||
if (size < length) {
|
if (size < length) {
|
||||||
|
|
||||||
*pStr = 0;
|
*pStr = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
*(--pStr) = 0;
|
*(--pStr) = 0;
|
||||||
size--;
|
size--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -390,14 +390,14 @@ signed int vsnprintf(char *pStr, size_t length, const char *pFormat, va_list ap)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int snprintf(char *pString, size_t length, const char *pFormat, ...)
|
signed int snprintf(char *pString, size_t length, const char *pFormat, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
signed int rc;
|
signed int rc;
|
||||||
|
|
||||||
va_start(ap, pFormat);
|
va_start(ap, pFormat);
|
||||||
rc = vsnprintf(pString, length, pFormat, ap);
|
rc = vsnprintf(pString, length, pFormat, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -410,7 +410,7 @@ signed int snprintf(char *pString, size_t length, const char *pFormat, ...)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int vsprintf(char *pString, const char *pFormat, va_list ap)
|
signed int vsprintf(char *pString, const char *pFormat, va_list ap)
|
||||||
{
|
{
|
||||||
return vsnprintf(pString, MAX_STRING_SIZE, pFormat, ap);
|
return vsnprintf(pString, MAX_STRING_SIZE, pFormat, ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -422,17 +422,17 @@ signed int vsprintf(char *pString, const char *pFormat, va_list ap)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int vfprintf(FILE *pStream, const char *pFormat, va_list ap)
|
signed int vfprintf(FILE *pStream, const char *pFormat, va_list ap)
|
||||||
{
|
{
|
||||||
char pStr[MAX_STRING_SIZE];
|
char pStr[MAX_STRING_SIZE];
|
||||||
char pError[] = "stdio.c: increase MAX_STRING_SIZE\n\r";
|
char pError[] = "stdio.c: increase MAX_STRING_SIZE\n\r";
|
||||||
|
|
||||||
// Write formatted string in buffer
|
// Write formatted string in buffer
|
||||||
if (vsprintf(pStr, pFormat, ap) >= MAX_STRING_SIZE) {
|
if (vsprintf(pStr, pFormat, ap) >= MAX_STRING_SIZE) {
|
||||||
|
|
||||||
fputs(pError, stderr);
|
fputs(pError, stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display string
|
// Display string
|
||||||
return fputs(pStr, pStream);
|
return fputs(pStr, pStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -443,7 +443,7 @@ signed int vfprintf(FILE *pStream, const char *pFormat, va_list ap)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int vprintf(const char *pFormat, va_list ap)
|
signed int vprintf(const char *pFormat, va_list ap)
|
||||||
{
|
{
|
||||||
return vfprintf(stdout, pFormat, ap);
|
return vfprintf(stdout, pFormat, ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -454,15 +454,15 @@ signed int vprintf(const char *pFormat, va_list ap)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int fprintf(FILE *pStream, const char *pFormat, ...)
|
signed int fprintf(FILE *pStream, const char *pFormat, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
signed int result;
|
signed int result;
|
||||||
|
|
||||||
// Forward call to vfprintf
|
// Forward call to vfprintf
|
||||||
va_start(ap, pFormat);
|
va_start(ap, pFormat);
|
||||||
result = vfprintf(pStream, pFormat, ap);
|
result = vfprintf(pStream, pFormat, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -472,15 +472,15 @@ signed int fprintf(FILE *pStream, const char *pFormat, ...)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int printf(const char *pFormat, ...)
|
signed int printf(const char *pFormat, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
signed int result;
|
signed int result;
|
||||||
|
|
||||||
// Forward call to vprintf
|
// Forward call to vprintf
|
||||||
va_start(ap, pFormat);
|
va_start(ap, pFormat);
|
||||||
result = vprintf(pFormat, ap);
|
result = vprintf(pFormat, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -490,15 +490,15 @@ signed int printf(const char *pFormat, ...)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int sprintf(char *pStr, const char *pFormat, ...)
|
signed int sprintf(char *pStr, const char *pFormat, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
signed int result;
|
signed int result;
|
||||||
|
|
||||||
// Forward call to vsprintf
|
// Forward call to vsprintf
|
||||||
va_start(ap, pFormat);
|
va_start(ap, pFormat);
|
||||||
result = vsprintf(pStr, pFormat, ap);
|
result = vsprintf(pStr, pFormat, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -507,6 +507,6 @@ signed int sprintf(char *pStr, const char *pFormat, ...)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
signed int puts(const char *pStr)
|
signed int puts(const char *pStr)
|
||||||
{
|
{
|
||||||
return fputs(pStr, stdout);
|
return fputs(pStr, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,33 +61,33 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void * memcpy(void *pDestination, const void *pSource, size_t num)
|
void * memcpy(void *pDestination, const void *pSource, size_t num)
|
||||||
{
|
{
|
||||||
unsigned char *pByteDestination;
|
unsigned char *pByteDestination;
|
||||||
unsigned char *pByteSource;
|
unsigned char *pByteSource;
|
||||||
unsigned int *pAlignedSource = (unsigned int *) pSource;
|
unsigned int *pAlignedSource = (unsigned int *) pSource;
|
||||||
unsigned int *pAlignedDestination = (unsigned int *) pDestination;
|
unsigned int *pAlignedDestination = (unsigned int *) pDestination;
|
||||||
|
|
||||||
// If num is more than 4 bytes, and both dest. and source are aligned,
|
// If num is more than 4 bytes, and both dest. and source are aligned,
|
||||||
// then copy dwords
|
// then copy dwords
|
||||||
if ((((unsigned int) pAlignedDestination & 0x3) == 0)
|
if ((((unsigned int) pAlignedDestination & 0x3) == 0)
|
||||||
&& (((unsigned int) pAlignedSource & 0x3) == 0)
|
&& (((unsigned int) pAlignedSource & 0x3) == 0)
|
||||||
&& (num >= 4)) {
|
&& (num >= 4)) {
|
||||||
|
|
||||||
while (num >= 4) {
|
while (num >= 4) {
|
||||||
|
|
||||||
*pAlignedDestination++ = *pAlignedSource++;
|
*pAlignedDestination++ = *pAlignedSource++;
|
||||||
num -= 4;
|
num -= 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy remaining bytes
|
// Copy remaining bytes
|
||||||
pByteDestination = (unsigned char *) pAlignedDestination;
|
pByteDestination = (unsigned char *) pAlignedDestination;
|
||||||
pByteSource = (unsigned char *) pAlignedSource;
|
pByteSource = (unsigned char *) pAlignedSource;
|
||||||
while (num--) {
|
while (num--) {
|
||||||
|
|
||||||
*pByteDestination++ = *pByteSource++;
|
*pByteDestination++ = *pByteSource++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pDestination;
|
return pDestination;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -99,23 +99,23 @@ void * memcpy(void *pDestination, const void *pSource, size_t num)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void * memset(void *pBuffer, int value, size_t num)
|
void * memset(void *pBuffer, int value, size_t num)
|
||||||
{
|
{
|
||||||
unsigned char *pByteDestination;
|
unsigned char *pByteDestination;
|
||||||
unsigned int *pAlignedDestination = (unsigned int *) pBuffer;
|
unsigned int *pAlignedDestination = (unsigned int *) pBuffer;
|
||||||
unsigned int alignedValue = (value << 24) | (value << 16) | (value << 8) | value;
|
unsigned int alignedValue = (value << 24) | (value << 16) | (value << 8) | value;
|
||||||
|
|
||||||
// Set words if possible
|
// Set words if possible
|
||||||
if ((((unsigned int) pAlignedDestination & 0x3) == 0) && (num >= 4)) {
|
if ((((unsigned int) pAlignedDestination & 0x3) == 0) && (num >= 4)) {
|
||||||
while (num >= 4) {
|
while (num >= 4) {
|
||||||
*pAlignedDestination++ = alignedValue;
|
*pAlignedDestination++ = alignedValue;
|
||||||
num -= 4;
|
num -= 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set remaining bytes
|
// Set remaining bytes
|
||||||
pByteDestination = (unsigned char *) pAlignedDestination;
|
pByteDestination = (unsigned char *) pAlignedDestination;
|
||||||
while (num--) {
|
while (num--) {
|
||||||
*pByteDestination++ = value;
|
*pByteDestination++ = value;
|
||||||
}
|
}
|
||||||
return pBuffer;
|
return pBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -126,16 +126,16 @@ void * memset(void *pBuffer, int value, size_t num)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
char * strchr(const char *pString, int character)
|
char * strchr(const char *pString, int character)
|
||||||
{
|
{
|
||||||
char * p = (char *)pString;
|
char * p = (char *)pString;
|
||||||
char c = character & 0xFF;
|
char c = character & 0xFF;
|
||||||
|
|
||||||
while(*p != c) {
|
while(*p != c) {
|
||||||
if (*p == 0) {
|
if (*p == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -144,12 +144,12 @@ char * strchr(const char *pString, int character)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
size_t strlen(const char *pString)
|
size_t strlen(const char *pString)
|
||||||
{
|
{
|
||||||
unsigned int length = 0;
|
unsigned int length = 0;
|
||||||
|
|
||||||
while(*pString++ != 0) {
|
while(*pString++ != 0) {
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -161,14 +161,14 @@ size_t strlen(const char *pString)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
char * strrchr(const char *pString, int character)
|
char * strrchr(const char *pString, int character)
|
||||||
{
|
{
|
||||||
char *p = 0;
|
char *p = 0;
|
||||||
|
|
||||||
while(*pString != 0) {
|
while(*pString != 0) {
|
||||||
if (*pString++ == character) {
|
if (*pString++ == character) {
|
||||||
p = (char*)pString;
|
p = (char*)pString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -179,10 +179,10 @@ char * strrchr(const char *pString, int character)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
char * strcpy(char *pDestination, const char *pSource)
|
char * strcpy(char *pDestination, const char *pSource)
|
||||||
{
|
{
|
||||||
char *pSaveDest = pDestination;
|
char *pSaveDest = pDestination;
|
||||||
|
|
||||||
for(; (*pDestination = *pSource) != 0; ++pSource, ++pDestination);
|
for(; (*pDestination = *pSource) != 0; ++pSource, ++pDestination);
|
||||||
return pSaveDest;
|
return pSaveDest;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -196,22 +196,22 @@ char * strcpy(char *pDestination, const char *pSource)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
int strncmp(const char *pString1, const char *pString2, size_t count)
|
int strncmp(const char *pString1, const char *pString2, size_t count)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
while(count) {
|
while(count) {
|
||||||
r = *pString1 - *pString2;
|
r = *pString1 - *pString2;
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
if (*pString1 == 0) {
|
if (*pString1 == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pString1++;
|
pString1++;
|
||||||
pString2++;
|
pString2++;
|
||||||
count--;
|
count--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -223,17 +223,17 @@ int strncmp(const char *pString1, const char *pString2, size_t count)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
char * strncpy(char *pDestination, const char *pSource, size_t count)
|
char * strncpy(char *pDestination, const char *pSource, size_t count)
|
||||||
{
|
{
|
||||||
char *pSaveDest = pDestination;
|
char *pSaveDest = pDestination;
|
||||||
|
|
||||||
while (count) {
|
while (count) {
|
||||||
*pDestination = *pSource;
|
*pDestination = *pSource;
|
||||||
if (*pSource == 0) {
|
if (*pSource == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pDestination++;
|
pDestination++;
|
||||||
pSource++;
|
pSource++;
|
||||||
count--;
|
count--;
|
||||||
}
|
}
|
||||||
return pSaveDest;
|
return pSaveDest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user