Better fix for hardware FCS error on JTAG reset

Correct silly error introduced by trying to save two bytes.
This commit is contained in:
David Kopf 2011-11-15 13:24:58 -05:00
parent 63e40d195e
commit fb977cb9ef
3 changed files with 27 additions and 23 deletions

View file

@ -232,13 +232,19 @@ hal_init(void)
// hal_reset_flags();
/*IO Specific Initialization - sleep and reset pins. */
/* Set pins low before they are initialized as output? Does not seem to matter */
// hal_set_rst_low();
// hal_set_slptr_low();
DDR_SLP_TR |= (1 << SLP_TR); /* Enable SLP_TR as output. */
DDR_RST |= (1 << RST); /* Enable RST as output. */
/*SPI Specific Initialization.*/
/* Set SS, CLK and MOSI as output. */
HAL_DDR_SPI |= (1 << HAL_DD_SS) | (1 << HAL_DD_SCK) | (1 << HAL_DD_MOSI);
/* To avoid a SPI glitch, the port register shall be set before the DDR register */
HAL_PORT_SPI |= (1 << HAL_DD_SS) | (1 << HAL_DD_SCK); /* Set SS and CLK high */
HAL_DDR_SPI |= (1 << HAL_DD_SS) | (1 << HAL_DD_SCK) | (1 << HAL_DD_MOSI);
HAL_DDR_SPI &=~ (1<< HAL_DD_MISO); /* MISO input */
/* Run SPI at max speed */
SPCR = (1 << SPE) | (1 << MSTR); /* Enable SPI module and master operation. */
SPSR = (1 << SPI2X); /* Enable doubled SPI speed in master mode. */

View file

@ -721,18 +721,29 @@ rf230_init(void)
{
uint8_t i;
DEBUGFLOW('i');
/* A jtag or brownout reset of the mcu tristates the RF230 control pins while
* it is in operation, which can result in a mulfunctioning condition when the
* radio is later re-initialized.
* This manifests as an incorrectly computed hardware FCS checksum.
* Setting up the pins before the poweron time delay seems to fix this.
*/
#if 1 //this works after a brownout or jtag reset
/* Initialize Hardware Abstraction Layer */
hal_init();
/* Wait in case VCC just applied */
delay_us(TIME_TO_ENTER_P_ON);
#else //this gives FCS errors 5 out of 6 times
/* Wait in case VCC just applied */
delay_us(TIME_TO_ENTER_P_ON);
/* Initialize Hardware Abstraction Layer */
hal_init();
#endif
/* Calibrate oscillator */
// printf_P(PSTR("\nBefore calibration OSCCAL=%x\n"),OSCCAL);
// calibrate_rc_osc_32k();
// printf_P(PSTR("After calibration OSCCAL=%x\n"),OSCCAL);
/* Initialize Hardware Abstraction Layer */
hal_init();
/* Set receive buffers empty and point to the first */
for (i=0;i<RF230_CONF_RX_BUFFERS;i++) rxframe[i].length=0;
rxframe_head=0;rxframe_tail=0;

View file

@ -167,19 +167,6 @@ uint8_t i,j;
/*------Done in a subroutine to keep main routine stack usage small--------*/
void initialize(void)
{
/* A jtag or brownout reset of the mcu tristates the RF230 control pins while
* it is in operation, which can result in a mulfunctioning condition when the
* radio is later re-initialized.
* This manifests as an incorrectly computed hardware FCS checksum.
* Setting up the pins as soon as possible after mcu reset seems to fix this.
* Additionally, hold the radio in reset to prevent premature rx interrupts.
*/
#if RF230BB
#include "radio/rf230bb/hal.h"
hal_init();
hal_set_rst_low();
#endif
watchdog_init();
watchdog_start();
@ -370,7 +357,7 @@ uint8_t i;
{
#if AVR_WEBSERVER
uint8_t i;
char buf[80];
char buf1[40],buf[40];
unsigned int size;
for (i=0;i<UIP_DS6_ADDR_NB;i++) {
@ -380,11 +367,11 @@ uint8_t i;
}
}
cli();
eeprom_read_block (buf,eemem_server_name, sizeof(eemem_server_name));
eeprom_read_block (buf1,eemem_server_name, sizeof(eemem_server_name));
eeprom_read_block (buf,eemem_domain_name, sizeof(eemem_domain_name));
sei();
buf[sizeof(eemem_server_name)]=0;
PRINTA("%s",buf);
buf1[sizeof(eemem_server_name)]=0;
PRINTA("%s",buf1);
buf[sizeof(eemem_domain_name)]=0;
size=httpd_fs_get_size();
#ifndef COFFEE_FILES
@ -491,7 +478,7 @@ main(void)
if ((clocktime%STAMPS)==0) {
#if ENERGEST_CONF_ON
#include "lib/print-stats.h"
// print_stats();
print_stats();
#elif RADIOSTATS
extern volatile unsigned long radioontime;
PRINTF("%u(%u)s\n",clocktime,radioontime);