1 / 26

EE 319K Introduction to Embedded Systems

EE 319K Introduction to Embedded Systems. Lecture 13: 2-D Arrays, Bitmaps, Sprites, Structs, Lab 10. Agenda. Recap Lab9 UART, Interrupts FIFO Queues Race Condition, Critical section Agenda Software design 2-D array Bitmaps Structs Lab 10. http://www.youtube.com/watch?v=-pIMVZZRb7Y.

yehudi
Download Presentation

EE 319K Introduction to Embedded Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EE 319KIntroduction to Embedded Systems Lecture 13: 2-D Arrays, Bitmaps, Sprites, Structs, Lab 10 Bard, Gerstlauer, Valvano, Yerraballi

  2. Agenda Recap Lab9 UART, Interrupts FIFO Queues Race Condition, Critical section Agenda Software design 2-D array Bitmaps Structs Lab 10 http://www.youtube.com/watch?v=-pIMVZZRb7Y Bard, Gerstlauer, Valvano, Yerraballi

  3. Software Design Modular programming Make it easier to understand Each screen is a complete story without scrolling Maximize the number of modules Minimize the interdependency Bandwidth of data passed from one to another Control coupling: actions in one cause effects in another Shared variables (very bad) Book Section 5.2 Bard, Gerstlauer, Valvano, Yerraballi

  4. Software Design Design for test Consider how it will be tested while designing Module has three files Header: What the module does Code: How it works Test: A main program used to test the module Manage resources LCD graphics Time (processor cycles) A fun game requires careful control of time Input/Output Switches, slide pot, DAC, LCD Bard, Gerstlauer, Valvano, Yerraballi

  5. 2-D Array or Matrix What: 2 rows and 3 columns, 8 bits each unsigned char M[2][3]; Why: Images Maps How: (C uses row major) C code to access M[i][j] = 5; Write this in assembly (R0=i, R1=j) i = row j = column n= # of columns Base+n*i+j Base+2*(n*i+j) Base+4*(n*i+j) Num of bytes/element Bard, Gerstlauer, Valvano, Yerraballi

  6. 2-D Array or Matrix • What: 6 rows and 7 columns • short Connect4[6][7]; • Why: • Images • Maps • How: (row major) • Write C code to set array values to 0 • Write in assembly j i Base+2*(7*i+j) Bard, Gerstlauer, Valvano, Yerraballi

  7. 2-D Array or Matrix Assuming C[6][7] j // check the rows for(i=0;i<6;i++){ for(j=0;j<4;j++){ if((C[i][j]==1) &&(C[i][j+1]==1) &&(C[i][j+2]==1) &&(C[i][j+3]==1)){ Iwin(); } } } i 0 means free 1 means me -1 means you Bard, Gerstlauer, Valvano, Yerraballi

  8. Kentec Graphics Format Column 0 Row 0 Row 239 LCD is 240 rows, 320 columns, 16 bits/pixel Column 319 Bard, Gerstlauer, Valvano, Yerraballi

  9. 4-bit (16-color) Palette // Map 4-bit color to 16-bit color: red,green,blue // bits 15-11 5 bit red // bits 10-5 6-bit green // bits 4-0 5-bit blue unsigned short const Color4[16] = { 0, //0 – black ((0x00>>3)<<11) | ((0x00>>2)<<5) | (0xAA>>3), //1 – blue ((0x00>>3)<<11) | ((0xAA>>2)<<5) | (0x00>>3), //2 – green ((0x00>>3)<<11) | ((0xAA>>2)<<5) | (0xAA>>3), //3 – cyan ((0xAA>>3)<<11) | ((0x00>>2)<<5) | (0x00>>3), //4 – red ((0xAA>>3)<<11) | ((0x00>>2)<<5) | (0xAA>>3), //5 – magenta ((0xAA>>3)<<11) | ((0x55>>2)<<5) | (0x00>>3), //6 – brown ((0xAA>>3)<<11) | ((0xAA>>2)<<5) | (0xAA>>3), //7 – light gray ((0x55>>3)<<11) | ((0x55>>2)<<5) | (0x55>>3), //8 – dark gray ((0x55>>3)<<11) | ((0x55>>2)<<5) | (0xFF>>3), //9 – bright blue ((0x55>>3)<<11) | ((0xFF>>2)<<5) | (0x55>>3), //10 – bright green ((0x55>>3)<<11) | ((0xFF>>2)<<5) | (0xFF>>3), //11 – bright cyan ((0xFF>>3)<<11) | ((0x55>>2)<<5) | (0x55>>3), //12 – bright red ((0xFF>>3)<<11) | ((0x55>>2)<<5) | (0xFF>>3), //13 – bright magenta ((0xFF>>3)<<11) | ((0xFF>>2)<<5) | (0x55>>3), //14 – bright yellow ((0xFF>>3)<<11) | ((0xFF>>2)<<5) | (0xFF>>3) //15 – bright white }; #define BURNTORANGE 0xCB01 // R=197/8 G=96/2 B=6/8 Use 4-bit color to reduce code size, still fits in 32k Bard, Gerstlauer, Valvano, Yerraballi

  10. BMP File Format • Sprites as objects moving across screen SmallEnemy sprites are 16-color, 16 pixels wide by 10 pixels high Alien sprites are 16-color, 32 pixels wide by 20 pixels high Bard, Gerstlauer, Valvano, Yerraballi

  11. BMP File Format LCD_DrawBMP(SmallEnemy10pointA,50,100); 16 wide, 10 high Placed at x=50, y=100 F F F F FFFFFFFFFF FFFFFFFFFFFF FFF FFFF FFF F FFFFFFFF F F F F F F F The raw data from BMP file to illustrate how the image is stored (0s replaced with spaces). Bard, Gerstlauer, Valvano, Yerraballi

  12. BMP File Format const unsigned char Enemy10Point1[] = { 0x42,0x4D,0xC6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x00,0x00,0x00,0x28,0x00, 0x00,0x00,0x10,0x00,0x00,0x00,0x0A,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00, 0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x80, 0x00,0x00,0x00,0x80,0x80,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x80, 0x00,0x00,0x80,0x80,0x80,0x00,0xC0,0xC0,0xC0,0x00,0x00,0x00,0xFF,0x00,0x00,0xFF, 0x00,0x00,0x00,0xFF,0xFF,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF,0xFF,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x0F,0x00,0x00,0x00,0x00,0xF0,0x00, 0x00,0x00,0xF0,0x00,0x00,0x0F,0x00,0x00, 0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xF0,0x00, 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00, 0x00,0xFF,0xF0,0xFF,0xFF,0x0F,0xFF,0x00, 0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0x0F,0x00, 0x00,0xF0,0x0F,0x00,0x00,0xF0,0x0F,0x00, 0x00,0x00,0xF0,0x00,0x00,0x0F,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xFF }; • Example BMP file written as C constant • Header (w x h) • Pixel data We can use either 24-bit BMP or 4-bit BMP Bard, Gerstlauer, Valvano, Yerraballi

  13. Structure Definition • One object • Collection of data • Data has dissimilar types or meanings struct State { unsigned long x; // x coordinate unsigned long y; // y coordinate const unsigned char *image; // ptr->image long life; // 0=dead, 1=alive }; typedef struct State STyp; a new type Bard, Gerstlauer, Valvano, Yerraballi

  14. Structure Creation • Put in RAM if data changes • Initialized at run time, before main() the new type STyp Enemy[18]={ {0,10, SmallEnemy30PointA,1}, {20,10, SmallEnemy30PointA,1}, {40,10, SmallEnemy30PointA,1}, {60,10, SmallEnemy30PointA,1}, {80,10, SmallEnemy30PointA,1}, {100,10, SmallEnemy30PointA,1}, … {100,30, SmallEnemy10PointA,1} }; Bard, Gerstlauer, Valvano, Yerraballi

  15. Structure Creation • Put in RAM if data changes • Run-time initialization inside main() STyp Enemy[18]; void Init(void){ int i; for(i=0;i<6;i++){ Enemy[i].x = 20*i; Enemy[i].y = 10; Enemy[i].image = SmallEnemy30PointA; Enemy[i].life = 1; } } Bard, Gerstlauer, Valvano, Yerraballi

  16. Structure Example • Student database • Set of student records • Structure definition struct Student { char Initials[2]; short id; struct Student *teammate; }; typedef struct Student SType; Bard, Gerstlauer, Valvano, Yerraballi

  17. Arrays of Structures • Pointers to specific elements • Array of structure creation #define XYpt &class[0] #define ABpt &class[1] #define RSpt &class[2] ... SType class[6] = { {{'X','Y'},123, RSpt}, // XY {{'A','B'}, 23, RYpt}, // AB {{'R','S'}, 11, XYpt}, // RS ... {{'R','Y'},2457, ABpt}}; // RY Bard, Gerstlauer, Valvano, Yerraballi

  18. Arrays of Structures • Traverse array • Add features • Seating chart • Write a function to place a student into seat Write code to navigate through the class array and print all student records in the following format: FI-LI : id (team-mate_id) SType seatChart[5][24]; //2-D array Bard, Gerstlauer, Valvano, Yerraballi

  19. Timer 2A Periodic interrupt • Resolution: bus period • Precision: 32 bits • Max period: 53 sec (80 MHz) 0) activate timer2 clock 1) disable timer2A 2) Precision to 32 bits 3) periodic mode 4) TAILR value 5) clock resolution 6) clear timeout flag 7) arm timeout 8) priority 4 9) enable in NVIC 10) enable timer2A Bard, Gerstlauer, Valvano, Yerraballi

  20. Vector address Number IRQ ISR name inStartup.s NVIC Priority bits 0x00000038 14 -2 PendSV_Handler NVIC_SYS_PRI3_R 23 – 21 0x0000003C 15 -1 SysTick_Handler NVIC_SYS_PRI3_R 31 – 29 0x00000040 16 0 GPIOPortA_Handler NVIC_PRI0_R 7 – 5 0x00000044 17 1 GPIOPortB_Handler NVIC_PRI0_R 15 – 13 0x00000048 18 2 GPIOPortC_Handler NVIC_PRI0_R 23 – 21 0x0000004C 19 3 GPIOPortD_Handler NVIC_PRI0_R 31 – 29 0x00000050 20 4 GPIOPortE_Handler NVIC_PRI1_R 7 – 5 0x00000054 21 5 UART0_Handler NVIC_PRI1_R 15 – 13 0x00000058 22 6 UART1_Handler NVIC_PRI1_R 23 – 21 0x0000005C 23 7 SSI0_Handler NVIC_PRI1_R 31 – 29 0x00000060 24 8 I2C0_Handler NVIC_PRI2_R 7 – 5 0x00000064 25 9 PWMFault_Handler NVIC_PRI2_R 15 – 13 0x00000068 26 10 PWM0_Handler NVIC_PRI2_R 23 – 21 0x0000006C 27 11 PWM1_Handler NVIC_PRI2_R 31 – 29 0x00000070 28 12 PWM2_Handler NVIC_PRI3_R 7 – 5 0x00000074 29 13 Quadrature0_Handler NVIC_PRI3_R 15 – 13 0x00000078 30 14 ADC0_Handler NVIC_PRI3_R 23 – 21 0x0000007C 31 15 ADC1_Handler NVIC_PRI3_R 31 – 29 0x00000080 32 16 ADC2_Handler NVIC_PRI4_R 7 – 5 0x00000084 33 17 ADC3_Handler NVIC_PRI4_R 15 – 13 0x00000088 34 18 WDT_Handler NVIC_PRI4_R 23 – 21 0x0000008C 35 19 Timer0A_Handler NVIC_PRI4_R 31 – 29 0x00000090 36 20 Timer0B_Handler NVIC_PRI5_R 7 – 5 0x00000094 37 21 Timer1A_Handler NVIC_PRI5_R 15 – 13 0x00000098 38 22 Timer1B_Handler NVIC_PRI5_R 23 – 21 0x0000009C 39 23 Timer2A_Handler NVIC_PRI5_R 31 – 29 0x000000A0 40 24 Timer2B_Handler NVIC_PRI6_R 7 – 5 0x000000A4 41 25 Comp0_Handler NVIC_PRI6_R 15 – 13 0x000000A8 42 26 Comp1_Handler NVIC_PRI6_R 23 – 21 0x000000AC 43 27 Comp2_Handler NVIC_PRI6_R 31 – 29 0x000000B0 44 28 SysCtl_Handler NVIC_PRI7_R 7 – 5 0x000000B4 45 29 FlashCtl_Handler NVIC_PRI7_R 15 – 13 0x000000B8 46 30 GPIOPortF_Handler NVIC_PRI7_R 23 – 21 0x000000BC 47 31 GPIOPortG_Handler NVIC_PRI7_R 31 – 29 0x000000C0 48 32 GPIOPortH_Handler NVIC_PRI8_R 7 – 5 0x000000C4 49 33 UART2_Handler NVIC_PRI8_R 15 – 13 0x000000C8 50 34 SSI1_Handler NVIC_PRI8_R 23 – 21 0x000000CC 51 35 Timer3A_Handler NVIC_PRI8_R 31 – 29 0x000000D0 52 36 Timer3B_Handler NVIC_PRI9_R 7 – 5 0x000000D4 53 37 I2C1_Handler NVIC_PRI9_R 15 – 13 0x000000D8 54 38 Quadrature1_Handler NVIC_PRI9_R 23 – 21 0x000000DC 55 39 CAN0_Handler NVIC_PRI9_R 31 – 29 0x000000E0 56 40 CAN1_Handler NVIC_PRI10_R 7 – 5 0x000000E4 57 41 CAN2_Handler NVIC_PRI10_R 15 – 13 0x000000E8 58 42 Ethernet_Handler NVIC_PRI10_R 23 – 21 0x000000EC 59 43 Hibernate_Handler NVIC_PRI10_R 31 – 29 0x000000F0 60 44 USB0_Handler NVIC_PRI11_R 7 – 5 0x000000F4 61 45 PWM3_Handler NVIC_PRI11_R 15 – 13 0x000000F8 62 46 uDMA_Handler NVIC_PRI11_R 23 – 21 0x000000FC 63 47 uDMA_Error NVIC_PRI11_R 31 – 29 Lab 7 Lab 8 Lab 9 77 total INTERRUPT VECTORS Bard, Gerstlauer, Valvano, Yerraballi

  21. Timer 2A Periodic interrupt Max is 53 sec unsigned long TimerCount; void Timer2_Init(unsigned long period){ unsigned long volatile delay; SYSCTL_RCGCTIMER_R |= 0x04; // 0) activate timer2 delay = SYSCTL_RCGCTIMER_R; TimerCount = 0; TIMER2_CTL_R = 0x00000000; // 1) disable timer2A TIMER2_CFG_R = 0x00000000; // 2) 32-bit mode TIMER2_TAMR_R = 0x00000002; // 3) periodic mode TIMER2_TAILR_R = period-1; // 4) reload value TIMER2_TAPR_R = 0; // 5) clock resolution TIMER2_ICR_R = 0x00000001; // 6) clear timeout flag TIMER2_IMR_R = 0x00000001; // 7) arm timeout NVIC_PRI5_R = (NVIC_PRI5_R&0x00FFFFFF)|0x80000000; // 8) priority 4 NVIC_EN0_R = 1<<23; // 9) enable IRQ 23 in TIMER2_CTL_R = 0x00000001; // 10) enable timer2A } Output sound at 11.025 kHz Bard, Gerstlauer, Valvano, Yerraballi

  22. Timer 2A plays sounds // trigger is Timer2A Time-Out Interrupt // set periodically TATORIS set on rollover void Timer2A_Handler(void){ TIMER2_ICR_R = 0x00000001; // acknowledge TimerCount++; // run some background stuff here } void Timer2A_Stop(void){ TIMER2_CTL_R &= ~0x00000001; // disable } void Timer2A_Start(void){ TIMER2_CTL_R |= 0x00000001; // enable } TATORIS Ack Output sounds here Stuff Call to stop sound Call to start sound Bard, Gerstlauer, Valvano, Yerraballi

  23. Lab 10 – Connect Four • There must be at least one button and one slide pot. • The colored pieces must move on the LCD. • There must be sounds appropriate for the game. • The score should be displayed on the screen (but it could be displayed before or after the game action). • At least two interrupt ISRs must used in an appropriate manner. • The game must have a man versus machine mode. Bard, Gerstlauer, Valvano, Yerraballi

  24. Lab10 – Space Invaders, Pipe Dreams … • There must be at least one button and one slide pot. • There must be at least three images on the LCD display that move. • There must be sounds appropriate for the game. • The score should be displayed on the screen (but it could be displayed before or after the game action). • At least two interrupt ISRs must used in an appropriate manner. • The game must have a “time” aspect to it (For e.g., if you don’t move a sprite within a certain time it could be killed). Contrast with ConnectFour which is a taking “turns” game • The game must be both simple to learn and fun to play. http://youtu.be/QxDQUUDStOw Bard, Gerstlauer, Valvano, Yerraballi

  25. Lab 10 – Grading • The TAs will sort into groups and certify requirements • Show game to TA before class on 4/30 or 5/1 • Wonderful group will have max of 100 points • Supreme group will have a max of 120 points • Lab 10 will be graded subjectively by other students • During class on 4/30 or 5/1 meet in ENS507 • One team member demonstrates • The other team member scores other games • Groups of one are checked out by the TA • Can’t compete unless both members are present • Games are rank-ordered according to level of fun • Superfinals Friday 5/2 12-1 in ENS507 Bard, Gerstlauer, Valvano, Yerraballi

  26. Lab 10 – Grading • Wonderful group • 80 if 0th to 49th percentile • 90 if 50th to 74th percentile • 100 if 75th to 100th percentile • Supreme • 100 if 0th to 49th percentile • 110 if 50th to 74th percentile • 120 if 75th to 100th percentile • TA certification due date is 2 hours before the start of the last lecture class of the semester. 4/30 or 5/1 • Late checkouts are handled by the TA in the usual way. All late checkouts must be completed by Friday 3pm, • All LCDs with the bag must be returned by 5pm Friday. Bard, Gerstlauer, Valvano, Yerraballi

More Related