<wpwrak>
(that is, unless i put garbage into DISPLAY_TW, which produces "Unable to init server [...]" followed by a segfault. the latter since i don't check the success of Gdk::Display::open)
sandeepkr has quit [Read error: Connection reset by peer]
sandeepkr has joined #qi-hardware
dandon has joined #qi-hardware
pcercuei has quit [Quit: leaving]
pcercuei has joined #qi-hardware
<whitequark>
wpwrak: yeah bug #151
<whitequark>
as for DISPLAY_TW, hmm... not sure
r3dux has joined #qi-hardware
<r3dux>
Hi there, would I be able to ask any of you a question about SR-latches or D-latches (i.e. mechanisms for storing state)?
<larsc>
well, you can always ask
<r3dux>
Okay, will do! =D
<r3dux>
I've been reading about SR-latches - and they're quite simply two NOR gates cross-linked which can save state, which is the basis of all memory.
<r3dux>
After reading this, I thought "I know, I'll implement this in software to make sure it works and that I understand it." - only, it requires simultaneous outputs from both S (signal) and R (reset) NOR gates.
<r3dux>
And I don't know how to do that.
<r3dux>
I don't think I could even synchronise threads to do this.
<r3dux>
Or fake a clock.
<r3dux>
I think it has to be a truly synchronous physical operation.
<r3dux>
But... I'm merely an inquisitive programmer so I thought I'd ask some higher-powers, which in this case is you.
<DocScrutinizer05>
how about using spice or the like
<kyak>
if it means "by the end of sample time", than it can be perfectly done in software
<kyak>
that's just some logic
<kyak>
first calculate Q, than ~Q
<DocScrutinizer05>
I just completely lack the intended purpose of the exercise
<r3dux>
Thanks - that's a great suggestion and I'm sure it would work - but I was looking for getting it done without a third-party tool, just in a language
pcercuei has quit [Quit: bbl]
<DocScrutinizer05>
you need to implement a sort of clock, or loop runs
<r3dux>
DocScrutinizer05, the intended purpose is like inception... it's to go down many levels
<DocScrutinizer05>
well, then let me start with: nowadays basically all memory is so called "dynamic RAM" which does not work with RS-flipflops
<DocScrutinizer05>
but basically with storage/buffer capacitors
<r3dux>
So I'm wasting my time?
<kyak>
definitely wasting mine...
<DocScrutinizer05>
no idea. I still don't get it what's the pirpose of writing a computer program that simulates one tiny element of that computer
<r3dux>
lol - but saying that, you can't implement it.
<r3dux>
DocScrutinizer05, to understand the nature of things - that's all.
<DocScrutinizer05>
listen buddy, we can implement that sort of thing in a single bash line. We just don't know why we would do that
<r3dux>
I've been working top-down, I want to see how low it goes.
<r3dux>
I know you can.
<whitequark>
I think what r3dux asks for is reasonable
<whitequark>
it's not obvious how to write a logic simulator that properly simulates feedback loops
<whitequark>
and I don't like the condescending attitude around here, it is a perfectly valid learning exercise
<DocScrutinizer05>
and my answer was: for any sort of simulation based on discrete numeric algorithms you need a sort of time granularity
<DocScrutinizer05>
aka a clock of sorts
<r3dux>
The D-latch incorporates the clock.
<DocScrutinizer05>
no, that's another clock
<whitequark>
that's a different meaning of "clock"
<r3dux>
oh
<r3dux>
learning.com - also, thanks whitequark
<DocScrutinizer05>
you calculate all states otf output signals for N+1 from input at N
<DocScrutinizer05>
N->N+1 is your clock, the smallest observable time unit
<whitequark>
what DocScrutinizer05 says. basically, you take a snapshot of the state of every wire, then use it to calculate the next state
<whitequark>
then replace the state in one step
<r3dux>
Well that's the point isn't it, S = 0, R = 0, Q = previous state
<whitequark>
you can assemble a latch from two NOR gates in this way
<whitequark>
you don't have to explicitly model it as a latch
<whitequark>
you also don't need any threading for this, it can be done in a single threaded way (and really *only* done in a single threaded way if we're taking a single latch)
<DocScrutinizer05>
Q and Q' are outputs and *also* inputs
<r3dux>
Yes they are.
<r3dux>
whitequark, I don't see how I can implement this in a single-threaded manner. I've tried: calc q, calc notQ using q, re-calc q ---- it's not it.
<DocScrutinizer05>
there is no "e-calc q" thing
<DocScrutinizer05>
re.calc*
<whitequark>
r3dux: you'll have to explain your algorithm in more exact terms if you want a specific answer
<whitequark>
or a guidance as to what you're doing wrong
<whitequark>
can you write some pseudocode? or actual code also works, sure
<r3dux>
whitequark - Let me show you a diagram and my code
<DocScrutinizer05>
your system has 4 inputs: Q, Q', R, S. It has two outputs: Qnew, Qnew'. After you calculated Qnew and Qnew', you print the results, then you move Qnew to Q and Qbew' to Q', and restart
<DocScrutinizer05>
anyway looking at that diagram you instantly see my explanation above started with correct assumptions
<r3dux>
I don't mean to demean you, I was just completing the process of: 1.) This is what I want. 2.) This is what I have.
<r3dux>
I didn't know how an RS flipflop was built until this evening.
<whitequark>
r3dux: so your problem is actually not the fact that you can't nor stuff not in sequence
<whitequark>
in fact, your srLatch function is very easy to write and I think you can do so; but it cannot be used with the rest of the code.
<r3dux>
whitequark, my problem is that my attempts to replicate an RS flipflop in software fail
<whitequark>
let me elaborate.
<whitequark>
you understand that an SR latch is an element with state, right?
<planasb>
r3dux: maybe you try to write true table of srlatch
<DocScrutinizer05>
the 'trick' is to not look at the feedback of Q and Q', and simply strictly calculate "from left to right" until you got the output values right side of Q and Q'. Then you "do the loop" and copy the output states to input (left side) for next iteration
<whitequark>
this means that the SR latch at iteration loop=1 must take its initial state from the iteration loop=0
sandeepkr_ has joined #qi-hardware
<whitequark>
however, every invocation of srLatch runs on completely new data
<whitequark>
so of course, when s[loop]=r[loop]=0 then the latch simply lacks the information to correctly set its outputs
<r3dux>
Yup
<planasb>
i want to write software to model logic gates and sell it..
<whitequark>
planasb: pretty sure iverilog is cheaper than whatever you can come up with... at $0
sandeepkr has quit [Ping timeout: 240 seconds]
<whitequark>
r3dux: so do you have any idea how to fix this?
<planasb>
whitequark: for iOS platform
<r3dux>
whitequark, with bodges, yes. -1 bodge for sure...
<whitequark>
r3dux: that's not a bodge.
<whitequark>
that's a fundamental fact of how a latch (any latch, or any flip-flop for that matter) works
<r3dux>
smiles
<planasb>
r3dux: buy some DDR4 chips
<whitequark>
you will have to do that even if you forget about SR latches entirely and just use NOR gates (or whichever you have) in your entire model
<r3dux>
planasb, not sure I need any more than 16GB tbh...
<DocScrutinizer05>
r3dux: for calculating step[N] you take the input for Q and Q' from Q[N-1] and notQ[N-1]
<r3dux>
DocScrutinizer05, I understand. Thank you for your help.
<DocScrutinizer05>
for "Q[-1]" you define either 0 or 1, as you like. To start with. Of course notQ[-1]=~Q[-1] then
<DocScrutinizer05>
or rather, you should define R[-1]=1
<DocScrutinizer05>
that is what real hardware does
<r3dux>
Things get real at low-level.
<DocScrutinizer05>
when you power up the RS-Latch, the Reset input gets a power-on-reset
<r3dux>
When I power up my toaster it gets warm. Industrial design is also very cool.
<r3dux>
(would love to know how those machines crack walnuts without there being bits of shell in it also - I can't even do that manually)
<r3dux>
<<< off-topic. It was a pleasure to talk with you, and I've learnt a lot. So thank you.
r3dux has left #qi-hardware ["Leaving"]
<planasb>
thanks for pointing icarus verilog
eintopf_ has joined #qi-hardware
eintopf has quit [Ping timeout: 240 seconds]
eintopf_ is now known as eintopf
sb0 has joined #qi-hardware
pcercuei has joined #qi-hardware
<DocScrutinizer05>
for really help him out of this problem (oscillating? most likely) we had needed to start with propagation delay and then even have a short dive into analog aspects of digital circuits
<DocScrutinizer05>
I guess with POR (s)he's fine off, for a start
<wpwrak>
whitequark going through the tutorial videos ... tutorial #2 https://www.youtube.com/watch?v=13qKQ9BHXCM has a lot of repetition. can't one just reuse a sketch for each side ?
<DocScrutinizer05>
also maybe silego GreenPak designer would be sth for r3d2<-ux: R,S,Q->Q: 1,x,x->0; 0,0,Q->Q; 0,1,x->1. :-D
<DocScrutinizer05>
with a single 3LUT
<wpwrak>
oh, and regarding sending the text window elsewhere, if i remove TW->set_transient_for(*GW); the window briefly opens on the other screen, then closes. if i keep on opening/closing it with Tab, it eventually stays there. seems to be some sort of race.
<wpwrak>
however, when moving the mouse cursor over the text window (if TW->set_transient_for was not called, no matter on which screen it is), cause it to fail with Gdk:ERROR:/build/gtk+3.0-VoKwSM/gtk+3.0-3.20.9/./gdk/gdkwindow.c:6153:gdk_window_set_cursor_internal: assertion failed: (!cursor || gdk_window_get_display (window) == gdk_cursor_get_display (cursor))
<DocScrutinizer05>
or create a !RS latch from just two discrete components: resistor and thyristor ;-)
<wpwrak>
called from gdkwin->set_cursor in TextWidget:set_cursor_hand
<wpwrak>
commenting out that call to set_cursor does seem to avoid the crash
<wpwrak>
so we're getting closer :)
<wpwrak>
also, once i got the window to become stable, it seems to come up without a fuss on subsequent invocations. not sure if it's solvespace remembering something that contributes to the success (i see that it remembers window positions and such), or if it's the window manager remembering it
<whitequark>
wpwrak: set_transient_for not working is expected
<whitequark>
wpwrak: as for gdk::cursor::create...
<wpwrak>
this bringe me to the issue of what a Glib::RefPtr<Gtk::Display> really is, how one gets anything done with it without the compiler complaining, and why on earth gtkmm needs to introduce some pointer concept that isn't just a pointer ...
<whitequark>
Glib::RefPtr is more or less the same thing as std::shared_ptr if you know what that is
<wpwrak>
i.e., i tried to store the result of gdk_display_open so that i could check it for MULL, but even that seems hopeless :(
<wpwrak>
nyet :)
<whitequark>
define hopeless
<whitequark>
Glib::RefPtr<T> can be used in the same way as T*
<wpwrak>
C has beautiful pointers, and they're all very standard :)
<whitequark>
you can do x->foo() and you can check if(x != NULL)
<whitequark>
and they don't do the reference counting for you.
<whitequark>
thanks, but no.
<whitequark>
gtk has many awful decisions but this one makes a lot of sense
<wpwrak>
hopeless = none of the syntax variations i tried when using it to get_default_screen seemed acceptable to the compiler
<whitequark>
get_default_screen?
<whitequark>
you're using Gdk::Display::get_default_screen() right?
<whitequark>
can you show me specific code and the error?
<wpwrak>
turning Gdk::Display::open(display_tw)->get_default_screen() into {whatever} dpy = ... ; ...dpy...gdk_display_get_default_screen...
<wpwrak>
that was already a form that didn't work. the one that does work is Gdk::Display::open(display_tw)->get_default_screen()
<whitequark>
dpy->get_default_screen()
<whitequark>
this will work
<whitequark>
also you can use "auto dpy = Gdk::Display::open(display_tw);" in a pinch but I personally prefer to write it out explicitly in C++
<wpwrak>
kewl. that did the trick. thanks !
<wpwrak>
now errors to open the display are just ignored, not crashed upon :)
* DocScrutinizer05
idly wonders how you'd generically catch exceptions in C programs. Except of the very obvious coredump and postmortem debug
<whitequark>
DocScrutinizer05: not really any nicely portable way
<whitequark>
POSIX doesn't even let you return from SIGSEGV!
<DocScrutinizer05>
oooh "portable" - yeah for sure not
<DocScrutinizer05>
man 7 signal
<wpwrak>
setjmp/longjmp is a common approximaition of "exceptions"
<whitequark>
I am aware
<DocScrutinizer05>
sure?
<whitequark>
it's not legal according to POSIX to siglongjmp out of a SIGSEGV handler
<whitequark>
it works on basically every OS out there
<whitequark>
but not legal according to POSIX anyway
* whitequark
shrugs
<wpwrak>
whitequark: ah, i guess it depends on the definition of "exceptions" :) a segfault pretty much means that you're screwed
<DocScrutinizer05>
"SIGSEGV 11 Core Invalid memory reference " -- but "The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored." so I assumed the others could get intercepted
<whitequark>
DocScrutinizer05: you can intercept it
<DocScrutinizer05>
oooh, but not return from handler
<whitequark>
but you cannot jump out of it or return from it (according to POSIX but not in practice)
<whitequark>
yep
<whitequark>
in reality this works fairly nicely for "userspace virtual memory" schemes
<DocScrutinizer05>
that's ROTFL
<wpwrak>
whitequark: now ... i'm trying to pass the display i get in TextWindowGtk to the outside world. for deciding on whether i should TW->set_transient_for but also the for the cursor. alas, i can't seem to find a way to get at that TextWindowGtk object
<whitequark>
I think some ass-backwards architecture doesn't let you catch a SEGV precisely
<whitequark>
it miiight have been Alpha?
<DocScrutinizer05>
however you wouldn't need to return, after all you don't want to resume
<whitequark>
depends
<whitequark>
let's say I am managing my own file mappings for some reason
<whitequark>
then a SEGV is a perfectly fine thing to catch and return from
<DocScrutinizer05>
what you really want is a proper diagnostic output to STDERR
<DocScrutinizer05>
then coredump
<whitequark>
there's backtrace(3)... but not standardized
<wpwrak>
oh, wait ... you're defining that one yourself
<whitequark>
TW is another of those pointers
<whitequark>
although this one is C++'s std::unique_ptr for a reason I do not recall
<whitequark>
just do TW->fn() for whatever you want to call
<wpwrak>
gtkmm really is the height of perversion. gtk was made to have a nice graphic library without all the senseless struggle and bloodshed of c++, and then they brought all that right back in :(
<whitequark>
no. gtkmm makes gtk barely usable
<whitequark>
as opposed to just being totally unusable, that is.
<wpwrak>
i can call things on TW. but how do i get the TextWindowGtk that's somewhere hidden in there ? and as TextWindowGtk not as some other vaguely related class ?
<whitequark>
TW->get()
<whitequark>
erm, TW.get()
<wpwrak>
yes ! thanks ! :)
<pcercuei>
are there still people with nanonotes?
<pcercuei>
I'd like to know if suspend/resume still works on 4.9 or 4.10
<wpwrak>
whoa ! fun storm coming
<wpwrak>
hmm. get() is not available in TextWidget::set_cursor_hand ?
<wpwrak>
i.e., the "get" i used successfully to get the TextWindowGtk in TW->get()
<DocScrutinizer05>
whitequark: when backtrace fails epically, would it nuke the computer? ;-) or 'even worse' the program could maybe SEGFAULT and COREDUMP ;-P
<DocScrutinizer05>
I'm proolly as fuzzy and ambiguous as usual - what I want to say is: it doesn't matter if the process segfaults right away or segfaults in a segfault handler while trying in vain to backtrace()
<DocScrutinizer05>
worst thing you trade in (aka pay) for using the backtrace(3) is an #ifdef to make the shite compile on platforms that never heard of backtrace()
<DocScrutinizer05>
and prolly there are smarter more nifty ways to deal with that, like "unresoved external symbol" that nevertheless doesn'T stop the process from starting normally and would just cause a segfault^2 when the unresolved function call actually gets called... which is no probkem at all as I explained above. I'm not the wizard to handle linker and whatnot in such a way to make that fly, I'm also sure there are even better methods than
<DocScrutinizer05>
this crude one I just made up
paul_boddie has joined #qi-hardware
<paul_boddie>
pcercuei: Great timing! Was just about to test something on the Ben.
<paul_boddie>
I did try a fairly recent kernel when that new guy was setting up his purchase from IDA Systems a month or so ago, perhaps.
<paul_boddie>
Not sure if I ever used suspend/resume on the Ben, though.
<paul_boddie>
whitequark: I think MIPS has some oddness around exceptions that might prevent recovery from SEGV.
<pcercuei>
oh cool
<mth>
pcercuei: does suspend still work on Dingoo A320 with current kernels?
<pcercuei>
it's hard to say. Upstream Linux doesn't support the A320
<mth>
I thought you might have a serial-only build for it
<pcercuei>
I have a 4.10 kernel for the A320, but it uses a lot of non-upstream stuff (new TCU drivers, new pinctrl driver)
<pcercuei>
and those drivers might be the reason why I can't suspend/resume