|
|
Número de pieza | AN3334 | |
Descripción | Data Structures | |
Fabricantes | Freescale Semiconductor | |
Logotipo | ||
Hay una vista previa y un enlace de descarga de AN3334 (archivo pdf) en la parte inferior de esta página. Total 26 Páginas | ||
No Preview Available ! Freescale Semiconductor
Application Note
Document Number: AN3334
Rev. 0, 11/2006
Data Structures for RS08
Microcontrollers
by: Inga Harris
8-bit Microcontroller Applications Engineer
East Kilbride, Scotland
1 Introduction
This application note presents data structures useful in
developing microcontroller software. You can apply
these basic data structures in a microcontroller
application.
A data structure describes how information is organized
and stored in a computer system. Although data
structures are usually presented in the context of
computers, the same principles can be applied to
embedded 8-bit processors. The efficient use of
appropriate data structures can improve both the
dynamic (time-based) and static (storage-based)
performance of microcontroller software.
The RS08 core differs from other Freescale 8-bit cores,
in that it does not have a stack pointer or index register
(data structures use both). Software can recover these
feature, as shown in this application note. For other
Freescale 8-bit core examples, refer to Freescale
document-order number AN1752.
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1 Storing Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Accessing Strings . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 String Applications. . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.1 Stack Reading and Writing . . . . . . . . . . . . . . . . . . . 4
3.2 MCU Hardware Stack . . . . . . . . . . . . . . . . . . . . . . . 4
3.3 RS08 Stack Applications . . . . . . . . . . . . . . . . . . . . . 5
4 Queues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.1 Reading and Writing . . . . . . . . . . . . . . . . . . . . . . . . 8
4.2 Queue Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.3 Queue Applications . . . . . . . . . . . . . . . . . . . . . . . . . 8
5 Multiple Access Circular Queue (MACQ) . . . . . . . . . . . 11
5.1 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
6 Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
6.1 Table Applications . . . . . . . . . . . . . . . . . . . . . . . . . 15
6.2 Table Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
7 Linked Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
7.1 Linked List Applications . . . . . . . . . . . . . . . . . . . . . 18
7.2 State Machines . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
7.3 State Machine Example. . . . . . . . . . . . . . . . . . . . . 19
7.4 Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
8 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
© Freescale Semiconductor, Inc., 2006. All rights reserved.
Free Datasheet http://www.datasheet4u.com/
1 page Stacks
3.2.1 RS08 Stack
The RS08 family of MCUs have no stack-pointer registers in the core and, therefore, no automatic program
control. Section 7, “Linked Lists,” shows a macro managing the use of the shadow program counter (SPC)
for nested subroutines. The rest of this chapter described a generic stack application adaptable for any
application need.
3.3 RS08 Stack Applications
A stack is useful for dynamically allocating memory or passing parameters to and from subroutines.
Typically, MCU RAM variables are statically allocated at assembly time.
For example:
; Statically allocated RAM variables
ORG RAMSPACE
MyVar1
MyVar2
MyVar3
RMB 1
RMB 1
RMB 2
; Another method to statically allocate variable
MyVar4
EQU RAMSPACE+4
MyVar5
EQU RAMSPACE+5
This is appropriate for global variables, which need to be available throughout the program flow. However,
for local variables only used in specific subroutines, this method is not most efficient. These variables’
RAM space can be dynamically allocated by using a software stack or MCU stack, freeing up RAM
memory. The same method can apply to subroutine input and output parameters, passing them on the stack
instead of in the A or X register.
The following code shows a software implementation of a stack appropriate for RS08 family of MCUs.
Software stack:
;**************************************************************************
;* A simple software stack implementation simply shows the PUSH and
*
;* PULL operations on a stack; not intended to be a complete application. *
;* StackPtr points to next (empty) available location
*
;**************************************************************************
;Stack Equates
StackTop: equ $00000048
StackBottom: equ $0000004F
;
; variable/data section
;
ORG RAMStart
StackPointer
DC.B 1
temp
DC.B 1
;Pointer to next stack byte
;Temporary storage location
Freescale Semiconductor
Data Structures for RS08 Microcontrollers, Rev. 0
5
Free Datasheet http://www.datasheet4u.com/
5 Page WrapGet
DeQDone
QEmpty
LDX GetPointer
LDA $0E
STA TempA
LDA GetPointer
CMP #QueueBottom
BEQ WrapGet
INC GetPointer
BRA DeQDone
LDA #QueueTop
STA GetPointer
LDX TempX
LDA TempA
DEC QCount
CLC
RTS
LDX TempX
SEC
RTS
Multiple Access Circular Queue (MACQ)
;If Queue has population
;get item from Queue
;Increment Pointer
;If OK move pointer back to
;Top of Queue
;Restore X register
;Decrement Q Counter
;Clear Carry Bit
;Restore X register
;Set Carry Bit
5 Multiple Access Circular Queue (MACQ)
A multiple access circular queue (or circular buffer) is a modified version of the queue data structure. It is
a fixed-length, order-preserving data structure and contains the most recent entries. It is useful for
data-flow problems, when only the latest data is of interest. Once initialized, it is full, and a write operation
discards the oldest data.
Figure 4 depicts a MACQ.
Latest data here
Data 8
Data 7
Data 6
Data 5
Data 4
Data 3
Data 2
Data 1
Data
New Data
Data 8
Data 7
Data 6
Data 5
Data 4
Data 3
Data 2
Address
$50
$51
$52
$53
$54
$55
$56
$57
Figure 4. Result of a MACQ Write
Freescale Semiconductor
Data Structures for RS08 Microcontrollers, Rev. 0
11
Free Datasheet http://www.datasheet4u.com/
11 Page |
Páginas | Total 26 Páginas | |
PDF Descargar | [ Datasheet AN3334.PDF ] |
Número de pieza | Descripción | Fabricantes |
AN3334 | Data Structures | Freescale Semiconductor |
AN3336 | 4-Head VCR Recording/Playback Amplifier IC | Panasonic Semiconductor |
AN3336SB | 4-Head VCR Recording/Playback Amplifier IC | Panasonic Semiconductor |
Número de pieza | Descripción | Fabricantes |
SLA6805M | High Voltage 3 phase Motor Driver IC. |
Sanken |
SDC1742 | 12- and 14-Bit Hybrid Synchro / Resolver-to-Digital Converters. |
Analog Devices |
DataSheet.es es una pagina web que funciona como un repositorio de manuales o hoja de datos de muchos de los productos más populares, |
DataSheet.es | 2020 | Privacy Policy | Contacto | Buscar |