Book Image

ARM?? Cortex?? M4 Cookbook

By : Dr. Mark Fisher
Book Image

ARM?? Cortex?? M4 Cookbook

By: Dr. Mark Fisher

Overview of this book

Embedded microcontrollers are at the core of many everyday electronic devices. Electronic automotive systems rely on these devices for engine management, anti-lock brakes, in car entertainment, automatic transmission, active suspension, satellite navigation, etc. The so-called internet of things drives the market for such technology, so much so that embedded cores now represent 90% of all processor’s sold. The ARM Cortex-M4 is one of the most powerful microcontrollers on the market and includes a floating point unit (FPU) which enables it to address applications. The ARM Cortex-M4 Microcontroller Cookbook provides a practical introduction to programming an embedded microcontroller architecture. This book attempts to address this through a series of recipes that develop embedded applications targeting the ARM-Cortex M4 device family. The recipes in this book have all been tested using the Keil MCBSTM32F400 board. This board includes a small graphic LCD touchscreen (320x240 pixels) that can be used to create a variety of 2D gaming applications. These motivate a younger audience and are used throughout the book to illustrate particular hardware peripherals and software concepts. C language is used predominantly throughout but one chapter is devoted to recipes involving assembly language. Programs are mostly written using ARM’s free microcontroller development kit (MDK) but for those looking for open source development environments the book also shows how to configure the ARM-GNU toolchain. Some of the recipes described in the book are the basis for laboratories and assignments undertaken by undergraduates.
Table of Contents (16 chapters)
ARM Cortex M4 Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

How to write a multithreaded Pong game


To further illustrate how to use the features of CMSIS-RTOS that we've introduced in this chapter, we'll return to the Pong program that we first introduced in Chapter 2, C Language Programming. We'll call this recipe: RTOS_Pong_v8v0. Due to space limitations, we're only showing those parts of the code that are relevant to the RTOS implementation. Refer to Chapter 2, C Language Programming for details of helper functions defined in the pong_utils.c file.

How to do it…

To create a multithreaded pong game, follow the steps given:

  1. Create a new project (new folder) called RTOS_Pong. Set the RTE to include board support for the ADC and GLCD. Include CMSIS-RTOS.

  2. Create a file named RTOS_Pong.c and add a task to handle the GLCD:

    void taskGLCD (void const *argument) {
      BallInfo init_pstn = thisGame.ball;
    
      for (;;) {
        osEvent evt = osMailGet(mail_box, osWaitForever);
        if (evt.status == osEventMail) {
          mail_t *mail = (mail_t*)evt.value.p;
          thisGame...