Skip to content

Commit

Permalink
ibmpc: Naked ISR with IO register:0x01 #717
Browse files Browse the repository at this point in the history
  • Loading branch information
tmk committed Feb 7, 2022
1 parent 93274fa commit 1a07497
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
42 changes: 33 additions & 9 deletions tmk_core/protocol/ibmpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,6 @@ void IBMPC::host_isr_clear(void)

void IBMPC::isr(void)
{
uint8_t dbit;
dbit = IBMPC_DATA_PIN&(1<<data_bit);

// Timeout check
uint8_t t;
// use only the least byte of millisecond timer
Expand All @@ -231,7 +228,7 @@ void IBMPC::isr(void)
}

isr_state = isr_state>>1;
if (dbit) isr_state |= 0x8000;
if (STORED_PIN & data_mask) isr_state |= 0x8000;

// isr_state: state of receiving data from keyboard
//
Expand Down Expand Up @@ -392,17 +389,44 @@ void IBMPC::host_set_led(uint8_t led)
}


// NOTE: With this ISR data line should be read within 5us after clock falling edge.
// Confirmed that ATmega32u4 can read data line in 2.5us from interrupt after
// ISR prologue pushs r18, r19, r20, r21, r24, r25 r30 and r31 with GCC 5.4.0
ISR(IBMPC_INT_VECT)
extern "C" void ibmpc_isr(void) __attribute__ ((signal,__INTR_ATTRS));
void ibmpc_isr(void)
{
IBMPC::interface0.isr();
}

ISR(IBMPC_INT_VECT, ISR_NAKED)
{
asm volatile (
"push r0" "\n\t"
"in r0, %[pin]" "\n\t"
"out %[sto], r0" "\n\t"
"pop r0" "\n\t"
"rjmp ibmpc_isr" "\n\t"
:
: [pin] "I" (_SFR_IO_ADDR(IBMPC_DATA_PIN)),
[sto] "I" (_SFR_IO_ADDR(STORED_PIN))
);
}

#if defined(IBMPC_CLOCK_BIT1) && defined(IBMPC_DATA_BIT1) && defined(IBMPC_INT_VECT1)
ISR(IBMPC_INT_VECT1)
extern "C" void ibmpc_isr1(void) __attribute__ ((signal,__INTR_ATTRS));
void ibmpc_isr1(void)
{
IBMPC::interface1.isr();
}

ISR(IBMPC_INT_VECT1, ISR_NAKED)
{
asm volatile (
"push r0" "\n\t"
"in r0, %[pin]" "\n\t"
"out %[sto], r0" "\n\t"
"pop r0" "\n\t"
"rjmp ibmpc_isr1" "\n\t"
:
: [pin] "I" (_SFR_IO_ADDR(IBMPC_DATA_PIN)),
[sto] "I" (_SFR_IO_ADDR(STORED_PIN))
);
}
#endif
2 changes: 2 additions & 0 deletions tmk_core/protocol/ibmpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ POSSIBILITY OF SUCH DAMAGE.
#define IBMPC_LED_NUM_LOCK 1
#define IBMPC_LED_CAPS_LOCK 2

// IO address to store pin state temprarily(DDRA: not exist on 32u2 and 32u4)
#define STORED_PIN _SFR_IO8(0x01)

class IBMPC
{
Expand Down

0 comments on commit 1a07497

Please sign in to comment.