/ components / kendryte_sdk / include / portmacro.h
portmacro.h
  1  /* Copyright 2018 Canaan Inc.
  2   *
  3   * Licensed under the Apache License, Version 2.0 (the "License");
  4   * you may not use this file except in compliance with the License.
  5   * You may obtain a copy of the License at
  6   *
  7   *     http://www.apache.org/licenses/LICENSE-2.0
  8   *
  9   * Unless required by applicable law or agreed to in writing, software
 10   * distributed under the License is distributed on an "AS IS" BASIS,
 11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   * See the License for the specific language governing permissions and
 13   * limitations under the License.
 14   */
 15  /*
 16   * FreeRTOS Kernel V10.0.1
 17   * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 18   *
 19   * Permission is hereby granted, free of charge, to any person obtaining a copy of
 20   * this software and associated documentation files (the "Software"), to deal in
 21   * the Software without restriction, including without limitation the rights to
 22   * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 23   * the Software, and to permit persons to whom the Software is furnished to do so,
 24   * subject to the following conditions:
 25   *
 26   * The above copyright notice and this permission notice shall be included in all
 27   * copies or substantial portions of the Software.
 28   *
 29   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 30   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 31   * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 32   * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 33   * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 34   * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 35   *
 36   * http://www.FreeRTOS.org
 37   * http://aws.amazon.com/freertos
 38   *
 39   * 1 tab == 4 spaces!
 40   */
 41  
 42  #ifndef PORTMACRO_H
 43  #define PORTMACRO_H
 44  
 45  #ifdef __cplusplus
 46  extern "C" {
 47  #endif
 48  
 49  /*-----------------------------------------------------------
 50   * Port specific definitions.
 51   *
 52   * The settings in this file configure FreeRTOS correctly for the
 53   * given hardware and compiler.
 54   *
 55   * These settings should not be altered.
 56   *-----------------------------------------------------------
 57   */
 58  #include <encoding.h>
 59  /* Multi-Core */
 60  #define portNUM_PROCESSORS 1
 61  
 62  /* Type definitions. */
 63  #define portCHAR        char
 64  #define portFLOAT       float
 65  #define portDOUBLE      double
 66  #define portLONG        long
 67  #define portSHORT       short
 68  #define portBASE_TYPE   long
 69  
 70  #define portSTACK_TYPE  uintptr_t
 71  #define portPOINTER_SIZE_TYPE   uintptr_t
 72  
 73  typedef portSTACK_TYPE StackType_t;
 74  typedef long BaseType_t;
 75  typedef unsigned long UBaseType_t;
 76  
 77  #if( configUSE_16_BIT_TICKS == 1 )
 78      typedef uint16_t TickType_t;
 79      #define portMAX_DELAY ( TickType_t ) 0xffff
 80  #else
 81      typedef uint32_t TickType_t;
 82      #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
 83  #endif
 84  /*-----------------------------------------------------------*/
 85  
 86  /* Architecture specifics. */
 87  #define portSTACK_GROWTH			( -1 )
 88  #define portTICK_PERIOD_MS			( ( TickType_t ) (1000 / configTICK_RATE_HZ) )
 89  #ifdef __riscv64
 90      #define portBYTE_ALIGNMENT	8
 91  #else
 92      #define portBYTE_ALIGNMENT	4
 93  #endif
 94  #define portCRITICAL_NESTING_IN_TCB					1
 95  /*-----------------------------------------------------------*/
 96  
 97  
 98  /* Scheduler utilities. */
 99  extern void vPortYield( void );
100  #define portYIELD()					vPortYield()
101  
102  extern void vPortYieldFromISR(void);
103  /*-----------------------------------------------------------*/
104  
105  /* Architecture specific optimisations. */
106  #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
107  #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
108  #endif
109  
110  #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
111  
112  /* Check the configuration. */
113  #if( configMAX_PRIORITIES > 32 )
114  #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32.  It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice.
115  #endif
116  
117  /* Store/clear the ready priorities in a bit map. */
118  #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
119  #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
120  
121  /*-----------------------------------------------------------*/
122  
123  #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - __builtin_clz( ( uxReadyPriorities ) ) )
124  
125  #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
126  
127  /* Critical section management. */
128  extern int vPortSetInterruptMask( void );
129  extern void vPortClearInterruptMask( int );
130  extern void vTaskEnterCritical( void );
131  extern void vTaskExitCritical( void );
132  extern UBaseType_t uxPortGetProcessorId(void);
133  void prvSetNextTimerInterrupt();
134  void vPortAddNewTaskToReadyListAsync(UBaseType_t uxPsrId, void* pxNewTaskHandle);
135  
136  void vPortEnterCritical(void);
137  void vPortExitCritical(void);
138  
139  UBaseType_t uxPortGetCPUClock();
140  
141  #define portGET_PROCESSOR_ID() uxPortGetProcessorId()
142  
143  #define portDISABLE_INTERRUPTS()                __asm volatile  ( "csrc mstatus,8" )
144  #define portENABLE_INTERRUPTS()                 __asm volatile  ( "csrs mstatus,8" )
145  #define portENTER_CRITICAL()					vPortEnterCritical()
146  #define portEXIT_CRITICAL()						vPortExitCritical()
147  #define portSET_INTERRUPT_MASK_FROM_ISR()       vPortSetInterruptMask()
148  #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue )       vPortClearInterruptMask( uxSavedStatusValue )
149  /*-----------------------------------------------------------*/
150  
151  /* Task function macros as described on the FreeRTOS.org WEB site. */
152  #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
153  #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
154  
155  #define portNOP() __asm volatile 	( " nop " )
156  
157  #ifdef __cplusplus
158  }
159  #endif
160  
161  #endif /* PORTMACRO_H */
162