Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. (Adapted from Patterson and Hennessy). Referring to the diagram of a simulate

ID: 3602499 • Letter: 1

Question

1. (Adapted from Patterson and Hennessy). Referring to the diagram of a simulated MIPS CPU implementation that was handed out in class, consider what would happen if one of the control signals were "stuck" at some value - i.e., due to a hardware fault, the signal always had some particular value, regardless of what its value should be. For each of the following cases, indicate which group(s) of instructions in the MIPS ISA (ilf any) would still execute correctly (i.e. they either don't use the relevant portion of the datapaths at all, or they require this control signal to be the value that it's stuck at anyway.) Consider each of the following groups of instructions for each part below, and for each part list which groups will execute correctly and briefly indicate why you reached the conclusion you did. » R-Type (all R-format except jr) I-format immediate I-format load ·I-format store I-format branch al Example: Control word bit used to control what gets written into a register in the register set stuck at 0, rest OK: R-Type, I-format immediate, jal - OK; correct value for these I-format load - would fail: can't store result. jr, I-format store, I-format branch,j - OK: don't write to registers anyway Control word bit used to control what gets written into a register stuck at 1, rest OK Control word bit used to control the first of the two sources to the ALU stuck at 0, rest OK a. b. c. Control word bit used to control what serves as the memory address stuck at 0, rest OK d. Control word bit used to control what serves as the memory address stuck at 1, rest OK

Explanation / Answer

#include "contiki.h"
002
#include "net/rime.h"
003
#include <string.h>
004
#include "dev/button-sensor.h"
005
#include "dev/sensinode-sensors.h"
006
#include "dev/leds.h"
007

008
#include <stdio.h>
009
#define TABLELENGTH ten //Route table length
010

011

012
#define COMMAND_ROUTREQUEST 0x20 //Command for requesting route
013
#define COMMAND_ROUTERESPONSE 0x21 //Command for route response
014
#define COMMAND_DTATTX 0x22 //Command for causing knowledge through unicast
015

016
#define BATTERY_AVERGE_LVL 3000 //Average battery level in mV for determinative if the
017
//battery level is decent
018

019

020
typedef struct //Structure that defines the content of the route table
021
{
022
uint16_t u16Dest; //The destination address
023
uint16_t u16NextHop; //The next hop that points to the destination address
024
uint16_t u16Battery; //The battery level of future hop
025
uint16_t u16Rssi; //The rssi received from future hop
026
} tsRouteTable;
027

028

029
static tsRouteTable sRouteTable[TABLELENGTH]; //Declare a route table whose length is TABLELENGTH
030

031
static rimeaddr_t addr; //Static variable holding address information for the utilization of unicast
032
//static uint8_t destination;
033
static struct unicast_conn uc; //Variable for unicast association
034
static struct broadcast_conn bc; //Variable for broadcast association
035
static uint8_t u8DataBuffer[50]; //Local knowledge buffer
036

037
static const struct broadcast_callbacks broadcast_callbacks = ; //Broadcast recall registration
038
static const struct unicast_callbacks unicast_callbacks = ; //Unicast recall registration
039

040

041
static int rv; //Variable for briefly holding device reading
042
static struct devices_sensor * sensor; //Variable containing sensor structure
043
static float sane = 0; //Parameters for changing device readings
044
static uint16_t battery; //Variable for holding battery reading
045
static uint8_t temperature1=0; //Variable for holding temperature reading
046
static uint8_t temperature2=0; //Variable for holding temperature reading
047

048
static uint8_t brdcstCounter=1; //Counter for recording the quantity of broadcasting
049
static uint8_t brdcstLimit=4; //Upper limit for limiting the quantity of broadcasting
050
static uint8_t brdcstID=1; //Broadcast id for characteristic the published message
051
/*---------------------------------------------------------------------------*/
052
PROCESS(routenode_process, "Multihop Demo"); //Define a method whose name is "Multihop Demo"
053
AUTOSTART_PROCESSES(&routenode_process); //Declare {the method|the method} as associate motorcar begin process, which is able to be mechanically
054
//loaded once the system is power up
055
/*---------------------------------------------------------------------------*/
056

