--- a/drivers/can_virtual/Makefile.in Thu May 18 21:56:59 2006 +0200
+++ b/drivers/can_virtual/Makefile.in Fri May 19 20:20:06 2006 +0200
@@ -34,6 +34,7 @@
CAN_DRIVER = SUB_CAN_DRIVER
TIMERS_DRIVER = SUB_TIMERS_DRIVER
LED_ENABLE = SUB_LED_ENABLE
+NVRAM_ENABLE = SUB_NVRAM_ENABLE
INCLUDES = -I../../include -I../../include/$(TARGET) -I../../include/$(CAN_DRIVER) -I../../include/$(TIMERS_DRIVER)
@@ -43,6 +44,11 @@
TARGET_HFILES = $(PREFIX)/include/canfestival/cancfg.h
+ifeq ($(NVRAM_ENABLE),YES)
+OBJS += nvram.o
+SRC_HFILES += ../include/nvram.h
+endif
+
all: driver
driver: $(OBJS)
--- a/drivers/ecos_lpc2138_sja1000/canOpenDriver.c Thu May 18 21:56:59 2006 +0200
+++ b/drivers/ecos_lpc2138_sja1000/canOpenDriver.c Fri May 19 20:20:06 2006 +0200
@@ -155,48 +155,13 @@
int nvram_open(void)
{
- int n = NVRAM_BLOCK_SIZE / sizeof(unsigned int);
-
- /* some actions to initialise the flash */
- data_len = 0;
- data_num_pages = 0;
-
- data_page = (unsigned int *)malloc(sizeof(unsigned int) * n);
- memset(data_page, 0, sizeof(unsigned int)*n);
-
- if (data_page == NULL)
- return -1;
-
- regs_page = (unsigned int *)malloc(sizeof(unsigned int) * n);
- memset(regs_page, 0, sizeof(unsigned int)*n);
- if (regs_page == NULL)
- return -2;
-
- iat_flash_read_regs();
-
- /* start the data at the location specified in the registers */
- if (0) /* for now it is 0, but put here a test to know whether
- or not the NVRAM has been written before */
- data_addr = regs_page[1];
- else
- data_addr = NVRAM_BLOCK_SIZE; /* let start at block 1 */
-
- return 0;
+ return iat_init();
}
void nvram_close(void)
{
- /* write the last page before closing */
- iat_flash_write_page(data_addr);
-
- /* some actions to end accessing the flash */
- free(data_page);
-
- regs_page[4] = data_num_pages;
- /* write the registers to the NVRAM before closing */
- iat_flash_write_regs();
- free(regs_page);
+ iat_end();
}
@@ -206,7 +171,7 @@
}
-void nvram_new_firmwave()
+void nvram_new_firmware()
{
/*
this function is called whenever a new firmware is about
--- a/drivers/ecos_lpc2138_sja1000/lpc2138_pinout.h Thu May 18 21:56:59 2006 +0200
+++ b/drivers/ecos_lpc2138_sja1000/lpc2138_pinout.h Fri May 19 20:20:06 2006 +0200
@@ -1,19 +1,7 @@
/*
This file is part of CanFestival, a library implementing CanOpen Stack.
- ____ _ _ _
- / ___| / \ | \ | | ___ _ __ ___ _ __
-| | / _ \ | \| |/ _ \| '_ \ / _ \ '_ \
-| |___ / ___ \| |\ | (_) | |_) | __/ | | |
- \____/_/ \_\_| \_|\___/| .__/ \___|_| |_|
- |_|
- ____ _
- / ___|__ _ _ __ __ _ __| | __ _
- | | / _` | '_ \ / _` |/ _` |/ _` |
- | |__| (_| | | | | (_| | (_| | (_| |
- \____\__,_|_| |_|\__,_|\__,_|\__,_|
- canfestival@canopencanada.ca
-/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
+ Author: Christian Fortin (canfestival@canopencanada.ca)
See COPYING file for copyrights details.
@@ -94,13 +82,9 @@
#define LPC2138_ale_PORT P0
#define LPC2138_ale_SIZE 1
-#define LPC2138_redled 27 /* Pin 27 */
-#define LPC2138_redled_PORT P0
-#define LPC2138_redled_SIZE 1
-
-#define LPC2138_greenled 28 /* Pin 28 */
-#define LPC2138_greenled_PORT P0
-#define LPC2138_greenled_SIZE 1
+#define LPC2138_redgreenled 27 /* Pin 27 */
+#define LPC2138_redgreenled_PORT P0
+#define LPC2138_redgreenled_SIZE 2
#define LPC2138_rd 29 /* Pin 29 */
#define LPC2138_rd_PORT P0
--- a/drivers/ecos_lpc2138_sja1000/nvram_iap.c Thu May 18 21:56:59 2006 +0200
+++ b/drivers/ecos_lpc2138_sja1000/nvram_iap.c Fri May 19 20:20:06 2006 +0200
@@ -54,6 +54,53 @@
IAP iap_entry;
+int iat_init()
+{
+ int n = NVRAM_BLOCK_SIZE / sizeof(unsigned int);
+
+ /* some actions to initialise the flash */
+ data_len = 0;
+ data_num_pages = 0;
+
+ data_page = (unsigned int *)malloc(sizeof(unsigned int) * n);
+ memset(data_page, 0, sizeof(unsigned int)*n);
+
+ if (data_page == NULL)
+ return -1;
+
+ regs_page = (unsigned int *)malloc(sizeof(unsigned int) * n);
+ memset(regs_page, 0, sizeof(unsigned int)*n);
+ if (regs_page == NULL)
+ return -2;
+
+ iat_flash_read_regs();
+
+ /* start the data at the location specified in the registers */
+ if (0) /* for now it is 0, but put here a test to know whether
+ or not the NVRAM has been written before */
+ data_addr = regs_page[1];
+ else
+ data_addr = NVRAM_BLOCK_SIZE; /* let start at block 1 */
+
+ return 0;
+}
+
+
+void iat_end()
+{
+ /* write the last page before closing */
+ iat_flash_write_page(data_addr);
+
+ /* some actions to end accessing the flash */
+ free(data_page);
+
+ regs_page[4] = data_num_pages;
+ /* write the registers to the NVRAM before closing */
+ iat_flash_write_regs();
+ free(regs_page);
+}
+
+
/************************************************************************/
/* */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/ecos_lpc2138_sja1000/timerscfg.h Fri May 19 20:20:06 2006 +0200
@@ -0,0 +1,37 @@
+/*
+This file is part of CanFestival, a library implementing CanOpen Stack.
+
+Copyright (C): Edouard TISSERANT and Francis DUPIN
+
+See COPYING file for copyrights details.
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef __TIMERSCFG_H__
+#define __TIMERSCFG_H__
+
+#include <pthread.h>
+
+// Time unit : us
+// Time resolution : 64bit (~584942 years)
+// #define TIMEVAL unsigned long long
+// #define TIMEVAL_MAX 0xffffffffffffffff
+// #define MS_TO_TIMEVAL(ms) ms*1000
+// #define US_TO_TIMEVAL(us) us
+
+#define TASK_HANDLE pthread_t
+
+#endif
--- a/drivers/nvram_file/nvram_file.c Thu May 18 21:56:59 2006 +0200
+++ b/drivers/nvram_file/nvram_file.c Fri May 19 20:20:06 2006 +0200
@@ -0,0 +1,114 @@
+#include <stdio.h>
+
+
+/* size of NVRAM in bytes */
+#define NVRAM_MAX_SIZE 262144
+
+/* size of block in byte */
+#define NVRAM_BLOCK_SIZE 256
+
+#define NVRAM_FILE_NAME "__nvram__"
+
+FILE *nvram_file = NULL;
+
+
+void iat_flash_read_regs();
+void iat_flash_write_regs();
+void iat_flash_write_page(unsigned int);
+void iat_flash_read_page(unsigned int);
+
+
+short data_len; /* 0 to NVRAM_BLOCK_SIZE bytes */
+short data_num_pages;
+unsigned int *data_page = NULL;
+unsigned int data_addr;
+
+unsigned int *regs_page = NULL;
+
+int iat_init()
+{
+ int i;
+
+ nvram_file = fopen(NVRAM_FILE_NAME, "wr");
+ if (nvram_file == NULL)
+ return -1;
+
+ int n = NVRAM_BLOCK_SIZE / sizeof(unsigned int);
+
+ /* some actions to initialise the flash */
+ data_len = 0;
+ data_num_pages = 0;
+
+ data_page = (unsigned int *)malloc(sizeof(unsigned int) * n);
+ memset(data_page, 0, sizeof(unsigned int)*n);
+
+ if (data_page == NULL)
+ return -1;
+
+ regs_page = (unsigned int *)malloc(sizeof(unsigned int) * n);
+ memset(regs_page, 0, sizeof(unsigned int)*n);
+ if (regs_page == NULL)
+ return -2;
+
+ iat_flash_read_regs();
+
+ /* start the data at the location specified in the registers */
+ if (0) /* for now it is 0, but put here a test to know whether
+ or not the NVRAM has been written before */
+ data_addr = regs_page[1];
+ else
+ data_addr = NVRAM_BLOCK_SIZE; /* let start at block 1 */
+
+ /* create a file the size of the simulated NVRAM */
+ for(i=0; i<NVRAM_MAX_SIZE/NVRAM_BLOCK_SIZE + 1; i++)
+ fwrite(data_page, sizeof(unsigned int), n, nvram_file);
+
+ return 0;
+}
+
+
+void iat_end()
+{
+ iat_flash_write_page(data_addr);
+
+ iat_flash_write_regs();
+
+ fclose(nvram_file);
+}
+
+
+void iat_flash_read_regs()
+{
+ fseek(nvram_file, 0, SEEK_SET);
+ fread(regs_page, sizeof(unsigned int), NVRAM_BLOCK_SIZE, nvram_file);
+}
+
+
+void iat_flash_write_regs()
+{
+ fseek(nvram_file, 0, SEEK_SET);
+ fwrite(regs_page, sizeof(unsigned int), NVRAM_BLOCK_SIZE, nvram_file);
+}
+
+
+void iat_flash_read_page(unsigned int addr)
+{
+ fseek(nvram_file, addr*sizeof(unsigned int), SEEK_SET);
+ fread(data_page, sizeof(unsigned int), NVRAM_BLOCK_SIZE, nvram_file);
+}
+
+
+void iat_flash_write_page(unsigned int addr)
+{
+ fseek(nvram_file, addr*sizeof(unsigned int), SEEK_SET);
+ fwrite(data_page, sizeof(unsigned int), NVRAM_BLOCK_SIZE, nvram_file);
+}
+
+
+/*------------------------------------------------------*/
+int main()
+{
+ iat_init();
+ iat_end();
+}
+/*------------------------------------------------------*/