Edison MCU Project
 All Files Functions Typedefs Macros Pages
Macros | Typedefs | Functions
mcu_api.h File Reference

Intel MCU API definition. More...

Go to the source code of this file.

Macros

#define DBG_FATAL   1
 
#define DBG_ERROR   2
 
#define DBG_WARNING   3
 
#define DBG_INFO   4
 
#define DBG_DEBUG   5
 
#define IRQ_NONE   0
 
#define IRQ_HANDLED   1
 

Typedefs

typedef int(* irq_handler_t )(int irq)
 

Functions

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,...)
 

Detailed Description

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.

Macro Definition Documentation

#define DBG_DEBUG   5

Definition at line 42 of file mcu_api.h.

#define DBG_ERROR   2

Definition at line 39 of file mcu_api.h.

#define DBG_FATAL   1

Definition at line 38 of file mcu_api.h.

#define DBG_INFO   4

Definition at line 41 of file mcu_api.h.

#define DBG_WARNING   3

Definition at line 40 of file mcu_api.h.

#define IRQ_HANDLED   1

Definition at line 72 of file mcu_api.h.

#define IRQ_NONE   0

Definition at line 71 of file mcu_api.h.

Typedef Documentation

typedef int(* irq_handler_t)(int irq)

ISR handler definition

Parameters
irqinterrupt request number
Returns
return IRQ_HANDLED after irq handled

Definition at line 78 of file mcu_api.h.

Function Documentation

int api_version ( )

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
levelone of DBG_XXX defined above
fmtformat string
int gpio_read ( int  gpio)

Read the value of one GPIO port

Parameters
gpiothe 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
gpiothe GPIO port number
int_mode0 for falling edge and 1 for rising edge
fnthe ISR handler
Returns
0 if successful
void gpio_setup ( int  gpio,
int  direction 
)

Setup the direction of one GPIO port

Parameters
gpiothe GPIO port number
direction0 for input and 1 for output
void gpio_write ( int  gpio,
int  val 
)

Write the value of one GPIO port

Parameters
gpiothe GPIO port number to be written
valthe 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
bufthe buffer point to contain the data
lengthsize of buffer
Returns
size of data that received
int host_send ( unsigned char *  buf,
int  length 
)

Send raw data to host

Parameters
bufthe buffer point that contains the data
lengthsize of buffer
Returns
0 if successful
Note
  1. The maximum value of buffer length is 255.
  2. 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
addrI2C device address
regregister address
bufthe buffer point to contain the data
lensize 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
addrI2C device address
regregister address
bufthe buffer point that contains the data
lensize of buffer
Returns
0 if successful
int mcu_delay ( int  delay_us)

Pause the application for a period of time

Parameters
delay_usthe 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
ticksone 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
bufthe buffer point to contain the data
sizesize of buffer
fmtformat 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
portPWM port(0 - 3)
duty_nsactive pulse duration of the PWM waveform, in nanosecond
period_nsthe 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
portPWM port(0 - 3)
Returns
0 if successful
int pwm_enable ( unsigned char  port)

Enable the output of PWM

Parameters
portPWM port(0 - 3)
Returns
0 if successful
unsigned long time_ms ( )

Get the number of milliseconds since the MCU boots up.

Parameters
N/A
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
N/A
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
portuart port(1 or 2)
bufthe buffer point to contain the data
lensize of buffer to be read
Returns
0 if successful
int uart_setup ( unsigned char  port,
int  baudrate 
)

Setup the baud rate of UART

Parameters
portuart port(1 or 2)
baudratethe 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
portuart port(1 or 2)
bufthe buffer point that contains the data
lensize of buffer
Returns
0 if successful