EE 319K Introduction to Embedded Systems - PowerPoint PPT Presentation

About This Presentation
Title:

EE 319K Introduction to Embedded Systems

Description:

EE 319K Introduction to Embedded Systems Lecture 13: 2-D Arrays, Bitmaps, Sprites, Structs, Lab 10 Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi – PowerPoint PPT presentation

Number of Views:191
Avg rating:3.0/5.0
Slides: 30
Provided by: BillBa89
Category:

less

Transcript and Presenter's Notes

Title: EE 319K Introduction to Embedded Systems


1
EE 319KIntroduction to Embedded Systems
  • Lecture 13 2-D Arrays, Bitmaps, Sprites,
    Structs, Lab 10

Fall 2014 EE319K http//youtu.be/RfBDuGIxzCU
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
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
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

5
Callbacks
// 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 none void
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_R0x00FFFFFF)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
COLORWHEELi(WHEELSIZE-1) i i
1 Timer0_Init(UserTask, 80000000)//
initialize timer0 (1 Hz)
6
2-D Array or Matrix
  • What 2 rows and 3 columns, 8 bits each
  • unsigned char M23
  • Why
  • Images
  • Maps
  • How (C uses row major)
  • C code to access Mij 5
  • Write this in assembly (R0i, R1j)

i row j column n of columns Basenij
Base2(nij) Base4(nij)
Num of bytes/element
7
2-D Array or Matrix
j
  • What 6 rows and 7 columns
  • int8_t Connect467
  • Why
  • Images
  • Maps
  • How (row major)
  • Write C code to set array values to 0
  • Write in assembly

i
Base2(7ij)
8
2-D Array or Matrix
  • Assuming C67

j
// check the rows for(i0ilt6i)
for(j0jlt4j) if((Cij1)
(Cij11) (Cij21)
(Cij31)) Iwin()
i
0 means free 1 means me -1 means you
9
ST7735 Graphics Format
Column 0
Row 0
Row 159
LCD is 160 rows, 128 columns, 18 bits/pixel
Column 127
10
BMP File Format
  • Sprites as objects moving across screen

SmallEnemy sprites are 16-bit color, 16 pixels
wide by 10 pixels high Alien sprites are 16-bit
color, 32 pixels wide by 20 pixels high
11
Rendering a Sprite
ST7735_DrawBitmap(50,100,SmallEnemy30pointB,16,10
)
16 wide, 10 high
Placed at x50, y100
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).
12
BMP File Format
const unsigned short SmallEnemy30pointB 0x0000
,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0
x0000, 0x0000,0x0000,0x0000,0x07E0,0x0000,0x07E0,0
x0000,0x0000,0x0000,0x0000,0x07E0,0x0000,0x07E0,0x
0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x
07E0,0x0000,0x07E0,0x07E0,0x07E0,0x07E0,0x0000,0x0
7E0,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0
000,0x0000,0x0000,0x07E0,0x0000,0x0000,0x0000,0x00
00,0x07E0,0x0000,0x0000,0x0000,0x0000,0x0000, 0x00
00,0x0000,0x0000,0x0000,0x07E0,0x07E0,0x07E0,0x07E
0,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,0
x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0
x0000,0x0000,0x0000,0x0000,0x07E0,0x07E0,0x07E0,0x
07E0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x
0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0
7E0,0x07E0,0x0000,0x0000,0x0000,0x0000,0x0000,0x00
00,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x00
00,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x000
0,0x0000,0x0000,0x0000,
Data is upside down
  • Example BMP file pixel data written as C constant
  • The color is a rgb565 model
  • Red 0x001F gtred31green0blue0
  • Green 0x07E0 gt red0green63blue0
  • Blue 0xF800 gt ref0green0blue31

13
Structure Definition
  • One object
  • Collection of data
  • Data 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-gtimage status life
// dead/alive typedef struct
State STyp
new data types
14
Structure Creation
  • Put in RAM if data changes
  • Initialized at run time, before main()

the new type
STyp Enemy18 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
15
Structure Creation
  • Put in RAM if data changes
  • Run-time initialization inside main()

STyp Enemy18 void Init(void) int i
for(i0ilt6i) Enemyi.x 20i
Enemyi.y 10 Enemyi.image
SmallEnemy30PointA Enemyi.life alive

16
Structure Example
  • Student database
  • Set of student records
  • Structure definition

struct Student char Initials2 short id
struct Student teammate typedef struct
Student SType
17
Arrays of Structures
  • Pointers to specific elements
  • Array of structure creation

define XYpt class0 define ABpt
class1 define RSpt class2 ... SType
class6 'X','Y',123, RSpt, //
XY 'A','B', 23, RYpt, // AB 'R','S',
11, XYpt, // RS ... 'R','Y',2457, ABpt
// RY
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
seatChart524 //2-D array
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, Tiwari, Janapa Reddi, Gerstlauer, Valvano,
Erez, Telang, Yerraballi
20
Lab 7 Lab 8 Lab 9
77 total
INTERRUPT VECTORS
Bard, Tiwari, Janapa Reddi, Gerstlauer, Valvano,
Yerraballi
21
Timer 2A Periodic interrupt
Max is 53 sec
unsigned long TimerCount void Timer2_Init(unsigne
d 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_R0x00FFFFFF)0x80000000 // 8)
priority 4 NVIC_EN0_R 1ltlt23 // 9)
enable IRQ 23 in TIMER2_CTL_R 0x00000001
// 10) enable timer2A
Output sound at 11.025 kHz
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
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.

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 dont 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
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
  • Cant 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
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.

27
Game Engine Call graph
28
Game Engine Data Flow
29
Game Engine Flowchart
Do not erase the LCD, it causes flicker
Could use GPIO interrupts
Write a Comment
User Comments (0)
About PowerShow.com