root/nano-RK/projects/basic_eeprom/main.c

Revision 428, 4.0 kB (checked in by agr, 6 months ago)

flash flood update

Line 
1 /******************************************************************************
2 *  Nano-RK, a real-time operating system for sensor networks.
3 *  Copyright (C) 2007, Real-Time and Multimedia Lab, Carnegie Mellon University
4 *  All rights reserved.
5 *
6 *  This is the Open Source Version of Nano-RK included as part of a Dual
7 *  Licensing Model. If you are unsure which license to use please refer to:
8 *  http://www.nanork.org/nano-RK/wiki/Licensing
9 *
10 *  This program is free software: you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License as published by
12 *  the Free Software Foundation, version 2.0 of the License.
13 *
14 *  This program is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 *
22 *******************************************************************************/
23
24
25 #include <nrk.h>
26 #include <include.h>
27 #include <ulib.h>
28 #include <stdio.h>
29 #include <avr/sleep.h>
30 #include <hal.h>
31 #include <nrk_error.h>
32 #include <nrk_timer.h>
33 #include <nrk_stack_check.h>
34 #include <avr/eeprom.h>
35 #include <nrk_eeprom.h>
36
37
38 NRK_STK Stack1[NRK_APP_STACKSIZE];
39 nrk_task_type TaskOne;
40 void Task1(void);
41
42 NRK_STK Stack2[NRK_APP_STACKSIZE];
43 nrk_task_type TaskTwo;
44 void Task2 (void);
45
46
47 void nrk_create_taskset();
48
49 uint32_t mac_address;
50
51 int
52 main ()
53 {
54   uint8_t t;
55   nrk_setup_ports();
56   nrk_setup_uart(UART_BAUDRATE_115K2);
57  
58   nrk_kprintf( PSTR("Starting up...\r\n") );
59
60   nrk_init();
61
62   nrk_led_clr(ORANGE_LED);
63   nrk_led_clr(BLUE_LED);
64   nrk_led_clr(GREEN_LED);
65   nrk_led_clr(RED_LED);
66  
67   nrk_time_set(0,0);
68   nrk_create_taskset ();
69   nrk_start();
70  
71   return 0;
72 }
73
74
75
76 void Task1()
77 {
78 uint16_t cnt;
79 int8_t val;
80 uint8_t chan;
81 uint8_t i;
82
83 val=read_eeprom_mac_address(&mac_address);
84 if(val==NRK_OK)
85         {
86         nrk_kprintf( PSTR("MAC = 0x"));
87         printf( "%x",(uint8_t)((mac_address>>24)&0xff));
88         printf( "%x",(uint8_t)((mac_address>>16)&0xff));
89         printf( "%x",(uint8_t)((mac_address>>8)&0xff));
90         printf( "%x\r\n",(uint8_t)((mac_address & 0xff)));
91         }
92 else
93         {
94         while(1)       
95                 {
96                 nrk_kprintf( PSTR( "* ERROR reading MAC address\r\n" ));
97                 nrk_wait_until_next_period();
98                 }
99         }
100
101 val=read_eeprom_channel(&chan);
102 printf( "chan = %d\r\n",chan );
103
104   printf( "Task1 PID=%d\r\n",nrk_get_pid());
105   val=0;
106   i=0;
107   for(cnt=0x100; cnt<0x110; cnt++ )
108         {
109         nrk_eeprom_write_byte(cnt,i);
110         printf( "Wrote %u to %d\r\n",i,cnt);
111         i++;
112         }
113   for(cnt=0x100; cnt<0x110; cnt++ )
114         {
115         i=nrk_eeprom_read_byte(cnt);
116         printf( "Read %u from %d\r\n",i,cnt);
117         }
118
119
120   cnt=0;
121   while(1) {
122         nrk_led_toggle(ORANGE_LED);
123         nrk_gpio_toggle(NRK_DEBUG_0);
124         //printf( "Task1 cnt=%d\r\n",cnt );
125         nrk_wait_until_next_period();
126         cnt++;
127         }
128 }
129
130 void Task2()
131 {
132   uint8_t cnt;
133   printf( "Task2 PID=%d\r\n",nrk_get_pid());
134   cnt=0;
135   while(1) {
136         nrk_led_toggle(BLUE_LED);
137         nrk_gpio_toggle(NRK_DEBUG_1);
138         //printf( "Task2 cnt=%d\r\n",cnt );
139         nrk_wait_until_next_period();
140         cnt++;
141         }
142 }
143
144
145 void
146 nrk_create_taskset()
147 {
148   TaskOne.task = Task1;
149   nrk_task_set_stk( &TaskOne, Stack1, NRK_APP_STACKSIZE);
150   TaskOne.prio = 1;
151   TaskOne.FirstActivation = TRUE;
152   TaskOne.Type = BASIC_TASK;
153   TaskOne.SchType = PREEMPTIVE;
154   TaskOne.period.secs = 0;
155   TaskOne.period.nano_secs = 250*NANOS_PER_MS;
156   TaskOne.cpu_reserve.secs = 0;
157   TaskOne.cpu_reserve.nano_secs =  0;
158   TaskOne.offset.secs = 0;
159   TaskOne.offset.nano_secs= 0;
160   nrk_activate_task (&TaskOne);
161
162   TaskTwo.task = Task2;
163   nrk_task_set_stk( &TaskTwo, Stack2, NRK_APP_STACKSIZE);
164   TaskTwo.prio = 2;
165   TaskTwo.FirstActivation = TRUE;
166   TaskTwo.Type = BASIC_TASK;
167   TaskTwo.SchType = PREEMPTIVE;
168   TaskTwo.period.secs = 0;
169   TaskTwo.period.nano_secs = 500*NANOS_PER_MS;
170   TaskTwo.cpu_reserve.secs = 0;
171   TaskTwo.cpu_reserve.nano_secs = 100*NANOS_PER_MS;
172   TaskTwo.offset.secs = 0;
173   TaskTwo.offset.nano_secs= 0;
174   nrk_activate_task (&TaskTwo);
175
176 }
177
178
Note: See TracBrowser for help on using the browser.