Sunday, 25 January 2015

arm core

ARM Core
- The ARM1136JF-S processor is built around the ARM11 core in an ARMv6 implementation that runs the 32-bit ARM, 16-bit Thumb, and 8-bit Jazelle instruction sets.
- The processor contains EmbeddedICE-RT logic and a JTAG debug interface to enable hardware debuggers to communicate with the processor.
- The core is described in more detail in the following sections:

Instruction set categories
The instruction sets are divided into four categories:
  • data processing instructions
  • load and store instructions
  • branch instructions
  • coprocessor instructions.
Note
Only load, store, and swap instructions can access data from memory.
Conditional execution
All ARM instructions are conditionally executed and can optionally update the four condition code flags, Negative, Zero, Carry, and Overflow, according to their result.
Registers
The ARM1136JF-S core contains:
  • 31 general-purpose 32-bit registers
  • seven dedicated 32-bit registers.
Note
At any one time, 16 registers are visible. The remainder are banked registers used to speed up exception processing.
Modes and exceptions
- seven operating modes, five of which are exception modes:
  • User mode
  • Supervisor mode
- Exception
  • fast interrupt
  • normal interrupt
  • memory aborts
  • software interrupts
  • Undefined instruction.
Thumb instruction set
Thumb is an extension to the ARM architecture. It contains a subset of the most commonly-used 32-bit ARM instructions that has been encoded into 16-bit wide opcodes, to reduce memory requirements.
DSP instructions
The ARM DSP instruction set extensions provide the following:
  • 16-bit data operations
  • saturating arithmetic
  • MAC operations.
Multiply instructions are processed using a single-cycle 32x16 implementation. There are 32x32, 32x16, and 16x16 multiply instructions (MAC).
Media extensions
The ARMv6 instruction set provides media instructions to complement the DSP instructions. The media instructions are divided into the following main groups:
  • Additional multiplication instructions for handling 16-bit and 32-bit data, including dual-multiplication instructions that operate on both 16-bit halves of their source registers.
  • This group includes an instruction that improves the performance and size of code for multiword unsigned multiplications.
  • Instructions to perform Single Instruction Multiple Data (SIMD) operations on pairs of 16-bit values held in a single register, or on quadruplets of 8-bit values held in a single register. The main operations supplied are addition and subtraction, selection, pack, and saturation.
  • Instructions to extract bytes and halfwords from registers and zero-extend or sign-extend them. These include a parallel extraction of two bytes followed by extension of each byte to a halfword.
  • Instructions to perform the unsigned Sum-of-Absolute-Differences (SAD) operation. This is used in MPEG motion estimation.
Datapath
The datapath consists of three pipelines:
  • ALU/shift pipe - executes most of the ALU operations, and includes a 32-bit barrel shifter. Three pipeline stages:
- Shift - full barrel shifter. All shifts, including those required by the LSU, are performed
- The saturating left shift, which doubles the value of an operand and saturates it, is implemented in the Shift stage.

Lauterbach debugger

The TRACE32 debuggers allow you to test your embedded hardware and software by using the on-chip debug interface of the microcontroller.
- JTAG a on-chip debug interface

- Debug features
• Read/write access to CPU registers
• Read/write access to all memories
Prerequisite: The system permits debugger access.
• Start/stop of program execution
Debug features specific for each microcontroller:
• Number of on-chip breakpoints
• Read/write access to memory while the program execution is running
• Additional features as benchmark counters, triggers etc.
- Two types of breakpoints
-- Set a software breakpoint - before resuming the CPU, the debugger replaces the instruction at the breakpoint address with a breakpoint code instruction.
- SW breakpoints can only be placed in RAM because they rely on modifying target memory.
- no restriction in the number of software breakpoints. But it must be considered, that by the usage of software breakpoint flash memory will be change, if program is run in flash memory.
When debugging code where instructions are copied (Scatterloading), modified or the processor MMU remaps areas of memory, HW breakpoints should be used. In these scenarios SW breakpoints are unreliable as they may be either lost or overwritten.


