You are on page 1of 11

Homework 5

Rashid Almerekhi

Date and Time:

07: 20 am

09/27/2022

Question 01:
/*

This code was automatically generated using the Riverside-Irvine State machine Builder tool

Version 2.7 --- 9/27/2022 7:28:34 PST

*/

#include "rims.h"

/*Define user variables and functions for this state machine here.*/

unsigned char CTT_Clk;

void TimerISR() {

CTT_Clk = 1;

}
enum CTT_States { CTT_DDL, CTT_MMP } CTT_State;

TickFct_RES() {

switch(CTT_State) { // Transitions

case -1:

CTT_State = CTT_MMP;

break;

case CTT_DDL:

if (A0) {

CTT_State = CTT_MMP;

break;

case CTT_MMP:

if (A1) {

CTT_State = CTT_DDL;

else if (1) {

CTT_State = CTT_MMP;

break;

default:

CTT_State = CTT_MMP;

} // Transitions

switch(CTT_State) { // State actions

case CTT_DDL:
B0=0;

break;

case CTT_MMP:

B0=1;

break;

default: // ADD default behaviour below

break;

} // State actions

int main() {

const unsigned int periodRES = 1000; // 1000 ms default

TimerSet(periodRES);

TimerOn();

CTT_State = -1; // Initial state

B = 0; // Init outputs

while(1) {

TickFct_RES();

while(!CTT_Clk);

CTT_Clk = 0;
} // while (1)

} // Main

Question 02:
/*

This code was automatically generated using the Riverside-Irvine State machine Builder tool

Version 2.7 --- 9/27/2022 7:30:16 PST

*/

#include "rims.h"

unsigned char JIK_Clk;

void TimerISR() {

JIK_Clk = 1;

}
enum JIK_States { JIK_MLC, JIK_TTU, JIK_QRT, JIK_ICI } JIK_State;

TickFct_VRBL() {

switch(JIK_State) { // Transitions

case -1:

JIK_State = JIK_MLC;

break;

case JIK_MLC:

if (A1) {

JIK_State = JIK_TTU;

else if (!A1) {

JIK_State = JIK_MLC;

break;

case JIK_TTU:

if (A1) {

JIK_State = JIK_QRT;

break;

case JIK_QRT:

if (B==0x80&&A1) {

JIK_State = JIK_ICI;

else if (!A1) {

JIK_State = JIK_MLC;
}

break;

case JIK_ICI:

if (B==0x01&&A1) {

JIK_State = JIK_QRT;

else if (!A1) {

JIK_State = JIK_MLC;

break;

default:

JIK_State = JIK_MLC;

} // Transitions

switch(JIK_State) { // State actions

case JIK_MLC:

if(B==0x00) {B=0xFF;}

else {B=0x00;}

break;

case JIK_TTU:

B=0x01;

break;

case JIK_QRT:

if(B==0x80&&A1)

{
}

else {B=B<<1;}

break;

case JIK_ICI:

if(B==0x01&&A1) {}

else

{B=B>>1;

break;

default: // ADD default behaviour below

break;

} // State actions

int main() {

const unsigned int periodVRBL = 1000; // 1000 ms default

TimerSet(periodVRBL);

TimerOn();

JIK_State = -1; // Initial state

B = 0; // Init outputs
while(1) {

TickFct_VRBL();

while(!JIK_Clk);

JIK_Clk = 0;

} // while (1)

} // Main

Outline:

Developers implementing applications that combine one or more very high-frequency


interrupts and a number of other interrupt-driven background functions may be tempted to
avoid using an RTOS because of concerns about the interrupt overhead.

However, this approach is akin to “throwing the baby out with the bathwater.” A more optimal
approach is to take advantage of an RTOS to implement the majority of the system function,
but to handle the high-frequency interrupts outside of the RTOS, enabling the specific ISRs to
be highly optimized.

The drawback of this approach is that a “non-RTOS” ISR cannot interact with the threads
managed by the RTOS. If the ISR functionality is truly standalone, this is not an issue. However,
in many applications it might be necessary for the high-frequency ISR to pass some data back
into an RTOS thread for background processing.

When you press a key down and it triggers the switch, sometimes the key can bounce. Since
computers run so quickly, this bouncing can register as multiple keystrokes as it triggers the
switch multiple times. Debouncing mechanisms detect these bounces and register them as only
one keystroke so you have more reliable key input. Debounce mechanisms are usually invisible
to the user and you (usually) won’t be able to trigger them by trying to press the key
repeatedly.

You might also like