test public

Dependencies:   HttpServer_snapshot_mbed-os

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers r_ospl_RTX.c Source File

r_ospl_RTX.c

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * DISCLAIMER
00003 * This software is supplied by Renesas Electronics Corporation and is only
00004 * intended for use with Renesas products. No other uses are authorized. This
00005 * software is owned by Renesas Electronics Corporation and is protected under
00006 * all applicable laws, including copyright laws.
00007 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
00008 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
00009 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00010 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
00011 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
00012 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
00013 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
00014 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
00015 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
00016 * Renesas reserves the right, without notice, to make changes to this software
00017 * and to discontinue the availability of this software. By using this software,
00018 * you agree to the additional terms and conditions found by accessing the
00019 * following link:
00020 * http://www.renesas.com/disclaimer
00021 * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
00022 *******************************************************************************/
00023 /**
00024 * @file  r_ospl_RTX.c
00025 * @brief   OS Porting Layer API for RTX
00026 *
00027 * $Module: OSPL $ $PublicVersion: 0.90 $ (=R_OSPL_VERSION)
00028 * $Rev: 35 $
00029 * $Date:: 2014-04-15 21:38:18 +0900#$
00030 */
00031 
00032 
00033 /******************************************************************************
00034 Includes   <System Includes> , "Project Includes"
00035 ******************************************************************************/
00036 #include  "r_ospl.h"
00037 #include  "r_ospl_os_less_private.h"
00038 #include  "r_ospl_private.h"
00039 #include  "core_ca.h"
00040 #if R_OSPL_IS_PREEMPTION
00041 #include  "cmsis_os.h"
00042 #include  "r_ospl_RTX_private.h"
00043 #endif
00044 
00045 
00046 /******************************************************************************
00047 Typedef definitions
00048 ******************************************************************************/
00049 
00050 /******************************************************************************
00051 Macro definitions
00052 ******************************************************************************/
00053 
00054 /**
00055 * @def  OS_ERROR_SIGNAL
00056 * @brief  CMSIS-RTOS defined immediate value
00057 * @par Parameters
00058 *    None
00059 * @return  None.
00060 */
00061 #define  OS_ERROR_SIGNAL  0x80000000
00062 
00063 
00064 /**
00065 * @def  R_OSPL_EVENT_WATCH
00066 * @brief  Debug tool
00067 * @par Parameters
00068 *    None
00069 * @return  None.
00070 */
00071 #define  R_OSPL_EVENT_WATCH  0  /* [R_OSPL_EVENT_WATCH] 0 or 1 */
00072 
00073 
00074 /******************************************************************************
00075 Imported global variables and functions (from other files)
00076 ******************************************************************************/
00077 
00078 /******************************************************************************
00079 Exported global variables and functions (to be accessed by other files)
00080 ******************************************************************************/
00081 
00082 /******************************************************************************
00083 Private global variables and functions
00084 ******************************************************************************/
00085 
00086 
00087 /***********************************************************************
00088 * Implement: R_OSPL_Initialize
00089 ************************************************************************/
00090 errnum_t  R_OSPL_Initialize( const void *const  in_NullConfig )
00091 {
00092     R_UNREFERENCED_VARIABLE( in_NullConfig );
00093     return  0;
00094 }
00095 
00096 
00097 /***********************************************************************
00098 * Implement: R_OSPL_THREAD_GetCurrentId
00099 ************************************************************************/
00100 r_ospl_thread_id_t  R_OSPL_THREAD_GetCurrentId(void)
00101 {
00102     return  osThreadGetId();
00103 }
00104 
00105 
00106 /***********************************************************************
00107 * Implement: R_OSPL_EVENT_Set
00108 ************************************************************************/
00109 void  R_OSPL_EVENT_Set( r_ospl_thread_id_t const  ThreadId,  bit_flags32_t const  SetFlags )
00110 {
00111     int32_t  ret;
00112 
00113     if ( ThreadId != NULL ) {
00114 #if  R_OSPL_EVENT_WATCH
00115         R_D_AddToIntLog( 0x70100000 + SetFlags );
00116         R_D_AddToIntLog( (uintptr_t) R_OSPL_THREAD_GetCurrentId() );
00117         R_D_AddToIntLog( (uintptr_t) ThreadId );
00118 #endif
00119 
00120         ret = osSignalSet( (osThreadId_t) ThreadId, (int32_t) SetFlags );
00121         ASSERT_D( (ret & OS_ERROR_SIGNAL) == 0,  R_NOOP() );
00122         R_UNREFERENCED_VARIABLE( ret );  /* for Release configuration */
00123     }
00124 }
00125 
00126 
00127 /***********************************************************************
00128 * Implement: R_OSPL_EVENT_Clear
00129 ************************************************************************/
00130 void  R_OSPL_EVENT_Clear( r_ospl_thread_id_t const  ThreadId,  bit_flags32_t const  ClearFlags1 )
00131 {
00132     int32_t  ret;
00133 
00134     if ( ThreadId != NULL ) {
00135         IF_D( ( ClearFlags1 & ~0xFFFF ) != 0 ) {
00136             R_NOOP();
00137         }
00138 
00139 #if  R_OSPL_EVENT_WATCH
00140         R_D_AddToIntLog( 0x70C00000 + ClearFlags1 );
00141         R_D_AddToIntLog( (uintptr_t) R_OSPL_THREAD_GetCurrentId() );
00142         R_D_AddToIntLog( (uintptr_t) ThreadId );
00143 #endif
00144 
00145         ret = osSignalClear( (osThreadId_t) ThreadId, (int32_t) ClearFlags1 );
00146         /* "& 0xFFFF" is for avoiding error in osSignalClear */
00147         ASSERT_D( (ret & OS_ERROR_SIGNAL) == 0,  R_NOOP() );
00148         R_UNREFERENCED_VARIABLE( ret );  /* for Release configuration */
00149     }
00150 }
00151 
00152 
00153 /***********************************************************************
00154 * Implement: R_OSPL_EVENT_Get
00155 ************************************************************************/
00156 #if ( ! defined( osCMSIS )  ||  osCMSIS <= 0x10001 ) &&  R_OSPL_VERSION < 85
00157 bit_flags32_t  R_OSPL_EVENT_Get( r_ospl_thread_id_t const  ThreadId )
00158 {
00159     int32_t  ret;
00160 
00161     if ( ThreadId == NULL ) {
00162         ret = 0;
00163     } else {
00164         ret = osSignalGet( (osThreadId_t) ThreadId );
00165         ASSERT_D( (ret & OS_ERROR_SIGNAL) == 0,  R_NOOP() );
00166     }
00167 
00168     return  (bit_flags32_t) ret;
00169 }
00170 #endif
00171 
00172 
00173 /***********************************************************************
00174 * Implement: R_OSPL_EVENT_Wait
00175 ************************************************************************/
00176 errnum_t  R_OSPL_EVENT_Wait( bit_flags32_t const  WaigingFlags,  bit_flags32_t *const  out_GotFlags,
00177                              uint32_t const  Timeout_msec )
00178 {
00179     errnum_t  e;
00180     osEvent   event;
00181 
00182     R_STATIC_ASSERT( R_OSPL_INFINITE == osWaitForever, "" );
00183 
00184 #if  R_OSPL_EVENT_WATCH
00185     R_D_AddToIntLog( 0x70BE0000 + WaigingFlags );
00186     R_D_AddToIntLog( (uintptr_t) R_OSPL_THREAD_GetCurrentId() );
00187 
00188     {
00189         static int tc;
00190         if ( R_D_Counter( &tc, 0, NULL ) ) {
00191             R_DEBUG_BREAK();
00192         }
00193     }
00194 #endif
00195 
00196 
00197     event = osSignalWait( (int32_t) WaigingFlags, Timeout_msec );
00198 
00199 
00200 #if  R_OSPL_EVENT_WATCH
00201     R_D_AddToIntLog( 0x70AF0000 );
00202     R_D_AddToIntLog( (uintptr_t) R_OSPL_THREAD_GetCurrentId() );
00203 #endif
00204 
00205     if ( (event.status == osOK) || (event.status == osEventTimeout) ) {
00206         if ( out_GotFlags != NULL ) {
00207             *out_GotFlags = R_OSPL_TIMEOUT;
00208         }
00209         IF ( event.status == osEventTimeout ) {
00210             e=E_TIME_OUT;
00211             goto fin;
00212         }
00213     } else {
00214         ASSERT_R( event.status == osEventSignal,  e=E_OTHERS;  goto fin );
00215 
00216         if ( out_GotFlags != NULL ) {
00217             *out_GotFlags = (bit_flags32_t) event.value.signals;
00218         }
00219     }
00220 
00221     e=0;
00222 fin:
00223     return  e;
00224 }
00225 
00226 
00227 /***********************************************************************
00228 * Implement: R_OSPL_SetInterruptPriority
00229 ************************************************************************/
00230 errnum_t  R_OSPL_SetInterruptPriority( bsp_int_src_t const  IRQ_Num, int_fast32_t const  Priority )
00231 {
00232     GIC_SetPriority( IRQ_Num, (uint32_t) Priority );
00233     return  0;
00234 }
00235 
00236 
00237 /***********************************************************************
00238 * Implement: R_OSPL_MEMORY_Flush
00239 ************************************************************************/
00240 void  R_OSPL_MEMORY_Flush( r_ospl_flush_t const  FlushType )
00241 {
00242     if ( FlushType == R_OSPL_FLUSH_WRITEBACK_INVALIDATE ) {
00243 #if 0
00244         printf( "L1Flush\n" );
00245 #endif
00246 
00247 #if IS_RTX_USED
00248         L1C_CleanInvalidateDCacheAll();
00249 #else
00250 #error
00251 #endif
00252     } else if ( FlushType == R_OSPL_FLUSH_WRITEBACK_INVALIDATE_2ND ) {
00253 #if 0
00254         printf( "PL310Flush\n" );
00255 #endif
00256 
00257         L2C_CleanInvAllByWay();
00258     } else {
00259         ASSERT_D( false,  R_NOOP() );
00260     }
00261 }
00262 
00263 
00264 /**
00265 * @brief   R_OSPL_Is1bitOnly_Fast32_Sub
00266 *
00267 * @par Parameters
00268 *    None
00269 * @return  None.
00270 */
00271 #ifndef  R_OSPL_NDEBUG
00272 static bool_t  R_OSPL_Is1bitOnly_Fast32_Sub( uint_fast32_t Value )
00273 {
00274     if ( (Value & 0x0000FFFFu) == 0 ) {
00275         Value >>= 16;
00276     }
00277     if ( (Value & 0x000000FFu) == 0 ) {
00278         Value >>=  8;
00279     }
00280     if ( (Value & 0x0000000Fu) == 0 ) {
00281         Value >>=  4;
00282     }
00283     if ( (Value & 0x00000003u) == 0 ) {
00284         Value >>=  2;
00285     }
00286     if ( (Value & 0x00000001u) == 0 ) {
00287         Value >>=  1;
00288     }
00289     return  ( Value == 1 );
00290 }
00291 #endif
00292 
00293 
00294 /***********************************************************************
00295 * Implement: R_OSPL_MEMORY_RangeFlush
00296 ************************************************************************/
00297 errnum_t  R_OSPL_MEMORY_RangeFlush( r_ospl_flush_t const  FlushType,
00298                                     const void *const  StartAddress,  size_t const  Length )
00299 {
00300     errnum_t   e;
00301     size_t     cache_line_size;
00302     size_t     cache_line_mask;
00303     uintptr_t  start;
00304     uintptr_t  over;
00305 
00306     ASSERT_R( FlushType == R_OSPL_FLUSH_INVALIDATE,  e=E_BAD_COMMAND_ID; goto fin );
00307 
00308     cache_line_size = R_OSPL_MEMORY_GetCacheLineSize();
00309     cache_line_mask = cache_line_size - 1u;
00310     ASSERT_D( R_OSPL_Is1bitOnly_Fast32_Sub( cache_line_size ), e=E_OTHERS; goto fin );
00311 
00312     /* ->MISRA 11.3 */ /* ->SEC R2.7.1 */
00313     ASSERT_R( ( (uintptr_t) StartAddress & cache_line_mask ) == 0u, e=E_OTHERS; goto fin );
00314     ASSERT_R( ( Length & cache_line_mask ) == 0u, e=E_OTHERS; goto fin );
00315 
00316     start = (uintptr_t) StartAddress;
00317     over  = ((uintptr_t) StartAddress + Length) - 1u;
00318     /* <-MISRA 11.3 */ /* <-SEC R2.7.1 */
00319 
00320     R_OSPL_MEMORY_RangeFlush_Sub( start, over, cache_line_size );
00321 
00322     e=0;
00323 fin:
00324     return  e;
00325 }
00326 
00327 
00328 /***********************************************************************
00329 * Implement: R_OSPL_MEMORY_GetSpecification
00330 ************************************************************************/
00331 void  R_OSPL_MEMORY_GetSpecification( r_ospl_memory_spec_t *const  out_MemorySpec )
00332 {
00333     IF_DQ( out_MemorySpec == NULL ) {
00334         goto fin;
00335     }
00336 
00337     out_MemorySpec->CacheLineSize = R_OSPL_MEMORY_GetCacheLineSize();
00338 
00339 fin:
00340     return;
00341 }
00342 
00343 
00344 /***********************************************************************
00345 * Implement: R_OSPL_Delay
00346 ************************************************************************/
00347 errnum_t  R_OSPL_Delay( uint32_t const  DelayTime_msec )
00348 {
00349     errnum_t   e;
00350     osStatus_t rs;
00351     bool_t const    is_overflow = ( DelayTime_msec > R_OSPL_MAX_TIME_OUT );
00352     uint32_t const  delay_parameter = DelayTime_msec + 1u;
00353 
00354     ASSERT_D( ! is_overflow, R_NOOP() );
00355     /* RTX 5.16: If delay_parameter = 100000, "osDelay" waits 65534 */
00356 
00357     rs= osDelay( delay_parameter );
00358     IF ( rs == osErrorISR ) {
00359         e=E_NOT_THREAD;
00360         R_OSPL_RaiseUnrecoverable( e );
00361         goto fin;
00362     }
00363     IF ( IS( is_overflow ) ) {
00364         e=E_TIME_OUT;
00365         goto fin;
00366     }
00367 
00368     IF (
00369         (rs != osOK) &&           /* for delay_parameter == 0 */
00370         (rs != osEventTimeout) ) { /* for delay_parameter != 0 */
00371         e=E_OTHERS;
00372         goto fin;
00373     }
00374 
00375     e=0;
00376 fin:
00377     return  e;
00378 }
00379 
00380 
00381 /***********************************************************************
00382 * Implement: R_OSPL_QUEUE_Create
00383 ************************************************************************/
00384 errnum_t  R_OSPL_QUEUE_Create( r_ospl_queue_t **out_self, r_ospl_queue_def_t *QueueDefine )
00385 {
00386     errnum_t  e;
00387     r_ospl_queue_t  *self = QueueDefine;
00388 
00389     self->MailQId = osMailCreate( (osMailQDef_t *) QueueDefine->MailQDef, NULL );
00390     IF ( self->MailQId == NULL ) {
00391         e=E_OTHERS;
00392         goto fin;
00393     }
00394     self->PublicStatus.UsedCount = 0;
00395 
00396     *out_self = self;
00397 
00398     e=0;
00399 fin:
00400     return  e;
00401 }
00402 
00403 
00404 /***********************************************************************
00405 * Implement: R_OSPL_QUEUE_GetStatus
00406 ************************************************************************/
00407 errnum_t  R_OSPL_QUEUE_GetStatus( r_ospl_queue_t *self,  const r_ospl_queue_status_t **out_Status )
00408 {
00409     *out_Status = &self->PublicStatus;
00410     return  0;
00411 }
00412 
00413 
00414 /***********************************************************************
00415 * Implement: R_OSPL_QUEUE_Allocate
00416 ************************************************************************/
00417 errnum_t  R_OSPL_QUEUE_Allocate( r_ospl_queue_t *self,  void *out_Address,  uint32_t Timeout_msec )
00418 {
00419     errnum_t  e;
00420     void     *address;
00421 
00422     address = osMailAlloc( self->MailQId, Timeout_msec );
00423     *(void **) out_Address = address;
00424     IF ( address == NULL  &&  Timeout_msec > 0 ) {
00425         if ( R_OSPL_THREAD_GetCurrentId() == NULL ) {
00426             e=E_NOT_THREAD;
00427         } else {
00428             e=E_TIME_OUT;
00429         }
00430         goto fin;
00431     }
00432 
00433     R_OSPL_DisableAllInterrupt();
00434     self->PublicStatus.UsedCount += 1;
00435 
00436     e=0;
00437     R_OSPL_EnableAllInterrupt();
00438 fin:
00439     return  e;
00440 }
00441 
00442 
00443 /***********************************************************************
00444 * Implement: R_OSPL_QUEUE_Put
00445 ************************************************************************/
00446 errnum_t  R_OSPL_QUEUE_Put( r_ospl_queue_t *self,  void *Address )
00447 {
00448     errnum_t    e;
00449     osStatus_t  status;
00450 
00451     status = osMailPut( self->MailQId, Address );
00452     IF ( status != osOK ) {
00453         e=E_OTHERS;
00454         goto fin;
00455     }
00456 
00457     e=0;
00458 fin:
00459     return  e;
00460 }
00461 
00462 
00463 /***********************************************************************
00464 * Implement: R_OSPL_QUEUE_Get
00465 ************************************************************************/
00466 errnum_t  R_OSPL_QUEUE_Get( r_ospl_queue_t *self,  void *out_Address,  uint32_t Timeout_msec )
00467 {
00468     errnum_t  e;
00469     osEvent   event;
00470 
00471     event = osMailGet( self->MailQId, Timeout_msec );
00472 
00473     if ( event.status != osOK ) {
00474         IF ( event.status != osEventMail ) {
00475             if ( event.status == osEventTimeout ) {
00476                 e = E_TIME_OUT;
00477             } else if ( event.status == osErrorParameter ) {
00478                 if ( R_OSPL_THREAD_GetCurrentId() == NULL ) {
00479                     e = E_NOT_THREAD;
00480                 } else {
00481                     e = E_OTHERS;
00482                 }
00483             } else {
00484                 e = E_OTHERS;
00485             }
00486             goto fin;
00487         }
00488     }
00489 
00490     *(void **) out_Address = event.value.p;
00491 
00492     e=0;
00493 fin:
00494     return  e;
00495 }
00496 
00497 
00498 /***********************************************************************
00499 * Implement: R_OSPL_QUEUE_Free
00500 ************************************************************************/
00501 errnum_t  R_OSPL_QUEUE_Free( r_ospl_queue_t *self,  void *Address )
00502 {
00503     errnum_t    e;
00504     osStatus_t  status;
00505 
00506     status = osMailFree( self->MailQId, Address );
00507     IF ( status != osOK ) {
00508         e=E_OTHERS;
00509         goto fin;
00510     }
00511 
00512     R_OSPL_DisableAllInterrupt();
00513     self->PublicStatus.UsedCount -= 1;
00514 
00515     e=0;
00516     R_OSPL_EnableAllInterrupt();
00517 fin:
00518     return  e;
00519 }
00520 
00521