UL_LIST_CUST_DEC(spi_rq_queue, spi_drv_t, spi_msg_head_t, rq_queue, node)
-/* ------------------------------------------------------------------------- */
-
-//typedef unsigned long spi_isr_lock_level_t;
-//#define spi_isr_lock save_and_cli
-//#define spi_isr_unlock restore_flags
-
-/* ------------------------------------------------------------------------- */
int spi_transfer(spi_drv_t *ifc, int addr, int rq_len, const void *tx_buf, void *rx_buf);
-//spi_drv_t *spi_find_drv(char *name, int number);
int spi_msg_rq_ins(spi_drv_t *ifc, spi_msg_head_t *msg);
int8_t port_spi_set(const struct port_desc *port, void *values, size_t size);
/adc.h eaton
/can.h eaton
/gio.h eaton
+/mutex.h eaton
/rpp.h eaton
/sci.h eaton
*
* Call this method before using this module.
*
+ * This function is not thread safe. Do not call it from multiple threads.
+ *
* @return SUCCESS if initialization successful.\n
* FAILURE if module already initialized.
*/
/**
* Get the current analog value on the given pin.
*
+ * The function is thread thread safe.
+ *
* @param[in] pin The pin number to read [1-16].
*
* @return [0-4095] Value representing the analog value on given pin
/**
* Get the current analog value on the given pin.
*
+ * The function is thread safe.
+ *
* @param[in] pin The pin number to read [1-12].
*
* @return [0-4095] Value representing the analog value on given pin
/**
* Read and update analog cached values.
*
+ * The function is thread safe.
+ *
* @return SUCCESS when transaction was successful.\n
* FAILURE if transaction could not be confirmed.
*/
*
* Call this method before using this module.
*
+ * This function is not thread safe. Do not call it from multiple threads.
+ *
* @param[in] config Configuration of CAN controllers and message objects
*
* @return @c SUCCESS if initialization was successful,\n
/**
* Submit a CAN message for transmission.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* Data pointed by @a pdu is copied to the given message object for
* transmission. A successful call to this function also resets the TX
* pending flag that can be retrieved with rpp_can_check_tx_pend().
/**
* Checks whether message transmission is pending.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* Call this function to check whether a message previously submitted
* for transmission with rpp_can_write() still waits for transmission
* or has already been transmitted to the bus.
/**
* Read a message from a message object.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* Data in the given message object is copied to @a pdu. A successful
* call to this function also clears the indication that can be
* retrieved with rpp_can_check_rx_ind().
/**
* Checks whether a message was received by the message object.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* @param[in] hw_obj Hardware object to be checked.
* @param[out] rx_ind Where to store the RX indication flag. Its value
* will be @c true if a message was received, @c false otherwise.
*
* Call this method before using this module.
*
+ * This function is not thread safe. Do not call it from multiple threads.
+ *
* @return SUCCESS if initialization successful.\n
* FAILURE if module already initialized.
*/
*
* Call rpp_dac_update() to commit setup changes to real hardware.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* @param[in] pin The pin number to setup [1-4].
* @param[in] enabled TRUE to enable pin or FALSE to disable it.
*
*
* Call rpp_dac_update() to flush cached values to real hardware.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* @param[in] pin The pin number to set [1-4].
* @param[in] val The value to be set [0-4095] (DAC is 12bit resolution).
*
*
* Helper function that calculates DAC value given a voltage in millivolts.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* @param[in] pin The pin number to set [1-4].
* @param[in] mv Voltage level in mV to be set on specified pin [0-12000].
*
/**
* Flush cached output values and configuration changes.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* @bug This function should be called only after the FreeRTOS Scheduler has
* started (which implies from a FreeRTOS Task). If called before starting the
* scheduler, like for library initialization, or application DAC
*
* Call this method before using this module.
*
+ * This function is not thread safe. Do not call it from multiple threads.
+ *
* @return SUCCESS if initialization successful.\n
* FAILURE if module already initialized.
*/
* Configure voltage reference levels for digital inputs using variable
* reference threshold.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* @param[in] refA [0-4095] value to set (DAC is 12bits) the reference
* voltage A (pins 12-15).
* @param[in] refB [0-4095] value to set (DAC is 12bits) the reference
*
* Call rpp_din_update() to commit configuration changes to the hardware.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* @param[in] pin The pin number to setup [0-15].
* @param[in] pull_up TRUE to setup pin as pull-up (a switch-to-ground device
* is connected) or FALSE to setup as pull-down
*
* Call rpp_din_update() to update cached values.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* @param[in] pin The pin number to read [0-15].
*
* @return RPP_CLOSED or RPP_OPEN if successful.\n
* Inputs [8-11] use programmable threshold B and [12-15] use
* programmable threshold A.\n
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* @see rpp_din_ref().
*
* @param[in] pin The pin number to read [8-15].
*
* Call rpp_din_update() to update cached values.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* @param[in] pin The pin number to read [0-15].
*
* @return HIGH or LOW if successful.\n
* Read and update cached values and diagnostic values of all pins. Also commit
* configuration changes.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
+ *
* @return SUCCESS when transaction was successful.\n
* FAILURE if transaction could not be confirmed.
*/
*
* @file fr.h
*
- * @copyright Copyright (C) 2013 Czech Technical University in Prague
+ * @copyright Copyright (C) 2013, 2015 Czech Technical University in Prague
*
* @author Carlos Jenkins <carlos@jenkins.co.cr>
* @author Michal Horn <hornmich@fel.cvut.cz>
/**
* FlexRay driver initialization.
*
+ * This function is not thread safe. Do not call it from multiple threads.
+ *
* This method should be called before any other function from this
* module.
*
/**
* FlexRay controller initialization.
*
+ * The function is thread safe, unless compiled with
+ * -DRPP_THREADSAFE=0.
+ *
* This method should be called after rpp_fr_init_driver(), rpp_fr_halt_communication() or
* rpp_fr_abort_communication() and before any other function from this module.
*
/**
* Start communication
*
+ * The function is thread safe, unless compiled with
+ * -DRPP_THREADSAFE=0.
+ *
* This method should be called after rpp_fr_init_controller() and
* before any attempt to send or receive messages.
*
/**
* Allow communication on all slots
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The FlexRay node can be configured to communicate only on key
* frames after the startup. If this is the case, after calling this
* function, communication on all configured slots is allowed.
/**
* Stop communication after the end of the communication cycle.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function should be called only after
* rpp_fr_start_communication() has been called.
*
/**
* Stop communication immediately.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function should be called only after
* rpp_fr_start_communication() has been called.
*
/**
* Send wakeup pattern.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function should be called after FlexRay controller is initialized
* and before the communication start.
*
/**
* Set channel for wakeup pattern sending.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* This allows to change the configuration passed to the
* rpp_fr_init_driver().
*
/**
* Get FlexRay POC state
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time after the driver is
* initialized.
*
/**
* Send a message on the bus in the specified frame
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time when communication is running
* (rpp_fr_start_communication() was called).
*
/**
* Cancel a transmission of the message.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time when communication is running
* (rpp_fr_start_communication() was called).
*
/**
* Receive a message from the bus from the specified frame.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time when communication is running
* (rpp_fr_start_communication() was called).
*
/**
* Check TX buffer status
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time when communication is running
* (rpp_fr_start_communication() was called).
*
/**
* Reconfigure buffer
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time when after controller was initialized
* (rpp_fr_init_controller() was called).
*
/**
* Disable a FlexRay buffer
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time when communication is running
* (rpp_fr_start_communication() was called).
*
/**
* Get FlexRay global time
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time after the controller is initialized.
*
* @param [in] ctrl Not used, set always to zero.
/**
* Get Network management vector.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time after the controller is initialized.
*
* The FlexRay controller updates the vector at the end of every cycle
/**
* Get channel status.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time after the controller is
* initialized.
*
/**
* Get clock correction.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called while the communication is running or
* was stopped.
*
/**
* Gets a list of syncframes received or transmitted on channel A and channel B via the even and odd communication cycle.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called while communication is running or was stopped.
*
* @param [in] ctrl Not used, set always to zero.
/**
* Get the status of WUP receiving
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time after controller is initialized.
*
* If the Wake Up Pattern was received on some channel, the flag is set in status address.
/**
* Set the absolute timer and start it.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time after communication is running.
*
* The FlexRay controller has two absolute timers. Each of them can be
/**
* Stop the absolute timer, clear IRQ.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time after communication is running.
*
* The FlexRay controller has two absolute timers. Each of them can be
/**
* Clear the IRQ flag of the absolute timer
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time after communication is running.
*
* The FlexRay controller has two absolute timers. Each of them can be
/**
* Get IRQ flag of the absolute timer
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time after communication is running.
*
* The FlexRay controller has two absolute timers. Each of them can be
/**
* Get information about the driver vendor, module and version.
*
+ * The function is thread safe
+ *
* The function can be called any time.
*
* @param [out] version Address, where the information will be stored.
/**
* Get configuration parameter value from the internal driver structures.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* The function can be called any time.
*
* @param [in] ctrl Not used, set always to zero.
* @param[in] init_ports Specifies which ports to initialize.
* RPP_GIO_PORT_ALL causes all ports to be initialized.
*
+ * This function is not thread safe. Do not call it from multiple
+ * threads.
+ *
* @return SUCCESS if successful, FAILURE otherwise.
*/
int8_t rpp_gio_init(uint32_t init_ports);
/**
* Sets GIO output pin to a value.
*
+ * The function is thread safe.
+ *
* @param pin Pin to set
* @param value Value to the pin to.
*
/**
* Reads the value of a GIO pin.
*
+ * The function is thread safe.
+ *
* @param pin Pin to read.
*
* @return Pin value (0 or 1) in case of success, FAILURE otherwise.
/**
* Configure GIO pin.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* @param pin Pin to configure
* @param io Configure the pin as input or output.
* @param in_mode Input settings. Ignored when pin is configured as
*
* Call this method before using this module.
*
+ * This function is not thread safe. Do not call it from multiple threads.
+ *
* @return SUCCESS if initialization successful.\n
* FAILURE if module already initialized.
*/
/**
* Enable the H-Bridge output and set PWM frequency.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* Sets duty cycle to zero, direction to LOW and enables the H-Bridge
* output. Duty cycle and direction can be later controlled with
* rpp_hbr_control() (see below).
/**
* Control the H-Bridge direction and PWM duty cycle.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* @param[in] cmd [-1.0, 1.0] A double between the previous range to
* command the H-Bridge in the following manner:
* - cmd > 0 : direction set to HIGH and PWM
/**
* Disable the H-Bridge output.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* Completely disable H-Bridge. After this call the H-Bridge cannot be
* controlled again until another call to rpp_hbr_enable() is made.
*
/**
* IRC module initialization.
*
- * Call this fuction before using this module.
+ * This function is not thread safe. Do not call it from multiple threads.
+ *
+ * Call this function before using this module.
*
* @return SUCCESS if initialization successful.\n
* FAILURE if module already initialized.
/**
* IRC enable
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* Call this function to enable IRC.
* Reconfigures PINMUX register and enables N2HET program for specified IRC.
* After calling this method corresponding pins are not usable as DIN.
/**
* Check IRC status.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* @param[in] irc IRC sensor connection number.\n
* RPP_IRC_1 IRC connected to DIN10, DIN11\n
* RPP_IRC_2 IRC connected to DIN14, DIN15\n
/**
* Get the current value.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* @param[in] irc IRC sensor connection number.\n
* RPP_IRC_1 IRC connected to DIN10, DIN11\n
* RPP_IRC_2 IRC connected to DIN14, DIN15\n
/**
* IRC disable
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* Call this function to disable IRC.
* This function reenables the DIN functionality.
*
*
* Call this method before using this module.
*
+ * This function is not thread safe. Do not call it from multiple threads.
+ *
* @return SUCCESS if initialization successful.\n
* FAILURE if module already initialized.
*/
/**
* Set the output cache of given pin to given value.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* Call rpp_lout_update() to flush cached values to real hardware.
*
* @param[in] pin The pin number to set [1-8].
/**
* Get the diagnostic cached value for given pin.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* Call rpp_lout_update() to update cached values.
*
* @param[in] pin The pin number to read [1-8].
/**
* Flush cached output values and read back diagnostic values of all pins.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* @return SUCCESS when transaction was successful.\n
* FAILURE if transaction could not be confirmed.
*/
*
* Call this method before using this module.
*
+ * This function is not thread safe. Do not call it from multiple threads.
+ *
* @return SUCCESS if initialization successful.\n
* FAILURE if module already initialized.
*/
/**
* Set the output of given pin to given value.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* This function will also verify if a faulty condition is detected. See return
* documentation below for details.
*
/**
* Get the cached value of the given pin set by rpp_mout_set().
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* This will not read the value on the pin. To confirm if the output is
* correctly set call rpp_mout_diag() and confirm SUCCESS.
*
/**
* Reads the value on the given diagnostic pin.
*
+ * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0.
+ *
* Note that rpp_mout_set() calls this routine already before returning.
*
* @param[in] pin The pin number to read [1-6].
--- /dev/null
+/*
+ * Copyright (C) 2015 Czech Technical University in Prague
+ *
+ * Authors:
+ * - Michal Sojka <sojkam1@fel.cvut.cz>
+ *
+ * This document contains proprietary information belonging to Czech
+ * Technical University in Prague. Passing on and copying of this
+ * document, and communication of its contents is not permitted
+ * without prior written authorization.
+ *
+ */
+
+#ifndef RPP_MUTEX_H
+#define RPP_MUTEX_H
+
+#ifndef RPP_THREADSAFE
+#define RPP_THREADSAFE 1
+#endif
+
+#if RPP_THREADSAFE
+
+#include <os/semphr.h>
+
+#define RPP_MUTEX_DEFINE(mutex) static xSemaphoreHandle mutex
+#define RPP_MUTEX_INIT(mutex) (((mutex) = xSemaphoreCreateMutex()) != NULL)
+#define RPP_MUTEX_LOCK(mutex) xSemaphoreTake((mutex), portMAX_DELAY)
+#define RPP_MUTEX_UNLOCK(mutex) xSemaphoreGive(mutex)
+
+#else
+
+#define RPP_MUTEX_DEFINE(mutex)
+#define RPP_MUTEX_INIT(mutex) true
+#define RPP_MUTEX_LOCK(mutex)
+#define RPP_MUTEX_UNLOCK(mutex)
+
+#endif
+
+#endif
/* Base includes */
#include "base.h"
+#include "rpp/mutex.h"
+
/* Include modules */
#if defined(TARGET_POSIX)
#include "rpp/adc.h"
#error No supported target specified!
#endif /* TARGET_TMS570_HDK */
-
-
/* Library main functions */
/**
*
* @file sci.h
*
- * @copyright Copyright (C) 2013-2014 Czech Technical University in Prague
+ * @copyright Copyright (C) 2013-2015 Czech Technical University in Prague
*
* @author Carlos Jenkins <carlos@jenkins.co.cr>
*/
* initialized to 115200. It can be changed later by calling
* rpp_sci_setup().
*
+ * This function is not thread safe. Do not call it from multiple threads.
+ *
* @return SUCCESS if initialization successful.\n
* FAILURE if module already initialized.
*/
/**
* SCI module setup.
*
+ * The function is thread safe.
+ *
* Configure the SCI module.
*
* @param[in] baud Baud rate for the SCI. Tested values are 9600 and 115200
/**
* Number of bytes available on input buffer.
*
+ * The function is thread safe.
+ *
* Get the number of bytes (characters) available for reading from the serial
* port. This is data that's already arrived and stored in the SCI input buffer.
*
/**
* Read n number of bytes from input buffer.
*
+ * The function is thread safe.
+ *
* Transfer given amount of bytes from SCI input buffer into given buffer.
* Buffer should be at least as large as the amount of data requested.
*
/**
* Read n number of bytes from input buffer if possible.
*
+ * The function is thread safe.
+ *
* Transfer given amount of bytes from SCI input buffer into given buffer.
* Buffer should be at least as large as the amount of data requested.
*
/**
* Write n number of bytes to the output buffer.
*
+ * The function is thread safe.
+ *
* Transfer given amount of bytes from given buffer to the SCI output buffer.
* Data buffer should be at least as large as the amount of data requested to be
* sent.
/**
* Write n number of bytes to the output buffer if possible.
*
+ * The function is thread safe.
+ *
* Transfer given amount of bytes from given buffer to the SCI output buffer.
* Data buffer should be at least as large as the amount of data requested to be
* sent.
/**
* Flush incomming or outgoing buffers.
*
+ * The function is thread safe.
+ *
* This is a blocking call.
*
* This will block if another process is writing to or reading data from the
/**
* C style printk using RPP SCI module.
*
+ * The function is not thread safe.
+ *
* This call is intended to be used from interrupt only.
* Function blocks until whole string was sent to the SCI output, therefore
* it should be used with care. Frequent usage is for debugging.
/**
* C style printk using RPP SCI module.
*
+ * The function is not thread safe.
+ *
* This call is intended to be used from interrupt only.
* Function tries to append string to the output buffer.
*
/**
* C style printf using RPP SCI module.
*
+ * The function is thread safe.
+ *
* This is a blocking call.
*
* This function will wait until all the bytes are sent to the SCI output
/**
* C style vprintf using RPP SCI module.
*
+ * The function is thread safe.
+ *
* This is a blocking call.
*
* This function will wait until all the bytes are sent to the SCI output
/**
* C style putc (put character) using RPP SCI module.
*
+ * The function is not thread safe.
+ *
* This is a blocking call.
*
* This function will wait until the given byte is put into SCI output buffer if
/**
* C style getc (get character) using RPP SCI module.
*
+ * The function is not thread safe.
+ *
* This is a blocking call.
*
* This function will wait until a byte is available in the SCI input buffer if
/**
* Clear log.
*
- * This funtion will clear all the data from the log. This will also stop the
+ * This function will clear all the data from the log. This will also stop the
* show task if it's currently flushing the log.
*
* @return SUCCESS if log was cleared.\n
int adc_idx = (adc == adcREG1) ? 0 : 1;
int grp_idx = (group == adcGROUP1) ? 0 : 1;
+ /* Note: Thread safety of rpp_adc_update depends on this! */
xSemaphoreTake(mutex[adc_idx], portMAX_DELAY);
// Calibrate
return 0;
}
+/*
+ * This function is thread safe.
+ */
int spi_transfer(spi_drv_t *ifc, int addr, int rq_len, const void *tx_buf, void *rx_buf)
{
spi_msg_head_t msg;
{
if (initialized)
return FAILURE;
+
initialized = TRUE;
#ifndef FREERTOS_POSIX
{
#ifndef FREERTOS_POSIX
const struct port_desc *port = &port_desc[PORT_ID_ADC];
+
+ /* Thread safety is ensured in port_adc_get() resp.
+ * drv_adc_generic_read() */
port->get(port, in_cache, sizeof(in_cache));
#endif
#include "rpp/rpp.h"
#include <math.h>
#include "sys/ti_drv_dmm.h"
+#include "rpp/mutex.h"
+
+RPP_MUTEX_DEFINE(mutex_can);
static const struct rpp_can_config *can_config = NULL;
{
uint16_t i;
+ if (!RPP_MUTEX_INIT(mutex_can))
+ return FAILURE;
+
#ifdef TARGET_TMS570_RPP
dmmInit();
return SUCCESS;
}
-
int8_t rpp_can_write(rpp_can_hw_obj hw_obj, const struct rpp_can_pdu *pdu)
{
uint8_t i;
if (!(controller = map_controller(tx_cfg->controller)))
return -RPP_EINVAL;
+ RPP_MUTEX_LOCK(mutex_can);
+
// Wait until IF1 is ready to use
while (controller->IF1STAT & (1U << 7)) ;
// Copy TX data into message box
controller->IF1NO = tx_cfg->msg_obj;
+ RPP_MUTEX_UNLOCK(mutex_can);
+
return SUCCESS;
}
reg_index = (can_config->rx_config[hw_obj].msg_obj - 1) >> 5;
bit_mask = 1 << ((can_config->rx_config[hw_obj].msg_obj - 1) & 0x1FU);
+ RPP_MUTEX_LOCK(mutex_can);
+
// FIXME: Check whether to abort if there are no new data
- if (!(controller->NWDATx[reg_index] & bit_mask))
+ if (!(controller->NWDATx[reg_index] & bit_mask)) {
+ RPP_MUTEX_UNLOCK(mutex_can);
return -RPP_ENODATA;
+ }
// Wait until IF2 is ready to use
while (controller->IF2STAT & (1U << 7)) ;
#endif
}
+ RPP_MUTEX_UNLOCK(mutex_can);
+
return SUCCESS;
}
#include "rpp/rpp.h"
+#include "rpp/mutex.h"
#ifndef FREERTOS_POSIX
#include "drv/dac.h"
#include "drv/spi_tms570.h"
#endif
+RPP_MUTEX_DEFINE(mutex_dac);
+
static boolean_t initialized = FALSE;
int8_t rpp_dac_init()
{
if (initialized)
return FAILURE;
+ if (!RPP_MUTEX_INIT(mutex_dac))
+ return FAILURE;
initialized = TRUE;
#ifndef FREERTOS_POSIX
spi_tms570_init();
uint8_t index = pin - 1;
+ RPP_MUTEX_LOCK(mutex_dac);
// Mark state
enabled_cache[index] = enabled;
// Mark as changed
changed_st[index] = TRUE;
-
+ RPP_MUTEX_UNLOCK(mutex_dac);
return SUCCESS;
}
uint8_t index = pin - 1;
+ RPP_MUTEX_LOCK(mutex_dac);
// Set value to output cache
out_cache[index] = val;
// Mark as changed
changed_st[index] = TRUE;
+ RPP_MUTEX_UNLOCK(mutex_dac);
return SUCCESS;
}
uint8_t index = pin - 1;
+ RPP_MUTEX_LOCK(mutex_dac);
// Set value to output cache
out_cache[index] = val;
// Mark as changed
changed_st[index] = TRUE;
+ RPP_MUTEX_UNLOCK(mutex_dac);
return SUCCESS;
}
int i = 0;
for (i = 0; i < 4; i++) {
-
+ RPP_MUTEX_LOCK(mutex_dac);
// If changed commit changes to hardware
if (changed_st[i]) {
changed_st[i] = FALSE;
}
+ RPP_MUTEX_UNLOCK(mutex_dac);
}
return SUCCESS;
#include "rpp/rpp.h"
+#include "rpp/mutex.h"
#ifndef FREERTOS_POSIX
#include "drv/din.h"
#include "drv/spi_tms570.h"
#endif
+RPP_MUTEX_DEFINE(mutex_din);
+
static boolean_t initialized = FALSE;
int8_t rpp_din_init()
{
if (initialized)
return FAILURE;
+ if (!RPP_MUTEX_INIT(mutex_din))
+ return FAILURE;
initialized = TRUE;
#ifndef FREERTOS_POSIX
dmmInit();
return -1;
#ifndef FREERTOS_POSIX
+ RPP_MUTEX_LOCK(mutex_din);
drv_din_ref(ref_a, ref_b);
+ RPP_MUTEX_UNLOCK(mutex_din);
#endif
return SUCCESS;
}
if (!pull_up && (pin > 7))
return -2;
+ RPP_MUTEX_LOCK(mutex_din);
// Check blockade of specific pins
- if (check_pin_busy(pin))
+ if (check_pin_busy(pin)) {
+ RPP_MUTEX_UNLOCK(mutex_din);
return -RPP_EBUSY;
+ }
// Set bits
if (pull_up)
bit_clear(can_wake_cache, pin);
config_changed = TRUE;
+ RPP_MUTEX_UNLOCK(mutex_din);
return SUCCESS;
}
if (check_pin_busy(pin))
return -RPP_EBUSY;
-
- if (is_bit_set(in_cache, pin))
- return RPP_CLOSED;
- return RPP_OPEN;
+ return is_bit_set(in_cache, pin) ? RPP_CLOSED : RPP_OPEN;
}
int8_t rpp_din_get_tr(uint8_t pin)
if (check_pin_busy(pin))
return -RPP_EBUSY;
-
#ifndef FREERTOS_POSIX
if (drv_din_get_varthr(pin) == 1)
return HIGH;
-
#endif
return LOW;
}
if (check_pin_busy(pin))
return -RPP_EBUSY;
-
- if (is_bit_set(diag_cache, pin))
- return HIGH;
- return LOW;
+ return is_bit_set(diag_cache, pin) ? HIGH : LOW;
}
/*
*/
int8_t rpp_din_update()
{
+ RPP_MUTEX_LOCK(mutex_din);
#ifndef FREERTOS_POSIX
/// Setup pins
if (config_changed) {
// FIXME: Implement. Dummy assign for now.
diag_cache = in_cache;
- if (diag_cache != in_cache)
+ if (diag_cache != in_cache) {
+ RPP_MUTEX_UNLOCK(mutex_din);
return FAILURE;
+ }
#else /* ifndef FREERTOS_POSIX */
UNUSED(config_changed);
#endif /* ifndef FREERTOS_POSIX */
+ RPP_MUTEX_UNLOCK(mutex_din);
return SUCCESS;
}
#include "string.h"
#include "drv/drv.h"
#include "drv/spi_tms570.h"
+#include "rpp/mutex.h"
+
+RPP_MUTEX_DEFINE(mutex_fr);
static rpp_fr_state_t rpp_fr_state = RPP_FR_NOT_INITIALIZED; /**< Stores the actual state of the FlexRay module */
#ifndef FREERTOS_POSIX
spi_tms570_init();
#endif
+ if (!RPP_MUTEX_INIT(mutex_fr))
+ return FAILURE;
Fr_Init(config_ptr);
rpp_fr_state = RPP_FR_DRV_INITIALIZED;
return SUCCESS;
int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_t *error)
{
Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
-
+ RPP_MUTEX_LOCK(mutex_fr);
if (rpp_fr_state == RPP_FR_DRV_INITIALIZED ||
rpp_fr_state == RPP_FR_HALTED ||
rpp_fr_state == RPP_FR_ABORTED) {
retVal = Fr_ControllerInit(ctrl);
if (retVal & E_OK) {
rpp_fr_state = RPP_FR_CTR_INITIALIZED;
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
}
else {
*error = retVal;
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
}
}
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_start_communication(uint8_t ctrl, uint32_t *error)
{
Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
+ RPP_MUTEX_LOCK(mutex_fr);
if (rpp_fr_state == RPP_FR_CTR_INITIALIZED) {
retVal = Fr_StartCommunication(ctrl);
if (retVal & E_OK) {
rpp_fr_state = RPP_FR_RUNNING;
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+
}
else {
*error = retVal;
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
}
}
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
}
int8_t rpp_fr_all_slots(uint8_t ctrl)
{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_AllSlots(ctrl) & E_OK)
- return SUCCESS;
- return FAILURE;
+ int8_t ret;
+
+ RPP_MUTEX_LOCK(mutex_fr);
+ ret = (rpp_fr_state == RPP_FR_RUNNING && Fr_AllSlots(ctrl) & E_OK);
+ RPP_MUTEX_UNLOCK(mutex_fr);
+
+ return ret ? SUCCESS : FAILURE;
}
int8_t rpp_fr_halt_communication(uint8_t ctrl)
{
+ RPP_MUTEX_LOCK(mutex_fr);
if (rpp_fr_state == RPP_FR_RUNNING && Fr_HaltCommunication(ctrl) & E_OK) {
rpp_fr_state = RPP_FR_HALTED;
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+
}
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
}
int8_t rpp_fr_abort_communication(uint8_t ctrl)
{
+ RPP_MUTEX_LOCK(mutex_fr);
if (rpp_fr_state == RPP_FR_RUNNING && Fr_AbortCommunication(ctrl) & E_OK) {
rpp_fr_state = RPP_FR_ABORTED;
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+
}
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
}
int8_t rpp_fr_send_wup(uint8_t ctrl)
{
- if (rpp_fr_state == RPP_FR_CTR_INITIALIZED && Fr_SendWUP(ctrl) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state == RPP_FR_CTR_INITIALIZED && Fr_SendWUP(ctrl) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
}
int8_t rpp_fr_set_wu_channel(uint8_t ctrl, Fr_ChannelType channel)
{
- if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_SetWakeupChannel(ctrl, channel) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_SetWakeupChannel(ctrl, channel) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
}
int8_t rpp_fr_get_poc_status(uint8_t ctrl, Fr_POCStatusType *poc_status_ptr)
{
- if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetPOCStatus(ctrl, poc_status_ptr) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetPOCStatus(ctrl, poc_status_ptr) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
}
int8_t rpp_fr_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx, const uint8_t *lsdu, uint8_t lsdu_length)
{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_TransmitTxLPdu(ctrl, lpdu_idx, lsdu, lsdu_length) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state == RPP_FR_RUNNING && Fr_TransmitTxLPdu(ctrl, lpdu_idx, lsdu, lsdu_length) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+
+ }
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_cancel_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx)
{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_CancelTxLPdu(ctrl, lpdu_idx) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state == RPP_FR_RUNNING && Fr_CancelTxLPdu(ctrl, lpdu_idx) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_receive_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint8_t *lsdu, Fr_RxLPduStatusType *lpdu_status, uint8_t *lsdu_length)
{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_ReceiveRxLPdu(ctrl, lpdu_idx, lsdu, lpdu_status, lsdu_length) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state == RPP_FR_RUNNING && Fr_ReceiveRxLPdu(ctrl, lpdu_idx, lsdu, lpdu_status, lsdu_length) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_check_tx_lpdu_status(uint8_t ctrl, uint16_t lpdu_idx, Fr_TxLPduStatusType *lpdu_status)
{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_CheckTxLPduStatus(ctrl, lpdu_idx, lpdu_status) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state == RPP_FR_RUNNING && Fr_CheckTxLPduStatus(ctrl, lpdu_idx, lpdu_status) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_reconfigure_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint16_t frame_id, Fr_ChannelType channel, uint8_t cycle_set, uint8_t cycle_offset, uint8_t payload, uint16_t header_crc)
{
- if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_ReconfigLPdu(ctrl, lpdu_idx, frame_id, channel, cycle_set, cycle_offset, payload, header_crc) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_ReconfigLPdu(ctrl, lpdu_idx, frame_id, channel, cycle_set, cycle_offset, payload, header_crc) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_disable_lpdu(uint8_t ctrl, uint16_t lpdu_idx)
{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_DisableLPdu(ctrl, lpdu_idx) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state == RPP_FR_RUNNING && Fr_DisableLPdu(ctrl, lpdu_idx) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_get_global_time(uint8_t ctrl, uint8_t *cycle, uint16_t *macroticks)
{
- if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetGlobalTime(ctrl, cycle, macroticks) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetGlobalTime(ctrl, cycle, macroticks) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_get_network_management_vector(uint8_t ctrl, uint8_t *nm_vector)
{
- if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetNmVector(ctrl, nm_vector) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetNmVector(ctrl, nm_vector) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_get_channel_status(uint8_t ctrl, uint16_t *channel_a_status, uint16_t *channel_b_status)
{
- if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetChannelStatus(ctrl, channel_a_status, channel_b_status) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetChannelStatus(ctrl, channel_a_status, channel_b_status) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_get_clock_correction(uint8_t ctrl, int16_t *rate_correction, int32_t *offset_correction)
{
- if (rpp_fr_state >= RPP_FR_RUNNING && Fr_GetClockCorrection(ctrl, rate_correction, offset_correction) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state >= RPP_FR_RUNNING && Fr_GetClockCorrection(ctrl, rate_correction, offset_correction) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_get_sync_frame_list(uint8_t ctrl, uint8_t list_size, uint16_t *channel_a_even_list, uint16_t *channel_b_even_list, uint16_t *channel_a_odd_list, uint16_t *channel_b_odd_list)
{
- if (rpp_fr_state >= RPP_FR_RUNNING && Fr_GetSyncFrameList(ctrl, list_size, channel_a_even_list, channel_b_even_list, channel_a_odd_list, channel_b_odd_list) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state >= RPP_FR_RUNNING && Fr_GetSyncFrameList(ctrl, list_size, channel_a_even_list, channel_b_even_list, channel_a_odd_list, channel_b_odd_list) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_get_wakeup_rx_status(uint8_t ctrl, uint8_t *status)
{
- if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetWakeupRxStatus(ctrl, status) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetWakeupRxStatus(ctrl, status) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_set_timer(uint8_t ctrl, uint8_t timer_idx, uint8_t cycle_set, uint16_t offset_threshold)
{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_SetAbsoluteTimer(ctrl, timer_idx, cycle_set, offset_threshold) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state == RPP_FR_RUNNING && Fr_SetAbsoluteTimer(ctrl, timer_idx, cycle_set, offset_threshold) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_cancel_timer(uint8_t ctrl, uint8_t timer_idx)
{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_CancelAbsoluteTimer(ctrl, timer_idx) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state == RPP_FR_RUNNING && Fr_CancelAbsoluteTimer(ctrl, timer_idx) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_clear_timer_irq(uint8_t ctrl, uint8_t timer_idx)
{
- if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_AckAbsoluteTimerIRQ(ctrl, timer_idx) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_AckAbsoluteTimerIRQ(ctrl, timer_idx) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_get_timer_irq_status(uint8_t ctrl, uint8_t timer_idx, boolean_t *irq_pending)
{
- if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetAbsoluteTimerIRQStatus(ctrl, timer_idx, irq_pending) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetAbsoluteTimerIRQStatus(ctrl, timer_idx, irq_pending) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
int8_t rpp_fr_get_driver_version(Std_VersionInfoType *version)
int8_t rpp_fr_read_com_ctrl_config(uint8_t ctrl, uint8_t param_idx, uint32_t *param_value)
{
- if (Fr_ReadCCConfig(ctrl, param_idx, param_value) & E_OK)
+ RPP_MUTEX_LOCK(mutex_fr);
+ if (Fr_ReadCCConfig(ctrl, param_idx, param_value) & E_OK) {
+ RPP_MUTEX_UNLOCK(mutex_fr);
return SUCCESS;
+ }
+
+ RPP_MUTEX_UNLOCK(mutex_fr);
return FAILURE;
+
}
+
#endif /* FREERTOS_POSIX */
#include "base.h"
#include "rpp/gio.h"
#include "drv/gio_tab.h"
+#include "rpp/mutex.h"
+
+RPP_MUTEX_DEFINE(mutex_gio);
static uint32_t ports_initialized = 0;
int8_t rpp_gio_init(uint32_t init_ports)
{
enum pin_name pin;
+ if (!RPP_MUTEX_INIT(mutex_gio))
+ return FAILURE;
gioREG->GCR0 = 1; // Bring GIO out of reset
if (ports_initialized == 0 || pin >= _PIN_COUNT || pin < 0)
return FAILURE;
- gio_tab_set(pin, value);
+ gio_tab_set(pin, value); /* Thread safe */
return SUCCESS;
}
if (ports_initialized == 0 || pin >= _PIN_COUNT || pin < 0)
return FAILURE;
- return gio_tab_get(pin) ? 1 : 0;
+ boolean_t ret_val = gio_tab_get(pin) ? 1 : 0; /* Thread safe */
+
+ return ret_val;
}
int8_t rpp_gio_setup(enum pin_name pin, enum rpp_gio_io io, enum rpp_gio_in_mode in_mode,
dsc |= mode_flags[in_mode];
dsc |= open_drain ? GIO_PIN_CONF_OD_ON : GIO_PIN_CONF_OD_OFF;
+ RPP_MUTEX_LOCK(mutex_gio);
gio_setup(dsc);
+ RPP_MUTEX_UNLOCK(mutex_gio);
+
return SUCCESS;
}
#include "rpp/rpp.h"
+#include "rpp/mutex.h"
#ifndef FREERTOS_POSIX
#include "drv/hbridge.h"
#include "drv/spi_tms570.h"
#endif
+RPP_MUTEX_DEFINE(mutex_hbr);
+
static boolean_t initialized = FALSE;
int8_t rpp_hbr_init()
{
if (initialized)
return FAILURE;
+ if (!RPP_MUTEX_INIT(mutex_hbr))
+ return FAILURE;
initialized = TRUE;
#ifndef FREERTOS_POSIX
dmmInit();
if (period < 1)
period = 55; // ~18kHz (18181.818181818 Hz to be precise)
- rpp_hdr_reset();
-
#ifndef FREERTOS_POSIX
+ RPP_MUTEX_LOCK(mutex_hbr);
+ rpp_hdr_reset();
// Configure N2HET
- if (drv_hbr_pwm_set_signal(period, 0) != SUCCESS)
+ if (drv_hbr_pwm_set_signal(period, 0) != SUCCESS) {
+ RPP_MUTEX_UNLOCK(mutex_hbr);
return FAILURE;
+ }
drv_hbr_pwm_start();
drv_hbr_set_en(HIGH);
// Start watchdog
int ret = drv_hbr_wdg_start();
- if (ret != SUCCESS && ret != -RPP_EBUSY) // Don't fail if already started
+ if (ret != SUCCESS && ret != -RPP_EBUSY) { // Don't fail if already started
+ RPP_MUTEX_UNLOCK(mutex_hbr);
return FAILURE;
-
+ }
+ RPP_MUTEX_UNLOCK(mutex_hbr);
#endif
enabled = TRUE;
// Set direction
+ RPP_MUTEX_LOCK(mutex_hbr);
drv_hbr_set_dir(scaled > 0);
// Set PWM duty cycle
drv_hbr_pwm_set_duty(abs(scaled));
+ RPP_MUTEX_UNLOCK(mutex_hbr);
#endif
return SUCCESS;
return FAILURE;
#ifndef FREERTOS_POSIX
+ RPP_MUTEX_LOCK(mutex_hbr);
rpp_hdr_reset();
// We ignore is watchdog could not be stopped, because is harmless.
// It would be worse if we just could not stop the H-Bridge just because
// the watchdog could not be stopped.
drv_hbr_wdg_stop();
+ RPP_MUTEX_UNLOCK(mutex_hbr);
#endif
enabled = FALSE;
*/
#include "rpp/rpp.h"
+#include "rpp/mutex.h"
+
+RPP_MUTEX_DEFINE(mutex_irc);
#ifndef FREERTOS_POSIX
#include "sys/sys.h"
#endif
static boolean_t initialized = FALSE;
-
static boolean_t rpp_irc_enabled[2] = {FALSE, FALSE};
int8_t rpp_irc_init()
if (initialized)
return FAILURE;
+ if (!RPP_MUTEX_INIT(mutex_irc))
+ return FAILURE;
#ifndef FREERTOS_POSIX
het2Init();
if (irc < 1 || irc > 2)
return -RPP_EINVAL;
+ RPP_MUTEX_LOCK(mutex_irc);
rpp_irc_enabled[irc-1] = TRUE;
setMuxForIRC(irc, TRUE);
ircEnable(irc);
+ RPP_MUTEX_UNLOCK(mutex_irc);
return SUCCESS;
}
if (irc < 1 || irc > 2)
return -RPP_EINVAL;
- return rpp_irc_enabled[irc-1];
+ RPP_MUTEX_LOCK(mutex_irc);
+ boolean_t ret_val = rpp_irc_enabled[irc-1];
+ RPP_MUTEX_UNLOCK(mutex_irc);
+
+ return ret_val;
}
int32_t rpp_irc_get(uint8_t irc)
return FAILURE;
#ifndef FREERTOS_POSIX
- return ircGet(irc);
+ RPP_MUTEX_LOCK(mutex_irc);
+ int32_t ret_val = ircGet(irc);
+ RPP_MUTEX_UNLOCK(mutex_irc);
+ return ret_val;
#else
return 1;
#endif
if (rpp_irc_status(irc) != 1)
return FAILURE;
+ RPP_MUTEX_LOCK(mutex_irc);
ircDisable(irc);
setMuxForIRC(irc, FALSE);
rpp_irc_enabled[irc-1] = FALSE;
+ RPP_MUTEX_UNLOCK(mutex_irc);
return SUCCESS;
}
#include "rpp/rpp.h"
+#include "rpp/mutex.h"
+
+RPP_MUTEX_DEFINE(mutex_lout);
#ifndef FREERTOS_POSIX
#include "drv/lout.h"
{
if (initialized)
return FAILURE;
+ if (!RPP_MUTEX_INIT(mutex_lout))
+ return FAILURE;
initialized = TRUE;
#ifndef FREERTOS_POSIX
spi_tms570_init();
return -1;
uint8_t index = pin - 1;
+ RPP_MUTEX_LOCK(mutex_lout);
if (val)
bit_set(out_cache, index);
else
bit_clear(out_cache, index);
+ RPP_MUTEX_UNLOCK(mutex_lout);
return SUCCESS;
}
if ((pin < 1) || (pin > 8))
return -1;
+ int8_t ret_val = LOW;
+
+ RPP_MUTEX_LOCK(mutex_lout);
if (is_bit_set(diag_cache, pin - 1))
- return HIGH;
- return LOW;
+ ret_val = HIGH;
+ RPP_MUTEX_UNLOCK(mutex_lout);
+ return ret_val;
}
int8_t rpp_lout_update()
{
#ifndef FREERTOS_POSIX
+ RPP_MUTEX_LOCK(mutex_lout);
// Update output values
lout_set_word(out_cache);
// FIXME: Check which SPI transfer statuses could be considered errors
// FIXME: Implement. Dummy assign for now.
diag_cache = out_cache;
- if (diag_cache != out_cache)
+ if (diag_cache != out_cache) {
+ RPP_MUTEX_UNLOCK(mutex_lout);
return FAILURE;
-
+ }
+ RPP_MUTEX_UNLOCK(mutex_lout);
#endif
return SUCCESS;
#include "rpp/rpp.h"
+#include "rpp/mutex.h"
+
+RPP_MUTEX_DEFINE(mutex_mout);
#ifndef FREERTOS_POSIX
#include "drv/mout.h"
{
if (initialized)
return FAILURE;
+ if (!RPP_MUTEX_INIT(mutex_mout))
+ return FAILURE;
initialized = TRUE;
#ifndef FREERTOS_POSIX
dmmInit();
#ifndef FREERTOS_POSIX
// Set and store value
+ RPP_MUTEX_LOCK(mutex_mout);
if (drv_mout_set(idx, val) != SUCCESS)
return -3;
cache[idx] = val;
+ RPP_MUTEX_UNLOCK(mutex_mout);
// FIXME Wait some time for synchronization
// Don't use vTaskDelay() here because the minimum time to wait is one tick,
asm (" nop");
}
+ RPP_MUTEX_LOCK(mutex_mout);
// Get value back and compare
- if (drv_mout_diag(idx) == FAILURE)
+ if (drv_mout_diag(idx) == FAILURE) {
+ RPP_MUTEX_UNLOCK(mutex_mout);
return -4;
+ }
+ RPP_MUTEX_UNLOCK(mutex_mout);
#else
+ RPP_MUTEX_LOCK(mutex_mout);
cache[idx] = val;
+ RPP_MUTEX_UNLOCK(mutex_mout);
#endif
return SUCCESS;
if ((pin < 1) || (pin > 6))
return -1;
- return cache[pin - 1];
+ RPP_MUTEX_LOCK(mutex_mout);
+ int8_t ret_val = cache[pin - 1];
+ RPP_MUTEX_UNLOCK(mutex_mout);
+
+ return ret_val;
}
return -1;
#ifndef FREERTOS_POSIX
- if (drv_mout_diag(pin - 1) == 0)
+ RPP_MUTEX_LOCK(mutex_mout);
+ if (drv_mout_diag(pin - 1) == 0) {
+ RPP_MUTEX_UNLOCK(mutex_mout);
return FAILURE;
-
+ }
#endif
return SUCCESS;
}
-/* Copyright (C) 2013 Czech Technical University in Prague
+/* Copyright (C) 2013, 2015 Czech Technical University in Prague
*
* Authors:
* - Carlos Jenkins <carlos@jenkins.co.cr>