2011-06-19 21:02:34 +02:00
|
|
|
/* Project Includes */
|
|
|
|
#include "pios.h"
|
|
|
|
|
|
|
|
#if defined(PIOS_INCLUDE_RCVR)
|
|
|
|
|
|
|
|
#include <pios_rcvr_priv.h>
|
|
|
|
|
2011-07-15 03:52:07 +02:00
|
|
|
enum pios_rcvr_dev_magic {
|
|
|
|
PIOS_RCVR_DEV_MAGIC = 0x99aabbcc,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pios_rcvr_dev {
|
|
|
|
enum pios_rcvr_dev_magic magic;
|
|
|
|
uint32_t lower_id;
|
|
|
|
const struct pios_rcvr_driver * driver;
|
|
|
|
};
|
|
|
|
|
2011-06-19 21:02:34 +02:00
|
|
|
static bool PIOS_RCVR_validate(struct pios_rcvr_dev * rcvr_dev)
|
|
|
|
{
|
|
|
|
return (rcvr_dev->magic == PIOS_RCVR_DEV_MAGIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(PIOS_INCLUDE_FREERTOS) && 0
|
|
|
|
static struct pios_rcvr_dev * PIOS_RCVR_alloc(void)
|
|
|
|
{
|
|
|
|
struct pios_rcvr_dev * rcvr_dev;
|
|
|
|
|
|
|
|
rcvr_dev = (struct pios_rcvr_dev *)malloc(sizeof(*rcvr_dev));
|
|
|
|
if (!rcvr_dev) return (NULL);
|
|
|
|
|
|
|
|
rcvr_dev->magic = PIOS_RCVR_DEV_MAGIC;
|
|
|
|
return(rcvr_dev);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static struct pios_rcvr_dev pios_rcvr_devs[PIOS_RCVR_MAX_DEVS];
|
|
|
|
static uint8_t pios_rcvr_num_devs;
|
|
|
|
static struct pios_rcvr_dev * PIOS_RCVR_alloc(void)
|
|
|
|
{
|
|
|
|
struct pios_rcvr_dev * rcvr_dev;
|
|
|
|
|
|
|
|
if (pios_rcvr_num_devs >= PIOS_RCVR_MAX_DEVS) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
rcvr_dev = &pios_rcvr_devs[pios_rcvr_num_devs++];
|
|
|
|
rcvr_dev->magic = PIOS_RCVR_DEV_MAGIC;
|
|
|
|
|
|
|
|
return (rcvr_dev);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialises RCVR layer
|
|
|
|
* \param[out] handle
|
|
|
|
* \param[in] driver
|
|
|
|
* \param[in] id
|
|
|
|
* \return < 0 if initialisation failed
|
|
|
|
*/
|
2011-07-26 06:27:03 +02:00
|
|
|
int32_t PIOS_RCVR_Init(uint32_t * rcvr_id, const struct pios_rcvr_driver * driver, uint32_t lower_id)
|
2011-06-19 21:02:34 +02:00
|
|
|
{
|
|
|
|
PIOS_DEBUG_Assert(rcvr_id);
|
|
|
|
PIOS_DEBUG_Assert(driver);
|
|
|
|
|
|
|
|
struct pios_rcvr_dev * rcvr_dev;
|
|
|
|
|
|
|
|
rcvr_dev = (struct pios_rcvr_dev *) PIOS_RCVR_alloc();
|
|
|
|
if (!rcvr_dev) goto out_fail;
|
|
|
|
|
2011-07-15 03:52:07 +02:00
|
|
|
rcvr_dev->driver = driver;
|
|
|
|
rcvr_dev->lower_id = lower_id;
|
2011-06-19 21:02:34 +02:00
|
|
|
|
|
|
|
*rcvr_id = (uint32_t)rcvr_dev;
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
out_fail:
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
2011-07-15 03:52:07 +02:00
|
|
|
int32_t PIOS_RCVR_Read(uint32_t rcvr_id, uint8_t channel)
|
2011-06-19 21:02:34 +02:00
|
|
|
{
|
2011-09-04 06:47:56 +02:00
|
|
|
if (rcvr_id == 0)
|
|
|
|
return PIOS_RCVR_NODRIVER;
|
|
|
|
|
2011-06-19 21:02:34 +02:00
|
|
|
struct pios_rcvr_dev * rcvr_dev = (struct pios_rcvr_dev *)rcvr_id;
|
|
|
|
|
|
|
|
if (!PIOS_RCVR_validate(rcvr_dev)) {
|
|
|
|
/* Undefined RCVR port for this board (see pios_board.c) */
|
2011-07-26 06:27:03 +02:00
|
|
|
PIOS_Assert(0);
|
2011-06-19 21:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PIOS_DEBUG_Assert(rcvr_dev->driver->read);
|
|
|
|
|
2011-07-15 03:52:07 +02:00
|
|
|
return rcvr_dev->driver->read(rcvr_dev->lower_id, channel);
|
2011-06-19 21:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|