1 /******************************************************************************
2 ** File Name: int_hisr.h *
3 ** Author: Steve.Zhan *
5 ** Copyright: 2010 Spreatrum, Incoporated. All Rights Reserved. *
7 ******************************************************************************/
8 /******************************************************************************
10 **---------------------------------------------------------------------------*
11 ** DATE NAME DESCRIPTION *
12 ** 06/29/2010 Steve.Zhan Create. *
13 ******************************************************************************/
14 #ifndef __INT_HISR_H__
15 #define __INT_HISR_H__
18 #include "isr_drvapi.h"
20 /*----------------------------------------------------------------------------*
22 **------------------------------------------------------------------------- */
24 /**---------------------------------------------------------------------------*
26 **--------------------------------------------------------------------------*/
32 /**---------------------------------------------------------------------------*
34 **---------------------------------------------------------------------------*/
35 /*****************************************************************************/
36 // Description: Circular Buffer Function MACROS..
37 // Is used to hold characters that arrive before the application is ready for them
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
48 #define ISR_WRITE_BUFFER_DEF \
49 LOCAL void IsrWriteBuffer(int value) \
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; \
60 #define THREAD_READ_BUFFER_DEF \
61 LOCAL BOOLEAN threadReadBuffer(int* value) \
63 if (input_read_ptr != input_write_ptr) \
65 *value = *input_read_ptr++; \
66 if (input_read_ptr > &input_buffer[MaxSize-1]) \
67 input_read_ptr = &input_buffer[0]; \
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) \
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; \
87 LOCAL BOOLEAN threadReadBuffer(VALUE_TYPE* value) \
89 if (input_read_ptr != input_write_ptr) \
91 *value = *input_read_ptr++; \
92 if (input_read_ptr > &input_buffer[MaxSize-1]) \
93 input_read_ptr = &input_buffer[0]; \
100 /**----------------------------------------------------------------------------*
101 ** Local Function Prototype **
102 **----------------------------------------------------------------------------*/
106 CHIPDRV_HISR_START_ID = 0x50,
118 typedef struct Hisr_T
120 hisr_func_t *hisr_func;
122 CHIPDRV_HISR_PRI_E pri;
124 struct Hisr_T* volatile next_hisr;
125 volatile uint32 hisr_count;
128 /**----------------------------------------------------------------------------*
129 ** Function Prototype **
130 **----------------------------------------------------------------------------*/
132 /*****************************************************************************/
133 // Description : This function is used to create HISR
134 // Global resource dependence :
135 // Author : steve.zhan
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);
142 /*****************************************************************************/
143 // Description : This function is used in task to get semaphore.
144 // Global resource dependence :
145 // Author : steve.zhan
147 /*****************************************************************************/
148 PUBLIC uint32 CHIPDRVHISR_WaitActive (CHIPDRV_HISR_ID_E ThreadId);
151 /*****************************************************************************/
152 // Description : This function is used to activate the HISR to process some
154 // Global resource dependence :
155 // Author : steve.zhan
157 /*****************************************************************************/
158 PUBLIC void CHIPDRVHISR_Activate (CHIPDRV_HISR_ID_E ThreadId);
162 /*****************************************************************************/
163 // Description : This function Init Hisr data struct.
164 // Global resource dependence :
165 // Author : steve.zhan
167 /*****************************************************************************/
168 PUBLIC void Hisr_init(void);
171 /*****************************************************************************/
172 // Description : Invoked by ISR.
173 // Global resource dependence :
174 // Author : steve.zhan
176 /*****************************************************************************/
177 PUBLIC void Hisr_put(int Intpri);
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
187 /*****************************************************************************/
188 PUBLIC uint32 Hisr_RegHandler (
190 hisr_func_t *pHisrFunc,
191 CHIPDRV_HISR_PRI_E hisrPri,
195 /**----------------------------------------------------------------------------*
197 **----------------------------------------------------------------------------*/
201 /**---------------------------------------------------------------------------*/