Commit 8e611e84 authored by Daniel Campora's avatar Daniel Campora
Browse files

cc3200: Add Timer module. Supports free running, PWM and capture modes.

parent 9466e154
......@@ -26,7 +26,6 @@
__stack_size__ = 2K; /* interrupts are handled within this stack */
__min_heap_size__ = 8K;
__rtos_heap_size = 16K;
MEMORY
{
......
......@@ -98,6 +98,7 @@ APP_MODS_SRC_C = $(addprefix mods/,\
pybsd.c \
pybsleep.c \
pybspi.c \
pybtimer.c \
pybuart.c \
pybwdt.c \
)
......@@ -192,6 +193,7 @@ $(BUILD)/FreeRTOS/Source/%.o: CFLAGS += -Os
$(BUILD)/ftp/%.o: CFLAGS += -Os
$(BUILD)/hal/%.o: CFLAGS += -Os
$(BUILD)/misc/%.o: CFLAGS += -Os
$(BUILD)/mods/%.o: CFLAGS += -Os
$(BUILD)/py/%.o: CFLAGS += -Os
$(BUILD)/simplelink/%.o: CFLAGS += -Os
$(BUILD)/drivers/cc3100/%.o: CFLAGS += -Os
......
......@@ -71,7 +71,6 @@ mp_obj_t mpcallback_new (mp_obj_t parent, mp_obj_t handler, const mp_cb_methods_
mpcallback_obj_t *mpcallback_find (mp_obj_t parent) {
for (mp_uint_t i = 0; i < MP_STATE_PORT(mpcallback_obj_list).len; i++) {
// search for the object and then remove it
mpcallback_obj_t *callback_obj = ((mpcallback_obj_t *)(MP_STATE_PORT(mpcallback_obj_list).items[i]));
if (callback_obj->parent == parent) {
return callback_obj;
......
......@@ -80,10 +80,10 @@ STATIC mp_obj_t network_server_stop(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_server_stop_obj, network_server_stop);
STATIC mp_obj_t network_server_enabled(void) {
STATIC mp_obj_t network_server_running(void) {
return MP_BOOL(servers_are_enabled());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_server_enabled_obj, network_server_enabled);
STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_server_running_obj, network_server_running);
STATIC mp_obj_t network_server_login(mp_obj_t user, mp_obj_t pass) {
const char *_user = mp_obj_str_get_str(user);
......@@ -102,7 +102,7 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
{ MP_OBJ_NEW_QSTR(MP_QSTR_start_server), (mp_obj_t)&network_server_start_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_stop_server), (mp_obj_t)&network_server_stop_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_server_enabled), (mp_obj_t)&network_server_enabled_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_server_running), (mp_obj_t)&network_server_running_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_server_login), (mp_obj_t)&network_server_login_obj },
#endif
};
......
......@@ -62,6 +62,7 @@
#include "pybwdt.h"
#include "pybsleep.h"
#include "pybspi.h"
#include "pybtimer.h"
#include "utils.h"
#include "gccollect.h"
#include "mperror.h"
......@@ -271,6 +272,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_I2C), (mp_obj_t)&pyb_i2c_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SPI), (mp_obj_t)&pyb_spi_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Timer), (mp_obj_t)&pyb_timer_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Sleep), (mp_obj_t)&pyb_sleep_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_HeartBeat), (mp_obj_t)&pyb_heartbeat_obj },
......
......@@ -787,6 +787,7 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
// connect to the requested access point
modwlan_Status_t status;
status = wlan_do_connect (ssid, ssid_len, bssid, sec, key, key_len);
// TODO: make the timeout a parameter so that is configurable
if (status == MODWLAN_ERROR_TIMEOUT) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_operation_failed));
}
......
......@@ -755,6 +755,7 @@ STATIC void EXTI_Handler(uint port) {
uint32_t bit = MAP_GPIOIntStatus(port, true);
MAP_GPIOIntClear(port, bit);
// TODO: loop through all the active bits before exiting
pin_obj_t *self = (pin_obj_t *)pin_find_pin_by_port_bit(&pin_cpu_pins_locals_dict, port, bit);
mp_obj_t _callback = mpcallback_find(self);
mpcallback_handler(_callback);
......
......@@ -92,6 +92,18 @@ void pybrtc_init(void) {
}
}
void pyb_rtc_callback_disable (mp_obj_t self_in) {
// check the wake from param
if (pybrtc_data.prwmode & PYB_PWR_MODE_ACTIVE) {
// disable the slow clock interrupt
MAP_PRCMIntDisable(PRCM_INT_SLOW_CLK_CTR);
}
// disable wake from ldps and hibernate
pybsleep_configure_timer_wakeup (PYB_PWR_MODE_ACTIVE);
// read the interrupt status to clear any pending interrupt
(void)MAP_PRCMIntStatus();
}
/******************************************************************************
DECLARE PRIVATE FUNCTIONS
******************************************************************************/
......@@ -108,18 +120,6 @@ STATIC void pyb_rtc_callback_enable (mp_obj_t self_in) {
pybsleep_configure_timer_wakeup (pybrtc_data.prwmode);
}
STATIC void pyb_rtc_callback_disable (mp_obj_t self_in) {
// check the wake from param
if (pybrtc_data.prwmode & PYB_PWR_MODE_ACTIVE) {
// disable the slow clock interrupt
MAP_PRCMIntDisable(PRCM_INT_SLOW_CLK_CTR);
}
// disable wake from ldps and hibernate
pybsleep_configure_timer_wakeup (PYB_PWR_MODE_ACTIVE);
// read the interrupt status to clear any pending interrupt
(void)MAP_PRCMIntStatus();
}
/******************************************************************************/
// Micro Python bindings
......
......@@ -34,5 +34,6 @@
extern const mp_obj_base_t pyb_rtc_obj;
void pybrtc_init(void);
void pyb_rtc_callback_disable (mp_obj_t self_in);
#endif // PYBRTC_H_
This diff is collapsed.
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2015 Daniel Campora
*
* 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.
*/
/******************************************************************************
DECLARE EXPORTED DATA
******************************************************************************/
extern const mp_obj_type_t pyb_timer_type;
/******************************************************************************
DECLARE PUBLIC FUNCTIONS
******************************************************************************/
void timer_init0 (void);
void timer_disable_all (void);
......@@ -101,6 +101,7 @@ STATIC void UART0IntHandler(void);
STATIC void UART1IntHandler(void);
STATIC void uart_callback_enable (mp_obj_t self_in);
STATIC void uart_callback_disable (mp_obj_t self_in);
STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in);
/******************************************************************************
DEFINE PRIVATE TYPES
......@@ -124,7 +125,8 @@ struct _pyb_uart_obj_t {
/******************************************************************************
DECLARE PRIVATE DATA
******************************************************************************/
STATIC pyb_uart_obj_t pyb_uart_obj[PYB_NUM_UARTS];
STATIC pyb_uart_obj_t pyb_uart_obj[PYB_NUM_UARTS] = {{.reg = UARTA0_BASE, .peripheral = PRCM_UARTA0},
{.reg = UARTA1_BASE, .peripheral = PRCM_UARTA1}};
STATIC const mp_cb_methods_t uart_cb_methods;
/******************************************************************************
......@@ -208,20 +210,19 @@ mp_obj_t uart_callback_new (pyb_uart_obj_t *self, mp_obj_t handler, uint rxbuffe
return _callback;
}
void uart_disable_all (void) {
for (int i = 0; i < PYB_NUM_UARTS; i++) {
// in case it's not clocked
MAP_PRCMPeripheralClkEnable(pyb_uart_obj[i].peripheral, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
pyb_uart_deinit(&pyb_uart_obj[i]);
}
}
/******************************************************************************
DEFINE PRIVATE FUNCTIONS
******************************************************************************/
// assumes init parameters have been set up correctly
STATIC void uart_init (pyb_uart_obj_t *self) {
if (self->uart_id == PYB_UART_0) {
self->reg = UARTA0_BASE;
self->peripheral = PRCM_UARTA0;
}
else {
self->reg = UARTA1_BASE;
self->peripheral = PRCM_UARTA1;
}
// Enable the peripheral clock
MAP_PRCMPeripheralClkEnable(self->peripheral, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
......@@ -457,6 +458,7 @@ STATIC mp_obj_t pyb_uart_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t
pyb_uart_obj_t *self = &pyb_uart_obj[uart_id];
self->base.type = &pyb_uart_type;
self->uart_id = uart_id;
if (n_args > 1 || n_kw > 0) {
// start the peripheral
mp_map_t kw_args;
......@@ -474,7 +476,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_init_obj, 1, pyb_uart_init);
/// \method deinit()
/// Turn off the UART bus.
mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
pyb_uart_obj_t *self = self_in;
// unregister it with the sleep module
......
......@@ -38,12 +38,12 @@ typedef struct _pyb_uart_obj_t pyb_uart_obj_t;
extern const mp_obj_type_t pyb_uart_type;
void uart_init0(void);
mp_obj_t pyb_uart_deinit(mp_obj_t self_in);
bool uart_rx_any(pyb_uart_obj_t *uart_obj);
int uart_rx_char(pyb_uart_obj_t *uart_obj);
bool uart_tx_char(pyb_uart_obj_t *self, int c);
bool uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len);
void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len);
mp_obj_t uart_callback_new (pyb_uart_obj_t *self, mp_obj_t handler, uint rxbuffer_size, mp_int_t priority);
void uart_disable_all (void);
#endif // PYBUART_H_
......@@ -139,6 +139,7 @@ extern const struct _mp_obj_module_t mp_module_network;
mp_obj_list_t mod_network_nic_list; \
mp_obj_list_t pybsleep_obj_list; \
mp_obj_list_t mpcallback_obj_list; \
mp_obj_list_t pyb_timer_channel_obj_list; \
// type definitions for the specific machine
......
......@@ -63,6 +63,7 @@
#include "pybsd.h"
#include "pins.h"
#include "pybsleep.h"
#include "pybtimer.h"
#include "mpcallback.h"
/******************************************************************************
......@@ -124,6 +125,7 @@ soft_reset:
mperror_init0();
uart_init0();
pin_init0();
timer_init0();
readline_init0();
mod_network_init0();
#if MICROPY_HW_ENABLE_RNG
......@@ -242,15 +244,23 @@ soft_reset_exit:
// soft reset
pybsleep_signal_soft_reset();
mp_printf(&mp_plat_print, "PYB: soft reboot\n");
// disable all peripherals that could trigger a callback
pyb_rtc_callback_disable(NULL);
timer_disable_all();
uart_disable_all();
// flush the serial flash buffer
sflash_disk_flush();
#if MICROPY_HW_HAS_SDCARD
pybsd_deinit();
#endif
// wait for pending transactions to complete
HAL_Delay(20);
goto soft_reset;
}
......
......@@ -235,7 +235,7 @@ Q(network)
Q(route)
Q(start_server)
Q(stop_server)
Q(server_enabled)
Q(server_running)
Q(server_login)
// for WLAN class
......@@ -325,3 +325,28 @@ Q(send_recv)
Q(ACTIVE_LOW)
Q(ACTIVE_HIGH)
// for Timer class
Q(Timer)
Q(TimerChannel)
Q(init)
Q(deinit)
Q(freq)
Q(mode)
Q(width)
Q(channel)
Q(polarity)
Q(duty_cycle)
Q(time)
Q(event_count)
Q(event_time)
Q(A)
Q(B)
Q(AB)
Q(ONE_SHOT)
Q(PERIODIC)
Q(EDGE_COUNT)
Q(EDGE_TIME)
Q(PWM)
Q(POSITIVE)
Q(NEGATIVE)
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