Lab-1 – Introduction to Digital System Design

$24.99 $18.99

1. Learning method: You will learn by doing exercises and by designing systems. You will also learn “how to learn from additional sources” other than textbooks. System design is more of an art than science, which is best learned by observing work of other designers and looking over reference designs. Software often documents and reflects…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

1. Learning method:

You will learn by doing exercises and by designing systems. You will also learn “how to learn from additional sources” other than textbooks. System design is more of an art than science, which is best learned by observing work of other designers and looking over reference designs. Software often documents and reflects the design of the system. For the lab assignments you will be specifically asked to focus on the subset of the topics that you can learn from programs that will be provided to you by the instructors and the TA. However additional topics can be learnt by completely analyzing these given programs and progressively developing advanced skills by adopting and applying those throughout the rest of the course. As the lab class proceeds, we will progressively guide you towards those additional topics.

Therefore, read the complete programs that are provided even though you may not understand them entirely at this point of time. By doing so you would at least become familiar how code segments and functions look like, and when time permits you should do additional research using “Google” and “man” (from Linux/Unix environment) to understand and rationalize them. Instructions regarding these are provided in the next section. Your level of programming skill and knowledge (and future job prospects) will depend on your motivation to go this extra mile to learn additional topics beyond the immediate need of doing the assignments.

2. Resource that you may need:

The CS help desk webpages are a great resource. Remember that learning to use these software tools is your responsibility.

  1. How to compile C programs, can be found at – https://medium.com/@laura.derohan/compiling-c-files-with-gcc-step-by-step-8e78318052

  1. About off campus CS VPN access (for completing assignments from home) – https://it.tamu.edu/services/network-and-internet-access/virtual-private-networks/virtual-private-network-vpn/index.html

https://tamuengr.atlassian.net/wiki/spaces/helpdesk/pages/1148059651/Installing+and+U

sing+Cisco+VPN

  1. How to use Linux machine from Windows systems

putty” – https://www.ssh.com/ssh/putty/windows/ “mobaXterm” – https://mobaxterm.mobatek.net/

VS Code” https://code.visualstudio.com/docs/remote/ssh

    1. How to do file transfer from windows/mac/linux machine to CSE server?

      1. Windows user can use: winscp.net/eng/index.php

      1. Mac or Linux users can use the terminal: “scp -r <src files or folders> netid@unix.cse.tamu.edu:<path to the destination folder>”, if you don’t mention anything else after the “:” the files/folders will be copied to your home directory. If you don’t want to copy in your home directory, then you have to mention the path of the desired destination folder after the “:”.

    1. To access “man” pages, in the Linux/Unix console you have to type “man” followed by the Linux system call name. For example, to learn about the “gettimeofday” system call function, type “man gettimeofday”. Remember only the Linux system calls are documented under the linux Manual pages, not arbitrary C functions. You can also find the “man” pages on the web, as they are also published in html format. To find man pages on the web type “man gettimeofday” into Google. Ask your TA and develop an understanding what are system call functions and how are they different from standard C library functions.

  1. Specific instructions

    1. Submit a soft copy of all answers that you submit as lab assignments. Hard copies may be requested for specific assignments, you will be informed in this case. The soft copies should be submitted online on CANVAS before the deadline. For homework assignments, you must work out the problems on paper and then submit to instructor. The late penalty policy is as put in the course syllabus.

    1. For each problem, answer all the sub problems under “Activities to do”. This should be turned in as a PDF format. For some problems you may have to submit text and C program files in addition to the responses to the questions. For those lab assignments, combine all the files as a single zip file and upload the zip file. If you have questions about submission, please talk to your TA.

    1. You may use your own machines to compile and test code. However, to ensure fair grading, all assignments must be shown to work on the CS department Linux/Unix systems.

    1. Assignments might come with associated program code, text, etc. files. Those will be available inside a single zip file meant for that particular lab class. These files will be available in the lab page for downloading. A lab topic might span more than one lab class.

3

Chapter 2: Introduction to digital system design

In this chapter you learn about importance of low-level system design for solving real-life problems. This chapter will immerse you in a problem context, which will require you to apply the theoretical concepts taught in the class. This will help you to develop basic skills needed to become a device level system developers and digital system designer. While going through this chapter concentrate on developing a good understanding of the problem context, as it is a fundamental requirement for becoming a skilled system designer or application developer.

  1. Learning duration: 1 week. Required Tools: gcc

  1. Objective:

To learn –

Primary topics

  1. How numbers are actually stored in a computer system.

  1. How to relate computer programs to a given real-life applications.

  1. How to design C code to solve real-life problems using Boolean algebra basics (specifically how to construct the right logical expression and use them).

  2. How to optimize code for a real-life embedded system with programming tricks that applies Boolean logic concepts, tools (truth table) and low level C programming features.

  1. To appreciate the need to learn more about hardware. This hardware related knowledge is necessary to develop useful systems and real-world applications.

  1. How to design digital system especially for safety critical applications.

Secondary topics

  1. Useful C functions that will help to understand a platform’s data representation.

  1. How to use “gcc” compiler in Linux environment.

  1. Coding patterns, styles, jargons and terms used in the trade (computing profession).

  1. What are standard C library and Linux specific system functions, difference and relationship between them.

4

  1. Exercises to do (100 points in total) 3.1 Problem 1: (15 points)

You are provided with the following C program –

#include <stdio.h> // For input/output

#include <stdlib.h> // For exit()

#include <sys/time.h> // For gettimeofday() function

int main()

{

int int_var; // Tag 1

struct timeval this_instant;

double time_stamp;

FILE *my_file_pointer; // Tag 2

if ( (my_file_pointer = fopen(“lab1_prob1_out.txt”, “w”)) == NULL)

{

printf(“Error opening the file, so exiting\n”);

exit(1);

}

gettimeofday(&this_instant, 0);

time_stamp = this_instant.tv_sec;

//Code segment for file I/O

fprintf(my_file_pointer, “This program was executed at time : %ld or %f\n”, this_instant.tv_sec, time_stamp);

fprintf(my_file_pointer, “The sizes of different data type for this machine and compiler are -\n”);

fprintf(my_file_pointer, “int data type is %lu bytes or %lu bits long\n”,sizeof(int_var), sizeof(int_var)*8); // Tag 3 fprintf(my_file_pointer, “double data type is %lu bytes or %lu bits long\n”,sizeof(double), sizeof(double)*8);

//Code segment for console I/O, this can be used instead of the file I/O

printf(“This program was executed at time : %ld or %f\n”, this_instant.tv_sec, time_stamp);

printf(“The sizes of different data type for this machine and compiler are -\n”); printf(“int data type is %lu bytes or %lu bits long\n”,sizeof(int_var), sizeof(int_var)*8); printf(“double data type is %lu bytes or %lu bits long\n”,sizeof(double), sizeof(double)*8);

fclose(my_file_pointer); //To close the output file, mandatory to actually get an output !

return 0;

}

5

This code (file name “lab1_prob1.c”) is available in the zipped package for download from the lab webpage.

Activities to do- (5 points each, write your answer of (a)-(c) to your lab report)

  1. Using less than 4 sentences, explain what function/action, the two statements marked with “Tag 1”, “Tag 2”, and “Tag 3” perform.

  1. Compile and run this program with “gcc” on the CS CentOS 7 Linux machine

(linux.cse.tamu.edu). Provide a screenshot of the obtained result in the lab report.

  1. Find out the structure of type “timeval”. What is the data type of variable tv_sec?

Hint – See the instructions on how to compile with gcc as indicated under section named “Resource that you may need”.

3.2 Problem 2: (20 points)

Write a C program to get bit and byte lengths for all the following C numerical data types –

unsigned int, double, long, long long, char, float, struct timeval.

The C code file should have name “lab1_prob2.c” and it should generate an output file named “lab1_prob2_out.txt”.

Activities to do-

a) Provide a screenshot of your C code file and your output in the lab report.

Hint – You can add codes to the C program given for problem 1 to do the problem 2.

6

3.3 Problem 3: (25 points)

Assume you are hired by Ford Motor Company to develop the embedded software for their new model of cars. This software executes on the main computer that sits inside the car. Your manager wrote down the “Software Requirement Specification (SRS)” document and gave it to you. Based on the “requirements” listed in this document you have to develop a C program that materializes these requirements/specifications. Given below is a portion of the SRS document which includes the schematic of the car’s electronics and computer systems –

Fig. 1: Block diagram of the embedded control system for the car

Electro-mechanical world The computational world Electro-mechanical world

and o/p i/f sub-systems in later lab classes. You have choice to use a combination of hard-software (h/w+s/w) or hardware (h/w) alone to design this sub-system.

Eight Available sensors

Each hardware sensor provides a “high” (1) or “low” (0) output. The input interface sub-system sets the value of the corresponding global integer variable to the respective value. The decision/ control logic sub-system will read this integer to take the right decision. It is assumed that this integer is available for C programming. The i/p i/f sub-system keeps monitoring the sensor hardware outputs and takes action (changes value of the integer variable) as soon as the sensor output state changes.

  1. DOSdriver on seat. This sensor indicates whether a driver is present. This sensor provides logical “high” (1) as output when a person is sitting on the driver’s seat and “low” (0) if he is not on the seat.

  1. DSBFdriver seat belt fastened. This sensor indicates whether the driver seat belt is fastened or not. The sensor hardware provides “high” when driver’s seat belt is fastened, “low” otherwise. The corresponding integer variable that reflects the physical states inside the computer and programming world is “driver_seat_belt_fastened”. The i/p i/f sub-system sets this integer to 1 when DSBF output is high, and to 0 when DSBF is low, and the decision/control sub-system code reads/uses it.

  1. ERengine running. This sensor indicates whether engine is running or not. It provides “true” when engine is running, false otherwise. The corresponding integer variable to read and use is “engine_running”.

  1. DCdoors closed. Indicates whether all doors are closed or not. The corresponding integer is “doors_closed”.

  1. KICkey in car. Indicates that the keys are still inside the keyhole, the corresponding integer variable is “key_in_car”.

  1. DLCdoor lock lever. This indicates whether the door lock lever is closed or not. To close the electronic door locks the driver has to close this door lock lever. When the car’s computer finds that door lock lever is closed it checks all other variables to assess the situation and finally decides whether to activate the electronic door locks to lock the doors or not. For example, if the car keys are still inside but the driver is not on seat (has gone out of car) then the doors should never be locked even though the driver has closed the door lock lever.

  1. BPbrake pedal. This indicates that the brake pedal is pressed by the driver.

  1. CMcar moving. This sensor indicates the car is moving and at least one of its wheels are turning. The corresponding integer variable “car_moving” has value 1 when the car is moving, and has value 0 if the car is not moving.

8

Three Available actuators

  1. BELLA beeper/chime that sounds/plays to alert the driver of any abnormal/hazardous situation (as found in your car). A global integer variable named “bell” is provided in the computer, if your code that implements the decision/control sub-system sets this variable to 1, then the output interface sub-system will read this value and turn on the voltage on the electrical wire that feeds the beeper/chime. As a result, the beeper/chime will start beeping. The beeper will stop when the decision/control subsystem code sets the value of “bell” to 0, because then the o/p i/f will turn down the electrical voltage feeding the beeper hence it will stop. The o/p i/f keeps on monitoring the integer variable and takes action (change the voltage) when the integer changes its value.

  1. DLAdoor lock actuator. This actuator locks the doors. A corresponding global integer variable named “door_lock” is provided in the computer, if you set this integer to 1 all the doors are locked, it unlocks all doors when you set the value of “door_lock” to 0.

  1. BAbrake actuator. This actuator will actually activate the disk brakes in each of the four wheels if the global integer variable “brake” is set to 1. The brake will be released when this variable is set to 0 by the code that implements the decision/control logic sub-system.

Five Requirements

  1. The BELL should chime/sound when the driver starts the engine without fastening his seatbelt.

  1. The BELL should sound when the driver starts the car without closing all the doors.

  1. The BELL should be off as soon as the conditions change to normal.

  1. The doors should not lock when the driver has got out of the car, but the keys are still inside the engine, even though the driver has closed the door lock lever. Note: If the driver is on the seat and requests the doors to be locked, the doors must lock.

  1. The brake should be engaged when the driver presses the brake pedal. Brakes should disengage when the brake pedal is released. The brake should engage only when the car is moving, when the car is stationary the brake should not unnecessarily engage to reduce mechanical wear and tear of the brake’s hydraulic system.

Activities to do-

  1. For each requirement, separately provide the Boolean expressions that you decided to use. (7 pts)

  1. Create a single combined truth table with all the available sensor inputs and actuator outputs for all the five requirements together. Some of the truth table entries will be don’t-care states (represented by an X) instead of true or false. For this sub-problem assume that these five requirements together constitute a complete system. Note: if you don’t use the “don’t care” conditions, you could end up with a large 255 row truth table. (7 pts)

9

  1. Write a C program using the Boolean logic concepts and tools learnt in class to materialize these five requirements. Use if-then-else structure to do this. A basic code framework (file name “lab1_prob3_framework.c”) for a general control system has been provided. This is available in the lab files that you downloaded. Use this code to learn how to develop C program for a real-life control system. (3 pts)

  1. There are 8 different test cases provided in main function (code segment 2) to check whether your code is working as intended. Please comment out code segment 1 and uncomment the code segment 2. Then compile and run the code using following command: gcc -std=c99 -o test lab1_prob3_framework.c

Provide a screenshot of your code and output of the test cases in your report. (8 pts. You will get 1 point for correct output on each test case).

3.4 Problem 4: (20 points)

Next day after writing the code (for problem 3), you realized that it was a waste of hardware and memory space to use separate integers to represent sensor output and actuator input states. As you get more experienced and confident, you decide to improve your code to save space. You realized that saving space is essential because the cars computer is an “embedded system1” (you were quick to pick up the industry jargons) which has very small memory (say only 256 bytes compared to gigabytes of RAM in a traditional desktop system). You decided that all these sensor output states can fit inside a single 32-bit integer, and the actuator output states can be fit into another 32-bit integer. So instead of using 10 integers of 4 bytes each (total 40 bytes), you decided to use only 4 + 4 = 8 bytes. You decided the following integers with following bit formats–

A global integer variable named “sensor_inputs” with the following sensor input encoding format.

For the actuators you decided to use a global integer variable “actuator_outputs” with the following format –

not safe3”. You discussed with them to understand why the code is “unsafe”. After a long debate you realized that your code does not activate the brakes fast enough. The car – System Test Engineer wants the brakes to activate within 50 nano seconds of pressing the brake pedal. But your program is unable to respond that fast. So, you decided to measure the execution time (or speed) of the code to estimate how much faster it has to run.

Activities to do- (10 pts each)

  1. Measure the execution time of the code that you developed for problem 4 on both the CS CentOS 7 Linux system (linux.cse.tamu.edu) & the CS Red Hat Linux system (compute.cse.tamu.edu) A execution time measuring framework is provided for this purpose (lab1_prob5_framework.c). Insert your code within this framework to measure time in the place as indicated in the code file.

  1. Provide a screenshot of outputs generated by both machines to the lab report.

Instructions to measure the execution time of your code using the execution time measuring framework file –

    1. Insert your codes in the places as indicated in the “lab1_prob5_framework.c” framework file.

    1. Compile the “lab1_prob5.c” file using gcc and the realtime library using the –lrt option. [user@linux ~/]gcc file.c -lrt

    2. Run the executable created in the previous step.

    1. The executable will report the execution time of the code.

  1. Similarly measure the execution time of the code developed for problem 3.

    1. Provide a screenshot of outputs generated by both machines to the lab report. Compare the execution time for the codes developed for problem 3 and for problem 4.

    1. Are you convinced that code developed for problem 4 is faster than the code developed for problem 3? Why or why not?

  • A code is termed safe when it can be used in a safety critical system without any risk of potential damage or injury. Developers have the ethical and professional responsibility to create codes that are safe to use in safety critical systems like cars, elevators, etc. If the car brake doesn’t engage within certain time, the car may not stop causing accidents. Hence is the need for safety assessment during testing.

12

Lab-1 - Introduction to Digital System Design
$24.99 $18.99