00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00051 #ifndef TOPPERS_OVERRUNHANDLER_HPP_
00052 #define TOPPERS_OVERRUNHANDLER_HPP_
00053
00054 #include <toppers/context.hpp>
00055
00056 namespace toppers
00057 {
00058
00059 template <class Body> void overrunhandler_entry(ID, VP_INT);
00060
00061 template <class Diagnostics, class Stub> class overrunhandler_body;
00062 template <ID Id, class Diagnostics, class Stub> class task;
00063
00075 template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00076 class Stub = TOPPERS_DEFAULT_STUB >
00077 class overrunhandler : Diagnostics
00078 {
00079 public:
00081 typedef t_dovr definition;
00083 typedef t_rovr reference;
00085 typedef overrunhandler_body<Diagnostics, Stub> body;
00086
00089
00090
00091 static ER define(definition* pk_dobj)
00092 {
00093 ER ercd = Stub::stub_def_ovr(pk_dobj);
00094 return static_handle_error(ercd);
00095 }
00097 static ER define(const definition* pk_dobj)
00098 {
00099 ER ercd = Stub::stub_def_ovr(pk_dobj);
00100 return static_handle_error(ercd);
00101 }
00103 static ER define(ATR ovratr, void (*ovrhdr)(ID, VP_INT))
00104 {
00105 definition packet;
00106 packet.ovratr = ovratr;
00107 packet.ovrhdr = FP(ovrhdr);
00108 return define(&packet);
00109 }
00111 template <class Body>
00112 static ER define(ATR ovratr = 0)
00113 {
00114 return define(ovratr & ~TA_ASM | TA_HLNG, &overrunhandler_entry<Body>);
00115 }
00117 static ER undefine()
00118 {
00119 return define(static_cast<definition*>(0));
00120 }
00121
00123
00126
00128 template <ID Id, class Diagnostics2, class Stub2>
00129 static ER refer(const task<Id, Diagnostics2, Stub2>& host, reference* pk_robj)
00130 {
00131 ER ercd = Stub::stub_ref_ovr(get_unsafe_id(host), pk_robj);
00132 return handle_error(ercd);
00133 }
00135 static ER refer(reference* pk_robj)
00136 {
00137 ER ercd = Stub::stub_ref_ovr(TSK_SELF, pk_robj);
00138 return handle_error(ercd);
00139 }
00140
00142
00145
00147 template <ID Id, class Diagnostics2, class Stub2>
00148 static ER start(const task<Id, Diagnostics2, Stub2>& host, OVRTIM ovrtim)
00149 {
00150 ER ercd = Stub::stub_sta_ovr(get_unsafe_id(host), ovrtim);
00151 return handle_error(ercd);
00152 }
00154 template <ID Id, class Diagnostics2, class Stub2>
00155 static ER stop(const task<Id, Diagnostics2, Stub2>& host)
00156 {
00157 ER ercd = Stub::stub_stp_ovr(get_unsafe_id(host));
00158 return handle_error(ercd);
00159 }
00160
00162 static ER start(OVRTIM ovrtim)
00163 {
00164 ER ercd = Stub::stub_sta_ovr(TSK_SELF, ovrtim);
00165 return handle_error(ercd);
00166 }
00168 static ER stop()
00169 {
00170 ER ercd = Stub::stub_stp_ovr(TSK_SELF);
00171 return handle_error(ercd);
00172 }
00173
00175
00176 private:
00177 ID get_host_id() const
00178 {
00179 return get_unsafe_id(host_);
00180 }
00181 };
00182
00194 template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00195 class Stub = TOPPERS_DEFAULT_STUB >
00196 class overrunhandler_body : public non_task_context_body<Diagnostics, Stub>
00197 {
00198 task<0, Diagnostics, Stub> task_;
00199 VP_INT exinf_;
00200
00201 protected:
00203 ~overrunhandler_body() {}
00204
00205 public:
00207 explicit overrunhandler_body(ID tskid, VP_INT exinf)
00208 : task_(tskid), exinf_(exinf)
00209 {
00210 }
00211
00213 const task<0, Diagnostics, Stub>& get_task() const { return task_; }
00214
00216 VP_INT get_extended_info() const { return exinf_; }
00217 };
00218
00229 template <class Body>
00230 inline void overrunhandler_entry(ID tskid, VP_INT exinf)
00231 {
00232 Body body(tskid, exinf);
00233 body.run();
00234 }
00235
00236 }
00237
00238 #endif // ! TOPPERS_OVERRUNHANDLER_HPP_