Visual Aspect-Oriented Programming Visual Aspect-Oriented Programming of of Resource Constrained Real-Time Resource Constrained Real-Time Embedded Systems Embedded Systems using the Port-Based Object Model of using the Port-Based Object Model of Computation Computation Thomas W. Carley Dept. of Electrical & Computer Engineering University of Maryland, College Park [email protected]David B. Stewart Embedded Research Solutions, LLC http://www.embedded- zone.com [email protected]
25
Embed
Visual Aspect-Oriented Programming of Resource Constrained Real-Time Embedded Systems using the Port-Based Object Model of Computation Thomas W. Carley.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
> xxx: copy from global intolocal state variable table
xxx >: copy from local intoglobal state variable table> in/out >> in/out >
> in-consts> in-consts
initinit
> out-consts> out-consts
NOTCREATED
NOTCREATED
spawnspawn
OFFOFF
> in-vars> in-vars
> out-vars> out-vars
onon
out-vars >out-vars >
onon
ONON
offoff
out-vars >out-vars >
offoff
out-vars >out-vars >
offoff
termterm
> out-consts> out-consts
out-vars >out-vars >
reinitreinit
> in-consts> in-consts
offoff
reinitreinit
termterm
termterm
out-vars >out-vars >
cyclecycle
> in-vars> in-vars
wakeupwakeup
syncsync
clockinterrupt
external signal
Periodic Aperiodic
init
on
cycle
off
term
PB
OP
BO
Example PBO SystemExample PBO Systemcar cruise controlcar cruise control
accel
brake
ccui
position
split-pm
dashboard
dy/dx
control
engine
wheels
Control Module
PBO ImplementationPBO Implementationusing Traditional Techniquesusing Traditional Techniques
PBOImplementation
PBOFramework
PBOCommunication
/* =======================================================================// Echidna(tm) RTExec 1.0: FPBO Module// -----------------------------------------------------------------------// Cruise control.// If cruise control is on, this module calculates the force needed// to maintain the reference velocity. If cruise control is off// or the user presses the brakes (override), then this module// passes the direct force through to splitpm.//// State variable table:// INVAR: user_ref v_mez v_ref//// OUTVAR: v_ref f_direct//// ======================================================================= */
/* *********************************************************************** // Include files// *********************************************************************** */#include <btypes.h>#include <fpbo.h>
/* *********************************************************************** // Local table 'controlLocal_t' and module definition required by Echidna// *********************************************************************** */typedef struct { // Pointers to SVARs go here bool_t *user_ref; // cruise control ON or OFF uint16_t *v_mez; // measured velocity uint16_t *v_ref; // reference velocity for cruise ctrl int16_t *f_direct; // force for acceleration
// Pointers to local variables go here etimeAbs_t time_new; etimeAbs_t time_old;
} controlLocal_t;
// Generate all of the function headers and structures for controlFPBO_MODULE(control);
/* *********************************************************************** // FPBO Functions// *********************************************************************** */fpboStatus_t controlInit(control_t *fpbo) { // Map local SVAR pointers to SVARs in the global table fpbo->local->user_ref = svarXlateValue(&fpbo->svartable, "user_ref", bool_t); fpbo->local->v_mez = svarXlateValue(&fpbo->svartable, "v_mez", uint16_t); fpbo->local->v_ref = svarXlateValue(&fpbo->svartable, "v_ref", uint16_t); fpbo->local->f_direct = svarXlateValue(&fpbo->svartable, "f_direct", int16_t);
return FPBO_STATUS_CONTINUE;}
fpboStatus_t controlReinit(control_t *fpbo) { // This function intentionally left blank. return FPBO_STATUS_CONTINUE;}
PBO System ConfigurationPBO System Configurationusing Traditional Techniquesusing Traditional Techniques
/* =======================================================================// Echidna(tm) RTExec 1.0: Main FPBO Module// -----------------------------------------------------------------------// Automobile Speed Control.// Takes input from wheel position resolver, cruise control user// interface, brake pedal, and accelerator pedal. Outputs to // engine, wheels, speedometer, and odometer. Applies different// forces depending on whether cruise control is on or off.//// State variable table:// INVAR: none//// OUTVAR: none//// ======================================================================= */ /* *********************************************************************** // Include files// *********************************************************************** */#include <stdlib.h>#include <etime.h>#include <fpbo.h>#include <svar.h>#include <vt.h> /* *********************************************************************** // Internal macro definitions// *********************************************************************** */#define _PERIOD_MAIN ETIME_REL_INFINITY#define _PERIOD_ACCEL 1000 // x0.1 ms#define _PERIOD_BRAKE 1000 // x0.1 ms#define _PERIOD_CCUI 1000 // x0.1 ms#define _PERIOD_POSITION 1000 // x0.1 ms#define _PERIOD_SPLITPM 1000 // x0.1 ms#define _PERIOD_CONTROL 1000 // x0.1 ms#define _PERIOD_TDERIV 1000 // x0.1 ms#define _PERIOD_DASHBOARD 1000 // x0.1 ms#define _PERIOD_ENGINE 1000 // x0.1 ms#define _PERIOD_WHEELS 1000 // x0.1 ms /* *********************************************************************** // Local table 'mainLocal_t' and module definition required by Echidna// *********************************************************************** */typedef struct { // Pointers to SVARs go here // Pointers to local variables go here fpboSBS_t *sbs;} mainLocal_t; // Generate all of the function headers and structures for mainFPBO_MODULE(main); /* *********************************************************************** // External definition of modules for main to create// *********************************************************************** */FPBO_INCLUDE(accel);FPBO_INCLUDE(brake);FPBO_INCLUDE(ccui);FPBO_INCLUDE(position);FPBO_INCLUDE(tderiv);FPBO_INCLUDE(control);FPBO_INCLUDE(splitpm);FPBO_INCLUDE(engine);FPBO_INCLUDE(wheels);FPBO_INCLUDE(dashboard); /* *********************************************************************** // Pointers to FPBOs for main to create// *********************************************************************** */fpbo_t *ccui;fpbo_t *position;fpbo_t *tderiv;fpbo_t *control;fpbo_t *dashboard; /* *********************************************************************** // Configurations for FPBOs for main to create// *********************************************************************** */const fpboCfg_t dashboardFpboCfg = { NULL, // next fpboCfg_t NULL, // list of aliases &dashboardMod, // fpboMod (from FPBO_INCLUDE) "dashboard", // name of fpbo PERIODIC, // tasktype (PERIODIC, APERIODIC) _PERIOD_DASHBOARD // period}; const fpboCfg_t controlFpboCfg = { &dashboardFpboCfg, // next fpboCfg_t NULL, // list of aliases &controlMod, // fpboMod (from FPBO_INCLUDE) "control", // name of fpbo PERIODIC, // tasktype (PERIODIC, APERIODIC) _PERIOD_CONTROL // period}; const fpboCfg_t tderivFpboCfg = { &controlFpboCfg, // next fpboCfg_t NULL, // list of aliases &tderivMod, // fpboMod (from FPBO_INCLUDE) "tderiv", // name of fpbo PERIODIC, // tasktype (PERIODIC, APERIODIC) _PERIOD_TDERIV // period};
const fpboCfg_t positionFpboCfg = { &tderivFpboCfg, // next fpboCfg_t NULL, // list of aliases &positionMod, // fpboMod (from FPBO_INCLUDE) "position", // name of fpbo PERIODIC, // tasktype (PERIODIC, APERIODIC) _PERIOD_POSITION // period}; const fpboCfg_t ccuiFpboCfg = { &positionFpboCfg, // next fpboCfg_t NULL, // list of aliases &ccuiMod, // fpboMod (from FPBO_INCLUDE) "ccui", // name of fpbo PERIODIC, // tasktype (PERIODIC, APERIODIC) _PERIOD_CCUI // period}; const fpboCfg_t mainFpboCfg = { &ccuiFpboCfg, // next fpboCfg_t NULL, // list of aliases &mainMod, // fpboMod (from FPBO_INCLUDE) "main", // name of fpbo PERIODIC, // tasktype (PERIODIC, APERIODIC) _PERIOD_MAIN // period}; /* *********************************************************************** // Linked list of FPBO configurations for main to create// *********************************************************************** */fpboCfg_t *cfglist = &mainFpboCfg; // points to header of list (main) /* *********************************************************************** // SVAR Attributes for main to place in global SVAR table// *********************************************************************** */const svarAttrib_t f_brake = { "f_brake", // name VT_UINT16_T, // type 1 // number of elements}; const svarAttrib_t user_ref = { "user_ref", // name VT_BOOL_T, // type 1 // number of elements}; const svarAttrib_t v_mez = { "v_mez", // name VT_UINT16_T, // type 1 // number of elements}; const svarAttrib_t v_ref = { "v_ref", // name VT_UINT16_T, // type 1 // number of elements}; const svarAttrib_t f_direct = { "f_direct", // name VT_INT16_T, // type 1 // number of elements}; const svarAttrib_t x_mez = { "x_mez", // name VT_UINT32_T, // type 1 // number of elements}; /* *********************************************************************** // Array of SVARs for main to place in global SVAR table // *********************************************************************** */svarVar_t mainSvar[] = { {&f_brake, NULL}, // {svarAttrib_t * attrib, void *value} {&user_ref, NULL}, // {svarAttrib_t * attrib, void *value} {&v_mez, NULL}, // {svarAttrib_t * attrib, void *value} {&v_ref, NULL}, // {svarAttrib_t * attrib, void *value} {&f_direct, NULL}, // {svarAttrib_t * attrib, void *value} {&x_mez, NULL} // {svarAttrib_t * attrib, void *value}}; /* *********************************************************************** // FPBO Functions// *********************************************************************** */fpboStatus_t mainInit(main_t *fpbo) { fpboSBS_t *sbs = fpbo->local->sbs; svarGlobalTable_t *globt; // Create the SVAR table globt = svarCreate(mainSvar); svarAttach(globt, &fpbo->svartable, fpbo->cfg->aliaslist); // Initialize the subsystem configuration sbs = fpboInitSBS(cfglist, globt); // Create all FPBOs ccui = fpboCreate(sbs, "ccui");
position = fpboCreate(sbs, "position"); tderiv = fpboCreate(sbs, "tderiv"); control = fpboCreate(sbs, "control"); dashboard = fpboCreate(sbs, "dashboard"); return FPBO_STATUS_CONTINUE;} // mainReinit is not defined. Default empty definitionfpboStatus_t mainReinit(main_t *fpbo) { // This function intentionally left blank. return FPBO_STATUS_CONTINUE;} fpboStatus_t mainOn(main_t *fpbo) { // Turn on all FPBOs fpboTurnon(ccui); fpboTurnon(position); fpboTurnon(tderiv); fpboTurnon(control); fpboTurnon(dashboard); return FPBO_STATUS_CONTINUE;} // The mainCycle routine monitors various state variables, and // can turn modules on and off as necessary to perform dynamic // reconfiguration.fpboStatus_t mainCycle(main_t *fpbo) { return FPBO_STATUS_CONTINUE;} fpboStatus_t mainSync(main_t *fpbo) { // Define function if FPBO tasktype is aperiodic return FPBO_STATUS_CONTINUE;} fpboStatus_t mainOff(main_t *fpbo) { // Turn off all FPBOs in opposite order of fpboTurnon fpboTurnoff(dashboard); fpboTurnoff(control); fpboTurnoff(tderiv); fpboTurnoff(position); fpboTurnoff(ccui); return FPBO_STATUS_OFF;} // cleanup: destroy the svar table that was created in mainInitfpboStatus_t mainTerm(main_t *fpbo) { // Destroy all FPBOs in opposite order of fpboCreate fpboDestroy(dashboard); fpboDestroy(control); fpboDestroy(tderiv); fpboDestroy(position); fpboDestroy(ccui); // Destroy the SVAR Table svarDestroy(fpbo->local->sbs->globt); return FPBO_STATUS_TERM;}
PBOImplementation
PBOFramework
PBOCommunication
Difficulties Programming Difficulties Programming the PBO MoCthe PBO MoC
Framework visible to programmer Framework distributed across PBOs PBO not portable across frameworks Implementation tangled
Data Types, Algorithms, Framework, Communication, Scheduling, Resource Management, etc.
PBO Implementation Specify local data & types Implement PBO methods
Algorithmic Language Use existing C compilers
PBOPBO
/* =======================================================================// Echidna(tm) RTExec 1.0: FPBO Module// -----------------------------------------------------------------------// Cruise control.// If cruise control is on, this module calculates the force needed// to maintain the reference velocity. If cruise control is off// or the user presses the brakes (override), then this module// passes the direct force through to splitpm.//// State variable table:// INVAR: user_ref v_mez v_ref//// OUTVAR: v_ref f_direct//// ======================================================================= */
/* *********************************************************************** // Include files// *********************************************************************** */#include <btypes.h>#include <fpbo.h>
/* *********************************************************************** // Local table 'controlLocal_t' and module definition required by Echidna// *********************************************************************** */typedef struct { // Pointers to SVARs go here bool_t *user_ref; // cruise control ON or OFF uint16_t *v_mez; // measured velocity uint16_t *v_ref; // reference velocity for cruise ctrl int16_t *f_direct; // force for acceleration
// Pointers to local variables go here etimeAbs_t time_new; etimeAbs_t time_old;
} controlLocal_t;
// Generate all of the function headers and structures for controlFPBO_MODULE(control);
/* *********************************************************************** // FPBO Functions// *********************************************************************** */fpboStatus_t controlInit(control_t *fpbo) { // Map local SVAR pointers to SVARs in the global table fpbo->local->user_ref = svarXlateValue(&fpbo->svartable, "user_ref", bool_t); fpbo->local->v_mez = svarXlateValue(&fpbo->svartable, "v_mez", uint16_t); fpbo->local->v_ref = svarXlateValue(&fpbo->svartable, "v_ref", uint16_t); fpbo->local->f_direct = svarXlateValue(&fpbo->svartable, "f_direct", int16_t);
return FPBO_STATUS_CONTINUE;}
PBO System DesignPBO System DesignVisual AspectVisual Aspect