Mohammadali Estakhr 30077052 Embedded System: Abstract

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Mohammadali Estakhr

30077052
Embedded System
Abstract:
-This RTC project uses RTOS to construct a digital alarm clock. It will entail utilizing E2 studio
to create the synergy C project "S7G2_ALARMCLOCK." The chosen combinations are listed
below. These are the J-Link ARM Debugger, the GCC ARM Embedded Toolchain, the
Toolchain Version 4.9.3.20150529, the SSP Version 1.6.0, and the Board support package for
the chosen synergy family (BSP).
Super loop architecture and RTOS (Real-Time-Operating System) served as the foundation for
this project. The SK-S7G2 starting kit was needed for the application in order to read the
digital alarm clock's program code.
The HAL/Common stack must be used by the configuration. Priority 4 is used for the Period
Interrupt priority and the Alarm Interrupt priority.
This was displayed in "hal_entry.c." The RTC HAL on r_rtc stack from the HAL/Common Stacks
Drivers Timers was then added after choosing HAL/Common in the threads tab. After then,
the project material was produced.
In hal_entry.c, include an entry method that invokes rtc_initiate(). This was then assembled
again without any faults or warnings. The SK-S7G2 board is linked to the host at the other end
of the USB cord.

Introduction and explaination of the project:


-One of the special projects undertaken to evaluate our students' comprehension of the idea
of embedded system design is the construction of a digital alarm clock that utilizes a Real Time
Operating System.
Writing the program for the digital alarm clock requires the usage of the machine language C.
The application aims to incorporate both the regular clock and the alarm capabilities. Only
when the alarm clock is in the "Normal Display" mode can it be set or cleared.
This relates to the sole situation in which the alarm condition can be triggered, necessitating
the setting of the alarm and the alignment of the real time with the alarm time. It will turn off
the alarm, removing it from its predetermined state.
The alarm clock will automatically cease the LEDs from toggling after one minute if the user
does not intervene to stop the alarm, which will again remove it from its predetermined state.
The programming language C is used to write these parameters, and the project design will use
it. initializes and configures the RTC HAL module, is defined in the related source file. A user-
callback function in this file toggles the corresponding LEDs in response to an interrupt that is
created.
-The Interrupt type was enabled to support more than one sequence. For the periodic interrupt
event was added in the interrupt enable API.
Similarly, the periodic interrupt rate was configured to generate an interrupt at every 60
second(s).In the same note, the alarm interrupt was set by configuring the RTC alarm time
structure to enable alarm for various entity to match the set the timer in the RTC time sub-
structure.

Generating RTC Hal:


-The RTC HAL module application code was imported into the ISDE, built, and ran debugged in
order to run the project and observe it executed on a target kit.
In accordance with this, the GUIX was set up to permit the development of an extra button.
This button was created after being modified to meet the precise specifications. It was checked
and shown on the display panel.
- The steps for the implementation procedure were as follows:

first, the BSP project template was chosen, and then a new Renesas Synergy Project for the SK-
S7G2 board called RTC_HAL was created.
After choosing the configuration file from the project, the RTC HAL on the r_rtc stack from the
HAL/Common Stacks Drivers Timers was chosen, followed by the Threads tab, the
Hal/Common tab, and the Threads tab.
After choosing the interrupt priority, click the Generate ProjectContent button to start the
project's generation. After that, the program code was introduced from the entry function
hal_entry.c, which calls rtc_initiate(), and the file rtc_hal_mg.c/.h.
The flow chart's design, which clearly displayed the program's operation flow, served as the
basis for writing this code.
Creating buttons on screen :
Using the GUIX interface, button B2 was created, and its settings were set to comply with the
necessary requirements.
The setup was then debugged into the S7G2 Board once the outputwas created. In accordance,
a picture display is attached.

The next step is configuring LEDS :


To setup the LED, a superloop was created in the hal.c entry, code was written, and the LED
was set up. The sample code is written as follows.

Then configuring Timer :


Similar to this, a new stack was made in the RTC clock thread entry for timer configuration
because the system is an RTOS design standard. It was set up using the appropriate settings.

Additionally, the alarm clock thread entry was made and set up to operate in line with the
project model and design's design specifications.
Enclosed with the C code for the thread entry for each of the events is the program
configuration.The state diagram is displayed. displaying the state machine's operational
sequence. It is the digital alarm clock in this instance.

The State Diagrams:


Related flow charts:

The user-defined data, which was pre-configured in the project template, was utilized for the
time keeping variable for each RTC and alarm clock. According to the flow chart below,
button 2 will update the appropriate vanable of the time if any of the clocks is in a time
adjust condition.
Alarm ring state should be displayed by switching LEDs, as there are no available audio
outputs. The toggling function was implemented in this design in accordance with the
provided flow diagram.
Explainations about Real Time Clock :
We ought to be able to turn on or off the alarm in accordance with the necessity. The alarm
set feature has been implemented for that reason.
This function's objective is to visually display the alarm set states by turning on LED 2 and
verifying that the alarm is activated by utilizing the alarm active flag.
If the alarm is on and no button is pressed, it should turn off automatically. In order to do
that, we have included a second hardware timer, designated timer 1, with a one-minute
duration within the RTC Thread in this architecture.
This timer was set up as a one-shot timer, meaning that it must be manually restarted each
time the timer overflows.

Conclusion:
In conclusion, creating a diagram of state transitions to control various modes of operation,
such as regular display and alarm activation, is a necessary step in constructing a digital alarm
clock using the Renesas S7G2-SK development board.
While the alarm functionality only permits the setting and clearing of alarms while the display
is in its usual state, the clock feature uses LEDs to show the current time. LEDs are used to
show if the alarm is set and in what condition.
Two buttons allow the user to interact: one for mode selection and the other for stopping
the alarm. Furthermore, if the alarm is not manually turned off after one minute, automatic
alarm stopping takes place. Making sure the digital alarm clock implementation is reliable
and functioning requires careful testing, optimization, documentation, and deployment.
SG72_alarmclock setting screenshots :
SG72_alarmclock Code:
#include "RTC_thread.h"
#include "u_rtc_clk.h"

clock_t u_rtc_clk; // setting normal clock


clock_t u_Alarm_clk; // alarm timing
estate state; // state variable deceleration
uint8_t flag_B1 = 0; // button 1 global variable
uint8_t flag_B2 = 0; // button 2 global variable
volatile uint8_t toggling = 0;
volatile uint8_t Alarm_flag = 0;

/* RTC Thread entry function */


