2014-12-22 12:35:05 +01:00
|
|
|
// Platform-specific functions
|
|
|
|
|
|
|
|
#ifndef __PLATFORM_H__
|
|
|
|
#define __PLATFORM_H__
|
|
|
|
|
|
|
|
#include "cpu_esp8266.h"
|
|
|
|
|
|
|
|
#include "c_types.h"
|
|
|
|
#include "driver/pwm.h"
|
2016-12-11 20:35:04 +01:00
|
|
|
#include "driver/uart.h"
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
#include "task/task.h"
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
// Error / status codes
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PLATFORM_ERR,
|
|
|
|
PLATFORM_OK,
|
|
|
|
PLATFORM_UNDERFLOW = -1
|
|
|
|
};
|
|
|
|
|
|
|
|
// Platform initialization
|
|
|
|
int platform_init(void);
|
|
|
|
void platform_int_init(void);
|
|
|
|
|
|
|
|
// ****************************************************************************
|
|
|
|
// KEY_LED functions
|
|
|
|
uint8_t platform_key_led( uint8_t level);
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// GPIO subsection
|
|
|
|
#define PLATFORM_GPIO_FLOAT 0
|
|
|
|
#define PLATFORM_GPIO_PULLUP 1
|
|
|
|
|
|
|
|
#define PLATFORM_GPIO_INT 2
|
|
|
|
#define PLATFORM_GPIO_OUTPUT 1
|
2016-03-10 22:55:44 +01:00
|
|
|
#define PLATFORM_GPIO_OPENDRAIN 3
|
2014-12-22 12:35:05 +01:00
|
|
|
#define PLATFORM_GPIO_INPUT 0
|
|
|
|
|
|
|
|
#define PLATFORM_GPIO_HIGH 1
|
|
|
|
#define PLATFORM_GPIO_LOW 0
|
|
|
|
|
2016-02-28 20:48:41 +01:00
|
|
|
typedef uint32_t (* platform_hook_function)(uint32_t bitmask);
|
|
|
|
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
static inline int platform_gpio_exists( unsigned pin ) { return pin < NUM_GPIO; }
|
2014-12-22 12:35:05 +01:00
|
|
|
int platform_gpio_mode( unsigned pin, unsigned mode, unsigned pull );
|
|
|
|
int platform_gpio_write( unsigned pin, unsigned level );
|
|
|
|
int platform_gpio_read( unsigned pin );
|
2016-02-28 20:48:41 +01:00
|
|
|
|
|
|
|
// Note that these functions will not be compiled in unless GPIO_INTERRUPT_ENABLE and
|
|
|
|
// GPIO_INTERRUPT_HOOK_ENABLE are defined.
|
|
|
|
int platform_gpio_register_intr_hook(uint32_t gpio_bits, platform_hook_function hook);
|
|
|
|
#define platform_gpio_unregister_intr_hook(hook) \
|
|
|
|
platform_gpio_register_intr_hook(0, hook);
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
void platform_gpio_intr_init( unsigned pin, GPIO_INT_TYPE type );
|
2016-02-28 20:48:41 +01:00
|
|
|
void platform_gpio_init( task_handle_t gpio_task );
|
2014-12-22 12:35:05 +01:00
|
|
|
// *****************************************************************************
|
|
|
|
// Timer subsection
|
|
|
|
|
|
|
|
// Timer data type
|
|
|
|
typedef uint32_t timer_data_type;
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// CAN subsection
|
|
|
|
|
|
|
|
// Maximum length for any CAN message
|
|
|
|
#define PLATFORM_CAN_MAXLEN 8
|
|
|
|
|
|
|
|
// eLua CAN ID types
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ELUA_CAN_ID_STD = 0,
|
|
|
|
ELUA_CAN_ID_EXT
|
|
|
|
};
|
|
|
|
|
2016-03-02 03:55:21 +01:00
|
|
|
static inline int platform_can_exists( unsigned id ) { return NUM_CAN && (id < NUM_CAN); }
|
2014-12-22 12:35:05 +01:00
|
|
|
uint32_t platform_can_setup( unsigned id, uint32_t clock );
|
|
|
|
int platform_can_send( unsigned id, uint32_t canid, uint8_t idtype, uint8_t len, const uint8_t *data );
|
|
|
|
int platform_can_recv( unsigned id, uint32_t *canid, uint8_t *idtype, uint8_t *len, uint8_t *data );
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// SPI subsection
|
|
|
|
|
|
|
|
// There are 4 "virtual" SPI ports (SPI0...SPI3).
|
|
|
|
#define PLATFORM_SPI_TOTAL 4
|
|
|
|
// TODO: PLATFORM_SPI_TOTAL is not used - figure out purpose, or remove?
|
|
|
|
|
|
|
|
// SPI mode
|
|
|
|
#define PLATFORM_SPI_MASTER 1
|
|
|
|
#define PLATFORM_SPI_SLAVE 0
|
|
|
|
// SS values
|
|
|
|
#define PLATFORM_SPI_SELECT_ON 1
|
|
|
|
#define PLATFORM_SPI_SELECT_OFF 0
|
|
|
|
// SPI enable/disable
|
|
|
|
#define PLATFORM_SPI_ENABLE 1
|
|
|
|
#define PLATFORM_SPI_DISABLE 0
|
2015-01-16 21:41:34 +01:00
|
|
|
// SPI clock phase
|
|
|
|
#define PLATFORM_SPI_CPHA_LOW 0
|
|
|
|
#define PLATFORM_SPI_CPHA_HIGH 1
|
|
|
|
// SPI clock polarity
|
|
|
|
#define PLATFORM_SPI_CPOL_LOW 0
|
|
|
|
#define PLATFORM_SPI_CPOL_HIGH 1
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
|
|
|
|
// Data types
|
|
|
|
typedef uint32_t spi_data_type;
|
|
|
|
|
|
|
|
// The platform SPI functions
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
static inline int platform_spi_exists( unsigned id ) { return id < NUM_SPI; }
|
2015-10-27 23:30:33 +01:00
|
|
|
uint32_t platform_spi_setup( uint8_t id, int mode, unsigned cpol, unsigned cpha, uint32_t clock_div);
|
2015-10-11 13:42:03 +02:00
|
|
|
int platform_spi_send( uint8_t id, uint8_t bitlen, spi_data_type data );
|
2015-10-25 22:58:06 +01:00
|
|
|
spi_data_type platform_spi_send_recv( uint8_t id, uint8_t bitlen, spi_data_type data );
|
2014-12-22 12:35:05 +01:00
|
|
|
void platform_spi_select( unsigned id, int is_select );
|
|
|
|
|
2016-09-05 20:17:13 +02:00
|
|
|
int platform_spi_blkwrite( uint8_t id, size_t len, const uint8_t *data );
|
|
|
|
int platform_spi_blkread( uint8_t id, size_t len, uint8_t *data );
|
2015-10-08 23:13:31 +02:00
|
|
|
int platform_spi_transaction( uint8_t id, uint8_t cmd_bitlen, spi_data_type cmd_data,
|
|
|
|
uint8_t addr_bitlen, spi_data_type addr_data,
|
2015-10-27 23:30:33 +01:00
|
|
|
uint16_t mosi_bitlen, uint8_t dummy_bitlen, int16_t miso_bitlen );
|
2015-10-08 23:13:31 +02:00
|
|
|
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
// *****************************************************************************
|
|
|
|
// UART subsection
|
|
|
|
|
|
|
|
// There are 3 "virtual" UART ports (UART0...UART2).
|
|
|
|
#define PLATFORM_UART_TOTAL 3
|
|
|
|
// TODO: PLATFORM_UART_TOTAL is not used - figure out purpose, or remove?
|
|
|
|
// Note: Some CPUs (e.g. LM4F/TM4C) have more than 3 hardware UARTs
|
|
|
|
|
|
|
|
// Parity
|
|
|
|
enum
|
|
|
|
{
|
2015-12-14 20:17:04 +01:00
|
|
|
PLATFORM_UART_PARITY_NONE = 0,
|
|
|
|
PLATFORM_UART_PARITY_EVEN = 1,
|
|
|
|
PLATFORM_UART_PARITY_ODD = 2,
|
|
|
|
PLATFORM_UART_PARITY_MARK = 3,
|
|
|
|
PLATFORM_UART_PARITY_SPACE = 4
|
2014-12-22 12:35:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Stop bits
|
|
|
|
enum
|
|
|
|
{
|
2015-12-14 20:17:04 +01:00
|
|
|
PLATFORM_UART_STOPBITS_1 = 1,
|
|
|
|
PLATFORM_UART_STOPBITS_2 = 2,
|
|
|
|
PLATFORM_UART_STOPBITS_1_5 = 3
|
2014-12-22 12:35:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Flow control types (this is a bit mask, one can specify PLATFORM_UART_FLOW_RTS | PLATFORM_UART_FLOW_CTS )
|
|
|
|
#define PLATFORM_UART_FLOW_NONE 0
|
|
|
|
#define PLATFORM_UART_FLOW_RTS 1
|
|
|
|
#define PLATFORM_UART_FLOW_CTS 2
|
|
|
|
|
|
|
|
// The platform UART functions
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
static inline int platform_uart_exists( unsigned id ) { return id < NUM_UART; }
|
2014-12-22 12:35:05 +01:00
|
|
|
uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int parity, int stopbits );
|
|
|
|
int platform_uart_set_buffer( unsigned id, unsigned size );
|
|
|
|
void platform_uart_send( unsigned id, uint8_t data );
|
|
|
|
void platform_s_uart_send( unsigned id, uint8_t data );
|
|
|
|
int platform_uart_recv( unsigned id, unsigned timer_id, timer_data_type timeout );
|
|
|
|
int platform_s_uart_recv( unsigned id, timer_data_type timeout );
|
|
|
|
int platform_uart_set_flow_control( unsigned id, int type );
|
|
|
|
int platform_s_uart_set_flow_control( unsigned id, int type );
|
2016-01-20 09:37:03 +01:00
|
|
|
void platform_uart_alt( int set );
|
2016-12-11 20:35:04 +01:00
|
|
|
void platform_uart_get_config(unsigned id, uint32_t *baudp, uint32_t *databitsp, uint32_t *parityp, uint32_t *stopbitsp);
|
2014-12-22 12:35:05 +01:00
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// PWM subsection
|
|
|
|
|
|
|
|
// There are 16 "virtual" PWM channels (PWM0...PWM15)
|
|
|
|
#define PLATFORM_PWM_TOTAL 16
|
|
|
|
// TODO: PLATFORM_PWM_TOTAL is not used - figure out purpose, or remove?
|
|
|
|
|
|
|
|
#define NORMAL_PWM_DEPTH PWM_DEPTH
|
|
|
|
#define NORMAL_DUTY(d) (((unsigned)(d)*NORMAL_PWM_DEPTH) / PWM_DEPTH)
|
|
|
|
#define DUTY(d) ((uint16_t)( ((unsigned)(d)*PWM_DEPTH) / NORMAL_PWM_DEPTH) )
|
|
|
|
|
|
|
|
// The platform PWM functions
|
2016-03-02 03:55:21 +01:00
|
|
|
void platform_pwm_init( void );
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
static inline int platform_pwm_exists( unsigned id ) { return ((id < NUM_PWM) && (id > 0)); }
|
2014-12-22 12:35:05 +01:00
|
|
|
uint32_t platform_pwm_setup( unsigned id, uint32_t frequency, unsigned duty );
|
|
|
|
void platform_pwm_close( unsigned id );
|
2016-02-18 03:07:33 +01:00
|
|
|
bool platform_pwm_start( unsigned id );
|
2014-12-22 12:35:05 +01:00
|
|
|
void platform_pwm_stop( unsigned id );
|
|
|
|
uint32_t platform_pwm_set_clock( unsigned id, uint32_t data );
|
|
|
|
uint32_t platform_pwm_get_clock( unsigned id );
|
|
|
|
uint32_t platform_pwm_set_duty( unsigned id, uint32_t data );
|
|
|
|
uint32_t platform_pwm_get_duty( unsigned id );
|
|
|
|
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// The platform ADC functions
|
|
|
|
|
|
|
|
// Functions requiring platform-specific implementation
|
|
|
|
int platform_adc_update_sequence(void);
|
|
|
|
int platform_adc_start_sequence(void);
|
|
|
|
void platform_adc_stop( unsigned id );
|
|
|
|
uint32_t platform_adc_set_clock( unsigned id, uint32_t frequency);
|
|
|
|
int platform_adc_check_timer_id( unsigned id, unsigned timer_id );
|
|
|
|
|
|
|
|
// ADC Common Functions
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
static inline int platform_adc_exists( unsigned id ) { return id < NUM_ADC; }
|
2014-12-22 12:35:05 +01:00
|
|
|
uint32_t platform_adc_get_maxval( unsigned id );
|
|
|
|
uint32_t platform_adc_set_smoothing( unsigned id, uint32_t length );
|
|
|
|
void platform_adc_set_blocking( unsigned id, uint32_t mode );
|
|
|
|
void platform_adc_set_freerunning( unsigned id, uint32_t mode );
|
|
|
|
uint32_t platform_adc_is_done( unsigned id );
|
|
|
|
void platform_adc_set_timer( unsigned id, uint32_t timer );
|
|
|
|
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
// ****************************************************************************
|
|
|
|
// OneWire functions
|
|
|
|
|
|
|
|
static inline int platform_ow_exists( unsigned id ) { return ((id < NUM_OW) && (id > 0)); }
|
|
|
|
|
|
|
|
// ****************************************************************************
|
|
|
|
// Timer functions
|
|
|
|
|
|
|
|
static inline int platform_tmr_exists( unsigned id ) { return id < NUM_TMR; }
|
|
|
|
|
2016-01-31 21:48:59 +01:00
|
|
|
// *****************************************************************************
|
|
|
|
// Sigma-Delta platform interface
|
|
|
|
|
|
|
|
// ****************************************************************************
|
|
|
|
// Sigma-Delta functions
|
|
|
|
|
|
|
|
static inline int platform_sigma_delta_exists( unsigned id ) {return ((id < NUM_GPIO) && (id > 0)); }
|
|
|
|
uint8_t platform_sigma_delta_setup( uint8_t pin );
|
|
|
|
uint8_t platform_sigma_delta_close( uint8_t pin );
|
|
|
|
void platform_sigma_delta_set_pwmduty( uint8_t duty );
|
|
|
|
void platform_sigma_delta_set_prescale( uint8_t prescale );
|
|
|
|
void platform_sigma_delta_set_target( uint8_t target );
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
// *****************************************************************************
|
|
|
|
// I2C platform interface
|
|
|
|
|
|
|
|
// I2C speed
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PLATFORM_I2C_SPEED_SLOW = 100000,
|
I2C sw driver with support of multiple buses, Slow, Fast, FastPlus, and user-defined speed selection (#2465)
* I2C driver speed-up, i2c.SLOW, i2c.FAST and user-defined speed selection
* - Multiple buses (up to 10) with different speeds on each bus
- Standard(Slow, 100kHz), Fast(400kHz) and FastPlus(1MHz) modes or an
arbitrary clock speed
- Sharing SDA line over multiple I²C buses to save available pins
- GPIO16 pin can be used as SCL pin, but it does not support clock
stretching and selected bus will be limited to FAST speed.
* Dynamic memory allocation, error checks, simplification, timing tweaks.
* Separated the code of old driver for better compatibility and simplicity
* Change of driver interface
* Add bus status check in setup(); simplify getDC(); remove unnesessary lines in ACK read/write
* Fix for moved doc file and trailing whitespaces
2019-04-05 06:56:11 +02:00
|
|
|
PLATFORM_I2C_SPEED_FAST = 400000,
|
|
|
|
PLATFORM_I2C_SPEED_FASTPLUS = 1000000
|
2014-12-22 12:35:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// I2C direction
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PLATFORM_I2C_DIRECTION_TRANSMITTER,
|
|
|
|
PLATFORM_I2C_DIRECTION_RECEIVER
|
|
|
|
};
|
|
|
|
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
#ifdef NUM_I2C
|
|
|
|
static inline int platform_i2c_exists( unsigned id ) { return id < NUM_I2C; }
|
|
|
|
#else
|
|
|
|
static inline int platform_i2c_exists( unsigned id ) { return 0; }
|
|
|
|
#endif
|
2014-12-22 12:35:05 +01:00
|
|
|
uint32_t platform_i2c_setup( unsigned id, uint8_t sda, uint8_t scl, uint32_t speed );
|
I2C sw driver with support of multiple buses, Slow, Fast, FastPlus, and user-defined speed selection (#2465)
* I2C driver speed-up, i2c.SLOW, i2c.FAST and user-defined speed selection
* - Multiple buses (up to 10) with different speeds on each bus
- Standard(Slow, 100kHz), Fast(400kHz) and FastPlus(1MHz) modes or an
arbitrary clock speed
- Sharing SDA line over multiple I²C buses to save available pins
- GPIO16 pin can be used as SCL pin, but it does not support clock
stretching and selected bus will be limited to FAST speed.
* Dynamic memory allocation, error checks, simplification, timing tweaks.
* Separated the code of old driver for better compatibility and simplicity
* Change of driver interface
* Add bus status check in setup(); simplify getDC(); remove unnesessary lines in ACK read/write
* Fix for moved doc file and trailing whitespaces
2019-04-05 06:56:11 +02:00
|
|
|
bool platform_i2c_configured( unsigned id );
|
2014-12-22 12:35:05 +01:00
|
|
|
void platform_i2c_send_start( unsigned id );
|
|
|
|
void platform_i2c_send_stop( unsigned id );
|
|
|
|
int platform_i2c_send_address( unsigned id, uint16_t address, int direction );
|
|
|
|
int platform_i2c_send_byte( unsigned id, uint8_t data );
|
|
|
|
int platform_i2c_recv_byte( unsigned id, int ack );
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// Ethernet specific functions
|
|
|
|
|
|
|
|
void platform_eth_send_packet( const void* src, uint32_t size );
|
|
|
|
uint32_t platform_eth_get_packet_nb( void* buf, uint32_t maxlen );
|
|
|
|
void platform_eth_force_interrupt(void);
|
|
|
|
uint32_t platform_eth_get_elapsed_time(void);
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// Internal flash erase/write functions
|
|
|
|
|
|
|
|
uint32_t platform_flash_get_first_free_block_address( uint32_t *psect );
|
|
|
|
uint32_t platform_flash_get_sector_of_address( uint32_t addr );
|
|
|
|
uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size );
|
|
|
|
uint32_t platform_flash_read( void *to, uint32_t fromaddr, uint32_t size );
|
|
|
|
uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t size );
|
|
|
|
uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size );
|
|
|
|
uint32_t platform_flash_get_num_sectors(void);
|
|
|
|
int platform_flash_erase_sector( uint32_t sector_id );
|
|
|
|
|
2015-12-08 00:25:05 +01:00
|
|
|
/**
|
|
|
|
* Translated a mapped address to a physical flash address, based on the
|
2018-06-22 23:29:16 +02:00
|
|
|
* current flash cache mapping, and v.v.
|
2015-12-08 00:25:05 +01:00
|
|
|
* @param mapped_addr Address to translate (>= INTERNAL_FLASH_MAPPED_ADDRESS)
|
|
|
|
* @return the corresponding physical flash address, or -1 if flash cache is
|
|
|
|
* not currently active.
|
|
|
|
* @see Cache_Read_Enable.
|
|
|
|
*/
|
|
|
|
uint32_t platform_flash_mapped2phys (uint32_t mapped_addr);
|
2018-06-22 23:29:16 +02:00
|
|
|
uint32_t platform_flash_phys2mapped (uint32_t phys_addr);
|
2019-04-05 17:01:45 +02:00
|
|
|
uint32_t platform_flash_get_partition (uint32_t part_id, uint32_t *addr);
|
2015-12-08 00:25:05 +01:00
|
|
|
|
2016-01-20 09:37:03 +01:00
|
|
|
// *****************************************************************************
|
|
|
|
// Other glue
|
|
|
|
|
|
|
|
int platform_ow_exists( unsigned id );
|
|
|
|
int platform_gpio_exists( unsigned id );
|
2016-01-22 00:55:57 +01:00
|
|
|
int platform_tmr_exists( unsigned id );
|
2016-01-20 09:37:03 +01:00
|
|
|
|
2015-12-13 03:29:37 +01:00
|
|
|
// *****************************************************************************
|
2017-03-01 12:42:20 +01:00
|
|
|
|
|
|
|
void* platform_print_deprecation_note( const char *msg, const char *time_frame);
|
|
|
|
|
2015-12-13 03:29:37 +01:00
|
|
|
// Helper macros
|
|
|
|
#define MOD_CHECK_ID( mod, id )\
|
|
|
|
if( !platform_ ## mod ## _exists( id ) )\
|
|
|
|
return luaL_error( L, #mod" %d does not exist", ( unsigned )id )
|
|
|
|
|
|
|
|
#define MOD_CHECK_TIMER( id )\
|
|
|
|
if( id == PLATFORM_TIMER_SYS_ID && !platform_timer_sys_available() )\
|
|
|
|
return luaL_error( L, "the system timer is not available on this platform" );\
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
if( !platform_tmr_exists( id ) )\
|
2015-12-13 03:29:37 +01:00
|
|
|
return luaL_error( L, "timer %d does not exist", ( unsigned )id )\
|
|
|
|
|
|
|
|
#define MOD_CHECK_RES_ID( mod, id, resmod, resid )\
|
|
|
|
if( !platform_ ## mod ## _check_ ## resmod ## _id( id, resid ) )\
|
|
|
|
return luaL_error( L, #resmod" %d not valid with " #mod " %d", ( unsigned )resid, ( unsigned )id )
|
|
|
|
|
2019-05-01 19:29:11 +02:00
|
|
|
// *****************************************************************************
|
|
|
|
// Reboot config page
|
|
|
|
/*
|
|
|
|
* The 4K flash page in the linker section .irom0.ptable (offset 0x10000) is used
|
|
|
|
* for configuration changes that persist across reboots. This 4k page contains a
|
|
|
|
* sequence of records that are written using flash NAND writing rules. See the
|
|
|
|
* header app/spiffs/spiffs_nucleus.h for a discussion of how SPIFFS uses these. A
|
|
|
|
* similar technique is used here.
|
|
|
|
*
|
|
|
|
* Each record is word aligned and the first two bytes of the record are its size
|
|
|
|
* and record type. Type 0xFF means unused and type 0x00 means deleted. New
|
|
|
|
* records can be added by overwriting the first unused slot. Records can be
|
|
|
|
* replaced by adding the new version, then setting the type of the previous version
|
|
|
|
* to deleted. This all works and can be implemented with platform_s_flash_write()
|
|
|
|
* upto the 4K limit.
|
|
|
|
*
|
|
|
|
* If a new record cannot fit into the page then the deleted records are GCed by
|
|
|
|
* copying the active records into a RAM scratch pad, erasing the page and writing
|
|
|
|
* them back. Yes, this is powerfail unsafe for a few mSec, but this is no worse
|
|
|
|
* than writing to SPIFFS and won't even occur in normal production use.
|
|
|
|
*/
|
|
|
|
#define IROM_PTABLE_ATTR __attribute__((section(".irom0.ptable")))
|
|
|
|
#define PLATFORM_PARTITION(n) (SYSTEM_PARTITION_CUSTOMER_BEGIN + n)
|
|
|
|
#define PLATFORM_RCR_DELETED 0x0
|
|
|
|
#define PLATFORM_RCR_PT 0x1
|
|
|
|
#define PLATFORM_RCR_PHY_DATA 0x2
|
|
|
|
#define PLATFORM_RCR_REFLASH 0x3
|
|
|
|
#define PLATFORM_RCR_FREE 0xFF
|
|
|
|
typedef union {
|
|
|
|
uint32_t hdr;
|
|
|
|
struct { uint8_t len,id; };
|
|
|
|
} platform_rcr_t;
|
|
|
|
|
|
|
|
uint32_t platform_rcr_read (uint8_t rec_id, void **rec);
|
|
|
|
uint32_t platform_rcr_write (uint8_t rec_id, const void *rec, uint8_t size);
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
#endif
|