Ap1605110 Emulating ASC Via SSC
Ap1605110 Emulating ASC Via SSC
2004
AP16051
SAB C161K/V/O
Emula ting a n async hro nous s er ia l
i n te r face ( A S C ) v ia th e on - c h ip
sync hro nous s er ia l inte r face
( S SC)
.
N e v e r s t o p t h i n k i n g .
SAB C161K/V/O
LEGAL DISCLAIMER
THE INFORMATION GIVEN IN THIS APPLICATION NOTE IS GIVEN AS A HINT FOR THE
IMPLEMENTATION OF THE INFINEON TECHNOLOGIES COMPONENT ONLY AND SHALL NOT BE
REGARDED AS ANY DESCRIPTION OR WARRANTY OF A CERTAIN FUNCTIONALITY, CONDITION OR
QUALITY OF THE INFINEON TECHNOLOGIES COMPONENT. THE RECIPIENT OF THIS APPLICATION
NOTE MUST VERIFY ANY FUNCTION DESCRIBED HEREIN IN THE REAL APPLICATION. INFINEON
TECHNOLOGIES HEREBY DISCLAIMS ANY AND ALL WARRANTIES AND LIABILITIES OF ANY KIND
(INCLUDING WITHOUT LIMITATION WARRANTIES OF NON-INFRINGEMENT OF INTELLECTUAL
PROPERTY RIGHTS OF ANY THIRD PARTY) WITH RESPECT TO ANY AND ALL INFORMATION GIVEN
IN THIS APPLICATION NOTE.
Information
For further information on technology, delivery terms and conditions and prices please contact your nearest
Infineon Technologies Office (www.infineon.com).
Warnings
Due to technical requirements components may contain dangerous substances. For information on the types
in question please contact your nearest Infineon Technologies Office.
Infineon Technologies Components may only be used in life-support devices or systems with the express
written approval of Infineon Technologies, if a failure of such components can reasonably be expected to
cause the failure of that life-support device or system, or to affect the safety or effectiveness of that device or
system. Life support devices or systems are intended to be implanted in the human body, or to support
and/or maintain and sustain and/or protect human life. If they fail, it is reasonable to assume that the health
of the user or other persons may be endangered.
AP16051
Emulating an ASC via the on-chip SSC
Table of Contents
1 Introduction ................................................................................................... 2
2 General Operation and Hardware Environment ............................................ 2
2.1 Supported Features ...................................................................................... 2
2.2 Required Resources ..................................................................................... 2
2.3 External Routing............................................................................................ 2
2.4 Principles of Emulation.................................................................................. 2
2.4.1 ASC Write ................................................................................................. 2
2.4.2 ASC READ................................................................................................ 2
3 ASC Emulation Software Description............................................................ 2
3.1 Software Structure ........................................................................................ 2
3.2 Main Program................................................................................................ 2
3.3 Emulation Subroutines .................................................................................. 2
3.4 Baud Rate Calculation................................................................................... 2
3.5 Load Measurement ....................................................................................... 2
3.6 Performance Limitations................................................................................ 2
3.7 Debugging Support Pins ............................................................................... 2
3.8 Make File....................................................................................................... 2
3.9 Support of KitCON161 Evaluation Board ...................................................... 2
1 Introduction
The C16x microcontroller family provides only one on-chip asynchronous serial
communication channel (ASC). If a second ASC is required, an emulation of the
missing interface may help to avoid an external hardware solution with additional
electronic components.
The solution presented in this paper and in the attached source files emulates the
most important ASC functions by using the on-chip synchronous serial communication
channel (SSC) with a performance up to 125 KBaud in half duplex mode and an
overhead less than 12% at SAB C161O with 16 MHz. All files are available for Keil and
Tasking C Cross Compiler.
Due to the implementation in C this performance is not the limit of the chip. A pure
implementation in assembler will result in a reduction of the CPU load and therefore
increase the maximum speed of the interface.
Speaking about performance, it is strongly advised to have a close look at the
assembler code generated by the different compilers. Moreover, at C16x architecture
the speed of executing code strongly depends on the area where code and data are
fetched from (external memory 16 bit data access, external memory 8 bit data access,
Internal RAM, on-chip Flash, ...).
In addition, only a pin compatible solution is provided. The internal register based
programming interface is replaced by a set of subroutine calls.
The attached source files also contain a test shell, which demonstrates how to
exchange information between an on-chip HW-ASC and the emulated SSC-ASC via
three external wires in different operation modes. It is based on the SAB C161O
(Siemens 16 bit microcontroller).
A table with load measurements is presented to give an indication for the fraction of
CPU performance required by software for emulating the ASC.
EX1
P2.15 (optional)
MTSR
1 1 Stop Stop Parity Data Bits Start
Bit Bit Bit Bit
Pin
MSB LSB
Data Frame
Start
USART Bit
Stop
Bit
Ext. Interrupt
Timer
An ASC READ is initiated by an ASC Start Bit arriving at the SSC-SRI input pin, which
is externally connected to an External Interrupt pin. The correlated interrupt service
routine starts a timer loaded with 0.5 bit time of the required baud rate.
The timer interrupt service routine starts the SSC in ‘Master Mode’ by writing a dummy
byte (0xFFFF) into the SSCTB buffer, which simultaneously starts the SSC receive
shift register sampling n data bits. Although the dummy byte 0xFFFF may be shifted
out without triggering the external communication partner’s receive HW (because the
transmitted message byte does not contain any ‘0’ bit to be interpreted as Start Bit),
the MTSR output pin will be configured as input to avoid any noise transmission to the
external communication partner.
The final ASC Stop Bit provided by the external transmitter is completely ignored to
gain some time for preparing reception of the next byte of a continuous input data
stream.
USSC_INIT_
_EMULATED_
_USART_READ
USSC_FINISH_
_EMULATED_
_USART_WRITE
USSC_HW_
_USART_
_WRITE_OUT ussc_flag_hw
ussc_flag_hw _ssc_ready == ON
_ssc_ready == ON &
& transmit_word_number
transmit_word_number == USSC_BUFFER_LENGTH
< USSC_BUFFER
_LENGTH
USSC_WHILE_ USSC_WHILE_ ussc_flag_
ussc_flag_hw _hw_ssc_
_SSC_ _SSC_
_ssc_ready == OFF _ready
_READS_IN _WRITES_OUT
== OFF
ussc_flag_hw ussc_flag_hw
_ssc_ready == ON _ssc_ready == ON
& &
transmit_word_number transmit_word_number
== USSC_BUFFER_LENGTH < USSC_BUFFER
_LENGTH
ussc_ssc_receive_
_word_number-- > 0
&
error == OFF
USSC_FINISH_ USSC_INIT_
_EMULATED_ _EMULATED_
_USART_READ _USART_WRITE
The first test case verifies the emulated ASC by a data reception from an external
source:
• In the first state ‘USSC_INIT_EMULATED_USART_READ’ the emulated ASC
interface is initialized with the baud rate to be supported (125 KBaud). As
communication partner serves the on-chip HW-ASC which is set up in same baud
rate.
• The second state ‘USSC_HW_USART_WRITE_OUT’ starts the on-chip HW-ASC.
• In the third state ‘USSC_WHILE_SSC_READS_IN’ a flag is polled indicating the end
of data reception via the SSC. User application code to be executed during the SSC
read in operation may be included here instead of wasting 8 or 9 bit times only for
running a polling loop. After finishing the transmission of a whole message
containing a programmable number of words the state machine proceeds to the next
state.
• The state ‘USSC_INPUT_PARITY_CHECK’ analyzes the message string received
by SSC. If a difference between received and calculated parity bit is detected the
state machine goes to the error state ‘USSC_PARITY_ERROR’ and stops.
• The last state ‘USSC_FINISH_EMULATED_USART_READ’ disables all hardware
modules required for data transmission.
In the second test case the communication is started with an altered transmission
direction. The SSC operates as data source and provides the on-chip HW-ASC with a
message string.
fOSC
USSC_HW_USART_xxxx_BAUD =
2 * 16 * Desired_Baud_Rate - 1
For SSC read operations the load value of timer 2 (0.5 bit time delay) is corrected by a
constant in file ‘uss_defi.h’ (USSC_INTERRUPT_DELAY), which takes into account
• the Interrupt Response Time for External Interrupt1 after receiving a Start Bit,
• the Interrupt Response Time for Timer2 underflow including the execution time for
all statements in the corresponding interrupt service routine before starting a SSC
operation.
The exact value for ‘USSC_INTERRUPT_DELAY’ may be extracted by analyzing the
assembler program listing or by checking bit pulse signals with an oscilloscope.
Note: The ‘USSC_INTERRUPT_DELAY’ value depends on the clock generator
frequency.
For double checking purpose test statements are included in emulation subroutines
indicating the begin and the end of an interrupt service or emulation routine by
switching port pin P2.15 to ‘Low’ and to ‘High’ state. This port pin may be scanned by
an oscilloscope. However, the pulse width measured at this test pin does not exactly
represent the CPU load caused by a subroutine execution. Even if the macro
‘reset_test_pin_latch()’ is found at the very beginning of a C coded subroutine or the
macro ‘set_test_pin_latch()’ is seen as last statement in C source code, several stack
operations to be executed are found in the compiler’s object module listing before or
after the test pin is affected (PUSH register x, PULL register x).
The next table presents load calculation results for an ASC emulation via the on-chip
SSC running with different baud rates (data frames without parity bit).
Table 2 Load Measurement Values for an ASC emulation via the on-chip
SSC (without parity bit) at SAB C161O
HW-SSC-MRST HW-SSC-MTSR
(P3.8) (P3.9)
HW-ASC-TXD X
(P3.10)
HW-ASC-RXD X
(P3.11)
Ext. Interrupt 1 X
(P2.9)
After setting jumper 9 to position (2+3) and pressing the restart button the test program
runs in an endless loop.