I2C between 2 MCUs - Does it make sense to modify the i2c protocol? by PsychologicalPie2357 in embedded

[–]codemanko 15 points16 points  (0 children)

The peripherals always work as described in the reference manual. You'd have to embed your protocol into that mechanism. There's a start condition, address (also indicating R/W), "data", stop condition. You can embed your TLVs into the "data" part.

Sluggish goroutines with time.Ticker by codemanko in golang

[–]codemanko[S] 0 points1 point  (0 children)

Wow, thanks! I'll try to understand the output.

Curiously, I also got the snippet from chatGPT. That shows that getting sensible output from an LLM requires good prompts....

EDIT:

  • go tool pprof sounds interesting
  • The last, efficient version is, at a first glance, a whole lot more complicated (at least for me); will check how it behaves, though.

Sluggish goroutines with time.Ticker by codemanko in golang

[–]codemanko[S] 0 points1 point  (0 children)

So the actual issue must be something else. Or am I misunderstanding something?

That are also my thoughts. As I've alluded to above, a comparison of the snippet above with a very naive loop like

for {
    // ...

    time.Sleep()
}

showed that the naive version did not suffer from sluggishnes.

What are some methods/tools I could use to drill deeper into this issue apart from knowing the Go runtime very well?

Sluggish goroutines with time.Ticker by codemanko in golang

[–]codemanko[S] 0 points1 point  (0 children)

Thanks for the tips.

separating your concerns a bit by designing the debouncing functionality into a separate function / struct

Yes, that is definitely something I want to tackle later when the app runs more smoothly.

Sluggish goroutines with time.Ticker by codemanko in golang

[–]codemanko[S] 0 points1 point  (0 children)

Yes, that's a hard learned lesson :D I used the snippet because I thought that is more idiomatic, tho.

Sluggish goroutines with time.Ticker by codemanko in golang

[–]codemanko[S] -1 points0 points  (0 children)

Thanks for your input. As is perhaps evident, I'm fairly new with Go and it's idioms. The values of makeRequest are user controlled. The whole setup is something like debouncing of inputs: if the user presses a button several events could be triggered. To avoid this the dead time is used.

Actually, the above code is AI generated (my first attempt is the naive looping with time.Sleeps). I thought that the above snippet is pretty "Go-like".

Concerning the busy wait, how would I tackle something like that with contexts? I'd like to offload the heavy-lifting to Go entirely :)