+ All Categories
Home > Documents > EE 319K Introduction to Embedded Systems

EE 319K Introduction to Embedded Systems

Date post: 08-Jan-2016
Category:
Upload: yehudi
View: 36 times
Download: 0 times
Share this document with a friend
Description:
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. - PowerPoint PPT Presentation
29
13-1 Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi EE 319K Introduction to Embedded Systems Lecture 13: 2-D Arrays, Bitmaps, Sprites, Structs, Lab 10 Fall 2014 EE319K http://youtu.be/RfBDuGIxzCU
Transcript
Page 1: EE 319K Introduction to Embedded Systems

13-1Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

EE 319KIntroduction to Embedded Systems

Lecture 13: 2-D Arrays, Bitmaps, Sprites,

Structs, Lab 10

Fall 2014 EE319K http://youtu.be/RfBDuGIxzCU

Page 2: EE 319K Introduction to Embedded Systems

13-2

AgendaRecap

Lab9UART, InterruptsFIFO QueuesRace Condition, Critical section

AgendaSoftware design2-D arrayBitmapsStructsLab 10

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

http://www.youtube.com/watch?v=-pIMVZZRb7Y

Page 3: EE 319K Introduction to Embedded Systems

13-3

Software Design

Modular programmingMake it easier to understand

o Each screen is a complete story without scrollingMaximize the number of modulesMinimize the interdependency

o Bandwidth of data passed from one to anothero Control coupling: actions in one cause effects in anothero Shared variables (very bad)

Book Section 5.2

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

LCD routines

ADChardware

Mathroutines

ADC routines

mainLCD

hardware

0 to 50Hzanalog signal

12-bit digitalevery 10ms

16-bit data100 halfwords/sec

100-element 16-bit buffer1 buffer/sec

16-bit result1 halfword/sec

10-character string1 string/sec

ASCII characters10 character/sec

Page 4: EE 319K Introduction to Embedded Systems

13-4

Software Design

Design for testConsider how it will be tested while designingModule has three files

o Header: What the module doeso Code: How it workso Test: A main program used to test the module

Manage resourcesLCD graphicsTime (processor cycles)

o A fun game requires careful control of timeInput/Output

o Switches, slide pot, DAC, LCD

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 5: EE 319K Introduction to Embedded Systems

13-5

Callbacks

Bard, Gerstlauer, Valvano, Yerraballi

// ***************** Timer0_Init ****************// Activate Timer0 interrupts to run user task periodically// Inputs: task is a pointer to a user function// period in units (1/clockfreq)// Outputs: nonevoid Timer0_Init(void(*task)(void), unsigned long period){long sr; sr = StartCritical(); SYSCTL_RCGCTimer_R |= 0x01; // 0) activate timer0 PeriodicTask = task; // user function TIMER0_CTL_R &= ~TIMER_CTL_TAEN; // 1) disable timer0A during setup // 2) configure for 32-bit timer mode TIMER0_CFG_R = TIMER_CFG_32_BIT_TIMER; // 3) configure for periodic mode, default down-count settings TIMER0_TAMR_R = TIMER_TAMR_TAMR_PERIOD; TIMER0_TAILR_R = period-1; // 4) reload value // 5) clear timer0A timeout flag TIMER0_ICR_R = TIMER_ICR_TATOCINT; TIMER0_IMR_R |= TIMER_IMR_TATOIM;// 6) arm timeout interrupt NVIC_PRI4_R = (NVIC_PRI4_R&0x00FFFFFF)|0x40000000; // 7) priority 2 NVIC_EN0_R = NVIC_EN0_INT19; // 8) enable interrupt 19 in NVIC TIMER0_CTL_R |= TIMER_CTL_TAEN; // 9) enable timer0A EndCritical(sr);}

void UserTask(void){ static int i = 0; LEDS = COLORWHEEL[i&(WHEELSIZE-1)]; i = i + 1;}…Timer0_Init(&UserTask, 80000000);// initialize timer0 (1 Hz)