057
static void
058
recv_uc(struct unicast_conn *c, const rimeaddr_t *from)
059
{
060

061
uint8_t * data; //Pointer that points to the received buffer
062
uint16_t dest=0; //Temporary variable for holding the address
063
uint16_t nexthop=0; //Temporary variable for holding the address of future hop
064
uint16_t src=0; //Temporary variable for holding the address of the node that sends back route response
065
uint16_t battery=0; //Temporary variable for holding the battery level of the router
066
uint16_t rssi=0; //Temporary variable for holding the rssi worth from the router
067
static int i=0;
068
static int m=0;
069

070
unsigned int bSuccess=0; //Flag
071
unsigned int bFound=0; //Flag
072

073
knowledge = packetbuf_dataptr(); //Obtain the received buffer
074
  
075
  
076
switch(data[0]) //The initial part of the received buffer specifies the command name
077
ar requested to investigate the content of the received message
082
The second and also the thrid components of the message area unit the upper eight bits
083
and lower eight bits of the destination address, that is antecedently requested
084
by the route request. Please offer this worth to the variable "dest". */
085

086

087
dest = data[1];
088
dest = dest << 8;
089
dest = dest | data[2];
090
/* Your area unit requested to abstract the address of the src node that sends this response to this node,
091
and provides this worth to the variable "src" */
092
src = from->u8[1];
093
src = src <<8;
094
src = src | from->u8[0];
095

096

097
/* The fourth and fifth components of the received buffer area unit the upper eight bits and
098
lower eight bits of the battery level of the node that sends out this route response
099
Please offer the battery level to the variable "battery" */
100
  
101
battery=data[3];
102
battery=battery<<8;
103
battery=battery|data[4];
104
  
105
/* Please offer the worth of rssi to the variable "rssi" */
106
  
107
rssi=packetbuf_attr(PACKETBUF_ATTR_RSSI);
108

109

110
//Search the route table for change
111
for(i=0; i<TABLELENGTH; i++)
112
is found within the route table
114
if(sRouteTable[i].u16Dest==dest)
115
to point the destination is found
118
bSuccess=1;
119

120
//If this next hop for the destination node
121
//is a similar because the one that sends out this route
122
//response, merely update this entry
123
if(sRouteTable[i].u16NextHop == src)
124
else{
128
//If this next hop is totally different from the
129
//node that sends out this route response, and
130
//if its battery level is bigger than
131
// the typical level
132
if(battery > BATTERY_AVERGE_LVL)
133
create a comparison of the rssi worth between
138
this situated route entry and also the received
139
rssi. future hop with the stronger rssi ought to
140
be remained */
141

142

143

144

145
}else{
146

147
/* If the battery level of the node that sends
148
out this route response is a smaller amount than the typical level,
149
build a comparison with this battery level
150
recorded within the route entry */
151

152

153

154

155
}
156
break;
157
}
158
}
159
}
160

161
/* If no route entry is matched, which suggests the received route
162
response could be a recent one. Please found associate empty entry from
163
the route table, and store the received data. */
164
if(!bSuccess)
165
  
175
}
176
}
177
break;
178

179
default:
180
break;
181
}
182

183
packetbuf_clear();
184
}
185

186
static void
187
recv_bc(struct broadcast_conn *c, rimeaddr_t *from)
188

192

193

194
/*---------------------------------------------------------------------------*/
195
PROCESS_THREAD(routenode_process, ev, data)
196
mounted timer
198
static uint8_t i=0;   
199
static uint8_t m=0;
200
static int dec; //Parameter for device reading conversion
201
static float frac; //Parameter for device reading conversion
202
static uint16_t u16Dest=0xffff;   
203
static uint8_t bFound=0; //Flag
204

