SlideShare a Scribd company logo
© 2017 Arm Limited
Application Programming
Interface and
Final Application
© 2017 Arm Limited
2
Module Syllabus
Design and Implementation of Simple Application Programming Interface (API)
Final Application to Run on SoC: the Snake Game
• Reduce Application Power Consumption
© 2017 Arm Limited
3
Building a System on a Chip (SoC)
Memory
VGA
Peripheral
UART
Peripheral
Timer
Peripheral
GPIO
Peripheral
7-Segment
Peripheral
Arm CMSIS-Core
Application Programming Interface (API)
Application Design (e.g., Game)
Arm Cortex-M0
Processor
Hardware design
Software low-level drivers
& libraries programming
Software high-level
application development
Peripheral Drivers
AHB
Interrupt
© 2017 Arm Limited
4
API Overview
An API is a software abstract layer that can provide a standard programming interface for
applications developers.
For example, most OSs provide their own APIs to allow programmers to easily develop
their applications.
An API can provide a number of interface services, such as base services, graphic
interface, network services, etc.
There are a variety of commercial APIs available in the market, such as Java API, Windows
API, Google AJAX APIs, etc.
© 2017 Arm Limited
5
Develop a Simple API
In this module, we will develop a simple API for application development.
The API can provide generic, easy-to-use functions for the end-user by combining the
functions from both CMSIS and peripheral drivers.
For example, we can have a SoC initialization function to reset both the processor and
the peripherals.
Memory
VGA
Peripheral
UART
Peripheral
Timer
Peripheral
GPIO
Peripheral
7-Segment
Peripheral
Arm CMSIS
Application Programming Interface (API)
Arm Cortex-M0
Processor
Hardware
Software drivers Peripheral Drivers
AHB
Software API libraries
© 2017 Arm Limited
6
Hardware-Dependent Functions
API
Libraries
OS Shell Libraries
OS Kernel Libraries
Driver Libraries
Processor Mouse
UART VGA
……
Low-level libraries:
• Less generic
• Low programming efficiency
• More specific to hardware
• More control over low-level hardware
High-level API:
• Generic
• Easy-to-use
• High programming efficiency
• Not specific to hardware
• Less control over low-level hardware
printf (“helloworld!”)
How to choose a
specific device (e.g.,
VGA) to print?
Hardware
© 2017 Arm Limited
7
Call-Back Functions
To allow users to specify necessary low-level features, many APIs offer call-back functions
that enable users to control or specify the low-level hardware device in their application
code.
Usually, the call-back functions are accessible in the application program, where users can
modify or write their own code.
Main Function Call-Back Functions
Library Functions
Libraries
Application
Call Functions
Call Back
© 2017 Arm Limited
8
Retargeting
Similar to the call-back functions, in μVision development tools, we use a “retarget.c” file
to define these hardware-dependent functions, such as the “printf” function.
The retarget functions include:
Function Description
int fputc(int ch, FILE *f) Writes a character to the console
int fgetc(FILE *f) Read a character to the console
int ferror(FILE *f) Checks error indicator
void _sys_exit(int return_code) The library exit function. All exits from the library
eventually call _sys_exit().
© 2017 Arm Limited
9
Retargeting Examples
For example, you can retarget functions to the UART console.
Alternatively, you can retarget the output console to VGA.
int fputc(int ch, FILE *f) {
return (UartPutc(ch));
}
int fgetc(FILE *f) {
return (UartGetc());
}
int fputc(int ch, FILE *f) {
return (VGAPutc(ch));
}
© 2017 Arm Limited
10
Example of API Functions
API Functions Descriptions
void SoC_init(void) SoC initialization
void rectangle(int x1,int y1,int x2,int y2, int color) Draw a rectangle on the screen.
void clear_screen (void) Clean up the screen.
int read_switch Read the value of the 8-bit switches.
write_LED Write a value to the 8-bit LEDs.
void Display_Int_Times (void) Display the number of interrupts the occurred using the 7-segment display.
void delay(int value) Software delay program
char random (char min, char max) A simple random generator based on system tick
int KBHIT(void) Wait for keyboard hit.
Retarget functions Input/output console texts.
© 2017 Arm Limited
11
Game Application: Snake
In the lab associated with this module, you will write a Snake game application to
demonstrate your SoC.
Memory
VGA
Peripheral
UART
Peripheral
Timer
Peripheral
GPIO
Peripheral
7-Segment
Peripheral
Arm CMSIS-Core
Application Programming Interface (API)
Application Design (e.g., Game)
Arm Cortex-M0
Processor
Peripheral Drivers
AHB
© 2017 Arm Limited
12
Game Application: Snake
Here are some suggested game features:
• Basic features: snake moving, target reaching, length increasing, etc.
• Game instructions and current score are displayed in the VGA console.
• The position of targets can be randomly generated using system ticks.
• Increase the speed each time a target is reached.
• Game over on: (1) snake’s head touches the boundary, or (2) snake’s head touches its own body.
• Game can be paused and resumed.
© 2017 Arm Limited
13
Game Application: Snake
Try to make full use of all the hardware peripherals and software functions; for example:
• VGA: displaying the game elements (e.g., snake and boundaries) in the image region and displaying the game
information (e.g., current score, additional instructions) in the text console region
• UART: receiving commands (e.g., move up, down, left, right) from the keyboard
• Timer: triggering the movement of the snake or recording the time elapsed in a game
• 7-segment: displaying the time elapsed in a game
• GPIO output (LEDs): showing the current score
• GPIO input (switches): changing difficulty level, snake color, etc.
© 2017 Arm Limited
14
More Game Applications
A number of games can be
programmed by just using UART as
input and VGA as output; for example:
• PACMAN
• TETRIS
• BREAK
• TicTac
SNAKE
BREAK
© 2017 Arm Limited
15
Cortex-M0 Low-Power Features Review
Two architectural sleep modes:
• Normal sleep and deep sleep
Two instructions for entering sleep modes:
• WFE (wait for event) and WFI (wait for interrupt)
Sleep-on-exit feature
• Allow processor to stay in sleep mode as much as possible
Wakeup interrupt controller (WIC)
• An optional feature that allows the clock of the processor to be completely removed during deep sleep
Low-power design implementation
• Since the gate count is very low, the static leakage power is tiny when compared to other 32-bit processors.
© 2017 Arm Limited
16
Cortex-M0 Sleep Mode
The Cortex-M0 processor supports two sleep modes: normal sleep mode and deep sleep
mode.
The exact meaning and behaviors of the two modes depends on the implementation of
the microcontroller. For example,
• Normal sleep: switch off some of the clock signals
• Deep sleep: reduce voltage supply to the memory blocks, switch off additional components
To enter sleep mode, we can use WFE or WFI instructions.
The processor can exit the sleep mode if an event occurs.
© 2017 Arm Limited
17
System Control Register
The sleep feature can be programmed by accessing the system control register (SCR) in the
system control block (at address 0xE000ED10).
System control register (0xE000ED10)
Bits Field Description
0 Reserved -
1 SleepOnExit Sleep-on-exit enable bit
2 SleepDeep Sleep mode type bit, 0: normal sleep; 1: deep sleep
3 Reserved -
4 SeVOnPend Send event on pend bit; enable generation of event by a new interrupt
pending status
[31:5] Reserved -
SCR can be accessed by register symbol “SCB->SCR”; for example:
SCB -> SCR = 1<1; //Enable sleep-on-exit bit
© 2017 Arm Limited
18
Sleep-on-Exit
The sleep-on-exit feature does not carry out the unstacking process after the program
returns from ISR.
The power consumption is reduced since
• The execution of unnecessary programs in the main thread is avoided.
• The unnecessary stacking and unstacking operation is avoided.
Main Thread
WFI
Stacking
IRQ ISR
Sleep Sleep
Sleep-on-Exit
(no unstacking)
Time
Priority
© 2017 Arm Limited
19
Polling v Interrupts
A comparison of the two programming solutions for the same Snake application:
Initialization
Update snake direction
Keyboard hit
Move the snake
Hit wall
Game over
Delay for a short time
Yes
No
Yes
No
Interrupted by timer Keyboard hit
Initialization
Update
direction
Move
snake
Hit wall
Game over
Yes
No
Sleep
Interrupt Driven Mode
Polling Mode
© 2017 Arm Limited
20
Developing Low-Power Applications
In our application, we can reduce power consumption by using low-power features of
Cortex-M0. Some suggestions are listed below:
• Change your code structure and make it an interrupt-driven application. For example, in the Snake game,
– the movement of the snake can be triggered by the interrupt from the timer.
– use UART interrupt to receive commands from the keyboard.
Idle (sleep)
Timer ISR UART ISR
Interrupted by timer Keyboard hit
Sleep
Sleep
© 2017 Arm Limited
21
Developing Low-Power Applications
Try to make the processor stay in the sleep mode as much as possible. This will reduce the
processor duty cycle. For example,
• Use the sleep-on-exit feature to avoid unnecessary stacking/unstacking overheads and reduce the wakeup latency.
• Disable some of the peripherals if they are not frequently used; e.g., disable their clock sources.
Power
Time
Interrupt
Sleeping mode Average power
duty cycle

More Related Content

Similar to Lecture Presentation 11.pdfLecture Presentation 9.pdf fpga soc (20)

PPT
Arm processor
SHREEHARI WADAWADAGI
 
PPTX
Introduction to embedded System.pptx
Pratik Gohel
 
PDF
embedded system introduction to microcontrollers
BarER4
 
PDF
migrating from pic to m3
Wassim Smati
 
PDF
Dai0234 a migrating_from_pic_to_m3
Wassim Smati
 
PDF
Arm cm3 architecture_and_programmer_model
Ganesh Naik
 
PPT
ARM7TDMI-S_CPU.ppt
MostafaParvin1
 
PDF
arm
Pratik Gohel
 
PDF
ARM CORTEX M3 PPT
Gaurav Verma
 
PPT
ARM - Advance RISC Machine
EdutechLearners
 
PPTX
Lecture 1.pptx
GautamDhargalkar1
 
PDF
Chapter Two Hahhhhhhhhhhhhhhhhhhhhhhhndout RTES.pdf
hamsalubekana
 
PDF
Arm architecture overview
Sathish Arumugasamy
 
PPTX
Introduction to arm processor
RAMPRAKASHT1
 
PDF
18CS44-MODULE1-PPT.pdf
VanshikaRajvanshi1
 
DOCX
Chapter Two Hbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbandout RTES.docx
hamsalubekana
 
PPTX
Arm corrected ppt
anish jagan
 
PDF
Introduction to Embedded System
Emertxe Information Technologies Pvt Ltd
 
PPT
Introduction to embedded systems
Игорь Медведев
 
PDF
Embedded systems introduction
mohamed drahem
 
Arm processor
SHREEHARI WADAWADAGI
 
Introduction to embedded System.pptx
Pratik Gohel
 
embedded system introduction to microcontrollers
BarER4
 
migrating from pic to m3
Wassim Smati
 
Dai0234 a migrating_from_pic_to_m3
Wassim Smati
 
Arm cm3 architecture_and_programmer_model
Ganesh Naik
 
ARM7TDMI-S_CPU.ppt
MostafaParvin1
 
ARM CORTEX M3 PPT
Gaurav Verma
 
ARM - Advance RISC Machine
EdutechLearners
 
Lecture 1.pptx
GautamDhargalkar1
 
Chapter Two Hahhhhhhhhhhhhhhhhhhhhhhhndout RTES.pdf
hamsalubekana
 
Arm architecture overview
Sathish Arumugasamy
 
Introduction to arm processor
RAMPRAKASHT1
 
18CS44-MODULE1-PPT.pdf
VanshikaRajvanshi1
 
Chapter Two Hbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbandout RTES.docx
hamsalubekana
 
Arm corrected ppt
anish jagan
 
Introduction to Embedded System
Emertxe Information Technologies Pvt Ltd
 
Introduction to embedded systems
Игорь Медведев
 
Embedded systems introduction
mohamed drahem
 

Recently uploaded (20)

PDF
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
GitOps_Without_K8s_Training simple one without k8s
DanialHabibi2
 
PPTX
Day2 B2 Best.pptx
helenjenefa1
 
PPT
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PPTX
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
PPTX
Types of Bearing_Specifications_PPT.pptx
PranjulAgrahariAkash
 
PPTX
Green Building & Energy Conservation ppt
Sagar Sarangi
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
Thermal runway and thermal stability.pptx
godow93766
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
GitOps_Without_K8s_Training simple one without k8s
DanialHabibi2
 
Day2 B2 Best.pptx
helenjenefa1
 
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
Types of Bearing_Specifications_PPT.pptx
PranjulAgrahariAkash
 
Green Building & Energy Conservation ppt
Sagar Sarangi
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
Thermal runway and thermal stability.pptx
godow93766
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
Design Thinking basics for Engineers.pdf
CMR University
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
Ad

