LOGIN   :::   RECOVER PASS   :::   GET ACCOUNT    
Browse
  • Projects
  • Code (CVS)
  • Forums
  • News
  • Articles
  • Polls
  •  
    OpenCores
  • FAQ
  • CVS HowTo
  • Mission
  • Media
  • Tools
  • Advertise
  • Mirrors
  • Logos
  • Contact us
  • Job Opportunity
  •  
    Tools
  • Search
      
  • Download Cores (CVSGet)
  •  
    More
  • Wishbone
  • Perlilog
  • EDA tools
  • OpenTech CD
  •  
    Navigation: All forums > Cvs-checkins > Message List > Message Post

    Message

    Reply | Reply all
    Date Prev | Date Next | Thread Prev | Thread Next Date Index | Thread Index

    From: cvs at opencores.org<cvs@o...>
    Date: Mon Nov 13 15:53:57 CET 2006
    Subject: [cvs-checkins] MODIFIED: jop ...
    Top
    Date: 00/06/11 13:15:53

    Added: jop/java/target/src/rtapi/safetycritical RtEvent.java
    RtSystem.java
    Log:
    Classes for safety-critical Java


    Revision Changes Path
    1.1 jop/java/target/src/rtapi/safetycritical/RtEvent.java

    http://www.opencores.org/cvsweb.shtml/jop/java/target/src/rtapi/safetycritical/RtEvent.java?rev=1.1&content-type=text/x-cvsweb-markup

    Index: RtEvent.java
    ===================================================================
    package safetycritical;

    import java.util.*;

    public abstract class RtEvent {

    int period;
    int deadline;
    int offset;
    String event;

    static Vector eventList;


    /**
    * A periodic real-time event, equivalent to a periodic thread
    * @param period
    * @param deadline
    * @param offset
    */
    public RtEvent(int period, int deadline, int offset) {

    if (eventList==null) {
    eventList = new Vector();
    }
    this.period = period;
    this.deadline = deadline;
    this.offset = offset;
    this.event = null;

    // insert in a deadline monotonic order
    int cnt = eventList.size();
    int pos;
    for (pos=0; pos<cnt; ++pos) {
    RtEvent re = (RtEvent) eventList.elementAt(pos);
    if (deadline<=re.deadline) {
    break;
    }
    }

    eventList.insertElementAt(this, pos);
    }

    public RtEvent(int period, int deadline) {
    this(period, deadline, 0);
    }

    public RtEvent(int period) {
    this(period, period, 0);
    }

    /**
    * A sporadic event with a minimum interarrival time
    * @param event
    * @param minInterval
    * @param deadline
    */
    public RtEvent(String event, int minInterval, int deadline) {

    this(minInterval, deadline, 0);
    this.event = event;
    }


    public RtEvent(String event, int minInterval) {
    this(event, minInterval, 0);
    }


    /**
    * The logic for the event. run() gets invoked from the
    * scheduler either periodic, or on a hardware event or
    * on a software event (fire):
    * @return true if ready for termination
    */
    abstract protected boolean run();

    /**
    * Gets invoked in the shutdown phase at the same period as
    * run (instead of run()). Invoked until return true.
    * @return true is shutdown is finished.
    */
    protected boolean cleanup() {
    return true;
    }
    }

    1.1 jop/java/target/src/rtapi/safetycritical/RtSystem.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/rtapi/safetycritical/RtSystem.java?rev=1.1&content-type=text/x-cvsweb-markup Index: RtSystem.java =================================================================== package safetycritical; import java.util.*; import com.jopdesign.sys.RtThreadImpl; import joprt.RtThread; import joprt.SwEvent; public class RtSystem { private RtSystem() { // no RtSystem object } static Vector rtaLst, rsaLst; /** * Starts the real-time mission. All periodic and sporadic * RT-events are scheduled. * */ public static void start() { RtThreadImpl.init(); rtaLst = new Vector(); rsaLst = new Vector(); int cnt = RtEvent.eventList.size(); for (int i=0; i<cnt; ++i) { RtEvent re = (RtEvent) RtEvent.eventList.elementAt(i); if (re.event==null) { // a normal periodic thread RtThreadAdapter rta = new RtThreadAdapter(re, cnt-i, re.period, re.offset); rtaLst.addElement(rta); } else { // a SW (or HW) event) RtSwEventAdapter rsa = new RtSwEventAdapter(re, cnt-i, re.period); rsaLst.addElement(rsa); } } RtThread.startMission(); } /** * Stop the mission. When the event run() method returns * true the cleanup() methods are invoked until returning true * for a clean shutdown. * */ public static void stop() { for (int i=0; i<rtaLst.size(); ++i) { ((RtThreadAdapter) rtaLst.elementAt(i)).shutdown(); } for (int i=0; i<rsaLst.size(); ++i) { ((RtSwEventAdapter) rsaLst.elementAt(i)).shutdown(); ((RtSwEventAdapter) rsaLst.elementAt(i)).handle(); } } /** * Schedule a software event. * @param event */ public static void fire(String event) { // a simple linear search :-( for (int i=0; i<rsaLst.size(); ++i) { RtSwEventAdapter rsa = (RtSwEventAdapter) rsaLst.elementAt(i); if (rsa.re.event.equals(event)) { rsa.fire(); break; } } } /** * Return the elapsed time from system startup in micro seconds. * Wraps around all 4295 seconds. * * @return */ public static int currentTimeMicro() { return 0; } } class RtThreadAdapter extends RtThread { boolean runReturn; boolean cleanupReturn; boolean shutdown; RtEvent re; public RtThreadAdapter(RtEvent re, int prio, int us, int off) { super(prio, us, off); this.re = re; }; void shutdown() { shutdown = true; } public void run() { for (;;) { if (runReturn && shutdown) { if (!cleanupReturn) { cleanupReturn = re.cleanup(); } } else { runReturn = re.run(); } waitForNextPeriod(); } } } class RtSwEventAdapter extends SwEvent { boolean runReturn; boolean cleanupReturn; boolean shutdown; RtEvent re; public RtSwEventAdapter(RtEvent re, int prio, int us) { super(prio, us); this.re = re; // we assume true for a handler that was never called runReturn = true; }; void shutdown() { shutdown = true; } public void handle() { // who invokes it for cleanup? if (runReturn && shutdown) { if (!cleanupReturn) { cleanupReturn = re.cleanup(); } } else { runReturn = re.run(); } } }

     
    Copyright (c) 1999 OPENCORES.ORG. All rights reserved.