📄 platform.c
字号:
/*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* This software is copyrighted by and is the sole property of
* VIA Networking Technologies, Inc. This software may only be used
* in accordance with the corresponding license agreement. Any unauthorized
* use, duplication, transmission, distribution, or disclosure of this
* software is expressly forbidden.
*
* This software is provided by VIA Networking Technologies, Inc. "as is"
* and any express or implied warranties, including, but not limited to, the
* implied warranties of merchantability and fitness for a particular purpose
* are disclaimed. In no event shall VIA Networking Technologies, Inc.
* be liable for any direct, indirect, incidental, special, exemplary, or
* consequential damages.
*
*
* File: platform.c
*
* Purpose: Functions of platform to support tasks/timers/ISRs
*
* Author: Tevin Chen
*
* Date: Jan 08, 2002
*
* Functions:
*
* Revision History:
*
*/
#if !defined(__TTYIO_H__)
#include "ttyio.h"
#endif
#if !defined(__PLATFORM_H__)
#include "platform.h"
#endif
/*--------------------- Static Definitions ------------------------*/
#define UART_RING_LEN 4
/*--------------------- Static Types ------------------------------*/
/*--------------------- Static Macros -----------------------------*/
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Static Variables --------------------------*/
static DIRECT_MEMTYPE_DATA BYTE s_abyUartRxRing[UART_RING_LEN];
static DIRECT_MEMTYPE_DATA BYTE s_byRingInPtr = 0;
static DIRECT_MEMTYPE_DATA BYTE s_byRingOutPtr = 0;
/*--------------------- Static Functions --------------------------*/
void s_vCpuIdleTask(void) DIRECT_FUNTYPE_REENT;
/*--------------------- Export Variables --------------------------*/
bit g_fCpuIntShadow = 0;
#ifdef __MODULE_WEB_SMART
DIRECT_MEMTYPE_DATA UINT16 g_wWebAutoLogoutTime = 0;
DIRECT_MEMTYPE_DATA UINT16 g_wWebAutoLogoutCntr = 0;
#endif
DIRECT_MEMTYPE_DATA UINT16 g_wAutoLogoutTime = 0;
DIRECT_MEMTYPE_DATA UINT16 g_wAutoLogoutCntr = 0;
DIRECT_MEMTYPE_DATA BYTE g_byTimer = 0;
#ifdef __MODULE_WEB_SMART
PFN_CALLBACK g_pfnIdleTaskFunc[3] = { NULL, NULL, NULL };
#else
PFN_CALLBACK g_pfnIdleTaskFunc[1] = { NULL };
#endif
//
// Interrupt Service Routines: Timer 0
//
void PLATvIsrTimer0 (void) interrupt 1
{
PLATvTimer0Init();
g_byTimer++;
// if auto-logout is enabled
if (g_wAutoLogoutTime != 0)
g_wAutoLogoutCntr++;
#ifdef __MODULE_WEB_SMART
if (g_wWebAutoLogoutTime != 0)
g_wWebAutoLogoutCntr++;
#endif
}
//
// Interrupt Service Routines: UART
//
void PLATvIsrUart (void) interrupt 4
{
if (RI == 1) {
// skip cKey==0 for hyper terminal of windows XP
// if UART-rx-buffer is not full and there is an input key
if ( (((s_byRingInPtr + 1) % UART_RING_LEN) != s_byRingOutPtr) && (SBUF != 0) ) {
// increase s_byRingInPtr with wrap around
s_byRingInPtr = (s_byRingInPtr + 1) % UART_RING_LEN;
s_abyUartRxRing[s_byRingInPtr] = SBUF;
// if got input key, reset timer0 counter
g_wAutoLogoutCntr = 0;
g_byTimer = 0;
}
RI = 0;
}
}
// When CPU is idle, will call this function
//
void s_vCpuIdleTask (void) DIRECT_FUNTYPE_REENT
{
// Call IdleTask function 0
(*(g_pfnIdleTaskFunc[0]))();
#ifdef __MODULE_WEB_SMART
// Call IdleTask function 1
(*(g_pfnIdleTaskFunc[1]))();
#endif
}
void PLATvUartInit (void) DIRECT_FUNTYPE_REENT
{
SCON = 0x50; // SCON: mode 1, 8-bit UART; enable rcvr
PCON &= 0x7f; // disable double baud rate
TMOD = 0x21; // TMOD: timer 0: mode 1, 16-bit timer;
// timer 1: mode 2, 8-bit reload timer
TH1 = 249; // TH1: reload value for 9600 baud @ 25MHz
TR1 = 1; // TR1: timer 1 run for UART
}
BYTE PLATbyUartGetKeyMultiTask (void) DIRECT_FUNTYPE_REENT
{
// UART Ring buf is empty
while (s_byRingInPtr == s_byRingOutPtr) {
// Polling for auto logout
if (g_wAutoLogoutCntr > g_wAutoLogoutTime) {
g_wAutoLogoutCntr = 0;
return KEY_DISCONNECT;
}
// idle, thus call IdelTask()
s_vCpuIdleTask();
// check if 0.5 second time out,
// if no key input during this period, thus return 0
if (g_byTimer > (TICK_PER_SEC / 2)) {
// reset timer counter
g_byTimer = 0;
return 0;
}
}
// increase s_byRingOutPtr with wrap around
s_byRingOutPtr = (s_byRingOutPtr + 1) % UART_RING_LEN;
return s_abyUartRxRing[s_byRingOutPtr];
}
// unit of wDelay is ms for 8051 at 25MHz
// BEWARE: wDelay will overflow when wDelay > 851
void PLATvDelay (UINT16 wDelay) DIRECT_FUNTYPE_REENT
{
#ifdef __MODULE_WEB_SMART
DIRECT_MEMTYPE_DATA UINT16 ui;
#else
UINT16 ui;
#endif
wDelay = 77 * wDelay - 5; // DON'T change this formula
for (ui = 0; ui < wDelay; ui++)
;
}
void PLATvCpuInit (void) DIRECT_FUNTYPE_REENT
{
EA = 0; // disable CPU interrupt
TR0 = 0; // stop timer 0
TR1 = 0; // stop timer 1
TMOD = 0x21; // TMOD: timer 0: mode 1, 16-bit timer;
// timer 1: mode 2, 8-bit reload timer
PLATvTimer0Init();
TH1 = 249; // TH1: reload value for 9600 baud @ 25MHz
PCON &= 0x7f; // disable double baud rate
}
void PLATvCpuReset (void) DIRECT_FUNTYPE_REENT
{
#pragma asm
JMP 0
#pragma endasm
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -