Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MISRA-C coding guidelines for personal use programs?

Tags:

c

embedded

misra

I am usually a wood worker and not a developer. I'm learning C/C++ for embedded systems while trying to make some of my tool autonomous to save me hours of repetitive work.

For now, its fun and going well, I have spend maybe a hundred of hours coding/learning and already saved more time*.

As I want to keep going is buying and following MISRA coding rule a "mandatory good idea"? What does MISRA contain? Only coding rules, or kind of tips to make it safer?

Those tools could be dangerous (after all they cut wood and a human body is far less resistant...).

Note: I obviously do my test in 4 steps:

  1. Just the pic running with an OSD & SD card logger (one day I'll make an anylze tool and stop reading those).

  2. I plug the tool with nothing on it

  3. I use soft drill/cutters on foam

  4. I conduct real test at good distance with my hand on the emergency stop button.

Also I'm the only employee and no one else has access to my work-place.

*for now I've turn a drill into a kinda 3D wood printer (doing the not precise part of the work), and a "cutter-board" into an automated one.

Note2: I'm not a native speaker so tools' names are probably off.

like image 395
A.albin Avatar asked Apr 24 '17 12:04

A.albin


1 Answers

MISRA is designed originally for use in the automotive industry, though it has grown well past that at this stage. The MISRA guidlines stated aims are:

  • Ensure safety
  • Bring in robustness, reliability to the software.
  • Human safety must take precedence when in conflict with security of property.
  • Consider both random and systematic faults in system design.
  • Demonstrate robustness, not just rely on the absence of failures.
  • Application of safety considerations across the design, manufacture, operation, servicing and disposal of products.

The documents mainly consist of rule based advisory information for code that tries to meet these aims. MISRA document prices have dropped somewhat over the years, some documents can be bought online from MISRA for as little as GBP £10 + VAT.

However, as a beginner and amateur coder, I would advise first bolstering your knowledge of C and C++. While in most areas of industry it is often good to follow a pertinent standard, if applicable, the documents are written with the assumption that the reader has a very solid grounding in the languages and also in the concerns and processes governing full-scale commercial type applications written in them. If your workshop is for personal use only, and depending on rules governing workplace safety in your jurisdiction, I can say that having a good understanding of the languages, language tools and the hardware would allow you to start making good choices with regards to how to code things more-so than reading MISRA could at such a stage in.

As commented above, and it is worth reiterating, MISRA is not some kind of magic wand or concrete way of going about things that will guarantee your code is good, works and is safe. Both good and bad code can meet standards. Following MISRA before having a good and complete grasp of what you are doing might be the same as ensuring every cable in your work shop is neatly tacked in place but then stabbing yourself with a chisel.

like image 66
Toby Avatar answered Oct 01 '22 13:10

Toby