예제 #1
0
파일: iso7816.c 프로젝트: ddm/chipwhisperer
/**
 * \brief Initializes a ISO7816 interface device.
 *
 * \param p_usart_opt     Pointer to an ISO7816 instance.
 * \param ul_mck          USART module input clock frequency.
 * \param ul_rst_pin_idx  Control smart card RST pin index.
 */
unsigned int iso7816_init(const usart_iso7816_opt_t *p_usart_opt,
		uint32_t ul_mck, uint32_t ul_rst_pin_idx)
{
	/* Pin RST of ISO7816 initialize. */
	gs_ul_rst_pin_idx = ul_rst_pin_idx;
#if defined(SMART_CARD_USING_GPIO)
	gpio_set_pin_low(gs_ul_rst_pin_idx);
#elif defined(SMART_CARD_USING_IOPORT)
	ioport_set_pin_level(gs_ul_rst_pin_idx, IOPORT_PIN_LEVEL_LOW);
#endif
	/* Init the global variable for ISO7816. */
	g_ul_clk = ul_mck;

	if(usart_init_iso7816(ISO7816_USART, p_usart_opt, g_ul_clk)){
		return 1;
	}

	/* Disable interrupts. */
	usart_disable_interrupt(ISO7816_USART, 0xffffffff);

	/* Write the Timeguard Register. */
	usart_set_tx_timeguard(ISO7816_USART, 5);

	/* Enable TX and RX. */
	usart_enable_rx(ISO7816_USART);
	//usart_enable_tx(ISO7816_USART);
	
	return 0;
}
/**
 *  \brief USART RS485 mode configuration.
 *
 *  Configure USART in RS485 mode, asynchronous, 8 bits, 1 stop bit,
 *  no parity, 256000 bauds and enable its transmitter and receiver.
 */
void configure_usart(void)
{
	const sam_usart_opt_t usart_console_settings = {
		BOARD_USART_BAUDRATE,
		US_MR_CHRL_8_BIT,
		US_MR_PAR_NO,
		US_MR_NBSTOP_1_BIT,
		US_MR_CHMODE_NORMAL,
		/* This field is only used in IrDA mode. */
		0
	};

	/* Enable the peripheral clock in the PMC. */
	sysclk_enable_peripheral_clock(BOARD_ID_USART);

	/* Configure USART in RS485 mode. */
//jsi 7feb16 we want rs232 not rs485 for our application	usart_init_rs485(BOARD_USART, &usart_console_settings,
//jsi 7feb16 we want rs232 not rs485 for our application			sysclk_get_cpu_hz());
			
	usart_init_rs232(BOARD_USART, &usart_console_settings, sysclk_get_cpu_hz());

	/* enable transmitter timeguard, 4 bit period delay. */
	usart_set_tx_timeguard(BOARD_USART, 4);

	/* Disable all the interrupts. */
	usart_disable_interrupt(BOARD_USART, ALL_INTERRUPT_MASK);

	/* Enable TX & RX function. */
	usart_enable_tx(BOARD_USART);
	usart_enable_rx(BOARD_USART);

	/* Configure and enable interrupt of USART. */
	NVIC_EnableIRQ(USART_IRQn);
}