182 694 microcontroller vu
play

182.694 Microcontroller VU Martin Perner SS 2017 Featuring Today: - PowerPoint PPT Presentation

182.694 Microcontroller VU Martin Perner SS 2017 Featuring Today: TinyOS Part 2 Weekly Training Objective Already done 3.4.1 Input capture 3.6.3 SPI 3.7.2 Watchdog This week 4.2.1 UART to GLCD 4.2.2 Keypad 4.2.3 Debounced


  1. 182.694 Microcontroller VU Martin Perner SS 2017 Featuring Today: TinyOS Part 2

  2. Weekly Training Objective Already done 3.4.1 Input capture 3.6.3 SPI ∗ 3.7.2 Watchdog ∗ This week 4.2.1 UART to GLCD † 4.2.2 Keypad 4.2.3 Debounced Buttons ∗ Martin Perner TinyOS Part 2 May 22, 2017 2

  3. TinyOS – Recap TinyOS is a small operating system that is designed to run on low-power wireless sensor nodes, and networked embedded systems. provides a set of important services and abstractions. defines a concurrent execution model. is written in nesC, which is a C dialect. can be seen as a mixture of OOP and hardware wiring. Martin Perner TinyOS Part 2 May 22, 2017 3

  4. TinyOS first steps Flash an example application in apps/Blink/ execute $ make bigAVR6 1280 with connected board execute $ make bigAVR6 1280 install A binary is generated and downloaded. Hint $ make bigAVR6 1280 install,id Sets TOS NODE ID to the value of id . This can be used, e.g., for defining the IP address of the node, or allow for different functionality (master/slave). Martin Perner TinyOS Part 2 May 22, 2017 4

  5. Interfaces Enabling reusability Multiple interfaces can be used/provided. Interfaces are bidirectional. command , implemented by provider of the interface, called by user. event , implemented by user of the interface, signaled by provider. Bidirectionality is the basis for split-phase. Martin Perner TinyOS Part 2 May 22, 2017 5

  6. Example Interface A generic timer interface – Timer.nc i n t e r f a c e Timer < p r e c i s i o n t a g > { command void s t a r t P e r i o d i c ( u i n t 3 2 t dt ) ; command void startOneShot ( u i n t 3 2 t dt ) ; command void stop ( ) ; event f i r e d ( ) ; void . . . } Interface, and thus timer-usage, independent of microcontroller used. Martin Perner TinyOS Part 2 May 22, 2017 6

  7. Configurations Wiring TinyOS only allows to wire interfaces. This wiring is done in configurations. Connecting interfaces of components via -> resp. <- The arrow goes from user to provider! Connecting an interface of the configuration to an interface of a component is done with = Martin Perner TinyOS Part 2 May 22, 2017 7

  8. Example Configuration Configuration Boot c o n f i g u r a t i o n DemoC { uses i n t e r f a c e Boot ; p r o v i d e s i n t e r f a c e MoreMagic ; } DemoC implementation { components DemoP, MakeMagicC ; Boot = DemoP . Boot ; MoreMagic MoreMagic = MakeMagicC . MoreMagic ; MakeMagicC . Magic − > DemoP . Magic ; } Martin Perner TinyOS Part 2 May 22, 2017 8

  9. Example Configuration Boot Configuration DemoC c o n f i g u r a t i o n DemoC { uses i n t e r f a c e Boot ; p r o v i d e s i n t e r f a c e MoreMagic ; } MoreMagic Magic implementation Boot { components DemoP, MakeMagicC ; Boot = DemoP . Boot ; MakeMagicC DemoP MoreMagic = MakeMagicC . MoreMagic ; MakeMagicC . Magic − > DemoP . Magic ; } Magic MoreMagic Martin Perner TinyOS Part 2 May 22, 2017 8

  10. Example Configuration Boot Configuration DemoC c o n f i g u r a t i o n DemoC { uses i n t e r f a c e Boot ; p r o v i d e s i n t e r f a c e MoreMagic ; } Magic implementation { components DemoP, MakeMagicC ; Boot = DemoP . Boot ; MakeMagicC DemoP MoreMagic = MakeMagicC . MoreMagic ; MakeMagicC . Magic − > DemoP . Magic ; } Magic MoreMagic Martin Perner TinyOS Part 2 May 22, 2017 8

  11. Example Configuration Boot Configuration Boot c o n f i g u r a t i o n DemoC DemoP { uses i n t e r f a c e Boot ; p r o v i d e s i n t e r f a c e MoreMagic ; } DemoC implementation { MakeMagicC components DemoP, MakeMagicC ; Boot = DemoP . Boot ; MoreMagic MoreMagic = MakeMagicC . MoreMagic ; MakeMagicC . Magic − > DemoP . Magic ; MoreMagic } Martin Perner TinyOS Part 2 May 22, 2017 8

  12. Example Module Modules – Where code is placed module DemoP Boot { uses i n t e r f a c e Boot ; p r o v i d e s i n t e r f a c e Magic ; } DemoP implementation { event void Boot . booted () { . . . } Magic command i n t Magic . get ( ) { . . . } } Martin Perner TinyOS Part 2 May 22, 2017 9

  13. Function Examples Required by Interface Command function: ( async ) command u i n t 8 t f ( u i n t 8 t x ) ; y = c a l l f ( x ) ; Event function: ( async ) event void am ready ( u i n t 8 t x ) ; s i g n a l am ready ( x ) ; To be used inside a module Task: task void f ( ) ; post f ( ) ; Plain function: u i n t 8 t f ( u i n t 8 t x ) ; y = f ( x ) ; Martin Perner TinyOS Part 2 May 22, 2017 10

  14. Split-Phase Classic Approach call f ( x ) return; y = f ( x ) f ( x ) f ( x ) access some hardware, and has to wait for a signal by the hardware. After calling f ( x ) the exeuction blocks until completion (busy waiting . . . ) Martin Perner TinyOS Part 2 May 22, 2017 11

  15. Split-Phase The Split-Phase Approach call f ( x ) signals fdone ( y ) return start f ( x ) y = f ( x ) is done After calling f ( x ) , the execution is started in the background. The caller receives a callback (event) upon completion of f ( x ) . Martin Perner TinyOS Part 2 May 22, 2017 12

  16. Deferred Task Execution Function call call f ( x ) f ( x ) cont. f ( x ) signal/call g ( z ) g ( z ) etc. Assume that the return value and the side-effects of g ( · ) are not required by f ( · ) . Why should we wait? Martin Perner TinyOS Part 2 May 22, 2017 13

  17. Deferred Task Execution Post a Task call f ( x ) f ( x ) post g () g () Task have no parameters. Parameter passing needs to be done with state-variables in the module. A task can only be posted once onto the tasklist. Martin Perner TinyOS Part 2 May 22, 2017 14

  18. Booting How is TinyOS booted? We have seen the interface Boot of MainC being used for initialization. It provides an event booted , which is called after start-up of the system. Martin Perner TinyOS Part 2 May 22, 2017 15

  19. Booting tos/system/MainC.nc #i n c l u d e ” hardware . h” c o n f i g u r a t i o n MainC { p r o v i d e s i n t e r f a c e Boot ; uses i n t e r f a c e I n i t as S o f t w a r e I n i t ; } implementation { components PlatformC , RealMainP , TinySchedulerC ; RealMainP . Scheduler − > TinySchedulerC ; RealMainP . P l a t f o r m I n i t − > PlatformC ; // Export the S o f t w a r e I n i t and Booted f o r a p p l i c a t i o n s S o f t w a r e I n i t = RealMainP . S o f t w a r e I n i t ; Boot = RealMainP ; } Martin Perner TinyOS Part 2 May 22, 2017 16

  20. Booting tos/system/RealMainP.nc module RealMainP @safe () { provides interface Boot; uses interface Scheduler; uses interface Init as PlatformInit; uses interface Init as SoftwareInit; } implementation { int main() @C() @spontaneous () { atomic { platform_bootstrap (); call Scheduler.init (); call PlatformInit.init (); while (call Scheduler.runNextTask ()); call SoftwareInit.init (); while (call Scheduler.runNextTask ()); } __nesc_enable_interrupt (); signal Boot.booted (); call Scheduler.taskLoop (); return -1; } default command error_t PlatformInit.init() { return SUCCESS; } default command error_t SoftwareInit.init() { return SUCCESS; } default event void Boot.booted (){} } Martin Perner TinyOS Part 2 May 22, 2017 17

  21. How many instances of a Component are there? Do we care? If we need some boot-up initialization, we use MainC and the Boot interface Do we get a new component every time we use it? No, components are “singletons” (there is only one) What can we do if we want two instances of a stateful component? (e.g., Queue) Generic Components Add generic in front of signature of configuration/module Instantiate with new keyword We can pass parameters, and even types, at instantiation. Martin Perner TinyOS Part 2 May 22, 2017 18

  22. Generic Components – Examples QueueC.nc g e n e r i c module QueueC ( typedef queue t , u i n t 8 t queueSize ) { p r o v i d e s i n t e r f a c e Queue < queue t > ; } . . . SomeThing g e n e r i c c o n f i g u r a t i o n SomeThing () { . . . } implementation { components new QueueC ( u i n t 8 t , 5) as Queue ; . . . } Martin Perner TinyOS Part 2 May 22, 2017 19

  23. Generic Component Limitation Contrary to, e.g., C++, the type checking happens on declaration At this point, the used type is unknown Does x + 1 compile for very type used for x ? The attribute @integer() can be applied to the declaration for some type assumptions. WeirdC g e n e r i c module WeirdC ( typedef f o o t @ i n t e g e r ( ) ) { . . . } Martin Perner TinyOS Part 2 May 22, 2017 20

  24. Abstract Data Type (ADT) Does a type argument to a component helps? How can we use it in an interface? Use a typed interface! QueueC.nc i n t e r f a c e Queue < t > { . . . command t head ( ) ; . . . } Martin Perner TinyOS Part 2 May 22, 2017 21

  25. Recap – Fan-In and Fan-Out What happens if an interface is connected to multiple component If there are multiple modules connected to the same interface, then All connected providers of a command receive the call. All connected users of an event are signaled. The order is not defined! Generally, there is no possibility to determine whose signal caused an event. The last item can be circumvented by using parameterized interfaces. Martin Perner TinyOS Part 2 May 22, 2017 22

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend