1 |
3 |
iztok |
/*************************************************************************
|
2 |
|
|
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
3 |
|
|
* All rights reserved. All use of this software and documentation is *
|
4 |
|
|
* subject to the License Agreement located at the end of this file below.*
|
5 |
|
|
**************************************************************************
|
6 |
|
|
* Description: *
|
7 |
|
|
* The following is a simple hello world program running MicroC/OS-II.The *
|
8 |
|
|
* purpose of the design is to be a very simple application that just *
|
9 |
|
|
* demonstrates MicroC/OS-II running on NIOS II.The design doesn't account*
|
10 |
|
|
* for issues such as checking system call return codes. etc. *
|
11 |
|
|
* *
|
12 |
|
|
* Requirements: *
|
13 |
|
|
* -Supported Example Hardware Platforms *
|
14 |
|
|
* Standard *
|
15 |
|
|
* Full Featured *
|
16 |
|
|
* Low Cost *
|
17 |
|
|
* -Supported Development Boards *
|
18 |
|
|
* Nios II Development Board, Stratix II Edition *
|
19 |
|
|
* Nios Development Board, Stratix Professional Edition *
|
20 |
|
|
* Nios Development Board, Stratix Edition *
|
21 |
|
|
* Nios Development Board, Cyclone Edition *
|
22 |
|
|
* -System Library Settings *
|
23 |
|
|
* RTOS Type - MicroC/OS-II *
|
24 |
|
|
* Periodic System Timer *
|
25 |
|
|
* -Know Issues *
|
26 |
|
|
* If this design is run on the ISS, terminal output will take several*
|
27 |
|
|
* minutes per iteration. *
|
28 |
|
|
**************************************************************************/
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
#include <stdio.h>
|
32 |
|
|
#include "includes.h"
|
33 |
|
|
|
34 |
|
|
#include "ownet.h"
|
35 |
|
|
#include "temp10.h"
|
36 |
|
|
#include "findtype.h"
|
37 |
|
|
|
38 |
|
|
// defines
|
39 |
|
|
#define MAXDEVICES 20
|
40 |
|
|
#define ONEWIRE_P 0
|
41 |
|
|
|
42 |
|
|
// local functions
|
43 |
|
|
void DisplaySerialNum(uchar sn[8]);
|
44 |
|
|
|
45 |
|
|
/* Definition of Task Stacks */
|
46 |
|
|
#define TASK_STACKSIZE 2048
|
47 |
|
|
OS_STK task1_stk[TASK_STACKSIZE];
|
48 |
|
|
OS_STK task2_stk[TASK_STACKSIZE];
|
49 |
|
|
|
50 |
|
|
/* Definition of Task Priorities */
|
51 |
|
|
|
52 |
|
|
#define TASK1_PRIORITY 1
|
53 |
|
|
#define TASK2_PRIORITY 2
|
54 |
|
|
|
55 |
|
|
/* Prints "Hello World" and sleeps for three seconds */
|
56 |
|
|
void task1(void* pdata)
|
57 |
|
|
{
|
58 |
|
|
uchar FamilySN[MAXDEVICES][8];
|
59 |
|
|
float current_temp;
|
60 |
|
|
int i = 0;
|
61 |
|
|
int j = 0;
|
62 |
|
|
int NumDevices = 0;
|
63 |
|
|
SMALLINT didRead = 0;
|
64 |
|
|
|
65 |
|
|
//use port number for 1-wire
|
66 |
|
|
uchar portnum = ONEWIRE_P;
|
67 |
|
|
|
68 |
|
|
//----------------------------------------
|
69 |
|
|
// Introduction header
|
70 |
|
|
printf("\r\nTemperature\r\n");
|
71 |
|
|
|
72 |
|
|
// attempt to acquire the 1-Wire Net
|
73 |
|
|
if (!owAcquire(portnum,NULL))
|
74 |
|
|
{
|
75 |
|
|
printf("Acquire failed\r\n");
|
76 |
|
|
while(owHasErrors())
|
77 |
|
|
printf(" - Error %d\r\n", owGetErrorNum());
|
78 |
|
|
return;
|
79 |
|
|
}
|
80 |
|
|
printf("Acquire done\r\n");
|
81 |
|
|
|
82 |
|
|
do
|
83 |
|
|
{
|
84 |
|
|
j = 0;
|
85 |
|
|
// Find the device(s)
|
86 |
|
|
NumDevices = FindDevices(portnum, FamilySN, 0x28, MAXDEVICES);
|
87 |
|
|
if (NumDevices>0)
|
88 |
|
|
{
|
89 |
|
|
printf("\r\n");
|
90 |
|
|
// read the temperature and print serial number and temperature
|
91 |
|
|
for (i = NumDevices; i; i--)
|
92 |
|
|
{
|
93 |
|
|
printf("(%d) ", j++);
|
94 |
|
|
DisplaySerialNum(FamilySN[i-1]);
|
95 |
|
|
didRead = ReadTemperature(portnum, FamilySN[i-1],¤t_temp);
|
96 |
|
|
|
97 |
|
|
if (didRead)
|
98 |
|
|
{
|
99 |
|
|
printf(" %5.1f Celsius\r\n", current_temp);
|
100 |
|
|
}
|
101 |
|
|
else
|
102 |
|
|
{
|
103 |
|
|
printf(" Convert failed. Device is");
|
104 |
|
|
if(!owVerify(portnum, FALSE))
|
105 |
|
|
printf(" not");
|
106 |
|
|
printf(" present.\r\n");
|
107 |
|
|
while(owHasErrors())
|
108 |
|
|
printf(" - Error %d\r\n", owGetErrorNum());
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
else
|
114 |
|
|
printf("No temperature devices found!\r\n");
|
115 |
|
|
|
116 |
|
|
printf("\r\nPress any key to continue\r\n");
|
117 |
|
|
i = getchar();
|
118 |
|
|
}
|
119 |
|
|
while (i!='q');
|
120 |
|
|
|
121 |
|
|
// release the 1-Wire Net
|
122 |
|
|
owRelease(portnum);
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
/* Prints "Hello World" and sleeps for three seconds */
|
126 |
|
|
void task2(void* pdata)
|
127 |
|
|
{
|
128 |
|
|
while (1)
|
129 |
|
|
{
|
130 |
|
|
printf("Hello from task2\n");
|
131 |
|
|
OSTimeDlyHMSM(0, 0, 3, 0);
|
132 |
|
|
}
|
133 |
|
|
}
|
134 |
|
|
/* The main function creates two task and starts multi-tasking */
|
135 |
|
|
int main(void)
|
136 |
|
|
{
|
137 |
|
|
printf("Hello before OS\n");
|
138 |
|
|
|
139 |
|
|
OSTaskCreateExt(task1,
|
140 |
|
|
NULL,
|
141 |
|
|
(void *)&task1_stk[TASK_STACKSIZE-1],
|
142 |
|
|
TASK1_PRIORITY,
|
143 |
|
|
TASK1_PRIORITY,
|
144 |
|
|
task1_stk,
|
145 |
|
|
TASK_STACKSIZE,
|
146 |
|
|
NULL,
|
147 |
|
|
0);
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
OSTaskCreateExt(task2,
|
151 |
|
|
NULL,
|
152 |
|
|
(void *)&task2_stk[TASK_STACKSIZE-1],
|
153 |
|
|
TASK2_PRIORITY,
|
154 |
|
|
TASK2_PRIORITY,
|
155 |
|
|
task2_stk,
|
156 |
|
|
TASK_STACKSIZE,
|
157 |
|
|
NULL,
|
158 |
|
|
0);
|
159 |
|
|
OSStart();
|
160 |
|
|
return 0;
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
/******************************************************************************
|
164 |
|
|
* *
|
165 |
|
|
* License Agreement *
|
166 |
|
|
* *
|
167 |
|
|
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
|
168 |
|
|
* All rights reserved. *
|
169 |
|
|
* *
|
170 |
|
|
* Permission is hereby granted, free of charge, to any person obtaining a *
|
171 |
|
|
* copy of this software and associated documentation files (the "Software"), *
|
172 |
|
|
* to deal in the Software without restriction, including without limitation *
|
173 |
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
174 |
|
|
* and/or sell copies of the Software, and to permit persons to whom the *
|
175 |
|
|
* Software is furnished to do so, subject to the following conditions: *
|
176 |
|
|
* *
|
177 |
|
|
* The above copyright notice and this permission notice shall be included in *
|
178 |
|
|
* all copies or substantial portions of the Software. *
|
179 |
|
|
* *
|
180 |
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
181 |
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
182 |
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
183 |
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
184 |
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
185 |
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
186 |
|
|
* DEALINGS IN THE SOFTWARE. *
|
187 |
|
|
* *
|
188 |
|
|
* This agreement shall be governed in all respects by the laws of the State *
|
189 |
|
|
* of California and by the laws of the United States of America. *
|
190 |
|
|
* Altera does not recommend, suggest or require that this reference design *
|
191 |
|
|
* file be used in conjunction or combination with any other product. *
|
192 |
|
|
******************************************************************************/
|
193 |
|
|
|
194 |
|
|
// -------------------------------------------------------------------------------
|
195 |
|
|
// Read and print the serial number.
|
196 |
|
|
//
|
197 |
|
|
void DisplaySerialNum(uchar sn[8])
|
198 |
|
|
{
|
199 |
|
|
int i;
|
200 |
|
|
for (i = 7; i>=0; i--)
|
201 |
|
|
printf("%02X", (int)sn[i]);
|
202 |
|
|
}
|