LCOV - code coverage report
Current view: top level - ports/unix - mphalport.h (source / functions) Hit Total Coverage
Test: unix_coverage_v1.22.0-343-g7b050b366.info Lines: 3 8 37.5 %
Date: 2024-04-25 17:00:48 Functions: 0 1 0.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * This file is part of the MicroPython project, http://micropython.org/
       3                 :            :  *
       4                 :            :  * The MIT License (MIT)
       5                 :            :  *
       6                 :            :  * Copyright (c) 2015 Damien P. George
       7                 :            :  *
       8                 :            :  * Permission is hereby granted, free of charge, to any person obtaining a copy
       9                 :            :  * of this software and associated documentation files (the "Software"), to deal
      10                 :            :  * in the Software without restriction, including without limitation the rights
      11                 :            :  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      12                 :            :  * copies of the Software, and to permit persons to whom the Software is
      13                 :            :  * furnished to do so, subject to the following conditions:
      14                 :            :  *
      15                 :            :  * The above copyright notice and this permission notice shall be included in
      16                 :            :  * all copies or substantial portions of the Software.
      17                 :            :  *
      18                 :            :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      19                 :            :  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      20                 :            :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      21                 :            :  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      22                 :            :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      23                 :            :  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      24                 :            :  * THE SOFTWARE.
      25                 :            :  */
      26                 :            : #include <errno.h>
      27                 :            : #include <unistd.h>
      28                 :            : 
      29                 :            : #ifndef CHAR_CTRL_C
      30                 :            : #define CHAR_CTRL_C (3)
      31                 :            : #endif
      32                 :            : 
      33                 :            : // If threading is enabled, configure the atomic section.
      34                 :            : #if MICROPY_PY_THREAD
      35                 :            : #define MICROPY_BEGIN_ATOMIC_SECTION() (mp_thread_unix_begin_atomic_section(), 0xffffffff)
      36                 :            : #define MICROPY_END_ATOMIC_SECTION(x) (void)x; mp_thread_unix_end_atomic_section()
      37                 :            : #endif
      38                 :            : 
      39                 :            : // In lieu of a WFI(), slow down polling from being a tight loop.
      40                 :            : //
      41                 :            : // Note that we don't delay for the full TIMEOUT_MS, as execution
      42                 :            : // can't be woken from the delay.
      43                 :            : #define MICROPY_INTERNAL_WFE(TIMEOUT_MS) mp_hal_delay_us(500)
      44                 :            : 
      45                 :            : void mp_hal_set_interrupt_char(char c);
      46                 :            : 
      47                 :            : #define mp_hal_stdio_poll unused // this is not implemented, nor needed
      48                 :            : void mp_hal_stdio_mode_raw(void);
      49                 :            : void mp_hal_stdio_mode_orig(void);
      50                 :            : 
      51                 :            : #if MICROPY_PY_BUILTINS_INPUT && MICROPY_USE_READLINE == 0
      52                 :            : 
      53                 :            : #include <malloc.h>
      54                 :            : #include "py/misc.h"
      55                 :            : #include "input.h"
      56                 :            : #define mp_hal_readline mp_hal_readline
      57                 :            : static inline int mp_hal_readline(vstr_t *vstr, const char *p) {
      58                 :            :     char *line = prompt((char *)p);
      59                 :            :     vstr_add_str(vstr, line);
      60                 :            :     free(line);
      61                 :            :     return 0;
      62                 :            : }
      63                 :            : 
      64                 :            : #elif MICROPY_PY_BUILTINS_INPUT && MICROPY_USE_READLINE == 1
      65                 :            : 
      66                 :            : #include "py/misc.h"
      67                 :            : #include "shared/readline/readline.h"
      68                 :            : // For built-in input() we need to wrap the standard readline() to enable raw mode
      69                 :            : #define mp_hal_readline mp_hal_readline
      70                 :          0 : static inline int mp_hal_readline(vstr_t *vstr, const char *p) {
      71                 :          0 :     mp_hal_stdio_mode_raw();
      72                 :          0 :     int ret = readline(vstr, p);
      73                 :          0 :     mp_hal_stdio_mode_orig();
      74                 :          0 :     return ret;
      75                 :            : }
      76                 :            : 
      77                 :            : #endif
      78                 :            : 
      79                 :       9966 : static inline void mp_hal_delay_us(mp_uint_t us) {
      80                 :       9966 :     usleep(us);
      81                 :          4 : }
      82                 :            : #define mp_hal_ticks_cpu() 0
      83                 :            : 
      84                 :            : // This macro is used to implement PEP 475 to retry specified syscalls on EINTR
      85                 :            : #define MP_HAL_RETRY_SYSCALL(ret, syscall, raise) { \
      86                 :            :         for (;;) { \
      87                 :            :             MP_THREAD_GIL_EXIT(); \
      88                 :            :             ret = syscall; \
      89                 :            :             MP_THREAD_GIL_ENTER(); \
      90                 :            :             if (ret == -1) { \
      91                 :            :                 int err = errno; \
      92                 :            :                 if (err == EINTR) { \
      93                 :            :                     mp_handle_pending(true); \
      94                 :            :                     continue; \
      95                 :            :                 } \
      96                 :            :                 raise; \
      97                 :            :             } \
      98                 :            :             break; \
      99                 :            :         } \
     100                 :            : }
     101                 :            : 
     102                 :            : #define RAISE_ERRNO(err_flag, error_val) \
     103                 :            :     { if (err_flag == -1) \
     104                 :            :       { mp_raise_OSError(error_val); } }
     105                 :            : 
     106                 :            : void mp_hal_get_random(size_t n, void *buf);
     107                 :            : 
     108                 :            : #if MICROPY_PY_BLUETOOTH
     109                 :            : enum {
     110                 :            :     MP_HAL_MAC_BDADDR,
     111                 :            : };
     112                 :            : 
     113                 :            : void mp_hal_get_mac(int idx, uint8_t buf[6]);
     114                 :            : #endif

Generated by: LCOV version 1.15-5-g462f71d