Professional Documents
Culture Documents
Rashid Almerekhi
07: 20 am
09/27/2022
Question 01:
/*
This code was automatically generated using the Riverside-Irvine State machine Builder tool
*/
#include "rims.h"
/*Define user variables and functions for this state machine here.*/
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
case CTT_DDL:
B0=0;
break;
case CTT_MMP:
B0=1;
break;
break;
} // State actions
int main() {
TimerSet(periodRES);
TimerOn();
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
*/
#include "rims.h"
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
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;
break;
} // State actions
int main() {
TimerSet(periodVRBL);
TimerOn();
B = 0; // Init outputs
while(1) {
TickFct_VRBL();
while(!JIK_Clk);
JIK_Clk = 0;
} // while (1)
} // Main
Outline:
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.