Lecture Presentation 11.pdfLecture Presentation 9.pdf fpga soc

  • 1. © 2017 Arm Limited Application Programming Interface and Final Application
  • 2. © 2017 Arm Limited 2 Module Syllabus Design and Implementation of Simple Application Programming Interface (API) Final Application to Run on SoC: the Snake Game • Reduce Application Power Consumption
  • 3. © 2017 Arm Limited 3 Building a System on a Chip (SoC) Memory VGA Peripheral UART Peripheral Timer Peripheral GPIO Peripheral 7-Segment Peripheral Arm CMSIS-Core Application Programming Interface (API) Application Design (e.g., Game) Arm Cortex-M0 Processor Hardware design Software low-level drivers & libraries programming Software high-level application development Peripheral Drivers AHB Interrupt
  • 4. © 2017 Arm Limited 4 API Overview An API is a software abstract layer that can provide a standard programming interface for applications developers. For example, most OSs provide their own APIs to allow programmers to easily develop their applications. An API can provide a number of interface services, such as base services, graphic interface, network services, etc. There are a variety of commercial APIs available in the market, such as Java API, Windows API, Google AJAX APIs, etc.
  • 5. © 2017 Arm Limited 5 Develop a Simple API In this module, we will develop a simple API for application development. The API can provide generic, easy-to-use functions for the end-user by combining the functions from both CMSIS and peripheral drivers. For example, we can have a SoC initialization function to reset both the processor and the peripherals. Memory VGA Peripheral UART Peripheral Timer Peripheral GPIO Peripheral 7-Segment Peripheral Arm CMSIS Application Programming Interface (API) Arm Cortex-M0 Processor Hardware Software drivers Peripheral Drivers AHB Software API libraries
  • 6. © 2017 Arm Limited 6 Hardware-Dependent Functions API Libraries OS Shell Libraries OS Kernel Libraries Driver Libraries Processor Mouse UART VGA …… Low-level libraries: • Less generic • Low programming efficiency • More specific to hardware • More control over low-level hardware High-level API: • Generic • Easy-to-use • High programming efficiency • Not specific to hardware • Less control over low-level hardware printf (“helloworld!”) How to choose a specific device (e.g., VGA) to print? Hardware
  • 7. © 2017 Arm Limited 7 Call-Back Functions To allow users to specify necessary low-level features, many APIs offer call-back functions that enable users to control or specify the low-level hardware device in their application code. Usually, the call-back functions are accessible in the application program, where users can modify or write their own code. Main Function Call-Back Functions Library Functions Libraries Application Call Functions Call Back
  • 8. © 2017 Arm Limited 8 Retargeting Similar to the call-back functions, in μVision development tools, we use a “retarget.c” file to define these hardware-dependent functions, such as the “printf” function. The retarget functions include: Function Description int fputc(int ch, FILE *f) Writes a character to the console int fgetc(FILE *f) Read a character to the console int ferror(FILE *f) Checks error indicator void _sys_exit(int return_code) The library exit function. All exits from the library eventually call _sys_exit().
  • 9. © 2017 Arm Limited 9 Retargeting Examples For example, you can retarget functions to the UART console. Alternatively, you can retarget the output console to VGA. int fputc(int ch, FILE *f) { return (UartPutc(ch)); } int fgetc(FILE *f) { return (UartGetc()); } int fputc(int ch, FILE *f) { return (VGAPutc(ch)); }
  • 10. © 2017 Arm Limited 10 Example of API Functions API Functions Descriptions void SoC_init(void) SoC initialization void rectangle(int x1,int y1,int x2,int y2, int color) Draw a rectangle on the screen. void clear_screen (void) Clean up the screen. int read_switch Read the value of the 8-bit switches. write_LED Write a value to the 8-bit LEDs. void Display_Int_Times (void) Display the number of interrupts the occurred using the 7-segment display. void delay(int value) Software delay program char random (char min, char max) A simple random generator based on system tick int KBHIT(void) Wait for keyboard hit. Retarget functions Input/output console texts.
  • 11. © 2017 Arm Limited 11 Game Application: Snake In the lab associated with this module, you will write a Snake game application to demonstrate your SoC. Memory VGA Peripheral UART Peripheral Timer Peripheral GPIO Peripheral 7-Segment Peripheral Arm CMSIS-Core Application Programming Interface (API) Application Design (e.g., Game) Arm Cortex-M0 Processor Peripheral Drivers AHB
  • 12. © 2017 Arm Limited 12 Game Application: Snake Here are some suggested game features: • Basic features: snake moving, target reaching, length increasing, etc. • Game instructions and current score are displayed in the VGA console. • The position of targets can be randomly generated using system ticks. • Increase the speed each time a target is reached. • Game over on: (1) snake’s head touches the boundary, or (2) snake’s head touches its own body. • Game can be paused and resumed.
  • 13. © 2017 Arm Limited 13 Game Application: Snake Try to make full use of all the hardware peripherals and software functions; for example: • VGA: displaying the game elements (e.g., snake and boundaries) in the image region and displaying the game information (e.g., current score, additional instructions) in the text console region • UART: receiving commands (e.g., move up, down, left, right) from the keyboard • Timer: triggering the movement of the snake or recording the time elapsed in a game • 7-segment: displaying the time elapsed in a game • GPIO output (LEDs): showing the current score • GPIO input (switches): changing difficulty level, snake color, etc.
  • 14. © 2017 Arm Limited 14 More Game Applications A number of games can be programmed by just using UART as input and VGA as output; for example: • PACMAN • TETRIS • BREAK • TicTac SNAKE BREAK
  • 15. © 2017 Arm Limited 15 Cortex-M0 Low-Power Features Review Two architectural sleep modes: • Normal sleep and deep sleep Two instructions for entering sleep modes: • WFE (wait for event) and WFI (wait for interrupt) Sleep-on-exit feature • Allow processor to stay in sleep mode as much as possible Wakeup interrupt controller (WIC) • An optional feature that allows the clock of the processor to be completely removed during deep sleep Low-power design implementation • Since the gate count is very low, the static leakage power is tiny when compared to other 32-bit processors.
  • 16. © 2017 Arm Limited 16 Cortex-M0 Sleep Mode The Cortex-M0 processor supports two sleep modes: normal sleep mode and deep sleep mode. The exact meaning and behaviors of the two modes depends on the implementation of the microcontroller. For example, • Normal sleep: switch off some of the clock signals • Deep sleep: reduce voltage supply to the memory blocks, switch off additional components To enter sleep mode, we can use WFE or WFI instructions. The processor can exit the sleep mode if an event occurs.
  • 17. © 2017 Arm Limited 17 System Control Register The sleep feature can be programmed by accessing the system control register (SCR) in the system control block (at address 0xE000ED10). System control register (0xE000ED10) Bits Field Description 0 Reserved - 1 SleepOnExit Sleep-on-exit enable bit 2 SleepDeep Sleep mode type bit, 0: normal sleep; 1: deep sleep 3 Reserved - 4 SeVOnPend Send event on pend bit; enable generation of event by a new interrupt pending status [31:5] Reserved - SCR can be accessed by register symbol “SCB->SCR”; for example: SCB -> SCR = 1<1; //Enable sleep-on-exit bit
  • 18. © 2017 Arm Limited 18 Sleep-on-Exit The sleep-on-exit feature does not carry out the unstacking process after the program returns from ISR. The power consumption is reduced since • The execution of unnecessary programs in the main thread is avoided. • The unnecessary stacking and unstacking operation is avoided. Main Thread WFI Stacking IRQ ISR Sleep Sleep Sleep-on-Exit (no unstacking) Time Priority
  • 19. © 2017 Arm Limited 19 Polling v Interrupts A comparison of the two programming solutions for the same Snake application: Initialization Update snake direction Keyboard hit Move the snake Hit wall Game over Delay for a short time Yes No Yes No Interrupted by timer Keyboard hit Initialization Update direction Move snake Hit wall Game over Yes No Sleep Interrupt Driven Mode Polling Mode
  • 20. © 2017 Arm Limited 20 Developing Low-Power Applications In our application, we can reduce power consumption by using low-power features of Cortex-M0. Some suggestions are listed below: • Change your code structure and make it an interrupt-driven application. For example, in the Snake game, – the movement of the snake can be triggered by the interrupt from the timer. – use UART interrupt to receive commands from the keyboard. Idle (sleep) Timer ISR UART ISR Interrupted by timer Keyboard hit Sleep Sleep
  • 21. © 2017 Arm Limited 21 Developing Low-Power Applications Try to make the processor stay in the sleep mode as much as possible. This will reduce the processor duty cycle. For example, • Use the sleep-on-exit feature to avoid unnecessary stacking/unstacking overheads and reduce the wakeup latency. • Disable some of the peripherals if they are not frequently used; e.g., disable their clock sources. Power Time Interrupt Sleeping mode Average power duty cycle