📄 ser0.c
字号:
/***************************************************************************
* This code and information is provided "as is" without warranty of any *
* kind, either expressed or implied, including but not limited to the *
* implied warranties of merchantability and/or fitness for a particular *
* purpose. *
* *
* Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved. *
***************************************************************************/
//**************************************************************************
//
// DESCRIPTION: 71M651x POWER METER - hardware abstraction layer
// for SERIAL Ports. The idea here is to hide the hardware just
// enough that several identical files can include this file
// and become adapted to a serial port.
//
// AUTHOR: RGV
//
// HISTORY: See end of file
//
//**************************************************************************
// File: SER0.C
//
//**************************************************************************
// Hardware access layer for UART 0
//
#ifndef SER0_C
#define SER0_C 1
#include "options.h"
#if SERIAL0
#include "batmodes.h"
#include "ser0.h"
#if PARITY_NONE_0
#else
bool ser0_error; // status for the serial port; needed only with parity
#endif
// Get data from the receive register
#pragma save
#pragma NOAREGS
uint8_t ser0_rcv(void) small reentrant
{
// The RI bit is cleared here to be like other UARTs, where
// reading the data register clears the ready bit.
// This lets polling reads always wait for RI,
// and the applications' interrupt code will always clear RI.
RI = 0; // data is being received
#if PARITY_NONE_0
#if SEVEN_BIT_0
// 7 bit, no parity
return (0x7f & SBUF);
#else
// 8 bit, no parity
return SBUF;
#endif
#else // parity cases
#if SEVEN_BIT_0
// 7 bit, parity
A = SBUF; // Calculate parity, result in flag.
if (P != PARITY_ODD_0)
ser0_error = TRUE;
return (A & 0x7F);
#else
// 8 bit, parity
A = SBUF; // Calculate parity, result in flag.
if ((RB8 ^ P) != PARITY_ODD_0)
ser0_error = TRUE;
return A;
#endif
#endif
}
#pragma restore
// serial interrupts for UART 0
#pragma save
#pragma REGISTERBANK (ES0_BANK)
void es0_isr (void) small reentrant interrupt ES0_IV using ES0_BANK
{
if (RI)
{
#ifdef SER0_RCV_INT
// call the higher-level protocol, if any, defined in options.h
// or main\opt_gbl.h
SER0_RCV_INT ();
#else
ser_rcv(); // no higher protocol- throw away the character
#endif
}
if (TI)
{
#ifdef SER0_XMIT_INT
// call the higher-level protocol, if any, defined in options.h
// or main\opt_gbl.h
SER0_XMIT_INT ();
#else
ser_disable_xmit_rdy(); // no higher protocol- stop sending
#endif
}
}
#pragma restore
// Initialize UART 0
#pragma save
#pragma NOAREGS
void ser0_initialize (enum SERIAL_SPD speed) small reentrant
{
ES0 = FALSE; // Begin critical code section, interrupts OFF.
REN = FALSE; // Make sure it gets reset.
ES0_SEL = TRUE; // Run off S0REL.
PCON |= SMOD_; // Force divider = 32 * (2^10 - S0REL).
#if BROWNOUT_BATMODE
if (batmode_is_brownout())
{
S0RELH = BPS_BROWNOUT_300 >> 8;
S0RELL = BPS_BROWNOUT_300 & 0xFF;
}
else
{
#endif
speed += CONFIG0 & MPU_DIV;
S0RELH = bit_rate_tbl[ speed ] >> 8;
S0RELL = bit_rate_tbl[ speed ] & 0xFF;
#if BROWNOUT_BATMODE
}
#endif
#if (((SEVEN_BIT_0 || PARITY_NONE_0) && !STOP_BIT2_0) \
|| (SEVEN_BIT_0 && PARITY_NONE_0 && STOP_BIT2_0))
// 8N1, 7E1, 7E2, 7N2 are 8 bits; 7N1 is impossible
// Serial port mode 1, (8-Bit UART), REN, TB8.
SCON = _8BIT_SERIAL0_ | REN_ | TB8_;
#else
// 8N2, 7E2, 7O2, 8E1, 8O1 are 9 bits; 8E2 and 8O2 are impossible
// Serial port mode 1, (9-Bit UART), REN, TB8.
SCON = _9BIT_SERIAL0_ | REN_ | TB8_;
#endif
// When transmit interrupts are enabled, transfer will begin immediately
// Polling transmits can always check TI first
TI = 1; // transmit is ready
// clear out unwanted data
while (ser_rcv_rdy ())
ser_rcv ();
#ifdef ser0_error
ser0_error = FALSE;
#endif
// Interrupt priorities are set in main.
// leave interrupts disabled- enabling interrupts is for application
}
#pragma restore
#endif
#endif
/***************************************************************************
* $Log: ser0.c,v $
* Revision 1.24 2006/09/27 00:57:01 tvander
* More comments
*
* Revision 1.23 2006/09/20 23:49:34 tvander
* Set interrupt priorities only once, during start-up
*
* Revision 1.22 2006/09/18 19:22:43 tvander
* Sets interrupt priorities.
*
* Revision 1.21 2006/09/09 01:09:57 gmikef
* *** empty log message ***
*
* Revision 1.20 2006/08/09 00:56:35 tvander
* *** empty log message ***
*
* Revision 1.19 2006/07/18 23:35:51 tvander
* Wrong register space for initialization routine.
*
* Revision 1.18 2006/07/07 00:55:31 tvander
* Fixed register accesses, and baud rate selection.
*
* Revision 1.17 2006/03/06 03:32:06 Michael T. Fischer
* More 6530 prep.
*
* Revision 1.15 2005/10/18 02:17:09 tvander
* Access CLI in brownout by pressing reset.
* Debugged serial 1 usage from CLI.
* Implemented scrolling display as M17
*
* Revision 1.14 2005/09/22 23:45:06 tvander
* Clean build all models and unit tests, updated copyright to be fore Teridian
*
* Revision 1.13 2005/09/11 00:33:58 tvander
* Clean compiles
*
* Revision 1.12 2005/09/08 00:31:40 tvander
* Fixed: Lost data due to overwrite of Ithrshld, xfer busy never runs,
* unavailable second phase, cosmetic issues with status. Updated
* date.
*
* Revision 1.11 2005/08/28 02:14:54 gmikef
* *** empty log message ***
*
* Revision 1.10 2005/08/20 01:32:46 gmikef
* *** empty log message ***
*
* Revision 1.9 2005/08/19 01:04:39 gmikef
* *** empty log message ***
*
* Revision 1.8 2005/05/14 00:56:18 tvander
* Integrated flag0, ser0
* Regression tested and fixed 6521b
*
* Revision 1.7 2005/04/21 02:00:11 gmikef
* *** empty log message ***
*
* Revision 1.7 2005/04/09 02:04:25 gmikef
* *** empty log message ***
*
* Revision 1.6 2005/03/31 00:18:21 tvander
* Minimally unit tested.
* UART 0 is tested at 9600 BAUD 7 bits even parity, one stop bit.
* UART 1 is tested at 300 BAUD 7 bits even parity, one stop bit.
*
* Revision 1.5 2005/03/24 22:12:51 tvander
* Misc improvements
*
* Revision 1.4 2005/03/24 01:38:59 tvander
* First successful compile of serial unit test
*
* Revision 1.3 2005/03/23 19:19:31 tvander
* Added untested timer functions.
* Updated iicdio and iiceep to reflect improvements in 6510 code.
* ser0 and ser1 updated to provide features for flag.
*
* Revision 1.2 2005/03/15 00:32:34 tvander
* More realistic hardware abstraction layer.
*
* Revision 1.1 2005/03/11 22:17:21 tvander
* Structure
*
* Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved. *
* this program is fully protected by the United States copyright *
* laws and is the property of Teridian Semiconductor Corporation. *
***************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -