📄 bsp.cpp
字号:
//////////////////////////////////////////////////////////////////////////////// Product: QDPP example// Last Updated for Version: 3.3.00// Date of the Last Update: Jan 24, 2007//// Q u a n t u m L e a P s// ---------------------------// innovating embedded systems//// Copyright (C) 2002-2007 Quantum Leaps, LLC. All rights reserved.//// This software may be distributed and modified under the terms of the GNU// General Public License version 2 (GPL) as published by the Free Software// Foundation and appearing in the file GPL.TXT included in the packaging of// this file. Please note that GPL Section 2[b] requires that all works based// on this software must also be made publicly available under the terms of// the GPL ("Copyleft").//// Alternatively, this software may be distributed and modified under the// terms of Quantum Leaps commercial licenses, which expressly supersede// the GPL and are specifically designed for licensees interested in// retaining the proprietary status of their code.//// Contact information:// Quantum Leaps Web site: http://www.quantum-leaps.com// e-mail: sales@quantum-leaps.com//////////////////////////////////////////////////////////////////////////////#include "qf_port.h"#include "qdpp.h"#include "video.h"#include "qassert.h"#include <stdlib.h> // for _exit()Q_DEFINE_THIS_FILE// local objects -------------------------------------------------------------static void interrupt (*l_dosTmrISR)(...);static void interrupt (*l_dosKbdISR)(...);static uint32_t l_tickCtr;#define TICKS_PER_SEC 200#define TMR_VECTOR 0x08#define KBD_VECTOR 0x09#define TMR_ISR_PRIO (0xFF)#define KBD_ISR_PRIO (0xFF - 1)//............................................................................static void interrupt tmrISR(...) { // ISR is entered with interrupts disabled uint8_t pin; displayPreemptions(QK_currPrio_, TMR_ISR_PRIO); // for testing, NOTE01 QK_ISR_ENTRY(pin, TMR_ISR_PRIO); QF::tick(); // process armed timers busyDelay(); // for testing, NOTE02 QK_ISR_EXIT(pin);}//............................................................................static void interrupt kbdISR(...) { uint8_t pin; uint8_t key = inport(0x60); // key scan code from the 8042 kbd controller displayPreemptions(QK_currPrio_, KBD_ISR_PRIO); // for testing, NOTE01 QK_ISR_ENTRY(pin, KBD_ISR_PRIO); KbdEvt *ke = Q_NEW(KbdEvt, KBD_SIG); // allocate new KbdEvt ke->key = key; // fill the ke->key parameter QF::publish(ke); // publish the event to the framework busyDelay(); // for testing, NOTE02 QK_ISR_EXIT(pin);}//............................................................................void QF::init(void) { // save the origingal DOS vectors ... l_dosTmrISR = getvect(TMR_VECTOR); l_dosKbdISR = getvect(KBD_VECTOR);}//............................................................................void QF::start(void) { // divisor for the 8254 timer/counter uint16_t count = (uint16_t)(((1193180 * 2) / TICKS_PER_SEC + 1) >> 1); QF_INT_LOCK(ignore); // lock the interrupts outportb(0x43, 0x36); // use mode-3 for timer 0 in the 8254 outportb(0x40, count & 0xFF); // load low byte of timer 0 outportb(0x40, (count >> 8) & 0xFF); // load high byte of timer 0 setvect(TMR_VECTOR, &tmrISR); setvect(KBD_VECTOR, &kbdISR); QF_INT_UNLOCK(ignore); // unlock the interrupts}//............................................................................void QK::onIdle(void) {}//............................................................................void QF::exit(void) { QF_INT_LOCK(ignore); // lock the interrupts outportb(0x43, 0x36); // use mode-3 for timer 0 in the 8254 outportb(0x40, 0); // load low byte of timer 0 outportb(0x40, 0); // load high byte of timer 0 // restore the original DOS vectors ... setvect(TMR_VECTOR, l_dosTmrISR); setvect(KBD_VECTOR, l_dosKbdISR); QF_INT_UNLOCK(ignore); // unlock the interrupts _exit(0); // exit to DOS}//----------------------------------------------------------------------------void Q_assert_handler(char const Q_ROM * const Q_ROM_VAR file, int line) { Video::clearRect(0, 24, 80, 25, Video::BGND_RED); Video::printStrAt(0, 24, Video::FGND_WHITE, "ASSERTION FAILED in file:"); Video::printStrAt(26, 24, Video::FGND_YELLOW, file); Video::printStrAt(57, 24, Video::FGND_WHITE, "line:"); Video::printNumAt(62, 24, Video::FGND_YELLOW, line); QF::exit(); // exit and cleanup QF}//............................................................................void displyPhilStat(uint8_t n, char const *stat) { Video::printStrAt(17, 12 + n, Video::FGND_YELLOW, stat);}//............................................................................void displayKey(uint8_t key) { Video::printNumAt(60, 12 + 0, Video::FGND_YELLOW, key);}//............................................................................void displayPreemptions(uint8_t pprev, uint8_t pnext) { if (pnext == TMR_ISR_PRIO) { static uint32_t tmrIsrCtr; // timer interrupt counter Video::printNumAt(51, 12 + 1, Video::FGND_YELLOW, ++tmrIsrCtr); } else if (pnext == KBD_ISR_PRIO) { static uint32_t kbdIsrCtr; // kbd interrupt counter Video::printNumAt(51, 12 + 0, Video::FGND_YELLOW, ++kbdIsrCtr); } else { Q_ERROR(); // unexpected interrupt priority } // is this a task preemption? if (((uint8_t)1 <= pprev) && (pprev <= (uint8_t)QF_MAX_ACTIVE)) { static uint32_t preCtr[QF_MAX_ACTIVE + 1]; Video::printNumAt(30, 12 + (pprev - 1)/10, Video::FGND_YELLOW, ++preCtr[pprev]); } else if (pprev == (uint8_t)(QF_MAX_ACTIVE + 1)) { // locked preemption? static uint32_t lockPreCtr; // locked scheduler preemption counter Video::printNumAt(30, 12 + N + 3, Video::FGND_YELLOW, ++lockPreCtr); } else if (pprev == KBD_ISR_PRIO) { // is this kbg ISR preemption? static uint32_t kbdPreCtr; // kbd ISR preemption counter Video::printNumAt(71, 12 + 0, Video::FGND_YELLOW, ++kbdPreCtr); } else if (pprev == TMR_ISR_PRIO) { // is this TMR ISR preemption? static uint32_t tmrPreCtr; // tmr ISR preemption counter Video::printNumAt(71, 12 + 1, Video::FGND_YELLOW, ++tmrPreCtr); } else { // this must be the idle task preemption Q_ASSERT(pprev == (uint8_t)0); }}//////////////////////////////////////////////////////////////////////////////// NOTE01:// The function call to displayPreemptions() is added only to showcase// preemptive feature of the Quantum Kernel. Preemption occurs when the// initial priority "pin" is greater than the priority of the idle task (0).//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -