Professional Documents
Culture Documents
#include <LPC21xx.H>
void clock_wise(void);
void anti_clock_wise(void);
int main(void)
{
PINSEL0 = 0x00FFFFFF; //P0.12 to P0.15 GPIo
IO0DIR |= 0x0000F000; //P0.12 to P0.15 output
while(1)
{
for(j=0;j<50;j++) // 20 times in Clock wise Rotation
clock_wise();
} // End of while(1)
} // End of main
void clock_wise(void)
{
var1 = 0x00000800; //For Clockwise
for(i=0;i<=3;i++) // for A B C D Stepping
{
var1 = var1<<1; //For Clockwise
var2 = ~var1;
var2 = var2 & 0x0000F000;
IO0PIN = ~var2;
}
The stepping of stepper motor can be implemented in different ways by changing the sequence of activation of the
stator windings
Wave Step: In the wave step mode only one phase is energized at a time and each coils of the phase is energies
alternatively.
The coils A, B, C and D are energized in the following order:
OR
With a neat interface diagram, illustrate the connection of master and slave devices on I2C bus
Inter Integrated Circuit (I2C) Bus: The Inter Integrated Circuit Bus (I2C-Pronounced 'I square C') is a
synchronous bidirectional half duplex (one-directional communication at a given point of time) two wire serial
interface bus. The concept of I2C bus was developed by 'Philips Semiconductors' in the early 1980s. The original
intention of I2C was to provide an easy way of connection between a microprocessor/ microcontroller system and
the peripheral chips in television sets. The I2C bus comprise of two bus lines, namely; Serial Clock-SCL and
Serial Data-SDA. o SCL line is responsible for generating synchronization clock pulses. o SDA is responsible for
2 a. transmitting the serial data across devices. I2C bus is a shared bus system to which many number of I2C devices 2+6=8
can be connected. Devices connected to the I2C bus can act as either 'Master' device or 'Slave' device. o The
'Master' device is responsible for controlling the communication by initiating/ terminating data transfer, sending
data and generating necessary synchronization clock pulses. o 'Slave' devices wait for the commands from the master
and respond upon receiving the commands. 'Master' and 'Slave' devices can act as either transmitter or receiver;
regardless whether a master is acting as transmitter or receiver, the synchronization clock signal is generated by the
'Master' device only. I2C supports multi-masters on the same bus. The following Figure shows bus interface
diagram, which illustrates the connection of master and slave devices on the I2C bus
The sequence of operations for communicating with an I2C slave device is listed below:
1. The master device pulls the clock line (SCL) of the bus to 'HIGH '
2. The master device pulls the data line (SDA) 'LOW', when the SCL line is at logic 'HIGH' (This is the 'Start'
condition for data transfer)
3. The master device sends the address (7-bit or 10-bit wide) of the 'slave' device to which it wants to communicate,
over the SDA line. Clock pulses are generated at the SCL line for synchronizing the bit reception by the slave device.
The MSB of the data is always transmitted first. The data in the bus is valid during the 'HIGH' period of the clock
signal
4. The master device sends the Read or Write bit (Bit value = 1 Read operation; Bit value = 0 Write operation)
according to the requirement
5. The master device waits for the acknowledgement bit from the slave device whose address is sent on the bus
along with the Read/ Write operation command. Slave devices connected to the bus compares the address received
with the address assigned to them
6. The slave device with the address requested by the master device responds by sending an acknowledge bit (Bit
value = 1) over the SDA line
7. Upon receiving the acknowledge bit, the master device sends the 8-bit data to the slave device over SDA line, if
the requested operation is 'Write to device'. If the requested operation is 'Read from device', the slave device sends
data to the master over the SDA line
8. The master device waits for the acknowledgement bit from the device upon byte transfer complete for a write
operation and sends an acknowledge bit to the Slave device for a read operation
9. The master device terminates the transfer by pulling the SDA line ‘HIGH' when the clock line SCL is at logic
'HIGH' (Indicating the 'STOP' condition)
“Cross-complier (for cross platform development and complier for same platform development)”,
a. 8
“Linker”, and
a “Debugger”.
Ignore Deadlocks: Always assume that the system design is deadlock free. This is acceptable for the
reason the cost of removing a deadlock is large compared to the chance of happening a deadlock. UNIX
is an example for an OS following this principle. A life critical system cannot pretend that it is deadlock
free for any reason.
Detect and Recover: This approach suggests the detection of a deadlock situation and recovery from it.
This is similar to the deadlock condition that may arise at a traffic junction. When the vehicles from
different directions compete to cross the junction, deadlock (traffic jam) condition is resulted. Once a
deadlock (traffic jam) is happened at the junction, the only solution is to back up the vehicles from one
direction and allow the vehicles from opposite direction to cross the junction. If the traffic is too high,
lots of vehicles may have to be backed up to resolve the traffic jam. This technique is also known as
„back up cars‟ technique.
Operating Systems keep a resource graph in their memory. The resource graph is updated on each
resource request and release. A deadlock condition can be detected by analyzing the resource graph by
graph analyzer algorithms. Once a deadlock condition is detected, the system can terminate a process or
preempt the resource to break the deadlocking cycle.
Avoid Deadlocks: Deadlock is avoided by the careful resource allocation techniques by the Operating System. It
is similar to the traffic light mechanism at junctions to avoid the traffic jams.
Prevent Deadlocks: Prevent the deadlock condition by negating one of the four conditions favoring the deadlock
situation.
Ensure that a process does not hold any other resources when it requests a resource. This can be achieved by
implementing the following set of rules/ guidelines in allocating resources to processes.
1. A process must request all its required resource and the resources should be allocated before the process begins
its execution.
2. Grant resource allocation requests from processes only if the process does not hold a resource currently.
Ensure that resource preemption (resource releasing) is possible at operating system level. This can be achieved
by implementing the following set of rules/ guidelines in resources allocation and releasing:
1. Release all the resources currently held by a process if a request made by the process for a new resource is not
able to fulfill immediately.
2. Add the resources which are preempted (released) to a resource list describing the resources which the process
requires to complete its execution.
3. Reschedule the process for execution only when the process gets its old resources and the new resource which
is requested by the process.
OR
Illustrate the functional and non-functional requirements for selecting RTOS for an embedded
system.
Functional Requirements:
Processor Support: It is not necessary that all RTOS‟s support all kinds of processor architecture. It is
essential to ensure the processor support by the RTOS.
Memory Requirements: The OS requires ROM memory for holding the OS files and it is normally stored
in a non-volatile memory like FLASH. OS also requires working memory RAM for loading the OS
services. Since embedded systems are memory constrained, it is essential to evaluate the minimal ROM
and RAM requirements for the OS under consideration.
Real-time Capabilities: It is not mandatory that the operating system for all embedded systems need to be
4 a. Real-time and all embedded Operating systems-are 'Real-time' in behavior. The task/ process scheduling 4+4=8
policies play an important role in the 'Real-time' behavior of an OS. Analyze the real-time capabilities of
the OS under consideration and the standards met by the operating system for real-time capabilities.
Kernel and Interrupt Latency: The kernel of the OS may disable interrupts while executing certain services
and it may lead to interrupt latency. For an embedded system whose response requirements are high, this
latency should be minimal.
Inter Process Communication and Task Synchronization: The implementation of Inter Process
Communication and Synchronization is OS kernel dependent. Certain kernels may provide a bunch of
options whereas others provide very limited options. Certain kernels implement policies for avoiding
priority inversion issues in resource sharing.
Modularization Support: Most of the operating systems provide a bunch of features. At times it may not
be necessary for an embedded product for its functioning. It is very useful if the OS supports
moclularisation where in which the developer can choose the essential modules and re-compile the OS
image for functioning. Windows CE is an example for a highly modular operating system.
Support for Networking and Communication: The OS kernel may provide stack implementation and driver
support for a bunch of communication interfaces and networking. Ensure that the OS under consideration
provides support for all the interfaces required by the embedded product.
Development Language Support: Certain operating systems include the run time libraries required for
running applications written in languages like Java and C#. A Java Virtual Machine (JVM) customized
for the Operating System is essential for running java applications. Similarly the .NET Compact
Framework (.NETCF) is required for running Microsoft .NET applications on top of the Operating
System. The OS may include these components as built-in component, if not; check the availability of the
same from a third party vendor or the OS under consideration.
Non-functional Requirements:
Custom Developed or Off the Shelf: Depending on the OS requirement, it is possible to go for the complete
development of an operating system suiting the embedded system needs or use an off the shelf, readily
available operating system, which is either a commercial product or an Open Source product, which is in
close match with the system requirements. Sometimes it may be possible to build the required features by
customizing an Open source OS. The decision on which to select is purely dependent on the development
cost, licensing fees for the OS, development time and availability of skilled resources.
Cost: The total cost for developing or buying the OS and maintaining it in terms of commercial product
and custom build needs to be evaluated before taking a decision on the selection of OS.
Development and Debugging Tools Availability: The availability of development and debugging tools is
a critical decision making factor in the selection of an OS for embedded design. Certain Operating
Systems may be superior in performance, but the availability of tools for supporting the development may
be limited. Explore the different tools available for the OS under consideration.
Ease of Use: How easy it is to use a commercial RTOS is another important feature that needs to be
considered in the RTOS selection.
After Sales: For a commercial embedded RTOS, after sales in the fom1 of e-mail, on-call services etc.,
for bug fixes, critical patch updates and support for production issues, etc., should be analyzed thoroughly.
The ability of the Operating System to have multiple programs in memory, which are ready for execution,
is referred as multiprogramming. In a uni-processor system, it is not possible to execute multiple processes
simultaneously.
Multitasking refers to the ability of an operating system to hold multiple processes in memory and switch the
processor (CPU) from executing one process to another process.
b. Multitasking involves „Context switching‟ (see the following Figure), „Context saving‟ and „Context retrieval‟.
3+4=7
The act of switching CPU among the processes or changing the current execution context is known as
„Context switching‟.
The act of saving the current context (details like Register details, Memory details, System Resource
Usage details, Execution details, etc.) for the currently running processes at the time of CPU switching is
known as „Context saving‟.
The process of retrieving the saved context details for a process, which is going to be executed due to CPU
switching, is known as „Context retrieval‟
Types of Multitasking: Depending on how the task/ process execution switching act is implemented, multitasking
can is classified into –
Co-operative Multitasking: Co-operative multitasking is the most primitive form of multitasking in
which a task/ process gets a chance to execute only when the currently executing task/ process voluntarily
relinquishes the CPU. In this method, any task/ process can avail the CPU as much time as it wants. Since
this type of implementation involves the mercy of the tasks each other for getting the CPU time for
execution, it is known as co-operative multitasking. If the currently executing task is non-cooperative, the
other tasks may have to wait for a long time to get the CPU.
Preemptive Multitasking: Preemptive multitasking ensures that every task/ process gets a chance to
execute. When and how much time a process gets is dependent on the implementation of the preemptive
scheduling. As the name indicates, in preemptive multitasking, the currently running task/process is
preempted to give a chance to other tasks/process to execute. The preemption of task may be based on
time slots or task/ process priority.
Non-preemptive Multitasking: The process/ task, which is currently given the CPU time, is allowed to
execute until it terminates (enters the „Completed‟ state) or enters the „Blocked/ Wait‟ state, waiting for
an I/O. The co-operative and non-preemptive multitasking differs in their behavior when they are in the
„Blocked/Wait‟ state. In co-operative multitasking, the currently executing process/task need not
relinquish the CPU when it enters the „Blocked/ Wait‟ sate, waiting for an I/O, or a shared resource access
or an event to occur whereas in non-preemptive multitasking the currently executing task relinquishes the
CPU when it waits for an I/O.