|
|
| Again, we will have to change folders. We will create a new file for this tutorial, but let's create it in the same directory we've been working with, so type | | Again, we will have to change folders. We will create a new file for this tutorial, but let's create it in the same directory we've been working with, so type |
| | | |
− | ::<code> cd contiki-2.7/examples/rime </code>
| + | <code> |
| + | cd contiki-2.7/examples/rime |
| + | </code> |
| | | |
| into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type | | into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type |
| | | |
− | ::<code> cp example-broadcast.c example-timer.c </code>
| + | <code> |
| + | cp example-broadcast.c example-timer.c |
| + | </code> |
| | | |
| into your terminal. You should now see a new file, "example-timer.c" in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial): | | into your terminal. You should now see a new file, "example-timer.c" in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial): |
| | | |
− | ::<code> gedit example-timer.c </code>
| + | <code> |
| + | gedit example-timer.c |
| + | </code> |
| | | |
| === Step 2 === | | === Step 2 === |
|
|
| There is currently a working example of an etimer in this code, so before we proceed, let's understand this. At the beginning of the process, it is declared with | | There is currently a working example of an etimer in this code, so before we proceed, let's understand this. At the beginning of the process, it is declared with |
| | | |
− | ::<code> static struct etimer et; </code>
| + | <code> |
| + | static struct etimer et; |
| + | </code> |
| | | |
| This creates an etimer instance. Within the while loop, it is set with the function | | This creates an etimer instance. Within the while loop, it is set with the function |
| | | |
− | ::<code> etimer_set(&et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); </code>
| + | <code> |
| + | etimer_set(&et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); |
| + | </code> |
| | | |
| This function takes the arguments: | | This function takes the arguments: |
| | | |
− | ::<code> etimer_set(struct etimer *et, clock_time_t interval); </code>
| + | <code> |
| + | etimer_set(struct etimer *et, clock_time_t interval); |
| + | </code> |
| | | |
| and sets the etimer et to expire after interval. | | and sets the etimer et to expire after interval. |
|
|
| After that, we see the line: | | After that, we see the line: |
| | | |
− | ::<code> PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); </code>
| + | <code> |
| + | PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); |
| + | </code> |
| | | |
| which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let's incorporate some other timers. | | which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let's incorporate some other timers. |
|
|
| To start simply, we are going to use a timer to just print out a message once it expires. Just below | | To start simply, we are going to use a timer to just print out a message once it expires. Just below |
| | | |
− | ::<code> static struct etimer et; </code>
| + | <code> |
| + | static struct etimer et; |
| + | </code> |
| | | |
| declare a timer with the line: | | declare a timer with the line: |
| | | |
− | ::<code> static struct timer t; </code>
| + | <code> |
| + | static struct timer t; |
| + | </code> |
| | | |
| Before the while loop, set the timer with the line: | | Before the while loop, set the timer with the line: |
| | | |
− | ::<code> timer_set(&t, CLOCK_SECOND * 10); </code>
| + | <code> |
| + | timer_set(&t, CLOCK_SECOND * 10); |
| + | </code> |
| | | |
| This sets the timer to expire after 10 seconds. | | This sets the timer to expire after 10 seconds. |
|
|
| Below the line | | Below the line |
| | | |
− | ::<code> printf("broadcast message sent\n"); </code>
| + | <code> |
| + | printf("broadcast message sent\n"); |
| + | </code> |
| | | |
| add in the code: | | add in the code: |
| | | |
Exception encountered, of type "Error"