• Grundle (unregistered)

    As the song goes:

    "Walking back to cr@ppiness ..."

  • MIKE (unregistered)

    If the PWM generators are programme to make an audible frequency, maybe, hooking a loudspeaker on the pin it's possible to hear the program working and if a test is failing or not....

  • Michael R (unregistered)

    Using PWM? I don't like the sound of that.

  • Tim Ward (unregistered)

    Deliberately taking the piss?

    I knew someone who built a Rugby clock using, I think, a Z80, with no RAM, because it had enough registers.

    But it only just had enough registers - this did involve using the upper few bits of the dynamic RAM refresh control register (the bottom few bits weren't any use because they changed too fast).

  • Brian Boorman (google)

    What are you testing exactly? First off, it's utterly ridiculous to test on-chip RAM (OCM). If you are testing all of OCM then you just trashed your stack. That's TRWTF. You test external memory. You run your code in OCM, or perhaps XIP in FLASH memory, and you use the OCM RAM for stack and variables.

  • (nodebb) in reply to Tim Ward

    But it only just had enough registers

    Including the shadow registers?

  • (nodebb)

    It is using the PWM registers as a small RAM to provide workspace for internal variables, so it can test ALL of the on-chip RAM. Code is being run from ROM : this code was almost certainly not called as a subroutine, but in-line at initialisation.

    If the RAM passes the test, then you can continue running code using the RAM. Otherwise the MCU is dead.

    The only strangeness in fact is setting a flag saying the RAM is good at the end of the test. Either it is good and you continue, or it fails and you stop, and do something to alert the outside world.

    All it needs is that as an explanation of the choice made, not that it is a bad choice...

  • PMF1 (unregistered)

    Are we sure these really are PWM registers? The declarations at the beginning of the code block look like they're just calling them PWM registers, but actually map to the bottom of the regular RAM. (Now of course that address space could indeed be mapped to a physical device, but without any comments, things are difficult when working with low-level hardware access)

  • Wizofaus (unregistered)

    I don't know nearly enough about chip architecture to judge whether using PWM registers makes any sense, but plenty of other things in that code strike me as WTFs - the use of 30 to mean "failure detected" for a start. Why 30?

  • Sauron (unregistered)

    There are additional weird things in that code.

    Take PWMDTY4 for example. It serves as a loop counter and index to access values in that _PowOfTwo_16 array. Yet it some places it is arbitrarily set to 30 (magic number!) just to trigger various if/else branches (from the looks of it, the value 30 means "The test has failed"). That's a dangerous mix of concerns, especially when dealing with low-level memory access. If the dev had messed up and accidentally accessed PowOfTwo[30], it could have returned something from garbage memory and caused undefined behaviour. Also, the value of PWMDTY4 might even be overwritten by various iterations of some loop, so it's not even guaranteed that it properly works.

    Instead of setting PWMDTY4 to 30 in the middle of a loop and happily resuming the loops, they should just have used some goto statement to exit the loops and go straight to the code saying the test was failed.

    There's also a suspicious smell in those ((uint16_t)PWMDTY01 casts. Maybe they are actually necessary for that memory test. And maybe there's some bad typing lurking in the shadows and this is an ugly workaround. In any case, here be dragons.

  • (nodebb)

    Agreed with the others, o obvious WTF in the design. Using the PWM registers rather than general purpose is potentially a GOOD idea. There is always the possibility that the compiler will decide to use a given register and cause problems, by avoiding the common registers this problem it mitigated.

  • Tim Ward (unregistered) in reply to Jeremy Pereira

    C'mon, it was a long time ago, and I never saw the code - I'm just reporting what the guy who built it told me. At a clock changing party, where we were watching it switch from 3am back to 2am (or whatever it was). If I ever knew any more detail I've forgotten it.

  • Zygo (unregistered)
    Comment held for moderation.
  • Rod (unregistered) in reply to TheCPUWizard
    Comment held for moderation.
  • deepakbishtfarswan (unregistered)
    Comment held for moderation.
  • deepakbishtfarswan (unregistered)
    Comment held for moderation.
  • Just another Embedded Designer (unregistered)
    Comment held for moderation.
  • Charles (unregistered)
    Comment held for moderation.
  • (nodebb) in reply to Wizofaus

    Why 30?

    Possibly this: https://en.wikipedia.org/wiki/-30-

  • (nodebb)

    Since these registers are usually used to control sound generation (maybe for a modem), I can just imagine what this would sound like if the speaker is hooked up.

  • mk guru (unregistered) in reply to mike_james
    Comment held for moderation.
  • deepakbishtfarswan (unregistered)
    Comment held for moderation.

Leave a comment on “Walking is your Duty”

Log In or post as a guest

Replying to comment #579108:

« Return to Article