diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2008-05-21 13:57:47 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2008-05-21 13:57:47 +0000 |
commit | b34347c0257b14e5da0704ba2c710f39a9f9f002 (patch) | |
tree | 2e072c0c7c4c0a102e4ebe3186357a79cd8dff64 /ports/ARM7-AT91SAM7X | |
parent | f2022a264125bdf3b18e5fe0fe0c2e523cf41ded (diff) | |
download | ChibiOS-b34347c0257b14e5da0704ba2c710f39a9f9f002.tar.gz ChibiOS-b34347c0257b14e5da0704ba2c710f39a9f9f002.tar.bz2 ChibiOS-b34347c0257b14e5da0704ba2c710f39a9f9f002.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@303 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'ports/ARM7-AT91SAM7X')
-rw-r--r-- | ports/ARM7-AT91SAM7X/sam7x_emac.c | 49 | ||||
-rw-r--r-- | ports/ARM7-AT91SAM7X/sam7x_emac.h | 11 |
2 files changed, 48 insertions, 12 deletions
diff --git a/ports/ARM7-AT91SAM7X/sam7x_emac.c b/ports/ARM7-AT91SAM7X/sam7x_emac.c index 0a3d1144b..e55c6fcd6 100644 --- a/ports/ARM7-AT91SAM7X/sam7x_emac.c +++ b/ports/ARM7-AT91SAM7X/sam7x_emac.c @@ -17,10 +17,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <ch.h>
-
#include <string.h>
+#include <ch.h>
+
#include "board.h"
#include "sam7x_emac.h"
#include "mii.h"
@@ -242,7 +242,7 @@ void InitEMAC(int prio) { /*
* Set the MAC address.
*/
-void EMACSetAddress(uint8_t *eaddr) {
+void EMACSetAddress(const uint8_t *eaddr) {
AT91C_BASE_EMAC->EMAC_SA1L = (AT91_REG)((eaddr[3] << 24) | (eaddr[2] << 16) |
(eaddr[1] << 8) | eaddr[0]);
@@ -286,10 +286,50 @@ bool_t EMACGetLinkStatus(void) { }
/*
+ * Allocates and locks a buffer for a transmission operation.
+ */
+BufDescriptorEntry *EMACGetTransmitbuffer(void) {
+ BufDescriptorEntry *cptr;
+
+ if (!link_up)
+ return NULL;
+
+ chSysLock();
+ cptr = txptr;
+ if (!(cptr->w2 & W2_T_USED) ||
+ (cptr->w2 & W2_T_LOCKED)) {
+ chSysUnlock();
+ return FALSE;
+ }
+ cptr->w2 |= W2_T_LOCKED; /* Locks the buffer while copying.*/
+ if (++txptr >= &tent[EMAC_TRANSMIT_BUFFERS])
+ txptr = tent;
+ chSysUnlock();
+ return cptr;
+}
+
+/*
+ * Transmits a previously allocated buffer and then releases it.
+ */
+void EMACTransmit(BufDescriptorEntry *cptr, size_t size) {
+
+ chDbgAssert(size < EMAC_TRANSMIT_BUFFERS_SIZE, "sam7x_emac.c, EMACTransmit");
+
+ cptr->w2 &= ~W2_R_LENGTH_MASK;
+ cptr->w2 |= size;
+
+ chSysLock();
+ cptr->w2 &= ~(W2_T_USED | W2_T_LOCKED);
+ AT91C_BASE_EMAC->EMAC_NCR |= AT91C_EMAC_TSTART;
+ chSysUnlock();
+}
+
+/*
* Transmits an ethernet frame.
* Returns TRUE if the frame is queued for transmission else FALSE.
*/
-bool_t EMACTransmit(struct MACHeader *hdr, uint8_t *data, size_t size) {
+#if 0
+bool_t EMACTransmit2(struct MACHeader *hdr, uint8_t *data, size_t size) {
uint8_t *p;
BufDescriptorEntry *cptr;
@@ -332,6 +372,7 @@ bool_t EMACTransmit(struct MACHeader *hdr, uint8_t *data, size_t size) { chSysUnlock();
return TRUE;
}
+#endif
/*
* Reads a buffered frame.
diff --git a/ports/ARM7-AT91SAM7X/sam7x_emac.h b/ports/ARM7-AT91SAM7X/sam7x_emac.h index aa69a5e29..d585f1fe2 100644 --- a/ports/ARM7-AT91SAM7X/sam7x_emac.h +++ b/ports/ARM7-AT91SAM7X/sam7x_emac.h @@ -61,19 +61,14 @@ typedef struct { #define W2_T_WRAP 0x40000000
#define W2_T_USED 0x80000000
-struct MACHeader {
- uint8_t destination[6];
- uint8_t source[6];
- uint8_t ethertype[2];
-};
-
#ifdef __cplusplus
extern "C" {
#endif
void InitEMAC(int prio);
- void EMACSetAddress(uint8_t *eaddr);
+ void EMACSetAddress(const uint8_t *eaddr);
bool_t EMACGetLinkStatus(void);
- bool_t EMACTransmit(struct MACHeader *hdr, uint8_t *data, size_t size);
+ BufDescriptorEntry *EMACGetTransmitbuffer(void);
+ void EMACTransmit(BufDescriptorEntry *cptr, size_t size);
bool_t EMACReceive(uint8_t *buf, size_t *sizep);
#ifdef __cplusplus
}
|