Intel MCU API definition.
More...
Go to the source code of this file.
|
| int | api_version () |
| |
| int | gpio_read (int gpio) |
| |
| void | gpio_write (int gpio, int val) |
| |
| void | gpio_setup (int gpio, int direction) |
| |
| int | gpio_register_interrupt (int gpio, int int_mode, irq_handler_t fn) |
| |
| int | uart_setup (unsigned char port, int baudrate) |
| |
| int | uart_read (unsigned char port, unsigned char *buf, unsigned char len) |
| |
| int | uart_write (unsigned char port, unsigned char *buf, unsigned char len) |
| |
| int | pwm_configure (unsigned char port, int duty_ns, int period_ns) |
| |
| int | pwm_enable (unsigned char port) |
| |
| int | pwm_disable (unsigned char port) |
| |
| int | i2c_read (unsigned char addr, unsigned char reg, unsigned char *buf, int len) |
| |
| int | i2c_write (unsigned char addr, unsigned char reg, unsigned char *buf, int len) |
| |
| void | mcu_sleep (int ticks) |
| |
| int | mcu_delay (int delay_us) |
| |
| unsigned long | time_ms () |
| |
| unsigned long | time_us () |
| |
| int | host_send (unsigned char *buf, int length) |
| |
| int | host_receive (unsigned char *buf, int length) |
| |
| void | debug_print (int level, const char *fmt,...) |
| |
| int | mcu_snprintf (char *buf, unsigned int size, const char *fmt,...) |
| |
Intel MCU API definition.
User can utilize these APIs to control devices that connected with MCU and to communicate with host.
Definition in file mcu_api.h.
| typedef int(* irq_handler_t)(int irq) |
ISR handler definition
- Parameters
-
| irq | interrupt request number |
- Returns
- return IRQ_HANDLED after irq handled
Definition at line 78 of file mcu_api.h.
Get API version
- Returns
- 100 multiples major version number plus minor version number
| void debug_print |
( |
int |
level, |
|
|
const char * |
fmt, |
|
|
|
... |
|
) |
| |
Print the debug message to debug console
- Parameters
-
| level | one of DBG_XXX defined above |
| fmt | format string |
| int gpio_read |
( |
int |
gpio | ) |
|
Read the value of one GPIO port
- Parameters
-
| gpio | the GPIO port number to be read |
- Returns
- the value of the GPIO port. 0 if low voltage and 1 if high voltage
| int gpio_register_interrupt |
( |
int |
gpio, |
|
|
int |
int_mode, |
|
|
irq_handler_t |
fn |
|
) |
| |
Register on ISR for one GPIO port
- Parameters
-
| gpio | the GPIO port number |
| int_mode | 0 for falling edge and 1 for rising edge |
| fn | the ISR handler |
- Returns
- 0 if successful
| void gpio_setup |
( |
int |
gpio, |
|
|
int |
direction |
|
) |
| |
Setup the direction of one GPIO port
- Parameters
-
| gpio | the GPIO port number |
| direction | 0 for input and 1 for output |
| void gpio_write |
( |
int |
gpio, |
|
|
int |
val |
|
) |
| |
Write the value of one GPIO port
- Parameters
-
| gpio | the GPIO port number to be written |
| val | the value to be written. 0 for low voltage and 1 for high voltage |
| int host_receive |
( |
unsigned char * |
buf, |
|
|
int |
length |
|
) |
| |
Receive raw data from host
- Parameters
-
| buf | the buffer point to contain the data |
| length | size of buffer |
- Returns
- size of data that received
| int host_send |
( |
unsigned char * |
buf, |
|
|
int |
length |
|
) |
| |
Send raw data to host
- Parameters
-
| buf | the buffer point that contains the data |
| length | size of buffer |
- Returns
- 0 if successful
- Note
- The maximum value of buffer length is 255.
- Every host_send call will trigger an interrupt to host CPU. So do NOT call it very frequently.
| int i2c_read |
( |
unsigned char |
addr, |
|
|
unsigned char |
reg, |
|
|
unsigned char * |
buf, |
|
|
int |
len |
|
) |
| |
Read the value of one I2C device's register
- Parameters
-
| addr | I2C device address |
| reg | register address |
| buf | the buffer point to contain the data |
| len | size of buffer |
- Returns
- 0 if successful
| int i2c_write |
( |
unsigned char |
addr, |
|
|
unsigned char |
reg, |
|
|
unsigned char * |
buf, |
|
|
int |
len |
|
) |
| |
Write the value of one I2C device's register
- Parameters
-
| addr | I2C device address |
| reg | register address |
| buf | the buffer point that contains the data |
| len | size of buffer |
- Returns
- 0 if successful
| int mcu_delay |
( |
int |
delay_us | ) |
|
Pause the application for a period of time
- Parameters
-
| delay_us | the number of microsecond to pause |
- Note
- This API does not make application sleep. Always call mcu_sleep() if application need sleep for more than one tick (10 ms).
- Returns
- 0 if successful
| void mcu_sleep |
( |
int |
ticks | ) |
|
Make application sleep
- Parameters
-
| ticks | one tick is 10 ms for Intel MCU |
| int mcu_snprintf |
( |
char * |
buf, |
|
|
unsigned int |
size, |
|
|
const char * |
fmt, |
|
|
|
... |
|
) |
| |
A simplified version of snprintf
- Note
- only %d, %x, %s are supported
- Parameters
-
| buf | the buffer point to contain the data |
| size | size of buffer |
| fmt | format string |
- Returns
- the number of characters that have been written
| int pwm_configure |
( |
unsigned char |
port, |
|
|
int |
duty_ns, |
|
|
int |
period_ns |
|
) |
| |
Configure the parameters of PWM port
- Parameters
-
| port | PWM port(0 - 3) |
| duty_ns | active pulse duration of the PWM waveform, in nanosecond |
| period_ns | the whole period of the PWM waveform, in nanosecond. The period value should be between 104 and 218453000 according to the SoC spec. |
- Returns
- 0 if successful
| int pwm_disable |
( |
unsigned char |
port | ) |
|
Disable the output of PWM
- Parameters
-
- Returns
- 0 if successful
| int pwm_enable |
( |
unsigned char |
port | ) |
|
Enable the output of PWM
- Parameters
-
- Returns
- 0 if successful
| unsigned long time_ms |
( |
| ) |
|
Get the number of milliseconds since the MCU boots up.
- Parameters
-
- Returns
- the number of milliseconds
- Note
- This number will overflow (go back to zero) after around 1193 hours.
| unsigned long time_us |
( |
| ) |
|
Get the number of microseconds since the MCU boots up.
- Parameters
-
- Returns
- the number of microseconds
- Note
- This number will overflow (go back to zero) after around 71 minutes.
| int uart_read |
( |
unsigned char |
port, |
|
|
unsigned char * |
buf, |
|
|
unsigned char |
len |
|
) |
| |
Read the input from UART
- Parameters
-
| port | uart port(1 or 2) |
| buf | the buffer point to contain the data |
| len | size of buffer to be read |
- Returns
- 0 if successful
| int uart_setup |
( |
unsigned char |
port, |
|
|
int |
baudrate |
|
) |
| |
Setup the baud rate of UART
- Parameters
-
| port | uart port(1 or 2) |
| baudrate | the baud rate to be set. It can be one of below: 115200 | 57600 | 38400 | 28800 | 19200 | 14400 | 9600 | 7200 | 4800 |
- Returns
- 0 if successful
| int uart_write |
( |
unsigned char |
port, |
|
|
unsigned char * |
buf, |
|
|
unsigned char |
len |
|
) |
| |
Write one buffer to UART
- Parameters
-
| port | uart port(1 or 2) |
| buf | the buffer point that contains the data |
| len | size of buffer |
- Returns
- 0 if successful