📄 bsp.c
字号:
/****************************************************************************** Product: QDPP example, 80x86, QK/DOS, Turbo C++ 1.01* Last Updated for Version: 4.0.00* Date of the Last Update: Apr 07, 2008** Q u a n t u m L e a P s* ---------------------------* innovating embedded systems** Copyright (C) 2002-2008 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: info@quantum-leaps.com*****************************************************************************/#include "qp_port.h"#include "dpp.h"#include "bsp.h"#include "video.h"#include <math.h> /* to test the FPU */#include <stdlib.h> /* for _exit() */Q_DEFINE_THIS_FILE/* Global-scope objects ----------------------------------------------------*/Lib1_context * volatile impure_ptr1;Lib2_context * volatile impure_ptr2;/* Local-scope objects -----------------------------------------------------*/static void interrupt (*l_dosTmrISR)();static void interrupt (*l_dosKbdISR)();static uint32_t l_delay = 0UL; /* limit for the loop counter in busyDelay() */#ifdef Q_SPY static uint16_t l_uart_base; /* QS data uplink UART base address */ static QSTimeCtr l_tickTime; /* keeps timestamp at tick */ static uint32_t l_lastTime; /* last timestamp */ #define UART_16550_TXFIFO_DEPTH 16 enum AppRecords { /* application-specific trace records */ PHILO_STAT = QS_USER };#endif#define TMR_VECTOR 0x08#define KBD_VECTOR 0x09#define TMR_ISR_PRIO (0xFF)#define KBD_ISR_PRIO (0xFF - 1)static void dispPreemptions(uint8_t pisr); /* for testing *//*..........................................................................*/void interrupt ISR_tmr(void) {#ifdef Q_SPY l_tickTime += 0x10000; /* add 16-bit rollover */#endif dispPreemptions(TMR_ISR_PRIO); /* for testing only, NOTE01 */ QK_ISR_ENTRY(); /* inform QK about entering the ISR */ QF_tick(); /* call QF_tick() outside of critical section */ BSP_busyDelay(); /* for testing, NOTE02 */ QK_ISR_EXIT(); /* inform QK about exiting the ISR */}/*..........................................................................*/void interrupt ISR_kbd(void) { uint8_t key; uint8_t kcr; dispPreemptions(KBD_ISR_PRIO); /* for testing only, NOTE01 */ QK_ISR_ENTRY(); /* inform QK about entering the ISR */ key = inport(0x60); /* key scan code from the 8042 kbd controller */ kcr = inport(0x61); /* get keyboard control register */ outportb(0x61, (uint8_t)(kcr | 0x80)); /* toggle acknowledge bit high */ outportb(0x61, kcr); /* toggle acknowledge bit low */ if (key == (uint8_t)129) { /* ESC key pressed? */ static QEvent term = {TERMINATE_SIG, 0}; /* static event */ QF_publish(&term); /* publish to all interested AOs */ } else { static QEvent test = {TEST_SIG, 0}; /* static event */ QActive_postFIFO(AO_Table, &test); /* post a test event to Table */ } Video_printNumAt(60, 12 + 0, VIDEO_FGND_YELLOW, key);/* display the key */ BSP_busyDelay(); /* for testing, NOTE02 */ QK_ISR_EXIT(); /* inform QK about exiting the ISR */}/*..........................................................................*/void QF_onStartup(void) { /* save the origingal DOS vectors ... */ l_dosTmrISR = getvect(TMR_VECTOR); l_dosKbdISR = getvect(KBD_VECTOR); QF_INT_LOCK(dummy); setvect(TMR_VECTOR, &ISR_tmr); setvect(KBD_VECTOR, &ISR_kbd); QF_INT_UNLOCK(dummy);}/*..........................................................................*/void QF_onCleanup(void) { /* restore the original DOS vectors ... */ QF_INT_LOCK(dummy); setvect(TMR_VECTOR, l_dosTmrISR); setvect(KBD_VECTOR, l_dosKbdISR); QF_INT_UNLOCK(dummy); QS_EXIT(); /* exit QS */ _exit(0); /* exit to DOS */}/*..........................................................................*/void QK_onIdle(void) {#ifdef Q_SPY if ((inportb(l_uart_base + 5) & (1 << 5)) != 0) { /* Tx FIFO empty? */ uint16_t fifo = UART_16550_TXFIFO_DEPTH; /* 16550 Tx FIFO depth */ uint8_t const *block; QF_INT_LOCK(dummy); block = QS_getBlock(&fifo); /* try to get next block to transmit */ QF_INT_UNLOCK(dummy); while (fifo-- != 0) { /* any bytes in the block? */ outportb(l_uart_base + 0, *block++); } }#endif}/*..........................................................................*/void BSP_init(int argc, char *argv[]) { char const *com = "COM1"; uint8_t n; if (argc > 1) { l_delay = atol(argv[1]); /* set the delay counter for busy delay */ } if (argc > 2) { com = argv[2]; (void)com; /* avoid compiler warning if Q_SPY not defined */ } if (!QS_INIT(com)) { /* initialize QS */ Q_ERROR(); } Video_clearScreen(VIDEO_BGND_BLACK); Video_clearRect( 0, 0, 80, 7, VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 11, 80, 12, VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 12, 41, 23, VIDEO_BGND_BLUE); Video_clearRect(41, 12, 80, 23, VIDEO_BGND_RED); Video_clearRect( 0, 23, 80, 24, VIDEO_BGND_LIGHT_GRAY); n = VIDEO_FGND_BLUE; Video_printStrAt(10, 0, n, " __"); Video_printStrAt(10, 1, n, " / | _ _ -|- _ _"); Video_printStrAt(10, 2, n, " \\__| | | _\\ | \\ | | | | \\ \\"); Video_printStrAt(10, 3, n, " | \\_/ |_| | | | \\_| | | |"); Video_printStrAt(10, 4, n, " |"); n = VIDEO_FGND_RED; Video_printStrAt(43, 0, n, " _ __ "); Video_printStrAt(43, 1, n, "| /_\\ | \\ TM"); Video_printStrAt(43, 2, n, "| \\_ _ |__/ _"); Video_printStrAt(43, 3, n, "| _\\ | |_"); Video_printStrAt(43, 4, n, "|___ |_| | _|"); Video_printStrAt(10, 5, VIDEO_FGND_BLUE, "_____________________________________________________"); Video_printStrAt(10, 6, VIDEO_FGND_RED, "i n n o v a t i n g e m b e d d e d s y s t e m s"); Video_printStrAt(18, 7, VIDEO_FGND_WHITE, "Dining Philosophers Problem (DPP)"); Video_printStrAt(18, 8, VIDEO_FGND_WHITE, "QEP/C"); Video_printStrAt(28, 8, VIDEO_FGND_YELLOW, QEP_getVersion()); Video_printStrAt(18, 9, VIDEO_FGND_WHITE, "QF/C"); Video_printStrAt(28, 9, VIDEO_FGND_YELLOW, QF_getVersion()); Video_printStrAt(18, 10, VIDEO_FGND_WHITE, "QK/C"); Video_printStrAt(28, 10, VIDEO_FGND_YELLOW, QK_getVersion()); Video_printStrAt(41, 10, VIDEO_FGND_WHITE, "Delay Counter"); Video_printNumAt(54, 10, VIDEO_FGND_YELLOW, l_delay); Video_printStrAt( 1, 11, VIDEO_FGND_BLUE, "Active Object State Preemptions");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -