mirror of https://gerrit.osmocom.org/simtrace2
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:
parent
dde112e71c
commit
3bafe43376
|
@ -22,6 +22,10 @@ typedef struct {
|
|||
void (*exit) (void);
|
||||
/* main loop content for given configuration */
|
||||
void (*run) (void);
|
||||
/* Interrupt handler for USART1 */
|
||||
void (*usart0_irq) (void);
|
||||
/* Interrupt handler for USART1 */
|
||||
void (*usart1_irq) (void);
|
||||
} conf_func;
|
||||
|
||||
static const conf_func config_func_ptrs[] = {
|
||||
|
@ -48,6 +52,8 @@ static const conf_func config_func_ptrs[] = {
|
|||
.init = mode_cardemu_init,
|
||||
.exit = mode_cardemu_exit,
|
||||
.run = mode_cardemu_run,
|
||||
.usart0_irq = mode_cardemu_usart0_irq,
|
||||
.usart1_irq = mode_cardemu_usart1_irq,
|
||||
},
|
||||
#endif
|
||||
#ifdef HAVE_MITM
|
||||
|
@ -81,6 +87,16 @@ void USBDDriverCallbacks_ConfigurationChanged(uint8_t 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
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -167,17 +167,13 @@ int card_emu_uart_tx(uint8_t uart_chan, uint8_t byte)
|
|||
|
||||
|
||||
/* 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);
|
||||
struct cardem_inst *ci = &cardem_inst[0];
|
||||
Usart *usart = get_usart_by_chan(inst_num);
|
||||
struct cardem_inst *ci = &cardem_inst[inst_num];
|
||||
uint32_t csr;
|
||||
uint8_t byte = 0;
|
||||
|
||||
#ifdef CARDEMU_SECOND_UART
|
||||
if (uart == 1)
|
||||
ci = &cardem_inst[1];
|
||||
#endif
|
||||
csr = usart->US_CSR & usart->US_IMR;
|
||||
|
||||
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 */
|
||||
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 MITM_run( void );
|
||||
|
||||
extern void mode_cardemu_usart0_irq(void);
|
||||
extern void mode_cardemu_usart1_irq(void);
|
||||
|
||||
/* Timer helper function */
|
||||
void Timer_Init( void );
|
||||
void TC0_Counter_Reset( void );
|
||||
|
|
|
@ -78,14 +78,12 @@ void ISR_PhoneRST(const Pin * pPin)
|
|||
PIO_DisableIt(&pinPhoneRST);
|
||||
}
|
||||
|
||||
extern void usart_irq_rx(uint8_t num);
|
||||
/*
|
||||
* char_stat is zero if no error occured.
|
||||
* 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;
|
||||
char_stat = 0;
|
||||
// Rcv buf full
|
||||
|
@ -115,9 +113,6 @@ void USART1_IrqHandler(void)
|
|||
|
||||
char_stat = stat;
|
||||
}
|
||||
#else
|
||||
usart_irq_rx(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* FIDI update functions */
|
||||
|
|
Loading…
Reference in New Issue