On-chip breakpoints - resources to set the breakpoints are provided by the CPU.
- To set breakpoints on code in read-only memory - only the on-chip instruction address breakpoints are available.
With the command MAP.BOnchip it is possible to declare memory address ranges for use with on-chip breakpoints to the debugger.
ex - Break.Set 0xfcf00 /Program ; Software breakpoint 1
- Break.Set 0x100 /Program ; On-chip breakpoint
- SYStem.CPU ; select processor type
Total amount of available on-chip breakpoints.
Instruction breakpoints: Number of on-chip breakpoints that can be used to set program
breakpoints into ROM/FLASH/EPROM. (for cortext a9 - six(6) instruction)
Read/Write breakpoints: Number of on-chip breakpoints that can be used as Read or Write
breakpoints. (4 read/write)
Data breakpoint: Number of on-chip data breakpoints that can be used to stop the program
when a specific data value is written to an address or when a specific data value is read from an
address(No)
- For the ARM architecture the on-chip breakpoints are provided by the “ICEbreaker” unit. on-chip breakpoints are usually  needed for instructions in FLASH/ROM.

The number of on-chip breakpoints for data accesses can be extended by using the ETM Address and Data comparators.

ARM

Exception vectors:

Reset - 0x00
Undefined instruction - 0x04
Software interrupt - 0x08
Prefetch Abort - 0x0c
Data Abort - 0x10
Reserved - 0x14
IRQ - 0x18
FIQ - 0x1c

SPSR

-- to store the current value of the CPSR when an exception is taken so that it can be restored after handling the exception.
- Each exception handling mode can access its own SPSR.
- User mode and System mode do not have an SPSR because they are not exception handling modes.
CPSR holds:
- the APSR flags
- the current processor mode
- interrupt disable flags
- current processor state (ARM, Thumb, ThumbEE, or Jazelle®)
- endianness state (on ARMv4T and later)
- execution state bits for the IT block (on ARMv6T2 and later).

TLB structure

- used for both data accesses and instruction fetches.
-- two parts:
-- an eight-entry fully-associative part used exclusively for holding lockdown TLB entries
-- a set-associative part for all other entries, 2 way x 32 entry.
- which part an instruction is determined by state of the TLB lockdown register
- micro TLB of 32 entries - implemented on each of the instruction and data sides.
The main TLB is the second layer in the TLB structure that catches the misses from the Micro TLBs.
Each TLB entry contains a virtual address, a page size, a physical address, and a set of memory properties.
* Block sizes:
- Supersections - Describe 16MB blocks of memory.
- Sections 1MB
- Large pages - 64KB
- Small pages -4KB
* Supersections, sections and large pages are supported to permit mapping of a large region of memory while using only a single entry in a TLB.
* If no mapping for an address is found within the TLB, then the translation table is automatically read by hardware and a mapping is placed in the TLB.

Making ASCII File to Unicode File in Windows

Problem Statement

How to create a unicode file? Many a time we want to insert unicode i.e. Chinese character in file but if file is ASCII, you can not open it successfully. So insert unicode character into a file, you will be required to have unicode file.

Solution

Insert two character as first two bytes i.e. 0xEE and 0xEF. It mean these two bytes should be at the beginning.

Calculate Size of a folder in Windows

Problem Statement

Many a times, we wish to monitor space left in disk then only allow to get log generated in disk. If it exceeded there should be a alarm raised regarding memory crunch.

Solution

The solution can be used for other purposes as well.

GetFolderSize(Provide the path)
{
     Call FindFirstFile to get handle
     {
         While(True)
         {   
            Check if it is not directory (.(current directory), ..(previous directory))
            Check if it is a directory
            If YES
            {
                   Call GetFolderSize recursively
            }
            else
            {
                   Keep account of file size
            }
            If FindNextFile successful
            {
                   Continue
            }
            Else
            {
                   Close Handle and break
            }
         }
     }
}

CAN understanding


- CAN averts message/data collisions by using the message ID of the node, i.e. the message with the highest priority (= lowest message ID) will gain access to the bus, while all other nodes (with lower priority message IDs) switch to a “listening” mode.
- At a baud rate of 1 MBit/sec this would translate into 12 microseconds of actual bus arbitration
- bit stuffing - In CAN frames, a bit of opposite polarity is inserted after five consecutive bits of the same polarity. This practice is called bit stuffing, and is due to the non-return to zero (NRZ) coding adopted. The stuffed data frames are destuffed by the receiver.
- Since bit stuffing is used, six consecutive bits of the same type (111111 or 000000) are considered an error.
- Bit stuffing implies that sent data frames could be larger than one would expect by simply enumerating the bits shown in the tables above.
- PeliCAN mode the complete CAN 2.0B functionality is supported (29-bit
identifier).

Deleting oldest file in a folder

Problem statement

Many a times we want to have automatic cleaning mechanism for oldest file to create more space for new files. It is very useful when we no longer require old files.

Solution

DeleteOldestFile(provide the path)
{
     Call FindFirstFile
     If Success
     {
            Check if it is not directory else skip
            Compare timing of files
            Swap files to local variable keeping point of oldest file if local variable timing is newer then current file timing
            Call FindFileNext
            If not success, close handle and break
            
     }
}

UML Fundamental

UML Class diagram is used to visually describe the problem domain in terms of types of object (classes) related to each other in different ways.
- There are three primary inter-object relationships: association, aggregation, and composition.
- Using the right relationship line is important for placing implicit restrictions on the visibility and propagation of changes to the related classes, matter which play major role in reducing system complexity.

Association
- some kind of a link or a dependency between two classes or more.
- class A can exist with class b but one uses others services
image

Aggregation (Shared Association)
- there’s a part-of relationship between ClassA (whole) and ClassB (part),
- taking special notice that ClassB can also be aggregated by other classes in the application (therefore aggregation is also known as shared association).
image
- the aggregation link doesn’t state in any way that ClassA owns ClassB nor that there is a parent-child relationship (when parent deleted all its child’s are being deleted as a result) between the two.
- Actually, quite the opposite! The aggregation link usually used to stress the point that ClassA is not the exclusive container of ClassB, as in fact ClassB has another container.  
image
Aggregation v.s. Association
- The association link can replace the aggregation link in every situation,
-  while aggregation cannot replace association in situations were there is only a ‘weak link’ between the classes, i.e. ClassA has method/s that contain parameter of ClassB but ClassA doesn’t hold reference to ClassB instance.
- the aggregation link should not be used at all because it has no added value and it disturb consistency, Quoting  Jim Rumbaugh "Think of it as a modeling placebo".
Composition (Not-Shared Association)
In cases where in addition to the part-of relationship between ClassA and ClassB - there’s a strong life cycle dependency between the two, meaning that when ClassA is deleted then ClassB is also deleted as a result, we should be more specific and use the composition link instead of the aggregation link or the association link.
image
- The composition link shows that a class (container, whole) has exclusive ownership over other class/s (parts),
- container object and its parts constitute a parent-child/s relationship.
- Unlike association and aggregation, in the composition relationship, the composed class cannot appear as a return type or parameter type of the composite class,  thus changes in the composed class cannot be propagated to the rest of the system.
- Consequently, usage of composition limits complexity growth as the system grows.

UML
- Object Management Group (OMG) released the Unified Modeling Language (UML).
- purposes of UML was to provide the development community with a stable and common design language that could be used to develop and build computer applications.
- UML brought forth a unified standard modeling notation

- UML has become a standard modeling language is that it is programming-language independent.
- increase the ease of understanding an application under development.
-  By placing standard UML diagrams in your methodologies work products, you make it easier for UML-proficient people to join your project and quickly become productive.
- The most useful, standard UML diagrams are: use case diagram, class diagram, sequence diagram, statechart diagram, activity diagram, component diagram, and deployment diagram.