void RTC_thread_entry(void)
{
u_rtc_clk.hour = 23; // clock hour to start on screen
u_rtc_clk.min = 58; // clock minutes to start on screen
u_rtc_clk.sec = 50; //clock seconds to start on screen

u_Alarm_clk.hour = 23; // alarm hour to start on screen


u_Alarm_clk.min = 59; // alarm min to start on screen
u_Alarm_clk.sec = 00; // alarm seconds to start on screen

state = rtc_clk; // initialising state to "rtc_clk"

g_timer0.p_api->open(g_timer0.p_ctrl,g_timer0.p_cfg); // Initialising of Timer


channel 0 stack
g_timer0.p_api->start(g_timer0.p_ctrl); // start the hardware timer

g_timer1.p_api->open(g_timer1.p_ctrl,g_timer1.p_cfg); // Initialising of Timer


channel 1 stack

g_ioport.p_api->pinWrite(IOPORT_PORT_06_PIN_00,IOPORT_LEVEL_HIGH); // turning of
green LED
g_ioport.p_api->pinWrite(IOPORT_PORT_06_PIN_01,IOPORT_LEVEL_HIGH); // turning of
Red LED
g_ioport.p_api->pinWrite(IOPORT_PORT_06_PIN_02,IOPORT_LEVEL_HIGH); // turning of
Amber LED

state = rtc_clk;

while (1)

if(Alarm_flag == 1)
{
if(toggling)
{
toggling=0;
g_ioport.p_api->pinWrite(IOPORT_PORT_06_PIN_00,IOPORT_LEVEL_LOW); //
turning on LED 1
g_ioport.p_api->pinWrite(IOPORT_PORT_06_PIN_01,IOPORT_LEVEL_HIGH); //
turning on LED 2
}
else
{
toggling=1;
g_ioport.p_api->pinWrite(IOPORT_PORT_06_PIN_00,IOPORT_LEVEL_HIGH); //
turning off LED 1
g_ioport.p_api->pinWrite(IOPORT_PORT_06_PIN_01,IOPORT_LEVEL_LOW); //
turning off LED 2
}
R_BSP_SoftwareDelay(500,BSP_DELAY_UNITS_MILLISECONDS); // creating delay
of 5 seconds

if(flag_B1==0 |flag_B2==0)
{
Alarm_flag = 0;
}
}

/* TODO: add your own code here */


switch(state)
{

case rtc_clk: // Its a normal display

if((u_rtc_clk.sec == u_Alarm_clk.sec) &&( u_rtc_clk.min ==


u_Alarm_clk.min) && (u_rtc_clk.hour == u_Alarm_clk.hour)) // If hour , min and
seconds of the alarm and clock are matched.

{
Alarm_flag = 1; //notice alarm flag
g_timer1.p_api->start(g_timer1.p_ctrl); // start
the hardware timer

if(flag_B1 == 1)
{
flag_B1 = 0; // reseting B1 flag
state = rtc_clk_setH; // changing next state
}
if (flag_B2 == 1)
{
flag_B2 = 0; // reseting flag
state = alarm_clk;
}
break;

case rtc_clk_setH:
if(flag_B1 == 1)
{
flag_B1 = 0; //resetting flag B1
state = rtc_clk_setM; // changing state
}

if(flag_B2 == 1)
{
if (u_rtc_clk.hour>=23)
{
u_rtc_clk.hour = 0;
flag_B2 = 0; // reseting flag
}
else
{
u_rtc_clk.hour = u_rtc_clk.hour +1; // incrementing of hour
flag_B2 = 0;
}

}
break;

case rtc_clk_setM:
if(flag_B1 == 1)
{
flag_B1 = 0; // resetting flag B1
state = rtc_clk_setS; // changing state
}

if(flag_B2 == 1)
{
if (u_rtc_clk.min>=59)
{
u_rtc_clk.min = 0;
flag_B2 = 0; // reseting flag
}
else
{
u_rtc_clk.min = u_rtc_clk.min +1; // incrementing of hour
flag_B2 = 0; // resetting flag B1
}

}
break;

case rtc_clk_setS:
if(flag_B1 == 1)
{
flag_B1 = 0; // resetting flag B1
state = rtc_clk; // changing state
}

if(flag_B2 == 1)
{
if (u_rtc_clk.sec>=59)
{
u_rtc_clk.sec = 0;
flag_B2 = 0; // reseting flag
}
else
{
u_rtc_clk.sec = u_rtc_clk.sec +1; // incrementing of seconds
flag_B2 = 0;
}
}
break;

case alarm_clk:
if(flag_B2 == 1)
{
flag_B2=0; // resetting flag B2
state= rtc_clk;

}
if (flag_B1 == 1)
{
flag_B1 =0; // resetting flag B1

state = alarm_clk_setH;
}
break;

case alarm_clk_setH:
if(flag_B2 == 1)
{
state= alarm_clk_setM ;
flag_B1 = 0; // resetting flag B1
}
if (flag_B2 == 1)
{
if(u_Alarm_clk.hour >= 23)
{
u_Alarm_clk.hour = u_Alarm_clk.hour+1 ; // increment alarm
clock hour
flag_B2 = 0; // resetting flag B2
}

else
{
u_Alarm_clk.hour = 0;
flag_B2=0; // resetting flag B2
}

break;

case alarm_clk_setM:

if(flag_B1 == 1)
{
state= alarm_clk_setS ;
flag_B1 = 0; // resetting flag B1
}

if (flag_B2 == 1)
{
if(u_Alarm_clk.min>=59)
{
u_Alarm_clk.min = 0; ;
flag_B2 = 0; // resetting flag B2
}
else
{
u_Alarm_clk.min = u_Alarm_clk.min+1; // increment alarm clock
minutes
flag_B2=0; // resetting flag B2

}
}
break;

case alarm_clk_setS:

if(flag_B1 == 1)
{
state= alarm_clk ;
flag_B1 = 0; // resetting flag B1
}
if (flag_B2 == 1)
{
if(u_Alarm_clk.sec>=59)
{
u_Alarm_clk.sec = u_Alarm_clk.sec +1 ;
flag_B2 = 0; // resetting flag B2
}

else
{
u_Alarm_clk.sec = 0;
flag_B2=0;
}
}

break;

default:

break;

tx_thread_sleep (1); // leave this line, thread execution rate is 10ms


}
}

// timer0 interrupt service rutine

void cb_timer_ch0(timer_callback_args_t *p_args)


{

if (u_rtc_clk.sec>=59)
{
u_rtc_clk.sec = 0;

if (u_rtc_clk.min>=59)
{
u_rtc_clk.min = 0;

if (u_rtc_clk.hour>=23)
{
u_rtc_clk.hour = 0;
}
else
{
u_rtc_clk.hour = u_rtc_clk.hour+1 ; // increment hours
}
}
else
{
u_rtc_clk.min = u_rtc_clk.min+1; // increment minutes
}
}
else
{
u_rtc_clk.sec = u_rtc_clk.sec+1 ; // increment seconds
}
}

// timer1 interrupt service rutine

void CB_timer1(timer_callback_args_t *p_args)


{
if(p_args->event == TIMER_EVENT_EXPIRED)
{
Alarm_flag= 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy