Peripheral Template Library - efficient solution for cross-MCU development
i'd introduce project called "peripheral template library" (ptl), (experimental) library allow development of software/firmware portable across different boards , mcu types/architectures, without compromising efficiency. achieve both, ptl heavily relies on compile-time metaprogramming techniques , compile-time optimizations targeting level of efficiency , performance higher of typical c lib, , closer towards assembler.
people solid software development background, when hearing metaprogramming, thought lisp , powerful macros. indeed, in parallel world efficient mcu lib written in lisp (or scheme). however, in our world lisp niche language due syntax, , there're no optimizing lisp compilers simple mcus. fortunately, alexandrescu et al. thought giving metaprogramming hands of c programmers, commonly known "c++ templates". so, that's - ptl c++ template library depends on (usually simple) metaprogramming techniques achieve desired efficiency. note c++ still associated runtime object-oriented programming (that's in particular how arduino uses it), ~20-years old c++ usage. modern c++ multi-paradigm language, metaprogramming being central feature of it.
ptl of course inspired (spirit of) arduino. arduino, have def-facto standard api programming microcontrollers. unfortunately, it's well-known fact standard implementation of arduino api far being efficient, pin access methods being dozen if not hundred times slower allowed hardware. reuse of components problem - there're oftentimes problem using different libs accessing same bus/pins, , typical solution problem sacrifices efficiency. finally, while arduino api ported many popular architectures (msp430 energia, stm32 maple, etc.), overall support , compatibility rather sketchy , porting new platform or chip variant cumbersome, , - again - result inefficient.
so, target audience of ptl people "growing out" of arduino , want freely explore new chips , board, , write code, can directly turned "production" , optimized. example, if fits within attiny13, don't need put entire arduino it. , if have app works on arduino, can put shiny new arm cortex-m board use running there too, without collecting dust on shelf, while try find time delve beautiful , frightening world of cortex-m...
ptl available here: https://github.com/pfalcon/peripheraltemplatelibrary
people solid software development background, when hearing metaprogramming, thought lisp , powerful macros. indeed, in parallel world efficient mcu lib written in lisp (or scheme). however, in our world lisp niche language due syntax, , there're no optimizing lisp compilers simple mcus. fortunately, alexandrescu et al. thought giving metaprogramming hands of c programmers, commonly known "c++ templates". so, that's - ptl c++ template library depends on (usually simple) metaprogramming techniques achieve desired efficiency. note c++ still associated runtime object-oriented programming (that's in particular how arduino uses it), ~20-years old c++ usage. modern c++ multi-paradigm language, metaprogramming being central feature of it.
ptl of course inspired (spirit of) arduino. arduino, have def-facto standard api programming microcontrollers. unfortunately, it's well-known fact standard implementation of arduino api far being efficient, pin access methods being dozen if not hundred times slower allowed hardware. reuse of components problem - there're oftentimes problem using different libs accessing same bus/pins, , typical solution problem sacrifices efficiency. finally, while arduino api ported many popular architectures (msp430 energia, stm32 maple, etc.), overall support , compatibility rather sketchy , porting new platform or chip variant cumbersome, , - again - result inefficient.
so, target audience of ptl people "growing out" of arduino , want freely explore new chips , board, , write code, can directly turned "production" , optimized. example, if fits within attiny13, don't need put entire arduino it. , if have app works on arduino, can put shiny new arm cortex-m board use running there too, without collecting dust on shelf, while try find time delve beautiful , frightening world of cortex-m...
ptl available here: https://github.com/pfalcon/peripheraltemplatelibrary
currently, ptl supports following mcu architectures , boards:
here's expected led blinker example in ptl:
again, example can compiled of boards listed above without changes , "just work", , @ same time contain little code needed implement functionality.
code: [select]
* ti msp430
* msp430 launchpad
* atmel avr
* arduino duemilanove
* arm cortex-m
* st stm32
* stm32vldiscovery
* energy micro efm32
* efm32gg-stk3700
* ti tiva c tm4 (former stellaris lm4)
* stellaris/tiva launchpad
here's expected led blinker example in ptl:
code: [select]
#include <gpio.hpp>
#include <cpu.hpp>
#include <board.hpp>
#include <delay_static.hpp>
#include <delay_time.hpp>
using namespace ptl;
typedef timedelay<board::freq, staticdelay> delayer;
int main()
{
cpu::init(cpu::default);
board::led::port::enable();
board::led::output();
while (true) {
board::led::high();
delayer::delay_ms(500);
board::led::low();
delayer::delay_ms(500);
}
}
again, example can compiled of boards listed above without changes , "just work", , @ same time contain little code needed implement functionality.
Arduino Forum > Development > Other Software Development > Peripheral Template Library - efficient solution for cross-MCU development
arduino
Comments
Post a Comment