Use-case diagram
- A use case illustrates a unit of functionality provided by the system.
- The main purpose of the use-case diagram is to help development teams visualize the functional requirements of a system, including the relationship of "actors" (human beings who will interact with the system) to essential processes, as well as the relationships among different use cases.
- Use-case diagrams generally show groups of use cases — either all use cases for the complete system, or a breakout of a particular group of use cases with related functionality (e.g., all security administration-related use cases).
- To show a use case on a use-case diagram, you draw an oval in the middle of the diagram and put the name of the use case in the center of, or below, the oval.
- To draw an actor (indicating a system user) on a use-case diagram, you draw a stick person to the left or right of your diagram (and just in case you're wondering, some people draw prettier stick people than others).
- Use simple lines to depict relationships between actors and use cases, as shown in Figure 1.
Sample use-case diagram
- used to communicate the high-level functions of the system and the system's scope.
- easily tell the functions that our example system provides.
- This system lets the band manager view a sales statistics report and the Billboard 200 report for the band's CDs. It also lets the record manager view a sales statistics report and the Billboard 200 report for a particular CD. The diagram also tells us that our system delivers Billboard reports from an external system called Billboard Reporting Service.
- In addition, the absence of use cases in this diagram shows what the system doesn't do.
- For example, it does not provide a way for a band manager to listen to songs from the different albums on the Billboard 200 — i.e., we see no reference to a use case called Listen to Songs from Billboard 200.
- This absence is not a trivial matter.
- With clear and simple use-case descriptions provided on such a diagram, a project sponsor can easily see if needed functionality is present or not present in the system.
Back to top
Class diagram
Class diagram
- shows how the different entities (people, things, and data) relate to each other
- shows the static structures of the system.
- A class diagram can be used to display logical classes, which are typically the kinds of things the business people in an organization talk about — rock bands, CDs, radio play; or loans, home mortgages, car loans, and interest rates.
- show implementation classes, which are the things that programmers typically deal with.
- An implementation class diagram will probably show some
- complete class diagram, including the class object shown in Figure 2 of the same classes as the logical classes diagram.
- The implementation class diagram won't be drawn with the same attributes, however, because it will most likely have references to things like Vectors and HashMaps.

- A class is depicted on the class diagram as a rectangle with three horizontal sections, as shown in Figure 2. The upper section shows the class's name; the middle section contains the class's attributes; and the lower section contains the class's operations (or "methods").
Sample class object in a class diagram
- every developer knows what this diagram is, yet draw the relationship lines incorrectly.

A complete class diagram- every developer knows what this diagram is, yet I find that most programmers draw the relationship lines incorrectly.
- in Figure 3, draw the inheritance relationship using a line with an arrowhead at the top pointing to the super class, and the arrowhead should be a completed triangle.
- An association relationship should be a solid line if both classes are aware of each other and a line with an open arrowhead if the association is known by only one of the classes.
- The CDSalesReport class inherits from the Report class.
- A CDSalesReport is associated with one CD, but the CD class doesn't know anything about the CDSalesReport class.
- The CD and the Band classes both know about each other, and both classes can be associated to one or more of each other.
- A class diagram can incorporate many more concepts, which we will cover later in this article series.
Back to top

Sequence diagram
Sequence diagram
- shows detailed flow for a specific use case or even just part of a specific use case.
- show the calls between the different objects in their sequence
- show, at a detailed level, different calls to different objects.
- two dimensions
-- vertical dimension shows the sequence of messages/calls in the time order that they occur
-- horizontal dimension shows the object instances to which the messages are sent.
-Drawing sequence diagram
-- Across the top of your diagram, identify the class instances (objects) by putting each class instance inside a box (see Figure 4).
-- In the box, put the class instance name and class name separated by a space/colon/space " : " (e.g., myReportGenerator : ReportGenerator).
- If a class instance sends a message to another class instance, draw a line with an open arrowhead pointing to the receiving class instance
- place the name of the message/method above the line.
- Optionally, for important messages, you can draw a dotted line with an arrowhead pointing back to the originating class instance; label the return value above the dotted line.
- Reading a sequence diagram
-- Start at the top left corner with the "driver" class instance that starts the sequence.
-- Then follow each message down the diagram.
-- Remember: Even though the example sequence diagram in Figure 4 shows a return message for each sent message, this is optional.
sequence diagram
- CD Sales Report
- a Servlet object is our example driver.
- aServlet sends a message to the ReportGenerator class instance named gen.
- The message is labeled generateCDSalesReport, which means that the ReportGenerator object implements this message handler.
- On closer inspection, the generateCDSalesReport message label has cdId in parentheses, which means that aServlet is passing a variable named cdId with the message.
- When gen instance receives a generateCDSalesReport message, it then makes subsequent calls to the CDSalesReport class, and an actual instance of a CDSalesReport called aCDReport gets returned.
- The gen instance then makes calls to the returned aCDReport instance, passing it parameters on each message call.
- At the end of the sequence, the gen instance returns aCDReport to its caller aServlet.
- Please note: arguably too detailed for a typical sequence diagram.
- shows how nested calls are drawn.
- with junior developers, sometimes it is necessary to break down sequences to this explicit level to help them understand what they are supposed to do.
Statechart diagram
- models the different states that a class can be in and how that class transitions from state to state.
- can be argued that every class has a state, but that every class shouldn't have a statechart diagram.
- Only classes with "interesting" states — that is, classes with three or more potential states during system activity — should be modeled.
- Figure , the notation set of the statechart diagram has five basic elements: the initial starting point, which is drawn using a solid circle; a transition between states, which is drawn using a line with an open arrowhead; a state, which is drawn using a rectangle with rounded corners; a decision point, which is drawn as an open circle; and one or more termination points, which are drawn using a circle with a solid circle inside it.
- To draw a statechart diagram, begin with a starting point and a transition line pointing to the initial state of the class.
- Draw the states themselves anywhere on the diagram, and then simply connect them using the state transition lines.
Figure showing the various states that classes pass through in a functioning system
Statechart diagram
- Figure shows some of the potential information they can communicate.
- For instance, you can tell that loan processing begins in the Loan Application state.
- When the pre-approval process is done, depending on the outcome, you move to either the Loan Pre-approved state or the Loan Rejected state.
- This decision, which is made during the transition process, is shown with a decision point — the empty circle in the transition line.
- By looking at the example, a person can tell that a loan cannot go from the Loan Pre-Approved state to the Loan in Maintenance state without going through the Loan Closing state.
- by looking at our example diagram, a person can tell that all loans will end in either the Loan Rejected state or the Loan in Maintenance state.
Activity diagram
- show the procedural flow of control between two or more class objects while processing an activity.
- can be used to model higher-level business process at the business unit level, or to model low-level internal class actions.
- best used to model higher-level processes, such as how the company is currently doing business, or how it would like to do business.
- are "less technical" in appearance, compared to sequence diagrams, and business-minded people tend to understand them more quickly.
- notation set is similar to that used in a statechart diagram.
- Like a statechart diagram, the activity diagram starts with a solid circle connected to the initial activity.
- The activity is modeled by drawing a rectangle with rounded edges, enclosing the activity's name.
- Activities can be connected to other activities through transition lines, or to decision points that connect to different activities guarded by conditions of the decision point.
- Activities that terminate the modeled process are connected to a termination point (just as in a statechart diagram).
- the activities can be grouped into swimlanes, which are used to indicate the object that actually performs the activity, as shown in Figure 6.
Activity diagram, with two swimlanes
In our example activity diagram
-  we have two swimlanes because we have two objects that control separate activities: a band manager and a reporting tool.
- The process starts with the band manager electing to view the sales report for one of his bands. The reporting tool then retrieves and displays all the bands that person manages and asks him to choose one.
- After the band manager selects a band, the reporting tool retrieves the sales information and displays the sales report.
- shows that displaying the report is the last step in the process.

Component diagram
- provides a physical view of the system.
- Its purpose is to show the dependencies that the software has on the other software components (e.g., software libraries) in the system.
- The diagram can be shown at a very high level, with just the large-grain components, or it can be shown at the component package level. [Note: The phrase component package level is a programming language-neutral way of referring to class container levels such as .NET's namespaces (e.g., System.Web.UI) or Java's packages (e.g., java.util).]
Modeling a component diagram is best described through an example. Figure 7 shows four components: Reporting Tool, Billboard Service, Servlet 2.2 API, and JDBC API. The arrowed lines from the Reporting Tool component to the Billboard Service, Servlet 2.2 API, and JDBC API components mean that the Reporting Tool is dependent on those three components.
Figure 7: A component diagram shows interdependencies of various software components the system comprises
Component diagram
Back to top
Deployment diagram
- shows how a system will be physically deployed in the hardware environment.
- purpose is to show where the different components of the system will physically run and how they will communicate with each other.
- diagram models the physical runtime, a system's production staff will make considerable use of this diagram.
- The notation in a deployment diagram includes the notation elements used in a component diagram, with a couple of additions, including the concept of a node.
- A node represents either a physical machine or a virtual machine node (e.g., a mainframe node).
- To model a node, simply draw a three-dimensional cube with the name of the node at the top of the cube.
- Use the naming convention used in sequence diagrams: [instance name] : [instance type] (e.g., "w3reporting.myco.com : Application Server").
Sample of a deployment diagram
- Figure shows that the users access the Reporting Tool by using a browser running on their local machine and connecting via HTTP over their company's intranet to the Reporting Tool.

- This tool physically runs on the Application Server named w3reporting.myco.com. The diagram shows the Reporting Tool component drawn inside of IBM WebSphere, which in turn is drawn inside of the node w3.reporting.myco.com. The Reporting Tool connects to its reporting database using the Java language to IBM DB2's JDBC interface, which then communicates to the actual DB2 database running on the server named db1.myco.com using native DB2 communication. In addition to talking to the reporting database, the Report Tool component communicates via SOAP over HTTPS to the Billboard Service.