tizen 2.4 release
[kernel/u-boot-tm1.git] / arch / arm / include / asm / arch-sc8800g / int_hisr.h
1 /******************************************************************************
2  ** File Name:    int_hisr.h                                             *
3  ** Author:       Steve.Zhan                                                  *
4  ** DATE:         06/29/2010                                                  *
5  ** Copyright:    2010 Spreatrum, Incoporated. All Rights Reserved.           *
6  ** Description:                                                              *
7  ******************************************************************************/
8 /******************************************************************************
9  **                   Edit    History                                         *
10  **---------------------------------------------------------------------------*
11  ** DATE                   NAME               DESCRIPTION                     *
12  ** 06/29/2010         Steve.Zhan       Create.                               *
13  ******************************************************************************/
14 #ifndef __INT_HISR_H__
15 #define __INT_HISR_H__
16
17 #include "os_api.h"
18 #include "isr_drvapi.h"
19
20 /*----------------------------------------------------------------------------*
21  **                         Dependencies                                      *
22  **------------------------------------------------------------------------- */
23
24 /**---------------------------------------------------------------------------*
25  **                             Compiler Flag                                 *
26  **--------------------------------------------------------------------------*/
27 #ifdef   __cplusplus
28 extern   "C"
29 {
30 #endif
31
32 /**---------------------------------------------------------------------------*
33 **                               Micro Define                                **
34 **---------------------------------------------------------------------------*/
35 /*****************************************************************************/
36 //  Description:    Circular Buffer Function MACROS..
37 //  Is used to hold characters that arrive before the application is ready for them
38 //  Author:         steve.zhan
39 //  Note:  Use these three MACROS together..
40 /*****************************************************************************/
41 #define INPUT_BUFFER_INIT(_MAX_SIZE)\
42     static int input_buffer[_MAX_SIZE]; \
43     static int*  input_write_ptr  = &input_buffer[0];\
44     static int*  input_read_ptr = &input_buffer[0];\
45     static int MaxSize = _MAX_SIZE
46
47 #define ISR_WRITE_BUFFER_DEF \
48     LOCAL void IsrWriteBuffer(int value) \
49     { \
50         int *save_ptr = input_write_ptr; \
51         *input_write_ptr++ = value; \
52         if (input_write_ptr > &input_buffer[MaxSize-1]) \
53             input_write_ptr = &input_buffer[0]; \
54         if (input_write_ptr == input_read_ptr) \
55             input_write_ptr = save_ptr; \
56     }
57
58
59 #define THREAD_READ_BUFFER_DEF \
60     LOCAL BOOLEAN threadReadBuffer(int* value) \
61     { \
62         if (input_read_ptr != input_write_ptr) \
63         { \
64             *value = *input_read_ptr++; \
65             if (input_read_ptr > &input_buffer[MaxSize-1]) \
66                 input_read_ptr = &input_buffer[0]; \
67             return FALSE; \
68         } \
69         return TRUE; \
70     }
71
72 /**----------------------------------------------------------------------------*
73 **                         Local Function Prototype                           **
74 **----------------------------------------------------------------------------*/
75
76 typedef enum
77 {
78     CHIPDRV_HISR_START_ID = 0x50,
79     CHIPDRV_HISR_0,
80     CHIPDRV_HISR_1,
81     CHIPDRV_HISR_2,
82     CHIPDRV_HISR_3,
83
84     
85     CHIPDRV_HISR_LAST_ID
86
87 } CHIPDRV_HISR_ID_E;
88
89
90 typedef struct Hisr_T
91 {
92     hisr_func_t            *hisr_func;
93     void                   *data;
94     CHIPDRV_HISR_PRI_E     pri;
95     
96     struct Hisr_T* volatile  next_hisr;
97     volatile uint32          hisr_count;
98 } Hisr_T;
99
100 /**----------------------------------------------------------------------------*
101 **                           Function Prototype                               **
102 **----------------------------------------------------------------------------*/
103
104 /*****************************************************************************/
105 // Description :    This function is used to create HISR
106 // Global resource dependence :
107 // Author : steve.zhan
108 // Note :
109 /*****************************************************************************/
110 PUBLIC void CHIPDRVHISR_Create (const uint8 *HisrName, CHIPDRV_HISR_ID_E ThreadId, void (*entry) (uint32, void *),
111                                 CHIPDRV_HISR_PRI_E Priority, int queueNum);
112
113
114 /*****************************************************************************/
115 // Description :    This function is used in task to get semaphore.
116 // Global resource dependence :
117 // Author : steve.zhan
118 // Note :
119 /*****************************************************************************/
120 PUBLIC  uint32  CHIPDRVHISR_WaitActive (CHIPDRV_HISR_ID_E ThreadId);
121
122
123 /*****************************************************************************/
124 // Description :    This function is used to activate the HISR to process some 
125 //                  Delay isr things.
126 // Global resource dependence :
127 // Author : steve.zhan
128 // Note :
129 /*****************************************************************************/
130 PUBLIC void CHIPDRVHISR_Activate (CHIPDRV_HISR_ID_E ThreadId);
131
132
133
134 /*****************************************************************************/
135 // Description :    This function Init Hisr data struct.                  
136 // Global resource dependence :
137 // Author : steve.zhan
138 // Note :
139 /*****************************************************************************/
140 PUBLIC void Hisr_init(void);
141
142
143 /*****************************************************************************/
144 // Description :    Invoked by ISR.
145 // Global resource dependence :
146 // Author : steve.zhan
147 // Note :
148 /*****************************************************************************/
149 PUBLIC void Hisr_put(int Intpri);
150
151
152
153 /*****************************************************************************/
154 // Description :    Invokedy by interrupt module, register Hisr callback 
155 //                  function and the priority to HISR.
156 // Global resource dependence :
157 // Author : steve.zhan
158 // Note :
159 /*****************************************************************************/
160 PUBLIC uint32 Hisr_RegHandler (
161                                      uint32 priIndex,
162                                      hisr_func_t *pHisrFunc,
163                                      CHIPDRV_HISR_PRI_E hisrPri,
164                                      void *            pHisrData
165 );
166
167 /**----------------------------------------------------------------------------*
168 **                         Compiler Flag                                      **
169 **----------------------------------------------------------------------------*/
170 #ifdef   __cplusplus
171 }
172 #endif
173 /**---------------------------------------------------------------------------*/
174 #endif
175 // End
176