0
\$\begingroup\$

At first, I am still learning and there is still long way to go. Please bear with me. As far as I know that a standard single core MCU can handle single program.

But, I have seen some MCU's have a sort of default program running all the time and user can upload his/her program in order to make some additions or customization without dealing with the default program.

For example, I have come across a product has single MCU (ATXMEGA128D3). This MCU has a program on it. It runs all the time and communicate with many sensors. So far so good. The Product allows me to write code for my custom demands. To do this, the Product provides with their libraries. It doesn't allow me to access to the MCU's peripherals/sensors explicitly but via some libraries.

So, when I am done with my programming I have very few lines of code. I flash it via PDI interface using Atmel ICE. It is quite straight forward.

Here is the code for a simple add-on;

#include "ApplicationIncludes.h"
static volatile word Counter;

static void Maint1000()
{
  WriteCStr(chMon,"\r\nHello World!");
  debugWrUInt("Counter",Counter++,-1);
}
static void Maint() {

}
void ApplicationInit()
{
  Register_Maint1000(Maint1000);
  Register_Maint(Maint);
  SetMonState(1);
} 

This is the part I don't get it. I like to know how this is possible, how this is called and how I can use same way for my own applications?

\$\endgroup\$
  • \$\begingroup\$ your thinking is incorrect ..... this line #include "ApplicationIncludes.h" adds the sensor interface code to your program \$\endgroup\$ – jsotola Jun 3 '18 at 1:39
  • \$\begingroup\$ Basically, main program is added to your code by #include. When it starts it calls ApplicationInit() where you register entry points to your own functions with their proprietary code. After that their code does whatever they want and calls your functions from time to time. If, for example, you never return control from your functions you might be able to stop their code completely... or not, if they use timer interrupts for thread management. \$\endgroup\$ – Maple Jun 3 '18 at 1:49
  • \$\begingroup\$ @jsotola, thank you for your input. I have only .h and .a files given by the product seller. Are those enough to operate the default program? \$\endgroup\$ – Sener Jun 3 '18 at 1:54
  • \$\begingroup\$ @Maple, thank you for your input as well. I am getting enlightened. In fact that, Now, I noticed, the default program stops when I flashed mine! I need to figure out how to prevent this happening. Can you see a way to do that based on my code in the question? \$\endgroup\$ – Sener Jun 3 '18 at 2:03
  • \$\begingroup\$ the .h and .a files should be enough .... the .a file is "compiled code" and the .h file is basically an index into the .a file that tells the compiler and the linker where to find the functions \$\endgroup\$ – jsotola Jun 3 '18 at 2:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.