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
00055 #ifndef TOPPERS_INTERRUPT_HPP_
00056 #define TOPPERS_INTERRUPT_HPP_
00057
00058 #include <toppers/context.hpp>
00059
00060 namespace toppers
00061 {
00062
00063 template <class Body> void interrupthandler_entry();
00064
00065 template <class Diagnostics, class Stub> class interrupthandler_body;
00066
00079 template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00080 class Stub = TOPPERS_DEFAULT_STUB >
00081 class interrupt : Diagnostics
00082 {
00083 public:
00086
00088 static ER disable(INTNO intno)
00089 {
00090 ER ercd = Stub::stub_dis_int(intno);
00091 return static_handle_error(ercd);
00092 }
00094 static ER enable(INTNO intno)
00095 {
00096 ER ercd = Stub::stub_ena_int(intno);
00097 return static_handle_error(ercd);
00098 }
00099
00101
00104
00106 static ER change_mask(IMS ims)
00107 {
00108 ER ercd = Stub::stub_chg_ims(ims);
00109 return static_handle_error(ercd);
00110 }
00112 static ER get_mask(IMS* p_ims)
00113 {
00114 ER ercd = Stub::stub_get_ims(p_ims);
00115 return static_handle_error(ercd);
00116 }
00117
00119 };
00120
00132 template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00133 class Stub = TOPPERS_DEFAULT_STUB >
00134 class interrupthandler : Diagnostics
00135 {
00136 public:
00138 typedef t_dinh definition;
00139
00140
00141 static ER define(INHNO inhno, definition* pk_dobj)
00142 {
00143 ER ercd = Stub::stub_def_inh(inhno, pk_dobj);
00144 return static_handle_error(ercd);
00145 }
00147 static ER define(INHNO inhno, const definition* pk_dobj)
00148 {
00149 ER ercd = Stub::stub_def_inh(inhno, pk_dobj);
00150 return static_handle_error(ercd);
00151 }
00153 static ER define(INHNO inhno, ATR inhatr, void (*inthdr)())
00154 {
00155 definition packet;
00156 packet.inhatr = inhatr;
00157 packet.inthdr = FP(inthdr);
00158 return define(inhno, &packet);
00159 }
00161 template <class Body>
00162 static ER define(INHNO inhno, ATR inhatr = 0)
00163 {
00164 return define(inhno, inhatr, &interrupthandler_entry<Body>);
00165 }
00167 static ER undefine(INHNO inhno)
00168 {
00169 return define(inhno, static_cast<definition*>(0));
00170 }
00171 };
00172
00183 template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00184 class Stub = TOPPERS_DEFAULT_STUB >
00185 class interrupthandler_body : public non_task_context_body<Diagnostics, Stub>
00186 {
00187 protected:
00188 ~interrupthandler_body() {}
00189
00190 public:
00191 interrupthandler_body() {}
00192 };
00193
00204 template <class Body>
00205 inline void interrupthandler_entry()
00206 {
00207 Body body;
00208 body.run();
00209 }
00210
00211
00212 template <class Body> void isr_entry(VP_INT);
00213
00214 template <class Diagnostics, class Stub> class isr_body;
00215
00227 template <ID Id = 0,
00228 class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00229 class Stub = TOPPERS_DEFAULT_STUB >
00230 class isr : Diagnostics
00231 {
00232 typedef object_controller<Id, obj_isr, Stub> controller;
00233 object_id<Id> objid_;
00234
00235 public:
00237 typedef t_cisr creation;
00239 typedef t_risr reference;
00241 typedef isr_body<Diagnostics, Stub> body;
00242
00245
00247 isr() {}
00249 explicit isr(ID id) : objid_(id) {}
00250
00252 template <ID Id2, class Diagnostics2, class Stub2>
00253 isr(const isr<Id2, Diagnostics2, Stub2>& other)
00254 : objid_(get_unsafe_id(other))
00255 {
00256 TOPPERS_STATIC_ASSERT(Id == 0);
00257 }
00258
00260
00263
00264
00265 ER create(creation* pk_cobj)
00266 {
00267 ER ercd = controller::create(objid_, pk_cobj);
00268 return handle_error(ercd);
00269 }
00271 ER create(const creation* pk_cobj)
00272 {
00273 ER ercd = controller::create(objid_, pk_cobj);
00274 return handle_error(ercd);
00275 }
00277 ER create(ATR isratr, VP_INT exinf, INTNO intno, void (*entry)(VP_INT))
00278 {
00279 creation packet;
00280 packet.isratr = isratr;
00281 packet.exinf = exinf;
00282 packet.intno = intno;
00283 packet.isr = FP(entry);
00284 return create(&packet);
00285 }
00287 template <class Body>
00288 ER create(ATR isratr, VP_INT exinf, INTNO intno)
00289 {
00290 return create(isratr & ~TA_ASM | TA_HLNG, exinf, intno, &isr_entry<Body>);
00291 }
00293 ER destroy()
00294 {
00295 ER ercd = controller::destroy(objid_);
00296 return handle_error(ercd);
00297 }
00298
00300
00303
00305 ER refer(reference* pk_robj) const
00306 {
00307 ER ercd = controller::refer(objid_, pk_robj);
00308 return handle_error(ercd);
00309 }
00310
00312
00314 friend ID get_unsafe_id(const isr<Id, Diagnostics, Stub>& obj)
00315 {
00316 return obj.objid_.id();
00317 }
00318 };
00319
00330 template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00331 class Stub = TOPPERS_DEFAULT_STUB >
00332 class isr_body : public non_task_context_body<Diagnostics, Stub>
00333 {
00334 VP_INT exinf_;
00335
00336 protected:
00337 ~isr_body() {}
00338
00339 public:
00341 explicit isr_body(VP_INT exinf) : exinf_(exinf) {}
00342
00344 VP_INT get_extended_info() const { return exinf_; }
00345 };
00346
00357 template <class Body>
00358 inline void isr_entry(VP_INT exinf)
00359 {
00360 Body body(exinf);
00361 body.run();
00362 }
00363
00364 }
00365
00366 #endif // ! TOPPERS_INTERRUPT_HPP_