---
# System prepended metadata

title: EESM6000C Lab 4-1

---

# Execute Code in User Memory (lab_4-1)
Student ID: 20726557

## List relevant code changes from rtl/firmware

#### fir.c
![image](https://hackmd.io/_uploads/Hy3Aq_Qygg.png)

#### fir.h
![image](https://hackmd.io/_uploads/SyhBod7ygx.png)

initfir() initializes the inputbuffer and outputsignal arrays to 0. When fir() is called, the initfir() will be run and the FIR computation will store the data into the outputsignal.

#### user_project_example.counter.v
![image](https://hackmd.io/_uploads/HkG0sO71ll.png)

The wishbone bus controller is designed with a response after the delay. The delay is configured by the DELAYS parameter. This is implemented by using a counter. When the counter reaches the value of DELAYS, wbs_acks_o will be asserted.

![image](https://hackmd.io/_uploads/HJAI3uXyee.png)


#### bram.v
![image](https://hackmd.io/_uploads/ryCm2Omygg.png)

To configure the suitable size of the BRAM, the BRAM will use the parameter N, which is the number of taps, to determine the size.

---
## Memory map & linker (lds)

The following is the memory map of the project.

![image](https://hackmd.io/_uploads/rJDzXtm1ge.png)

In this lab, the BRAM is used for FIR computation. The BRAM address is mapped to "mprjram" at 0x38000000. 

To excute the FIR computation and store in BRAM, the address at 0x38000000 is accessed.

![image](https://hackmd.io/_uploads/rJy14tQkxl.png)

In the wishbone controller, the BRAM enable is qualified by the wishbone address of 0x38000000.

![image](https://hackmd.io/_uploads/Sk3BEKX1lg.png)

---
## How to move code from spiflash to user project area memory

After compiling the code, it is stored in "counter_la_fir.hex". In the testbench, the .hex file is directly written as the spiflash.

![image](https://hackmd.io/_uploads/Bk8uBF7kxl.png)

The code from the SPIFlash is written to the user project area memory through the Wishbone interface.

![image](https://hackmd.io/_uploads/r1t2dY7kex.png)

---
## How to execute code from user project memory

In this lab, the target function is the computer FIR. The code was first pre-loaded into the User Project Memory. The code is executed from the user project memory when the target function is called.

![image](https://hackmd.io/_uploads/HylZNqQJgl.png)

![image](https://hackmd.io/_uploads/rJl0m5Qygx.png)

The code is read from the user project memory to fetch the corresponding instruction to execute.

---
## Show the Operation sequence and its waveform

The FIR computation is started when mprj_io is set to 0xAB40.

![image](https://hackmd.io/_uploads/rJUXF97Jgg.png)

![image](https://hackmd.io/_uploads/rk_f1cX1gx.png)

![image](https://hackmd.io/_uploads/SJcy6FQ1lx.png)

The FIR code is fetched from the user project memory to execute the "initfir" and "fir" function.

![image](https://hackmd.io/_uploads/SJiPOcQyel.png)

In the code, the "fir" function is computed 11 times and sets check bits 11 times.
![image](https://hackmd.io/_uploads/rkKsd9m1gx.png)

![image](https://hackmd.io/_uploads/BJAxKcXJgx.png)

When check_bits is set to 0xAB51, the FIR computation is finished.

![image](https://hackmd.io/_uploads/r1p4t9Q1le.png)

![image](https://hackmd.io/_uploads/rk_f1cX1gx.png)

![image](https://hackmd.io/_uploads/HyNrycX1ll.png)

---
#### GitHub
https://github.com/AnthonyGithub/EESM6000C-Lab-4/tree/main/Lab%204-1