Main Page | Modules | Related Pages | Examples

Getting Started, Hello World!

Hello World!

This section tells you how to write applications for Turbo Programmer.

We start with a simple hello-world example.

/*
 * Copyright (C) 2004 BLADOX, s.r.o.  All rights reserved.
 * 
 * This file is part of an example program for Turbo. This example
 * program may be used, distributed and modified without limitation.
 *
 */

#include <config.h>
#include <tprog/tprog.h>

u8 PROGMEM hello[] = "helloworld!";

void turbo_handler (u8 action, USB_Data *data)
{
  switch (action)
  {
    case 0x80:
        usb_send (NO_ERROR, sizeof (hello), hello);
    default:
      break;
  }
}

You can see there is one function in this example:

This function is required for every application and has to be called turbo_handler().

Attention:
Your application code must include the turbo_handler() function.
The turbo_handler() function is a handler - it receives actions and somehow handles them.
Note:
We could call the "action" also "event" or "signal" as well, but we decided to use the term action (ACTION_SOMETHING).
app_struct.png

Application structure


So handler receives actions and somehow reacts. There are actions related to:

For more see Actions.

In our hello-world example we handle just one action 0x80. It responds with "helloworld!" string.

prog_apps                       # you get the application number list
prog_apps -a app_nr -x 128      # send the 0x80 action to the application

Application Persistent Data

Application can store data in the EEPROM. The question is how to store the pointer on such data - it cannot be in RAM because its value would be lost after reset. So it has to be in EEPROM - pointer stored in EEPROM on data stored in EEPROM. The solution are the reg_app_data() and app_data() calls.

Typical example of persistent data usage

typedef struct _My_Persistent_Data
{
u8      x;
u16     y;
u8 *    p1;
} My_Persistent_Data;

u8 x;
u16 y;
u8 *p1;

void turbo_handler (u8 action, void *data)
{
  switch (action)
  {
    case ACTION_APP_REGISTER:
      {
        My_Persistent_Data *p = emalloc (sizeof (My_Persistent_Data));
        
        wb (&p->x, 0);
        ww (&p->y, 0x1234);
        ww (&p->p1, NULL);

        reg_app_data (p);
        break;
      }
    case ACTION_APP_UNREGISTER:
      {
        My_Persistent_Data *p = app_data ();
        
        efree (rw (&p->p1));
        efree (p);
        break;
      }
    case ACTION_APP_INIT:
      {
        My_Persistent_Data *p = app_data ();

        x = rb (&p->x);
        y = rw (&p->y);
        p1 = rw (&p->p1);
        break;
      }
...
  }
}


Copyright © 2004 BLADOX
Turbo Programmer version 2.0