Tuesday, 29 November 2016

A RTOS
G Anand

RTOS is simple and powerful for standalone embedded systems. Simple kernel handles task switching and task stack for multi-tasking. It can be handled easily by the programmer for self-programing. Boot loaded RTOS kernel can reduce the compiler compiling time.
ARTOS is introduced to simplify the operations when compared to other RTOSs. Interrupt latency is the main problem which is faced by other RTOSs. In this ARTOS a new method is used to avoid interrupt latency. Normally all interrupts access same location in the stack. So interrupt-2 couldn’t access that location until the execution of the interrupt-1. In order to avoid this delay the function to be handled by interrupt-1 will be assigned to another stack variable as a handling function. So program control leaves interrupt 1 and starts to concentrate on the handling function. Inside the handling function user can define their program. Now at the same time, interrupt-2 get serviced and also interrupt 1 will be implemented. In conventional RTOS, only after creation of all tasks, implementation will be performed. ARTOS is designed in-order to perform simultaneous operations. In ARTOS tasks can be created at any point of time. Task creation and implementation can be performed simultaneously. In the process of interrupt handling, to enable and disable Interrupt we need to write coding. But in ARTOS interrupt enable and disable are created as a function. Now it will be easy to access interrupt enable and disable. Thus ARTOS will be user-friendly. ARTOS library functions are explained below.


FEATURES
Ø Task Priority
All the task ruined at least one time in every kernel routine (Total Task switching)
·        LOW:  This priority tasks will be called once after HIGH priority task. It works on the basis of auto task switching. Every time the task can be switched between TMR0 interrupt act. If for loop based delay is used in the task, then it will be difficult to predict the time because of auto switching process. In-order to avoid the task switching in the task in which for loop is used, ARTOS_LOCK () function can be used.
·        HIGH: This priority tasks will be called once before LOW priority task. It works on the basis of auto task switching. Every time the task can be switched between TMR0 interrupt act. If for loop based delay is used in the task, then it will be difficult to predict the time because of auto switching process. In-order to avoid the task switching in the task in which for loop is used, ARTOS_LOCK () function can be used.
·        REALTIME: This priority tasks will be called multiple times after each HIGH and LOW priority tasks. It’s used to debugger task for fetch task status from each calling task. It is a Controlled task. It works on the basis of manual task switching. If once the task resource is allocated to real time priority tasks, then the process will not move to another task. If there is a need to switch the task, then use ARTOS_Idle () function (switching to the next task).
Ø Semaphore
·        All processor’s internal resources are accessed by semaphore.
·        Example: Consider the processor has single serial port. If the same resource is accessed by 2 tasks simultaneously, then data interference will be occurred in serial port.
·        To avoid this CONNECT and DISCONNECT instructions can be used. If one task is already connected to the serial port, other tasks should wait to establish connection to that resource.
Ø IPC (Inter Process Communication)
·        Pointer based IPC. Only the Variable address will be transferred from one process to another process. Thus any data type  and large data can be accessed from another task
·        Perfect address handling is done with the help of global and heap variables.
·        Semaphore based data communication.
Ø Interrupt Handling
·        Easy to access interrupt functions
·        All interrupts are enabled and disabled by inbuilt functions and interrupt event handles header functions.
·        Software nested interrupt sequence
·        Interrupt Priority
§  LOW: Handle has individual stack. It processes newly arrived LOW and HIGH priority interrupts. If HIGH or LOW interrupt comes into play while one low priority interrupt is in process, then current interrupt context has been saved and jump to next interrupt. All the interrupts are processes in the manner last in first out.
§  HIGH: Handle has individual stack. It processes newly arrived HIGH priority interrupt. If one interrupt is processing at the same time another HIGH interrupts comes into play, then the Current interrupt context has been saved and jump to next interrupt. All the interrupts are processed in the manner last in first out.
§  REALTIME: Handle has no individual stack. All the interrupts are processed in the manner last in first out.
·        If user enabled the TMR interrupt, it generates interrupt event handling function and call this function every interrupt occur.
·        TMR0 interrupt is reserved for kernel routine. This interrupt event can be used for fixed kernel time. If the time of this interrupt kernel is changed, only the time will be changed and the other system operations will not be affected.
Ø UART function
·        Interrupt based TX an RX
·        Buffered receiver which doesn’t listen every time while receiving
·        Semaphore based UART functions like sending and receiving operations using byte and string.
Ø System Timer
·        Inbuilt HR: MIN: SEC: MSEC: USEC task for perfect timer operation.
·        Get system time sample for timeout operation.
·        Use Kernel Timer (TMR0) , so don’t need special timer
·        LOW priority task only.
Ø Auto prediction of the function stack top
Ø Main routine is like individual task. This task is handled by ARTOS_INIT function
Ø Inbuilt library
·        GSM
·        Audio reader
·        LCD
·        ALARM
·        Multi data type EEPROM ( int, char, string..)
·        Seven Segment
·        DS1307 (Timer chip)
·        Bounce Button
·        Soft button
·        Universal IR decoder
FUNCTIONS

Ø int8 ARTOS_Init(uint16 Main_ThreadID,int8 *Main_Stack,uint16 Main_Stack_Depth,uint8 Main_Task_Priority);
This function should be called before calling other functions (i.e at initial stage).  In our ARTOS, creation and implementation of tasks are performed simultaneously. For this simultaneous operation init function should be declared at first. Consider the main function consists of 2 tasks.
Main()
{
int8 ARTOS_Init(uint16 Main_ThreadID,int8 *Main_Stack,uint16 Main_Stack_Depth,uint8 Main_Task_Priority);
Task 1
- - - - - - - - - - - -
- - - - - - - - - - - -
Task 2
}
Used to back up the main task context
First task 1 will be created and implemented initially. Task 1 will be interrupted after particular time delay and the program control switch into task 2 creation and implementation. This will be interrupted after particular time delay and the program control has switched to task 1. Thus the simultaneous operation can be achieved.
Default delay time is 500 micro seconds. We can change this delay time according to our need. In other versions of RTOS first we should create task in the main function.  Only after creation of all tasks OS starts to implement them. If the OS starts to implement the tasks, then it will never return to the main function.
To declare init function we need to assign thread ID(uint16 Main_ThreadID), stack name(int8 *Main_Stack), stack size(uint16 Main_Stack_Depth) and priority(uint8 Main_Task_Priority).
Thread ID
It should be 16 bit number. Avoid assigning FF as main thread ID because some inbuilt function has used FF as their thread ID.
Stack name and size:
These arguments are used to define stack to store temporal variables of the main function. This stack does not include particular task variable. If we implement the tasks only after creation then there is no need to keep track of main function. We are performing creation and implementation of tasks simultaneously. So we need to keep track of main function. For this purpose, a stack should be defined to store temporal variables of the main function. This stack does not include particular task variable.
Priority:
There are 3 priorities in our system design. They are low priority, high priority and real_time priority. In these, real_time priority has most significance than other priorities. Second most significant priority is High priority. Least significant priority is Low priority.
If 2 tasks (task 1- high priority, task 2- Low priority) are waiting for the input from the same source, then the task will get the input from the source according to their priority. Normally after particular delay, program control will be switched into another task. If we assign the priority as realtime_priority then the program control will not be switched into another task after particular delay. Only after completing the task program control will be switched into another task.
Ø void ARTOS_ASM_delay(uint8 Nnop);
This function is used to provide assembly delay. It indicates number of no-operation to be performed.

Ø int8 ARTOS_ChangePriority(uint8 Thread_Priority);
This function is used to change the priority of the task (thread) at any step.
Ø int8 ARTOS_Create( uint16 Thread_ID,__Thread Thread_ADDR ,int8 *Stack,uint16 Stack_Depth,int8 *IPC, int8 Thread_Priority );

Create function is used to generate new task. To generate new task thread id, thread address, stack name, stack size, pointer value and thread priority should be given as input arguments.
Uint16 Thread_ID: Should be 16 bit number
Thread_ADDR: Address allocated for the task


Ø int8 *Stack(name), uint16 Stack_Depth(size):

Stack is used to store the variables associated with the task. We need to assign name and size of the stack.

Ø int8 *IPC(pointer value):

Pointer value is used to address the location of the variables used. The change made in the variable will be updated in the address location(denoted by the pointer) directly.

Ø int8 ARTOS_Start(  uint16 Thread_ID );
This function is used to start the implementation of the task which is created and stored in the buffer. After creating each task we need to declare start operation to implement that task. We can start any task from any step using the ID of the task.
Ø int8 ARTOS_Stop(  uint16 Thread_ID );
This function is used to stop the implementation of the task. Normally after particular delay, program control will be switched into another task. Once the program control get the stop command of particular task, then the program control should not get into task until the task is started by using start function We can stop any task from any step using the ID of the task.

Ø int8 ARTOS_Delete(  uint16 Thread_ID );
This function is used to delete the particular task using task ID(thread ID). This function clear the memory associated with the task.

Ø void ARTOS_Return();
This function is used to return the output of a function.
Return value = 0 indicates the output of a function has returned successfully
Return value = negative number indicates the return of output is unsuccessful

Ø void ARTOS_Idle();
This function is used to idle the function for one cycle.
Main()
{
int8 ARTOS_Init(uint16 Main_ThreadID,int8 *Main_Stack,uint16 Main_Stack_Depth,uint8 Main_Task_Priority);
Task 1
- - - - - - - - - - - -
- - - - - - - - - - - -
Task 2
- - - - - - - - - - - -
Idle function
- - - - - - - - - - - -
Task 3
- - - - - - - - - - - -
- - - - - - - - - - - -
Task 4
- - - - - - - - - - - -
- - - - - - - - - - - -
}
First task 1 will implemented. It will get interrupted after particular delay time. And the program control will be switched into task 2. In task 2 we have idle function. So task 2 will not be performed. Program control will be switched into task 3. task 3 will be performed and it will get interrupted after particular delay time. Then the program control will be switched into task 4. It will get interrupted after particular delay time. Then the program control will be switched into task 1. Then the
Ø void ARTOS_Delay(uint16 delay_ms);
This function is used provide delay. We should pass delay time as argument of this function.

Ø void ARTOS_Lock();
Normally after particular delay, program control will be switched into another task. Lock function is used to avoid this switching. So the program control moved to next task only after completing the task which has lock function. This will be helpful to avoid switching in-case of low and high priority tasks.

Ø void ARTOS_UnLock();
This function is used to unlock the task which was locked.

Thursday, 7 April 2016

SILENT DRIVING SYSTEM

G. Anand,
Email id-
anandg.embedd@gmail.com,
Mobile No- +91 9994879483


ABSTRACT
The rapid growth of technology has made our life easier. In this project profile management based driving system is introduced. Android is a mobile operating system (OS) based on the Linux kernel that is currently developed by Google. Change Profile and sensing SMS to the call maker is an android stage based application which runs in the android versatile or in the android emulator at the improvement time. In driving mode, the profile will be changed into silent and also the message will be sent to the call-maker. GPS data is utilized to find whether it is normal mode or driving mode. The reason for this application is to change the cell telephone profile is to ensure safe and smooth driving system. Proposed method is implemented in ANDROID platform. Simulation results show that the proposed method performs better than conventional methods.
INTRODUCTION:
Common activities that divert attention from the road include texting, most mobile phone use, eating/drinking, reaching for an object, talking with a passenger or reading navigation systems. Hence the ratio of road accidents which take place frequently increases causing immense loss of life due to poor emergency facilities. Advancement in technology will ensure the safety and smooth driving system. Profile management system

plans to achieve the following objectives: Easy to use, Automated profile switching, Accuracy, Increase usability, User-friendly. Profile Management System in Android Mobiles is a next level of smart driving system which reduces human intervention for simple task such as sound profile switching. Android Smart Phone becomes much smarter by this application. Profile will probably annoy and irritate fellow employees where they may be concentrating on work at their hand. For example professors in college, employees at office area, employers at meetings, drivers all have to remember either switching off their device or changing the profile from general to silent mode. Automated Profile Changing and Mobile Monitoring System is the system which changes the profile automatically
Android Operating System is the driving force behind context aware services of the mobile devices. Android occupies almost 70 percent of the global market. Using Android application which will be built on the top of Android operating system, profile of the device will be changed and due to context aware services of Android OS monitoring of the device is also possible. Android is a software stack for mobile devices that includes an operating system, middleware and key applications. Google Inc. purchased the initial developer of the software, Android Inc., in 2005.  


Fig.1 Proposed architecture


Google and other members of the Open Handset Alliance collaborated on Android's development and release. The Android operating system is the world's best-selling Smartphone platform. The Android SDK provides the tools and APIs necessary to begin developing applications Android platform using the Java programming language.
Features of android:
·         Application framework enabling reuse and replacement of components
·         Dalvik virtual machine optimized for mobile devices
·         Integrated browser based on the open source WebKit engine
Present driving system does not integrate technology with the system. In this paper android based profile management system for driving is proposed. Our proposed method will be effective in-terms of automation, time consumption, accuracy and efficiency.
PROPOSED SYSTEM
Figure 1 describes the proposed architecture. In this project GPS is utilized to track the speed of a person. From speed it can be evaluated that the vehicle is in driving mode or not. If it is driving mode the phone profile will be changed to silent mode. If anybody calls him/her, then the call will be disconnected and the message will be sent to the person who tries to contact a person who is in driving. The message will be in the following format: “The person you want to contact is in driving. So please make a call after sometime. If it is urgent please make a call 3 times.” If the person called more than 3 times the phone profile mode will be changed from silent to normal mode. Otherwise no change will be made. Over all flow diagram is shown in the figure 3.
GLOBAL POSITIONING SYSTEM (GPS)
The Global Positioning System (GPS) is a space based navigation system that provides location and time information in all weather conditions, anywhere on or near the Earth where there is an unobstructed line of sight to four or more GPS satellites. The system provides critical capabilities to military, civil, and a commercial user around the world The United States government created the system, maintains it, and makes it freely accessible to anyone with a GPS receiver.
SPEED CALCULATION
Speed calculation procedure is shown in the figure 2. Speed is calculated using the data available from the GPS.



Fig.2 Speed calculation
Position difference is used to calculate the speed of the vehicle. At last position difference is converted into speed.
THRESHOLD
In this project call count threshold is 3. If the person called to the person who is in driving more than 3 times then the phone profile will be changed from silent to normal.
CALL COUNTS
Call counts represents the no of times the third person try to connect with the person who is in driving.
GLOBAL SYSTEM FOR MOBILE COMMUNICATION (GSM)
GSM (Global System for Mobile communication) is a digital mobile telephony system. GSM uses a variation of time division multiple access (TDMA) and is the most widely used of the three digital wireless telephony technologies (TDMA, GSM, and CDMA). In this project GSM is used to send the message to the call maker.
MANUAL IMPLEMENTATION:
 In android based accident prevention system, there are 2 operating modes. User can choose one mode according to his/her need. Two operating modes are
1. Auto-driving mode
2. Manual driving mode
Auto-driving mode: If the user chooses auto-driving mode, the profile will be changed to silent mode according to the speed. 
Fig.3 Overall flow diagram



Here the speed is calculated using GPS data. This mode will not be effective at the place where GPS is not available. Phone profile will not be changed when there is no availability of GPS even if the person is in driving. To overcome this problem manual driving mode is introduced here. Figure 5 represents auto driving mode
Manual driving mode: If the manual driving mode is chosen by the user, phone profile will be changed to silent without the consideration of speed. This will be effective at the time at-which GPS data is not available. User can use this mode when he/she is in meeting. Figure 6 represents manual driving mode.
Settings: Message to be sent to the call maker can be edited by the user using the menu settings. Figure 7 represents the settings.


Fig.4 No driving mode


Fig.5 Auto driving mode


Fig.6 Manual driving mode


 Fig.7 Settings


Fig.8 Location of the vehicle

CONCLUSION:

The main contribution of this paper is to provide road safety with advanced driver-assistance systems. This application will lives-up to expectations just on Android OS mobiles. With the overwhelming improvement through Android, portable Applications have been broadly utilized on the different versatile Gadgets. Proposed application performs better to provide efficient driving system. Experimental results show that the performance of the proposed application.

REFERENCES

[1]http://developer.android.com/guide/basics/what-isandroid. html

[2] 3G Mobile Terminal Development Trend of the operating system [M/OL] http://pda.c114.net/32/c4948.html, 2007


[4] Static detection of malicious code in executable programs by J. Bergeron, M. Debbabi, J. Desharnais, M. M. Erhioui, Y. Lavoie, and N. Tawbi.

[5] Android Official Website (2008)—“Android | Official Website”, http://www.android.com/

[6] An Android Application Sandbox System for Suspicious Software Detection, by Thomas Bl¨asing, Leonid Batyuk, Aubrey-Derrick Schmidt,SeyitAhmetCamtepe, and SahinAlbayrak

[8]P.Mohan,V.N.Padmanabhan,andR.Ramjee,―Nericell:Richmonitoring of road and traffic conditions using mobile smartphones, in Proc. ACM SenSys, Raleigh, NC, Nov. 2008.

[9] J. Dai, J. Teng, X. Bai, Z. Shen, and D. Xuan, ―Mobile phone based drunk driving detection, in Proc. 4th Int. Conf. PervasiveHealth—NO PERMISSIONS, Mar. 2010, pp. 1–8.

[10] L. Langle and R. Dantu, ―Are you a safe driver? in Proc. Int. CSE Conf., Aug. 2009, vol. 2, pp. 502–507.

[11] S. Amin, S. Andrews, S. Apte, J. Arnold, J. Ban, M. Benko, R. M. Bayen, B. Chiou, C. Claudel, C. Claudel, T. Dodson, O. Elhamshary, C. Flens-Batina, M. Gruteser, J.-C. Herrera, R. Herring, B. Hoh, Q. Jacobson, T. Iwuchukwu, J. Lew, X. Litrico, L. Luddington, J. Margulici, A. Mortazavi, X. Pan, T. Rabbani, T. Racine, E. SherlockThomas, D. Sutter, and A. Tinka, ―Mobile century—Using GPS mobile phones as traffic sensors: A field experiment, in Proc. 15th World Congr. Intell. Transp. Syst., New York, Nov. 2008.

[12] C.-Y. Chan, ―On the detection of vehicular crashes-system characteristics and architecture, IEEE Trans. Veh. Technol., vol. 51, no. 1, pp. 180–193, Jan. 2002.

[13] M.-H. Pham, A. Bhaskar, E. Chung, and A.-G. Dumont, ―Random forest models for identifying motorway rear-end crash risks using disaggregate data, in Proc. 13th IEEE Int. Conf. ITSC, Sep. 2010, pp. 468–47

Download Full Code ( Use with Android Studio 1.1.0 )