Even though functionfs forces us to use Linux AIO, we actually don't
want to submit multiple concurrent pendign writes, but we simply want
to emulate the poll/select interface. So we must introduce a write
(message) queue for the IN and IRQ endpoint, and we must always only
pull one message off the queue, submit the iocb. On completion, we
dequeue the next message, and so on.
Change-Id: I8f7026f13cf542185cfec4d4780c64965d1706e2
which is already sufficient to make pcsc_scan happy and list all
eight cards/slots like
Reader 1: sysmoOCTSIM Test Reader [Osmocom CCID Interface] (2342) 01 00
Event number: 0
Card state: Card removed,
Change-Id: I37bd952ef0add662d565150f70e83d85ffd0c254
talloc is a hirearchical memory allocator which Osmocom uses a lot
for its userspace programs on Linux. Experiments show that it's
actually very much possible to use it inside of microcontroller firmware
projects, particularly the small subset which we generally use.
Change-Id: Ibd31b40d5b75b3fc1783a6b02b0e97da430e0f60
this function takes care of reading and writing the complete TPDU
to the card.
note: the sim-iccid command uses this function, but still only to
select MF.
Change-Id: I50c90f3697580a4c93220a3e09cc33ec85889814
currently the sim-iccid command only selects MF.
this is a proof of concept for card communication.
the transmission/reception must be generalized to avoid copying
the code multiple times.
IMPORTANT: the sim-iccid commands only works after the sim-atr
command, which sets up the cards correctly
Change-Id: Icbcde783143694afce23af6e3f26bcd7a9a13b85
it will set the GCLK as SERCOM core clock with the lowest baud
rate error and set the closest baud rate in the SERCOM peripheral.
Change-Id: I01db273f4c8170a4942049653c575010b93296ce
the SERCOMM clock triplet 0.5 MHz (100 MHz / 200),
7.0588 MHz (120 MHz / 17), and 50 MHz (100 MHz / 2) allows to
generate all possible ISO 7816 baud rates (from
F = 2048 / D = 1 @ f = 2.5 MHz -> 1220 bps to
F = 372 / D = 64 @ f = 20 MHz -> 3.4 Mbps) with a maximum baud
rate error of 2.57 %, for available SIM clocks 2.5, 5, 10, 20 MHz.
2.57% means a bit more than quarter a bit might be wrong after the
11 bits ISO transmission (still less than half a bit).
This triplet is one of the optimum when 3 clocks are used.
An additional clock would be required for higher accuracy.
The 50 MHz clock is re-used from the RMII clock output.
Change-Id: I2c69848582e49031fa6453f535a2bf1408f8e22e
in hardware revision 2 the Ethernet PHY RMII_CLOCK input clock is
connected to the MCU pin PA10.
GCLK4 of the MCU now outputs the required 50 MHz clock on this pin.
the same clock is re-used for UART debug to generate the 921600
bps baud rate.
Change-Id: Id3a3dee15c3986536b0623d0f39ca62e94acd1fd
the standard async library expected the caller to wait until the
transmission was complete (by counting using the transmit callback
or checking using usart_async_get_status) before freeing/reusing
the memory holding the data to be transmitted.
this is not practical when using stdio on top of the peripheral
since printf returns directly and reuses the memory.
the new USART async library has a ring buffer for the data to be
transmitted (similar to the data being received).
WARNING: write is blocking when the TX buffer is full.
this prevents loosing data.
Change-Id: Iafd5295b90ef9f428f640314c24f6c31ee82c9d6
using the synchronous HAL library causes RX overflow after 5 bytes
on bulk incoming data (e.g. pasted).
this mainly due to printing synchronously the character, but to
further prevent congestion we switch to asynchronous (e.g.
interrupt driven) communication.
The RX part works great now (no overflow), but the TX part is
malfunctioning because the HAL Async library does not buffer the
data to be transmitted and expects it to be in memory until
the transmission is complete (which printf does not do).
This change will not be reflected in Atmel START since it does not
allow to set the underlying STDIO redirect peripheral to async.
Change-Id: If18883e96f336aa9f6b11607859260da5e1503c7
using the SWO signal on TX has the advantage of being able to
have printf debug while still using SERCOM7 in ISO7816 mode for
the SIM card, but it has two drawbacks:
- SWO outputs data only if a debug session is ongoing (e.g. a SWD
debugger is connected). this saves output processing when no SWD
is connected, but it is not possible to force output without
having an SWD debugger connect (confirmed by Microchip help),
which is not convenient for simple UART debugging.
- no input is possible (SWO can only output).
Thus instead we will still use SERCOM7 for UART debug, allowing
commands to be input.
SERCOM7 should only be used for UART debug when no card in present
in SIM7.
This check in not yet implemented.
Change-Id: I199d6e356129526e65d5d1075a264eb35904d099
we use the SERCOM peripheral for USART (in 7816 mode SIM card
communication) in synchronous mode (TX and RX clock are the same).
in this mode only the 8 least significant bits of the BAUD register
are used (see TRM 33.6.2.3 Clock Generation – Baud-Rate Generator).
When the SERCOM is clocked at 100 MHz the minimum resulting baud
rate would be 100E6 / (2 * 255 + 1) = 195694 bps.
clocking SERCOM at 3.33 MHz also to have a baud rate of 6720 bps
(~ 3.33E6 / (2 * 247 + 1)), used after reset to read the ATR.
Change-Id: Id60322e092a6652a89821fc737d5336d79a1420c
the ISO7816 I/O baud rate is f / (Fd / Dd), with Fd 372, Dd = 1.
f_max is 4 MHz, but we will use the minimum 20 / 8 = 2.5 MHz,
thus the baud rate after reset will be 6720 bps.
Change-Id: I9165575404f070c7429daaa3593838d08a5c5e10
as the code will use alternative libraries, the examples will not
be able to compile anymore.
plus they are not required for the firmware and the example code
can be downloaded from Atmel start.
Change-Id: If53df47089de9eb8498734c19d6a0420c1e79031
This is form Atmel Start and provides functionality for hardware-based
DMA copies from memory to memory.
Change-Id: Ib07755b2c5974af70817f5460fb0f358c631452a
In hardware, the Card RST pin is low-active. There's a level
translator in the NCN8025, but there's no logic inversion, so RSTIN
is also low-active. In software, we have the policy of all signals
being "true-active", i.e. true represents the active state, and false
the inactive state.
Hence, we must invert the logic of how we handle rstin.
Change-Id: Ia45246b7517b2e6ecb01d22b3af52aee7a51de64
The ncn8025 has no impact on the UART, so no matter if we use
SERCOM7 as debug uart or as SIM UART, we can always initialize
the NCN8025 and thereby allow control of (e.g.) the LED.
Change-Id: I70ae1e050d5540627bc77626dbf1b6040e95dae4