SlideShare une entreprise Scribd logo
1  sur  23
IOT FIRMWARE DESIGN:
BEST PRACTICES
(for embedded development that sucks less)
@farmckon
@BuLogics
EMBEDDED
DEVELOPMENT IS
PAINFUL
It doesn’t have to be.
Common Problems:
• “Code, flash, bang-on-it” cycle
• Development environment setup sucks
• Debugging with little/no IO
• Complex bug scenario recreation
• “Hurry up and wait” on hardware spins
Design ToAvoid ‘em:
• Program in C
• State Machines Everywhere
• Proper Modular Design
• Hardware Abstraction Layer,
• Hardware Abstraction Layer,
• Hardware Abstraction Layer!
• On-Device debugging is a last resort
Program Drivers/Firmware in C++?
Program Drivers/Firmware in C!
Just do it
• Platform portable
• Fast
• Clear behavior (mostly)
• Simple
State Machines Everywhere
Business Logic: State Machine
Hardware Abstraction: State Machine
Grocery List: State Machine
• Manages complexity.
• Testable.
• Automatically avoids most ‘'Once a year on a full moon”.
• Avoids accidental algrorithmic runtime complexity.
• Easier to share/outsource/reuse.
Modular Design
• Manages complexity
• Testable, unit and integration
• By side effect avoids “Once a year on a full moon”.
• Avoids accidental algorithmic runtime complexity.
• Allows desktop (a.k.a., much faster, better, stronger)
debugging and testing by divorcing behavior from
hardware.
AlarmBehavior.c, AlarmIO.c, AlertSend.c
vs.
Main.c, IO.c, Wireless.c
HARDWARE
ABSTRACTION LAYER
(HAL)
Separate hardware interface from behavior
Keep It Simple Stupid.
Do the minimum to create a clear abstraction.
(do not teach it to read lips)
Hardware Abstraction Layer (HAL)
A basic re-usable HAL design:
• HW_Init
• SW_Init
• Tick_1ms (10, 100)
• $OtherInterrupts
• ProcessData
• StateUpdate (Optional)
• SW_Deinit, HW_Deinit (Optional)
HW_Init, SW_Init
• HW_Init call to setup hardware (IO, memory, DMA)
• SW_Init to setup software (state machines, load NVM
values, etc)
• These happen on every awake, restore, or power on.
• Called by start-up or shutdown interrupts.
• (Optional mirror ‘HW_/SW_Deinit’ for sleep/shutdown).
• These do nothing but setup the landscape for the
program
Tick_?ms
• Maintenance function to tick clocks, watchdogs, timers
• Set time-based flags (timeouts, timers, error-flags)
• 1, 10, 100ms based on how “real time” your needs are
• Called by timer interrupt(s)
$OtherInterrupts
• All of your other interrupts in this category:
• DMA
• SPI
• FPU/GPU
• Radio
• Always: Clear or checks interrupt status, sets flags.
• Sometimes: Ticks state, sets timers, etc.
• Never: Processes data, does anything time-intensive.
ProcessData
• Checks flags. Does logic and intelligence. Shuffles
data/settings to modules.
• Called over and over again by main loop. Put time-
intensive things here.
• Checks flags, does business logic, and pulls/processes
data.
• For most projects StateUpdate behavior can be part of
this.
StateUpdate
• Updates state of HAL or driver
• Every HAL is a StateMachine
• With documentation
• And exceptions noted in cod
• Can be wrapped into ProcessData in most cases
SW_Deinit, HW_Deinit (Optional)
• Called on sleep/shutdown/timeout/fail
• First stop HAL software (SW_Deinit) then Hardware
• Set lines high
• Unregister interrupts
• Panic and/or cry
• In a lot of designs, this is avoidable.
• May never be called in a crash or a power-loss, so keep it
to “nice-to-have” things (sleep, pin safety, etc.)
Example Main.c
#include "spi.h"
#include "dma.h"
#include <interrupts.h>
// wake callback
int wakeFunction() I01_INT
{
int reason = IO1_INT_CAUSE & 0x0F;// Wake, POR,
SPI_HW_Init(reason);
DMA_HW_INIT(reason);
SPI_SW_INIT();
DMA_HW_INIT();
}
int main()
{
SPI_ProcessData();
DMA_ProcessData();
// Business Logic of how to handle, etc here.
If (DMA_running())
ThinkAboutDma();
else if (SPI_Complete())
SpiToDmaCollection();
}
int Tick_10ms() TIMER_0_INT
{
tick++;
DMA_Tick_10ms();
if(tick %10)
SPI_Tick_100ms()
watchdogKick();
}
void watchdogTimeout() WD_DOWN_INT
{
DMA_Deinit();
// no SPI_Deinit. Too simple
}
// #endif _EXAMPLE_MAIN_
Example SPI.c
#include "spi.h”
#include <interrupts.h>
Void SPI_HW_Init(WAKE_REASON r)
{
reason = r;
SET_INPUT(MISO);
SET_OUTPUT(MOSI,0);
SET_OUTPUT(SEL,0);
SET_OUTPUT(CLK,0);
w = CreateWatchdog();
Timer(&tick_10ms, 1);
}
void SPI_SW_Init()
{
queuedSz = 0; //bytes in quueed
memset(queued,0x5A, sizeof(queued)
clkLevel = 0;
byteJustCompleted = FALSE:
}
void SPI_Tick_10ms()
{
if (byteJustCompleted ) {
queueNextByte(); }
ColckBit() ..setsMOSI for next byte to send, reads MISO
PIN_SET(CLK, clkLevel)
clkLevel = (clkLevel == 1) ? 0 : 1 ; //toggle clk
// could do timeout checking here.
}
// We are master. No interrupts for us.
uint8_t SPI_QueueData( uint8_t data, uint8_t sz) {
//in reality, check size, buffer overflow, etc
memcpy( (&queued) + queueSz, data, sz)
queueSz += sz;
}
void SPI_ProcessData() {
tickWatchdog(w) ;
}
void SPI_SW_Deinit () { /*nothing to do here */ } ,
boolean SPI_Complete(){
return queueSz == 0;
}
void SPI_HW_Deinit ()
{
SET_OUTPUT(MISO,1);
SET_OUTPUT(MOSI,1);
SET_OUTPUT(SEL,1);
SET_OUTPUT(CLK,1);
}
ON DEVICE DEBUGGING
IS YOUR LAST RESORT
On device debugging is Last Resort
• If you are debugging on a device and it turns out it’s not a
hardware issue, you lost.
• Almost all testing should be on a desktop, using modern
desktop tools:
• Faster
• Better tools
• Less Flash/Test/WTF?/Tinker -> Flash/Test cycle
• Test -> WTF -> Test/ WTF cycle
• Using HAL and Modules = easy desktop debugging
• Using desktop debugging = easy HAL and modules
Bonus Best Pratices
20% Free Content, Yours For Only $10.99!!!
• Build and implement OTA/programming first(ish)
• Virtual Machines (for standard compilers at least)
• Have a canonical build server (even if just a senior
developer)
• Unit Test (almost) All The Things.
• Open Source (almost) All The Things.
• Decide on debugging streams at hardware design time
Questions? Comments?
Now Go Eat Cookies.
@farmckon
Bulogics.com
FarMcKon.net
Credits for Media
Pictures
• P1 - by Moyan Brenn on Flickr
• P2 – by Dannobytes on Flickr
• P4 - http://pixabay.com/en/lego-build-building-blocks-toys-708088/
• P5 - learnyousomeerlang.com (dog diagram)

Contenu connexe

Tendances

Spying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitSpying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitAndrea Righi
 
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)Dina Goldshtein
 
Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...
Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...
Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...Anne Nicolas
 
Measuring directly from cpu hardware performance counters
Measuring directly from cpu  hardware performance countersMeasuring directly from cpu  hardware performance counters
Measuring directly from cpu hardware performance countersJean-Philippe BEMPEL
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudAndrea Righi
 
Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...ScyllaDB
 
The Art of Java Benchmarking
The Art of Java BenchmarkingThe Art of Java Benchmarking
The Art of Java BenchmarkingAzul Systems Inc.
 
Get Lower Latency and Higher Throughput for Java Applications
Get Lower Latency and Higher Throughput for Java ApplicationsGet Lower Latency and Higher Throughput for Java Applications
Get Lower Latency and Higher Throughput for Java ApplicationsScyllaDB
 
Kernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at FacebookKernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at FacebookAnne Nicolas
 
ACPI and FreeBSD (Part 2)
ACPI and FreeBSD (Part 2)ACPI and FreeBSD (Part 2)
ACPI and FreeBSD (Part 2)Nate Lawson
 
When the OS gets in the way
When the OS gets in the wayWhen the OS gets in the way
When the OS gets in the wayMark Price
 
How NOT to Write a Microbenchmark
How NOT to Write a MicrobenchmarkHow NOT to Write a Microbenchmark
How NOT to Write a MicrobenchmarkAzul Systems Inc.
 
Linux kernel memory allocators
Linux kernel memory allocatorsLinux kernel memory allocators
Linux kernel memory allocatorsHao-Ran Liu
 
LCA14: LCA14-306: CPUidle & CPUfreq integration with scheduler
LCA14: LCA14-306: CPUidle & CPUfreq integration with schedulerLCA14: LCA14-306: CPUidle & CPUfreq integration with scheduler
LCA14: LCA14-306: CPUidle & CPUfreq integration with schedulerLinaro
 
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...Anne Nicolas
 
Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Brendan Gregg
 

Tendances (20)

Spying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitSpying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profit
 
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)
 
Meltdown & spectre
Meltdown & spectreMeltdown & spectre
Meltdown & spectre
 
Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...
Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...
Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...
 
Measuring directly from cpu hardware performance counters
Measuring directly from cpu  hardware performance countersMeasuring directly from cpu  hardware performance counters
Measuring directly from cpu hardware performance counters
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloud
 
Introduction to Perf
Introduction to PerfIntroduction to Perf
Introduction to Perf
 
Onnc intro
Onnc introOnnc intro
Onnc intro
 
Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...
 
The Art of Java Benchmarking
The Art of Java BenchmarkingThe Art of Java Benchmarking
The Art of Java Benchmarking
 
Get Lower Latency and Higher Throughput for Java Applications
Get Lower Latency and Higher Throughput for Java ApplicationsGet Lower Latency and Higher Throughput for Java Applications
Get Lower Latency and Higher Throughput for Java Applications
 
Kernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at FacebookKernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at Facebook
 
ACPI and FreeBSD (Part 2)
ACPI and FreeBSD (Part 2)ACPI and FreeBSD (Part 2)
ACPI and FreeBSD (Part 2)
 
When the OS gets in the way
When the OS gets in the wayWhen the OS gets in the way
When the OS gets in the way
 
How NOT to Write a Microbenchmark
How NOT to Write a MicrobenchmarkHow NOT to Write a Microbenchmark
How NOT to Write a Microbenchmark
 
Linux kernel memory allocators
Linux kernel memory allocatorsLinux kernel memory allocators
Linux kernel memory allocators
 
LCA14: LCA14-306: CPUidle & CPUfreq integration with scheduler
LCA14: LCA14-306: CPUidle & CPUfreq integration with schedulerLCA14: LCA14-306: CPUidle & CPUfreq integration with scheduler
LCA14: LCA14-306: CPUidle & CPUfreq integration with scheduler
 
Cache profiling on ARM Linux
Cache profiling on ARM LinuxCache profiling on ARM Linux
Cache profiling on ARM Linux
 
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
 
Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)
 

En vedette

Building mobile web apps with Mobello
Building mobile web apps with MobelloBuilding mobile web apps with Mobello
Building mobile web apps with MobelloJeong-Geun Kim
 
Bluetooth Smart: Connecting Medical Devices to Smart Phones
Bluetooth Smart: Connecting Medical Devices to Smart PhonesBluetooth Smart: Connecting Medical Devices to Smart Phones
Bluetooth Smart: Connecting Medical Devices to Smart PhonesCambridge Consultants
 
Test Cases Maintaining & Documenting
Test Cases Maintaining & DocumentingTest Cases Maintaining & Documenting
Test Cases Maintaining & DocumentingSeyed Ali Marjaie
 
ATAGTR2017 The way to recover the issue faced in IoT regression Testing
ATAGTR2017 The way to recover the issue faced in IoT regression TestingATAGTR2017 The way to recover the issue faced in IoT regression Testing
ATAGTR2017 The way to recover the issue faced in IoT regression TestingAgile Testing Alliance
 
50+ ways to improve tester - programmer relationship
50+ ways to improve tester - programmer relationship50+ ways to improve tester - programmer relationship
50+ ways to improve tester - programmer relationshipAgile Testing Alliance
 
IoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreadsIoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreadsIndicThreads
 
Android testing
Android testingAndroid testing
Android testingBitbar
 
Testing Checklist for Mobile Applications-By Anurag Khode
Testing Checklist for Mobile Applications-By Anurag KhodeTesting Checklist for Mobile Applications-By Anurag Khode
Testing Checklist for Mobile Applications-By Anurag KhodeAnurag Khode
 
AWS re:Invent 2016: IoT: Build, Test, and Securely Scale (GPST302)
AWS re:Invent 2016: IoT: Build, Test, and Securely Scale (GPST302)AWS re:Invent 2016: IoT: Build, Test, and Securely Scale (GPST302)
AWS re:Invent 2016: IoT: Build, Test, and Securely Scale (GPST302)Amazon Web Services
 
Mobile App Testing Checklist
Mobile App Testing ChecklistMobile App Testing Checklist
Mobile App Testing ChecklistManoj Lonar
 
ATAGTR2017 What Lies Beneath Robotics Process Automation
ATAGTR2017 What Lies Beneath Robotics Process AutomationATAGTR2017 What Lies Beneath Robotics Process Automation
ATAGTR2017 What Lies Beneath Robotics Process AutomationAgile Testing Alliance
 
Prototyping IoT- Easy Tools to Start Demonstrating Your Hardware Ideas- Santh...
Prototyping IoT- Easy Tools to Start Demonstrating Your Hardware Ideas- Santh...Prototyping IoT- Easy Tools to Start Demonstrating Your Hardware Ideas- Santh...
Prototyping IoT- Easy Tools to Start Demonstrating Your Hardware Ideas- Santh...WithTheBest
 
Testing Techniques for Mobile Applications
Testing Techniques for Mobile ApplicationsTesting Techniques for Mobile Applications
Testing Techniques for Mobile ApplicationsIndicThreads
 
Test cases for testing mobile phone
Test cases for testing mobile phoneTest cases for testing mobile phone
Test cases for testing mobile phoneAshwini Kamble
 
Information System Development
Information System DevelopmentInformation System Development
Information System DevelopmentSamudin Kassan
 
End-to-end Testing for IoT Integrity
End-to-end Testing for IoT IntegrityEnd-to-end Testing for IoT Integrity
End-to-end Testing for IoT IntegrityParasoft
 

En vedette (20)

Building mobile web apps with Mobello
Building mobile web apps with MobelloBuilding mobile web apps with Mobello
Building mobile web apps with Mobello
 
Bluetooth Smart: Connecting Medical Devices to Smart Phones
Bluetooth Smart: Connecting Medical Devices to Smart PhonesBluetooth Smart: Connecting Medical Devices to Smart Phones
Bluetooth Smart: Connecting Medical Devices to Smart Phones
 
Test Cases Maintaining & Documenting
Test Cases Maintaining & DocumentingTest Cases Maintaining & Documenting
Test Cases Maintaining & Documenting
 
Mobile App Testing
Mobile App TestingMobile App Testing
Mobile App Testing
 
ATAGTR2017 The way to recover the issue faced in IoT regression Testing
ATAGTR2017 The way to recover the issue faced in IoT regression TestingATAGTR2017 The way to recover the issue faced in IoT regression Testing
ATAGTR2017 The way to recover the issue faced in IoT regression Testing
 
50+ ways to improve tester - programmer relationship
50+ ways to improve tester - programmer relationship50+ ways to improve tester - programmer relationship
50+ ways to improve tester - programmer relationship
 
Testing AS A Container - Irfan Ahmad
Testing AS A Container - Irfan AhmadTesting AS A Container - Irfan Ahmad
Testing AS A Container - Irfan Ahmad
 
IoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreadsIoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreads
 
Android testing
Android testingAndroid testing
Android testing
 
D2D - Device to Device Communication
D2D - Device to Device CommunicationD2D - Device to Device Communication
D2D - Device to Device Communication
 
IoT: Testing - Shardul Rao
IoT: Testing - Shardul RaoIoT: Testing - Shardul Rao
IoT: Testing - Shardul Rao
 
Testing Checklist for Mobile Applications-By Anurag Khode
Testing Checklist for Mobile Applications-By Anurag KhodeTesting Checklist for Mobile Applications-By Anurag Khode
Testing Checklist for Mobile Applications-By Anurag Khode
 
AWS re:Invent 2016: IoT: Build, Test, and Securely Scale (GPST302)
AWS re:Invent 2016: IoT: Build, Test, and Securely Scale (GPST302)AWS re:Invent 2016: IoT: Build, Test, and Securely Scale (GPST302)
AWS re:Invent 2016: IoT: Build, Test, and Securely Scale (GPST302)
 
