Library for AdvaBoard RPi1
Version: | 2014-06-25 |
---|---|
Status: | beta |
SeeAlso: | AdvaBoard RPi1 documentation, am_rpi.c/.h |
Note: | If you want to access the AdvaBoard RPi1, better only use the functions in this library and do not access the Raspberry Pi directly. |
Author: | Advamation, Roland Koebler (support@advamation.de) |
Copyright: | (c) Advamation (info@advamation.de) |
License: | open-source / MIT |
RCS: | am_rpi_advaboard.c,v 1.36 2014/06/26 13:00:37 rk Exp |
Table of contents
- 1 init / exit / logging
- 2 basic / low-level access to the AdvaBoard RPi1
- 2.1 F912: communicate with AdvaBoard RPi1 - F912 microcontroller
- 2.2 F912: check command-status
- 2.3 F912: manually lock AdvaBoard RPi1 - F912 microcontroller
- 2.4 F912: manually unlock AdvaBoard RPi1 - F912 microcontroller
- 2.5 F912: set auto-locking-timeout
- 2.6 F353: communicate with AdvaBoard RPi1 - F353 microcontroller
- 2.7 F353: check command-status
- 2.8 F353: manually lock AdvaBoard RPi1 - F353 microcontroller
- 2.9 F353: manually unlock AdvaBoard RPi1 - F353 microcontroller
- 2.10 F353: set auto-locking-timeout
- 2.11 CPLD: communicate with AdvaBoard RPi1 - CPLD
- 2.12 GPIOs: write Raspberry Pi GPIOs
- 2.13 GPIOs: read Raspberry Pi GPIOs
- 2.14 SPI: set clock
- 2.15 SPI: set clock-phase/-polarity
- 2.16 SPI: set MUX
- 2.17 SPI: communicate
- 2.18 SPI: manually lock
- 2.19 SPI: manually unlock
- 2.20 SPI: set auto-locking-timeout
- 2.21 I2C: communicate
- 2.22 I2C: set clock
- 2.23 I2C: manually lock
- 2.24 I2C: manually unlock
- 2.25 I2C: set auto-locking-timeout
- 3 AdvaBoard RPi1 functions
- 3.1 system information
- 3.2 Status
- 3.3 Power-Management
- 3.4 RTC
- 3.5 I/O
- 3.5.1 I/O-configuration: configure digital-I/Os 0.4..0.7
- 3.5.2 I/O-configuration: read configuration of digital-I/Os 0.4..0.7
- 3.5.3 I/O-configuration: configure digital-I/Os 1.0..1.7
- 3.5.4 I/O-configuration: read configuration of digital-I/Os 1.0..1.7
- 3.5.5 digital-I/O: read status
- 3.5.6 digital-I/O: control digital-I/Os / events
- 3.5.7 digital-I/O: write outputs
- 3.5.8 digital-I/O: read I/Os 0.4..0.7
- 3.5.9 digital-I/O: read all I/Os
- 3.5.10 digital-I/O: set an output-pin to high
- 3.5.11 digital-I/O: clear an output-pin to low
- 3.5.12 digital-I/O: get level of a I/O-pin
- 3.5.13 analog-I/O: read status
- 3.5.14 analog-I/O, PWM: control analog-I/Os / PWM
- 3.5.15 analog-in: read analog-inputs
- 3.5.16 analog-in: read a single analog-input
- 3.5.17 analog-out: write analog-outputs
- 3.5.18 analog-out: read analog-outputs
- 3.5.19 analog-out: write a single analog-output
- 3.5.20 analog-out: read a single analog-output
- 3.5.21 PWM: configure PWM-clock
- 3.5.22 PWM: read PWM-clock
- 3.5.23 PWM: set PWM-value
- 3.5.24 PWM: read a PWM-value
- 3.5.25 PWM: read PWM-values
- 3.6 event-based automation
- 3.6.1 power-management / RTC (eventpwr)
- 3.6.1.1 read event-handler-flags
- 3.6.1.2 clear event-handler-flags
- 3.6.1.3 trigger event-handler
- 3.6.1.4 handler: configure digital-outputs
- 3.6.1.5 handler: read digital-output-configuration
- 3.6.1.6 handler: configure analog-control
- 3.6.1.7 handler: read analog-control-configuration
- 3.6.1.8 handler: configure power-on/off
- 3.6.1.9 handler: read power-on/off-configuration
- 3.6.1.10 event: define handler for I2C-interrupt
- 3.6.1.11 event: read handler for I2C-interrupt
- 3.6.1.12 event: define RTC-alarm
- 3.6.1.13 event: define RTC-alarm and activate it
- 3.6.1.14 event: read RTC-alarm
- 3.6.2 I/O (eventio)
- 3.6.2.1 read event-handler-flags
- 3.6.2.2 clear event-handler-flags
- 3.6.2.3 trigger event-handler
- 3.6.2.4 handler: configure digital-outputs
- 3.6.2.5 handler: read digital-output-configuration
- 3.6.2.6 handler: configure digital-control
- 3.6.2.7 handler: read digital-control-configuration
- 3.6.2.8 event: configure event
- 3.6.2.9 event: read event-configuration
- 3.6.1 power-management / RTC (eventpwr)
- 3.7 EEPROM
- 3.8 E-SPI-interface
- 3.9 I2C-interface
- 3.9.1 communicate with I2C-devices
- 3.9.2 communication with I2C-devices with the Advamation RS-485-/I2C-protocol
- 3.9.3 set I2C-clock
- 3.9.4 read I2C-/SMBus-interrupt
- 3.9.5 clear I2C-INT-pin of F912
- 3.9.6 manually lock I2C
- 3.9.7 manually unlock I2C
- 3.9.8 set I2C auto-locking-timeout
- 3.9.9 I2C-clock-stretching: configure
- 3.9.10 I2C-clock-stretching: read configured delay
- 3.9.11 I2C-clock-stretching: configure injection
- 3.9.12 I2C-clock-stretching: read configured injection
- 3.10 RS-232 / RS-485
- 3.11 misc
1 init / exit / logging
1.1 init library, Raspberry Pi and AdvaBoard RPi1
Init the library, check and init the Raspberry Pi, GPIO pins, I2C, SPI and AdvaBoard RPi1.
Does nothing (except incrementing the init-counter) if it already has been called before. am_rpi_advaboard_init() and am_rpi_advaboard_exit() must always be called pairwise.
Usage: | AM_ERROR am_rpi_advaboard_init() |
---|---|
Returns: | 0 on success, <0 on error |
SeeAlso: | am_rpi.h |
1.2 exit library
De-initialize the library. Must be used for every successful call of am_rpi_advaboard_init().
Usage: | void am_rpi_advaboard_exit(void) |
---|
1.3 configure logging
All messages up to "level" are printed and/or stored in the logfile. DEBUG/INFO are printed to stdout, MESSAGE/WARNING/CRITICAL/ERROR are printed to stderr.
The available levels are:
- AM_LOG_LEVEL_DEBUG
- AM_LOG_LEVEL_INFO
- AM_LOG_LEVEL_MESSAGE
- AM_LOG_LEVEL_WARNING (default)
- AM_LOG_LEVEL_CRITICAL
- AM_LOG_LEVEL_ERROR
Usage: | AM_ERROR am_rpi_advaboard_logging(enum am_log_level level, char const *logfile, enum am_log_level logfile_level) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error (AM_ERROR_INVALID_ARGUMENT, AM_ERROR_IO if the logfile cannot be opened (see errno for details)) |
SeeAlso: | am_logging |
2 basic / low-level access to the AdvaBoard RPi1
Basic functions to access the AdvaBoard RPi1.
These functions can be used to access all functions of the AdvaBoard RPi1. But they are rather low-level, so better look at the higher-level-functions in the next sections.
SeeAlso: | AdvaBoard RPi1 documentation |
---|
2.1 F912: communicate with AdvaBoard RPi1 - F912 microcontroller
Communicate with the SiLabs C8051F912-microcontroller (power-controller) of the AdvaBoard RPi1 (incl. locking).
Usage: | AM_ERROR am_rpi_advaboard_f912_comm(enum am_cmd cmd, unsigned int txlen, char const *txdata, unsigned int rxlen, unsigned int *received_len, char *rxdata) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_COMM_TOOSHORT if received_len<rxlen, <0 on error |
SeeAlso: | AdvaBoard RPi1 documentation, Advamation RS485-/I2C-protocol, advamation.h, am_rpi_i2c_prot() in am_rpi.c/.h |
2.2 F912: check command-status
Check if the commands, sent to the SiLabs C8051F912-microcontroller (power-controller) of the AdvaBoard RPi1, were completely processed.
Usage: | AM_ERROR am_rpi_advaboard_f912_cmdstatus(uint8_t *status) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_NOT_IMPLEMENTED, <0 on error |
Note: | This is only supported if the AdvaBoard RPi1-firmware is >= 20140219. For older firmware, AM_ERROR_NOT_IMPLEMENTED is returned. |
SeeAlso: | AdvaBoard RPi1 documentation, Advamation RS485-/I2C-protocol |
2.3 F912: manually lock AdvaBoard RPi1 - F912 microcontroller
Manually lock the SiLabs C8051F912-microcontroller (power-controller) of the AdvaBoard RPi1 for several communications.
Note that you additionally have to use a mutex, if you're accessing I2C from several threads in the same program.
Usage: | AM_ERROR am_rpi_advaboard_f912_lock(int32_t timeout_ms) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_BUSY after timeout |
2.4 F912: manually unlock AdvaBoard RPi1 - F912 microcontroller
Unlock the F912 again after am_rpi_advaboard_f912_lock(). This has to be used for every successful call to am_rpi_advaboard_f912_lock().
Usage: | void am_rpi_advaboard_f912_unlock(void) |
---|
2.5 F912: set auto-locking-timeout
Set timeout, after which F912-communication-functions return AM_ERROR_BUSY if they cannot lock the F912.
Usage: | void am_rpi_advaboard_f912_locking_timeout(uint16_t timeout_ms) |
---|---|
Parameters: |
|
2.6 F353: communicate with AdvaBoard RPi1 - F353 microcontroller
Communicate with the SiLabs C8051F353-microcontroller (I/O-controller) of the AdvaBoard RPi1 (incl. locking).
Usage: | AM_ERROR am_rpi_advaboard_f353_comm(enum am_cmd cmd, unsigned int txlen, char const *txdata, unsigned int rxlen, unsigned int *received_len, char *rxdata) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_COMM_TOOSHORT if received_len<rxlen, <0 on error |
SeeAlso: | AdvaBoard RPi1 documentation, Advamation RS485-/I2C-protocol, advamation.h, am_rpi_i2c_prot() in am_rpi.c/.h |
2.7 F353: check command-status
Check if the commands, sent to the SiLabs C8051F353-microcontroller (I/O-controller) of the AdvaBoard RPi1, were completely processed.
Usage: | AM_ERROR am_rpi_advaboard_f353_cmdstatus(uint8_t *status) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_NOT_IMPLEMENTED, <0 on error |
Note: | This is only supported if the AdvaBoard RPi1-firmware is >= 20140219. For older firmware, AM_ERROR_NOT_IMPLEMENTED is returned. |
SeeAlso: | AdvaBoard RPi1 documentation, Advamation RS485-/I2C-protocol |
2.8 F353: manually lock AdvaBoard RPi1 - F353 microcontroller
Manually lock the SiLabs C8051F353-microcontroller (I/O-controller) of the AdvaBoard RPi1 for several communications.
Note that you additionally have to use a mutex, if you're accessing I2C from several threads in the same program.
Usage: | AM_ERROR am_rpi_advaboard_f353_lock(int32_t timeout_ms) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_BUSY after timeout |
2.9 F353: manually unlock AdvaBoard RPi1 - F353 microcontroller
Unlock the F353 again after am_rpi_advaboard_f353_lock(). This has to be used for every successful call to am_rpi_advaboard_f353_lock().
Usage: | void am_rpi_advaboard_f353_unlock(void) |
---|
2.10 F353: set auto-locking-timeout
Set timeout, after which F353-communication-functions return AM_ERROR_BUSY if they cannot lock the F353.
Usage: | void am_rpi_advaboard_f353_locking_timeout(uint16_t timeout_ms) |
---|---|
Parameters: |
|
2.11 CPLD: communicate with AdvaBoard RPi1 - CPLD
Write/read registers of the Xilinx CPLD of the AdvaBoard RPi1.
Usage: | AM_ERROR am_rpi_advaboard_cpldreg(unsigned int len, char const *tx, char *rx) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
SeeAlso: | AdvaBoard RPi1 documentation, am_rpi_spi_comm() |
2.12 GPIOs: write Raspberry Pi GPIOs
Set/clear Raspberry Pi GPIOs, which are connected to the AdvaBoard RPi1.
Valid GPIOs:
- ADVABOARD_RPi_SEL0 (E-SPI SEL0)
- ADVABOARD_RPi_SEL1 (E-SPI SEL1)
- ADVABOARD_RPi_SEL2 (E-SPI SEL2)
- ADVABOARD_RPi_SEL3 (E-SPI SEL3)
- ADVABOARD_RPi_PWM (I/O 1.0)
- ADVABOARD_LCD_RS
Usage: | AM_ERROR am_rpi_advaboard_gpio_write(uint32_t gpios, bool level) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_INVALID_ARGUMENT on error |
SeeAlso: | AdvaBoard RPi1 documentation |
2.13 GPIOs: read Raspberry Pi GPIOs
Read Raspberry Pi GPIOs, which are connected to the AdvaBoard RPi1.
Usual GPIOs:
- ADVABOARD_I2C_INT
- ADVABOARD_TP_INT
- ADVABOARD_RPi_PWM
- ADVABOARD_RPi_SEL0
- ADVABOARD_RPi_SEL1
- ADVABOARD_RPi_SEL2
- ADVABOARD_RPi_SEL3
- ADVABOARD_SPI_MISO
Usage: | uint32_t am_rpi_advaboard_gpio_read(uint32_t gpios) |
---|---|
Parameters: |
|
Returns: | current input levels, masked by gpios |
SeeAlso: | AdvaBoard RPi1 documentation |
2.14 SPI: set clock
Set the SPI-clock.
Usage: | AM_ERROR am_rpi_advaboard_spi_clk(enum am_rpi_spi_clk clkdiv) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_INVALID_ARGUMENT on error |
Note: | SPI-speed is 250 MHz / clkdiv |
SeeAlso: | am_rpi.c/.h, especially enum am_rpi_spi_clk, am_rpi_spi_clk() |
2.15 SPI: set clock-phase/-polarity
Set the SPI-clock-phase and -polarity.
The possible clock-phases and -polarities are:
- SPI_CLK_IDLELOW_SHIFTFALLING_READRISING
- SPI_CLK_IDLELOW_SHIFTRISING_READFALLING
- SPI_CLK_IDLEHIGH_SHIFTRISING_READFALLING (default)
- SPI_CLK_IDLEHIGH_SHIFTFALLING_READRISING
Usage: | AM_ERROR am_rpi_advaboard_spi_clkcfg(enum am_rpi_spi_clkcfg clkcfg) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_INVALID_ARGUMENT on error |
SeeAlso: | am_rpi.c/.h, especially enum am_rpi_spi_clkcfg, am_rpi_spi_config() |
2.16 SPI: set MUX
Set SPI-multiplexer of the AdvaBoard RPi1 (without locking!).
Usage: | AM_ERROR am_rpi_advaboard_spi_mux(int mux) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
2.17 SPI: communicate
This is a low-level-function. If you want to communicate with E-SPI-devices, which are connected to the AdvaBoard RPi1, use am_rpi_advaboard_espi() instead.
Usage: | AM_ERROR am_rpi_advaboard_spi_comm(unsigned int len, char const *txdata, char *rxdata) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_INVALID_ARGUMENT on error |
SeeAlso: | am_rpi.c/.h, especially am_rpi_spi_comm() |
2.18 SPI: manually lock
Manually lock SPI for several subsequent communications.
Note that you additionally have to use a mutex, if you're accessing the SPI from several threads in the same program.
Usage: | AM_ERROR am_rpi_advaboard_spi_lock(int32_t timeout_ms) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_BUSY after timeout |
SeeAlso: | am_rpi.c/.h, especially am_rpi_spi_lock() |
2.19 SPI: manually unlock
Unlock SPI again after am_rpi_advaboard_spi_lock(). This has to be used for every successful call to am_rpi_advaboard_spi_lock().
Usage: | void am_rpi_advaboard_spi_unlock(void) |
---|---|
SeeAlso: | am_rpi.c/.h, especially am_rpi_spi_unlock() |
2.20 SPI: set auto-locking-timeout
Set timeout, after which SPI-communication-functions return AM_ERROR_BUSY if they cannot lock the SPI.
Usage: | void am_rpi_advaboard_spi_locking_timeout(uint16_t timeout_ms) |
---|---|
Parameters: |
|
SeeAlso: | am_rpi.c/.h, especially am_rpi_spi_locking_timeout() |
2.21 I2C: communicate
This is a low-level-function. If you want to communicate with I2C-devices, which are connected to the AdvaBoard RPi1, use am_rpi_advaboard_i2c() instead.
Usage: | AM_ERROR am_rpi_advaboard_rpii2c_comm(uint8_t address, uint16_t txlen, char const *txdata, uint16_t rxlen, char *rxdata) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
SeeAlso: | am_rpi.c/.h, especially am_rpi_i2c_write_read() |
2.22 I2C: set clock
Set the I2C-clock.
Usage: | AM_ERROR am_rpi_advaboard_rpii2c_clk(enum am_rpi_i2c_clk clkdiv) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_INVALID_ARGUMENT on error |
Note: | The I2C core clock is 250 MHz; default-clkdiv is 1500 (166.7kHz). (The Raspberry Pi datasheet is wrong, here.) |
SeeAlso: | am_rpi.c/.h, especially enum am_rpi_i2c_clk, am_rpi_i2c_clk() |
2.23 I2C: manually lock
Manually lock I2C for several communications.
Note that you additionally have to use a mutex, if you're accessing the I2C from several threads in the same program.
Usage: | AM_ERROR am_rpi_advaboard_rpii2c_lock(int32_t timeout_ms) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_BUSY after timeout |
SeeAlso: | am_rpi.c/.h, especially am_rpi_i2c_lock() |
2.24 I2C: manually unlock
Unlock I2C again after am_rpi_advaboard_i2c_lock(). This must be used for every successful call to am_rpi_advaboard_rpii2c_lock().
Usage: | void am_rpi_advaboard_rpii2c_unlock(void) |
---|---|
SeeAlso: | am_rpi.c/.h, especially am_rpi_i2c_unlock() |
2.25 I2C: set auto-locking-timeout
Set timeout, after which I2C-communication-functions return AM_ERROR_BUSY if they cannot lock the I2C.
Usage: | void am_rpi_advaboard_rpii2c_locking_timeout(uint16_t timeout_ms) |
---|---|
Parameters: |
|
SeeAlso: | am_rpi.c/.h, especially am_rpi_i2c_locking_timeout() |
3 AdvaBoard RPi1 functions
All AdvaBoard-functionality can be accessed with the "basic/low-level" functions above. But the following functions simplify the use of the most commonly used functionality of the AdvaBoard RPi1.
3.1 system information
3.1.1 hardware/firmware information
Retrieve hardware-information from the AdvaBoard RPi1.
Usage: | AM_ERROR am_rpi_advaboard_info(char const **model, char const **rev, uint64_t *serno, char const **f912_firmware, char const **f353_firmware, unsigned int *cpld_firmware) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: |
|
3.1.2 read temperatures
Read the temperature-sensors of the microcontrollers on the AdvaBoard RPi1. Note that the returned temperatures are uncalibrated. For more precise measurements, an offset should be calibrated and added to the value.
Usage: | AM_ERROR am_rpi_advaboard_temperature_read(float *t_f912, float *t_f353) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
3.2 Status
Much of the AdvaBoard RPi1-functionality is implemented by the two microcontrollers on the AdvaBoard. The Raspberry Pi communicates with these microcontrollers via I2C, and sends commands to them, which the microcontrollers then process. Although the microcontrollers are quite fast, they need some time (usually up to a few ms) to process these commands.
For cases where it is necessary that a command is done before the next is sent (e.g. if you configure an I/O as input and then read it, you want to be sure that the input-configuration has finished before reading the I/O), it's possible to check, if the microcontrollers have finished processing the command.
3.2.1 check if a command is done
Check if a command is done, e.g. if sent output-values have reached the (hardware-)pins, if a changed I/O-configuration is active or if a manually triggered event completeted.
cmd may be one, or multiple or-combined values of:
- AM_RPI_ADVABOARD_DONE_POWER
- AM_RPI_ADVABOARD_DONE_PINS
- AM_RPI_ADVABOARD_DONE_RTC
- AM_RPI_ADVABOARD_DONE_IO_DIGITAL
- AM_RPI_ADVABOARD_DONE_IO_ANALOG
- AM_RPI_ADVABOARD_DONE_IO_PWM (alias for AM_RPI_ADVABOARD_DONE_IO_ANALOG)
- AM_RPI_ADVABOARD_DONE_EVENTPWR
- AM_RPI_ADVABOARD_DONE_EVENTIO
- AM_RPI_ADVABOARD_DONE_I2CCLKEXT
- AM_RPI_ADVABOARD_DONE_RS485CFG
- AM_RPI_ADVABOARD_DONE_LED
Usage: | int am_rpi_advaboard_done(uint16_t cmd) |
---|---|
Parameters: |
|
Returns: | 1 if done, 0 if not done, <0 on ERROR, especially AM_ERROR_NOT_IMPLEMENTED if the AdvaBoard firmware-version is too old |
Note: | This is only supported if the AdvaBoard RPi1-firmware is >= 20140219. |
3.3 Power-Management
3.3.1 read voltages
Read the power-supply-voltages of the AdvaBoard RPi1. Note that this may return arbitrary voltages for unconnected/floating pins (e.g. vbatt is only valid if a battery is connected).
Usage: | AM_ERROR am_rpi_advaboard_voltages_read(float *v5v, float *vbatt, float *vdd_f912) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
3.3.2 power-on/off
Switch power on/off of different parts of the AdvaBoard RPi1. Power-off also disables the CPLD-pins to the appropriate part.
Usage: | AM_ERROR am_rpi_advaboard_power(int pwron, int cpld_3V, int peripheral_5V, int rpi, int tft, int tft_backlight) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: |
|
SeeAlso: | event-based automation below |
3.3.3 power-on/off: read power-switches
Read the power-state.
Usage: | AM_ERROR am_rpi_advaboard_power_read(bool *pwron, bool *cpld_3V, bool *peripheral_5V, bool *rpi, bool *tft, bool *tft_backlight) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
3.3.4 CPLD-pins: enable/disable
Enable/disable the CPLD-pins to E-SPI, the Raspberry Pi and TFT-display.
They must be disabled if the appropriate part is powered-off, and must be enabled to access them when they are powered-on.
Usage: | AM_ERROR am_rpi_advaboard_pins(int espi_rs485, int rpi, int tft) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.3.5 CPLD-pins: read enabled/disabled
Read the enabled-state of the CPLD-pins to E-SPI, the Raspberry Pi and the TFT-Display.
Usage: | AM_ERROR am_rpi_advaboard_pins_read(bool *espi_rs485, bool *rpi, bool *tft) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
3.3.6 TFT-backlight: write PWM
Set PWM for tft_backlight. This modifies the brightness of the backlight of the 3.2" TFT-display, and should be 0xFF for other displays.
Usage: | AM_ERROR am_rpi_advaboard_power_tftblpwm(uint8_t pwm) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.3.7 TFT-backlight: read PWM
Read PWM of tft_backlight.
Usage: | AM_ERROR am_rpi_advaboard_power_tftblpwm_read(uint8_t *pwm) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.4 RTC
The initial time of the RTC (in seconds) is 0x10000000 (268435456).
It's also possible to set the RTC to smaller values but this should not be done if alarms are used, since alarms < 0x10000000 are interpreted as relative to the current time, and then relative_alarm + current_time would still be < 0x10000000 and be interpreted as relative alarm, again.
The time is usually interpreted as seconds since the epoch (01.01.1970).
3.4.1 read RTC-status
Read the status of the real-time-clock.
bit | description | values |
---|---|---|
0 | (reserved) | |
1 | running | 0=stopped, 1=running |
2 | (reserved) | |
3 | error-flag | 0=ok, 1=RTC oscillator failure |
4 | alarm0-enabled | 0=alarm0 disabled, 1=alarm0 enabled |
5 | alarm0-flag | 0=no alarm, 1=alarm0 occurred |
6 | alarm1-enabled | 0=alarm1 disabled, 1=alarm1 enabled |
7 | alarm1-flag | 0=no alarm, 1=alarm1 occurred |
Usage: | AM_ERROR am_rpi_advaboard_rtc_status(uint8_t *status) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
SeeAlso: | AdvaBoard RPi1 documentation |
3.4.2 control RTC
Control the RTC.
control may be one, or multiple or-combined values of:
- AM_RPI_ADVABOARD_RTC_STOP
- AM_RPI_ADVABOARD_RTC_START
- AM_RPI_ADVABOARD_RTC_SET
- AM_RPI_ADVABOARD_RTC_CLRFLAGS
- AM_RPI_ADVABOARD_RTC_ALARM0_OFF
- AM_RPI_ADVABOARD_RTC_ALARM0_ON
- AM_RPI_ADVABOARD_RTC_ALARM1_OFF
- AM_RPI_ADVABOARD_RTC_ALARM1_ON
Usage: | AM_ERROR am_rpi_advaboard_rtc_control(uint8_t control) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on errno |
SeeAlso: | AdvaBoard RPi1 documentation |
3.4.3 read RTC-time
Read the current RTC-time.
Usage: | AM_ERROR am_rpi_advaboard_rtc_read(uint32_t *time, uint16_t *subseconds) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
3.4.4 write RTC-time
Write time to a RTC register, but do not yet activate it. Use AM_RPI_ADVABOARD_RTC_SET to actually set the RTC to the written time (or use am_rpi_advaboard_rtc_set()).
The initial time (at power-on) is 0x10000000. Do not set smaller times if you're using alarms.
Usage: | AM_ERROR am_rpi_advaboard_rtc_write(uint32_t time) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.4.5 set RTC-time
Set RTC (=write time to RTC-register and use AM_RPI_ADVABOARD_RTC_SET).
The initial time (at power-on) is 0x10000000. Do not set smaller times if you're using alarms.
Usage: | AM_ERROR am_rpi_advaboard_rtc_set(uint32_t time) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.5 I/O
3.5.1 I/O-configuration: configure digital-I/Os 0.4..0.7
Configure the digital-I/Os 0.4..0.7 of the AdvaBoard RPi1. These pins have a weak pullup.
Possible configurations:
- AM_INPUT: use as input
- AM_OUTPUT / AM_OUTPUT_OPENDRAIN: use as opendrain-output
- AM_OUTPUT_PUSHPULL: use as push-pull-output
Usage: | AM_ERROR am_rpi_advaboard_io0_config(enum am_config_io io4_ida0, enum am_config_io io5_ida1, enum am_config_io io6_pwm0, enum am_config_io io7_pwm1) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
SeeAlso: | see am_rpi_advaboard_analog_control() for IDA, am_rpi_advaboard_pwm_* for PWM |
3.5.2 I/O-configuration: read configuration of digital-I/Os 0.4..0.7
Read the I/O-configuration of I/Os 0.4..0.7.
Usage: | AM_ERROR am_rpi_advaboard_io0_config_read(enum am_config_io *io4_ida0, enum am_config_io *io5_ida1, enum am_config_io *io6_pwm0, enum am_config_io *io7_pwm1) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
3.5.3 I/O-configuration: configure digital-I/Os 1.0..1.7
Configure the digital-I/Os 1.0..1.7 / CPLD-I/O 0..7 of the AdvaBoard RPi1. The CPLD-inputs are special: They don't have a pullup/pulldown, but they keep their current level (low or high) until a different level is applied.
Possible configurations:
- AM_INPUT: use as input
- AM_OUTPUT: use as output
Usage: | AM_ERROR am_rpi_advaboard_io1_config(enum am_config_io cpldio0, enum am_config_io cpldio1, enum am_config_io cpldio2, enum am_config_io cpldio3, enum am_config_io cpldio4, enum am_config_io cpldio5, enum am_config_io cpldio6, enum am_config_io cpldio7) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | I/O 1.0 is special, since it can also be used as RPi-PWM-output. So, if I/O 1.0 is configured as output, the effective output-level is I/O_1.0_value AND RPi_PWM. RPi_PWM is set to high at initialization (so I/O 1.0 works as normal I/O), and can be set by am_rpi_advaboard_gpio_write(ADVABOARD_RPi_PWM, level) or by configuring the Raspberry Pi-PWM on P1-12 of the Raspberry Pi. |
3.5.4 I/O-configuration: read configuration of digital-I/Os 1.0..1.7
Read the I/O-configuration of the I/Os 1.0..1.7.
Usage: | AM_ERROR am_rpi_advaboard_io1_config_read(enum am_config_io *cpldio0, enum am_config_io *cpldio1, enum am_config_io *cpldio2, enum am_config_io *cpldio3, enum am_config_io *cpldio4, enum am_config_io *cpldio5, enum am_config_io *cpldio6, enum am_config_io *cpldio7) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
3.5.5 digital-I/O: read status
Read the status of the digital-I/Os of the AdvaBoard RPi1.
byte | bit | description | values |
---|---|---|---|
0 | 0 | CPLD-input-update | 0=update disabled, 1=update enabled |
0 | 4 | event0 enabled | 0=disabled, 1=enabled |
0 | 5 | event1 enabled | 0=disabled, 1=enabled |
0 | 6 | event2 enabled | 0=disabled, 1=enabled |
0 | 7 | event3 enabled | 0=disabled, 1=enabled |
Usage: | AM_ERROR am_rpi_advaboard_io_status(unsigned int len, char *status) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
SeeAlso: | AdvaBoard RPi1 documentation |
3.5.6 digital-I/O: control digital-I/Os / events
Control the digital-I/Os of the AdvaBoard RPi1.
control may be one, or multiple or-combined values of:
- AM_RPI_ADVABOARD_IO_CPLDINUPDATE_DISABLE
- AM_RPI_ADVABOARD_IO_CPLDINUPDATE_ENABLE
- AM_RPI_ADVABOARD_IO_EVENT0_DISABLE
- AM_RPI_ADVABOARD_IO_EVENT0_ENABLE
- AM_RPI_ADVABOARD_IO_EVENT1_DISABLE
- AM_RPI_ADVABOARD_IO_EVENT1_ENABLE
- AM_RPI_ADVABOARD_IO_EVENT2_DISABLE
- AM_RPI_ADVABOARD_IO_EVENT2_ENABLE
- AM_RPI_ADVABOARD_IO_EVENT3_DISABLE
- AM_RPI_ADVABOARD_IO_EVENT3_ENABLE
Usage: | AM_ERROR am_rpi_advaboard_io_control(uint16_t control) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on errno |
SeeAlso: | AdvaBoard RPi1 documentation |
3.5.7 digital-I/O: write outputs
Write digital-outputs.
Usage: | AM_ERROR am_rpi_advaboard_io_write(int io7654, int cpldio76543210) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: |
|
3.5.8 digital-I/O: read I/Os 0.4..0.7
Read digital-I/Os 0.4..0.7 of the AdvaBoard RPi1.
Usage: | AM_ERROR am_rpi_advaboard_io_read1(char *iovalues) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | I/O 0.4 uses bit 4 of iovalues, I/O 0.5 uses bit 5, I/O 0.6 uses bit 6, I/O 7 uses bit 7 |
3.5.9 digital-I/O: read all I/Os
Read all digital-I/Os of the AdvaBoard RPi1.
Usage: | AM_ERROR am_rpi_advaboard_io_read2(char *iovalues) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | I/O 0.4..0.7 use bit 4..7 of the 1st byte, I/O 1.0..1.7 use bit 0..7 of the 2nd byte in iovalues |
3.5.10 digital-I/O: set an output-pin to high
Set an digital-output (-> high).
Usage: | AM_ERROR am_rpi_advaboard_io_set(unsigned int i) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | If the digital-I/O is currently configured as input, only the output-buffer is set; the level is assigned to the pin, as soon as the pin is configured as output. |
3.5.11 digital-I/O: clear an output-pin to low
Clear a digital-output (-> low).
Usage: | AM_ERROR am_rpi_advaboard_io_clr(unsigned int i) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | If the digital-I/O is currently configured as input, only the output-buffer is set; the level is assigned to the pin, as soon as the pin is configured as output. |
3.5.12 digital-I/O: get level of a I/O-pin
Read the level of a digital-I/O-pin.
Usage: | int am_rpi_advaboard_io_get(unsigned int i) |
---|---|
Parameters: |
|
Returns: | 1 if high, 0 if low, <0 on error |
3.5.13 analog-I/O: read status
Read the status of the analog-I/Os of the AdvaBoard RPi1.
byte | bit | description | values |
---|---|---|---|
0 | 0 | ADC0 sampling | 0=idle, 1=currently sampling |
0 | 1 | ADC0 mode | 0=oneshot-mode, 1=continuous mode |
0 | 2 | ADC0 valid | 0=value invalid, 1=value valid |
0 | 3 | ADC0 error | 0=no error, 1=overflow/underflow occurred |
0 | 4 | ADC1 sampling | 0=idle, 1=currently sampling |
0 | 5 | ADC1 mode | 0=oneshot-mode, 1=continuous mode |
0 | 6 | ADC1 valid | 0=value invalid, 1=value valid |
0 | 7 | ADC1 error | 0=no error, 1=overflow/underflow occurred |
1 | 0 | ADC2 sampling | 0=idle, 1=currently sampling |
1 | 1 | ADC2 mode | 0=oneshot-mode, 1=continuous mode |
1 | 2 | ADC2 valid | 0=value invalid, 1=value valid |
1 | 3 | ADC2 error | 0=no error, 1=overflow/underflow occurred |
1 | 4 | ADC3 sampling | 0=idle, 1=currently sampling |
1 | 5 | ADC3 mode | 0=oneshot-mode, 1=continuous mode |
1 | 6 | ADC3 valid | 0=value invalid, 1=value valid |
1 | 7 | ADC3 error | 0=no error, 1=overflow/underflow occurred |
2 | 0 | TEMP sampling | 0=idle, 1=currently sampling |
2 | 1 | TEMP mode | 0=oneshot-mode, 1=continuous mode |
2 | 2 | TEMP valid | 0=value invalid, 1=value valid |
2 | 3 | TEMP error | 0=no error, 1=overflow/underflow occurred |
2 | 4 | IDA0 enabled | 0=disabled, 1=enabled |
2 | 5 | IDA1 enabled | 0=disabled, 1=enabled |
2 | 6 | – | |
2 | 7 | – | |
3 | 3-0 | PWM0/PCA0 mode | 0=off, 2=PWM8, 3=PWM16, 4=FREQ |
4 | 3-0 | PWM1/PCA1 mode | 0=off, 2=PWM8, 3=PWM16, 4=FREQ |
Usage: | AM_ERROR am_rpi_advaboard_analog_status(unsigned int len, char *status) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
SeeAlso: | AdvaBoard RPi1 documentation |
3.5.14 analog-I/O, PWM: control analog-I/Os / PWM
Control (=start/stop/set mode) analog-I/Os of the AdvaBoard RPi1.
control may be one, or multiple or-combined values of:
- AM_RPI_ADVABOARD_ANALOG_ADC0_STOP
- AM_RPI_ADVABOARD_ANALOG_ADC0_ONESHOT
- AM_RPI_ADVABOARD_ANALOG_ADC0_CONTINUOUS
- AM_RPI_ADVABOARD_ANALOG_ADC1_STOP
- AM_RPI_ADVABOARD_ANALOG_ADC1_ONESHOT
- AM_RPI_ADVABOARD_ANALOG_ADC1_CONTINUOUS
- AM_RPI_ADVABOARD_ANALOG_ADC2_STOP
- AM_RPI_ADVABOARD_ANALOG_ADC2_ONESHOT
- AM_RPI_ADVABOARD_ANALOG_ADC2_CONTINUOUS
- AM_RPI_ADVABOARD_ANALOG_ADC3_STOP
- AM_RPI_ADVABOARD_ANALOG_ADC3_ONESHOT
- AM_RPI_ADVABOARD_ANALOG_ADC3_CONTINUOUS
- AM_RPI_ADVABOARD_ANALOG_ADC4_STOP
- AM_RPI_ADVABOARD_ANALOG_ADC4_ONESHOT
- AM_RPI_ADVABOARD_ANALOG_ADC4_CONTINUOUS
- AM_RPI_ADVABOARD_ANALOG_IDA0_DISABLE
- AM_RPI_ADVABOARD_ANALOG_IDA0_ENABLE
- AM_RPI_ADVABOARD_ANALOG_IDA1_DISABLE
- AM_RPI_ADVABOARD_ANALOG_IDA1_ENABLE
- AM_RPI_ADVABOARD_ANALOG_PWM0_DISABLE
- AM_RPI_ADVABOARD_ANALOG_PWM0_PWM8
- AM_RPI_ADVABOARD_ANALOG_PWM0_PWM16
- AM_RPI_ADVABOARD_ANALOG_PWM0_FREQ
- AM_RPI_ADVABOARD_ANALOG_PWM1_DISABLE
- AM_RPI_ADVABOARD_ANALOG_PWM1_PWM8
- AM_RPI_ADVABOARD_ANALOG_PWM1_PWM16
- AM_RPI_ADVABOARD_ANALOG_PWM1_FREQ
Usage: | AM_ERROR am_rpi_advaboard_analog_control(uint64_t control) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on errno |
SeeAlso: | AdvaBoard RPi1 documentation |
3.5.15 analog-in: read analog-inputs
Read the analog-inputs (AIN0..3) of the AdvaBoard RPi1.
Usage: | AM_ERROR am_rpi_advaboard_analogins_read(uint16_t *ain0, uint16_t *ain1, uint16_t *ain2, uint16_t *ain3) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: |
|
3.5.16 analog-in: read a single analog-input
Read the value of a single analog-input.
Usage: | int am_rpi_advaboard_analogin_read(unsigned int i) |
---|---|
Parameters: |
|
Returns: | the value, or <0 on error |
3.5.17 analog-out: write analog-outputs
Write analog-outputs of the AdvaBoard RPi1.
Usage: | AM_ERROR am_rpi_advaboard_analogouts_write(uint8_t ida0, uint8_t ida0_scale, uint8_t ida1, uint8_t ida1_scale) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: |
|
3.5.18 analog-out: read analog-outputs
Read the analog-outputs (IDA0..1) of the AdvaBoard RPi1.
Usage: | AM_ERROR am_rpi_advaboard_analogouts_read(uint8_t *ida0, uint8_t *ida0_scale, uint8_t *ida1, uint8_t *ida1_scale) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: |
|
3.5.19 analog-out: write a single analog-output
Write a single analog-output.
Usage: | AM_ERROR am_rpi_advaboard_analogout_write(unsigned int i, uint8_t value, uint8_t scale) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | scale: 0=0..0.25mA, 1=0..0.5mA, 2=0..1.0mA, 3=0..2.0mA |
3.5.20 analog-out: read a single analog-output
Read a single analog-output.
Usage: | int am_rpi_advaboard_analogout_read(unsigned int i) |
---|---|
Parameters: |
|
Returns: | the value (bit 0..7: value, bit 8..9: scale), or <0 on error |
3.5.21 PWM: configure PWM-clock
Set the PWM-clock.
- PWM8 repeating-frequency = 95.7kHz / (clkdiv+1) / prescaler
- PWM16 repeating-frequency = 373.84Hz / (clkdiv+1) / prescaler
- FREQ frequency = 12.25MHz / (clkdiv+1) / prescaler / value, (value "0" is treated as 256)
Note that the clock has a tolerance of +-2%.
Usage: | AM_ERROR am_rpi_advaboard_pwm_clk(uint8_t clkdiv, uint8_t prescaler) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.5.22 PWM: read PWM-clock
Read the PWM-clock.
Usage: | AM_ERROR am_rpi_advaboard_pwm_clk_read(uint8_t *clkdiv, uint8_t *prescaler) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
3.5.23 PWM: set PWM-value
Set a PWM.
Usage: | AM_ERROR am_rpi_advaboard_pwm_write(unsigned int i, uint16_t value) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | The PWM-modes "PWM8" and "FREQ" only use the higher 8 bit of value. |
3.5.24 PWM: read a PWM-value
Read a PWM-value.
Usage: | int am_rpi_advaboard_pwm_read(unsigned int i) |
---|---|
Parameters: |
|
Returns: | PWM-value, or <0 on error |
3.5.25 PWM: read PWM-values
Read all PWM-values.
Usage: | AM_ERROR am_rpi_advaboard_pwms_read(uint16_t *pwm0, uint16_t *pwm1) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: |
|
3.6 event-based automation
The microcontrollers of the AdvaBoard RPi1 contain an event-based automation, so that they can react to certain events very quickly and without the Raspberry Pi. This can remove real-time-requirements from the Raspberry Pi, and simplify many tasks.
Therefore, there are configurable events (e.g. changing inputs), which can trigger an event-handler; for every handler, the actions (e.g. set outputs) can be configured.
The AdvaBoard RPi1 has two such event-based automation systems:
- eventpwr: switch power on/off, start Raspberry Pi etc. on RTC-alarms or I2C-interrupts
- eventio: set/clear digital-output-pins on digital-input-changes
SeeAlso: | AdvaBoard RPi1 documentation |
---|
3.6.1 power-management / RTC (eventpwr)
Events:
- reset, always triggers handler 0
- 5V-power-supply off / switch to battery, always triggers handler 1
- 5V-power-supply on, always triggers handler 2
- RTC alarm 0
- RTC alarm 1
- I2C interrupt
Handlers:
- 8 configurable handlers (0..7)
Actions:
- set power-outputs
- set I2C-interrupt
- control analog-I/O
3.6.1.1 read event-handler-flags
Read event-handler-flags. Every time an event-handler is triggered, its flag is set. The handlers 0..7 use the bits 0..7 of flags.
Usage: | AM_ERROR am_rpi_advaboard_eventpwr_flags(uint8_t *flags) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.6.1.2 clear event-handler-flags
Clear some event-handler-flags.
Usage: | AM_ERROR am_rpi_advaboard_eventpwr_clear(uint8_t flags) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.6.1.3 trigger event-handler
Manually trigger an event-handler.
Usage: | AM_ERROR am_rpi_advaboard_eventpwr_trigger(unsigned int handler_pwr) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.6.1.4 handler: configure digital-outputs
Define which outputs should be set/cleared by an event-handler.
Usage: | AM_ERROR am_rpi_advaboard_eventpwr_output_write(unsigned int handler_pwr, uint8_t mask0, uint8_t output0) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
SeeAlso: | am_rpi_advaboard_eventpwr_power_write() |
3.6.1.5 handler: read digital-output-configuration
Read which outputs are set/cleared by an event-handler.
Usage: | AM_ERROR am_rpi_advaboard_eventpwr_output_read(unsigned int handler_pwr, uint8_t *mask0, uint8_t *output0) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
SeeAlso: | am_rpi_advaboard_eventpwr_power_read() |
3.6.1.6 handler: configure analog-control
Define which analog-controls should be executed by an event-handler.
Usage: | AM_ERROR am_rpi_advaboard_eventpwr_analogcontrol_write(unsigned int handler_pwr, uint8_t analogcontrol0, uint8_t analogcontrol1, uint8_t analogcontrol2) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: |
|
3.6.1.7 handler: read analog-control-configuration
Read which analog-controls are executed by an event-handler.
Usage: | AM_ERROR am_rpi_advaboard_eventpwr_analogcontrol_read(unsigned int handler_pwr, uint8_t *analogcontrol0, uint8_t *analogcontrol1, uint8_t *analogcontrol2) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
3.6.1.8 handler: configure power-on/off
Configure which parts of the AdvaBoard RPi1 should be powered-on/off by an event-handler.
Every parameter can have 3 values:
value | meaning |
---|---|
-1, <0 | do not change |
0 | power-off |
1, >0 | power-on |
Usage: | AM_ERROR am_rpi_advaboard_eventpwr_power_write(unsigned int handler_pwr, int pwron, int cpld_3V, int peripheral_5V, int rpi, int tft, int tft_backlight) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.6.1.9 handler: read power-on/off-configuration
Read which parts of the AdvaBoard RPi1 are powered-on/off by an event-handler.
Usage: | AM_ERROR am_rpi_advaboard_eventpwr_power_read(unsigned int handler_pwr, int *pwron, int *cpld_3V, int *peripheral_5V, int *rpi, int *tft, int *tft_backlight) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
3.6.1.10 event: define handler for I2C-interrupt
Define which handler should be executed when an I2C-interrupt occurs.
Usage: | AM_ERROR am_rpi_advaboard_eventpwr_i2cint_write(unsigned int handler_pwr_en) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.6.1.11 event: read handler for I2C-interrupt
Read which handler is executed when an I2C-interrupt occurs.
Usage: | AM_ERROR am_rpi_advaboard_eventpwr_i2cint_read(unsigned int *handler_pwr_en) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.6.1.12 event: define RTC-alarm
Define a RTC-alarm and which handler should be executed when the RTC-alarm occurs.
Usage: | AM_ERROR am_rpi_advaboard_rtc_alarm_write(unsigned int i, unsigned int handler_pwr, uint32_t time, uint32_t periodic) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: |
|
3.6.1.13 event: define RTC-alarm and activate it
Define a RTC-alarm and which handler should be executed when the RTC-alarm occurs, and activate it. This is a simple wrapper around am_rpi_advaboard_rtc_alarm_write() and am_rpi_advaboard_rtc_control().
Usage: | AM_ERROR am_rpi_advaboard_rtc_alarm_set(unsigned int i, unsigned int handler_pwr, uint32_t time, uint32_t periodic) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
SeeAlso: | am_rpi_advaboard_rtc_alarm_write(), am_rpi_advaboard_rtc_control() |
3.6.1.14 event: read RTC-alarm
Read RTC-alarm and which handler is executed when the RTC-alarm occurs.
Usage: | AM_ERROR am_rpi_advaboard_rtc_alarm_read(unsigned int i, unsigned int *handler_pwr, uint32_t *time, uint32_t *periodic) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: |
|
3.6.2 I/O (eventio)
Events:
- reset, always triggers handler 0
- 4 configurable events, depending on the digital-inputs I/O 0.4..0.7, 1.0..1.7
Handlers:
- 4 handlers with configurable actions (0..3)
Actions:
- set digital-outputs 0.4..0.7, 1.0..1.7
- control digital-I/Os 0.4..0.7, 1.0..1.7
3.6.2.1 read event-handler-flags
Read event-handler-flags. Every time an event-handler is triggered, its flag is set. The handlers 0..3 use the bits 0..3 of flags.
Usage: | AM_ERROR am_rpi_advaboard_eventio_flags(uint8_t *flags) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.6.2.2 clear event-handler-flags
Clear some event-handler-flags.
Usage: | AM_ERROR am_rpi_advaboard_eventio_clear(uint8_t flags) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.6.2.3 trigger event-handler
Manually trigger an event-handler.
Usage: | AM_ERROR am_rpi_advaboard_eventio_trigger(unsigned int handler_io) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.6.2.4 handler: configure digital-outputs
Define which outputs should be set/cleared by an event-handler.
Usage: | AM_ERROR am_rpi_advaboard_eventio_output_write(unsigned int handler_io, int mask0, int output0, int mask1, int output1, int mask2, int output2) |
|||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters: |
|
|||||||||||||||||||||
Returns: | 0 on success, <0 on error |
|||||||||||||||||||||
Note: | The F353-output-byte 2 is a virtual output, with:
|
|||||||||||||||||||||
SeeAlso: | AdvaBoard RPi1 documentation |
3.6.2.5 handler: read digital-output-configuration
Read which outputs are set/cleared by an event-handler.
Usage: | AM_ERROR am_rpi_advaboard_eventio_output_read(unsigned int handler_io, uint8_t *mask0, uint8_t *output0, uint8_t *mask1, uint8_t *output1, uint8_t *mask2, uint8_t *output2) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
SeeAlso: | am_rpi_advaboard_eventio_output_write(), AdvaBoard RPi1 documentation |
3.6.2.6 handler: configure digital-control
Define which digital-controls should be executed by an event-handler.
Usage: | AM_ERROR am_rpi_advaboard_eventio_control_write(unsigned int handler_io, uint16_t control) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
SeeAlso: | AdvaBoard RPi1 documentation, am_rpi_advaboard_io_control() |
3.6.2.7 handler: read digital-control-configuration
Read which digital-controls are executed by an event-handler.
Usage: | AM_ERROR am_rpi_advaboard_eventio_control_read(unsigned int handler_io, uint16_t *control) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
SeeAlso: | AdvaBoard RPi1 documentation |
3.6.2.8 event: configure event
Configure an event. When the I/Os match the configured value, an event-handler is triggered.
Usage: | AM_ERROR am_rpi_advaboard_eventio_event_write(unsigned int event_io, unsigned int handler_io, uint8_t mask0, uint8_t input0, uint8_t mask1, uint8_t input1) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.6.2.9 event: read event-configuration
Read an event-configuration.
Usage: | AM_ERROR am_rpi_advaboard_eventio_event_read(unsigned int event_io, unsigned int *handler_io, uint8_t *mask0, uint8_t *input0, uint8_t *mask1, uint8_t *input1) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.7 EEPROM
3.7.1 store F912-configuration in EEPROM
Store the current configuration of the F912 to its EEPROM, from which it is loaded after reset / power-off/on.
The stored configuration contains:
- communication-parameters (I2C-clock-extension / I2C-clock-extension-injection)
- I2C-interrupt-event
- I/O-event-handlers (power-on/off at event, I2C-interrupt at event), incl. power-on/off directly after reset
- ADC- and RTC-event-handlers (ADC-modes, RTC-start/stop/alarm-enable), incl. modes directly after reset
Usage: | AM_ERROR am_rpi_advaboard_f912_store(void) |
---|---|
Returns: | 0 on success, <0 on error |
3.7.2 store F353-configuration in EEPROM
Store the current configuration of the F353 to its EEPROM, from which it is loaded after reset / power-off/on.
The stored configuration contains:
- communication-parameters (I2C-clock-extension, RS-485-speed)
- I/O-configuration of I/O 0.4..0.7, 1.0..1.7 (input/output/output_opendrain/output_pushpull)
- PWM-clock
- I/O-events
- I/O-handlers (output / control / pins at handler), incl. output-values, I/O-control and enabled pins directly after reset
Usage: | AM_ERROR am_rpi_advaboard_f353_store(void) |
---|---|
Returns: | 0 on success, <0 on error |
3.8 E-SPI-interface
This library supports concurrent access to the E-SPI from different programs, which use this library, by using automatic locks.
If you want to use E-SPI, the TFT-display/-touchpanel/-SD-card or any other SPI-communication from different threads in a program, use e.g. a SPI-mutex to make sure only 1 thread accesses the SPI at the same time. If the threads use different E-SPI-configurations, make sure to reconfigure the E-SPI after acquiring the mutex.
SeeAlso: | AdvaBoard RPi1 documentation |
---|
3.8.1 communicate with E-SPI-devices
Communicate with an E-SPI-device (incl. auto-locking).
Usage: | AM_ERROR am_rpi_advaboard_espi(int sel, unsigned int len, char const *txdata, char *rxdata) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.8.2 configure E-SPI-clock
Configure the E-SPI on the AdvaBoard RPi.
The valid clock-phases and -polarities are:
- SPI_CLK_IDLELOW_SHIFTFALLING_READRISING
- SPI_CLK_IDLELOW_SHIFTRISING_READFALLING
- SPI_CLK_IDLEHIGH_SHIFTRISING_READFALLING (default)
- SPI_CLK_IDLEHIGH_SHIFTFALLING_READRISING
Usage: | AM_ERROR am_rpi_advaboard_espi_clk(enum am_rpi_spi_clk clkdiv, enum am_rpi_spi_clkcfg clkcfg) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_INVALID_ARGUMENT on error |
Note: |
|
SeeAlso: | am_rpi.h |
3.8.3 E-SPI SEL0..3: set
Set E-SPI select-pins (incl. E-SPI-locking).
Usage: | AM_ERROR am_rpi_advaboard_espi_sel(uint8_t sel) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
3.8.4 E-SPI SEL0..3: read
Read E-SPI select-pins.
Usage: | void am_rpi_advaboard_espi_sel_read(uint8_t *sel) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | This returns the current levels, which may differ from the value set by am_rpi_advaboard_espi_sel() if the E-SPI is not locked. |
3.8.5 read E-SPI-interrupt
Read the E-SPI-interrupt (incl. E-SPI-locking).
Usage: | AM_ERROR am_rpi_advaboard_espi_int_read(void) |
---|---|
Returns: | 0 if no interrupt, 1 on interrupt, AM_ERROR_BUSY on error |
SeeAlso: | AdvaBoard RPi1 documentation |
3.8.6 manually lock E-SPI
Manually lock E-SPI for several communications.
Note that you additionally have to use a mutex, if you're accessing the SPI from several threads in the same program.
Usage: | AM_ERROR am_rpi_advaboard_espi_lock(int32_t timeout_ms) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_BUSY after timeout |
3.8.7 manually unlock E-SPI
Unlock E-SPI again after am_rpi_advaboard_espi_lock(). This has to be used for every successful call to am_rpi_advaboard_espi_lock().
Usage: | void am_rpi_advaboard_espi_unlock(void) |
---|
3.8.8 set E-SPI auto-locking-timeout
Set timeout, after which E-SPI-communication-functions return AM_ERROR_BUSY if they cannot lock the E-SPI.
Usage: | void am_rpi_advaboard_espi_locking_timeout(uint16_t timeout_ms) |
---|---|
Parameters: |
|
3.9 I2C-interface
This library supports concurrent access to the I2C from different programs, which use this library, by using automatic locks.
If you want to use the I2C-interface, the F912/F353, the power-management, RTC, I/O, event-based automation, EEPROM, RS-485-configuration, or any other I2C-communication from different threads in a program, use e.g. a I2C-mutex to make sure only 1 thread accesses the I2C-bus at the same time. If the threads use different I2C-configurations, make sure to reconfigure the I2C after acquiring the mutex.
SeeAlso: | AdvaBoard RPi1 documentation |
---|
3.9.1 communicate with I2C-devices
Communicate with I2C-devices, which are connected to the AdvaBoard RPi1.
Usage: | AM_ERROR am_rpi_advaboard_i2c(uint8_t address, uint16_t txlen, char const *txdata, uint16_t rxlen, char *rxdata) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
SeeAlso: | am_rpi.c/.h, especially am_rpi_i2c_write_read() |
3.9.2 communication with I2C-devices with the Advamation RS-485-/I2C-protocol
Communicate with I2C-devices, which are connected to the AdvaBoard RPi1, with the Advamation RS-485-/I2C-protocol (incl. CRC/PEC).
Usage: | AM_ERROR am_rpi_advaboard_i2c_prot(uint8_t address, enum am_cmd cmd, unsigned int txlen, char const *txdata, unsigned int *received_len, unsigned int rxlen, char *rxdata) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error, AM_ERROR_COMM_TOOSHORT if less then rxlen bytes received |
SeeAlso: | advamation.h, am_rpi_i2c_prot() |
3.9.3 set I2C-clock
Set the I2C-clock.
Usage: | AM_ERROR am_rpi_advaboard_i2c_clk(enum am_rpi_i2c_clk clkdiv) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_INVALID_ARGUMENT on error |
Note: | The I2C core clock is 250 MHz; default-clkdiv is 1500 (166.7kHz). (The Raspberry Pi datasheet is wrong, here.) |
SeeAlso: | am_rpi.h |
3.9.4 read I2C-/SMBus-interrupt
Read the I2C-/SMBus-interrupt.
Usage: | bool am_rpi_advaboard_i2c_int_read(void) |
---|---|
Returns: | FALSE if no interrupt, TRUE on interrupt |
SeeAlso: | AdvaBoard RPi1 documentation |
3.9.5 clear I2C-INT-pin of F912
Set the I2C-interrupt-pin of F912-microcontroller to high. Can be used to release the interrupt again after the F912-microcontroller of the AdvaBoard RPi1 has caused an I2C-interrupt.
Usage: | AM_ERROR am_rpi_advaboard_i2c_f912int_clear(void) |
---|---|
Returns: | 0 on success, <0 on error |
SeeAlso: | AdvaBoard RPi1 documentation |
3.9.6 manually lock I2C
Manually lock I2C for several subsequent communications.
Note that you additionally have to use a mutex, if you're accessing the I2C-bus from several threads in the same program.
Usage: | AM_ERROR am_rpi_advaboard_i2c_lock(int32_t timeout_ms) |
---|---|
Parameters: |
|
Returns: | 0 on success, AM_ERROR_BUSY after timeout |
3.9.7 manually unlock I2C
Unlock I2C again after am_rpi_advaboard_i2c_lock(). This must be used for every successful call to am_rpi_advaboard_i2c_lock().
Usage: | void am_rpi_advaboard_i2c_unlock(void) |
---|
3.9.8 set I2C auto-locking-timeout
Set timeout, after which I2C-communication-functions return AM_ERROR_BUSY if they cannot lock the I2C.
Usage: | void am_rpi_advaboard_i2c_locking_timeout(uint16_t timeout_ms) |
---|---|
Parameters: |
|
3.9.9 I2C-clock-stretching: configure
The Raspberry Pi has a bug, which causes problems when communicating with I2C-devices which use clock-stretching. Some of these problems can be resolved by making sure that clock-stretches in the ACK-phase are always longer than a minimum value.
For this, the AdvaBoard RPi1 can
- use a minimum clock-stretching in its internal communication to its F912/F353
- inject clock-stretching in the ACK-phase into the I2C-communication with other devices (see am_rpi_advaboard_i2c_clkextinj()).
The delay should be about 1 bit time, so:
delay >= 24.5MHz / I2C_clock / 32 * 105%
e.g. delay=8 for an I2C-clock of 100 kHz.
Usage: | AM_ERROR am_rpi_advaboard_i2c_clkext(uint8_t delay) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
SeeAlso: | http://www.advamation.com/knowhow/raspberrypi/rpi-i2c-bug.html |
3.9.10 I2C-clock-stretching: read configured delay
Read the configured delay for I2C-clock-stretching and I2C-clock-stretching-injection.
Usage: | AM_ERROR am_rpi_advaboard_i2c_clkext_read(uint8_t *delay, uint8_t *delay353) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
3.9.11 I2C-clock-stretching: configure injection
Inject clock-stretching-delays in the ACK-phase for some I2C-devices. The length of the delay is configured by am_rpi_advaboard_i2c_clkext().
The delay is injected in communications with I2C-devices where I2C_device_address & address_mask == address & address_mask.
Usage: | AM_ERROR am_rpi_advaboard_i2c_clkextinj(uint8_t addressmask, uint8_t address) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: |
|
SeeAlso: | am_rpi_advaboard_i2c_clkext(), http://www.advamation.com/knowhow/raspberrypi/rpi-i2c-bug.html |
3.9.12 I2C-clock-stretching: read configured injection
Read the configured addresses for I2C-clock-stretching-injection.
Usage: | AM_ERROR am_rpi_advaboard_i2c_clkextinj_read(uint8_t *addressmask, uint8_t *address) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
3.10 RS-232 / RS-485
3.10.1 configure RS-485 / RS-232
Configure the RS-485/RS-232 interface.
Usage: | AM_ERROR am_rpi_advaboard_rs485_cfg(int mux, int32_t speed, int bit9) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: |
|
3.10.2 read RS-485/RS-232 configuration
Read the RS-485/RS-232 configuration.
Usage: | AM_ERROR am_rpi_advaboard_rs485_cfg_read(bool *mux, uint16_t *speed, bool *bit9) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
Note: | All output-parameters may be NULL if the value is not needed. |
3.11 misc
3.11.1 set LED
Set the LED of the AdvaBoard RPi1.
- 0x00: off
- 0xff: on
- 0x01: blink, about 3 times per second
- 0x02: blink, about 1.5 times per second
- 0x04: blink, about 0.8 times per second
- 0x08: blink, about 0.4 times per second
Usage: | AM_ERROR am_rpi_advaboard_led(uint8_t mode) |
---|---|
Parameters: |
|
Returns: | 0 on success, <0 on error |
SeeAlso: | AdvaBoard RPi1-documentation / Advamation RS-485-/I2C-protocol for blink-modes |