Evolution of Microcontroller Firmware Development David Benjamin Overview
Evolution of Microcontroller Firmware Development David Benjamin
Overview o Traditional microcontroller firmware n n Polling Interrupts o Real-time Operating Systems o Demonstration
Polling o Polling is when a process continually evaluates the status of a register in an effort to synchronize program execution. o Polling is not widely used because it is an inefficient use of microcontroller resources.
Polling Example void main ( void ) { while(1) { while (!button 1_pressed); turn_on_led; while (!button 1_pressed); turn_off_led; } }
Interrupts o Interrupt as defined by Merriam Webster n to break in upon an action o Interrupt n An event that causes the Program Counter (PC) to change. These events can be internal or external. o Interrupt Service Routine (ISR) n Set of instructions that is executed when an interrupt occurs o Interrupt Vector n Memory address of the first instruction in the ISR.
Interrupts o Why should one use interrupts? n n Provides more efficient use of microcontroller resources. Provides a means to create firmware that can “multi-task”.
Interrupts o Interrupts are often prioritized within the system and are associated with a variety of on-chip and off-chip peripherals n Timers, A/D D/A converters, UART, GP I/O o A majority of the m. C interrupts can be enabled or disabled. n n n Globally Individually Those interrupts that cannot be disabled are called Non. Maskable Interrupts (NMI). o Interrupts can be nested. o Interrupts can occur at anyplace, at anytime. n ISRs should be kept short and fast.
What happens when an interrupt occurs?
Interrupts PC = 0 x 8 A 3 0 x 08 A 2 0 x 0 FE 0 XXX 0 x 08 A 3 SR = 0 x. FE 0 x 7 E XXX 0 x. FE STACK o The current program instruction completes execution. o The PC and status register values are placed on the stack. o The interrupt vector is loaded into the PC and SR is updated. o Program execution resumes with the first step of the ISR. o When the ISR has completed execution, the values of the PC and status registers are restored. o Program execution resumes with next instruction that would have occurred had the interrupt not taken place. Main() { … some code turn_on_led 1; turn_off_led 1; … } __interrupt void port 1_ISR(void) { disable_interrupts. . . reti } 0 x 08 A 2 0 x 08 A 3 0 x 0 FE 0
Interrupts vs. Polling o Allowed for more efficient use of the microcontroller. n n Faster program execution Multi-tasking o Facilitated the development of complex firmware. n Supports a modular approach to firmware design.
Real-time Operating Systems
Real-time Operating System o A real-time operating system (RTOS) is a multi-tasking operating system intended for real-time applications. n n Mainly used in embedded applications. Facilitates the creation of a real-time system. Tool for the real-time software developer. Provides a layer abstraction between the hardware and software.
Real-time Operating System o State n A unique operating condition of the system. o Task n A single thread of execution through a group of related states. o Task Manager n Responsible for maintaining the current state of each task. n Responsible for providing each task with execution time.
Real-time Operating System Collection of Tasks… Single Task
Real-time Operating System o A more detailed explanation state n A function void idle. State ( void ); n n Should be kept short and fast Should represent a logical step in the task p i. e. Evaluating different parts of an incoming message.
Real-time Operating System void idle. State( void ) { if (rx_buffer_full) { read_rx. Buffer; if (sync. Byte_received) { transition_to_work. State 1; } else { stay_in_idle. State; } }
Real-time Operating System o Event-driven n n Tasks are granted execution time, based on an event (interrupt). Tasks of higher priority are executed first (interrupt priorities). o Time sharing n n Each task is granted a given amount of time to execute. Tasks may also be granted execution time based on events. “Round-robin” approach Creates a more deterministic multi-tasking system.
Real-time Operating Systems void main ( void ) { init. System(); while (1) { work(); sleep(); } } void work (void) { do. Task(Recieve. Msg); do. Task(Process); do. Task(Transmitt. Response); } __interrupt void Timer_A (void) { wake. Up(); }
Real-time Operating System o Available commercially n Tiny. OS -an open source component-based operating system and platform targeting wireless sensor networks (WSNs). n Salvo - an RTOS developed by Pumpkin Inc. n Free. RTOS - free RTOS that runs on several architectures. n Dr. RTOS - works with ARM 7 o Implement a custom RTOS n Can be highly optimized to suit your application
Real-time Operating Systems o A tool for real-time software developers. o Allows increasingly complex systems to be developed in less time. o Provides a level abstraction between software and hardware. o Continues the evolution microcontroller system design.
Example Implementation o Example of RTOS application that requires wireless communication. o Hardware abstraction layer for the radio. Performs low-level interaction between m. C and radio. o Groups low-level interactions from the HAL into higher-level functions. n o o Sending a packet Middle-ware that provides a gateway between the application and RTOS. Application Protocol Radio Operation Layer CC 1100 HAL
Demonstration
Questions?
- Slides: 24