#define _BV(_x_) (1UL << (_x_)) void SetupSmartcardInterface(uint32_t f_max, uint32_t clock_in_etu, uint32_t etu_divider, int databits, int parity, int guardbits, int retries) { system_clock_divider = (SystemCoreClock + f_max - 1) / f_max; OSR = clock_in_etu / etu_divider; temp = _BV(3) | (0x1UL << 4) | (databits - 1) & 0x3; LPC_USART->LCR = temp | _BV(7);// databits&parity LPC_USART->DLM = (system_clock_divider >> 8) & 0xff; // Fmax(Hi) LPC_USART->DLL = system_clock_divider & 0xff; // Fmax(Low) LPC_USART->FDR = (DivAddVal & 0x0F) | ((MulVal & 0x0F) << 4);// Fmax(Low) LPC_USART->OSR = (OSR - 1) << 4; // Supesampling - Fi LPC_USART->LCR &= ~(1 << 7); /* DLAB = 0 */ LPC_USART->FCR = 0x07; /* Enable and reset TX and RX FIFO. */ LPC_USART->SCICTRL &= ~((0xffUL << 8) | (0x3UL << 5)); /* clear guard bits and retries */ LPC_USART->SCICTRL |= ((guardbits & 0xff) << 8) | /* guard bits */ ((retries & 0x7) << 5); /* retries */ LPC_USART->IER = IER_RBR | IER_RLS; /* Enable UART interrupt */ } |