📄 chap.8.interrupts.ps
字号:
3832(very)X4037(costly.)X576 915(This)N771(is)X859(why)X1048(the)X1190(interrupt-driven)X1824(scheme)X2137(of)X2241(Figure)X2516(8.1b)X2708(may)X2898(be)X3013(considered)X3454(to)X3553(be)X3668(more)X3 f3890(ef\256cient)X1 f4216(.)X776 1055(A)N869(second)X1160(problem)X1505(with)X1700(a)X1767(polled)X2033(scheme)X2347(as)X2452(in)X2552(Figure)X2828(8.1a)X3016(is)X3105(illustrated)X3516(as)X3621(follows.)X3982(Assume)X576 1167(we)N724(have)X942(a)X1021 0.2898(time-related)AX1524(function)X1881(occurring)X2286(in)X2397(a)X2476(device)X2764(and)X2939(it)X3029(is)X3129(critical)X3433(that)X3613(the)X3766(CPU)X3987(respond)X576 1279(very)N771(quickly)X1084(after)X1285(some)X1512(external)X1847(event)X2080(has)X2232(occurred.)X2641(If,)X2753(in)X2852(the)X2994(polled)X3260(system,)X3576(the)X3719(minimum)X4119(time)X576 1391(between)N927("polls")X1222(of)X1332(the)X1480("done)X1736(bit")X1907(of)X2016(the)X2163(device)X2444(is)X2537(greater)X2834(than)X3029(the)X3176(tolerance)X3559(of)X3668(the)X3815(device)X4096(to)X4200(be)X576 1503(serviced,)N954(a)X1030(failure)X1315(could)X1562(occur.)X1857(For)X2023(example,)X2407(let's)X2606(say)X2767(that)X2945(a)X3022(system)X3323(has)X3485(100)X3663(devices)X3986(needing)X576 1615(service.)N926(Further,)X1262(assume)X1574(it)X1657(takes)X1884(the)X2031(CPU)X2246(20)X9 f2370(m)X1 f2453(to)X2556(poll)X2734(each)X2939(device.)X3267(Therefore,)X3699(we)X3839(have)X4049(a)X4120(loop)X576 1727(as)N680(follows:)X7 f1152 1887(do)N1326({)X1728 1999(if)N1902 0.3938(\(*device0_status_reg\))AX2304 2111(service)N2768 0.4167(device0\(\);)AX1728 2223(if)N1902 0.3938(\(*device1_status_reg\))AX2304 2335(service)N2768 0.4167(device1\(\);)AX1728 2447(if)N1902 0.3938(\(*device2_status_reg\))AX2304 2559(service)N2768 0.4167(device2\(\);)AX2304 2671(.)N2478(.)X2652(.)X1728 2783(if)N1902 0.3929(\(*device99_status_reg\))AX2304 2895(service)N2768 0.4125(device99\(\);)AX1152 3007(})N1268(while)X1616(\(1\);)X1 f576 3167(In)N696(this)X875(example,)X1266(we)X1418(are)X1576(assuming)X1979(that)X2164(each)X7 f2415(if)X1 f2571(test)X2745(statement)X3155(takes,)X3418(on)X3555(average,)X3920(20)X9 f4057(m)X1 f4112(-sec.)X576 3279(Now,)N814(assume)X1125(that)X1298(each)X1503(device)X1783(generates)X2175(an)X2294(interrupt)X2654(every)X2896(10)X3020(seconds.)X3376(Since)X3618(100)X3790(x)X3866(20)X9 f(m)S1 f4017(-secs)X4237(=)X576 3391(2ms)N772(there)X1001(is)X1102(plenty)X1380(of)X1497(time)X1706(to)X1818(service)X2128(all)X2262(100)X2443(devices,)X2793(but)X2953(now,)X3179(consider)X3542(the)X3697(additional)X4120(con-)X576 3503(straint)N855(that)X1038(each)X1253(device)X1543(requires)X1891(service)X2202(no)X2336(more)X2572(than)X2776(1ms)X2974(after)X3188(it)X3279(is)X3380("ready".)X3757(If)X3858(a)X3938(device)X4227(is)X576 3615(unlucky)N914(enough)X1225(to)X1328(become)X1656("ready")X1976(immediately)X2 f2487(after)X1 f2697(having)X2987(been)X3197(polled,)X3490(there)X3711(will)X3890(be)X4010(a)X4082(delay)X576 3727(of)N681(approximately)X1263(2ms)X1448(before)X1719(it)X1798(is)X1887(polled)X2153(again.)X2435(Thus,)X2676(as)X2781(illustrated)X3192(here,)X3407(a)X3474(polled)X3739(system)X4030(suffers)X576 3839(from)N787(a)X854(loss)X1027(of)X3 f1131(accuracy)X1 f1500(.)X3 f576 4063(8.2.)N768(Concepts)X1170(of)X1274(the)X1426(Interrupt)X1839(Process)X1 f776 4203(One)N960(way)X1144(to)X1243(describe)X1588(what)X1799(an)X1914(interrupt)X2270(is)X2358(\(from)X2601(the)X2743(programmer's)X3312(point)X3535(of)X3640(view\))X3884(is)X3973(``A)X4131(way)X576 4315(to)N684(invoke)X979(a)X1054(subroutine)X1492(without)X1818(calling)X2113(it''.)X2287(In)X2399(other)X2629(words,)X2919(when)X3159(an)X3282(external,)X3649(real-world)X4082(event)X576 4427(occurs,)N880(the)X1027(programmer)X1533(wants)X1787(to)X1892(cause)X2136(a)X2209(change)X2512(in)X2617(the)X2765(\257ow)X2965(of)X3075(control)X3378(of)X3488(the)X3636(running)X3965(program)X576 4539(in)N681(response)X1047(to)X1152(this)X1321(event.)X1608(More)X1846(speci\256cally,)X2339(in)X2444(response)X2809(to)X2913(an)X3033(event,)X3295(an)X2 f3415(Interrupt)X3791(Service)X4104(Rou-)X576 4651(tine)N745(\(ISR\))X1 f972(is)X1060(to)X1159(be)X1274(executed)X1641(to)X1740("process")X2130(the)X2272(event.)X2553(Recall)X2824(from)X3035(Chapter)X3364(3)X3436(the)X3578(three)X3795(basic)X4018(control)X576 4763(\257ow)N778(mechanisms:)X1312(sequencing,)X1800(alternation,)X2268(and)X2438(iteration.)X2815(When)X3076(you)X3251(add)X3421(to)X3527(that)X3703(the)X3852(mechanism)X576 4875(of)N689(subroutines,)X1189(there)X1415(are)X1566(four.)X1783(Now,)X2026(with)X2230(interrupts)X2633(we)X2779(have)X2995(yet)X3147(a)X3224(\256fth)X3418(mechanism.)X3915(However,)X576 4987(interrupts)N979(are)X1131(fundamentally)X1722(different)X2088(in)X2197(that)X2376(the)X2528(main)X2755(program)X3115(does)X3324(not)X3480(explicitly)X3878(invoke)X4173(the)X576 5099(service)N873(subroutine.)X1327(It)X1410(is)X1498(onvoked)X1853(only)X2048(on)X2168(demand)X2497(from)X2708(the)X2850(world)X3098(outside)X3400(the)X3542(computer.)X3 f576 5323(8.3.)N768(Motivation:)X1278(Aviation)X1654(Navigation)X2126(Control)X2470(Example)X1 f776 5463(We)N948(consider)X1312(now)X1515(a)X1596(semi-realistic)X2154(example)X2519(of)X2637(aircraft)X2954(control.)X3289(At)X3423(a)X3504(very)X3713(high)X3922(level,)X4173(the)X576 5575(computer)N966(control)X1265(of)X1371(an)X1488(airplane)X1824(can)X1983(be)X2099(viewed)X2402(much)X2641(like)X2811(the)X2954(code)X3161(segment)X3507(we)X3644(saw)X3818(in)X3918(the)X4061(previ-)X576 5687(ous)N739(section.)X1066(Assume)X1405(that)X1580(the)X1728(main)X1951(function)X2303(of)X2414(the)X2563(control)X2867(program)X3224(is)X3319(to)X3425(periodically)X3917(check)X4173(the)X576 5799(input)N803(sensors)X1114(\(aircraft)X1454(attitude,)X1797(elevation,)X2204(airspeed,)X2578(etc\))X2752(and)X2920(in)X3024(response)X3389(to)X3492(perform)X3830(calculations)X61 p%%Page: 61 412 s 0 xH 0 xS 1 f3 f576 400(57:017)N872(CIE)X1 f2329(-)X2385(61)X2505(-)X3 f3717(Lecture)X4062(Notes)X1 f576 803(to)N675(adjust)X929(its)X1044(outputs)X1351(\(engine)X1664(thrust,)X1931(\257aps,)X2160(etc\).)X2353(This)X2548(might)X2797(be)X2912(done)X3123(as)X3227(in)X3326(Figure)X3601(8.2.)X7 f1152 963(main\(\))N1558({)X1152 1187(while)N1500(\(1\))X1732({)X1728 1299(/*)N1902(Normal)X2308(Sample)X2714(and)X2946(Control)X3410(*/)X1728 1411(x)N1844(=)X1960 0.3906(sample_attitude_sensor\(\);)AX1728 1523 0.4062(set_flaps\(x\);)AN1728 1635(y)N1844(=)X1960 0.3906(check_desired_altitude\(\);)AX1728 1747 0.3947(set_flaps-thrust\(y\);)AN2304 1859(.)N2478(.)X2652(.)X2826(.)X1728 1971(z)N1844(=)X1960 0.3971(sample_airspeed\(\);)AX1728 2083 0.4062(set_thrust\(\);)AN1728 2307(/*)N1902(Check)X2250(for)X2482(Problems)X3004(*/)X1728 2419(w)N1844(=)X1960 0.3894(check_hydraulic_pressure\(\);)AX1728 2531(if)N1902(\(w\))X2304 2643 0.3906(service_hydraulic_leak\(\);)AN2304 2755(.)N2478(.)X2652(.)X1728 2867(})N1152 2979(})N1152 3203(void)N1442 0.3913(service_hydraulic_leak\(\))AX2892({)X1728 3315(/*)N1902 0.4219(Emergency)AX2482(service)X2946(to)X3120(repair)X3526(leak)X1678 3427(or)N1852(switch)X2258(system)X2664(to)X2838(backup)X3244(*/)X1152 3539(})N3 f1393 3747(Figure)N1690(8.2.)X1858(Main)X2 f2101(Polling)X3 f2409(Control)X2753(Loop)X2990(for)X3137(Aircraft)X2025 3859(Navigation)N2497(Control.)X1 f576 4047(The)N772(program)X1144(segment)X1511(shown)X1807(in)X1928(Figure)X2226(8.2)X2393(illustrates)X2815(the)X2980(basic)X3225(idea)X3433(in)X3555(a)X3645(control)X3965(program)X576 4159(employing)N3 f1019(polling)X1 f1333(of)X1444(all)X1572(sensors.)X1909(However,)X2316(there)X2540(are)X2688(important)X3093(differences)X3551(between)X3902(the)X4050(nature)X576 4271(of)N684(the)X830(checks)X1120(being)X1362(done)X1577(in)X1680(the)X1827(top)X1979(portion)X2286(of)X2395(the)X2542(loop)X2742(and)X2910(the)X3057(last)X3220(one.)X3412(The)X3591(last)X3754(one)X3922(hopefully)X576 4383(will)N751(never)X990(test)X1149(TRUE,)X1449(but)X1597(if)X1681(it)X1760(does,)X1985(it)X2064(will)X2239(happen)X2542(infrequently,)X3062(and)X3226(must)X3438(be)X3554(serviced)X3900(as)X4005(soon)X4211(as)X576 4495(possible)N915(after)X1116(the)X1258(condition)X1646(arises.)X1937(This)X2132(illustrates)X2531(the)X2673(3)X2745(basic)X2967(disadvantages)X3531(of)X3635(polling)X3932(systems.)X776 4635(1.)N920(The)X1105(time)X1312(spent)X1551(checking)X1935(the)X2089(pressure)X2445(leak)X2642(sensor)X2923(in)X3034(the)X3188(main)X3417(loop)X3624(on)X3756(each)X3969(iteration)X920 4747(will)N1094(reduce)X1375(the)X2 f1517(quality)X1 f1809(and)X2 f1972(\256delity)X1 f2259(of)X2363(the)X2505(checking)X2877(of)X2981(the)X3123(normal)X3420(controls)X3754(and)X3917(\257aps,)X4146(etc.)X776 4887(2.)N920(If,)X1041(in)X1149(addition)X1498(to)X1607(a)X1684(hydraulic)X2082(leak,)X2301(there)X2528(are)X2680(many)X2928(other)X3160(emergency)X3617(sensors)X3933(to)X4042(check,)X920 4999(the)N1063(\256delity)X1361(of)X1466(the)X1609(system)X1901(may)X2092(degrade)X2422(to)X2521(a)X2588(point)X2810(where)X3069(the)X3211(system)X3502(becomes)X3863(uncontroll-)X920 5111(able)N1105(and)X1268(in)X1367(some)X1594(cases,)X1845(unsafe.)X776 5251(3.)N920(Finally,)X1252(if)X1346(the)X1499(upper)X1753(part)X1938(of)X2053(the)X2206(loop)X2413(body)X2641(is)X2741(too)X2900(long,)X3131(the)X3285(emergency)X3744(sensors)X4062(in)X4173(the)X920 5363(lower)N1175(part)X1361(may)X1563(not)X1722(get)X1876(checked)X2228(frequently)X2660(enough.)X3003(In)X3119(other)X3353(words,)X3647(if)X3742(an)X3868(emergency)X920 5475(condition)N1313(is)X1406(not)X1558(checked)X1903(soon)X2113(enough)X2425(after)X2631(it)X2714(is)X2808(raised,)X3092(the)X3240(situation)X3602(may)X3798(not)X3951(be)X4072(servi-)X920 5587(cable.)N1187(In)X1306(the)X1463(worst)X1715(case,)X1944(if)X2042(an)X2172(emergency)X2634(condition)X3037(becomes)X3412(true)X2 f3600(immediately)X4109(after)X1 f920 5699(being)N1165(checked,)X1537(the)X1687(sensor)X1964(will)X2146(not)X2301(be)X2424(checked)X2772(until)X2981(the)X3131(entire)X3383(loop)X3586(body)X3810(has)X3970(been)X4184(re-)X920 5811(executed,)N1330(and)X1512(if)X1614(the)X1775(lenght)X2059(of)X2182(time)X2397(required)X2761(to)X2879(execute)X3217(the)X3378(loop)X3592(body)X3826(exceeds)X4173(the)X62 p%%Page: 62 512 s 0 xH 0 xS 1 f3 f576 400(57:017)N872(CIE)X1 f2329(-)X2385(62)X2505(-)X3 f3717(Lecture)X4062(Notes)X1 f920 803(maximum)N1335(delay)X1568(for)X1704(servicing)X2081(the)X2223(emergnecy)X2670(condition,)X3082(the)X3224(system)X3515(may)X3705(fail.)X576 943(The)N756(obvious)X1090(solution)X1431(to)X1537(the)X1686(problems)X2075(above)X2336(is)X2431(to)X2537(remove)X2857(the)X3006(emergency)X3460(checks)X3753(from)X3971(the)X4120(loop)X576 1055(body,)N822(and)X991(only)X1192(invoke)X1484(the)X1632(emergency)X2085(service)X2388(routines)X2727(when)X2964(needed.)X3290(A)X3388(simple)X3674(idea,)X3888(but)X4040(as)X4149(yet,)X576 1167(not)N726(one)X893(that)X1066(is)X1158(easily)X1411(implemented.)X1967(All)X2118(processor)X2514(architectures)X3035(\(including)X3459(the)X3605(M68000\))X3990(have)X4200(an)X576 1279(interrupt)N942(mechanism.)X1439(That)X1650(is,)X1772(when)X2014(attached)X2369(appropriately,)X2940(a)X3016(device)X3301(may)X3500(be)X
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -