ECE 330 Homework 7 Fall 2010 Due: 10/11/2010

advertisement
ECE 330
Due: 10/11/2010
1.
Homework 7
Fall 2010
Provide assembly code for statements a, b and c.
typedef unsigned int REGISTER;
struct abc {
REGISTER
REGISTER
REGISTER
};
a;
b;
c;
char mem[sizeof(struct abc)];
int main()
{
struct abc *pabc = (struct abc *) ????;
unsigned int a = 0x11111111;
unsigned int b;
pabc->c = a;
(*pabc).c = a;
b = a;
// a.
// b.
// c.
return 0;
}
2. What are the resulting values for i, j and k? Which of the statements (a, b or c) are
equal.
int main()
{
unsigned char a[] = {0x11, 0x22, 0x33, 0x44,
0x55, 0x66, 0x77, 0x88,
0x99, 0xaa, 0xbb, 0xcc};
int
*pi = (int *)a;
unsigned int
i, j, k;
i = *pi++;
// a.
j = (*pi)++;
// b.
k = *(pi++);
// c.
return 0;
}
3. Complete the following code that results in fp_reg with the current value of the Nios
II fp register and r2_req with the current value of the Nios II r2 register.
typedef unsigned int REGISTER;
int main()
{
REGISTER fp_reg;
REGISTER r2_reg;
return 0;
}
Page 1 of 2
ECE 330
Due: 10/11/2010
Homework 7
Fall 2010
4. Using the header files provided below complete the dev1.c program that will provide
the functionality given below. You will need to create an accessor function
(DEV1_Get_Value1) that returns the bits 4-8 of the data register of a PIO type device
DEV1. Usage of this accessor function is shown in the following main.c program. Write
all code necessary (must be able to compile) to support the requested function.
#ifndef PIO_REGS_H_
#define PIO_REGS_H_
#ifndef TYPES_H_
#define TYPES_H_
typedef unsigned int
typedef unsigned short
typedef unsigned char
ui32;
ui16;
ui8;
typedef
hword;
typedef
typedef
typedef
typedef
byte;
word;
bool;
bits;
unsigned short
unsigned
unsigned
unsigned
unsigned
char
int
int
int
typedef unsigned int
typedef unsigned int
#endif
REG;
BITS;
// #ifdef TYPES_H_
#ifndef DEV1_REGS_H_
#define DEV1_REGS_H_
#include "types.h"
union dev1_data {
REG value;
struct {
BITS x0
BITS val1
BITS x1
BITS val2
BITS x2
} bf;
};
:
:
:
:
:
4;
5;
8;
3;
12;
#include "types.h"
struct PIO_REGS {
REG data;
REG direction;
REG intmask;
REG edgecapture;
};
data register
direction register
interrupt mask register
edge capture register
#endif /*PIO_REGS_H_*/
#ifndef __SYSTEM_H_
#define __SYSTEM_H_
...
/*
* dev1 configuration
*
*/
#define DEV1_NAME "/dev/dev1"
#define DEV1_TYPE "altera_avalon_pio"
#define DEV1_BASE 0x01111110
#define DEV1_SPAN 16
#define DEV1_DO_TEST_BENCH_WIRING 0
#define DEV1_DRIVEN_SIM_VALUE 0
#define DEV1_HAS_TRI 0
#define DEV1_HAS_OUT 1
#define DEV1_HAS_IN 0
#define DEV1_CAPTURE 0
#define DEV1_DATA_WIDTH 32
#define DEV1_EDGE_TYPE "NONE"
#define DEV1_IRQ_TYPE "NONE"
#define DEV1_FREQ 50000000
#define ALT_MODULE_CLASS_dev1 altera_avalon_pio
...
#endif /* __SYSTEM_H_ */
#endif /* DEV1_REGS_H_*/
// file: dev1.c
#ifndef DEV1_H_
#define DEV1_H_
#include "types.h"
BITS DEV1_Get_Value1 ( void
);
#endif /* DEV1_H_*/
// file: main.c
#include "dev1.h"
int main()
{
unsigned int value1;
value1 = DEV1_Get_Value1();
}
//
//
//
//
return 0;
Page 2 of 2
Download