How to port VSCP to new platform

How to port VSCP to new platform

To port VSCP to a new platform is not very hard even if it involves some steps.

  • Locate the firmware/common folder in the source. Here the two file vscp.c and vscp.h is located which actually implement a full VSCP node. The folder src/vscp/common holds other important files which are aimed for higher level systems but the files vscp_class.h which defines all classes and the vscp_type.h which defines types is needed.
  • inttypes.h is needed by the VSCP code. Most systems have this code already available if your systme does not there is an inttype.h in the common floder. Check that it is correct for your firmware.
  • Now think of how the registers should be organized for your device. Most nodes need a zone and at least one subzone or maybe several. All registers are 8-bit wide so if you have larger values they need to be split. In this case place the MSB first i.e. at the lowest register position. The VSCP Kelvin node (found here http://www.vscp.org/wiki/doku.php/kelvin_smart_ii_-_temperature_times_2_module) can be used as a guide.
  • Now define the events the node should send. Also determine if it should respond to certain events. All CLASS1.PROTOCOL such as register read/writes are taken care of by the vscp.c code
  • Now start to code on your platform. Get the system up and running and construct a one millisecond timebase. Update the vscp_timer here.
  • Add another timing variable that just like the vscp_timer is updated every millisecond.
  • In the free flowing mainloop of your program check if the timing variable of above is > 1000 that is if one second has elapsed. Now set the value to zero and call vscp_doOneSecondWork()
  • Each VSCP node should have a init button. Typically the init button should be pressed for two seconds before an init condition occurs. A variable vscp_initbtncnt hold this information and the buttons should be checked in the timebase and set to zero if the button is not pressed or increased by one as long as it is pressed.
  • Each VSCP node should have a status LED. This LED should blink when the node is initializing. That is searching for a free nickname address. It should light steady when the node is active and be turned off if init error. Typical code in the timebase can look like this for a PIC processor
    // Status LED
 
    vscp_statuscnt++;
 
    if ( ( VSCP_LED_BLINK1 == vscp_initledfunc ) && ( vscp_statuscnt > 100 ) ) {
 
        if ( PORTCbits.RC1 ) {
 
            PORTCbits.RC1 = 0;
 
        }
        else {
 
            PORTCbits.RC1 = 1;
 
        }
 
        vscp_statuscnt = 0;
 
    }
    else if ( VSCP_LED_ON == vscp_initledfunc ) {
 
        PORTCbits.RC1 = 1;
        vscp_statuscnt = 0;
 
    }
    else if ( VSCP_LED_OFF == vscp_initledfunc ) {
 
        PORTCbits.RC1 = 0;
        vscp_statuscnt = 0;
 
    }
  • A typical main loop can look something like this
//***************************************************************************
 
// Main() - Main Routine
 
//***************************************************************************
 
void main()
 
{
 
    init();                  // Initialize Microcontroller
 
 
 
    // Check VSCP persistent storage and
 
    // restore if needed
 
    if ( !vscp_check_pstorage() ) {
 
 
 
        init_app_eeprom();     // Initialize the application EEPROM
 
 
 
    }
 
 
 
    vscp_init();           // Initialize the VSCP functionality
 
 
 
    while ( 1 ) {          // Loop Forever
 
 
 
           ClrWdt();           // Feed the dog
 
 
 
       if ( ( vscp_initbtncnt > 500 ) && ( VSCP_STATE_INIT != vscp_node_state ) ) {
 
 
           // Init button pressed
 
           vscp_nickname = VSCP_ADDRESS_FREE;
 
               writeEEPROM( VSCP_EEPROM_NICKNAME, VSCP_ADDRESS_FREE );
 
               vscp_init();
 
           }
 
 
 
           // Check for a valid event
           vscp_imsg.flags = 0;
 
           vscp_getEvent();
 
 
 
           // do a meaurement if needed
 
           if ( measurement_clock > 1000 ) {
 
 
 
               measurement_clock = 0;
 
 
 
 
               // Do VSCP one second jobs
 
               vscp_doOneSecondWork();
 
 
 
 
 
               switch ( vscp_node_state ) {
 
 
 
               case VSCP_STATE_STARTUP:            // Cold/warm reset
 
 
 
                   // Get nickname from EEPROM
 
                   if ( VSCP_ADDRESS_FREE == vscp_nickname ) {
 
                       // new on segment need a nickname
 
                       vscp_node_state = VSCP_STATE_INIT;
 
                   }
 
 
                   else {
 
                       // been here before - go on
 
                       vscp_node_state = VSCP_STATE_ACTIVE;
 
                       vscp_goActiveState();
 
                    }
 
                    break;
 
 
 
               case VSCP_STATE_INIT:            // Assigning nickname
 
                   vscp_handleProbeState();
 
                   break;
 
 
 
               case VSCP_STATE_PREACTIVE:        // Waiting for host initialisation
 
                   vscp_goActiveState();
 
                   break;
 
 
 
                case VSCP_STATE_ACTIVE:            // The normal state
 
 
 
                    if ( vscp_imsg.flags & VSCP_VALID_MSG ) {    // incoming message?
 
 
 
                        vscp_handleProtocolEvent();
 
 
 
                    }
 
                    break;
 
 
 
                case VSCP_STATE_ERROR:            // Everything is *very* *very* bad.
 
                    vscp_error();
 
            break;
 
 
 
                default:                    // Should not be here...
 
                    vscp_node_state = VSCP_STATE_STARTUP;
 
                    break;
 
 
 
         }
 
 
 
         doWork(); // Do general application work
 
 
 
    } // while
  • Now construct a MDF file that describes your module and upload it to a server where it can be reached by application software.
  • This is it. Now just code your application.
  • A good example to look at is the Kelvin Smart II module. The code is available in firmware/pic/Kelvin/Smart2/project

Go back

howto/how_to_port_vscp_to_new_firmware.txt · Last modified: 2010/08/19 02:55 (external edit)
Public Domain www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0