Page 6: EE 319K Introduction to Embedded Systems

13-6

2-D Array or Matrix

What: 2 rows and 3 columns, 8 bits eachunsigned char M[2][3];

Why:ImagesMaps

How: (C uses row major)C code to access M[i][j] = 5;Write this in assembly (R0=i, R1=j)

row Icolumn J

01

0 1 2M[0,0] M[0,1] M[0,2]M[1,0] M[1,1] M[1,2]

0x2000.09100x2000.09110x2000.09120x2000.09130x2000.09140x2000.0915

row major

M[0,0]M[0,1]M[0,2]M[1,0]M[1,1]M[1,2]

row 0

row 1

column major

M[0,0]M[1,0]M[0,1]M[1,1]M[0,2]M[1,2]

column 0

column 1

column 2

0x2000.09100x2000.09110x2000.09120x2000.09130x2000.09140x2000.0915

i = rowj = columnn= # of columnsBase+n*i+j Base+2*(n*i+j)Base+4*(n*i+j)

Num of bytes/element

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 7: EE 319K Introduction to Embedded Systems

13-7

2-D Array or Matrix

What: 6 rows and 7 columnsint8_t Connect4[6][7];

Why:ImagesMaps

How: (row major)Write C code to set array values to 0Write in assembly

Base+2*(7*i+j)

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

ji

Page 8: EE 319K Introduction to Embedded Systems

13-8

2-D Array or Matrix

Assuming C[6][7]

0 means free1 means me-1 means you

// 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(); } }}

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

ji

Page 9: EE 319K Introduction to Embedded Systems

13-9

ST7735 Graphics Format

LCD is 160 rows, 128 columns, 18 bits/pixel

Row 0

Row 159

Column 0

Column 127

Page 10: EE 319K Introduction to Embedded Systems

13-10

BMP File Format

SmallEnemy sprites are 16-bit color, 16 pixels wide by 10 pixels highAlien sprites are 16-bit color, 32 pixels wide by 20 pixels high

Sprites as objects moving across screen

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 11: EE 319K Introduction to Embedded Systems

13-11

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).

Rendering a Sprite ST7735_DrawBitmap(50,100,SmallEnemy30pointB,16,10);

Placed at x=50, y=100

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

16 wide, 10 high

Page 12: EE 319K Introduction to Embedded Systems

13-12

BMP File Formatconst unsigned short SmallEnemy30pointB[]={0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x07E0,0x0000,0x07E0,0x0000,0x0000,0x0000,0x0000,0x07E0,0x0000,0x07E0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x07E0,0x0000,0x07E0,0x07E0,0x07E0,0x07E0,0x0000,0x07E0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x07E0,0x0000,0x0000,0x0000,0x0000,0x07E0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x07E0,0x07E0,0x07E0,0x07E0,0x07E0,0x07E0,0x07E0,0x07E0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x07E0,0x07E0,0x0000,0x07E0,0x07E0,0x0000,0x07E0,0x07E0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x07E0,0x07E0,0x07E0,0x07E0,0x07E0,0x07E0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x07E0,0x07E0,0x07E0,0x07E0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x07E0,0x07E0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,};

Example BMP file pixel data written as C constant•The color is a rgb565 model:• Red: 0x001F =>red=31;green=0;blue=0• Green: 0x07E0 => red=0;green=63;blue=0• Blue: 0xF800 => ref=0;green=0;blue=31

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Data is upside down

Page 13: EE 319K Introduction to Embedded Systems

13-13

Structure Definition

One objectCollection of dataData has dissimilar types or meanings

