📄 ser0cli.c
字号:
irq_enable (); // critical section- find the buffer size in use
return (len);
}
#pragma restore
#endif
#if PORT == 0
uint16_t Serial0_CRx (uint8x_t *buffer, uint16_t rxlen)
#elif PORT == 1
uint16_t Serial1_CRx (uint8x_t *buffer, uint16_t rxlen)
#else
#error unhandled port selection
#endif
{ // Here we assume (head = tail) => EMPTY
if (rxlen > 0)
{
uint16_t len;
irq_disable (); // critical section- find the buffer size available
len = (uint16_t) cchRx;
irq_enable (); // critical section- find the buffer size available
rxlen = len = min (rxlen, len); // figure the size to be used
while (len--) // copy the data out
{
ichOutRx &= mbuf;
*buffer++ = achRx[ ichOutRx++ ];
}
if (rxlen > 0)
{
irq_disable (); // critical section- consume the buffer
cchRx -= rxlen;
if (xon_xoff_s && !rxs_flow)
{ // Maybe turn flow back ON.
if (cchRx < sbf / 4)
rxs_flow_on ();
}
irq_enable (); // critical section- consume the buffer
}
}
return rxlen;
}
#pragma save
#pragma NOAREGS
static void rxs_flow_on (void) small reentrant
{
rxs_flow = ON; // Turn flow ON.
txs = XON; // Send XON.
if (S_EMPTY == txs_status)
{
txs_status = S_PENDING;
stm_stop (free_cnt);
free_cnt = NULL;
ser_enable_xmit_rdy();
}
}
static void rxs_flow_off (void) small reentrant
{
rxs_flow = OFF; // Turn flow OFF.
txs = XOFF; // Send XOFF.
if (S_EMPTY == txs_status)
{
txs_status = S_PENDING;
stm_stop (free_cnt);
free_cnt = NULL;
ser_enable_xmit_rdy();
}
}
static void free_timer (void) small reentrant
{
free_cnt = NULL;
ser_xmit_free(); // free the transmitter for other uses
}
#pragma restore
#if ROM == 1
#if PORT == 0
void Serial0_RxFlowOn (void)
#elif PORT == 1
void Serial1_RxFlowOn (void)
#else
#error unhandled port selection
#endif
{
irq_disable (); // Begin critical section.
rxs_flow_on ();
irq_enable (); // End critical section.
}
#endif
#if ROM == 1
#if PORT == 0
void Serial0_RxFlowOff (void)
#elif PORT == 1
void Serial1_RxFlowOff (void)
#else
#error unhandled port selection
#endif
{
irq_disable (); // Begin critical section.
rxs_flow_off ();
irq_enable (); // End critical section.
}
#endif
#pragma save
#pragma NOAREGS
#if PORT == 0
void cli0_in (void) small reentrant
#elif PORT == 1
void cli1_in (void) small reentrant
#else
#error unhandled port selection
#endif
{
static uint8_t data rx;
rxs = ser_rcv();
rx = rxs & 0x7F;
if (xon_xoff_s && (XON == rx || XOFF == rx))
{
switch (rx)
{
case XON:
if (!txs_flow && (S_PENDING == txs_status))
{ // Restart XMT'r.
stm_stop (free_cnt);
free_cnt = NULL;
ser_enable_xmit_rdy();
}
txs_flow = TRUE;
break;
case XOFF:
txs_flow = FALSE;
break;
}
}
else if (cchRx < sbf)
{
ichInRx &= mbuf;
achRx[ ichInRx++ ] = rxs;
cchRx++;
if (xon_xoff_s && ((rxs_flow && (sbf / 2 < cchRx)) || (cchRx > sbf - 4)))
rxs_flow_off (); // Turn flow off.
}
}
#pragma restore
#pragma save
#pragma NOAREGS
#if PORT == 0
void cli0_out (void) small reentrant
#elif PORT == 1
void cli1_out (void) small reentrant
#else
#error unhandled port selection
#endif
{
if (txs != '\0')
{
ser_xmit (txs);
txs = '\0'; // Allows insertion of single flow control byte later.
}
else if (0 == cchTx)
{
txs_status = S_EMPTY;
ser_disable_xmit_rdy();
free_cnt = stm_start (milliseconds(7000), 0, free_timer);
}
else if (txs_flow)
{
ichOutTx &= mbuf;
ser_xmit (achTx[ ichOutTx++ ]);
cchTx--;
}
else
{ // TX flow turned off..
ser_disable_xmit_rdy(); // ..probably via XOFF.
free_cnt = stm_start (milliseconds(7000), 0, free_timer);
}
}
#pragma restore
/***************************************************************************
* $Log: ser0cli.c,v $
* Revision 1.25 2006/09/27 00:54:23 tvander
* Initialize low level driver after high level buffering is set up.
*
* Revision 1.24 2006/09/09 01:08:34 gmikef
* *** empty log message ***
*
* Revision 1.23 2006/06/29 00:54:05 tvander
* Minor fix to comments
*
* Revision 1.22 2006/06/23 20:46:05 tvander
* Removed wait-for-io; it slowed response in brownout mode, and caused
* hangs. The cure was definitely worse than the disease: a few clobbered characters after certain commands.
*
* Revision 1.21 2006/06/15 19:56:04 tvander
* Fixed misc. serial errors.
*
* Revision 1.20 2006/06/06 03:53:51 tvander
* Added calibration count to access.c
* Added to help files, at least, they compile for a 6513.
* io.c support the calibration loader.
* ser0cli.c and ser1cli.c were allocating too many timers. Fixed.
*
* Revision 1.19 2006/05/25 03:25:58 tvander
* Some untested adjustments for calibration loader.
* Added automatic enabling of UART2 and switching to pulse output on DIO2
*
* Revision 1.18 2006/04/28 22:24:05 tvander
* Reverse ported defects fixed when these files were ported to the 3.05 code.
*
* Revision 1.17 2006/03/07 23:57:08 tvander
* Revised help system for accuracy.
* Revised help system for compile flags.
* Clean build
*
* Revision 1.16 2006/03/06 03:28:54 Michael T. Fischer
* More 6530 prep.
*
* Revision 1.15 2006/01/16 20:11:20 tvander
* Clean Keil build, all versions
*
* Revision 1.14 2006/01/10 03:55:21 gmikef
* Added PDATA support for CE Outputs.
*
* Revision 1.12 2005/12/07 01:36:53 tvander
* Added conditionals to make Xoff/Xon flow controls present in ROM.
*
* Revision 1.11 2005/11/15 05:11:35 gmikef
* Added Serial_RxFlowOn/Off publics.
*
* Revision 1.10 2005/11/05 02:23:45 gmikef
* Fixed bug in XON/XOFF protocol.
* Detect and notify of out of range download data.
*
* Revision 1.9 2005/11/04 03:16:30 gmikef
* Enhanced XOFF (send out extra XOFF if necessary).
* Enhanced help and download info.
*
* Revision 1.8 2005/11/03 19:18:31 tvander
* Same logic, but ser1cli.c and ser0cli.c are the same code.
*
* Revision 1.7 2005/11/02 03:07:28 gmikef
* Xon/Xoff flow control working.
*
* Revision 1.6 2005/10/18 02:17:08 tvander
* Access CLI in brownout by pressing reset.
* Debugged serial 1 usage from CLI.
* Implemented scrolling display as M17
*
* Revision 1.5 2005/10/08 04:41:18 tvander
* Fixed priority inversion.
* Rewrote watchdog to work in brownout, but of course it doesn't work.
* Watchdog can now be defeated by clearing watchdog option to 0.
* Reorganized watt hour modules (at last!).
* Disabled reading of STATUS in 6521_cli because the CE's status is always SAG.
* Tested with 6521_CLI; measurements seem to work.
* Fixed other builds.
*
* Revision 1.4 2005/09/12 07:47:28 tvander
* Power measurement is stable, with no creep.
* VARh measurement is stable, with no creep.
* Pulse sources work.
* Full access to MPU variables.
* Rolled date.
* Clock software works.
*
* Revision 1.3 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.2 2005/08/31 05:52:45 gmikef
* First version w/ LAPIE interface.
*
* Revision 1.1 2005/08/28 02:25:41 gmikef
* *** empty log message ***
*
* Revision 1.2 2005/08/20 01:32:45 gmikef
* *** empty log message ***
*
* Revision 1.1 2005/08/19 01:06:52 gmikef
* *** empty log message ***
*
* 2005 August 18; First Version.
*
* 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. *
***************************************************************************/
#endif /* SER0CLI.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -