TABLE OF CONTENTS 1. Introduction 2. Download Code and Setup 3. Problem 1: Battery Meter Simulation...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
TABLE OF CONTENTS 1. Introduction 2. Download Code and Setup 3. Problem 1: Battery Meter Simulation o 3.1. Overview o 3.2. batt update.c: Updating the Display with User Code o 3.3. Battery Meter Simulator o 3.4. Sample Runs of batt main 3.5. Problem 1 Grading Criteria 4. Problem 2: Debugging the Puzzlebox o 4.1. Overview o 4.2. input.txt Input File o 4.3. gdb The GNU Debugger O 4.4. Typical Cycle o 4.5. Kinds of Puzzles o 4.6. Tests for puzzlebox.c 5. Problem 3: Tree Sets in C o 5.1. Overview o 5.2. treeset main Demonstration o 5.3. tree funcs.c: tree functions o 5.4. treeset main.c: main function / application o 5.5. Grading Criteria for Problem 3 6. Assignment Submission o 6.1. Submit to Gradescope o 6.2. Late Policies 3.1 Overview You are tasked with writing code which will be run by a microcontroller in a digital battery meter. The hardware has the following relevant features. A voltage sensor whose value can be accessed via a memory mapped port. In C this is presented as a global variable. Another port indicates whether the voltage should be displayed in Volts or Percentage of total battery capacity. A digital display with a port control port; setting certain global variable will change the display to show information to a user of the battery meter. User code that you will need to write to update the display based on the sensor value. A simulator program with Makefile to test your code Each feature is discussed in subsequent sections. Voltage Sensor A voltage sensor is attached to the battery meter and can be accessed via a C global variable. This is declared in the batt.h header file as follows. extern short BATT_VOLTAGE_PORT; // Sensor tied to the battery, provides a measure of voltage in units // of 0.0005 volts (half milli volts). The sensor can sense a wide // range of voltages including negatives but the batteries being // measured are Full when 3.8V (7600 sensor value) or above is read // and Empty when 3.0V (6000 sensor value) or lower is read. You do not need to define this variable as it is already there. You do NOT need to set this variable as it is automatically changed by the hardware. Instead, you will need to access its value to determine various the voltage level of the attached battery. As indicated in the variable documentation, a common (though mildly unreliable) means of detecting how much charge is left in a battery is to read the voltage on the battery. The type of battery being measured in this case has a higher voltage when fully charged and its lower voltage continuously lowers as it discharges. Past certain low voltage, the battery is unsafe to discharge and other hardware will disable the meter. The figure below shows the voltage range and corresponding Capacity Percentage for the battery. battery-voltage-v-percent2.png Figure 1: Relationship between Voltage and Percent full for batteries being measured by the meter. Notice the relationship between the Voltage which can be read directly and the Percent full which needs to be calculated from the voltage using the given formula: TABLE OF CONTENTS 1. Introduction 2. Download Code and Setup 3. Problem 1: Battery Meter Simulation o 3.1. Overview o 3.2. batt update.c: Updating the Display with User Code o 3.3. Battery Meter Simulator o 3.4. Sample Runs of batt main 3.5. Problem 1 Grading Criteria 4. Problem 2: Debugging the Puzzlebox o 4.1. Overview o 4.2. input.txt Input File o 4.3. gdb The GNU Debugger O 4.4. Typical Cycle o 4.5. Kinds of Puzzles o 4.6. Tests for puzzlebox.c 5. Problem 3: Tree Sets in C o 5.1. Overview o 5.2. treeset main Demonstration o 5.3. tree funcs.c: tree functions o 5.4. treeset main.c: main function / application o 5.5. Grading Criteria for Problem 3 6. Assignment Submission o 6.1. Submit to Gradescope o 6.2. Late Policies Notice the relationship between the Voltage which can be read directly and the Percent full which needs to be calculated from the voltage using the given formula: BattV = BattVolt Port / 2 Batt%= (BattV - 3000) / 8 Note the conversion is done in millivolts (0.001 volts) and the the voltage sensor is in units of half millivolts (0.0005 volts). Voltage Display Mode Another global variable exposes whether the user has pressed a button which toggles between displaying Volts or Percent full in the battery. extern unsigned char BATT_STATUS_PORT; // The bit at index 4 indicates whether display should be in Volts (0) // or Percent (1); the bit is tied to a user button which will toggle // it between modes. Other bits in this char may be set to indicate // the status of other parts of the meter and should be ignored: ONLY // BIT 4 BIT MATTERS. C code should only read this port. As per the documentation, only the 4th bit should be used while other bits may be nonzero and should be ignored. Bitwise operations are useful for this. Display Port The battery meter has a digital display which shows the remaining battery capacity. This display is controlled by a special memory area exposed as another global variable in C. extern int BATT_DISPLAY_PORT; // Controls battery meter display. Readable and writable. C code // should mostly write this port with a sequence of bits which will // light up specific elements of the LCD panel. While listed as in int, each bit of the is actually tied to part of the LCD display screen. When bits are set to 1, part of the display is lit up while 0 means it is not lit. The following diagrams show how various bit patterns will light up parts of the LCD display. Some bits correspond to parts of digits like "9" and "4" while others light up portions for the decimal place, Volt/Percent indicator, and bars of the leftmost visual level indicator. Above the display is the bit string which results in the elements on the display being turned on with "1" and off with a "0". TABLE OF CONTENTS 1. Introduction 2. Download Code and Setup 3. Problem 1: Battery Meter Simulation o 3.1. Overview o 3.2. batt update.c: Updating the Display with User Code o 3.3. Battery Meter Simulator o 3.4. Sample Runs of batt main o 3.5. Problem 1 Grading Criteria 4. Problem 2: Debugging the Puzzlebox o 4.1. Overview o 4.2. input.txt Input File o 4.3. gdb The GNU Debugger O 4.4. Typical Cycle o 4.5. Kinds of Puzzles o 4.6. Tests for puzzlebox.c 5. Problem 3: Tree Sets in C o 5.1. Overview o 5.2. treeset main Demonstration o 5.3. tree funcs.c: tree functions o 5.4. treeset main.c: main function / application o 5.5. Grading Criteria for Problem 3 6. Assignment Submission o 6.1. Submit to Gradescope o 6.2. Late Policies Display Port The battery meter has a digital display which shows the remaining battery capacity. This display is controlled by a special memory area exposed as another global variable in C. extern int BATT DISPLAY_PORT; // Controls battery meter display. Readable and writable. C code // should mostly write this port with a sequence of bits which will // light up specific elements of the LCD panel. While listed as in int, each bit of the is actually tied to part of the LCD display screen. When bits are set to 1, part of the display is lit up while 0 means it is not lit. The following diagrams show how various bit patterns will light up parts of the LCD display. Some bits correspond to parts of digits like "9" and "4" while others light up portions for the decimal place, Volt/Percent indicator, and bars of the leftmost visual level indicator. Above the display is the bit string which results in the elements on the display being turned on with "1" and off with a "0". Notice the following. The BATT_DISPLAY_PORT is a 32-bit integer but only some bits control the display 29 bits are used to control the full battery display (bits 0-28) Bit 0 controls whether the '%' Percent indicator is shown Bit 1 controls whether the 'V' Voltage indicator is shown Bit 2 controls whether the decimal place is on (for Volts) or off (for Percent) Bits 3-9 control the rightmost digit Bits 10-16 control the middle digit Bits 17-23 control the left digit Each digit follows the same pattern: lowest bit controls the upper right LCD digit bar with each higher bit going in a clockwise fashion and the middle bar being controlled by the highest order bit Bits 24-28 control the 5 'bars' in the visual level indicator Bits 29-31 are unused battery-meter-top-first-vp-right.png Figure 2: Full examples of how the 29 bits of the BATT_DISPLAY_PORT turns on/off parts of the LCD display. Each digit follows the same pattern of bit to bar correspondence. The lowest order (rightmost) bits control the percent, voltage, and decimal place indicator. Middle bits control "bar" of each digit starting with the top bar and proceeding around the outside clockwise with the final bit for each digit controlling the middle bar. This pattern is followed for all 3 digits. The uppermost bits control the level indicator bars. TABLE OF CONTENTS 1. Introduction 2. Download Code and Setup 3. Problem 1: Battery Meter Simulation o 3.1. Overview o 3.2. batt update.c: Updating the Display with User Code o 3.3. Battery Meter Simulator o 3.4. Sample Runs of batt main 3.5. Problem 1 Grading Criteria 4. Problem 2: Debugging the Puzzlebox o 4.1. Overview o 4.2. input.txt Input File o 4.3. gdb The GNU Debugger O 4.4. Typical Cycle o 4.5. Kinds of Puzzles o 4.6. Tests for puzzlebox.c 5. Problem 3: Tree Sets in C o 5.1. Overview o 5.2. treeset main Demonstration o 5.3. tree funcs.c: tree functions o 5.4. treeset main.c: main function / application o 5.5. Grading Criteria for Problem 3 6. Assignment Submission o 6.1. Submit to Gradescope o 6.2. Late Policies Figure 2: Full examples of how the 29 bits of the BATT_DISPLAY_PORT turns on/off parts of the LCD display. Each digit follows the same pattern of bit to bar correspondence. The lowest order (rightmost) bits control the percent, voltage, and decimal place indicator. Middle bits control "bar" of each digit starting with the top bar and proceeding around the outside clockwise with the final bit for each digit controlling the middle bar. This pattern is followed for all 3 digits. The uppermost bits control the level indicator bars. For reference, each number to be displayed in the LCD battery meter follows the same patter of bits which is shown in the below diagram with the rightmost digit bit positions. digital-digits-top-first.png Figure 3: Pattern of bits for all 10 numerals and a few extra symbols 3.2 batt_update.c: Updating the Display with User Code Periodically the microcontroller will run code to adjust the battery display to show the current battery level. This function is int batt_update(); and it will be your job to write it. Rather than write everything that needs to be done within batt_update(), several helper functions will be used to divide this task into several more manageable and testable chunks. These should all be written in batt_update.c and are as follows. Converting Voltage Values to a Struct int set batt_from_ports (batt_t *batt); // Uses the two global variables (ports) BATT_VOLTAGE_PORT and // BATT_STATUS_PORT to set the fields of the parameter 'batt'. If // BATT_VOLTAGE_PORT is negative, then battery has been wired wrong; // no fields of 'batt' are changed and 1 is returned to indicate an // error. Otherwise, sets fields of batt based on reading the voltage // value and converting to precent using the provided formula. Returns // 0 on a successful execution with no errors. This function DOES NOT // modify any global variables but may access global variables. // // CONSTRAINT: Avoids the use of the division operation much as TABLE OF CONTENTS 1. Introduction 2. Download Code and Setup 3. Problem 1: Battery Meter Simulation o 3.1. Overview o 3.2. batt update.c: Updating the Display with User Code o 3.3. Battery Meter Simulator o 3.4. Sample Runs of batt main 3.5. Problem 1 Grading Criteria 4. Problem 2: Debugging the Puzzlebox o 4.1. Overview o 4.2. input.txt Input File o 4.3. gdb The GNU Debugger O 4.4. Typical Cycle o 4.5. Kinds of Puzzles o 4.6. Tests for puzzlebox.c 5. Problem 3: Tree Sets in C o 5.1. Overview o 5.2. treeset main Demonstration o 5.3. tree funcs.c: tree functions o 5.4. treeset main.c: main function / application o 5.5. Grading Criteria for Problem 3 6. Assignment Submission o 6.1. Submit to Gradescope o 6.2. Late Policies 3.2 batt_update.c: Updating the Display with User Code Periodically the microcontroller will run code to adjust the battery display to show the current battery level. This function is int batt_update(); and it will be your job to write it. Rather than write everything that needs to be done within batt_update(), several helper functions will be used to divide this task into several more manageable and testable chunks. These should all be written in batt_update.c and are as follows. Converting Voltage Values to a Struct int set_batt_from_ports (batt_t *batt); // Uses the two global variables (ports) BATT_VOLTAGE_PORT and // BATT_STATUS_PORT to set the fields of the parameter 'batt'. If // BATT_VOLTAGE_PORT is negative, then battery has been wired wrong; // no fields of 'batt' are changed and 1 is returned to indicate an // error. Otherwise, sets fields of batt based on reading the voltage // value and converting to precent using the provided formula. Returns // 0 on a successful execution with no errors. This function DOES NOT // modify any global variables but may access global variables. // // CONSTRAINT: Avoids the use of the division operation as much as // possible. Makes use of shift operations in place of division where // possible. // CONSTRAINT: Uses only integer operations. No floating point // operations are used as the target machine does not have a FPU. // CONSTRAINT: Limit the complexity of code as much as possible. Do // not use deeply nested conditional structures. Seek to make the code // as short, and simple as possible. Code longer than 40 lines may be // penalized for complexity. This function works with the struct batt_t defined in batt.h which has the following layout. TABLE OF CONTENTS 1. Introduction 2. Download Code and Setup 3. Problem 1: Battery Meter Simulation o 3.1. Overview o 3.2. batt update.c: Updating the Display with User Code o 3.3. Battery Meter Simulator o 3.4. Sample Runs of batt main 3.5. Problem 1 Grading Criteria 4. Problem 2: Debugging the Puzzlebox o 4.1. Overview o 4.2. input.txt Input File o 4.3. gdb The GNU Debugger O 4.4. Typical Cycle o 4.5. Kinds of Puzzles o 4.6. Tests for puzzlebox.c 5. Problem 3: Tree Sets in C o 5.1. Overview o 5.2. treeset main Demonstration o 5.3. tree funcs.c: tree functions o 5.4. treeset main.c: main function / application o 5.5. Grading Criteria for Problem 3 6. Assignment Submission o 6.1. Submit to Gradescope o 6.2. Late Policies // 0 on a successful execution with no errors. This function DOES NOT // modify any global variables but may access global variables. // // CONSTRAINT: Avoids the use of the division operation as much as // possible. Makes use of shift operations in place of division where // possible. // CONSTRAINT: Uses only integer operations. No floating point // operations are used as the target machine does not have a FPU. // // CONSTRAINT: Limit the complexity of code as much as possible. Do // not use deeply nested conditional structures. Seek to make the code // as short, and simple as possible. Code longer than 40 lines may be // penalized for complexity. This function works with the struct batt_t defined in batt.h which has the following layout. // Breaks battery stats down into constituent parts typedef struct{ short mlvolts; char percent; char mode; } batt_t; // voltage read from port, units of 0.0005 Volts (milli Volts) // percent full converted from voltage // 1 for percent, 2 for volts, set based on bit 4 of BATT_STATUS_PORT The function set_batt_from_ports () will read the global variables mentioned above and fill in values for the struct fields of the parameter batt. Keep the following in mind while implementing the function. 1. Read the BATT_VOLTAGE_PORT value directly into the volt field. 2. Use the previously mentioned conversion formula to convert Volts to Percentage to fill in the percent field of the struct. BattV = BattVolt Port / 2 Batt% = (BattV - 3000) / 8 Note the CONSTRAINT that division should be avoided as much as possible. Employ shift operations in place of division where appropriate. 3. Note also the constraint: make use only of integer operations. Do not use float or double variables. This is emulates the somewhat common situation where simple microprocessors cannot perform floating point operations as they lack a Floating Point Unit (FPU). TABLE OF CONTENTS 1. Introduction 2. Download Code and Setup 3. Problem 1: Battery Meter Simulation o 3.1. Overview o 3.2. batt update.c: Updating the Display with User Code o 3.3. Battery Meter Simulator o 3.4. Sample Runs of batt main 3.5. Problem 1 Grading Criteria 4. Problem 2: Debugging the Puzzlebox o 4.1. Overview o 4.2. input.txt Input File o 4.3. gdb The GNU Debugger O 4.4. Typical Cycle o 4.5. Kinds of Puzzles o 4.6. Tests for puzzlebox.c 5. Problem 3: Tree Sets in C o 5.1. Overview o 5.2. treeset main Demonstration o 5.3. tree funcs.c: tree functions o 5.4. treeset main.c: main function / application o 5.5. Grading Criteria for Problem 3 6. Assignment Submission o 6.1. Submit to Gradescope o 6.2. Late Policies 3.1 Overview You are tasked with writing code which will be run by a microcontroller in a digital battery meter. The hardware has the following relevant features. A voltage sensor whose value can be accessed via a memory mapped port. In C this is presented as a global variable. Another port indicates whether the voltage should be displayed in Volts or Percentage of total battery capacity. A digital display with a port control port; setting certain global variable will change the display to show information to a user of the battery meter. User code that you will need to write to update the display based on the sensor value. A simulator program with Makefile to test your code Each feature is discussed in subsequent sections. Voltage Sensor A voltage sensor is attached to the battery meter and can be accessed via a C global variable. This is declared in the batt.h header file as follows. extern short BATT_VOLTAGE_PORT; // Sensor tied to the battery, provides a measure of voltage in units // of 0.0005 volts (half milli volts). The sensor can sense a wide // range of voltages including negatives but the batteries being // measured are Full when 3.8V (7600 sensor value) or above is read // and Empty when 3.0V (6000 sensor value) or lower is read. You do not need to define this variable as it is already there. You do NOT need to set this variable as it is automatically changed by the hardware. Instead, you will need to access its value to determine various the voltage level of the attached battery. As indicated in the variable documentation, a common (though mildly unreliable) means of detecting how much charge is left in a battery is to read the voltage on the battery. The type of battery being measured in this case has a higher voltage when fully charged and its lower voltage continuously lowers as it discharges. Past certain low voltage, the battery is unsafe to discharge and other hardware will disable the meter. The figure below shows the voltage range and corresponding Capacity Percentage for the battery. battery-voltage-v-percent2.png Figure 1: Relationship between Voltage and Percent full for batteries being measured by the meter. Notice the relationship between the Voltage which can be read directly and the Percent full which needs to be calculated from the voltage using the given formula: TABLE OF CONTENTS 1. Introduction 2. Download Code and Setup 3. Problem 1: Battery Meter Simulation o 3.1. Overview o 3.2. batt update.c: Updating the Display with User Code o 3.3. Battery Meter Simulator o 3.4. Sample Runs of batt main 3.5. Problem 1 Grading Criteria 4. Problem 2: Debugging the Puzzlebox o 4.1. Overview o 4.2. input.txt Input File o 4.3. gdb The GNU Debugger O 4.4. Typical Cycle o 4.5. Kinds of Puzzles o 4.6. Tests for puzzlebox.c 5. Problem 3: Tree Sets in C o 5.1. Overview o 5.2. treeset main Demonstration o 5.3. tree funcs.c: tree functions o 5.4. treeset main.c: main function / application o 5.5. Grading Criteria for Problem 3 6. Assignment Submission o 6.1. Submit to Gradescope o 6.2. Late Policies Notice the relationship between the Voltage which can be read directly and the Percent full which needs to be calculated from the voltage using the given formula: BattV = BattVolt Port / 2 Batt%= (BattV - 3000) / 8 Note the conversion is done in millivolts (0.001 volts) and the the voltage sensor is in units of half millivolts (0.0005 volts). Voltage Display Mode Another global variable exposes whether the user has pressed a button which toggles between displaying Volts or Percent full in the battery. extern unsigned char BATT_STATUS_PORT; // The bit at index 4 indicates whether display should be in Volts (0) // or Percent (1); the bit is tied to a user button which will toggle // it between modes. Other bits in this char may be set to indicate // the status of other parts of the meter and should be ignored: ONLY // BIT 4 BIT MATTERS. C code should only read this port. As per the documentation, only the 4th bit should be used while other bits may be nonzero and should be ignored. Bitwise operations are useful for this. Display Port The battery meter has a digital display which shows the remaining battery capacity. This display is controlled by a special memory area exposed as another global variable in C. extern int BATT_DISPLAY_PORT; // Controls battery meter display. Readable and writable. C code // should mostly write this port with a sequence of bits which will // light up specific elements of the LCD panel. While listed as in int, each bit of the is actually tied to part of the LCD display screen. When bits are set to 1, part of the display is lit up while 0 means it is not lit. The following diagrams show how various bit patterns will light up parts of the LCD display. Some bits correspond to parts of digits like "9" and "4" while others light up portions for the decimal place, Volt/Percent indicator, and bars of the leftmost visual level indicator. Above the display is the bit string which results in the elements on the display being turned on with "1" and off with a "0". TABLE OF CONTENTS 1. Introduction 2. Download Code and Setup 3. Problem 1: Battery Meter Simulation o 3.1. Overview o 3.2. batt update.c: Updating the Display with User Code o 3.3. Battery Meter Simulator o 3.4. Sample Runs of batt main o 3.5. Problem 1 Grading Criteria 4. Problem 2: Debugging the Puzzlebox o 4.1. Overview o 4.2. input.txt Input File o 4.3. gdb The GNU Debugger O 4.4. Typical Cycle o 4.5. Kinds of Puzzles o 4.6. Tests for puzzlebox.c 5. Problem 3: Tree Sets in C o 5.1. Overview o 5.2. treeset main Demonstration o 5.3. tree funcs.c: tree functions o 5.4. treeset main.c: main function / application o 5.5. Grading Criteria for Problem 3 6. Assignment Submission o 6.1. Submit to Gradescope o 6.2. Late Policies Display Port The battery meter has a digital display which shows the remaining battery capacity. This display is controlled by a special memory area exposed as another global variable in C. extern int BATT DISPLAY_PORT; // Controls battery meter display. Readable and writable. C code // should mostly write this port with a sequence of bits which will // light up specific elements of the LCD panel. While listed as in int, each bit of the is actually tied to part of the LCD display screen. When bits are set to 1, part of the display is lit up while 0 means it is not lit. The following diagrams show how various bit patterns will light up parts of the LCD display. Some bits correspond to parts of digits like "9" and "4" while others light up portions for the decimal place, Volt/Percent indicator, and bars of the leftmost visual level indicator. Above the display is the bit string which results in the elements on the display being turned on with "1" and off with a "0". Notice the following. The BATT_DISPLAY_PORT is a 32-bit integer but only some bits control the display 29 bits are used to control the full battery display (bits 0-28) Bit 0 controls whether the '%' Percent indicator is shown Bit 1 controls whether the 'V' Voltage indicator is shown Bit 2 controls whether the decimal place is on (for Volts) or off (for Percent) Bits 3-9 control the rightmost digit Bits 10-16 control the middle digit Bits 17-23 control the left digit Each digit follows the same pattern: lowest bit controls the upper right LCD digit bar with each higher bit going in a clockwise fashion and the middle bar being controlled by the highest order bit Bits 24-28 control the 5 'bars' in the visual level indicator Bits 29-31 are unused battery-meter-top-first-vp-right.png Figure 2: Full examples of how the 29 bits of the BATT_DISPLAY_PORT turns on/off parts of the LCD display. Each digit follows the same pattern of bit to bar correspondence. The lowest order (rightmost) bits control the percent, voltage, and decimal place indicator. Middle bits control "bar" of each digit starting with the top bar and proceeding around the outside clockwise with the final bit for each digit controlling the middle bar. This pattern is followed for all 3 digits. The uppermost bits control the level indicator bars. TABLE OF CONTENTS 1. Introduction 2. Download Code and Setup 3. Problem 1: Battery Meter Simulation o 3.1. Overview o 3.2. batt update.c: Updating the Display with User Code o 3.3. Battery Meter Simulator o 3.4. Sample Runs of batt main 3.5. Problem 1 Grading Criteria 4. Problem 2: Debugging the Puzzlebox o 4.1. Overview o 4.2. input.txt Input File o 4.3. gdb The GNU Debugger O 4.4. Typical Cycle o 4.5. Kinds of Puzzles o 4.6. Tests for puzzlebox.c 5. Problem 3: Tree Sets in C o 5.1. Overview o 5.2. treeset main Demonstration o 5.3. tree funcs.c: tree functions o 5.4. treeset main.c: main function / application o 5.5. Grading Criteria for Problem 3 6. Assignment Submission o 6.1. Submit to Gradescope o 6.2. Late Policies Figure 2: Full examples of how the 29 bits of the BATT_DISPLAY_PORT turns on/off parts of the LCD display. Each digit follows the same pattern of bit to bar correspondence. The lowest order (rightmost) bits control the percent, voltage, and decimal place indicator. Middle bits control "bar" of each digit starting with the top bar and proceeding around the outside clockwise with the final bit for each digit controlling the middle bar. This pattern is followed for all 3 digits. The uppermost bits control the level indicator bars. For reference, each number to be displayed in the LCD battery meter follows the same patter of bits which is shown in the below diagram with the rightmost digit bit positions. digital-digits-top-first.png Figure 3: Pattern of bits for all 10 numerals and a few extra symbols 3.2 batt_update.c: Updating the Display with User Code Periodically the microcontroller will run code to adjust the battery display to show the current battery level. This function is int batt_update(); and it will be your job to write it. Rather than write everything that needs to be done within batt_update(), several helper functions will be used to divide this task into several more manageable and testable chunks. These should all be written in batt_update.c and are as follows. Converting Voltage Values to a Struct int set batt_from_ports (batt_t *batt); // Uses the two global variables (ports) BATT_VOLTAGE_PORT and // BATT_STATUS_PORT to set the fields of the parameter 'batt'. If // BATT_VOLTAGE_PORT is negative, then battery has been wired wrong; // no fields of 'batt' are changed and 1 is returned to indicate an // error. Otherwise, sets fields of batt based on reading the voltage // value and converting to precent using the provided formula. Returns // 0 on a successful execution with no errors. This function DOES NOT // modify any global variables but may access global variables. // // CONSTRAINT: Avoids the use of the division operation much as TABLE OF CONTENTS 1. Introduction 2. Download Code and Setup 3. Problem 1: Battery Meter Simulation o 3.1. Overview o 3.2. batt update.c: Updating the Display with User Code o 3.3. Battery Meter Simulator o 3.4. Sample Runs of batt main 3.5. Problem 1 Grading Criteria 4. Problem 2: Debugging the Puzzlebox o 4.1. Overview o 4.2. input.txt Input File o 4.3. gdb The GNU Debugger O 4.4. Typical Cycle o 4.5. Kinds of Puzzles o 4.6. Tests for puzzlebox.c 5. Problem 3: Tree Sets in C o 5.1. Overview o 5.2. treeset main Demonstration o 5.3. tree funcs.c: tree functions o 5.4. treeset main.c: main function / application o 5.5. Grading Criteria for Problem 3 6. Assignment Submission o 6.1. Submit to Gradescope o 6.2. Late Policies 3.2 batt_update.c: Updating the Display with User Code Periodically the microcontroller will run code to adjust the battery display to show the current battery level. This function is int batt_update(); and it will be your job to write it. Rather than write everything that needs to be done within batt_update(), several helper functions will be used to divide this task into several more manageable and testable chunks. These should all be written in batt_update.c and are as follows. Converting Voltage Values to a Struct int set_batt_from_ports (batt_t *batt); // Uses the two global variables (ports) BATT_VOLTAGE_PORT and // BATT_STATUS_PORT to set the fields of the parameter 'batt'. If // BATT_VOLTAGE_PORT is negative, then battery has been wired wrong; // no fields of 'batt' are changed and 1 is returned to indicate an // error. Otherwise, sets fields of batt based on reading the voltage // value and converting to precent using the provided formula. Returns // 0 on a successful execution with no errors. This function DOES NOT // modify any global variables but may access global variables. // // CONSTRAINT: Avoids the use of the division operation as much as // possible. Makes use of shift operations in place of division where // possible. // CONSTRAINT: Uses only integer operations. No floating point // operations are used as the target machine does not have a FPU. // CONSTRAINT: Limit the complexity of code as much as possible. Do // not use deeply nested conditional structures. Seek to make the code // as short, and simple as possible. Code longer than 40 lines may be // penalized for complexity. This function works with the struct batt_t defined in batt.h which has the following layout. TABLE OF CONTENTS 1. Introduction 2. Download Code and Setup 3. Problem 1: Battery Meter Simulation o 3.1. Overview o 3.2. batt update.c: Updating the Display with User Code o 3.3. Battery Meter Simulator o 3.4. Sample Runs of batt main 3.5. Problem 1 Grading Criteria 4. Problem 2: Debugging the Puzzlebox o 4.1. Overview o 4.2. input.txt Input File o 4.3. gdb The GNU Debugger O 4.4. Typical Cycle o 4.5. Kinds of Puzzles o 4.6. Tests for puzzlebox.c 5. Problem 3: Tree Sets in C o 5.1. Overview o 5.2. treeset main Demonstration o 5.3. tree funcs.c: tree functions o 5.4. treeset main.c: main function / application o 5.5. Grading Criteria for Problem 3 6. Assignment Submission o 6.1. Submit to Gradescope o 6.2. Late Policies // 0 on a successful execution with no errors. This function DOES NOT // modify any global variables but may access global variables. // // CONSTRAINT: Avoids the use of the division operation as much as // possible. Makes use of shift operations in place of division where // possible. // CONSTRAINT: Uses only integer operations. No floating point // operations are used as the target machine does not have a FPU. // // CONSTRAINT: Limit the complexity of code as much as possible. Do // not use deeply nested conditional structures. Seek to make the code // as short, and simple as possible. Code longer than 40 lines may be // penalized for complexity. This function works with the struct batt_t defined in batt.h which has the following layout. // Breaks battery stats down into constituent parts typedef struct{ short mlvolts; char percent; char mode; } batt_t; // voltage read from port, units of 0.0005 Volts (milli Volts) // percent full converted from voltage // 1 for percent, 2 for volts, set based on bit 4 of BATT_STATUS_PORT The function set_batt_from_ports () will read the global variables mentioned above and fill in values for the struct fields of the parameter batt. Keep the following in mind while implementing the function. 1. Read the BATT_VOLTAGE_PORT value directly into the volt field. 2. Use the previously mentioned conversion formula to convert Volts to Percentage to fill in the percent field of the struct. BattV = BattVolt Port / 2 Batt% = (BattV - 3000) / 8 Note the CONSTRAINT that division should be avoided as much as possible. Employ shift operations in place of division where appropriate. 3. Note also the constraint: make use only of integer operations. Do not use float or double variables. This is emulates the somewhat common situation where simple microprocessors cannot perform floating point operations as they lack a Floating Point Unit (FPU).
Expert Answer:
Answer rating: 100% (QA)
In this code we are tasked with implementing the setdisplayfrombatt function that takes a battt struct and an integer pointer display This function is responsible for setting the bits in the integer p... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Our product is watch please tell answer of these questions . This is mini presentation Our product On this slide, describe: WHAT is the need / want for this product? (In other words, why do . you...
-
Select a personal selling situation and submit a one sentence description. Great examples: Selling your idea at work--start conversations with people at work about an idea you've been thinking about...
-
Below you can two sets of single-index model regression output. We collect data of the monthly return of S&P500, A, and B for the past 59 months. For each regression, we run either the monthly stock...
-
1 YOUR NAME: 2 Asset # 3 Asset name: 4 Date acquired: 5 Cost: 6 Depreciation method: 7 Salvage (residual) value: 8 Estimated useful life (years): 9 222 Computer 1/1/2018 $50,000 Straight Line (SL)...
-
The hydraulic lift in a car repair shop has an output diameter of 30 cm and is to lift cars up to 2000 kg. Determine the fluid gage pressure that must be maintained in the reservoir.
-
Do you expect ClCH2CH2NH2 to be a stronger or weaker base than CH3CH2NH2? Explain.
-
Asphalt at \(120^{\circ} \mathrm{F}\), considered to be a Newtonian fluid with a viscosity 80,000 times that of water and a specific gravity of 1.09, flows through a pipe of diameter \(2.0...
-
If you deposit $10,000 in a bank account that pays 10% interest annually, how much will be in your account after 5 years?
-
Discuss why the learning websites baby cant wait and naeyc are helpful and developmentally appropriate for the children with which you work?
-
Show how the IS and LM schedules look in the monetarist view. Use these schedules to illustrate the monetarist conclusions about the relative effectiveness of monetary and fiscal policy.
-
The volume of a typical hot-air balloon is 2,800 m. The temperature inside the balloon during flight is 110C. If the pressure inside the balloon is 101,000 Pa, determine the density of the air inside...
-
1) Suppose you invest $10000 into a mutual fund that is expected to earn a rate of return of 7%. How money will you have in 7 years? .Note: Express your answers in strictly numerical terms.For...
-
A +16 nC point charge is placed at the origin, and a +6 nC charge is placed on the x axis at x = 1m. At what position on the ax axis is the net electric field zero? (Be careful to keep track of the...
-
Steve wants to invest 2,000 today and leave that for 12 years at 6 % compounded annually plus he wants to invest 150 per month at the beginning for 6 % compounded annually for 12 years. How much will...
-
In year 0, Longworth Partnership purchased a machine for $50,500 to use in its business. In year 3, Longworth sold the machine for $35,200. Between the date of the purchase and the date of the sale,...
-
A battery is connected in series with a capacitor. There are 100 electrons on the bottom plate of the capacitor. What is the charge on the bottom plate of the capacitor?
-
Calculate the partial derivative using implicit differentiation: xy + sin(zz) + y = 0 y
-
Do public and private companies follow the same set of accounting rules? Explain.
-
Bev and Ken Hair have been married for 3 years. They live at 3567 River Street, Springfield, MO 63126. Ken is a full-time student at Southwest Missouri State University (SMSU) and Bev works as an...
-
In 2012, Gale and Cathy Alexander hosted an exchange student, Axel Muller, for 9 months. Axel was part of International Student Exchange Programs (a qualified organization). Axel attended tenth grade...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1 and 2. On September 1, Irene opened a retail store that specializes in sports car...
-
Refer to Example 7, Chapter 10, where 48 of 60 transceivers passed inspection. (a) Obtain the maximum likelihood estimate of the probability that a transceiver will pass inspection. (b) Obtain the...
-
The daily number of accidental disconnects with a server follows a Poisson distribution. On five days \[\begin{array}{lllll}2 & 5 & 3 & 3 & 7\end{array}\] accidental disconnects are observed. (a)...
-
In one area along the interstate, the number of dropped wireless phone connections per call follows a Poisson distribution. From four calls, the number of dropped connections is...
Study smarter with the SolutionInn App