typedef enum {dead,alive} status;struct State { unsigned long x; // x coordinate unsigned long y; // y coordinate const unsigned char *image; // ptr->image status life; // dead/alive}; typedef struct State STyp;

new data typesBard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 14: EE 319K Introduction to Embedded Systems

13-14

Structure Creation

Put in RAM if data changesInitialized at run time, before main()

STyp Enemy[18]={{0,10, SmallEnemy30PointA,alive},{20,10, SmallEnemy30PointA,alive},{40,10, SmallEnemy30PointA,alive},{60,10, SmallEnemy30PointA,alive},{80,10, SmallEnemy30PointA,alive},{100,10, SmallEnemy30PointA,alive}, …{100,30, SmallEnemy10PointA,alive}};

the new type

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 15: EE 319K Introduction to Embedded Systems

13-15

Structure Creation

Put in RAM if data changesRun-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 = alive; }}

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 16: EE 319K Introduction to Embedded Systems

13-16

Structure Example

Student databaseSet of student records

Structure definition

struct Student { char Initials[2]; short id; struct Student *teammate;};typedef struct Student SType;

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 17: EE 319K Introduction to Embedded Systems

13-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, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 18: EE 319K Introduction to Embedded Systems

13-18

Arrays of Structures

Traverse array

Add featuresSeating 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, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 19: EE 319K Introduction to Embedded Systems

13-19

Timer 2A Periodic interrupt

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

• Resolution: bus period• Precision: 32 bits• Max period: 53 sec (80 MHz)

TM4C123

Timer 0 T0CCP0T0CCP1

Timer 1 T1CCP0T1CCP1

Timer 2 T2CCP0T2CCP1

Timer 3 T3CCP0T3CCP1

Timer 4 T4CCP0T4CCP1

Timer 5 T5CCP0T5CCP1

Timer 2A

...TAILR, ... 3, 2, 1, 0, TAILR, TAILR-1...

TATORIS

32-bit Down Counter

Flag

TM4C

Bus clock

32-bit TAILR

0) activate timer2 clock1) disable timer2A2) Precision to 32 bits3) periodic mode4) TAILR value5) clock resolution6) clear timeout flag7) arm timeout8) priority 49) enable in NVIC10) enable timer2A

Page 20: EE 319K Introduction to Embedded Systems

13-20

Vector address Number IRQ ISR name in Startup.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

INTER

RU

PT V

EC

TO

RS

Lab 7

Lab 8

Lab 9

77 total

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Yerraballi

Page 21: EE 319K Introduction to Embedded Systems

13-21

Timer 2A Periodic interruptunsigned 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

Max is 53 sec

Page 22: EE 319K Introduction to Embedded Systems

13-22

Timer 2A plays sounds

// trigger is Timer2A Time-Out Interrupt// set periodically TATORIS set on rollovervoid 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}

Ack

Stuff

Output sounds here

Call to stop sound

Call to start sound

TATORIS

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 23: EE 319K Introduction to Embedded Systems

13-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, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 24: EE 319K Introduction to Embedded Systems

13-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/QxDQUUDStOwBard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 25: EE 319K Introduction to Embedded Systems

13-25

Lab 10 – Grading

The TAs will sort into groups and certify requirements Show game to TA by Tuesday 12/1 by 7pm 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 Wednesday/Thursday 12-2/12-3 One team member demonstrates The other team member scores other games Can’t compete unless both members are present Groups of one are checked out by the TA (Max Score 80)

Games are rank-ordered by peers

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 26: EE 319K Introduction to Embedded Systems

13-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 is due 7pm Tuesday 5/3/2016 Late checkouts are handled by the TA in the usual way.

All late checkouts must be completed by Friday 3pm.

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 27: EE 319K Introduction to Embedded Systems

13-27

Game Engine – Call graph

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 28: EE 319K Introduction to Embedded Systems

13-28

Game Engine – Data Flow

Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Page 29: EE 319K Introduction to Embedded Systems

13-29

Game Engine – Flowchart

Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Do not erase the LCD, it causes flicker

Could use GPIO interrupts


Recommended