tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / include / asm / arch-tiger / 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 #ifndef CONFIG_EMMC_BOOT
42 #define INPUT_BUFFER_INIT(_MAX_SIZE)\
43     static int input_buffer[_MAX_SIZE]; \
44     static int*  input_write_ptr  = &input_buffer[0];\
45     static int*  input_read_ptr = &input_buffer[0];\
46     static int MaxSize = _MAX_SIZE
47
48 #define ISR_WRITE_BUFFER_DEF \
49     LOCAL void IsrWriteBuffer(int value) \
50     { \
51         int *save_ptr = input_write_ptr; \
52         *input_write_ptr++ = value; \
53         if (input_write_ptr > &input_buffer[MaxSize-1]) \
54             input_write_ptr = &input_buffer[0]; \
55         if (input_write_ptr == input_read_ptr) \
56             input_write_ptr = save_ptr; \
57     }
58
59
60 #define THREAD_READ_BUFFER_DEF \
61     LOCAL BOOLEAN threadReadBuffer(int* value) \
62     { \
63         if (input_read_ptr != input_write_ptr) \
64         { \
65             *value = *input_read_ptr++; \
66             if (input_read_ptr > &input_buffer[MaxSize-1]) \
67                 input_read_ptr = &input_buffer[0]; \
68             return FALSE; \
69         } \
70         return TRUE; \
71     }
72 #else
73 #define INPUT_BUFFER_INIT(VALUE_TYPE, _MAX_SIZE)\
74     static VALUE_TYPE input_buffer[_MAX_SIZE]; \
75     static VALUE_TYPE*  input_write_ptr  = &input_buffer[0];\
76     static VALUE_TYPE*  input_read_ptr = &input_buffer[0];\
77     static int MaxSize = _MAX_SIZE; \
78     LOCAL void IsrWriteBuffer(VALUE_TYPE value) \
79     { \
80         VALUE_TYPE *save_ptr = input_write_ptr; \
81         *input_write_ptr++ = value; \
82         if (input_write_ptr > &input_buffer[MaxSize-1]) \
83             input_write_ptr = &input_buffer[0]; \
84         if (input_write_ptr == input_read_ptr) \
85             input_write_ptr = save_ptr; \
86     } \
87     LOCAL BOOLEAN threadReadBuffer(VALUE_TYPE* value) \
88     { \
89         if (input_read_ptr != input_write_ptr) \
90         { \
91             *value = *input_read_ptr++; \
92             if (input_read_ptr > &input_buffer[MaxSize-1]) \
93                 input_read_ptr = &input_buffer[0]; \
94             return FALSE; \
95         } \
96         return TRUE; \
97     }
98 #endif
99
100 /**----------------------------------------------------------------------------*
101 **                         Local Function Prototype                           **
102 **----------------------------------------------------------------------------*/
103
104 typedef enum
105 {
106     CHIPDRV_HISR_START_ID = 0x50,
107     CHIPDRV_HISR_0,
108     CHIPDRV_HISR_1,
109     CHIPDRV_HISR_2,
110     CHIPDRV_HISR_3,
111
112     
113     CHIPDRV_HISR_LAST_ID
114
115 } CHIPDRV_HISR_ID_E;
116
117
118 typedef struct Hisr_T
119 {
120     hisr_func_t            *hisr_func;
121     void                   *data;
122     CHIPDRV_HISR_PRI_E     pri;
123     
124     struct Hisr_T* volatile  next_hisr;
125     volatile uint32          hisr_count;
126 } Hisr_T;
127
128 /**----------------------------------------------------------------------------*
129 **                           Function Prototype                               **
130 **----------------------------------------------------------------------------*/
131
132 /*****************************************************************************/
133 // Description :    This function is used to create HISR
134 // Global resource dependence :
135 // Author : steve.zhan
136 // Note :
137 /*****************************************************************************/
138 PUBLIC void CHIPDRVHISR_Create (const uint8 *HisrName, CHIPDRV_HISR_ID_E ThreadId, void (*entry) (uint32, void *),
139                                 CHIPDRV_HISR_PRI_E Priority, int queueNum);
140
141
142 /*****************************************************************************/
143 // Description :    This function is used in task to get semaphore.
144 // Global resource dependence :
145 // Author : steve.zhan
146 // Note :
147 /*****************************************************************************/
148 PUBLIC  uint32  CHIPDRVHISR_WaitActive (CHIPDRV_HISR_ID_E ThreadId);
149
150
151 /*****************************************************************************/
152 // Description :    This function is used to activate the HISR to process some 
153 //                  Delay isr things.
154 // Global resource dependence :
155 // Author : steve.zhan
156 // Note :
157 /*****************************************************************************/
158 PUBLIC void CHIPDRVHISR_Activate (CHIPDRV_HISR_ID_E ThreadId);
159
160
161
162 /*****************************************************************************/
163 // Description :    This function Init Hisr data struct.                  
164 // Global resource dependence :
165 // Author : steve.zhan
166 // Note :
167 /*****************************************************************************/
168 PUBLIC void Hisr_init(void);
169
170
171 /*****************************************************************************/
172 // Description :    Invoked by ISR.
173 // Global resource dependence :
174 // Author : steve.zhan
175 // Note :
176 /*****************************************************************************/
177 PUBLIC void Hisr_put(int Intpri);
178
179
180
181 /*****************************************************************************/
182 // Description :    Invokedy by interrupt module, register Hisr callback 
183 //                  function and the priority to HISR.
184 // Global resource dependence :
185 // Author : steve.zhan
186 // Note :
187 /*****************************************************************************/
188 PUBLIC uint32 Hisr_RegHandler (
189                                      uint32 priIndex,
190                                      hisr_func_t *pHisrFunc,
191                                      CHIPDRV_HISR_PRI_E hisrPri,
192                                      void *            pHisrData
193 );
194
195 /**----------------------------------------------------------------------------*
196 **                         Compiler Flag                                      **
197 **----------------------------------------------------------------------------*/
198 #ifdef   __cplusplus
199 }
200 #endif
201 /**---------------------------------------------------------------------------*/
202 #endif
203 // End
204