From 9bf12dcfaefbcb7281ed3d2895e92300e2d17619 Mon Sep 17 00:00:00 2001 From: Benjamin Ramhorst <59868635+bo3z@users.noreply.github.com> Date: Fri, 25 Mar 2022 18:16:21 +0000 Subject: [PATCH 1/2] Added new lines --- README.md | 112 +++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index e488403..76c103f 100644 --- a/README.md +++ b/README.md @@ -2,77 +2,77 @@ The following document outlines the design, implementation and real-time dependecies of a music synthesizer for the 2nd coursework of the Embedded Systems module. ## System tasks -The sytem at hand executes several real-time tasks, including: -*Reading the key matrix -*Updating the display -*Generating sound +The sytem at hand executes several real-time tasks, including: +* Reading the key matrix +* Updating the display +* Generating sound -### Reading the key matrix -**Purpose:** -*Decode the key matrix, obtaining the states of the keys, knobs and joysticks -*Obtain the currently selected note from the decoded key matrix -*Select the appopriate step size for the currently selected note -*Transmit the currently selected note, along side its state (pressed or released) using CAN -*Obtain any changes in the knobs from the decoded key matrix, corresponding to volume, octave or waveform +### Reading the key matrix +**Purpose:** +* Decode the key matrix, obtaining the states of the keys, knobs and joysticks +* Obtain the currently selected note from the decoded key matrix +* Select the appopriate step size for the currently selected note +* Transmit the currently selected note, along side its state (pressed or released) using CAN +* Obtain any changes in the knobs from the decoded key matrix, corresponding to volume, octave or waveform -**Function:** code(void scanKeysTask(void *pvParameters)) -**Implementation:** Thread, executing every 50ms -**Minimum initiation time:** TO BE COMPLETED. -**Maximum execution time:** TO BE COMPLETED. -**Priority:** Highest (1), as playing the appropriate sound is more important than updating the display. +**Function:** code(void scanKeysTask(void *pvParameters)) +**Implementation:** Thread, executing every 50ms +**Minimum initiation time:** TO BE COMPLETED. +**Maximum execution time:** TO BE COMPLETED. +**Priority:** Highest (1), as playing the appropriate sound is more important than updating the display. -### Updating the display -**Purpose:** -*Display the currently selected note (string) -*Display the current volume (int) -*Display the current octave (int) -*Display the current waveform (XMB icons) +### Updating the display +**Purpose:** +* Display the currently selected note (string) +* Display the current volume (int) +* Display the current octave (int) +* Display the current waveform (XMB icons) -**Function:** code(displayUpdateTask(void *pvParameters) -**Implementation:** Thread, executing every 100ms. While a refresh rate of 10Hz does not sound impressive; the display is largely static. Therefore, 100ms was perfectly accetable, without any noticeable delays. -**Minimum initiation time:** TO BE COMPLETED. -**Maximum execution time:** TO BE COMPLETED. -**Priority:** Lowest (2). +**Function:** code(displayUpdateTask(void *pvParameters) +**Implementation:** Thread, executing every 100ms. While a refresh rate of 10Hz does not sound impressive; the display is largely static. Therefore, 100ms was perfectly accetable, without any noticeable delays. +**Minimum initiation time:** TO BE COMPLETED. +**Maximum execution time:** TO BE COMPLETED. +**Priority:** Lowest (2). -### Generating the sound -**Purpose:** -*Adds the sample rate to the accumulated value, corresponding to the desired frequency -*Sets the output voltage, by using the accumlated value and the desired volume -*Writes to analogue output, generating the desired sound +### Generating the sound +**Purpose:** +* Adds the sample rate to the accumulated value, corresponding to the desired frequency +* Sets the output voltage, by using the accumlated value and the desired volume +* Writes to analogue output, generating the desired sound -**Function:** code(sampleISR()) -**Implementation:** Interrupt executing with a frequency of 44.1kHz -**Minimum initiation time:** TO BE COMPLETED. -**Maximum execution time:** TO BE COMPLETED. +**Function:** code(sampleISR()) +**Implementation:** Interrupt executing with a frequency of 44.1kHz +**Minimum initiation time:** TO BE COMPLETED. +**Maximum execution time:** TO BE COMPLETED. ### CAN **Purpose:** -* TO BE ADDED +* TO BE ADDED -**Function:** -**Implementation:** -**Minimum initiation time:** -**Maximum execution time:** -**Priority:** +**Function:** +**Implementation:** +**Minimum initiation time:** +**Maximum execution time:** +**Priority:** -## Critical instant analysis of the rate monotonic scheduler -TO BE ADDED - After system is completed. +## Critical instant analysis of the rate monotonic scheduler +TO BE ADDED - After system is completed. -## CPU Resource Usage -TO BE ADDED - After system is completed; see this link: https://edstem.org/us/courses/19499/discussion/1300057 +## CPU Resource Usage +TO BE ADDED - After system is completed; see this link: https://edstem.org/us/courses/19499/discussion/1300057 -## Shared data structures -Shared data structures: -*code(currentStepSize), safe access guaranteed using code(std::atomic) -*code(keyArray), each element within the array is of type code(std::atomic) -*msgInQ, handled by FreeRTOS -*code(RX_Message), handled by code(std::atomic_flag) +## Shared data structures +Shared data structures: +* code(currentStepSize), safe access guaranteed using code(std::atomic) +* code(keyArray), each element within the array is of type code(std::atomic) +* msgInQ, handled by FreeRTOS +* code(RX_Message), handled by code(std::atomic_flag) -It was desiced to use C++ code(std::atomic), as it is easier to use and implement, while providing the same functionality as a mutex. According to the documentation: *"Each instantiation and full specialization of the std::atomic template defines an atomic type. If one thread writes to an atomic object while another thread reads from it, the behavior is well-defined (see memory model for details on data races). In addition, accesses to atomic objects may establish inter-thread synchronization and order non-atomic memory accesses as specified by std::memory_order."* (https://en.cppreference.com/w/cpp/atomic/atomic) +It was desiced to use C++ code(std::atomic), as it is easier to use and implement, while providing the same functionality as a mutex. According to the documentation: *"Each instantiation and full specialization of the std::atomic template defines an atomic type. If one thread writes to an atomic object while another thread reads from it, the behavior is well-defined (see memory model for details on data races). In addition, accesses to atomic objects may establish inter-thread synchronization and order non-atomic memory accesses as specified by std::memory_order.*"(https://en.cppreference.com/w/cpp/atomic/atomic) -TODO - Expand on the memory model for std:: atomic. -TODO - Explain how FreeRTOS handles msgInQ. -TODO - Once CAN is completed, expand on the protection of RX_Message +TODO - Expand on the memory model for std::atomic. +TODO - Explain how FreeRTOS handles msgInQ. +TODO - Once CAN is completed, expand on the protection of RX_Message ## Analysis of inter-task blocking dependencies From 13509eb5e72c2a82d941cd7e0e289a96445b4327 Mon Sep 17 00:00:00 2001 From: Benjamin Ramhorst <59868635+bo3z@users.noreply.github.com> Date: Fri, 25 Mar 2022 19:16:07 +0000 Subject: [PATCH 2/2] Updated README.md for tasks and their minimum initiation time --- README.md | 63 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 76c103f..b818890 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,55 @@ # ELEC60013 Embedded Systems - Music Synthesizer Documentation The following document outlines the design, implementation and real-time dependecies of a music synthesizer for the 2nd coursework of the Embedded Systems module. -## System tasks -The sytem at hand executes several real-time tasks, including: -* Reading the key matrix +## System workload +The sytem at hand executes several real-time tasks, including: +* Scannng the key matrix +* CAN decoding task * Updating the display * Generating sound -### Reading the key matrix +### Scanning the key matrix +**Function:** ```void scanKeysTask(void *pvParameters))``` + **Purpose:** * Decode the key matrix, obtaining the states of the keys, knobs and joysticks * Obtain the currently selected note from the decoded key matrix * Select the appopriate step size for the currently selected note -* Transmit the currently selected note, along side its state (pressed or released) using CAN +* Transmit the currently selected note, along side its state (pressed or released) and octave using CAN * Obtain any changes in the knobs from the decoded key matrix, corresponding to volume, octave or waveform -**Function:** code(void scanKeysTask(void *pvParameters)) -**Implementation:** Thread, executing every 50ms -**Minimum initiation time:** TO BE COMPLETED. +**Implementation:** Thread +**Minimum initiation time:** 50ms. **Maximum execution time:** TO BE COMPLETED. -**Priority:** Highest (1), as playing the appropriate sound is more important than updating the display. +**Priority:** Highest, as obtaining the note, volume and octave is required for playing the sound, transmitting over CAN and displaying on the screen. All other tasks depend on the results obtained from scanning the key matrix. + +### Decode task +**Function:** ```void decodeTask(void *pvParameters))``` + +**Purpose:** +* Receive the incoming CAN message +* Decide whether the key was pressed, released or the message originated from the main synthesizer +* Update the array of currently active notes +* Set the current step size, with respect to the currently active note. + +**Implementation:** Thread +**Minimum initiation time:** 70ms, assuming an average speed of 14 notes per second for professional pianist, as explained in the following Journal article - https://www.thejournal.ie/worlds-fastest-pianist-1780480-Nov2014/. This thread is an example for which the initiation time is not set internally, which was the case for ```void scanKeysTask(void *pvParameters))```. Instead, this task is a thread, whose initiation time depends on the purpose of the system - in this case, the speed of the pianist. +**Maximum execution time:** TO BE COMPLETED. +**Priority:** Medium, due to a lower initiation time, compared to scanning the key matrix. Furthermore, in order to receive CAN messages, they had to be transmitted first - which is handled in ```scanKeyTask```. ### Updating the display +**Function:** code(displayUpdateTask(void *pvParameters) + **Purpose:** * Display the currently selected note (string) -* Display the current volume (int) +* Display the current volume (int) or an animated icon of the sound (XMB icon) * Display the current octave (int) -* Display the current waveform (XMB icons) +* Display the current waveform (XMB icons), including sawtooth, triangle, sine and rectangle. -**Function:** code(displayUpdateTask(void *pvParameters) -**Implementation:** Thread, executing every 100ms. While a refresh rate of 10Hz does not sound impressive; the display is largely static. Therefore, 100ms was perfectly accetable, without any noticeable delays. -**Minimum initiation time:** TO BE COMPLETED. +**Implementation:** Thread, executing every 100ms. +**Minimum initiation time:** 100ms. While a refresh rate of 10Hz sounds insufficient (compared to modern monitors); the display is largely static. Therefore, 100ms is a perfectly accetable design choice, without any noticeable delays. **Maximum execution time:** TO BE COMPLETED. -**Priority:** Lowest (2). +**Priority:** Lowest, there is no point in updating the display if the current note, volume or octave have not been update - all of which take placee in the scanning key matrix task. ### Generating the sound **Purpose:** @@ -40,21 +57,11 @@ The sytem at hand executes several real-time tasks, including: * Sets the output voltage, by using the accumlated value and the desired volume * Writes to analogue output, generating the desired sound -**Function:** code(sampleISR()) -**Implementation:** Interrupt executing with a frequency of 44.1kHz -**Minimum initiation time:** TO BE COMPLETED. +**Function:** ```sampleISR()``` +**Implementation:** Interrupt, executing with a frequency of 44.1kHz. An interrupt is chosen as responding quickly is needed for playing sound. Otherwise, delays between the key press and the sound would exist. +**Minimum initiation time:** 22.7ms. **Maximum execution time:** TO BE COMPLETED. -### CAN -**Purpose:** -* TO BE ADDED - -**Function:** -**Implementation:** -**Minimum initiation time:** -**Maximum execution time:** -**Priority:** - ## Critical instant analysis of the rate monotonic scheduler TO BE ADDED - After system is completed.