git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1180 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2009-09-25 10:38:58 +00:00
parent d107ffedee
commit df471c9756
7 changed files with 161 additions and 41 deletions

View File

@ -51,22 +51,27 @@ void macInit(void) {
/**
* @brief MAC address setup.
*
* @param[in] macp pointer to the @p MACDriver object
* @param[in] p pointer to a six bytes buffer containing the MAC address. If
* this parameter is set to @p NULL then a system default MAC is
* used.
*
* @note This function should be invoked after the @p macInit() and before
* @p macStart() else the result is unspecified (performed or ignored).
* @note This function must be invoked only with the driver in the stopped
* state. If invoked on an active interface then it is ignored.
*/
void macSetAddress(uint8_t *p) {
void macSetAddress(MACDriver *macp, uint8_t *p) {
mac_lld_set_address(p);
if (state == ifStopped)
mac_lld_set_address(macp, p);
}
/**
* @brief Startsthe I/O activity and enters a low power mode.
*
* @param[in] macp pointer to the @p MACDriver object
*
*/
void macStart(void) {
void macStart(MACDriver *macp) {
chSysLock();
if (state == ifStarted) {
@ -75,13 +80,15 @@ void macStart(void) {
}
state = ifStarted;
chSysUnlock();
mac_lld_start();
mac_lld_start(macp);
}
/**
* @brief Stops the I/O activity.
*
* @param[in] macp pointer to the @p MACDriver object
*/
void macStop(void) {
void macStop(MACDriver *macp) {
chSysLock();
if (state == ifStopped) {
@ -93,7 +100,7 @@ void macStop(void) {
chSemResetI(&rdsem, 0);
chSchRescheduleS();
chSysUnlock();
mac_lld_stop();
mac_lld_stop(macp);
}
/**
@ -102,6 +109,7 @@ void macStop(void) {
* returned. If a descriptor is not currently available then the
* invoking thread is queued until one is freed.
*
* @param[in] macp pointer to the @p MACDriver object
* @param[in] time the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
@ -110,7 +118,8 @@ void macStop(void) {
* @return A pointer to a @p MACTransmitDescriptor structure or @p NULL if
* the operation timed out or the driver went in stop mode.
*/
MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time) {
MACTransmitDescriptor *macWaitTransmitDescriptor(MACDriver *macp,
systime_t time) {
MACTransmitDescriptor *tdp;
chSysLock();
@ -118,7 +127,7 @@ MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time) {
if ((state == ifStopped) || (chSemWaitTimeoutS(&tdsem, time) != RDY_OK))
tdp = NULL;
else
tdp = max_lld_get_transmit_descriptor();
tdp = max_lld_get_transmit_descriptor(macp);
chSysUnlock();
return tdp;
@ -128,12 +137,14 @@ MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time) {
* @brief Releases a transmit descriptor and starts the transmission of the
* enqueued data as a single frame.
*
* @param[in] macp pointer to the @p MACDriver object
* @param[in] tdp the pointer to the @p MACTransmitDescriptor structure
*/
void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) {
void macReleaseTransmitDescriptor(MACDriver *macp,
MACTransmitDescriptor *tdp) {
if (state == ifStarted)
mac_lld_release_transmit_descriptor(tdp);
mac_lld_release_transmit_descriptor(macp, tdp);
}
/**
@ -142,6 +153,7 @@ void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) {
* not immediately available then the invoking thread is queued
* until one is received.
*
* @param[in] macp pointer to the @p MACDriver object
* @param[in] time the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
@ -151,7 +163,8 @@ void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) {
* the operation timed out, the driver went in stop mode or some
* transient error happened.
*/
MACReceiveDescriptor *macWaitReceiveDescriptor(systime_t time) {
MACReceiveDescriptor *macWaitReceiveDescriptor(MACDriver *macp,
systime_t time) {
MACReceiveDescriptor *rdp;
chSysLock();
@ -159,7 +172,7 @@ MACReceiveDescriptor *macWaitReceiveDescriptor(systime_t time) {
if ((state == ifStopped) || (chSemWaitTimeoutS(&rdsem, time) != RDY_OK))
rdp = NULL;
else
rdp = max_lld_get_receive_descriptor();
rdp = max_lld_get_receive_descriptor(macp);
chSysUnlock();
return rdp;
@ -170,12 +183,14 @@ MACReceiveDescriptor *macWaitReceiveDescriptor(systime_t time) {
* @details The descriptor and its buffer is made available for more incoming
* frames.
*
* @param[in] macp pointer to the @p MACDriver object
* @param[in] rdp the pointer to the @p MACReceiveDescriptor structure
*/
void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) {
void macReleaseReceiveDescriptor(MACDriver *macp,
MACReceiveDescriptor *rdp) {
if (state == ifStarted)
mac_lld_release_receive_descriptor(rdp);
mac_lld_release_receive_descriptor(macp, rdp);
}
/** @} */

View File

@ -49,14 +49,17 @@
extern "C" {
#endif
void macInit(void);
void macSetAddress(uint8_t *p);
void macStart(void);
void macStop(void);
MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time);
void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp);
void macAddTransmitData(MACTransmitDescriptor *tdp,
uint8_t *buf,
size_t size);
void macSetAddress(MACDriver *macp, uint8_t *p);
void macStart(MACDriver *macp);
void macStop(MACDriver *macp);
MACTransmitDescriptor *macWaitTransmitDescriptor(MACDriver *macp,
systime_t time);
void macReleaseTransmitDescriptor(MACDriver *macp,
MACTransmitDescriptor *tdp);
MACReceiveDescriptor *macWaitReceiveDescriptor(MACDriver *macp,
systime_t time);
void macReleaseReceiveDescriptor(MACDriver *macp,
MACReceiveDescriptor *rdp);
#ifdef __cplusplus
}
#endif

30
os/io/phy.c Normal file
View File

@ -0,0 +1,30 @@
/*
ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file phy.c
* @brief PHY Driver code.
* @addtogroup PHY
* @{
*/
#include <ch.h>
#include <phy.h>
/** @} */

42
os/io/phy.h Normal file
View File

@ -0,0 +1,42 @@
/*
ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file phy.h
* @brief PHY Driver macros and structures.
* @addtogroup PHY
* @{
*/
#ifndef _PHY_H_
#define _PHY_H_
#include "phy_lld.h"
#ifdef __cplusplus
extern "C" {
#endif
void phyInit(void);
#ifdef __cplusplus
}
#endif
#endif /* _PHY_H_ */
/** @} */

View File

@ -42,6 +42,9 @@
/** Break detected.*/
#define SD_BREAK_DETECTED 32
/**
* @brief Structure representing a serial driver.
*/
typedef struct _SerialDriver SerialDriver;
#include "serial_lld.h"

View File

@ -37,6 +37,7 @@ void mac_lld_init(void) {
/**
* @brief Low level MAC address setup.
*
* @param[in] macp pointer to the @p MACDriver object
* @param[in] p pointer to a six bytes buffer containing the MAC address. If
* this parameter is set to @p NULL then a system default MAC is
* used.
@ -44,21 +45,25 @@ void mac_lld_init(void) {
* @note This function should be invoked after the @p macInit() and before
* @p macStart() else the result is unspecified (performed or ignored).
*/
void mac_lld_set_address(uint8_t *p) {
void mac_lld_set_address(MACDriver *macp, uint8_t *p) {
}
/**
* @brief Starts the I/O activity and enters a low power mode.
*
* @param[in] macp pointer to the @p MACDriver object
*/
void mac_lld_start(void) {
void mac_lld_start(MACDriver *macp) {
}
/**
* @brief Stops the I/O activity.
*
* @param[in] macp pointer to the @p MACDriver object
*/
void mac_lld_stop(void) {
void mac_lld_stop(MACDriver *macp) {
}
@ -67,10 +72,11 @@ void mac_lld_stop(void) {
* @details One of the available transmission descriptors is locked and
* returned.
*
* @param[in] macp pointer to the @p MACDriver object
* @return A pointer to a @p MACTransmitDescriptor structure or @p NULL if
* a descriptor is not available or the driver went in stop mode.
*/
MACTransmitDescriptor *max_lld_get_transmit_descriptor(void) {
MACTransmitDescriptor *max_lld_get_transmit_descriptor(MACDriver *macp) {
return NULL;
}
@ -79,9 +85,11 @@ MACTransmitDescriptor *max_lld_get_transmit_descriptor(void) {
* @brief Releases a transmit descriptor and starts the transmission of the
* enqueued data as a single frame.
*
* @param[in] macp pointer to the @p MACDriver object
* @param[in] tdp the pointer to the @p MACTransmitDescriptor structure
*/
void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp) {
void mac_lld_release_transmit_descriptor(MACDriver *macp,
MACTransmitDescriptor *tdp) {
}
@ -99,11 +107,12 @@ uint8_t *mac_lld_get_transmit_buffer(MACTransmitDescriptor *tdp) {
/**
* @brief Returns a received frame.
*
* @param[in] macp pointer to the @p MACDriver object
* @return A pointer to a @p MACReceiveDescriptor structure or @p NULL if
* the operation timed out, the driver went in stop mode or some
* transient error happened.
*/
MACReceiveDescriptor *max_lld_get_receive_descriptor(void) {
MACReceiveDescriptor *max_lld_get_receive_descriptor(MACDriver *macp) {
return NULL;
}
@ -113,9 +122,11 @@ MACReceiveDescriptor *max_lld_get_receive_descriptor(void) {
* @details The descriptor and its buffer is made available for more incoming
* frames.
*
* @param[in] macp pointer to the @p MACDriver object
* @param[in] rdp the pointer to the @p MACReceiveDescriptor structure
*/
void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp) {
void mac_lld_release_receive_descriptor(MACDriver *macp,
MACReceiveDescriptor *rdp) {
}
@ -127,6 +138,7 @@ void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp) {
*/
uint8_t *mac_lld_get_receive_buffer(MACReceiveDescriptor *rdp) {
return NULL;
}
/** @} */

View File

@ -42,10 +42,23 @@
/* Driver data structures and types. */
/*===========================================================================*/
/**
* @brief Structure representing a MAC driver.
*/
typedef struct {
} MACDriver;
/**
* @brief Structure representing a transmission descriptor.
*/
typedef struct {
} MACTransmitDescriptor;
/**
* @brief Structure representing a receive descriptor.
*/
typedef struct {
} MACReceiveDescriptor;
@ -58,14 +71,16 @@ typedef struct {
extern "C" {
#endif
void mac_lld_init(void);
void mac_lld_set_address(uint8_t *p);
void mac_lld_start(void);
void mac_lld_stop(void);
MACTransmitDescriptor *max_lld_get_transmit_descriptor(void);
void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp);
void mac_lld_set_address(MACDriver *macp, uint8_t *p);
void mac_lld_start(MACDriver *macp);
void mac_lld_stop(MACDriver *macp);
MACTransmitDescriptor *max_lld_get_transmit_descriptor(MACDriver *macp);
void mac_lld_release_transmit_descriptor(MACDriver *macp,
MACTransmitDescriptor *tdp);
uint8_t *mac_lld_get_transmit_buffer(MACTransmitDescriptor *tdp);
MACReceiveDescriptor *max_lld_get_receive_descriptor(void);
void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp);
MACReceiveDescriptor *max_lld_get_receive_descriptor(MACDriver *macp);
void mac_lld_release_receive_descriptor(MACDriver *macp,
MACReceiveDescriptor *rdp);
uint8_t *mac_lld_get_receive_buffer(MACReceiveDescriptor *rdp);
#ifdef __cplusplus
}