| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|