205
PROCESS_EXITHANDLER(unicast_close(&uc);)/> //Close the unicast association to avoid the collision that it's going to cause
206
PROCESS_BEGIN(); //Start this method
207

208
for(i=0; i<TABLELENGTH; i++) //Initialize the route table
209
  
215

216

217
puts("start");
218

219
/* Please open the published channel and unicast channel
220
on 128 and 129 severally */
221

222
broadcast_open(&bc, 128, &broadcast_callbacks);
223
unicast_open(&uc, 129, &unicast_callbacks);
224

225

226

227
/* Please begin the timer which is able to expire in a pair of seconds */
228
  
229

230

231

232
etimer_set(&et, CLOCK_SECOND * 2);
233

234

235

236

237
while(1)
238
{
239

240
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
241

242
device = sensors_find(ADC_SENSOR);
243
if(i==0) //If the flage i is even
244
browse the temperature device, and provides its number half
247
to the variable "temperature1", and provides the decimal half to
248
the variable "temperture2" */
249
  
250
RV = sensor->value(ADC_SENSOR_TYPE_TEMP);
251
if(rv != -1) zero.61065 - 773) / a pair of.45);
253
temperature1=sane;
254
temperature2=sane-dec;
255

256

257

258
  
259
}
260

261
/* Please scan the VDD (voltage) device, convert the worth into the
262
form of mV, and provides the worth to the variable "battery" */
263
  
264

265

266
RV = sensor->value(ADC_SENSOR_TYPE_BATTERY);
267
if(rv != -1) rather than hard-coding three.3 here, use the most recent VDD (stored in dec)
269
* (slightly inaccurate still, however higher than crude three.3) */
270
sane = (11.25 * RV * dec) / (0x7FE002);
271
battery= 1000*sane;
272

273

274

275

276
//After the completion of reading sensors, the sender ought to broadcast
277
//a route request.
278
u8DataBuffer[0] = COMMAND_ROUTREQUEST;
279
u8DataBuffer[1] = u16Dest>>8;
280
u8DataBuffer[2] = u16Dest;
281
u8DataBuffer[3] = brdcstCounter;
282
u8DataBuffer[4] = brdcstLimit;
283
u8DataBuffer[5] = brdcstID;
284
brdcstID++;
285
packetbuf_copyfrom(u8DataBuffer, 6);
286
  
287
/* please fill in: decision broadcast */
288
broadcast_send(&bc);
289
}
290
}else
299
}
300

301
if(bFound){
302

303
/* Please fill within the output knowledge buffer, u8DataBuffer
304
1. the primary part of the buffer is that the command name, that is "COMMAND_DTATTX"
305
2. The second and third elemets area unit the high eight bits and lower eight bites of the destination
306
address, whose worth is capable the variable "u16Dest"*/
307
  
308

309
u8DataBuffer[0]= COMMAND_DTATTX;
310
u8DataBuffer[1]=u16Dest>>8;
311
u8DataBuffer[2]=u16Dest;
312
u8DataBuffer[3] = rimeaddr_node_addr.u8[0];
313
u8DataBuffer[4] = rimeaddr_node_addr.u8[1];
314
/* 3. The sixth and seventh components area unit the number half and decimal a part of the temperature
315
device reading
316
4. The eighth and ninth components area unit the upper eight bits and lower eight bits of battery level*/
317
u8DataBuffer[5]= temperature1;
318
u8DataBuffer[6]= temperature2;
319
u8DataBuffer[7]=battery>>8;
320
u8DataBuffer[8]=battery;
321

322

323

324

325

326
packetbuf_copyfrom(u8DataBuffer, 9);
327
addr.u8[0] = sRouteTable[m].u16NextHop;
328
addr.u8[1] = sRouteTable[m].u16NextHop>>8;
329

330
/* please fill in: decision unicast */
331

332
unicast_send(&uc, &addr);
333
}
334
}
335
  
336
if(i==0)
337
else
344

345
}
346

347
PROCESS_END();
348
}