mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-24 17:28:32 +03:00
dynamically dispatch USART IRQs
The different modes (configurations) will have different interrupt handlers, so we need to dispatch them via config_func_ptrs
This commit is contained in:
@@ -22,6 +22,10 @@ typedef struct {
|
|||||||
void (*exit) (void);
|
void (*exit) (void);
|
||||||
/* main loop content for given configuration */
|
/* main loop content for given configuration */
|
||||||
void (*run) (void);
|
void (*run) (void);
|
||||||
|
/* Interrupt handler for USART1 */
|
||||||
|
void (*usart0_irq) (void);
|
||||||
|
/* Interrupt handler for USART1 */
|
||||||
|
void (*usart1_irq) (void);
|
||||||
} conf_func;
|
} conf_func;
|
||||||
|
|
||||||
static const conf_func config_func_ptrs[] = {
|
static const conf_func config_func_ptrs[] = {
|
||||||
@@ -48,6 +52,8 @@ static const conf_func config_func_ptrs[] = {
|
|||||||
.init = mode_cardemu_init,
|
.init = mode_cardemu_init,
|
||||||
.exit = mode_cardemu_exit,
|
.exit = mode_cardemu_exit,
|
||||||
.run = mode_cardemu_run,
|
.run = mode_cardemu_run,
|
||||||
|
.usart0_irq = mode_cardemu_usart0_irq,
|
||||||
|
.usart1_irq = mode_cardemu_usart1_irq,
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_MITM
|
#ifdef HAVE_MITM
|
||||||
@@ -81,6 +87,16 @@ void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum)
|
|||||||
simtrace_config = cfgnum;
|
simtrace_config = cfgnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void USART1_IrqHandler(void)
|
||||||
|
{
|
||||||
|
config_func_ptrs[simtrace_config].usart1_irq();
|
||||||
|
}
|
||||||
|
|
||||||
|
void USART0_IrqHandler(void)
|
||||||
|
{
|
||||||
|
config_func_ptrs[simtrace_config].usart0_irq();
|
||||||
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* Main
|
* Main
|
||||||
*------------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -167,17 +167,13 @@ int card_emu_uart_tx(uint8_t uart_chan, uint8_t byte)
|
|||||||
|
|
||||||
|
|
||||||
/* FIXME: integrate this with actual irq handler */
|
/* FIXME: integrate this with actual irq handler */
|
||||||
void usart_irq_rx(uint8_t uart)
|
static void usart_irq_rx(uint8_t inst_num)
|
||||||
{
|
{
|
||||||
Usart *usart = get_usart_by_chan(uart);
|
Usart *usart = get_usart_by_chan(inst_num);
|
||||||
struct cardem_inst *ci = &cardem_inst[0];
|
struct cardem_inst *ci = &cardem_inst[inst_num];
|
||||||
uint32_t csr;
|
uint32_t csr;
|
||||||
uint8_t byte = 0;
|
uint8_t byte = 0;
|
||||||
|
|
||||||
#ifdef CARDEMU_SECOND_UART
|
|
||||||
if (uart == 1)
|
|
||||||
ci = &cardem_inst[1];
|
|
||||||
#endif
|
|
||||||
csr = usart->US_CSR & usart->US_IMR;
|
csr = usart->US_CSR & usart->US_IMR;
|
||||||
|
|
||||||
if (csr & US_CSR_RXRDY) {
|
if (csr & US_CSR_RXRDY) {
|
||||||
@@ -197,6 +193,18 @@ void usart_irq_rx(uint8_t uart)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mode_cardemu_usart0_irq(void)
|
||||||
|
{
|
||||||
|
/* USART0 == Instance 1 == USIM 2 */
|
||||||
|
usart_irq_rx(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mode_cardemu_usart1_irq(void)
|
||||||
|
{
|
||||||
|
/* USART1 == Instance 0 == USIM 1 */
|
||||||
|
usart_irq_rx(0);
|
||||||
|
}
|
||||||
|
|
||||||
/* call-back from card_emu.c to change UART baud rate */
|
/* call-back from card_emu.c to change UART baud rate */
|
||||||
int card_emu_uart_update_fidi(uint8_t uart_chan, unsigned int fidi)
|
int card_emu_uart_update_fidi(uint8_t uart_chan, unsigned int fidi)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -106,6 +106,9 @@ extern void CCID_run( void );
|
|||||||
extern void mode_cardemu_run(void);
|
extern void mode_cardemu_run(void);
|
||||||
extern void MITM_run( void );
|
extern void MITM_run( void );
|
||||||
|
|
||||||
|
extern void mode_cardemu_usart0_irq(void);
|
||||||
|
extern void mode_cardemu_usart1_irq(void);
|
||||||
|
|
||||||
/* Timer helper function */
|
/* Timer helper function */
|
||||||
void Timer_Init( void );
|
void Timer_Init( void );
|
||||||
void TC0_Counter_Reset( void );
|
void TC0_Counter_Reset( void );
|
||||||
|
|||||||
@@ -78,14 +78,12 @@ void ISR_PhoneRST(const Pin * pPin)
|
|||||||
PIO_DisableIt(&pinPhoneRST);
|
PIO_DisableIt(&pinPhoneRST);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void usart_irq_rx(uint8_t num);
|
|
||||||
/*
|
/*
|
||||||
* char_stat is zero if no error occured.
|
* char_stat is zero if no error occured.
|
||||||
* Otherwise it is filled with the content of the status register.
|
* Otherwise it is filled with the content of the status register.
|
||||||
*/
|
*/
|
||||||
void USART1_IrqHandler(void)
|
void mode_trace_usart1_irq(void)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
uint32_t stat;
|
uint32_t stat;
|
||||||
char_stat = 0;
|
char_stat = 0;
|
||||||
// Rcv buf full
|
// Rcv buf full
|
||||||
@@ -115,9 +113,6 @@ void USART1_IrqHandler(void)
|
|||||||
|
|
||||||
char_stat = stat;
|
char_stat = stat;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
usart_irq_rx(0);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIDI update functions */
|
/* FIDI update functions */
|
||||||
|
|||||||
Reference in New Issue
Block a user