Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
software:deep:rts:os [2011-06-08 11:08] – angelegt graf | software:deep:rts:os [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | The mpc555 can be programmed either using interrupts in a foreground/ | ||
- | When choosing a RTOS you can select a simple, robust and very efficient non-preemtive tasking system (class mpc555.Task). The very popular MicroC/OSII is also available. | ||
- | For both of the RTOS’s the minimum task period is limited to the order of milliseconds. For fast control applications you can use the decrementer as a fast running timer and pro-duce exceptions at a very high frequency. | ||
- | The basic modules are written in Component Pascal. All the necessary resources are made public and can be accessed by application code written in Java through a Java na-tive interface. | ||
- | 3.1 Class Constructors and the main() Method | ||
- | When starting up a Java system has to call the static constructor of every class loaded and finally calls the main method. Our system does not support a main method. This has the advantage that you can have as many top-level classes (or application classes) as you like. In Chapter 4.3 you can see how to build several top-level classes into the same project. | ||
- | An example of using a class constructor is shown in the following section. | ||
- | 3.2 Non-Preemptive Tasking System | ||
- | The class mpc555.Task offers a very efficient non-preemtive scheduler. The basic timing resolution is 1ms. You can create and install as many tasks as you like. Care must be taken that each of those tasks terminates after a reasonably short time span. Control is than taken over by the scheduler which chooses the next available task in a round-robin fashion. | ||
- | There are two types of tasks: ready tasks have a period of 0. That is they are sched-uled as quickly as possible. There repetition frequency depends highly on the processor load and the task code itself. Periodic tasks have a non-zero period. They get scheduled after the system time passes the assigned period of the task. | ||
- | The following code shows how to create and install a task. | ||
- | |||
- | public class TestTask extends Task{ | ||
- | |||
- | public void Do () { | ||
- | // put task code here | ||
- | } | ||
- | |||
- | static { | ||
- | TestTask task1 = new TestTask(); | ||
- | task1.period = 500; // call twice per second | ||
- | Task.install(task1); | ||
- | } | ||
- | } | ||
- | |||
- | 3.3 MicroC/ | ||
- | MicroC/OSII is a small and efficient operating system. It offers a preemtive real-time kernel and many useful features. It can manage up to 64 tasks with unique priorities as-signed to it. Each task has its own stack with different stack sizes. It provides further ser-vices like time management functions, events, mutexes and semaphores. Interrupts can suspend the execution of a task. If a higher priority task is awakened as a result of the in-terrupt, it will run immediately. | ||
- | For more details about this OS please refer to the book “MicroC/ | ||
- | In order to use this OS you have the edit the class mpc555.Exceptions. Set the con-stant | ||
- | UCosEnable = TRUE | ||
- | and recompile the class. As the board can be programmed in Java instead of C as in the original port of the MicroC/OS we have made some modification to the original system described in the book. These changes make the use of the MicroC/OS much more intui-tive and elegant. The following example shows how to create a task and start the OS. | ||
- | |||
- | public class uCOSDemo1 extends uCTask { | ||
- | |||
- | public void Do () { | ||
- | while (true) { | ||
- | Mpiosm.out(15, | ||
- | uCOS.OSTimeDly(10); | ||
- | } | ||
- | } | ||
- | |||
- | static { | ||
- | uCOS.OSInit(); | ||
- | Mpiosm.init(15, | ||
- | Mpiosm.out(15, | ||
- | uCTask t1 = new uCOSDemo1(); | ||
- | byte res = uCOS.OSTaskCreate(t1, | ||
- | uCOS.OSStart(); | ||
- | } | ||
- | } | ||
- | More examples can be found in the package mpc555Demo. For the modifications to the original system check the Javadoc. | ||
- | |||
- | 3.4 Interrupts | ||
- | The mpc555 has no hardware priorization scheme when dealing with interrupts. Also there is no interrupt vectoring. All the potential internal and external interrupt sources get vectored to the same memory location and are dealt with a software scheduler. You have to assign a level to each of the interrupts. A low level means a high priority. To achieve highest efficiency interrupt nesting is switched off. That makes it necessary to write small interrupt routines. | ||
- | 3.4.1 Internal Interrupts | ||
- | Internal interrupts are all those who are caused by built-in peripheral modules, like TPU, ADC and communication interfaces. You can use them by extending the class Interrupt, write your own Do-Method and install this object into the interrupt scheduler by calling installInternalProc. As parameter you have to indicate the interrupt object together with a level which has to be between 0 and 7. You can install any number of interrupt objects with the same level. | ||
- | |||
- | public class IntTest extends Interrupt { | ||
- | |||
- | public void Do() { | ||
- | // put your code here | ||
- | } | ||
- | |||
- | static { | ||
- | IntTest int = new IntTest(); | ||
- | int.enableRegAdr = registername; | ||
- | int.flagRegAdr = registername; | ||
- | Exceptions.installInternalIntProc(int, | ||
- | } | ||
- | } | ||
- | 3.4.2 External Interrupts | ||
- | The mpc555 offers 8 external interrupt inputs. They are named IRQ0 to IRQ7. In order to use them you have to extend the class Interrupt, overwrite its Do-method and call the method installExternalProc(). As parameters you have to give the newly allocated inter-rupt and the number of the interrupt pin which corresponds to the interrupt level. Care must be taken not to assign more than one interrupt objects to the same interrupt pin. | ||
- | |||
- | public class ExtIntTest extends Interrupt { | ||
- | |||
- | public void Do() { | ||
- | // put your code here | ||
- | } | ||
- | |||
- | static { | ||
- | ExtIntTest int5 = new ExtIntTest(); | ||
- | Exceptions.installExternalIntProc(int5, | ||
- | } | ||
- | } | ||
- | |||
- | The voltage level on the external interrupt pins 5, 6 and 7 also select the operating when starting the device up. Do not override these levels during start-up! | ||
- | 3.4.3 Switch off Interrupts Globally | ||
- | All the external and internal interrupts can be switched off and on again, e.g. for access-ing shared resources. Keep the switch-off time as low as possible. This should always be done in the following manner. | ||
- | |||
- | void MyExampleMethod () { | ||
- | int sr = 0; // local variable to hold the content of the status register | ||
- | // must be the first local variable declared | ||
- | your code goes here | ||
- | |||
- | Kernel.getInterruptState(); | ||
- | Kernel.disableInts(); | ||
- | |||
- | more code, critical section // interrupts now disabled | ||
- | |||
- | Kernel.setInterruptState(); | ||
- | |||
- | even more code // Interrupts enabled if enabled at start of method | ||
- | } | ||
- | |||
- | 3.5 Decrementer Exceptions | ||
- | The decrementer is a timer with a resolution of 1s. Therefore you can use it for very fast control applications. Simply extend the class decrementer and overwrite the Do-method with your specific code. Make sure to set the period in s to some meaningful value. You then have to call the installDecrementer method. | ||
- | |||
- | public class DecrementerTest extends Decrementer { | ||
- | static int count; | ||
- | |||
- | public void Do() { | ||
- | OutT.print(' | ||
- | count++; | ||
- | } | ||
- | |||
- | static { | ||
- | DecrementerTest d = new DecrementerTest(); | ||
- | d.period = 1000000; // period is 1 s | ||
- | Exceptions.installDecrementer(d); | ||
- | } | ||
- | } | ||
- | |||
- | Please make sure that your exception code is reasonably short and that the processor is able to finish prior to a new decrementer exception. | ||
- | 3.6 Floating Point Numbers in Exceptions | ||
- | In order to use the built in floating point unit of the processor the compiler has to in-clude the floating point registers when doing a context save. To minimize the associated overhead when not using floating point numbers in exceptions the user has to call the function enableFPU() from the package JOCS if floats are used. The call of this method also enables the machine of using the floating point unit while an exception is processed. If this call is forgotten the machine will through a floating point unavailable axception. | ||