problème avec des registres
Salut à tous!
je ne suis probablement pas sur le bon endroit du forum pour deposer ma question mais comme je ne m'y retrouve pas je me permet quand meme de la poser ici, sachant qu'il s'agit au fond d'un dev fait en C.
Voila je travail sur un systeme embarqué composé d'un MCU de type
c8051f120 et d'un ethernet board cp2200.
J'avais comme objectif de pouvoir ecrire et lire directement les registres de mon board ethernet via UART, sachant que je suis connecté comme suis:
RJ45--->CP2200---->Port parrallele--->c8051f120--->rs232
Actuellement grace au code ci dessous je me suis defini un petit protocole que voici:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
void CommandParse(void)
{
unsigned int Addr;
unsigned int Value;
char c;
c = UART1_Parse();
if(c) putchar(c);
if(c!=0x0d) return;
UartRxPtr = 0;
switch(UartRxBuffer[0]){
case 'W': UartRxPtr++;
SkipRaw();
Addr = GetHex();
SkipRaw();
Value = GetHex();
MAC_Write(Addr, Value);
printf("\nOK\n");
break;
case 'R': UartRxPtr++;
SkipRaw();
Addr = GetHex();
Value = MAC_Read(Addr);
printf("\n%04x = %04x\n", Addr, Value);
break;
case 'T': UartRxPtr++;
SkipRaw();
CP220x_Send(&DESTMAC, UartRxBuffer, sizeof(UartRxBuffer) - UartRxPtr, IP_PACKET);
printf("\nOK\n");
break;
default : printf("\nERROR\n");
break;
}
UartRxPtr = 0;
} |
Voilà mais il se trouve que je n'arrive à ecrire et lire que certains registres (indirect MAC registers) de mon cp2200 Ceci probablement à cause de ma fonction MAC_Init() qui suit:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
void MAC_Init(void)
{
// Check the duplex mode and perform duplex-mode specific initializations
if(PHYCN & 0x10){
// The device is in full-duplex mode, configure MAC registers
// Padding is turned on.
MAC_Write(MACCF, 0x40B3);
MAC_Write(IPGT, 0x0015);
} else {
// The device is in half-duplex mode, configure MAC registers
// Padding is turned off.
MAC_Write(MACCF, 0x4012);
MAC_Write(IPGT, 0x0012);
}
// Configure the IPGR register
MAC_Write(IPGR, 0x0C12);
// Configure the MAXLEN register to 1518 bytes
MAC_Write(MAXLEN, 0x05EE);
// Copy MAC Address Stored in Flash to MYMAC
FLASHADDRH = 0x1F;
FLASHADDRL = 0xFA;
MYMAC.Char[0] = FLASHAUTORD;
MYMAC.Char[1] = FLASHAUTORD;
MYMAC.Char[2] = FLASHAUTORD;
MYMAC.Char[3] = FLASHAUTORD;
MYMAC.Char[4] = FLASHAUTORD;
MYMAC.Char[5] = FLASHAUTORD;
// Program the MAC address
MAC_SetAddress(&MYMAC);
// Enable Reception and configure Loopback mode
MAC_Write(MACCN, 0x0001); // Enable Reception without loopback
}
//-----------------------------------------------------------------------------
// Indirect MAC Register Access
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// MAC_Write
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters :
// 1) unsigned char mac_reg_offset - indirect register address
// 2) unsigned int mac_reg_data - the data to write to mac_reg_offset.
//
// Writes the value <mac_reg_data> to the indirect MAC register located at
// <mac_reg_offset>.
//-----------------------------------------------------------------------------
void MAC_Write(unsigned char mac_reg_offset, unsigned int mac_reg_data)
{
// Step 1: Write the address of the indirect register to MACADDR.
MACADDR = mac_reg_offset;
// Step 2: Copy the contents of <mac_reg_data> to MACDATAH:MACDATAL
MACDATAH = (mac_reg_data >> 8); // Copy High Byte
MACDATAL = (mac_reg_data & 0xFF); // Copy Low Byte
// Step 3: Perform a write on MACRW to transfer the contents of MACDATAH:MACDATAL
// to the indirect MAC register.
MACRW = 0;
return;
}
unsigned int MAC_Read(unsigned char mac_reg_offset)
{
int mac_reg_data;
// Step 1: Write the address of the indirect register to MACADDR.
MACADDR = mac_reg_offset;
// Step 3: Perform a read of MACRW to transfer the contents to MACDATAH:MACDATAL
// from the indirect MAC register.
MACRW;
// Step 2: Copy the contents of <mac_reg_data> to MACDATAH:MACDATAL
mac_reg_data = (MACDATAH << 8) | (MACDATAL & 0xff);
return mac_reg_data;
} |
alors que je puis je faire si je veux pouvoir agir sur tous les autres registres de mon cp2200?
Probablement ecrire une nouvelle fonction MAC_Init()?
Advice needed!!!
Thank's