Commit 731f3592 authored by Damien George's avatar Damien George Committed by Paul Sokolovsky
Browse files

all: Add py/mphal.h and use it in all ports.

py/mphal.h contains declarations for generic mp_hal_XXX functions, such
as stdio and delay/ticks, which ports should provide definitions for.  A
port will also provide mphalport.h with further HAL declarations.
parent 0bd3f329
......@@ -30,7 +30,6 @@
#include "py/nlr.h"
#include "py/obj.h"
#include "py/runtime.h"
#include MICROPY_HAL_H
#include "user_interface.h"
const mp_obj_type_t pyb_adc_type;
......
......@@ -30,7 +30,6 @@
#include "py/nlr.h"
#include "py/obj.h"
#include "py/runtime.h"
#include MICROPY_HAL_H
#include "timeutils.h"
#include "user_interface.h"
#include "modpyb.h"
......
......@@ -32,7 +32,7 @@
#include "py/obj.h"
#include "py/gc.h"
#include "py/runtime.h"
#include MICROPY_HAL_H
#include "py/mphal.h"
#include "modpyb.h"
#include "modpybrtc.h"
#include "timeutils.h"
......
......@@ -54,7 +54,6 @@ typedef void *machine_ptr_t; // must be of pointer size
typedef const void *machine_const_ptr_t; // must be of pointer size
typedef long mp_off_t;
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
// extra built in names to add to the global namespace
......@@ -94,7 +93,7 @@ extern const struct _mp_obj_module_t uos_module;
// board specifics
#define MICROPY_HAL_H "esp_mphal.h"
#define MICROPY_MPHALPORT_H "esp_mphal.h"
#define MICROPY_HW_BOARD_NAME "ESP module"
#define MICROPY_HW_MCU_NAME "ESP8266"
#define MICROPY_PY_SYS_PLATFORM "ESP8266"
......@@ -30,10 +30,8 @@
#include "py/mpstate.h"
#include "py/repl.h"
#include "py/mphal.h"
#include "readline.h"
#ifdef MICROPY_HAL_H
#include MICROPY_HAL_H
#endif
#if 0 // print debugging info
#define DEBUG_PRINT (1)
......
......@@ -65,7 +65,6 @@ typedef void *machine_ptr_t; // must be of pointer size
typedef const void *machine_const_ptr_t; // must be of pointer size
typedef long mp_off_t;
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
// extra built in names to add to the global namespace
......@@ -76,14 +75,6 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
// We need to provide a declaration/definition of alloca()
#include <alloca.h>
#define mp_hal_ticks_ms() 0
int mp_hal_stdin_rx_chr(void);
void mp_hal_stdout_tx_str(const char *str);
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
static inline void mp_hal_set_interrupt_char(char c) {}
#define MICROPY_HW_BOARD_NAME "minimal"
#define MICROPY_HW_MCU_NAME "unknown-cpu"
......
static inline mp_uint_t mp_hal_ticks_ms(void) { return 0; }
static inline void mp_hal_set_interrupt_char(char c) {}
#include <string.h>
#include <unistd.h>
#include "py/mpconfig.h"
#include "py/mphal.h"
/*
* Extra UART functions
......
......@@ -32,9 +32,9 @@
#include "py/compile.h"
#include "py/runtime.h"
#include "py/gc.h"
#include "py/mphal.h"
#include "pyexec.h"
#include "readline.h"
#include MICROPY_HAL_H
#include "board.h"
#include "modpyb.h"
......@@ -59,7 +59,7 @@ soft_reset:
led_state(1, 0);
led_state(2, 0);
led_state(3, 1);
mp_hal_milli_delay(150);
mp_hal_delay_ms(150);
led_state(3, 0);
// init MicroPython runtime
......
......@@ -27,17 +27,17 @@
#include <stdio.h>
#include "py/obj.h"
#include MICROPY_HAL_H
#include "py/mphal.h"
#include "modpyb.h"
STATIC mp_obj_t pyb_millis(void) {
return MP_OBJ_NEW_SMALL_INT(mp_hal_get_milliseconds());
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis);
STATIC mp_obj_t pyb_elapsed_millis(mp_obj_t start) {
uint32_t startMillis = mp_obj_get_int(start);
uint32_t currMillis = mp_hal_get_milliseconds();
uint32_t currMillis = mp_hal_ticks_ms();
return MP_OBJ_NEW_SMALL_INT((currMillis - startMillis) & 0x1fff);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis);
......@@ -45,7 +45,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis);
STATIC mp_obj_t pyb_delay(mp_obj_t ms_in) {
mp_int_t ms = mp_obj_get_int(ms_in);
if (ms >= 0) {
mp_hal_milli_delay(ms);
mp_hal_delay_ms(ms);
}
return mp_const_none;
}
......
......@@ -86,7 +86,6 @@ typedef void *machine_ptr_t; // must be pointer size
typedef const void *machine_const_ptr_t; // must be pointer size
typedef int mp_off_t;
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
// extra builtin names to add to the global namespace
......@@ -108,6 +107,6 @@ extern const struct _mp_obj_module_t pyb_module;
char *readline_hist[8]; \
mp_obj_t keyboard_interrupt_obj; \
#define MICROPY_HAL_H "pic16bit_mphal.h"
#define MICROPY_MPHALPORT_H "pic16bit_mphal.h"
#define MICROPY_HW_BOARD_NAME "dsPICSK"
#define MICROPY_HW_MCU_NAME "dsPIC33"
......@@ -25,7 +25,7 @@
*/
#include <string.h>
#include "pic16bit_mphal.h"
#include "py/mphal.h"
#include "board.h"
static int interrupt_char;
......@@ -34,12 +34,12 @@ void mp_hal_init(void) {
MP_STATE_PORT(keyboard_interrupt_obj) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
}
mp_uint_t mp_hal_get_milliseconds(void) {
mp_uint_t mp_hal_ticks_ms(void) {
// TODO
return 0;
}
void mp_hal_milli_delay(mp_uint_t ms) {
void mp_hal_delay_ms(mp_uint_t ms) {
// tuned for fixed CPU frequency
for (int i = ms; i > 0; i--) {
for (volatile int j = 0; j < 5000; j++) {
......@@ -63,13 +63,13 @@ void mp_hal_stdout_tx_str(const char *str) {
mp_hal_stdout_tx_strn(str, strlen(str));
}
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
for (; len > 0; --len) {
uart_tx_char(*str++);
}
}
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
for (; len > 0; --len) {
if (*str == '\n') {
uart_tx_char('\r');
......
......@@ -26,19 +26,10 @@
#ifndef __MICROPY_INCLUDED_PIC16BIT_PIC16BIT_MPHAL_H__
#define __MICROPY_INCLUDED_PIC16BIT_PIC16BIT_MPHAL_H__
#define HAL_GetTick mp_hal_get_milliseconds
#include "py/mpstate.h"
void mp_hal_init(void);
mp_uint_t mp_hal_get_milliseconds(void);
void mp_hal_milli_delay(mp_uint_t ms);
void mp_hal_set_interrupt_char(int c);
int mp_hal_stdin_rx_chr(void);
void mp_hal_stdout_tx_str(const char *str);
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#endif // __MICROPY_INCLUDED_PIC16BIT_PIC16BIT_MPHAL_H__
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2015 Damien P. George
*
* 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 __MICROPY_INCLUDED_PY_MPHAL_H__
#define __MICROPY_INCLUDED_PY_MPHAL_H__
#include "py/mpconfig.h"
#ifdef MICROPY_MPHALPORT_H
#include MICROPY_MPHALPORT_H
#else
#include <mphalport.h>
#endif
#ifndef mp_hal_stdin_rx_chr
int mp_hal_stdin_rx_chr(void);
#endif
#ifndef mp_hal_stdout_tx_str
void mp_hal_stdout_tx_str(const char *str);
#endif
#ifndef mp_hal_stdout_tx_strn
void mp_hal_stdout_tx_strn(const char *str, size_t len);
#endif
#ifndef mp_hal_stdout_tx_strn_cooked
void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len);
#endif
#ifndef mp_hal_delay_ms
void mp_hal_delay_ms(mp_uint_t ms);
#endif
#ifndef mp_hal_ticks_ms
mp_uint_t mp_hal_ticks_ms(void);
#endif
#endif // __MICROPY_INCLUDED_PY_MPHAL_H__
......@@ -30,6 +30,7 @@
#include <stdio.h>
#include <string.h>
#include "py/mphal.h"
#include "py/mpprint.h"
#include "py/obj.h"
#include "py/objint.h"
......
......@@ -113,7 +113,7 @@ SRC_C = \
usbd_desc.c \
usbd_cdc_interface.c \
usbd_msc_storage.c \
mphal.c \
mphalport.c \
irq.c \
pendsv.c \
systick.c \
......
......@@ -25,16 +25,15 @@
*/
#include <stdio.h>
#include STM32_HAL_H
#include <string.h>
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "py/mphal.h"
#include "adc.h"
#include "pin.h"
#include "genhdr/pins.h"
#include "mphal.h"
#include "timer.h"
/// \moduleref pyb
......
......@@ -3,8 +3,8 @@
#include <stdio.h>
#include "py/obj.h"
#include "py/mphal.h"
#include "pin.h"
#include MICROPY_HAL_H
#define AF(af_idx, af_fn, af_unit, af_type, af_ptr) \
{ \
......
......@@ -33,10 +33,10 @@
#include "py/objtuple.h"
#include "py/runtime.h"
#include "py/gc.h"
#include "py/mphal.h"
#include "bufhelper.h"
#include "can.h"
#include "pybioctl.h"
#include MICROPY_HAL_H
#if MICROPY_HW_ENABLE_CAN
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment