(ang. FIR - Finite Impulse Response). Program p
Transkrypt
(ang. FIR - Finite Impulse Response). Program p
Ćwiczenie II (3) Filtracja FIR (SOI) Ćwiczenie II (3) Filtracja FIR (SOI) Wprowadzenie Ćwiczenie wyjaśnia szczegóły implementacji cyfrowego filtru SOI (ang. FIR - Finite Impulse Response). Program przeznaczony na symulator uczy: • Korzystania z przesłań równoległych do efektywnego programowania • Implementacji sprzętowych pętli DO, użycia instrukcji REP(powtórz) • Tworzenia i użycia buforów modulo (cyklicznych) • Użycia symulatora do wprowadzania danych z zewnętrznego źródła • Użycia podprogramów i łączenia kilku plików .asm razem Praca nad programem napisanym na moduł EVM ma na celu: • Wstępne zapoznanie się z przerwaniami, tzn. z ich źródłami, obsługą i synchronizacją z pracą rdzenia • Poznania przykładu komunikacji z urządzeniem zewnętrznym – CODEC za pomocą portu ESSI • Zapoznanie się z pisaniem i uruchomianiem programów na konkretnym sprzęcie na podstawie procedury filtracji cyfrowej Opis implementacji Kolejne rozdziały opisują różne cechy implementacji filtru FIR. Każda z nich opisywana jest aby umożliwić jej zrozumienie. Więcej szczegółów można znaleźć w podręczniku rodziny DSP56300. Sugerujemy aby w czasie czytania tego opisu mieć dostępną zawartość plików ex4_main.asm i ex4_fir.asm, ponieważ programy te ilustrują dyskutowany przykład. UWAGA!!! Zadanie do wykonania na symulatorze przeznaczone jest od zapoznania się i przećwiczenia w domu – na zajęciach będziemy zajmowali się głównie programem filtracji przeznaczonym na moduł EVM!!! W domu konieczne przeczytanie instrukcji – oraz zastanowienie się a najlepiej przygotowanie pliku do aplikacji w module EVM (oczywiście na zajęciach będziemy go dopracowywać). W sprawozdaniu należy zawrzeć odpowiedzi na wszelkie pytania i problemy zawarte w instrukcji najlepiej w formie „obrazkowo-opisowej”. Rozważania techniczne Filtry FIR. Wprowadzanie teorii przetwarzania sygnałów cyfrowych nie jest celem tego ćwiczenia, niemniej ważne jest rozumienie podstaw algorytmu który będzie implementowany. Z tego powodu zamieszczono poniżej krótki opis matematyczny filtrów FIR. Działanie filtru FIR opisane jest równaniem: y(n) x(n-k) = y(n) = = M ∑ b x(n − k ) k k =0 próbka wyjściowa próbka wejściowa opóźniona o k okresów próbkowania bk = współczynnik filtru Można to równanie rozszerzyć do postaci: y(n) = b0(n)+b1x(n-1)+b2x(n-2)+...+bMx(n-M) Ilustracja graficzna filtru FIR przedstawiona jest na rysunku poniżej: ... b0 x[n] b1 delay b2 delay b3 delay W przypadku kiedy w pętli ma być wykonywana tylko jedna instrukcja należy użyć instrukcji rep, wymagająca najmniej wysiłku, ponieważ wymaga podania tylko ilości obiegów pętli w formie stałej lub zmiennej przekazywanej za pomocą rejestru. UWAGA: Instrukcja dor jest użyta zamiast do. Oznacza ona wersję relatywnego (podanie adresu końca pętli relatywnie, względem licznika rozkazów) zamiast absolutnego adresu końca pętli. y[n] bM ... Definiowanie przestrzeni pamięci i stałych. W omawianym przykładzie przestrzenie pamięci i stałe definiowane są na różne sposoby. Podstawowa przestrzeń definiowana jest dyrektywą ds (define storage definiuj pamięć). Dyrektywa rezerwuje żądaną ilość słów pamięci i etykietuje je. Pamięć ta nie jest inicjowana żadną wartością. Zauważysz, że pomimo użycia dyrektywy org do określenia gdzie dane (przestrzeń X i Y) mają być umieszczone, adres pod którym mają być zachowane nie jest kontrolowany w tym miejscu. Czyni to tę sekcję programu relokowalną. Precyzyjne położenie bloków pamięci kontrolowane jest przez program łączący (linker). W pewnych okolicznościach istnieją ograniczenia położenia danych w pamięci. Bufory kołowe muszą dla przykładu zaczynać się na granicach modulo. Musi to być zasygnalizowane asemblerowi i programowi łączącemu, a można tego dokonać na kilka sposobów. W przypadku konieczności utworzenia bufora cyklicznego bez inicjacji jego zawartości może być użyta dyrektywa dsm (define storage modulo - definiuj pamięć modulo), jednak w tym przypadku nasz bufor kołowy musi zawierać wartości współczynników filtru, które podawane są dyrektywą dc (define constant - definiuj stałą). W celu sygnalizacji, że ten zbiór stałych musi być umieszczony w pamięci adekwatnej dla bufora „NUM_OF TAPS” (ilość współczynników), użyjemy komendy bufora. Sprzętowa pętla DO oraz instrukcja powtarzania REP. W przykładzie zademonstrowano kilka sposobów wykonywania pętli programu. Pierwszy przykład dotyczy wiecznej pętli do, która wykonuje to co sugeruje nazwa i kontynuuje to w nieskończoność. Wieczna pętla może być zatrzymana instrukcją (rozkazem) ENDDO, lub pułapką(ang. breakpoint) w programie. Drugi przykład jest najbardziej typowy: wykonaj #n razy. W tym przypadku, przy każdym wywołaniu pętli wykonywana jest ona stałą ilość razy. Ta ilość jest stałą częścią instrukcji. W trzecim przykładzie (w fir_filter) podprogram jest pętlą do xx. W takim przypadku ilość obiegów pętli nie jest znana w fazie asemblacji programu i niewątpliwie może być zmienna, a ilość jej przebiegów przekazywana jest poprzez rejestr. delay Rys. 30 Ogólna postać filtru FIR Bufory modulo. Przykład ten wykorzystuje bufory modulo (cykliczne) do przechowywania współczynników. Bufory te tworzone są za pośrednictwem rejestrów modyfikatorów (Mn). Rejestry te zmieniają sposób widzenia pamięci przez rejestry wskaźników (Rn). Wszelkie szczegóły działania rejestrów modyfikatorów można znaleźć w podręczniku rodziny 56300. Rejestry modyfikatorów po zerowaniu zawierają $FFFFFF, co znaczy, że wskaźniki widzą pamięć X i Y jako ciągły blok komórek. Zmiana wartości w którymś z rejestrów Mn powoduje zmianę „optyki” odpowiadającego rejestru wskaźnika Rn. Pokażemy teraz użycie rejestru modyfikatora na przykładzie: załóżmy, że nasz filtr ma 20 współczynników. Chcemy, aby wskaźnik adresu zawracał z powrotem do adresu początkowego po dojściu do końca listy współczynników. Aby to uzyskać, zmieniamy zawartość rejestru M4 z wartości początkowej $FFFFFF na Laboratorium przetwarzania sygnałów cyfrowych za pomocą procesorów sygnałowych Laboratorium przetwarzania sygnałów cyfrowych za pomocą procesorów sygnałowych Ćwiczenie II (3) Filtracja FIR (SOI) $000013 (19 dziesiętnie), co wymusza na wskaźniku R4 widzenie pamięci układu jak poniżej, tzn. podzielonej na oddzielne bloki cykliczne z natury, po 20 komórek każdy. $213 $200 Rys. 1 Bufor modulo 20. Pamięć danych X lub Y Kiedy R4 wskazuje komórki w jednym z tych bloków a potem jest modyfikowany do wartości normalnie wypadającej poza blokiem, wskaźnik R4 automatycznie jest zawijany. PRZYKŁAD 1 PRZYKŁAD 2 PZRYKŁAD 3 przed wykonaniem: R4=$203, M4=$13 przed wykonaniem: przed wykonaniem: R4=$213, M4=$13 R4=$210, N4=6, M4=$13 instrukcja: move y:(R4)+,Y0 instrukcja: move y:(R4)+,Y0 instrukcja: move y:(R4)+N4,Y0 po wykonaniu: R4=$204 po wykonaniu: R4=$200 po wykonaniu: R4=$203 UWAGA: Użycie buforów cyklicznych oznacza, że pamięć danych musi być umieszczona zgodnie z pewnymi zasadami. Po szczegóły dot. tych zasad zerknij do podręcznika rodziny 56300. Podłączanie plików wejściowych i wyjściowych. W celu sprawdzenia programów które napisałeś musisz wykonać testy z użyciem pewnych danych wejściowych. W prostych przypadkach można to rozwiązać poprzez ręczne wstawienie wartości do odpowiednich rejestrów i komórek pamięci przed uruchomieniem programu, a następnie sprawdzeniu wyników. jest to metoda używana w innych ćwiczeniach. W pewnych przypadkach, kiedy musimy sprawdzić fragment programu na dużej ilości danych, to znaczy wektorach testowych dostarczanych przez różnorakie standardy, ręczne wstawianie wartości byłoby niepraktyczne i męczące. Środowisko uruchomieniowe DSP56300 dostarcza metody podłączania plików pod pewne miejsca pamięci, nóżki wyprowadzeń lub porty aby mogły udawać peryferia z których dane wczytywane są z zewnętrznych źródeł do debugger’a. W naszym przypadku podłączymy zewnętrzne źródło do pamięci w górnym obszarze przestrzeni Y. Dla przesłań w tym obszarze możemy używać instrukcji movep mieszczącej się w jednym słowie, a mimo tego pozwalającej przesyłać komórki wysokiej pamięci Y do innego miejsca w pamięci (dzięki krótkiemu, 7bitowemu adresowi zewnętrznego układu peryferyjnego mapowanego w tenże obszar). Ćwiczenie II (3) Filtracja FIR (SOI) Wykonanie ćwiczenia I. Ćwiczenie w symulatorze do przećwiczenia przed zajęciami (!) I.1. Otwórz plik ex4_main.asm w edytorze tekstu. Plik zawiera punkt startu programu realizującego filtr FIR. W programie znajduje się odwołanie do podprogramu fir_filter. I.2. Otwórz plik ex4_fir.asm w edytorze tekstu. Plik ten zawiera podprogram implementujący cyfrową filtrację FIR(SOI). I.3. Wywołaj asemblację głównego pliku otwierając okienko DOS w stosownym katalogu zawierającym wspomniane pliki, komendą: asm56300 -b -l ex4_main.asm I.4. Spowoduje ona utworzenie dwóch nowych plików: ex4_main.cln, przekazywanego do programu łączącego (linker’a) i ex4_main.lst zawierającego tzw. listing generowany przez asembler. I.5. UWAGA: Jeśli są z tym problemy, sprawdź czy jest ustawiona ścieżka dostępu do katalogu zawierającego asembler. I.6. Wywołaj asemblację pliku podprogramu filtrującego komendą: asm56300 -b -l ex4_fir.asm I.7. Zostanie wygenerowane ostrzeżenie o przestoju potoku, znane nam z ćwiczenia 1. I.8. Otwórz plik ex4.ctl w edytorze tekstu. Jest to plik do którego będzie się odwoływał linker aby zadecydować gdzie zostaną umieszczone sekcje programu w pamięci. I.9. Wywołaj linker aby połączyć te pliki razem w tak zwany absolutny plik obiektowy, który można załadować w symulatorze. Dokonaj tego poleceniem: dsplnk -mex4.map -bex4.cld -rex4.ctl ex4_main.cln ex4_fir.cln Oznacza to, że ex4_main.cln i ex4_fir.cln zostaną połączone razem poleceniami zawartymi w ex4.ctl. Rezultatem będzie kod maszynowy o nazwie ex4.cld i plik ex4.map mapujący wskazujący umiejscowienie sekcji programu w pamięci.Uruchom symulator. Jeżeli jest już uruchomiony wyzeruj procesor (czerwony przycisk RESET). I.10. Załaduj program ex4.cld (MENU: File, Load, Memory COFF). Wcześniej możesz ustawić ścieżkę dostępu do katalogu w którym znajduje się program ex4.cld. I.11. Jeśli nie są otwarte, otwórz okienka Sesji(Session), Komend(Command) i Asemblera(Assembly). Okienko sesji pokaże stan procesora po każdym kroku. Okienko komend pozwoli na ręczne (z klawiatury) zadawanie komend lub pokaże komendy zadane za pomocą paska menu. Okienko asemblera pokaże program (pamięć programu) i wskaże kolejną instrukcję do wykonania. I.12. Podłącz adres y:$FFFFEE do pliku wejściowego ip_data.io (MENU: File, Input, Open). Numer wejścia 1, wejście z pliku, plik podłączony jest do pamięci (przestrzeń Y, adres $FFFFEE), radix jest heksadecymalny, a nazwa pliku to ip_data.io. I.13. Podłącz adres y:$FFFFEF do pliku wyjściowego op_data.io (MENU: File, Output, Open). Numer wyjścia 1, wejście z pamięci do pliku, radix jest heksadecymalny, a nazwa pliku to op_data.io (jeśli narzędzie zgłasza istnienie pliku, zarządź nadpisanie [overwrite]). I.14. Załóż warunkową pułapkę w pliku. Chcemy sobie radzić z dowolną długością pliku wejściowego. Narzędzie może automatycznie wykrywać koniec pliku, a powinniśmy z tego skorzystać. Przy pierwszej próbie czytania wartości której tam nie ma nastąpi przerwa. (MENU: Execute, Breakpoints, Set). Numer pułapki 1, typ = wyrażenie, akcja = zatrzymanie (halt), wyrażeniem jest eof (end of file). I.15. Uruchom symulację(zielone światło). Zatrzyma się niezwłocznie po przefiltrowaniu zawartości pliku wejściowego. Nie zdziw się, jeśli potrwa to kilka minut ! Symulacja każdej instrukcji procesora sygnałowego wymaga masy czynności, dlatego trwa to znacznie dłużej niż wykonanie przez procesor sygnałowy. Po zakończeniu obliczeń zamknij plik wyjściowy (MENU: File, Output, Close). I.16. W celu upewnienia się, że funkcja zadziała poprawnie, porównaj op_data.io z op_ref.io ... powinny być identyczne. UWAGA: Opis korzystania z plików wejścia i wyjścia dotyczy wyłącznie symulatora. Plik wejściowy powinien mieć format ASCII. Po szczegóły należy odwołać się do mechanizmu pomocy symulatora. W omawianym ćwiczeniu używamy pliku ip_data.io w formacie heksadecymalnym ASCII. Opis czynności podłączania pliku pod komórki pamięci znajduje się w sekcji poniżej. Laboratorium przetwarzania sygnałów cyfrowych za pomocą procesorów sygnałowych Laboratorium przetwarzania sygnałów cyfrowych za pomocą procesorów sygnałowych Ćwiczenie II (3) Filtracja FIR (SOI) II. Ćwiczenie z użyciem modułu DSP56311EVM. II.1. Otwórz Debugger 56300 i załaduj do niego program pass.cld, który mam za zadanie odczytać oba kanały audio z portu z CODEC’a przez port ESSI * do akumulatorów wykorzystując przerwania ** oraz również za pomocą przerwań i portu ESSI wysłać na CODEC’a – tzn. program ma być przezroczysty dla dźwięku – przed przystąpieniem do dalszej części ćwiczenia należy sprawdzić działanie programu, tzn. • Podłącz na wejście audio modułu DSP56311EVM źródło dźwięku (wyjście karty dźwiękowej lub odtwarzacza CD audio). • Załaduj i uruchom program pass.cld, włącz źródło muzyki. II.2. Zobacz jak wyglądają zaprojektowane w Matlab-ie pliki współczynników filtrów SOI (zapisane do pliku coeff.asm za pomocą skryptu savecoeff.m- w domu możesz zaprojektować i wygenerować własne pliki dla różnych filtrów - zalecane) II.3. Wykorzystaj załączony plik pass.asm, który sprawdzałeś w pierwszym punkcie i otwórz do edycji. Zwróć szczególną uwagę na miejsce gdzie procesor czeka, aż pojawi się nowa dana (instrukcje jset i jclr – sprawdź w manualu ich działanie) – jak i po co jest to wykonywane – sprawdź co jest sprawdzane w tych instrukcjach - klucz w notce dot. Portu ESSI * II.4. Zwróć uwagę na program vectors.asm – zastanów się co on zawiera? Zwróć szczególną uwagę na miejsca gdzie jest coś innego niż „jmp *” i ”nop” ** II.5. Dołącz w odpowiednim miejscu plik ze współczynnikami pamiętając o dyrektywie org x:$***** (lub org y:$******) jeśli dalej pisany jest program to sprawdź czy jest dyrektywa typu org p:$***** wyjaśnij dlaczego jest potrzebna. II.6. Wklej w odpowiednim miejscu w programie instrukcje filtracji (inicjalizacja buforów, instrukcje splotu osobno dla obu kanałów) *** II.7. Wywołaj asemblację, a następnie załaduj do Debugger’a 56300. II.8. Podłącz na wejście audio modułu DSP56311EVM źródło dźwięku (wyjście karty dźwiękowej lub odtwarzacza CD audio). II.9. Załaduj i uruchom program filtrujący, włącz źródło muzyki. Jeśli wszystko zrobiłeś dobrze usłyszysz efekt swojej pracy, jeśli nie – zastanów się gdzie popełniłeś błąd i spróbuj go naprawić. * Port ESSI opisany jest DSP 56311 User Manual (mam nadzieje ze do tej pory był omówiony na wykładzie, ale jeśli nie to nie ma to kluczowego zanczenia) – bardzo szeroki opis dla zainteresowanych, a poniżej w dodatku opis przerwań (tzw. exceptions) i rejestru statusowego SSISR ** Źródła i sposób obsługi przerwań opisany w dodatku (notka po angielsku) *** Program splotu został wykorzystany w ćwiczeniu na symulatorze – zalecane jest użycie wersji nieco innej zawartej w dalszej części instrukcji, proszę się zastanowić w domu jak to wszystko działa - wyjaśnione dokładnie w dodatku „A. FIR Implementation on the DSP56300”. Aby uprościć zagadnienie zaleca się użyć dwykrotnie pętli REP jak w w/w dodatku osobno dla obydwu kanałów (zamiast efektywniejszej ale mniej przejrzystej pętli DO) Laboratorium przetwarzania sygnałów cyfrowych za pomocą procesorów sygnałowych 3. Hardware DO loops execute without overhead once the loop is started. After a three-cycle initialization of the DO loop, the body of the loop executes as if it were straight-line code. Since the DO loop does not require any overhead cycles for each pass, the need for straight-line code is eliminated. A. FIR Implementation on the DSP56300 The DSP56300 has several architectural features that make it ideally suited for implementing FIR filters: 1. Dual Harvard architecture uses two data memories with dedicated buses and address generation units, allowing two addresses to be generated in a single cycle. If one address is pointing to data and another address is pointing to coefficients, a word of data and a coefficient can be fetched in a single cycle. 2. Modulo addressing makes the shifting of data unnecessary. If an address pointer is incremented (or decremented) with the modulo modifier in effect, data shifting can be accomplished by just “backing up” the address register by one to overwrite the data that would normally be shifted out. This procedure allows very efficient addressing of operands without wasting time shifting the data or reinitializing pointers. For a four-coefficient example of a linear-phase FIR filter, the input-output difference equation can be found by expanding Eqn. 7-16: y(n) = h0x(n) + h1x(n-1) + h2x(n-2) + h3x(n-3) Eqn. 7-46 This difference equation can be realized with the discrete-time four-tap filter example shown in Figure 7-41. The filter can be efficiently implemented on the DSP56300 by using modulo addressing to implement the shifting and parallel data moves to load the multiplier-accumulator. The filter network is shown in Figure 7-41(a); the memory map for the filter inputs and coefficients is shown in Figure 7-41(b). The following DSP56001 code is used to implement the direct form FIR filter: CLR REP MAC MACR A X0,X:(R0)+ #NTAPS-1 X0,Y0,A X:(R0)+,X 0 X0,Y0,A (R0)- Y:(R4)+,Y0 ;Save input sample, fetch coef. ;Repeat next instruction. Y:(R4)+,Y0 ;FIR Filters. ;Round result and adjust R0. Register R0 points to the input variable buffer, M0 is set to three (modulo 4), R4 points to the coefficient buffer, and M4 is set to three. The input sample is in X0. 7-30 MOTOROLA MOTOROLA 7-31 The CLR instruction clears accumulator A and performs parallel data moves. The data move saves the most recent input value to the filter (assumed to be in XO) into the location occupied by the oldest data in the shift register and moves the first coefficient in the filter (h0) into the data ALU. The MAC instruction multiplies the data in X0 by the coefficient in Y0 and adds the result to accumulator A in a single cycle. The data move in this instruction loads the next input data variable into X0 and the next coefficient into Y0. Both address registers R0 and R4 are incremented. The MACR instruction calculates the final tap of the filter, rounds the result using convergent rounding, and address register R0 is decremented. The REP instruction repeats the next instruction NTAPS-1 times. Since there are four taps in this filter, the next instruction is repeated three times. x(n) z-1 z-1 z-1 Address register R4 is incremented once before the REP instruction and three times due to the REP instruction for a total of four increments. Since the modulus for R4 is four, the value of R4 wraps around pointing back to the first coefficient. y(n) + b3 b0 b2 b1 + The operation of RO is similar. The value input to the filter is saved, and then RO is incremented pointing to the first state. The REP instruction increments RO three times. Since the modulo on RO is four and RO is incremented four times, the value in RO wraps around pointing to the new input sample. When the MACR instruction is executed, the value of RO is decremented, pointing to the old value, x(n3). The next sample time overwrites the value of x(n-3) with the new input sample, x(n). Thus, the shifting of the input data is accomplished by simply adjusting the address pointer, and the modular addressing wraps the pointer around at the ends of the input data buffer. Instruction cycle counts for this filter are NTAPS+3. Thus, for a four-tap filter, seven ■ instructions are required. + (a) Direct-Form FIR Filter Network with Four Coefficients Y:(R4) X:(R0) x(n) R0 x(n-1) M0 =ntaps-1 =3 Input Data b(0) R0 M4 =ntaps-1 =3 b(1) x(n-2) b(2) x(n-3) b(3) x(n) b(4) Filter Coefficients (b) Data Structures for Four-Tap FIR Example Figure 7-42 FIR Filter Example 7-32 MOTOROLA 7-33 MOTOROLA Program Control Unit Processing States 5.4.4.2 Loop Address (LA) Register 2.3 Processing States The contents of the 24-bit Loop Address (LA) register indicate the location of the last instruction word in a hardware loop. This register is stacked into the SSH by a DO instruction and is unstacked either by end-of-loop processing or by execution of ENDDO and BRKcc instructions. The LA register, a read/write register, is written by a DO instruction and read by the System Stack when the register is stacked. The following paragraphs describe the DSP56300 core processing states. 5.4.4.3 Loop Counter (LC) Register The Loop Counter (LC) register is a special read/write 24-bit counter that specifies the number of times a hardware program loop repeats, in the range of 0 to (224 – 1). This register is stacked into the SSL by a DO instruction and unstacked by end-of-loop processing or by execution of ENDDO and BRKcc instructions. The LC is also used in the REP instruction to specify how many times to repeat the repeated instruction. 5.4.4.4 Vector Base Address (VBA) Register The Vector Base Address Register (VBA) is a 24-bit register. Eight of the bits VBA[7–0] are read-only and always cleared. The VBA is used as a base address of the interrupt vector table (discussed in Chapter 2, Core Architecture Overview). When a fast or long interrupt executes, VBA[7– 0] are driven from the program interrupt control unit, and bits 23–8 are driven from the VBA. The VBA Register is a read/write register that is referenced implicitly by interrupt processing or directly by the MOVEC instruction. The VBA is cleared during hardware reset. 2.3.1 Normal Processing State The Normal processing state is associated with instruction execution. DSP56300 core instructions execute in a seven-stage pipeline, typically at a rate of one instruction every clock cycle. However, the following instructions require additional time to execute: ■ All double-word instructions ■ Instructions with an addressing mode that requires more than one cycle for the address calculation ■ Instructions causing a change of flow Instruction pipelining allows overlapping of instruction execution so that a pipeline stage of a given instruction occurs concurrently with pipeline stages of other instructions. Only one word is fetched per cycle, so for double-word instructions, the second word of an instruction is fetched before the next instruction is fetched. Table 2-1 describes the seven stages of the DSP56300 core pipeline. The first and second instructions in Table 2-1 are referred to as n1 and n2. The third instruction, n3, which contains an instruction extension word, n3e, takes two clock cycles to execute. The extension word is either an absolute address or immediate data. Although it takes seven clock cycles for the pipeline to fill and the first instruction to execute, a further instruction usually completes on each clock cycle. Table 2-1. Instruction Pipeline Instruction Cycle Operation Fetch 1 Fetch 2 Decode Address Gen 1 1 2 3 4 5 6 7 8 9 10 11 n1 n2 n3 n1 n2 n3e n4 n5 n6 n7 n8 n9 n10 n3 n3e n4 n5 n6 n7 n8 n9 n1 n2 n3 n3e n4 n5 n6 n7 n8 n1 n2 n3 n3e n4 n5 n6 n7 n1 n2 n3 n3e n4 n5 n6 n1 n2 n3 n3e n4 n5 n1 n2 n3 n3e n4 Address Gen 2 Execute 1 Execute 2 n1 = first instruction; n2 = second instruction; and so forth n3e = instruction extension word 5-24 DSP56300 Family Manual Core Architecture Overview 2-5 Core Architecture Overview Processing States Each instruction requires a minimum of seven clock cycles to fetch, decode, and execute. This results in a delay of seven clock cycles from power-up to fill the pipeline. A new instruction may begin immediately following the previous instruction. Two-word instructions require a minimum of eight clock cycles to execute (seven cycles for the first instruction word to move through the pipe and execute and one more cycle for the second word to execute). For a complete description of the execution timing of the various instructions, see Appendix A, Instruction Timing and Restrictions. 2.3.2 Exception Processing State (Interrupt Processing) The Exception Processing state is associated with interrupts that are generated by conditions inside the DSP or by external sources. There are many sources for interrupts to the DSP56300 core, some generating more than one interrupt. An interrupt vector scheme with 128 vectors of defined priority provides fast interrupt service. Interrupt processing in the DSP56300 core proceeds as follows: 1. A hardware interrupt is synchronized with the DSP56300 core clock, and the interrupt pending flag for that particular hardware interrupt is set. An interrupt source can have only one interrupt pending at any given time. 2. All pending interrupts (external and internal) are arbitrated to select the interrupt to be processed. The arbiter automatically ignores any interrupts with an Interrupt Priority Level (IPL) lower than the interrupt mask level in the SR and selects the remaining interrupt with the highest IPL. Exceptions can be generated from one of two groups, core and peripherals, and can originate from any of the 128 vector locations listed in Table 2-2. The table lists only the sources originating from the core. For sources originating from peripherals, see the device-specific user’s manual. Table 2-2 shows the corresponding interrupt starting address for each interrupt source. These addresses reside in the 256 locations of program memory to which the Vector Base Address Register (VBA) in the PCU points. When an interrupt is serviced, the instruction at the interrupt starting address is fetched first. Because the program flow is directed to a different starting address for each interrupt, the interrupt structure of the DSP56300 core is said to be vectored. A vectored interrupt structure has low overhead execution. If certain interrupts will definitely not be used, their vector locations can be used for program or data storage. Table 2-2. Interrupt Sources Interrupt Starting Address Interrupt Priority Level (IPL) Interrupt Source VBA:$00 3 Hardware RESET VBA:$02 3 Stack Error 3. The interrupt controller freezes the Program Counter (PC) and fetches two instructions at the two interrupt vector addresses associated with the selected interrupt. VBA:$04 3 Illegal Instruction VBA:$06 3 Debug Request Interrupt VBA:$08 3 Trap 4. The interrupt controller inserts the two instructions into the instruction stream and releases the PC, which is used for the next instruction fetch. The next interrupt arbitration then begins. VBA:$0A 3 Non-Maskable Interrupt (NMI) VBA:$0C 3 Reserved for Future Level—3 Interrupt Source VBA:$0E 3 VBA:$10 0–2 IRQA VBA:$12 0–2 IRQB VBA:$14 0–2 IRQC VBA:$16 0–2 IRQD VBA:$18 0–2 DMA Channel 0 VBA:$1A 0–2 DMA Channel 1 VBA:$1C 0–2 DMA Channel 2 VBA:$1E 0–2 DMA Channel 3 VBA:$20 0–2 DMA Channel 4 VBA:$22 0–2 DMA Channel 5 When a fast interrupt executes, the state of the machine is not saved on the stack if neither of the two instructions is a Jump To Subroutine (JSR) instruction (for example, a JSCLR). A long interrupt executes if one of the interrupt instructions fetched is a JSR instruction. The PC is immediately released, the SR and the PC are saved in the stack, and the jump instruction controls from where the next instruction is fetched. Note: Any Jump to Subroutine (JSR) instruction makes the interrupt long (for example, JScc, BSSET, and so on.). One of the main uses of interrupts is to transfer data between DSP memory or registers and a peripheral device. When such an interrupt occurs, a limited context switch with 2-6 minimum overhead is often desirable. This limited context switch is accomplished by a fast interrupt. The long interrupt is used when a more complex task must be accomplished to service the interrupt. DSP56300 Family Manual Reserved for Future Level—3 Interrupt Source Core Architecture Overview 2-7 Core Architecture Overview Processing States Table 2-2. Interrupt Sources (Continued) Interrupt Starting Address Interrupt Priority Level (IPL) VBA:$24 0–2 Peripheral interrupt request 1 VBA:$26 0–2 Peripheral interrupt request 2 : : VBA:$FE 0–2 Interrupt Source When the IRQA, IRQB, IRQC, and IRQD interrupts are disabled in the interrupt priority register, the pending request is ignored, regardless of whether the interrupt input was defined as level-sensitive or edge-triggered. Additionally, as long as an interrupt (edge or level sensitive) is disabled, its detection latch remains in the Reset state. If the level-sensitive interrupt is disabled while the interrupt is pending, the pending interrupt is cancelled. However, if the interrupt has been fetched, it is not cancelled. Note: Peripheral interrupt request 110 The 128 interrupts are prioritized into four levels. Level 3, the highest priority level, is not maskable. Levels 0–2 are maskable. The interrupts within each level are prioritized. 2.3.2.1 Hardware Interrupt Source 2.3.2.2 Software Interrupt Sources There are two software interrupt sources: ■ Illegal Instruction Interrupt (III): A Non-Maskable Interrupt (IPL 3) that is serviced immediately after the illegal instruction executes or attempts to execute (any undefined operation code) ■ TRAP: A Non-Maskable Interrupt (IPL 3) that is serviced immediately after the TRAP or TRAPcc instruction executes (condition true) Two types of hardware interrupts to the DSP56300 core exist: internal and external. The internal interrupts come from on-chip sources: ■ Stack Error ■ Illegal Instruction ■ Debug Request 2.3.2.3 Interrupt Priority Structure ■ Trap ■ DMAs ■ Peripherals Four Interrupt Priority Levels (IPLs) exist. IPLs are numbered from 0 (the lowest level) to 3 (the highest level). IPLs 0, 1, and 2 are maskable. Level 3 is non-maskable. The IPL 3 interrupts are: Each internal interrupt source is serviced if it is not masked. When serviced, the interrupt request is cleared. Each maskable, internal interrupt source has independent enable control. The external hardware interrupts are: NMI, IRQA, IRQB, IRQC, and IRQD. The NMI interrupt is an edge-triggered, Non-Maskable Interrupt (NMI) for use in software development, watch-dog, power fail detect, and so on. The IRQA, IRQB, IRQC, and IRQD interrupts can be programmed to be level-sensitive or edge-triggered. Since the level-sensitive interrupts are not automatically cleared when they are serviced, they must be cleared by other means before the end of the interrupt routine because multiple interrupts must be prevented. Usually, external hardware detects the interrupt acknowledge of the core interrupt and removes the interrupt request source. The edge-triggered interrupts are latched as pending on the high-to-low transition of the interrupt input and are automatically cleared when the interrupt is serviced. IRQA, IRQB, IRQC, and IRQD can be programmed to one of three priority levels: 0, 1, or 2, all of which are maskable. Additionally, these interrupts have independent enable control. 2-8 On all external, level-sensitive interrupt sources, the interrupt should be serviced (that is, the interrupt source cleared) by the instructions at the interrupt vector for a fast interrupt, or by a long interrupt routine. DSP56300 Family Manual ■ Hardware Reset ■ Illegal Instruction Interrupt (III) ■ Stack Error ■ TRAP ■ NMI ■ Debug The interrupt mask bits (I1, I0) in the SR reflect the current processor priority level and indicate the IPL needed for an interrupt source to interrupt the processor (see Table 2-3). Interrupts are inhibited for all priority levels less than the current processor priority level. However, level 3 interrupts are not maskable and therefore can always interrupt the processor. Core Architecture Overview 2-9 Interrupt Sources and Priorities Interrupt Sources and Priorities Table 4-2. Interrupt Sources (Continued) 4.3.1 Interrupt Sources Each interrupt is allocated two instructions in the table, resulting in 128 table entries for interrupt handling. Table 4-2 shows the table entry address for each interrupt source. The DSP56311 initialization program loads the table entry for each interrupt serviced with two interrupt servicing instructions. In the DSP56311, only some of the 128 vector addresses are used for specific interrupt sources. The remaining interrupt vectors are reserved and can be used for host NMI (IPL = 3) or for host command interrupt (IPL = 2). Unused interrupt vector locations can be used for program or data storage. Interrupt Starting Address Interrupt Priority Level Range VBA:$32 0–2 VBA:$34 0–2 ESSI0 receive last slot VBA:$36 0–2 ESSI0 transmit data Table 4-2. Interrupt Sources Interrupt Starting Address Interrupt Priority Level Range Interrupt Source VBA:$00 3 Hardware RESET VBA:$02 3 Stack error VBA:$04 3 Illegal instruction VBA:$06 3 Debug request interrupt VBA:$08 3 Trap VBA:$0A 3 Nonmaskable interrupt (NMI) VBA:$0C 3 Reserved VBA:$0E 3 Reserved VBA:$10 0–2 IRQA VBA:$12 0–2 IRQB VBA:$14 0–2 IRQC VBA:$16 0–2 IRQD VBA:$18 0–2 DMA channel 0 VBA:$1A 0–2 DMA channel 1 VBA:$1C 0–2 DMA channel 2 VBA:$1E 0–2 DMA channel 3 VBA:$20 0–2 DMA channel 4 VBA:$22 0–2 DMA channel 5 VBA:$24 0–2 TIMER 0 compare VBA:$26 0–2 TIMER 0 overflow VBA:$28 0–2 TIMER 1 compare VBA:$2A 0–2 TIMER 1 overflow VBA:$2C 0–2 TIMER 2 compare VBA:$2E 0–2 TIMER 2 overflow VBA:$30 0–2 ESSI0 receive data Motorola Core Configuration 4-5 4-6 Interrupt Source ESSI0 receive data with exception status VBA:$38 0–2 ESSI0 transmit data with exception status VBA:$3A 0–2 ESSI0 transmit last slot VBA:$3C 0–2 Reserved VBA:$3E 0–2 Reserved VBA:$40 0–2 ESSI1 receive data VBA:$42 0–2 ESSI1 receive data with exception status VBA:$44 0–2 ESSI1 receive last slot VBA:$46 0–2 ESSI1 transmit data VBA:$48 0–2 ESSI1 transmit data with exception status VBA:$4A 0–2 ESSI1 transmit last slot VBA:$4C 0–2 Reserved VBA:$4E 0–2 Reserved VBA:$50 0–2 SCI receive data VBA:$52 0–2 SCI receive data with exception status VBA:$54 0–2 SCI transmit data VBA:$56 0–2 SCI idle line VBA:$58 0–2 SCI timer VBA:$5A 0–2 Reserved VBA:$5C 0–2 Reserved VBA:$5E 0–2 Reserved VBA:$60 0–2 Host receive data full VBA:$62 0–2 Host transmit data empty VBA:$64 0–2 Host command (default) VBA:$66 0–2 Reserved VBA:$68 0-2 EFCOP data input buffer empty VBA:$6A 0-2 EFCOP data output buffer full VBA:$6C 0-2 Reserved VBA:$6E 0-2 : : VBA:$FE 0–2 Reserved : Reserved DSP56311 User’s Manual Motorola Interrupt Sources and Priorities Interrupt Sources and Priorities 4.3.2 Interrupt Priority Levels . Table 4-3. Interrupt Priority Level Bits IPL bits There are two interrupt priority registers in the DSP56311. The IPR–C (Figure 4-1) is dedicated to DSP56300 core interrupt sources, and IPR–P (Figure 4-2) is dedicated to DSP56311 peripheral interrupt sources. 23 22 21 20 19 18 17 D5L1 D5L0 D4L1 D4L0 D3L1 D3L0 D2L1 16 15 D2L0 D1L1 14 13 12 D1L0 D0L1 D0L0 Interrupts Enabled Interrupts Masked Interrupt Priority Level 0 No — 0 1 Yes 0 1 1 0 Yes 0, 1 2 1 1 Yes 0, 1, 2 3 xxL1 xxL0 0 0 DMA0 IPL DMA1 IPL DMA2 IPL DMA3 IPL DMA4 IPL 4.3.3 Interrupt Source Priorities Within an IPL DMA5 IPL 11 10 9 8 7 6 5 IDL2 IDL1 IDL0 ICL2 ICL1 ICL0 IBL2 4 3 IBL1 IBL0 2 1 0 IAL2 IAL1 IAL0 If more than one interrupt request is pending when an instruction executes, the interrupt source with the highest IPL is serviced first. When several interrupt requests with the same IPL are pending, another fixed-priority structure within that IPL determines which interrupt source is serviced first. Table 4-4 shows this fixed-priority list of interrupt sources within an IPL, from highest to lowest at each level The interrupt mask bits in the Status Register (I[1:0]) can be programmed to ignore low priority level interrupt requests. IRQA IPL IRQA mode IRQB IPL IRQB mode IRQC IPL IRQC mode IRQD IPL IRQD mode Table 4-4. Interrupt Source Priorities Within an IPL Priority Figure 4-1. Interrupt Priority Register C (IPR-C) (X:$FFFFFF) Interrupt Source Level 3 (nonmaskable) Highest 23 22 21 20 19 18 17 16 15 14 13 Hardware RESET Stack error 12 Illegal instruction Debug request interrupt reserved 11 FCL1 10 FCL0 9 8 T0L1 T0L0 7 6 5 SCL1 SCL0 S1L1 4 S1L0 3 2 S0L1 S0L0 1 Trap 0 Lowest Nonmaskable interrupt Highest IRQA (external interrupt) Levels 0, 1, 2 (maskable) HPL1 HPL0 HI08 IPL ESSI0 IPL IRQB (external interrupt) ESSI1 IPL IRQC (external interrupt) SCI IPL TRIPLE TIMER IPL IRQD (external interrupt) EFCOP IPL DMA channel 0 interrupt DMA channel 1 interrupt Figure 4-2. Interrupt Priority Register P (IPR-P) (X:$FFFFFE) DMA channel 2 interrupt DMA channel 3 interrupt DMA channel 4 interrupt Motorola Core Configuration 4-7 4-8 DSP56311 User’s Manual Motorola Interrupt Sources and Priorities Table 4-4. Interrupt Source Priorities Within an IPL (Continued) Priority Operation 7.3.3 ESSI Exceptions The ESSI can generate six different exceptions. They are discussed in the following paragraphs (ordered from the highest to the lowest exception priority): Interrupt Source DMA channel 5 interrupt Highest Host command interrupt ■ ESSI receive data with exception status: Occurs when the receive exception interrupt is enabled, the receive data register is full, and a receiver overrun error has occurred. This exception sets the ROE bit. The ROE bit is cleared when you first read the SSISR and then read the Receive Data Register (RX). ■ ESSI receive data: Occurs when the receive interrupt is enabled, the receive data register is full, and no receive error conditions exist. A read of RX clears the pending interrupt. This error-free interrupt can use a fast interrupt service routine for minimum overhead. ■ ESSI receive last slot interrupt: Occurs when the ESSI is in Network mode and the last slot of the frame has ended. This interrupt is generated regardless of the receive mask register setting. The receive last slot interrupt can signal that the receive mask slot register can be reset, the DMA channels can be reconfigured, and data memory pointers can be reassigned. Using the receive last slot interrupt guarantees that the previous frame is serviced with the previous setting and the new frame is serviced with the new setting without synchronization problems. Host transmit data empty Host receive data full ESSI0 RX data with exception interrupt ESSI0 RX data interrupt ESSI0 receive last slot interrupt ESSI0 TX data with exception interrupt ESSI0 transmit last slot interrupt ESSI0 TX data interrupt ESSI1 RX data with exception interrupt ESSI1 RX data interrupt ESSI1 receive last slot interrupt ESSI1 TX data with exception interrupt ESSI1 transmit last slot interrupt ESSI1 TX data interrupt SCI receive data with exception interrupt SCI receive data Note: SCI transmit data SCI idle line SCI timer TIMER0 overflow interrupt ■ ESSI transmit data with exception status: Occurs when the transmit exception interrupt is enabled, at least one transmit data register of the enabled transmitters is empty, and a transmitter underrun error has occurred. This exception sets the TUE bit. The TUE bit is cleared when you first read the SSISR and then write to all the transmit data registers of the enabled transmitters, or when you write to TSR to clear the pending interrupt. ■ ESSI transmit last slot interrupt: Occurs when the ESSI is in Network mode at the start of the last slot of the frame. This exception occurs regardless of the transmit mask register setting. The transmit last slot interrupt can signal that the transmit mask slot register can be reset, the DMA channels can be reconfigured, and data memory pointers can be reassigned. Using the Transmit Last Slot interrupt guarantees that the previous frame is serviced with the previous frame settings and the new frame is serviced with the new frame settings without synchronization problems. TIMER0 compare interrupt TIMER1 overflow interrupt TIMER1 compare interrupt TIMER2 overflow interrupt TIMER2 compare interrupt EFCOP data input buffer empty Lowest Motorola EFCOP data output buffer full Core Configuration 4-9 7-8 The maximum time it takes to service a receive last slot interrupt should not exceed N – 1 ESSI bits service time (where N is the number of bits the ESSI can transmit per time slot). DSP56311 User’s Manual Motorola Operation Note: ■ ESSI Programming Model 7.5.3 ESSI Status Register (SSISR) The maximum transmit last slot interrupt service time should not exceed N – 1 ESSI bits service time (where N is the number of bits in a slot). ESSI transmit data: Occurs when the transmit interrupt is enabled, at least one of the enabled transmit data registers is empty, and no transmitter error conditions exist. Write to all the enabled TX registers or to the TSR to clear this interrupt. This error-free interrupt uses a fast interrupt service routine for minimum overhead (if no more than two transmitters are used). The SSISR is a 24-bit read-only status register by which the DSP reads the ESSI status and serial input flags. 23 22 21 20 11 10 9 8 To configure an ESSI exception, perform the following steps: 15 14 13 12 7 6 5 4 3 2 1 0 RDF TDE ROE TUE RFS TFS IF1 IF0 Table 7-5. ESSI Status Register (SSISR) Bit Definitions Bit Number Bit Name Reset Value 0 Reserved. Set to 0 for future compatibility. 7 RDF 0 Receive Data Register Full Set when the contents of the receive shift register transfer to the receive data register. RDF is cleared when the DSP reads the receive data register. If RIE is set, a DSP receive data interrupt request is issued when RDF is set. 6 TDE 0 Transmit Data Register Empty Set when the contents of the transmit data register of every enabled transmitter are transferred to the transmit shift register. It is also set for a TSR disabled time slot period in Network mode (as if data were being transmitted after the TSR has been written). When TDE is set, TDE data is written to all the TX registers of the enabled transmitters or to the TSR. The TDE bit is cleared when the DSP writes to all the transmit data registers of the enabled transmitters, or when the DSP writes to the TSR to disable transmission of the next time slot. If the TIE bit is set, a DSP transmit data interrupt request is issued when TDE is set. 5 ROE 0 Receiver Overrun Error Flag Set when the serial receive shift register is filled and ready to transfer to the receive data register (RX) but RX is already full (that is, the RDF bit is set). If the REIE bit is set, a DSP receiver overrun error interrupt request is issued when the ROE bit is set. The programmer clears ROE by reading the SSISR with the ROE bit set and then reading the RX. 23 – 8 a. Enable and prioritize overall peripheral interrupt functionality. IPRP (S0L1:0) Note: 16 Figure 7-11. ESSI Status Register (SSISR) 2. Configure interrupt trigger; preload transmit data Write data to all enabled transmit registers. Enable a peripheral interrupt-generating function. Enable a specific peripheral interrupt. Enable peripheral and associated signals. Unmask interrupts at the global level. 17 VBA (b23:8) b. Define I_VEC to be equal to the VBA value (if that is nonzero). If it is defined, I_VEC must be defined for the assembler before the interrupt equate file is included. c. Load the exception vector table entry: two-word fast interrupt, or jump/branch to subroutine (long interrupt). p:I_SI0TD b. c. d. e. f. 18 (ESSI0 X:$FFFFB7, ESSI1 X:$FFFFA7) 1. Configure the interrupt service routine (ISR): a. Load vector base address register 19 TX00 CRB (TE0) CRB0 (TIE) PCRC (PC[5 – 0]) SR (I1 – 0) The example material to the right of the steps shows register settings for configuring an ESSI0 transmit interrupt using transmitter 0. The order of the steps is optional except that the interrupt trigger configuration must not be completed until the ISR configuration is complete. Since step c may cause an immediate transmit without generating an interrupt, perform the transmit data preload in step b before step c to ensure that valid data is sent in the first transmission. Description After the first transmit, subsequent transmit values are typically loaded into TXnn by the ISR (one value per register per interrupt). Therefore, if N items are to be sent from a particular TXnn, the ISR needs to load the transmit register (N – 1) times. Steps, c, and d can be performed in step a as a single instruction. If an interrupt trigger event occurs before all interrupt trigger configuration steps are performed, the event is ignored and not queued. If interrupts derived from the core or othe Motorola Enhanced Synchronous Serial Interface (ESSI) 7-9 Motorola Enhanced Synchronous Serial Interface (ESSI) 7-29 ESSI Programming Model Table 7-5. ESSI Status Register (SSISR) Bit Definitions (Continued) Bit Number Bit Name Reset Value Description 4 TUE 0 Transmitter Underrun Error Flag TUE is set when at least one of the enabled serial transmit shift registers is empty (that is, there is no new data to be transmitted) and a transmit time slot occurs. When a transmit underrun error occurs, the previous data (which is still present in the TX registers not written) is retransmitted. In Normal mode, there is only one transmit time slot per frame. In Network mode, there can be up to 32 transmit time slots per frame. If the TEIE bit is set, a DSP transmit underrun error interrupt request is issued when the TUE bit is set. The programmer can also clear TUE by first reading the SSISR with the TUE bit set, then writing to all the enabled transmit data registers or to the TSR. 3 RFS 0 Receive Frame Sync Flag When set, the RFS bit indicates that a receive frame sync occurred during the reception of a word in the serial receive data register. In other words, the data word is from the first time slot in the frame. When the RFS bit is cleared and a word is received, it indicates (only in Network mode) that the frame sync did not occur during reception of that word. RFS is valid only if the receiver is enabled (that is , if the RE bit is set). NOTE: In Normal mode, RFS is always read as 1 when data is read because there is only one time slot per frame, the frame sync time slot. 2 TFS 0 Transmit Frame Sync Flag When set, TFS indicates that a transmit frame sync occurred in the current time slot. TFS is set at the start of the first time slot in the frame and cleared during all other time slots. If the transmitter is enabled, data written to a transmit data register during the time slot when TFS is set is transmitted (in Network mode) during the second time slot in the frame. TFS is useful in Network mode to identify the start of a frame. TFS is valid only if at least one transmitter is enabled that is, when TE0, TE1, or TE2 is set). NOTE: In Normal mode, TFS is always read as 1 when data is being transmitted because there is only one time slot per frame, the frame sync time slot. 7-30 1 IF1 0 Serial Input Flag 1 The ESSI latches any data on the SC1 signal during reception of the first received bit after the frame sync is detected. IF1 is updated with this data when the data in the receive shift register transfers into the receive data register. IF1 is enabled only when SC1 is an input flag and Synchronous mode is selected; that is, when SC1 is programmed as ESSI in the port control register (PCR), the SYN bit is set, and the TE2 and SCD1 bits are cleared. If it is not enabled, IF1 is cleared. 0 IF0 0 Serial Input Flag 0 The ESSI latches any data on the SC0 signal during reception of the first received bit after the frame sync is detected. The IF0 bit is updated with this data when the data in the receive shift register transfers into the receive data register. IF0 is enabled only when SC0 is an input flag and the Synchronous mode is selected; that is, when SC0 is programmed as ESSI in the port control register (PCR), the SYN bit is set, and the TE1 and SCD0 bits are cleared. If it is not enabled, the IF0 bit is cleared. DSP56311 User’s Manual Motorola