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

master
gdisirio 2008-05-07 12:00:55 +00:00
parent d1626cc8b5
commit d158e16ed8
5 changed files with 48 additions and 18 deletions

View File

@ -82,16 +82,16 @@ static uint32_t phy_get(uint8_t regno) {
}*/
/*
* Returns TRUE if the link is active else FALSE.
* Returns FALSE if the link is not established.
* It also setup the link-related EMAC registers.
*/
static bool_t check_link_status(void) {
static bool_t get_link_status(void) {
uint32_t ncfgr, bmsr, bmcr, lpa;
(void)phy_get(MII_BMSR);
bmsr = phy_get(MII_BMSR);
if (!(bmsr & BMSR_LSTATUS))
return TRUE;
return FALSE;
ncfgr = AT91C_BASE_EMAC->EMAC_NCFGR & ~(AT91C_EMAC_SPD | AT91C_EMAC_FD);
bmcr = phy_get(MII_BMCR);
@ -109,20 +109,41 @@ static bool_t check_link_status(void) {
ncfgr |= AT91C_EMAC_FD;
}
AT91C_BASE_EMAC->EMAC_NCFGR = ncfgr;
return FALSE;
return TRUE;
}
#define RSR_BITS (AT91C_EMAC_BNA | AT91C_EMAC_REC | AT91C_EMAC_OVR)
#define TSR_BITS (AT91C_EMAC_UBR | AT91C_EMAC_COL | AT91C_EMAC_RLES | \
AT91C_EMAC_BEX | AT91C_EMAC_COMP | AT91C_EMAC_UND)
__attribute__((noinline))
static void ServeInterrupt(void) {
uint32_t isr, rsr, tsr;
/* Fix for the EMAC errata */
isr = AT91C_BASE_EMAC->EMAC_ISR;
rsr = AT91C_BASE_EMAC->EMAC_RSR;
tsr = AT91C_BASE_EMAC->EMAC_TSR;
if ((isr & AT91C_EMAC_RCOMP) || (rsr & RSR_BITS)) {
if (rsr & AT91C_EMAC_REC)
chEvtSendI(&EMACFrameReceived);
AT91C_BASE_EMAC->EMAC_RSR = RSR_BITS;
}
if ((isr & AT91C_EMAC_TCOMP) || (tsr & TSR_BITS)) {
if (tsr & AT91C_EMAC_COMP)
chEvtSendI(&EMACFrameTransmitted);
AT91C_BASE_EMAC->EMAC_TSR = TSR_BITS;
}
AT91C_BASE_AIC->AIC_EOICR = 0;
}
__attribute__((naked, weak))
__attribute__((naked))
void EMACIrqHandler(void) {
chSysIRQEnterI();
ServeInterrupt();
chSysIRQExitI();
}
@ -216,13 +237,14 @@ void InitEMAC(int prio) {
if ((phy_get(MII_PHYSID1) != (MII_MICREL_ID >> 16)) ||
(phy_get(MII_PHYSID2 & 0xFFF0) != (MII_MICREL_ID & 0xFFF0)))
chDbgPanic("Wrong PHY identifier");
if (check_link_status())
if (!get_link_status())
chDbgPanic("No link");
AT91C_BASE_EMAC->EMAC_NCR &= ~AT91C_EMAC_MPE;
/*
* Interrupt setup.
*/
AT91C_BASE_EMAC->EMAC_IER = AT91C_EMAC_RCOMP;
AIC_ConfigureIT(AT91C_ID_EMAC,
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | prio,
EMACIrqHandler);

View File

@ -63,7 +63,7 @@ static void ServeInterrupt(AT91PS_USART u, FullDuplexDriver *com) {
SetError(u->US_CSR, com);
u->US_CR = AT91C_US_RSTSTA;
}
AT91C_BASE_AIC->AIC_EOICR = 0; \
AT91C_BASE_AIC->AIC_EOICR = 0;
}
__attribute__((naked, weak))

View File

@ -70,7 +70,9 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
produce better code.
- In the ARM7 and ARMCM3 ports chanced the bool_t base type from int8_t to
int32_t, this produces a bit faster and smaller code.
- Small fixes to the template files, there were some leftovers of the old
type names.
*** 0.6.3 ***
- NEW: ARM Cortex-M3 port completed. The demo program targets the STM32F103
chip from ST Microelectronics on an Olimex STM32-P103 board.

View File

@ -76,7 +76,7 @@ typedef struct {
* Macro used to allocate a thread working area aligned as both position and
* size.
*/
#define WorkingArea(s, n) BYTE8 s[UserStackSize(n)];
#define WorkingArea(s, n) uint8_t s[UserStackSize(n)];
/**
* Enters the ChibiOS/RT system mutual exclusion zone, the implementation is
@ -115,10 +115,16 @@ typedef struct {
*/
#define chSysIRQExitI()
void _IdleThread(void *p);
void chSysHalt(void);
void chSysSwitchI(Thread *otp, Thread *ntp);
void chSysPuts(char *msg);
#ifdef __cplusplus
extern "C" {
#endif
void _IdleThread(void *p);
void chSysHalt(void);
void chSysSwitchI(Thread *otp, Thread *ntp);
void chSysPuts(char *msg);
#ifdef __cplusplus
}
#endif
#endif /* _CHCORE_H_ */

View File

@ -33,9 +33,9 @@
#include <stdint.h>
#endif
typedef int8_t bool_t; /* Signed byte boolean. */
typedef uint8_t tmode_t; /* Thread mode flags, BYTE8 is ok. */
typedef uint8_t tstate_t; /* Thread state, BYTE8 is ok. */
typedef int32_t bool_t; /* Signed boolean. */
typedef uint8_t tmode_t; /* Thread mode flags, uint8_t is ok. */
typedef uint8_t tstate_t; /* Thread state, uint8_t is ok. */
typedef uint16_t tid_t; /* Thread id. */
typedef uint32_t tprio_t; /* Priority, use the fastest unsigned type. */
typedef int32_t msg_t; /* Message, use signed pointer equivalent.*/