more updates
[phd-thesis.git] / top / 4iot.tex
index 095b276..039af94 100644 (file)
@@ -4,11 +4,10 @@
 
 \begin{document}
 \input{subfileprefix}
-
-\chapter{\texorpdfstring{\Glsxtrshort{TOP} for the \glsxtrshort{IOT}}{TOP for the IoT}}%
+\chapter{\texorpdfstring{\Glsxtrlong{TOP} for the \glsxtrlong{IOT}}{Task-oriented programming for the internet of things}}%
 \label{chp:top4iot}
 \begin{chapterabstract}
-       This chapter:
+       \noindent This chapter:
        \begin{itemize}
                \item introduces the problems with \gls{TOP} for the \gls{IOT}.
                \item shows how to create the \emph{Hello World!} application for microcontrollers using \gls{ARDUINO};
@@ -19,7 +18,7 @@
        \end{itemize}
 \end{chapterabstract}
 
-The edge layer of \gls{IOT} system mostly consists of microcontrollers.
+The edge layer of \gls{IOT} systems predominantly contains of microcontrollers.
 Microcontrollers are tiny computers designed specifically for embedded applications.
 They therefore only have a soup\c{c}on of memory, have a slow processor, come with many energy efficient sleep modes and have a lot of peripheral support such as \gls{GPIO} pins.
 Usually, programming microcontrollers requires an elaborate multi-step toolchain of compilation, linkage, binary image creation, and burning this image onto the flash memory of the microcontroller in order to compile and run a program.
@@ -38,17 +37,19 @@ The programs are usually cyclic executives instead of tasks running in an operat
                Storage & \qty{1}{\tebi\byte} & \qty{32}{\kibi\byte} & \qtyrange{0.5}{4}{\mebi\byte}\\
                \gls{RAM} & \qtyrange{4}{16}{\gibi\byte} & \qty{2}{\kibi\byte} & \qty{160}{\kibi\byte}\\
                Power & \qtyrange{50}{100}{\watt} & \qtyrange{0.13}{250}{\milli\watt} & \qtyrange{0.1}{350}{\milli\watt}\\
+               Size & $\pm$\qty{1060}{\cubic\cm} & $\pm$\qty{7.5}{\cubic\cm} & $\pm$\qty{1.1}{\cubic\cm}\\
                Price & \euro{1500} & \euro{3} & \euro{4}\\
                \bottomrule
        \end{tabular}
 \end{table}
 
-Each type of microcontrollers comes with vendor-provided drivers, compilers and \glspl{RTS} but there are many platform that abstract away from this such as \gls{MBED} and \gls{ARDUINO} of which \gls{ARDUINO} is specifically designed for education and prototyping and hence used here.
-The popular \gls{ARDUINO} \gls{C}\slash\gls{CPP} dialect and accompanying libraries provide an abstraction layer for common microcontroller behaviour allowing the programmer to program multiple types of microcontrollers using a single language.
+Different models of microcontrollers require their own vendor-provided drivers, hardware abstraction layer, compilers and \glspl{RTS}.
+There are many platforms that abstract away from this such as \gls{MBED} and \gls{ARDUINO} of which \gls{ARDUINO} is specifically designed for education and prototyping and hence used here.
+The popular \gls{ARDUINO} \ccpp{} dialect and accompanying libraries provide an abstraction layer for common microcontroller behaviour allowing the programmer to program multiple types of microcontrollers using a single language.
 Originally it was designed for the in-house developed open-source hardware with the same name but the setup allows porting to many architectures.
 It provides an \gls{IDE} and toolchain automation to perform all steps of the toolchain with a single command.
 
-\section{\texorpdfstring{\Glsxtrlong{TOP}}{Task-oriented programming}}
+\subsection{\texorpdfstring{\Glsxtrshort{TOP} for the \glsxtrshort{IOT}}{TOP for the IoT}}
 \Gls{TOP} is a programming paradigm that allows multi-tier systems to be generated from a single declarative source.
 \Gls{ITASK} is a general-purpose \gls{TOP} system for programming distributed web applications.
 These distributed web applications often form the core of \gls{IOT} applications as well but integrating these devices in \gls{ITASK} is not straightforward.
