6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 7:01 am

All times are UTC




Post new topic Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3
Author Message
PostPosted: Thu Nov 07, 2013 8:01 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
BigDumbDinosaur wrote:
Suppose the following code (...) is being executed:
Code:
         lda sr_92a            ;channel A status
         bit #u92txdr          ;FIFO full?  <————————————— ABORTB IS ASSERTED HERE
         beq .iirq100          ;yes, defer next datum

(...) What do you think would happen when the MPU resumed execution at that instruction? Consider that "aborting" an instruction causes the 65C816 to discard computational results.


Let me see. Assuming that we push A to the stack during abort interrupt handling and then pull it back again, we return with the old status of of channel A, and have no idea what has happened in the meantime. For example, if the FIFO was not full, we'll still think it is not full, and BIT immediate will give us the z flag for the old value. However, depending on what happened in the meantime, the FIFO could be anything by now. We need to make sure that the handler always gets the current status of channel A by protecting this part from interrupts.

I, ah, think.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 07, 2013 10:02 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8505
Location: Midwestern USA
scotws wrote:
BigDumbDinosaur wrote:
Suppose the following code (...) is being executed:
Code:
         lda sr_92a            ;channel A status
         bit #u92txdr          ;FIFO full?  <————————————— ABORTB IS ASSERTED HERE
         beq .iirq100          ;yes, defer next datum

(...) What do you think would happen when the MPU resumed execution at that instruction? Consider that "aborting" an instruction causes the 65C816 to discard computational results.

Let me see. Assuming that we push A to the stack during abort interrupt handling and then pull it back again, we return with the old status of of channel A, and have no idea what has happened in the meantime. For example, if the FIFO was not full, we'll still think it is not full, and BIT immediate will give us the z flag for the old value. However, depending on what happened in the meantime, the FIFO could be anything by now.

Exactly. If you abort in code that manages I/O devices there's no telling what will happen when you re-execute the aborted instruction, since as you surmised, the condition being tested could have changed during the servicing of the abort interrupt.

Quote:
We need to make sure that the handler always gets the current status of channel A by protecting this part from interrupts.

You can't "protect" your code from an abort interrupt except by somehow forcing ABORTB to stay high no matter what. An abort is non-maskable and is the top dog in the 65C816 interrupt kennel.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 08, 2013 3:40 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
BigDumbDinosaur wrote:
You can't "protect" your code from an abort interrupt except by somehow forcing ABORTB to stay high no matter what. An abort is non-maskable and is the top dog in the 65C816 interrupt kennel.


Yes, that was what that paragraph was meant to say, we can't use ABORT.

Whole thing sounds fun. But first computer needs to be done first!


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 14, 2023 11:31 am 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
nyef wrote:
Dr Jefyll wrote:
Anyway, sometimes you really do need to hit some I/O device at a precise rate with no jitter, or at least no jitter greater than your oscillator variation, and having a scheme whereby you can do so on an interrupt-driven basis can be useful, as long as your clock speed is fast enough, and your interrupt handler short enough, that you can get useful work done in the meantime and still compensate for the jitter inherent in interrupt response on most platforms.

It's an interesting thread that Garth has just linked to. I didn't see any implementation of this here so thought I'd show a way I've done it for a similar purpose - this is to implement accurate split screen on a BBC Micro, using a VIA timer to wait until a point somewhat earlier than the target time and then a loop in the ISR to wait for an exact time point:

Code:
 1060 .topstart
 1070 LDA #(timerbias-(time2-time1)) AND &FF
 1080 JSR timersync
 ...
 1520 .timersync
 1530 STX zpsavedx
 1540 CLC
 1550 ADC &FE64
 1560 LSR A
 1570 BCS P%+2
 1580 BCS P%+2
 1590 LSR A
 1600 BCC P%+4
 1610 LSR zpjunk
 1620 TAX
 1630 .syncloop
 1640 BIT 0
 1650 DEX
 1660 BNE syncloop
 1670 LDX zpsavedx
 1680 BIT 0
 1690 RTS
 

In this context, at "topstart" a VIA Timer 1 interrupt has just fired and "time2-time1" is the value that was in the latches, and loaded into the timer at the time of the interrupt. "timerbias" is a small value, e.g. 10, used to make the interrupts occur slightly early so that latency in the interrupt can be tolerated more or less. If an interrupt was being serviced when the time elapsed for example then some of this tolerance would be used up. (Looking back, 10 seems a really small number so I might have misremembered this bit. )

So A gets loaded with a value we'd like to see on T1, and "timersync" compares it against the current count in T1 and adds a variable delay so that by its end we are at a consistent offset from that time point.

It's worth noting that the VIAs in the BBC Micro are clocked at half of the usual CPU frequency, and any access to them aligns the CPU with that slower clock. So this loop actually has to wait for twice as many CPU cycles than the T1 difference that was calculated. (Edit - I suspect adding an extra "LSR" and "BCS P%+2" after line 1550 would make it work for cases where the VIA shares the usual CPU clock.)

If you're interested in the wider use case for this or the rest of the code, please see here: https://stardot.org.uk/forums/viewtopic ... 12#p356012


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3

All times are UTC


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: