CircleOS  1
Util_spe.c
Go to the documentation of this file.
1 /****************** COPYRIGHT (C) 2007-2013 KEOLABS S.A.S. ********************/
14 /******************************************************************************/
15 
16 /* Includes ------------------------------------------------------------------*/
17 #include "circle.h"
18 
20 
21 /* Private defines -----------------------------------------------------------*/
22 #define TIMER_MULT_RATIO 110
23 #define TIMER_DIV_RATIO 200
24 
25 /* Private typedef -----------------------------------------------------------*/
26 
27 /* Private variables ---------------------------------------------------------*/
28 u32 CurrentTimerDelay = 0;
29 void ( *CurrentEventTimer )( void ) = 0;
30 
31 /* Private function prototypes -----------------------------------------------*/
32 
33 /* Private functions ---------------------------------------------------------*/
34 void fct_dummy() {;}
35 
36 /* External variables ---------------------------------------------------------*/
37 
38 /* Public functions ----------------------------------------------------------*/
39 
40 /*******************************************************************************
41 *
42 * delayms
43 *
44 *******************************************************************************/
53 /******************************************************************************/
54 void Delayms( u32 nTime )
55 {
56  TimingDelay = nTime;
57 
58  while ( TimingDelay != 0 );
59 }
60 
61 void delay( s32 count )
62 {
63  volatile s32 i, j;
64  for ( i = 0; i < count; i++ )
65  for ( j = 0; j < 1300; j++ )
66  fct_dummy();
67 }
68 
69 /*******************************************************************************
70 *
71 * starting_delay
72 *
73 *******************************************************************************/
79 /*******************************************************************************/
80 void starting_delay( void )
81 {
82  delay( 100 );
83 }
84 
85 /******************************************************************************
86 *
87 * Sleep_Call
88 *
89 ******************************************************************************/
90 /* To respect Misra rule 3 : */
91 /*"Assembly language functions that are called from C should be written as C functions containing only in-line assembly language. */
92 /*In-line assembly language should not be embedded in normal C code." */
93 void Sleep_Call( void )
94 {
95  asm( "wfi" );
96 }
97 
98 /*******************************************************************************
99 *
100 * UTIL_LoadApp
101 *
102 *******************************************************************************/
110 /********************************************************************************/
111 void UTIL_LoadApp( index_t app )
112 {
113 }
114 
115 
116 /*******************************************************************************
117 *
118 * my_strlen
119 *
120 *******************************************************************************/
129 /******************************************************************************/
130 len_t my_strlen( const u8* p )
131 {
132  len_t len = 0;
133 
134  for ( ; *p; p++ )
135  {
136  len++;
137  }
138 
139  return len;
140 }
141 
142 
144 
145 /*******************************************************************************
146 *
147 * UTIL_GetUsb
148 *
149 *******************************************************************************/
157 /******************************************************************************/
158 u8 UTIL_GetUsb( void )
159 {
160  return ( GPIO_ReadInputDataBit( USB_DISCONNECT_PORT, USB_DISCONNECT_PIN ) == Bit_SET );
161 }
162 
163 
164 /*******************************************************************************
165 *
166 * UTIL_SetIrqHandler
167 *
168 *******************************************************************************/
177 /********************************************************************************/
178 void UTIL_SetIrqHandler( s32 Offs, tHandler pHDL )
179 {
180  if ( ( Offs >= 8 ) && ( Offs < 0x180 ) ) // YRT20110627 - Changed for F200
181  *( tHandler* )( CIRCLEOS_RAM_BASE + Offs ) = pHDL;
182 }
183 
184 /*******************************************************************************
185 *
186 * UTIL_GetIrqHandler
187 *
188 *******************************************************************************/
199 /********************************************************************************/
200 tHandler UTIL_GetIrqHandler( s32 Offs )
201 {
202  if ( ( Offs >= 8 ) && ( Offs < 0x180 ) ) // YRT20110627 - Changed for F200
203  return *( tHandler* )( CIRCLEOS_RAM_BASE + Offs );
204  else
205  return 0;
206 }
207 
208 /*******************************************************************************
209 *
210 * UTIL_GetAppAddress
211 *
212 *******************************************************************************/
221 /********************************************************************************/
222 uint_t UTIL_GetAppAddress( const u8* AppName )
223 {
224  s32 i;
225 
226  for ( i = 0; i < MAXAPP; i++ )
227  {
228  tMenuItem* curapp;
229  long unsigned addr;
230 
231  if ( ( *ApplicationTable )[ -i ] == APP_VOID )
232  {
233  break;
234  }
235  else
236  {
237  addr = ( long unsigned )( *ApplicationTable )[ -i ] ;
238  //~ addr &= 0x00FFFFFF; //YRT130802 new FAT with complete address
239  //~ addr |= 0x08000000;
240  curapp = ( tMenuItem* ) addr;
241  if ( !strcmp( curapp->Text, AppName ) )
242  {
243  return addr;
244  }
245  }
246  }
247 
248  return 0;
249 }
250 
251 /*******************************************************************************
252 *
253 * UTIL_SetTimer
254 *
255 *******************************************************************************/
265 /********************************************************************************/
266 void UTIL_SetTimer( u32 millisec, void ( *fTimerHandler )( void ) )
267 {
268  CurrentTimerDelay = ( millisec * TIMER_MULT_RATIO ) / TIMER_DIV_RATIO ;
269  if ( !CurrentTimerDelay )
270  CurrentTimerDelay = 1;
271 
272  CurrentTimerDelay = ( CurrentTimerDelay * freqTIM2[CurrentSpeed] ) / freqTIM2[SPEED_MEDIUM];
273  CurrentEventTimer = fTimerHandler ;
274 
275  return;
276 }