mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-26 02:08:32 +03:00
Moved global Usart state into usart struct
This commit is contained in:
@@ -97,6 +97,7 @@
|
|||||||
|
|
||||||
typedef struct Usart_info {
|
typedef struct Usart_info {
|
||||||
Usart *base;
|
Usart *base;
|
||||||
|
uint8_t state;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
} Usart_info;
|
} Usart_info;
|
||||||
|
|
||||||
|
|||||||
@@ -60,12 +60,10 @@
|
|||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
* Internal variables
|
* Internal variables
|
||||||
*-----------------------------------------------------------------------------*/
|
*-----------------------------------------------------------------------------*/
|
||||||
/** Variable for state of send and receive froom USART */
|
|
||||||
static uint8_t StateUsartGlobal = USART_RCV;
|
|
||||||
/** Pin reset master card */
|
/** Pin reset master card */
|
||||||
static Pin *st_pinIso7816RstMC;
|
static Pin *st_pinIso7816RstMC;
|
||||||
|
|
||||||
struct Usart_info usart_sim = {.base = USART_SIM, .id = ID_USART_SIM};
|
struct Usart_info usart_sim = {.base = USART_SIM, .id = ID_USART_SIM, .state = USART_RCV};
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
* Internal functions
|
* Internal functions
|
||||||
@@ -84,10 +82,10 @@ uint32_t ISO7816_GetChar( uint8_t *pCharToReceive, Usart_info *usart)
|
|||||||
Usart *us_base = usart->base;
|
Usart *us_base = usart->base;
|
||||||
uint32_t us_id = usart->id;
|
uint32_t us_id = usart->id;
|
||||||
|
|
||||||
if( StateUsartGlobal == 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;
|
||||||
StateUsartGlobal = USART_RCV;
|
usart->state = USART_RCV;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait USART ready for reception */
|
/* Wait USART ready for reception */
|
||||||
@@ -133,9 +131,9 @@ uint32_t ISO7816_SendChar( uint8_t CharToSend, Usart_info *usart )
|
|||||||
|
|
||||||
TRACE_DEBUG("***Send char: 0x%X\n\r", CharToSend);
|
TRACE_DEBUG("***Send char: 0x%X\n\r", CharToSend);
|
||||||
|
|
||||||
if( StateUsartGlobal == 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;
|
||||||
StateUsartGlobal = USART_SEND;
|
usart->state = USART_SEND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait USART ready for transmit */
|
/* Wait USART ready for transmit */
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ static const Pin pinsPower[] = {PWR_PINS};
|
|||||||
static const Pin pinIso7816RstMC = PIN_ISO7816_RSTMC;
|
static const Pin pinIso7816RstMC = PIN_ISO7816_RSTMC;
|
||||||
static uint8_t sim_inserted = 0;
|
static uint8_t sim_inserted = 0;
|
||||||
|
|
||||||
static struct Usart_info usart_info = {.base = USART_SIM, .id = ID_USART_SIM};
|
static struct Usart_info usart_info = {.base = USART_SIM, .id = ID_USART_SIM, .state = USART_RCV};
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* Optional smartcard detection
|
* Optional smartcard detection
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ static const Pin pPwr[] = {
|
|||||||
|
|
||||||
static const Pin pinPhoneRST = PIN_ISO7816_RST_PHONE;
|
static const Pin pinPhoneRST = PIN_ISO7816_RST_PHONE;
|
||||||
|
|
||||||
static struct Usart_info usart_info = {.base = USART_PHONE, .id = ID_USART_PHONE};
|
static struct Usart_info usart_info = {.base = USART_PHONE, .id = ID_USART_PHONE, .state = USART_RCV};
|
||||||
|
|
||||||
#define PR TRACE_INFO
|
#define PR TRACE_INFO
|
||||||
|
|
||||||
@@ -123,9 +123,6 @@ static struct Usart_info usart_info = {.base = USART_PHONE, .id = ID_USART_PHONE
|
|||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
* Internal variables
|
* Internal variables
|
||||||
*-----------------------------------------------------------------------------*/
|
*-----------------------------------------------------------------------------*/
|
||||||
/** Variable for state of send and receive froom USART */
|
|
||||||
static uint8_t StateUsartGlobal = USART_RCV;
|
|
||||||
|
|
||||||
static uint8_t host_to_sim_buf[BUFLEN];
|
static uint8_t host_to_sim_buf[BUFLEN];
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -14,8 +14,16 @@
|
|||||||
#define PHONE_DATAIN 5
|
#define PHONE_DATAIN 5
|
||||||
#define PHONE_INT 6
|
#define PHONE_INT 6
|
||||||
|
|
||||||
#define CLK_MASTER 1
|
#define CLK_MASTER true
|
||||||
#define CLK_SLAVE 0
|
#define CLK_SLAVE false
|
||||||
|
|
||||||
|
/* ===================================================*/
|
||||||
|
/* Taken from iso7816_4.c */
|
||||||
|
/* ===================================================*/
|
||||||
|
/** Flip flop for send and receive char */
|
||||||
|
#define USART_SEND 0
|
||||||
|
#define USART_RCV 1
|
||||||
|
|
||||||
|
|
||||||
extern volatile ringbuf sim_rcv_buf;
|
extern volatile ringbuf sim_rcv_buf;
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ static const Pin pPwr[] = {
|
|||||||
{VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
|
{VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct Usart_info usart_info = {.base = USART_PHONE, .id = ID_USART_PHONE};
|
static struct Usart_info usart_info = {.base = USART_PHONE, .id = ID_USART_PHONE, .state = USART_RCV};
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
* Initialization routine
|
* Initialization routine
|
||||||
|
|||||||
Reference in New Issue
Block a user