O.VENARD - ESIEE/SIGTEL - 2007 1
Chaîne de traitement
Architecture matérielle et logicielle bas niveau
AIC23
Le système
CPU DMA
RxChan RxBuffer ADC
DAC
McBSP
Rx
Tx
TxChan TxBuffer
TNS
Po ng Po ng Pi ng
Pi ng
O.VENARD - ESIEE/SIGTEL - 2007 3
Tables des matières I
• Introduction.
– Introduction
– L’interface DSP-AIC (Analog Interface Component) – Interface utilisateur de programmation graphique
(CDB)
– Configuration des interface série du DSP
– Entrée-sorties : programmation par « polling »
Tables des matières II
• Travail à réaliser
– Traitement échantillon par échantillon :
• Gestion des entrées-sorties par interruption
– Traitement par bloc :
• Insertion des canaux DMA pour gérer le flux de données
O.VENARD - ESIEE/SIGTEL - 2007 5
La carte DSK5510
Atelier logiciel
Target Board DSP
CODEC DIP Switches Timer
CSL
Kernel/Scheduler DSP/BIOS™BSL Drivers
User Application
McBSP EMIF CPU
O.VENARD - ESIEE/SIGTEL - 2007 7
Periphériques TMS320VC5510
• 2 Timers 20-Bits.
• contrôleur DMA (Direct Memory Access) 6 Canaux.
• 3 ports série bufferisés, McBSP (Multichannel Buffered Serial Ports).
• 8 ports d’E/S d’usage général (GPIO), 1 dédié (XF).
Interface DSP-AIC
O.VENARD - ESIEE/SIGTEL - 2007 9
TLV320AIC23
• 90dB SNR ΣΔ ADC
• 100dB SNR ΣΔ DAC
• Control I²C ou SPI
• Data I²S ou DSP mode
– 16/20/24/32 bits
– Justification MSB ou LSB
Paramètres liaison série
• McBSP1 (contrôle) :
– Unidirectionnelle (DSP ¼AIC)
– SPI format – mot de contrôle de 16 bits
• McBSP2 (samples IO)
– Bidirectionnelle DSP mode 16 bits
O.VENARD - ESIEE/SIGTEL - 2007 11
SPI (Serial Peripheral Interface)
• http://www.epanorama.net/links/serialbus.html
•SCK (Serial Data Clock):Data is shifted/latched on the rising or falling edge of SCK (see next section).
•MOSI (Master Output/Slave Input):Data is transmittedoutof this pin if the chip is a Master and intothis pin if the chip is a Slave.
•MISO (Master Input/Slave Output):Data is received intothis pin if the chip is a Master and transmittedoutof this pin if the chip is a Slave.
•/CS (Chip Select, active low):Tells the peripheral that a transfer is about to begin CPOL (clock polarity) and CPHA (clock phase)
I²S (Inter IC Sound) bus
• Données audio, contrôle transmis séparément. 3 fils
– SCK : Serial ClocK (continue) généré par le maître.
– WS : Word Select généré par le maître.
• 0 : canal1/gauche – 1: canal2droit
• Échantillonné sur front montant de SCK dans le récepteur.
– SD : Serial Data
• Cà2 – MSB en premier
• Échantillonné sur front montant de SCK dans le récepteur.
O.VENARD - ESIEE/SIGTEL - 2007 13
M ulti- c hannel B uffered S erial P ort
Fonctionnalités McBSP
• mots: 8, 12, 16, 20, 24, 32 bits
• phase: 1 (max 128 mots/trame), 2 (max 256 mots/trame)
• trame:1 (max 4096bits)
• mode SPI mode, AC97, multi-canaux (jusqu’à 128), …
O.VENARD - ESIEE/SIGTEL - 2007 15
Registres de contrôle McBSP
(x= 0, 1, 2)
SPCR1x McBSP serial port control register 1 SPCR2x McBSP serial port control register 2 RCR1x McBSP receive control register 1 RCR2x McBSP receive control register 2 XCR1x McBSP transmit control register 1 XCR2x McBSP transmit control register 2
SRGR1x McBSP sample rate generator register 1 SRGR2x McBSP sample rate generator register 2 PCRx McBSP pin control register
Voir TMS320VC5501/5502/5503/5507/5509/5510 DSP Multichannel Buffered Serial Port (McBSP) Reference Guide (spru592d.pdf)
CDB : Configuration Data Base
• Interface graphique de programmation :
– Configuration système : définition des bancs mémoires, …
– Primitives RTOS (DSP/BIOS) : tâches,
interruptions, synchronisation (sémaphore), …
– Initialisation des périphériques du DSP (génération
du code) : McBSP, DMA, …
O.VENARD - ESIEE/SIGTEL - 2007 17
Création d’un fichier CDB
Endroit où se trouvera le fichier dans l’arborescence du projet
Création d’un nouveau fichier de configuration CDB
Sélection d’une plateforme cible
O.VENARD - ESIEE/SIGTEL - 2007 19
Interface Graphique de Programmation
Création d’une configuration pour le périphérique McBSP
Création d’une configuration
Édition de la configuration
O.VENARD - ESIEE/SIGTEL - 2007 21
Édition de la configuration
Association de la configuration avec un périphérique matériel
Initialisation d’un périphérique matériel
Association de ce périphérique avec la configuration créée
C55XX_CONTROLHANDLE_hMcbsp
O.VENARD - ESIEE/SIGTEL - 2007 23
Configuration mode SPI
TLV320AIC23
Configuration McBSP (CSL)
Fichiers de configuration générés
MCBSP_ConfigmcbspCfg1 = {
0x1000, /* Serial Port Control Register 1 */
0x0100, /* Serial Port Control Register 2 */
0x0000, /* Receive Control Register 1 */
0x0000, /* Receive Control Register 2 */
0x0040, /* Transmit Control Register 1 */
0x0000, /* Transmit Control Register 2 */
0x0063, /* Sample Rate Generator Register 1 */
0x2013, /* Sample Rate Generator Register 2 */
0x0000, /* Multichannel Control Register 1 */
0x0000, /* Multichannel Control Register 2 */
0x1a0a, /* Pin Control Register */
… };
MCBSP_HandleC55XX_CONTROLHANDLE_hMcbsp;
voidCSL_cfgInit() {
C55XX_CONTROLHANDLE_hMcbsp = MCBSP_open(MCBSP_PORT1, MCBSP_OPEN_RESET);
MCBSP_config(C55XX_CONTROLHANDLE_hMcbsp, &mcbspCfg1);
…
audioIOcfg.c
O.VENARD - ESIEE/SIGTEL - 2007 25
Registres de contrôle AIC
Contrôle de l’interface
O.VENARD - ESIEE/SIGTEL - 2007 27
Interface série
• Mode I²S
• Mode DSP
LRP=0
n dépend de IWL
Configuration DSP mode
•0x0043, /* 7 DSK5510_AIC23_DIGIF Digital audio interface format */
•FOR[1:0] = ’11’ DSP mode
•IWL[1:0]= ’00’16 bits
•LRP= ‘0’MSB sans délai après synchro trame
•MS = ‘0’mode maître (synchro générée par circuit AIC)
TLV320AIC23
Configuration McBSP (CSL) Handle :
C55XX_DMA_MCBSP_hMcbsp
O.VENARD - ESIEE/SIGTEL - 2007 29
Contrôle de volume entrée
Contrôle volume écouteur
O.VENARD - ESIEE/SIGTEL - 2007 31
Board Support Library
(répertoire dsk5510/c5510dsk.hlp )
basicAudioIO
while(1){
// Read 32 bits of codec data, loop to retry if data port is busy while(!DSK5510_AIC23_read32(hCodec, &Ldata));
// Write 32 bits to the codec, loop to retry if data port is busy while(!DSK5510_AIC23_write32(hCodec, Ldata));
} Build options :
•Compiler>preprocessor : « c:/ti/c5500/dsk5510/include »
•Linker>basic: « c:/ti/c5500/dsk5510/lib »
O.VENARD - ESIEE/SIGTEL - 2007 33
EVTs et INTs pilotés par le McBSP
Interruptions
IER
“Individual Enable”
INTM
“Master Enable”
‘C5510 CPU
IFR
Interrupt Flag
0 1 0
…
DMA McBSP Timers External EHPI
DMA McBSP Timers External EHPI
IFR – Interrupt Flag Reg Latches interrupt events
…
IER – Interrupt Enable Reg
INTM – Global Int Enable
Enables all IER-enabled
interrupts
O.VENARD - ESIEE/SIGTEL - 2007 35
Interruptions TMS320VC5510
Traitement d’interruption 1
…
// Validation des interruption // clear pending interrupts IRQ_clear(IRQ_EVT_RINT2);
// Enable receive RINT2 interrupt (IMR) IRQ_enable(IRQ_EVT_RINT2);
// enable global interrupts (INTM)
void ADCint() {
…
O.VENARD - ESIEE/SIGTEL - 2007 37
Traitement d’interruption 1bis
void ADCint() {
DSK5510_AIC23_read32(hCodec, &data);
DSK5510_AIC23_write32(hCodec, data);
}
void ADCint() {
DSK5510_AIC23_read32(hCodec, &data);
DSK5510_AIC23_write32(hCodec, data);
}
Traitement d’interruption 2
IRQ_clear(IRQ_EVT_RINT2);
IRQ_clear(IRQ_EVT_XINT2);
// Enable receive RINT2 interrupt (IMR) IRQ_enable(IRQ_EVT_RINT2);
IRQ_enable(IRQ_EVT_XINT2);
// enable global interrupts (INTM) //IRQ_globalEnable();
void ADCint() {
… }
void DACint() {
O.VENARD - ESIEE/SIGTEL - 2007 39
Traitement par bloc
In-255
tp
t
B. . .
In-0
Rx Buffer (Ping)
In-511
Process (Ping)
Rx Buffer (Pong) Rx Buffer (Ping) Process (Pong)
Out-0 . . . Out-255
Tx Buffer (Ping)Latency
Technical Training Organization
TTO
Po ng Pi ng
TNS
Po ng Pi ng
DMA
SRC addr DST addr
SOURCE DEST
Element 1 Element 2 Element 3
Frame 1 Frame 2 Frame 3
Element: basic unit of transfer (1, 2, or 4 bytes) Frame: a group of elements (up to 64K elements) Block: a group of frames (up to 64K frames)
Transfer dependent upon:
- Source/destination address
- Priority (rotating priority between channels, also Ch vs. CPU)
-
Event sync(20 different events can be selected for ‘C5510)
- Element/Frame count
O.VENARD - ESIEE/SIGTEL - 2007 41
DMA Channels 0 DMA Channels 0- -5 5
Source
Source DestinationDestination
ElemElemCountCount Frame CountFrame Count Elem
ElemIndexIndex Frame IndexFrame Index
Control
Control StatusStatus
EHPI
EHPI
AuxiliaryAuxiliary
ChannelChannel
Read
ReadBus
BusWrite
Write Bus
Bus16-
16-bit FIFO bit FIFO
32
32
32
32
Registres DMA
32 32 3232 32 32
1616
Peripherals
Peripherals DMADMA “ “ Ports”
Ports”
EMIF
EMIF SARAMSARAM
DARAMDARAM
EHPI
EHPI 1616
DMA Channels 0-5 have access to all ports except EHPI port
EHPI Auxiliary Channel has access to all ports except Peripherals port
Each CHx has: 2 32-bit buses (R/W) + 16-bit FIFO + 8 DMA regs shown
Technical Training Organization
TTO
Progammation « dynamique »
The user programs the “config registers”. When the DMA starts the transfer, it copies the config registers to the working registers:
Src Dest
Elem Ind Frame Ind Elem Cnt Frame Cnt
Config Registers
Src Dest
Elem Ind Frame Ind Elem Cnt Frame Cnt
Working Registers DMA_start()
Autoinit Copy
O.VENARD - ESIEE/SIGTEL - 2007 43
DMA throughput is affected by the combination of:
Ch
Ch- -3 3
Ch
Ch-2
-2
ChCh- -0 0 High
HighCh
Ch- -5 5
Ch-
Ch-4 4
ChCh- -1 1
Low
LowLow serviced when high:
- waiting for event sync - transfers are complete CPU has FIXED priority over the DMA
- Affects access to: EMIF, SARAM, DARAM
PRIO bits
: (DMA_CCRn:6) sets priority(hi/low) for DMA channel n
1122
DMA Throughput
DMA interrupt
• Interrupts can be generated from multiple events for each channel (DMA_CICR), all interrupts are Ored :
» Timeout : each resource access can be supervised thanks to a counter.
» Drop : Synchronisation not serviced.
» Half frame : At half of each frame.
» Frame : At the end of each frame.
» Last Frame : At the beginning of the last frame transfer.
» Block : At the end of the block transfer.
• Read DMA_CSR to determine source of interrupt
O.VENARD - ESIEE/SIGTEL - 2007 45
Fonctions CSL
Macros CSL
O.VENARD - ESIEE/SIGTEL - 2007 47
Synchronisation MCBSP-DMA
Architecture du traitement
•Déclaration et réservation buffers ping pong et mot d’état PingPong
•Configuration du port série McBSP2
•Configuration des canaux DMA 0 et 1
•Configuration interruption (DMA0)
•Création SWI pour traitement
•Déclaration fichier de commande d’éditeur de lien (.cmd) pour les buffers ping pong
Tâches à réaliser
O.VENARD - ESIEE/SIGTEL - 2007 49
Déclarations buffers
#define BUFFSIZE 20
…
Int16 RxBufferPing[BUFFSIZE];
…
Int16 RxBufferPong[BUFFSIZE];
…
Int16 TxBufferPing[BUFFSIZE];
…
Int16 TxBufferPong[BUFFSIZE];
#define PING 0
#define PONG 1 Int PingPong=PING;
main(){
memset((void *)RxBufferPing,0,BUFFSIZE*4);// string.h
}
…voir cmd à insérer pour l’édition de lien
Configuration McBSP2
Un événement pour chaque mot reçu
‘REVT2’
Un événement pour chaque mot
transmis ‘XEVT2’
O.VENARD - ESIEE/SIGTEL - 2007 51
Configuration canaux DMA
• Utilisation de l’interface graphique DSP-BIOS (possible avec CSL).
• Configuration canal DMA réception et canal DMA émission.
• Association des configurations avec des canaux physiques (0 et 1).
Canal de réception
McBSP2 DARAM
Adresse octet de DRR2
DARAM
O.VENARD - ESIEE/SIGTEL - 2007 53
…Canal de réception
Synchronisation avec Evt réception McBSP2
Création d’une interruption en fin de transfert de bloc (taille d’un buffer)
Canal de transmission
DARAM McBSP2
DARAM
Adresse octet de DXR2
McBSP2
O.VENARD - ESIEE/SIGTEL - 2007 55
Canal de transmission
Synchronisation avec EVT émission de McBSP2
Création d’une interruption en fin de transfert de bloc (taille d’un buffer)
Associations
réception
Canal DMA0
émission
Canal DMA1
O.VENARD - ESIEE/SIGTEL - 2007 57
Interruptions TMS320VC5510
Interruptions DMAC0
// Clear the DMA status registers to receive new interrupts DMA_RGETH(hDmaRx, DMACSR);
DMA_RGETH(hDmaTx, DMACSR);
// Clear any pending receive channel interrupts (IFR) IRQ_clear(IRQ_EVT_DMAC0);
IRQ_clear(IRQ_EVT_DMAC1);
// Enable receive DMA interrupt (IMR) IRQ_enable(IRQ_EVT_DMAC0);
// validation globale des interruptions IRQ_globalEnable();
// Start the DMA DMA_start(hDmaRx);
O.VENARD - ESIEE/SIGTEL - 2007 59
Traitement interruption DMAC0
void dmaRxHwi(void) {
SWI_post(&SWI_bufferProc);
if (PingPong==PING){
PingPong=PONG;
} else{
PingPong=PING;
}
// reset Flag pour autoriser les prochaines interruptions DMA_RGETH(hDmaRx,DMACSR);
}
Software interrupt traitement
void dmaRxHwi(void) {
SWI_post(&SWI_bufferProc);
…
}
Adresse fonction
O.VENARD - ESIEE/SIGTEL - 2007 61
Traitement software Int
void bufferProc(){
Uint32 addr;
// interruption software postée dans interruption hardware // est traitée à la fin de l'interruption hard
if (PingPong==PING){
// traitement buffer PONG
copyData(RxBufferPong,TxBufferPong,BUFFSIZE);
// Préparation DMA pour prochain transfert addr = ((Uint32)RxBufferPong) << 1;
DMA_RSETH(hDmaRx, DMACDSAL, addr & 0xffff);
DMA_RSETH(hDmaRx, DMACDSAU, (addr >> 16) & 0xffff);
addr = ((Uint32)TxBufferPong) << 1;
DMA_RSETH(hDmaTx, DMACSSAL, addr & 0xffff);
DMA_RSETH(hDmaTx, DMACSSAU, (addr >> 16) & 0xffff);
}
…
…
else{
// traitement buffer PING
copyData(RxBufferPing,TxBufferPing,BUFFSIZE);
// Préparation DMA pour prochain transfert addr = ((Uint32)RxBufferPing) << 1;
DMA_RSETH(hDmaRx, DMACDSAL, addr & 0xffff);
DMA_RSETH(hDmaRx, DMACDSAU, (addr >> 16) & 0xffff);
addr = ((Uint32)TxBufferPing) << 1;
DMA_RSETH(hDmaTx, DMACSSAL, addr & 0xffff);
DMA_RSETH(hDmaTx, DMACSSAU, (addr >> 16) & 0xffff);
} }
O.VENARD - ESIEE/SIGTEL - 2007 63
Utile
void copyData(Int16 *inbuf, Int16 *outbuf, Int16 length)
{
Int16 i = 0;
for (i = 0; i < length; i++) { outbuf[i] = inbuf[i];
} }
Buffers et édition de liens
#pragma DATA_SECTION(RxBufferPing,"DmaBuffer") Int16 RxBufferPing[BUFFSIZE];
#pragma DATA_SECTION(RxBufferPong,"DmaBuffer") Int16 RxBufferPong[BUFFSIZE];
#pragma DATA_SECTION(TxBufferPing,"DmaBuffer") Int16 TxBufferPing[BUFFSIZE];
#pragma DATA_SECTION(TxBufferPong,"DmaBuffer") Int16 TxBufferPong[BUFFSIZE];
SECTIONS{
DmaBuffer: > DARAM audioIO.cmd