- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I wonder why the component APIs aren't written for accessing the components "by reference". Instead, for each component the API is 'cloned'. Having the API functions only once would save code space.
Is there any special reason for that (e.g. hard to implement or not fail-save, etc.)? In fact, the ARM Cortex architecture is well suited for such an approach since registers must accessed by pointers anyway.
Regards,
Ralf
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, this would not always save space. Right now the configuration of the components is taken into account when generating code (e.g. when you use a UART but don't need the address matching feature no code is generated). When the code yould get a reference to a data object defining which hardware to use, and how it is configured, all the code needs to be there all the time. Also less optimizations could be done (speed-wise) since all cases must be evaluated all the time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, this would not always save space. Right now the configuration of the components is taken into account when generating code (e.g. when you use a UART but don't need the address matching feature no code is generated). When the code yould get a reference to a data object defining which hardware to use, and how it is configured, all the code needs to be there all the time. Also less optimizations could be done (speed-wise) since all cases must be evaluated all the time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi hli,
hmmm... no one keeps Cypress from ORing the component configurations to decide if a given function has to be included or not. And I think in this case space can be saved - for example, the 4100/4200 SCBs in unconfigured state eat >10kB of code space. Even if they'd be configured differently, the space for the common functions could be saved.
Of course, it'd be error prone if the developer must specify the pointer to the desired instance, but this could be solved like it's already done by the actual implementation ($INSTANCE_NAME prefix).
Also less optimizations could be done (speed-wise) since all cases must be evaluated all the time.
Not sure if I understand what you mean.
Regards,
Ralf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is also something I would like. For example, if I want to control 4 motors, then I need 4 quadrature decoders and 4 PWMs. Now I have to have 4 copies of my code, each identical, except for the names of the components it's talking to. It would be much cleaner if I could have just 1 function which took a pointer to the component.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I agree, even the initialization functions can be created only once. Only the variables marking that the initialization has already be done must be handled per instance.
Regards,
Ralf