📄 eep.c
字号:
/*
Copyright (c) 2004-2005 Vitesse Semiconductor Corporation "Vitesse".
All Rights Reserved. Unpublished rights reserved under the copyright laws
of the United States of America, other countries and international treaties.
The software is provided without a fee. Permission to use, copy, store and
modify, the software and its source code is granted. Permission to integrate
into other products, disclose, transmit and distribute the software in an
absolute machine readable format (e.g. HEX file) is also granted.
The source code of the software may not be disclosed, transmitted or
distributed without the written permission of Vitesse. The software and its
source code may only be used in products utilizing a Vitesse VSC73xx product.
This copyright notice must appear in any copy, modification, disclosure,
transmission or distribution of the software. Vitesse retains all ownership,
copyright, trade secret and proprietary rights in the software.
THIS SOFTWARE HAS BEEN PROVIDED "AS IS," WITHOUT EXPRESS OR IMPLIED WARRANTY
INCLUDING, WITHOUT LIMITATION, IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR USE AND NON-INFRINGEMENT.
*/
#include "common.h"
#include "hwconf.h"
#include "h2reg.h"
#include "h2io.h"
#include "uartdrv.h"
#include <absacc.h>
/* ************************************************************************ **
*
*
* Defines
*
*
*
* ************************************************************************ */
#define EEPROM_SIZE 8192
#define EEPROM_READ 3
#define EEPROM_WRITE 2
#define EEPROM_WREN 6
#define EEPROM_WRDI 4
#define EEPROM_RDSR 5
#define EEPROM_WRSR 1
/* ************************************************************************ **
*
*
* Typedefs and enums
*
*
*
* ************************************************************************ */
/* ************************************************************************ **
*
*
* Prototypes for local functions
*
*
*
* ************************************************************************ */
static uchar eep_read_byte (ushort addr);
static void eep_write_byte (ushort addr, uchar value);
static uchar eep_read_status (void);
static void eep_enable_write (void);
static void output_byte (uchar byte_val);
static uchar input_byte (void);
static void set_cs (uchar level);
static void set_o (uchar level);
static uchar get_i (void);
static void set_clk_hi (void);
static void set_clk_lo (void);
static void write_simaster (uchar value);
/* ************************************************************************ **
*
*
* Local data
*
*
*
* ************************************************************************ */
static uchar simaster_shadow = 0;
#ifndef NO_DEBUG_IF
#if LUTON_UNMANAGED_SWUP
/* ************************************************************************ */
void eep_download (ushort addr, ushort len)
/* ------------------------------------------------------------------------ --
* Purpose : Update EEPROM with image being loaded from serial port.
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
uchar j;
write_simaster(0x0a);
while (len > 0) {
eep_enable_write();
set_cs(0);
output_byte(EEPROM_WRITE);
output_byte(HIGH_BYTE(addr));
output_byte(LOW_BYTE(addr));
for (j = 0; j < 64 && len > 0; j++) {
while (!uart_byte_ready()) {
}
output_byte(uart_get_byte());
addr++;
len--;
}
set_cs(1);
while (eep_read_status() & 0x01) {
/* do nothing but wait */
}
}
write_simaster(0x00);
}
#endif
#endif
/* ************************************************************************ */
uchar eep_checksum_ok (void)
/* ------------------------------------------------------------------------ --
* Purpose : Check if checksum of image is correct
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
ushort len;
uchar csum;
ushort addr;
/*
** Read length and checksum field from EEPROM
*/
write_simaster(0x0a);
len = ((ushort) eep_read_byte(0) << 8) | eep_read_byte(1);
csum = eep_read_byte(len + (2 - 1));
write_simaster(0x00);
/*
** Calc. checksum based on image running from RAM
*/
len--;
for (addr = 0; addr < len; addr++) {
csum += CBYTE[addr];
}
return (csum == 0);
}
#if 0
/* ************************************************************************ */
void eeprom_dump (void)
/* ------------------------------------------------------------------------ --
* Purpose : Dump contents of entire EEPROM in hex bytes to RS-232.
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
ushort addr;
for (addr = 0; addr < EEPROM_SIZE; addr++) {
print_hex_b(eep_read_byte(addr));
print_spaces(1);
if ((addr & 0x0f) == 0x0f) {
print_cr_lf(); /* CR/LF every 16 byte */
}
}
print_cr_lf();
}
#endif
/* ************************************************************************ */
static uchar eep_read_byte (ushort addr)
/* ------------------------------------------------------------------------ --
* Purpose : Read a byte from EEPROM.
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
uchar byte_val;
set_cs(0);
output_byte(EEPROM_READ);
output_byte(HIGH_BYTE(addr));
output_byte(LOW_BYTE(addr));
byte_val = input_byte();
set_cs(1);
return byte_val;
}
#if 0
/* ************************************************************************ */
static void eep_write_byte (ushort addr, uchar value)
/* ------------------------------------------------------------------------ --
* Purpose : Write a byte to EEPROM
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
set_cs(0);
output_byte(EEPROM_WRITE);
output_byte(HIGH_BYTE(addr));
output_byte(LOW_BYTE(addr));
output_byte(value);
set_cs(1);
}
#endif
#ifndef NO_DEBUG_IF
#if LUTON_UNMANAGED_SWUP
/* ************************************************************************ */
static uchar eep_read_status (void)
/* ------------------------------------------------------------------------ --
* Purpose : Read status byte from EEPROM
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
uchar status;
set_cs(0);
output_byte(EEPROM_RDSR);
status = input_byte();
set_cs(1);
return status;
}
#endif
#if LUTON_UNMANAGED_SWUP
/* ************************************************************************ */
static void eep_enable_write (void)
/* ------------------------------------------------------------------------ --
* Purpose : Enable write to EEPROM
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
set_cs(0);
output_byte(EEPROM_WREN);
set_cs(1);
}
#endif
#endif
/* ************************************************************************ **
*
*
* Help functions
*
*
*
* ************************************************************************ */
static void output_byte (uchar byte_val)
{
uchar j;
for (j = 0; j < 8; j++) {
set_o(byte_val & 0x80);
byte_val <<= 1;
set_clk_hi();
set_clk_lo();
}
}
static uchar input_byte (void)
{
uchar j;
uchar byte_val;
for (j = 0; j < 8; j++) {
byte_val <<= 1;
set_clk_hi();
byte_val |= get_i();
set_clk_lo();
}
return byte_val;
}
static void set_cs (uchar level)
{
if (level) {
write_simaster(simaster_shadow | 2);
}
else {
write_simaster(simaster_shadow & ~2);
}
}
static void set_clk_hi (void)
{
write_simaster(simaster_shadow | 4);
}
static void set_clk_lo (void)
{
write_simaster(simaster_shadow & ~4);
}
static void set_o (uchar level)
{
if (level) {
write_simaster(simaster_shadow | 1);
}
else {
write_simaster(simaster_shadow & ~1);
}
}
static uchar get_i (void)
{
return (((uchar) h2_read(SYSTEM, 0, SYS_SIMASTER) & 0x10) >> 4);
}
static void write_simaster (uchar value)
{
simaster_shadow = value;
h2_write(SYSTEM, 0, SYS_SIMASTER, simaster_shadow);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -