​It appears not to execute handle_ping_response or switch the led on but I inserted a piece of code called respond_to_ping and it executes? Strange. I would love to wrap this code up tonight but I fear I'll but dumb founded for days.

E.g. if something makes the code unreachable then the compiler is very likely to not generate code at all. What could make that code unreachable? E.g. earlier condition in your nested if-statement is behaving like a "catch-all".

(How close do I need to be in my guesses for you to start cooking the hat? ;-)

Re the respond_to_ping(), do you have other calls to that in other places?

Fianawarrior wrote:

I never use the debugger

Why not?

Happy 75th anniversary to one of the best movies ever made! Rick Blane [Bogart]: "Of all the gin joints, in all the towns, in all the world, she walks into mine."

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

I'd add that posting such a small section of your code makes it almost impossible for anybody to understand what's going on ( just so you know, for any future code postings ). Did you check the generated *.asm to see if the function even got compiled ?

You might be fooling yourself by thinking the if-statement must "catch" since you've forced it with

icmp_header->type[0] = ICMP_REP;

but if you don't even get near that "forced conditional"...

Here are lessons I learned again and again (getting a little better at it each time) over the cause of software development for 35+ years:

Whenever things seems really strange it is time to take a step back and look for a natural explanation "outside my current box of thinking".

Move the lighting of the LED back (i.e. earlier) in the execution to where it lights up. Move it forward again to verify it does not light up. That "grapple" is an interesting point to study!

Get used to study generated assembler at the points which seems to be "troublesome". (Not that it is always the case, but being unable to place a breakpoint "any way near it" is just creaming at you to look at the disassembly.

And first and foremost: Get used to using an on-chip debugger! It makes for a much more effective debugging experience than "tracing with a LED". Faster. More rich on information.

There are of-course cases when on-chip debugging might mess things up by e.g. suggesting a bug while it actually is a "false positive". This is important to realize. Example: You have a stream of data coming into your controller. If you stop at a breakpoint then you risk data overrun and/or loss of data that might later look like a bug in your code.

LED debugging is simple to implement, but poor on "information richness".

UART logging/debugging is harder to implement, but can be richer on information. Of-course, if your UART(s) is(are) already occupied then this is not the way.

Real-hardware on-chip debugging is simple to implement, and very rich on information. There is a learning curve before it starts to really pay off but IMO it is definitively worth it!

Happy 75th anniversary to one of the best movies ever made! Rick Blane [Bogart]: "Of all the gin joints, in all the towns, in all the world, she walks into mine."

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

I’m debugging some encrypted protocol stuff at the moment - rather than do it on the target, i’m doing it on the PC (mac actually). This is saving me a whole heap of time. I’m debugging both ends at the one time - i’ve set up a test harness that has both instances and rather than send packets via serial, it just uses a mock function that copies the data to the other instance. Since you’re just doing tcp/ip, there’s no realtime constraint and you can send your packets via a virtual ethernet interface to the real world. No need to use Windows either.

Pretend that we're all really stupid and just beginning to know how a microcontroller works. Pretend that we all have no idea what "icmp_header->type[0] == ICMP_REP" could possibly mean. In C language, anything with a "->" after it is is a pointer [a 16-bit integer that refers to an address that is located in AVR SRAM] to a structure. This structure could possibly have an array in it. This array may be called "type" or it may a type called "type" or it may be a definition of a type of type[] type with value type of type that dereferences type with value pointing to type...

Why do "programmers" do this? Is this something that they learned in school? Did someone, somewhere tell them that this was some kind of elegance?

Happy 75th anniversary to one of the best movies ever made! Rick Blane [Bogart]: "Of all the gin joints, in all the towns, in all the world, she walks into mine."

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

I do.
The C language does not require a ; terminator for a {} block, but I find that it is a nice visual indicator of where the statement actually ends.
My caffeine level is low at the moment and I am having difficulty in envisioning scenario(s) where superfluous null statements will 'burn' me.

Thanks for highlighting the difference. I'm a bit worried about your 'fist packet'. Might make you a bit sore after a night of drinking, especially if the sleeper hold is applied. Refer to Chappelle's "mad real world".