text: /******************************************************************************
  
      @file    IntrOS: oscore.h
      @author  Rajmund Szymanski
      @date    16.12.2020
      @brief   IntrOS port file for STM8 uC.
  
   ******************************************************************************
  
     Copyright (c) 2018-2021 Rajmund Szymanski. All rights reserved.
  
     Permission is hereby granted, free of charge, to any person obtaining a copy
     of this software and associated documentation files (the "Software"), to
     deal in the Software without restriction, including without limitation the
     rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
     sell copies of the Software, and to permit persons to whom the Software is
     furnished to do so, subject to the following conditions:
  
     The above copyright notice and this permission notice shall be included
     in all copies or substantial portions of the Software.
  
     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
     THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     IN THE SOFTWARE.
  
   ******************************************************************************/
  
  #ifndef __INTROSCORE_H
  #define __INTROSCORE_H
  
  #include "osbase.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /* -------------------------------------------------------------------------- */
  
  #ifndef OS_STACK_SIZE
  #define OS_STACK_SIZE       128 /* default task stack size in bytes           */
  #endif
  
  /* -------------------------------------------------------------------------- */
  
  #ifndef OS_LOCK_LEVEL
  #define OS_LOCK_LEVEL         0 /* critical section blocks all interrupts     */
  #endif
  
  #if     OS_LOCK_LEVEL > 0
  #error  osconfig.h: Incorrect OS_LOCK_LEVEL value! Must be 0.
  #endif
  
  /* -------------------------------------------------------------------------- */
  
  typedef uint8_t               lck_t;
  typedef uint8_t               stk_t;
  
  /* -------------------------------------------------------------------------- */
  // task context
  
  typedef struct __ctx ctx_t;
  
  struct __ctx
  {
  	fun_t  * pc;
  	void   * sp;
  };
  
  #define _CTX_INIT() { NULL, NULL }
  
  /* -------------------------------------------------------------------------- */
  // init task context
  
  __STATIC_INLINE
  void port_ctx_init( ctx_t *ctx, stk_t *sp, fun_t *pc )
  {
  	ctx->sp = sp - 1;
  	ctx->pc = pc;
  }
  
  /* -------------------------------------------------------------------------- */
  
  void *_get_SP( void );
  lck_t _get_CC( void );
  void  _set_CC( lck_t lck );
  
  /* -------------------------------------------------------------------------- */
  // get current stack pointer
  
  __STATIC_INLINE
  void * port_get_sp( void )
  {
  	return _get_SP();
  }
  
  /* -------------------------------------------------------------------------- */
  
  __STATIC_INLINE
  lck_t port_get_lock( void )
  {
  	return _get_CC();
  }
  
  __STATIC_INLINE
  void port_put_lock( lck_t lck )
  {
  	_set_CC(lck);
  }
  
  __STATIC_INLINE
  void port_set_lock( void )
  {
  	disableInterrupts();
  }
  
  __STATIC_INLINE
  void port_clr_lock( void )
  {
  	enableInterrupts();
  }
  
  /* -------------------------------------------------------------------------- */
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif//__INTROSCORE_H
  