Commit d226dd2f authored by danicampora's avatar danicampora
Browse files

cc3200: Add preliminary low power deep sleep support.

parent 0475de13
......@@ -94,6 +94,7 @@ APP_MODS_SRC_C = $(addprefix mods/,\
pybpin.c \
pybrtc.c \
pybsd.c \
pybsleep.c \
pybsystick.c \
pybuart.c \
pybwdt.c \
......
......@@ -34,14 +34,21 @@
#include "py/obj.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "pin.h"
#include "gpio.h"
#include "pybpin.h"
#define PIN(p_pin_name, p_port, p_bit, p_pin_num) \
{ \
{ &pin_type }, \
.name = MP_QSTR_ ## p_pin_name, \
.port = PORT_A ## p_port, \
.bit = (p_bit), \
.pin_num = (p_pin_num) \
.name = MP_QSTR_ ## p_pin_name, \
.port = PORT_A ## p_port, \
.type = PIN_TYPE_STD, \
.bit = (p_bit), \
.pin_num = (p_pin_num), \
.af = PIN_MODE_0, \
.strength = PIN_STRENGTH_4MA, \
.mode = GPIO_DIR_MODE_IN, \
.used = false \
}
......@@ -38,7 +38,7 @@
///
/// This module provides network drivers and routing configuration.
void mod_network_init(void) {
void mod_network_init0(void) {
mp_obj_list_init(&MP_STATE_PORT(mod_network_nic_list), 0);
}
......
......@@ -70,7 +70,7 @@ typedef struct _mod_network_socket_obj_t {
extern const mod_network_nic_type_t mod_network_nic_type_wlan;
void mod_network_init(void);
void mod_network_init0(void);
void mod_network_register_nic(mp_obj_t nic);
mp_obj_t mod_network_find_nic(const uint8_t *ip);
......
......@@ -42,6 +42,7 @@
#include "rom_map.h"
#include "interrupt.h"
#include "pin.h"
#include "gpio.h"
#include "prcm.h"
#include "adc.h"
#include "pybadc.h"
......@@ -117,7 +118,7 @@ STATIC mp_obj_t adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw,
self->num = num;
// configure the pin in analog mode
pin_config (pin, 0, 0, PIN_TYPE_ANALOG, PIN_STRENGTH_2MA);
pin_config ((pin_obj_t *)pin, PIN_MODE_0, GPIO_DIR_MODE_IN, PYBPIN_ANALOG_TYPE, PIN_STRENGTH_2MA);
// enable the ADC channel
MAP_ADCChannelEnable(ADC_BASE, channel);
......
......@@ -303,7 +303,7 @@ extint_obj_t* extint_register(mp_obj_t pin_obj, uint32_t intmode, uint32_t pull,
self->callback = NULL;
// before enabling the interrupt, configure the gpio pin
pin_config(pin, PIN_MODE_0, GPIO_DIR_MODE_IN, pull, PIN_STRENGTH_4MA);
pin_config ((pin_obj_t *)pin, PIN_MODE_0, GPIO_DIR_MODE_IN, pull, PIN_STRENGTH_4MA);
MAP_GPIOIntTypeSet(pin->port, pin->bit, intmode);
switch (pin->port) {
......
......@@ -42,6 +42,7 @@
#include "prcm.h"
#include "gpio.h"
#include "pybpin.h"
#include "pybsleep.h"
#include "mpexception.h"
......@@ -78,7 +79,13 @@
/// 2. Supply a string which matches a CPU pin name
/// 3. Provide a pin number
STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
STATIC void pin_obj_configure (const pin_obj_t *self);
void pin_init0(void) {
}
// C API used to convert a user-supplied pin name into an ordinal pin number.
......@@ -116,11 +123,26 @@ void pin_verify_af (uint af) {
}
}
void pin_config(const pin_obj_t *self, uint af, uint mode, uint type, uint strength) {
void pin_config (pin_obj_t *self, uint af, uint mode, uint type, uint strength) {
// configure the pin in analog mode
((pin_obj_t *)self)->af = af;
((pin_obj_t *)self)->mode = mode;
((pin_obj_t *)self)->type = type;
((pin_obj_t *)self)->strength = strength;
pin_obj_configure ((const pin_obj_t *)self);
// mark the pin as used
((pin_obj_t *)self)->used = true;
// register it with the sleep module
pybsleep_add (self, (WakeUpCB_t)pin_obj_configure);
}
STATIC void pin_obj_configure (const pin_obj_t *self) {
// Skip all this if the pin is to be used in analog mode
if (type != PIN_TYPE_ANALOG) {
// PIN_MODE_0 means it stays as a Pin, else, another peripheral will take control of it
if (af == PIN_MODE_0) {
if (self->type != PYBPIN_ANALOG_TYPE) {
// verify the alternate function
pin_verify_af (self->af);
// PIN_MODE_0 means it stays as a pin, else, another peripheral will take control of it
if (self->af == PIN_MODE_0) {
// enable the peripheral clock for the GPIO port of this pin
switch (self->port) {
case PORT_A0:
......@@ -139,14 +161,12 @@ void pin_config(const pin_obj_t *self, uint af, uint mode, uint type, uint stren
break;
}
// configure the direction
MAP_GPIODirModeSet(self->port, self->bit, mode);
MAP_GPIODirModeSet(self->port, self->bit, self->mode);
}
// verify the alternate function
pin_verify_af (af);
// now set the alternate function, strenght and type
MAP_PinModeSet (self->pin_num, af);
MAP_PinModeSet (self->pin_num, self->af);
}
MAP_PinConfigSet(self->pin_num, strength, type);
MAP_PinConfigSet(self->pin_num, self->strength, self->type);
}
/// \method print()
......@@ -201,8 +221,6 @@ STATIC void pin_print(void (*print)(void *env, const char *fmt, ...), void *env,
print(env, ", strength=Pin.%s)", qstr_str(str_qst));
}
STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
/// \classmethod \constructor(id, ...)
/// Create a new Pin object associated with the id. If additional arguments are given,
/// they are used to initialise the pin. See `init`.
......@@ -280,7 +298,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, con
}
// configure the pin as requested
pin_config (self, af, mode, type, strength);
pin_config ((pin_obj_t *)self, af, mode, type, strength);
return mp_const_none;
}
......
......@@ -30,12 +30,19 @@
#include MICROPY_PIN_DEFS_PORT_H
#define PYBPIN_ANALOG_TYPE 0xFF
typedef struct {
mp_obj_base_t base;
qstr name;
uint32_t port;
uint32_t bit : 8;
uint32_t pin_num : 7;
uint16_t type;
uint8_t bit;
uint8_t pin_num;
uint8_t af;
uint8_t strength;
uint8_t mode;
bool used;
} pin_obj_t;
extern const mp_obj_type_t pin_type;
......@@ -58,7 +65,7 @@ MP_DECLARE_CONST_FUN_OBJ(pin_init_obj);
void pin_init0(void);
void pin_verify_af (uint af);
void pin_config(const pin_obj_t *self, uint af, uint mode, uint type, uint strength);
void pin_config(pin_obj_t *self, uint af, uint mode, uint type, uint strength);
const pin_obj_t *pin_find(mp_obj_t user_obj);
const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
const pin_obj_t *pin_find_pin(const mp_obj_dict_t *named_pins, uint pin_num);
......
......@@ -138,7 +138,7 @@ STATIC mp_obj_t pybsd_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_
// card detect pin was provided
if (n_args == 7) {
pybsd_obj.pin_sd_detect = (pin_obj_t *)pin_find(args[6]);
pin_config(pybsd_obj.pin_sd_detect, PIN_MODE_0, GPIO_DIR_MODE_IN, PIN_TYPE_STD_PU, PIN_STRENGTH_4MA);
pin_config (pybsd_obj.pin_sd_detect, PIN_MODE_0, GPIO_DIR_MODE_IN, PIN_TYPE_STD_PU, PIN_STRENGTH_4MA);
}
pybsd_obj.pinsset = true;
}
......
This diff is collapsed.
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* 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.
*/
#ifndef PYBSLEEP_H_
#define PYBSLEEP_H_
typedef void (*WakeUpCB_t)(mp_obj_t self);
void pyblsleep_init0 (void);
void pybsleep_add (mp_obj_t obj, WakeUpCB_t wakeup);
void pybsleep_remove (mp_obj_t obj);
void pybsleep_wakeup (void);
#endif /* PYBSLEEP_H_ */
......@@ -46,6 +46,7 @@
#include "uart.h"
#include "pybuart.h"
#include "pybioctl.h"
#include "pybsleep.h"
#include "mpexception.h"
#include "py/mpstate.h"
#include "osi.h"
......@@ -181,6 +182,8 @@ bool uart_init2(pyb_uart_obj_t *self) {
self->enabled = true;
// register it with the sleep module
pybsleep_add (self, (WakeUpCB_t)uart_init2);
return true;
}
......@@ -512,6 +515,8 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
return mp_const_none;
}
// unregister it with the sleep module
pybsleep_remove (self);
self->enabled = false;
MAP_UARTIntDisable(self->reg, UART_INT_RX | UART_INT_RT);
MAP_UARTIntClear(self->reg, UART_INT_RX | UART_INT_RT);
......
......@@ -123,6 +123,7 @@ extern const struct _mp_obj_module_t mp_module_network;
mp_obj_list_t pyb_extint_list; \
mp_obj_list_t pyb_uart_list; \
mp_obj_list_t mod_network_nic_list; \
mp_obj_list_t pybsleep_obj_list; \
// type definitions for the specific machine
......
......@@ -60,6 +60,7 @@
#include "pybi2c.h"
#include "pybsd.h"
#include "pins.h"
#include "pybsleep.h"
/******************************************************************************
DECLARE PRIVATE CONSTANTS
......@@ -141,13 +142,14 @@ soft_reset:
mperror_init0();
mpexception_init0();
pyblsleep_init0();
uart_init0();
pin_init0();
// configure stdio uart pins with the correct af
// param 3 ("mode") is DON'T CARE" for AFs others than GPIO
pin_config(&pin_GPIO1, PIN_MODE_3, 0, PIN_TYPE_STD, PIN_STRENGTH_2MA);
pin_config(&pin_GPIO2, PIN_MODE_3, 0, PIN_TYPE_STD, PIN_STRENGTH_2MA);
pin_config ((pin_obj_t *)&pin_GPIO1, PIN_MODE_3, 0, PIN_TYPE_STD, PIN_STRENGTH_2MA);
pin_config ((pin_obj_t *)&pin_GPIO2, PIN_MODE_3, 0, PIN_TYPE_STD, PIN_STRENGTH_2MA);
// Instantiate the stdio uart
mp_obj_t args[2] = {
mp_obj_new_int(MICROPY_STDIO_UART),
......@@ -157,7 +159,7 @@ soft_reset:
readline_init0();
extint_init0();
mod_network_init();
mod_network_init0();
wlan_init0();
#if MICROPY_HW_ENABLE_RNG
rng_init0();
......
Markdown is supported
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