Mobile App Testing Checklist
Mobile App Testing ChecklistMobile App Testing Checklist
Mobile App Testing Checklist
 
ATAGTR2017 What Lies Beneath Robotics Process Automation
ATAGTR2017 What Lies Beneath Robotics Process AutomationATAGTR2017 What Lies Beneath Robotics Process Automation
ATAGTR2017 What Lies Beneath Robotics Process Automation
 
Prototyping IoT- Easy Tools to Start Demonstrating Your Hardware Ideas- Santh...
Prototyping IoT- Easy Tools to Start Demonstrating Your Hardware Ideas- Santh...Prototyping IoT- Easy Tools to Start Demonstrating Your Hardware Ideas- Santh...
Prototyping IoT- Easy Tools to Start Demonstrating Your Hardware Ideas- Santh...
 
Testing Techniques for Mobile Applications
Testing Techniques for Mobile ApplicationsTesting Techniques for Mobile Applications
Testing Techniques for Mobile Applications
 
Test cases for testing mobile phone
Test cases for testing mobile phoneTest cases for testing mobile phone
Test cases for testing mobile phone
 
Information System Development
Information System DevelopmentInformation System Development
Information System Development
 
End-to-end Testing for IoT Integrity
End-to-end Testing for IoT IntegrityEnd-to-end Testing for IoT Integrity
End-to-end Testing for IoT Integrity
 

Similaire à IOT Firmware: Best Pratices

SMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgiSMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgiTakuya ASADA
 
Fast and Furious: Handling Edge Computing Data With Oracle 19c Fast Ingest an...
Fast and Furious: Handling Edge Computing Data With Oracle 19c Fast Ingest an...Fast and Furious: Handling Edge Computing Data With Oracle 19c Fast Ingest an...
Fast and Furious: Handling Edge Computing Data With Oracle 19c Fast Ingest an...Jim Czuprynski
 
OS scheduling and The anatomy of a context switch
OS scheduling and The anatomy of a context switchOS scheduling and The anatomy of a context switch
OS scheduling and The anatomy of a context switchDaniel Ben-Zvi
 
Week1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC BeginWeek1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC Begin敬倫 林
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -evechiportal
 
Capacity Planning for fun & profit
Capacity Planning for fun & profitCapacity Planning for fun & profit
Capacity Planning for fun & profitRodrigo Campos
 
May2010 hex-core-opt
May2010 hex-core-optMay2010 hex-core-opt
May2010 hex-core-optJeff Larkin
 
Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...
Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...
Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...Priyanka Aash
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak PROIDEA
 
Systems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesSystems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesHelpWithAssignment.com
 
Zabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet MensZabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet MensNETWAYS
 
Objects? No thanks!
Objects? No thanks!Objects? No thanks!
Objects? No thanks!corehard_by
 
E yantra robot abstractions
E yantra robot abstractionsE yantra robot abstractions
E yantra robot abstractionsAkshar Desai
 
HAB Software Woes
HAB Software WoesHAB Software Woes
HAB Software Woesjgrahamc
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugginglibfetion
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisC4Media
 

Similaire à IOT Firmware: Best Pratices (20)

SMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgiSMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgi
 
Fast and Furious: Handling Edge Computing Data With Oracle 19c Fast Ingest an...
Fast and Furious: Handling Edge Computing Data With Oracle 19c Fast Ingest an...Fast and Furious: Handling Edge Computing Data With Oracle 19c Fast Ingest an...
Fast and Furious: Handling Edge Computing Data With Oracle 19c Fast Ingest an...
 
OS scheduling and The anatomy of a context switch
OS scheduling and The anatomy of a context switchOS scheduling and The anatomy of a context switch
OS scheduling and The anatomy of a context switch
 
Week1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC BeginWeek1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC Begin
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
 
Capacity Planning for fun & profit
Capacity Planning for fun & profitCapacity Planning for fun & profit
Capacity Planning for fun & profit
 
May2010 hex-core-opt
May2010 hex-core-optMay2010 hex-core-opt
May2010 hex-core-opt
 
Ieee 1149.1-2013-tutorial-ijtag
Ieee 1149.1-2013-tutorial-ijtagIeee 1149.1-2013-tutorial-ijtag
Ieee 1149.1-2013-tutorial-ijtag
 
Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...
Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...
Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...
 
Audit
AuditAudit
Audit
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
 
Systems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesSystems Programming Assignment Help - Processes
Systems Programming Assignment Help - Processes
 
Zabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet MensZabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet Mens
 
Fedor Polyakov - Optimizing computer vision problems on mobile platforms
Fedor Polyakov - Optimizing computer vision problems on mobile platforms Fedor Polyakov - Optimizing computer vision problems on mobile platforms
Fedor Polyakov - Optimizing computer vision problems on mobile platforms
 
Objects? No thanks!
Objects? No thanks!Objects? No thanks!
Objects? No thanks!
 
E yantra robot abstractions
E yantra robot abstractionsE yantra robot abstractions
E yantra robot abstractions
 
Programar para GPUs
Programar para GPUsProgramar para GPUs
Programar para GPUs
 
HAB Software Woes
HAB Software WoesHAB Software Woes
HAB Software Woes
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic Analysis
 

Dernier

Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Configuration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentConfiguration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentBharaniDharan195623
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Coursebim.edu.pl
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptNarmatha D
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxVelmuruganTECE
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdfCaalaaAbdulkerim
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 

Dernier (20)

Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
Configuration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentConfiguration of IoT devices - Systems managament
Configuration of IoT devices - Systems managament
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Course
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdf
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 

IOT Firmware: Best Pratices

  • 1. IOT FIRMWARE DESIGN: BEST PRACTICES (for embedded development that sucks less) @farmckon @BuLogics
  • 3. Common Problems: • “Code, flash, bang-on-it” cycle • Development environment setup sucks • Debugging with little/no IO • Complex bug scenario recreation • “Hurry up and wait” on hardware spins
  • 4. Design ToAvoid ‘em: • Program in C • State Machines Everywhere • Proper Modular Design • Hardware Abstraction Layer, • Hardware Abstraction Layer, • Hardware Abstraction Layer! • On-Device debugging is a last resort
  • 6. Program Drivers/Firmware in C! Just do it • Platform portable • Fast • Clear behavior (mostly) • Simple
  • 7. State Machines Everywhere Business Logic: State Machine Hardware Abstraction: State Machine Grocery List: State Machine • Manages complexity. • Testable. • Automatically avoids most ‘'Once a year on a full moon”. • Avoids accidental algrorithmic runtime complexity. • Easier to share/outsource/reuse.
  • 8. Modular Design • Manages complexity • Testable, unit and integration • By side effect avoids “Once a year on a full moon”. • Avoids accidental algorithmic runtime complexity. • Allows desktop (a.k.a., much faster, better, stronger) debugging and testing by divorcing behavior from hardware. AlarmBehavior.c, AlarmIO.c, AlertSend.c vs. Main.c, IO.c, Wireless.c
  • 9. HARDWARE ABSTRACTION LAYER (HAL) Separate hardware interface from behavior Keep It Simple Stupid. Do the minimum to create a clear abstraction. (do not teach it to read lips)
  • 10. Hardware Abstraction Layer (HAL) A basic re-usable HAL design: • HW_Init • SW_Init • Tick_1ms (10, 100) • $OtherInterrupts • ProcessData • StateUpdate (Optional) • SW_Deinit, HW_Deinit (Optional)
  • 11. HW_Init, SW_Init • HW_Init call to setup hardware (IO, memory, DMA) • SW_Init to setup software (state machines, load NVM values, etc) • These happen on every awake, restore, or power on. • Called by start-up or shutdown interrupts. • (Optional mirror ‘HW_/SW_Deinit’ for sleep/shutdown). • These do nothing but setup the landscape for the program
  • 12. Tick_?ms • Maintenance function to tick clocks, watchdogs, timers • Set time-based flags (timeouts, timers, error-flags) • 1, 10, 100ms based on how “real time” your needs are • Called by timer interrupt(s)
  • 13. $OtherInterrupts • All of your other interrupts in this category: • DMA • SPI • FPU/GPU • Radio • Always: Clear or checks interrupt status, sets flags. • Sometimes: Ticks state, sets timers, etc. • Never: Processes data, does anything time-intensive.
  • 14. ProcessData • Checks flags. Does logic and intelligence. Shuffles data/settings to modules. • Called over and over again by main loop. Put time- intensive things here. • Checks flags, does business logic, and pulls/processes data. • For most projects StateUpdate behavior can be part of this.
  • 15. StateUpdate • Updates state of HAL or driver • Every HAL is a StateMachine • With documentation • And exceptions noted in cod • Can be wrapped into ProcessData in most cases
  • 16. SW_Deinit, HW_Deinit (Optional) • Called on sleep/shutdown/timeout/fail • First stop HAL software (SW_Deinit) then Hardware • Set lines high • Unregister interrupts • Panic and/or cry • In a lot of designs, this is avoidable. • May never be called in a crash or a power-loss, so keep it to “nice-to-have” things (sleep, pin safety, etc.)
  • 17. Example Main.c #include "spi.h" #include "dma.h" #include <interrupts.h> // wake callback int wakeFunction() I01_INT { int reason = IO1_INT_CAUSE & 0x0F;// Wake, POR, SPI_HW_Init(reason); DMA_HW_INIT(reason); SPI_SW_INIT(); DMA_HW_INIT(); } int main() { SPI_ProcessData(); DMA_ProcessData(); // Business Logic of how to handle, etc here. If (DMA_running()) ThinkAboutDma(); else if (SPI_Complete()) SpiToDmaCollection(); } int Tick_10ms() TIMER_0_INT { tick++; DMA_Tick_10ms(); if(tick %10) SPI_Tick_100ms() watchdogKick(); } void watchdogTimeout() WD_DOWN_INT { DMA_Deinit(); // no SPI_Deinit. Too simple } // #endif _EXAMPLE_MAIN_
  • 18. Example SPI.c #include "spi.h” #include <interrupts.h> Void SPI_HW_Init(WAKE_REASON r) { reason = r; SET_INPUT(MISO); SET_OUTPUT(MOSI,0); SET_OUTPUT(SEL,0); SET_OUTPUT(CLK,0); w = CreateWatchdog(); Timer(&tick_10ms, 1); } void SPI_SW_Init() { queuedSz = 0; //bytes in quueed memset(queued,0x5A, sizeof(queued) clkLevel = 0; byteJustCompleted = FALSE: } void SPI_Tick_10ms() { if (byteJustCompleted ) { queueNextByte(); } ColckBit() ..setsMOSI for next byte to send, reads MISO PIN_SET(CLK, clkLevel) clkLevel = (clkLevel == 1) ? 0 : 1 ; //toggle clk // could do timeout checking here. } // We are master. No interrupts for us. uint8_t SPI_QueueData( uint8_t data, uint8_t sz) { //in reality, check size, buffer overflow, etc memcpy( (&queued) + queueSz, data, sz) queueSz += sz; } void SPI_ProcessData() { tickWatchdog(w) ; } void SPI_SW_Deinit () { /*nothing to do here */ } , boolean SPI_Complete(){ return queueSz == 0; } void SPI_HW_Deinit () { SET_OUTPUT(MISO,1); SET_OUTPUT(MOSI,1); SET_OUTPUT(SEL,1); SET_OUTPUT(CLK,1); }
  • 19. ON DEVICE DEBUGGING IS YOUR LAST RESORT
  • 20. On device debugging is Last Resort • If you are debugging on a device and it turns out it’s not a hardware issue, you lost. • Almost all testing should be on a desktop, using modern desktop tools: • Faster • Better tools • Less Flash/Test/WTF?/Tinker -> Flash/Test cycle • Test -> WTF -> Test/ WTF cycle • Using HAL and Modules = easy desktop debugging • Using desktop debugging = easy HAL and modules
  • 21. Bonus Best Pratices 20% Free Content, Yours For Only $10.99!!! • Build and implement OTA/programming first(ish) • Virtual Machines (for standard compilers at least) • Have a canonical build server (even if just a senior developer) • Unit Test (almost) All The Things. • Open Source (almost) All The Things. • Decide on debugging streams at hardware design time
  • 22. Questions? Comments? Now Go Eat Cookies. @farmckon Bulogics.com FarMcKon.net
  • 23. Credits for Media Pictures • P1 - by Moyan Brenn on Flickr • P2 – by Dannobytes on Flickr • P4 - http://pixabay.com/en/lego-build-building-blocks-toys-708088/ • P5 - learnyousomeerlang.com (dog diagram)

Notes de l'éditeur

  1. Welcome to the talk. Thanks Tech Week folks, etc Glad to have you here.
  2. EMBEDDED DEVELOPMENT (AKA Things in Internet of Things) SHITTY. SLOW. PAINFUL. Stuck in the 1970’s
  3. .. Or objective C, or other