0% found this document useful (0 votes)
15 views

Copy of 371_2014_Q7

Copy of 371_2014_Q7

Uploaded by

ikokashechka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
15 views

Copy of 371_2014_Q7

Copy of 371_2014_Q7

Uploaded by

ikokashechka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
got Question 7: Embedded Application Programming in C (25 marks) page 8 of 11 ‘A system-on-a-chip FPGA hardware configuration has been defined as follows: Nios I processor __(no address range) address aren ROM (0x00000000-0x00003FFF) { Srcocosaoo Ti To)status S-BI input port data reg. (Ox00004400) | Oosoas |—=TaRRaE TN 8-bit output port data reg. (0x00004A80) Suarstin ; timer (0x00005000-0x00005010)~< 00005008 [________ start (lo) JTAG UART (data reg. 0x00006800, \o%xo000500¢ [stare hi status reg 0x00006804) : USE SCRAP PAPER RAM (0x00007000-0x00007FFF) TO DRAFT A SOLUTION Use the specifications below to write a € program for the above system hardware. * Assume that the Altera-provided exception handler is included, which makes a ‘normal subroutine call to a function named interrupt _handler(). + You must write the interrupt_handler() function in C to perform full checking to ‘identify the source of the interrupt, as if there were actually multiple sources. * Assume that macros NIOS2_WRITE_IENABLE(), NIOS2_WRITE_STATUS(), and NIOS2_READ_IPENDING() are available in the + With a 50-MHz clock input, configure a timer interrupt which is 5,000,000 cycles (0x004C4B40 in hexadecimal). + Assume that th 1e 8-bit parallel output port pins are connected to'8 LEDs. * At any time, . Every Gane ee * The main program must maintain SAT ORREMUMNET rer once ee + Every 4 seconds, the * The data read from the input parallel port ‘characters for hexadecimal digits, and they must be * After sending the two characters, the main program should’send a newline ‘character ('\n' or 0x0A) so that output appears on separate lines. + In addition to printing the data in ASCII form, the the * For the JTAG UART, the upper 16 bits of the status register indicate the amount of space available in the output buffer. A character is sent to the output buffer by writing a word to the data register with the character in the low 8 bits. * The ASCII code for '0" is 0x30 (or 48). The ASCII code for "Avis 0x41 (or 65). + You must organize your software with the following function: ~ void Init (void) ; void PrintChar (unsigned int ch); / void UpdateLEDs (void) ; v void interrupt_handler (void) ; int main (void) ; Elec 2a Zoi ao © —Maddy's “Tips. hii ee Pe ip Al tes Ul 3) Guaconteed to use Prat Ona a € Cree cetne la So Cer Wing to do? = vocite oak prio Cha tee : because you nos youre garg to lave 4o_use neon | a ay (Plus. you already lenau 95% of Hreen and hats le Ake guestan) Notice T_hightighted * header Fle nios2 control th" ____fhis is _inpoctant be cause —ouc int and inleccugh hondlec Aanchions use the funchions ia ais Lie Mou NEED (ime, z7AG_uaRS, atc) 2€ : : ; ; Aaitialize fhe leds > 4op /boiton 4 gre tit, start all off or saith cited padeca, peolodloly go with one of he _pattecn Cod, so nean ypu code! (stack usit nik, g needed ) Tridiabiganon Temprake . + PaatChec 2 a Aloid _Fnit (void) 4 TTo_intholiae Yhe ener. * * Tue start wt = O« SF * Timex status = 0 * “mer connen. = 0x3; ag cle shies Fes Ge Mond" v0" re_corksel cag. ussciiy ON > 0x4 (To isitialize ane qustablidien et partons mask 2 O00, ddegendts on outtons tennis bit + Burtows_Enac = 0 M “To seitiolize the gcten ted: 4 " ; P IL Sek ony Gags to shod salut { geaoaly 0) ceguced. BSI ea eee ee zs ateccupt Handler Template. sa oid \ Cans ak tpending Speeding + W022 ReALIPENDING LA, if Gpending & oxf)== 1) 4 2cesek _iateccupt source. I do someting usually cati_arcther finchen oc seta Fas, —_____# iP 4hece 15 another inteccugt sorcce check it toot sP Chgendiag & Ox == 4)§, = Noid starit (void) 4 A set uo timnec + “MER START LO = Ox 4840; ieee es Serna eo ei ec + Timex _ status = 0; “TUMeR_Conteol = Ox Aimed Cag = 0; ek up Leo's + Gacem LEDS = Ox OF; MU Lowee 4 = 0000 WW\\_ > = Mone = fet Alina sebelalinbenctighs tandem eh a 0S 2 OL ol Que " tod lool @_addiesses given | aad __UpdaleLEds (void) 4 Lunsigred iat shat, Core € Us <23 4 ale = ~ Greew— LEDS ___4 Geeen reps = Ox 0F P (sie £ Ox of) ==1)4 3 + Geeen_ Lens = 0. FO swap 5. ad = (una) § iok__ipendiag iP(ligending 2 0x4) ==) 4 A cesek timer 4 TIMER STATUS = 0; Smit () Goat sir _\ed tiene = 0, Groat dle cradntine £0 aside 4) § if Uimec Gag == 4 4 dimec— Fog =O Neda time += 0.15 ead ke += 0.1 £ (led time == 0.5) updoielens (>; led. time =O} Bi & iP (vead time == 4) 4 a MH get low. tad high bits to _sepacate digits. — uesigned int hac lo = input char £ 0x OF; tet: > i a corel ee ee if (chor lo 42 9) chac_to = cbaclo_+ 0x30 else Jooc—to = chac*lo_+ Ox 41 if (hace ni_<= 4) Clhachi_> chac_ni_+ 0x30, eise. hoc hi > chac_hi + Oxtl call % Prat Char ( chac-hid ; Print Choc char— to); Prat Chae ('\n');

You might also like