Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to extend basic functionality of the MBED API? #2181

Closed
hesolium opened this issue Jul 16, 2016 · 4 comments
Closed

How to extend basic functionality of the MBED API? #2181

hesolium opened this issue Jul 16, 2016 · 4 comments

Comments

@hesolium
Copy link

I need to generate a signal (PWM) with high frequency. The minimum (standard) period for PWM is 1 uS. How to modify the API to obtain a shorter period?
My board (Nucleo-F401/84 MHz) has the ability to generate a PWM with shorter periods.
Of course, I do not want to program the device (STM32 TIMx)) from the beginning.
I think a better solution would be a slight modification behaviour of the existing API.

For this purpose, I have modified HAL for STMF4 (pwmout_api.c) as follows:

  1. I added and exposed additional variable 'short TIMadditionalPrescaler'
  2. I added 3 lines in ''pwmout_period_us' function for conditionally increase the standard (1000000) prescaler for 1 uS period.
    In my application before call method 'period_us' I can set suitable value for TIMadditionalPrescaler.
    For example if I need 250 ns PWM period I can set my additional prescaler to 4.

In a similar (easy:) way, we can expand behavior AnalogIn class to add the ability to trigger the measurement via an external GPIO pin.

Now it's time for a general question.

How should we design an MBED API that such minor changes will be possible for the implementation for specific targets? Maybe definitions of each (PMW,AnalogIn, ...) class should contain some elements that enable smooth and easy implementation of additional functionality specific for some target boards. How it should be done from a theoretical point of view?

@dinau
Copy link
Contributor

dinau commented Jul 17, 2016

Just for reference , Erik Olieman's FastPWM.
https://developer.mbed.org/users/Sissors/code/FastPWM/

dinau

@hesolium
Copy link
Author

@dinau:"FastPWM"

Oh, no. Build new class (e.g BetterAnalogIn, BetterPwmOut, ...) for every basic MBED class it is horrible solution. I know much better. For example we can add to every basic class new method:
'void *getHardwareDevice()'. This method should return pointer to C structure mapping device control registers (or NULL for standard, empty implementation). Having access to control registers, we can change behavior of the device at any time. Or maybe it would be better to add to each class new methods (attach/detach) like in Ticker class. There are many possibilities. I'm interested in how it should be done in accordance with C++ object design principles.

@hesolium
Copy link
Author

I checked several design patterns, and I think that I found the right solution. I think the best is 'Extension Objects Pattern' (http://st.inf.tu-dresden.de/Lehre/WS06-07/dpf/gamma96.pdf). With this pattern, with each object (eg PwmOut) we can statically (or dynamically) tie additional object which provides fields / methods that modify the behavior of the basic object methods. This solution does not interfere with the existing API. We only need to add one method for each basic class: 'int registerExtension (ExtClass object)'.
In my example we can create new class PwmOutExt with one field 'additionalprescaler'. Create object of this class and register this object.

@ciarmcom
Copy link
Member

ciarmcom commented Aug 1, 2016

ARM Internal Ref: IOTMORF-129

@sg- sg- removed the mirrored label Aug 12, 2016
@ghost ghost closed this as completed Oct 27, 2017
JarkkoPaso pushed a commit to JarkkoPaso/mbed-os that referenced this issue Oct 7, 2019
…..0824752

0824752 Merge branch 'release_internal' into release_external
f598339 Merge branch 'master' into release_internal
678e0fd Removed unicast RX flag set. it was affecting that we remove neighbor too early.
a4317fc Corrected coding style
cd2848e Added support for calculating the length of the TLS send message buffer
f255931 Removed UDP echo msg data print and added source address print.
adcca3d RPL dio config advertisment update
6db1f31 Merge pull request ARMmbed#2198 from ARMmbed/IOTTHD-3691
ad244d1 MAC: changed CCA and TX fail trace level to debug
496074a RPL parent select update:
32e22d3 MAC: Added trace to when CCA fails and packet TX is canceled
47b2e03 Corrected GKH initiation on supplicant
c83423a PAE controller now removes keys from MAC on stop (ifdown)
a6f98b7 Flagged extended key usage call with mbedTLS flags
0675a89 Added dynamic setting to enable certificate validation
ff531d3 Added IDevID and LDevID certificate validation
b30635f Merge pull request ARMmbed#2191 from ARMmbed/IOTTHD-3693
88019ec Updated message generated traces
ea15b0e Remove all instances when domain is disbaled and clear EAPOL relay.
dce25d3 Corrected security protocols init and security message routing
7b39e25 Do not trig Renew again after RPL parent registration done state.
3cad7bd DHCPv6 renew and transaction id update
c5b6df3 DHCPv6 client update
dea0d53 DHCPv6 client API update
5eaad10 Added missing address active flag init.
34c751b Corrected triggering of next GTK handshake on authenticator
4fad826 Corrected export keys callback parameters
26c10a6 SW MAC / 802.15.4 Frame counter per key support Update
b62b120 Added robustness on DAO-ACK handling
dfcebef Added support for new certificate modification functions
fd4b2e9 WS ARO handler update
e2d46b9 wi-sun neagtive ARO missing ACK update
443f03f Merge pull request ARMmbed#2181 from ARMmbed/IOTTHD-3530_2
f36da31 MAC: Update frame counter for asynch frames
3260fa1 Merge pull request ARMmbed#2177 from ARMmbed/IOTTHD-3530
f18052a MAC: Initialize frame counter with 0xffffffff
5453e5b MAC: Do not increment framecounter if security param init fails
5bd19c4 MAC: Do not update framecounter for fhss channel retry

git-subtree-dir: features/nanostack/sal-stack-nanostack
git-subtree-split: 0824752
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants