⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bsp.c

📁 state machine working with rtos
💻 C
字号:
/****************************************************************************** Product: QDPP example, QK, 80x86, Turbo C++ 1.01* Version: Compatible with QF/C 3.1.yy* Updated: Aug 04, 2006** Copyright (C) 2002-2006 Quantum Leaps, LLC. All rights reserved.** This example is part of the Quantum Leaps QP/C software, and 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 in conjunction* with a valid QP/C Quantum Leaps commercial license. Quantum Leaps* commercial licenses are designed for users who want to retain proprietary* status of their code. The users who license this software under one of* Quantum Leaps commercial licenses do not use this software under the GPL* and therefore are not subject to any of its terms.** Contact information:* Quantum Leaps Web site:  http://www.quantum-leaps.com* Quantum Leaps licensing: http://www.quantum-leaps.com/licensing* Quantum Leaps products:  http://www.quantum-leaps.com/products* 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-scope objects -----------------------------------------------------*/static void interrupt (*l_dosTmrISR)();static void interrupt (*l_dosKbdISR)();#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() {    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);/*get scan code from the 8042 kbd controller */    KbdEvt *ke;    displayPreemptions(QK_currPrio_, KBD_ISR_PRIO);  /* for testing, NOTE01 */    QK_ISR_ENTRY(pin, KBD_ISR_PRIO);    ke = Q_NEW(KbdEvt, KBD_SIG);                     /* allocate new KbdEvt */    ke->key = key;                            /* fill the ke->key parameter */    QF_publish((QEvent *)ke);         /* publish the event to the framework */    busyDelay();                                     /* for testing, NOTE02 */    QK_ISR_EXIT(pin);}/*..........................................................................*/void QF_init(void) {}/*..........................................................................*/void QF_start(void) {                                      /* divisor for the 8254 timer/counter */    uint16_t count = (uint16_t)(((1193180 * 2) / TICKS_PER_SEC + 1) >> 1);                                      /* save the origingal DOS vectors ... */    l_dosTmrISR   = getvect(TMR_VECTOR);    l_dosKbdISR   = getvect(KBD_VECTOR);    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 *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 monitor the* "asynchronous" preemptions within the QK (see Section 4.1 in the "QK/C* Programmer's Manual".** NOTE02:* The call to busyDelay() (see main.c) is added only to extend the execution* time of the code to increase the chance of an "asynchronous" preemption.*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -