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

📄 bsp.c

📁 a super good method for designing finite state machine
💻 C
字号:
/****************************************************************************** PELICAN crossing example* Last Updated for Version: 1.5.00* Date of the Last Update:  Oct 16, 2006** Copyright (C) 2002-2006 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 allow the* licensees to retain the proprietary status of their code. The licensees* who use 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 "qpn_port.h"#include "bsp.h"#include <conio.h>                                           /* for kbhit() */#include <stdlib.h>                                          /* for _exit() *//* Local-scope objects -----------------------------------------------------*/static void interrupt (*l_dosTickISR)();static uint32_t l_tickCtr;#define TICK_VECTOR     0x08/* Direct Video Access .....................................................*/enum VideoColor {    /* foreground */    VIDEO_FGND_BLACK        = 0x00,    VIDEO_FGND_BLUE         = 0x01,    VIDEO_FGND_GREEN        = 0x02,    VIDEO_FGND_CYAN         = 0x03,    VIDEO_FGND_RED          = 0x04,    VIDEO_FGND_PURPLE       = 0x05,    VIDEO_FGND_BROWN        = 0x06,    VIDEO_FGND_LIGHT_GRAY   = 0x07,    VIDEO_FGND_DARK_GRAY    = 0x08,    VIDEO_FGND_LIGHT_BLUE   = 0x09,    VIDEO_FGND_LIGHT_GREEN  = 0x0A,    VIDEO_FGND_LIGHT_CYAN   = 0x0B,    VIDEO_FGND_LIGHT_RED    = 0x0C,    VIDEO_FGND_LIGHT_PURPLE = 0x0D,    VIDEO_FGND_YELLOW       = 0x0E,    VIDEO_FGND_WHITE        = 0x0F,    /* background */    VIDEO_BGND_BLACK        = 0x00,    VIDEO_BGND_BLUE         = 0x10,    VIDEO_BGND_GREEN        = 0x20,    VIDEO_BGND_CYAN         = 0x30,    VIDEO_BGND_RED          = 0x40,    VIDEO_BGND_PURPLE       = 0x50,    VIDEO_BGND_BROWN        = 0x60,    VIDEO_BGND_LIGHT_GRAY   = 0x70,    VIDEO_BGND_BLINK        = 0x80};/*..........................................................................*/static void Video_clearScreen(uint8_t bgColor);static void Video_clearRect(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2,                     uint8_t bgColor);static void Video_printChAt(uint8_t x, uint8_t y, uint8_t color, char ch);static void Video_printStrAt(uint8_t x, uint8_t y, uint8_t color,                      char const *str);static void Video_printNumAt(uint8_t x, uint8_t y, uint8_t color,                      uint32_t num);/*..........................................................................*/static void interrupt tickISR() {                             /* see NOTE01 */    QF_tick();                          /* process all time events (timers) */    Video_printNumAt(20, 17, VIDEO_FGND_YELLOW, ++l_tickCtr);    outportb(0x20, 0x20); /* EOI (End-Of-Interrupt) to the master 8259A PIC */}/*..........................................................................*/#if 0/* The following alternative implementation of the ISR requires defining* the macro QF_ISR_NEST in "qpn_port.h" to allow interrupt nesting.*/static void interrupt tickISR() {                             /* see NOTE02 */    /*clear any level-sensitive interrupt sources before enabling interrupts*/    enable();                                   /* enable interrupt nesting */    QF_tick();                          /* process all time events (timers) */    Video_printNumAt(20, 17, VIDEO_FGND_YELLOW, ++l_tickCtr);    disable();        /* disable interrupts for the exit from the interrupt */    outportb(0x20, 0x20); /* EOI (End-Of-Interrupt) to the master 8259A PIC */}#endif/*..........................................................................*/void BSP_init(void) {    uint8_t n;    Video_clearScreen(VIDEO_BGND_BLACK);    Video_clearRect( 0,  0, 80,  7, VIDEO_BGND_LIGHT_GRAY);    Video_clearRect( 0, 11, 41, 12, VIDEO_BGND_LIGHT_GRAY);    Video_clearRect( 0,  7, 41, 11, VIDEO_BGND_RED);    Video_clearRect( 0, 12, 41, 23, VIDEO_BGND_BLUE);    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(10,  8, VIDEO_FGND_WHITE,                    "PELICAN Crossing Example");    Video_printStrAt(10,  9, VIDEO_FGND_WHITE, "QP-nano");    Video_printStrAt(20,  9, VIDEO_FGND_YELLOW, QP_getVersion());    Video_printStrAt(4, 11, VIDEO_FGND_BLUE,                     "Active Object   State");    Video_printStrAt(4, 13, VIDEO_FGND_WHITE, "PELICAN");    Video_printStrAt(4, 14, VIDEO_FGND_WHITE, "Pedestrian");    Video_printStrAt(4, 17, VIDEO_FGND_WHITE, "Tick #");    n = VIDEO_FGND_WHITE | VIDEO_BGND_BLACK;    Video_printStrAt(43,  7, n, "      谀哪哪哪

⌨️ 快捷键说明

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