## 4 Mid-Layer Software EMIDE for User-Friendly Application Development Environment
### New MIROS Mid-Layer Software EMIDE
#### 4.3.1 The Design and Implementation of the EMIDE  
The objectives of EMIDE determine it to be designed as follows:  
_Decoupling the application space from the system space:_ Like the EJVM and the DLM, EMIDE should be able to decouple the application space from the system space and function as a bridge between these two spaces.  
_Machine code or interpreted code:_ The byte code is used in the EJVM application while the machine code is used in the ContikiDL module. Although the byte code can be platform independent, more energy and time will be consumed during its interpretation process. Therefore, the machine code is chosen in the EMIDE. In this way, EMIDE can address the challenge of better using the tight resource-constrained WSN nodes.  
_Pre-linked code or dynamic loading code:_ The pre-linked application code is used in most EJVMs [26; 27; 28; 29; 30; 31; 32] while the dynamic loading code is used in most DLMs [13; 33]. Compared with the dynamic loading code, the pre-linked code is smaller in size, and higher in execution efficiency. Moreover, the underlying system architectures can be simplified. Due to these reasons, the pre-linked approach is adopted in the EMIDE so that it can maintain a small memory footprint.  
_Application programming language:_ In most EJVMs, the language used in the application space (Java language) is different from the language used in the system space (commonly C language). As a result, two different run-time contexts should be created and this increases the complexity of the system architecture. In EMIDE, the application language is chosen to be the same as the systemlanguage. In so doing, the application code and the system code can call each other directly, thereby simplifying the system architecture.  
_Support of multitasking programming in the application:_ Multitasking programming is a fundamental requirement of the WSN application. In EMIDE, some mechanisms should be implemented to support the multitasking programming in the WSN application.  
_Support of callback from the system space to the application space:_ The callback from the system space to the application space is also needed in many cases, e.g., the low-level hardware ISR (interruption service routine) may need to be programmed in the application space. In these cases, the EMIDE should be responsible of this callback operation.  
_Prevention of the faults injected from the application space to the system space:_ Fault prevention is also needed in the EMIDE to prevent the faults injected from the application space to the low-level system space. The reliability of the EMIDE system can in this way be improved.  
According to the design concepts above, EMIDE can be described as a mid-layer software that decouples the application code from the system code; acts as a bridge between the application space and the system space; supports multitasking programming in the application space; generates the pre-linked and machine-code application image; and is efficient in both the memory and energy cost.  
To implement EMIDE, several topics should be realized, including the implementation of the mechanism to pre-link the application system-call functions to the corresponding system service functions (Figure 11); the implementation of the mechanism to access the system global variables from the application program (using the \"application system-call and global variable address returning\" mechanism); the implementation of the mechanisms to achieve the callback operation and the multitasking programming (using the \"callback registration and task registration\" mechanisms); the implementation of the mechanism to prevent the application faults injected into the system space (using the \"range checking and stack boundary checking\" mechanisms). In the technical report [34], the implementation of the EMIDE software is presented in detail.  
Figure 11: Elementary diagram of the EMIDE development process. The pre-linking is performed during the post-built process.