@@ -64,7 +65,7 @@ On microcontrollers, there usually is no screen for displaying text.
 Nevertheless, almost always there is a built-in monochrome $1\times1$ pixel screen, namely \pgls{LED}.
 The \emph{Hello World!} equivalent on microcontrollers blinks this \gls{LED}.
 
-\Cref{lst:arduinoBlink} shows how the logic of a blink program might look when using \gls{ARDUINO}'s \gls{C}\slash\gls{CPP} dialect.
+\Cref{lst:arduinoBlink} shows how the logic of a blink program might look when using \gls{ARDUINO}'s \ccpp{} dialect.
 Every \gls{ARDUINO} program contains a \arduinoinline{setup} and a \arduinoinline{loop} function.
 The \arduinoinline{setup} function is executed only once on boot, the \arduinoinline{loop} function is continuously called afterwards and contains the event loop.
 After setting the \gls{GPIO} pin to the correct mode, blink's \arduinoinline{loop} function alternates the state of the pin representing the \gls{LED} between \arduinoinline{HIGH} and \arduinoinline{LOW}, turning the \gls{LED} off and on respectively.
@@ -89,8 +90,7 @@ void loop() {
        delay(500);
        digitalWrite(D2, LOW);
        delay(500);
-}
-               \end{lstArduino}
+}\end{lstArduino}
        \end{subfigure}%
        \begin{subfigure}[b]{.5\linewidth}
                \begin{lstClean}[caption={Blink program.},label={lst:blinkImp}]
@@ -103,12 +103,11 @@ blink =
                >>|. writeD d2 false
                >>|. delay (lit 500)
        )
-}
-               \end{lstClean}
+}\end{lstClean}
        \end{subfigure}
 \end{figure}
 
-\section{Threaded blinking}
+\section{Multi tasking}
 Now say that we want to blink multiple blinking patterns on different \glspl{LED} concurrently.
 For example, blink three \glspl{LED} connected to \gls{GPIO} pins $1,2$ and $3$ at intervals of \qtylist{500;300;800}{\ms}.
 Intuitively you want to lift the blinking behaviour to a function and call this function three times with different parameters as done in \cref{lst:blinkthreadno}
@@ -161,7 +160,7 @@ void loop() {
 This method is very error prone, requires a lot of pointer juggling and generally results into spaghetti code.
 Furthermore, it is very difficult to represent dependencies between threads, often state machines have to be explicitly programmed by hand to achieve this.
 
-\section{Threaded blinking in \texorpdfstring{\gls{MTASK}}{mTask}}
+\subsection{Multi tasking in \texorpdfstring{\gls{MTASK}}{mTask}}
 The \cleaninline{delay} \emph{task} does not block the execution but \emph{just} emits no value when the target waiting time has not yet passed and emits a stable value when the time is met.
 In contrast, the \arduinoinline{delay()} \emph{function} on the \gls{ARDUINO} is blocking which prohibits interleaving.
 To make code reuse possible and make the implementation more intuitive, the blinking behaviour is lifted to a recursive function instead of using the imperative \cleaninline{rpeat} construct.
@@ -190,14 +189,18 @@ blinktask =
 % VimTeX: SynIgnore off
 
 \section{Conclusion}
-\todo[inline]{write}
+The edge layer of \gls{IOT} systems is powered by microcontrollers.
+Programming them happens through compiled firmwares using low-level imperative programming languages.
+Due to the lack of an \gls{OS}, writing applications that perform multiple tasks at the same time is error prone, and complex; and requires a lot of boilerplate and manual scheduling code.
+With the \gls{MTASK} system, a \gls{TOP} programming language for \gls{IOT} edge devices, this limitation can be overcome.
+\todo{uit\-breiden}
 
 \begin{subappendices}
 \section{History of \texorpdfstring{\gls{MTASK}}{mTask}}
 The development of \gls{MTASK} or its predecessors has been going on for almost seven years now though it really set off during my master's thesis.
 This section provides an exhaustive overview of the work on \gls{MTASK} and its predecessors.
 
-\subsection*{Generating \texorpdfstring{\gls{C}/\gls{CPP}}{C/C++} code}
+\subsection*{Generating \texorpdfstring{\ccpp{}}{\ccpp{}} code}
 A first throw at a class-based shallowly \gls{EDSL} for microcontrollers was made by \citet{plasmeijer_shallow_2016}.
 The language was called \gls{ARDSL} and offered a type safe interface to \gls{ARDUINO} \gls{CPP} dialect.
 A \gls{CPP} code generation backend was available together with an \gls{ITASK} simulation backend.
@@ -212,7 +215,7 @@ In this way, entire \gls{IOT} systems could be programmed from a single source.
 However, this version used a simplified version of \gls{MTASK} without functions.
 This was later improved upon by creating a simplified interface where \glspl{SDS} from \gls{ITASK} could be used in \gls{MTASK} and the other way around \citep{lubbers_task_2018}.
 It was shown by \citet{amazonas_cabral_de_andrade_developing_2018} that it was possible to build real-life \gls{IOT} systems with this integration.
-Moreover, a course on the \gls{MTASK} simulator was provided at the 2018 \gls{CEFP}/\gls{3COWS} winter school in Ko\v{s}ice, Slovakia \citep{koopman_simulation_2018}.
+Moreover, a course on the \gls{MTASK} simulator was provided at the 2018 \gls{CEFP}\slash\gls{3COWS} winter school in Ko\v{s}ice, Slovakia \citep{koopman_simulation_2018}.
 
 \subsection*{Transition to \texorpdfstring{\gls{TOP}}{TOP}}
 The \gls{MTASK} language as it is now was introduced in 2018 \citep{koopman_task-based_2018}.
@@ -220,7 +223,7 @@ This paper updated the language to support functions, simple tasks, and \glspl{S
 Later the byte code compiler and \gls{ITASK} integration was added to the language \citep{lubbers_interpreting_2019}.
 Moreover, it was shown that it is very intuitive to write microcontroller applications in a \gls{TOP} language \citep{lubbers_multitasking_2019}.
 One reason for this is that a lot of design patterns that are difficult using standard means are for free in \gls{TOP} (e.g.\ multithreading).
-In 2019, the \gls{CEFP} summer school in Budapest, Hungary hosted a course on developing \gls{IOT} applications with \gls{MTASK} as well \citep{lubbers_writing_2019}.
+In 2019, the \gls{CEFP}\slash\gls{3COWS} summer school in Budapest, Hungary hosted a course on developing \gls{IOT} applications with \gls{MTASK} as well \citep{lubbers_writing_2019}.
 
 \subsection*{\texorpdfstring{\Glsxtrshort{TOP}}{TOP}}
 In 2022, the SusTrainable summer school in Rijeka, Croatia hosted a course on developing greener \gls{IOT} applications using \gls{MTASK} as well \citep{lubbers_green_2022}.
@@ -233,7 +236,7 @@ An existing smart campus application was developed using \gls{MTASK} and quantit
 This research was later extended to include a four-way comparison: \gls{PYTHON}, \gls{MICROPYTHON}, \gls{ITASK}, and \gls{MTASK} \citep{lubbers_could_2022}.
 Currently, power efficiency behaviour of traditional versus \gls{TOP} \gls{IOT} stacks is being compared as well adding a \gls{FREERTOS} implementation to the mix as well.
 
-\subsection*{Future}
+\subsection*{Future work}
 Plans for extensions and improvements include exploring integrating \gls{TINYML} into \gls{MTASK}; adding intermittent computing support to \gls{MTASK}; and extending the formal semantics to cover the entirety of the language.
 In 2023, the SusTrainable summer school in Coimbra, Portugal will host a course on \gls{MTASK} as well.