drivers/ecos_lpc2138_sja1000/canOpenDriver.c
author frdupin
Tue, 19 Dec 2006 16:30:57 +0100
changeset 60 a8723422e0dd
parent 18 2fc8aa46980b
permissions -rw-r--r--
prototypes in c-ansi style
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
 Author: Christian Fortin (canfestival@canopencanada.ca)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    22
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
#include <stdlib.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
#include <sys/time.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
#include <signal.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
#include <cyg/kernel/kapi.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
#include <cyg/hal/hal_arch.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
#include "applicfg.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
#include <data.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
#include <def.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
#include <can.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
#include <can_driver.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
#include <objdictdef.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
#include <objacces.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
#include "lpc2138_pinout.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
#include "lpc2138_defs.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
#include "lpc2138.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
#include "sja1000.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
#include "time_slicer.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
	SEND/RECEIVE
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
CAN_HANDLE canOpen(s_BOARD *board)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
	return NULL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
int canClose(CAN_HANDLE fd0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
UNS8 canReceive(CAN_HANDLE fd0, Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
Message *m :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
	typedef struct {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
	  SHORT_CAN cob_id;     // l'ID du mesg
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
	  UNS8 rtr;             // remote transmission request. 0 if not rtr,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
        	                // 1 for a rtr message
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
	  UNS8 len;             // message length (0 to 8)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
	  UNS8 data[8];         // data
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
	} Message;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
Fill the structure "Message" with data from the CAN receive buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
return : 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
	the sja1000 must be set to the PeliCAN mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
    m->cob_id.w = sja1000_read(16) + (sja1000_read(17)<<8); // IO_PORTS_16(CAN0 + CANRCVID) >> 5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
    m->rtr = (sja1000_read(17) >> 4) & 0x01; // (IO_PORTS_8(CAN0 + CANRCVID + 1) >> 4) & 0x01; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
    m->len = sja1000_read(18);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
    m->data[0] = sja1000_read(19);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
    m->data[1] = sja1000_read(20);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
    m->data[2] = sja1000_read(21);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
    m->data[3] = sja1000_read(22);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
    m->data[4] = sja1000_read(23);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
    m->data[5] = sja1000_read(24);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
    m->data[6] = sja1000_read(25);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
    m->data[7] = sja1000_read(26);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
    sja1000_write(CMR, 1<<RRB );        // release fifo
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
    return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
UNS8 canSend(CAN_HANDLE fd0, Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
Message *m :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
	typedef struct {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
	  SHORT_CAN cob_id;     // l'ID du mesg
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
	  UNS8 rtr;                     // remote transmission request. 0 if not rtr,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
        	                        // 1 for a rtr message
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
	  UNS8 len;                     // message length (0 to 8)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
	  UNS8 data[8];         // data
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
	} Message;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
Send the content of the structure "Message" to the CAN transmit buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
return : 0 if OK, 1 if error
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
    unsigned char rec_buf;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
    do
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
        rec_buf = sja1000_read(SR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
    while ( (rec_buf & (1<<TBS))==0);           // loop until TBS high
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
    sja1000_write(16, m->cob_id.w & 0xff); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
    sja1000_write(17, (m->cob_id.w >> 8) & 0xff);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
    sja1000_write(18, m->len);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
    sja1000_write(19, m->data[0]); // tx data 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
    sja1000_write(20, m->data[1]); // tx data 2
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
    sja1000_write(21, m->data[2]); // tx data 3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
    sja1000_write(22, m->data[3]); // tx data 4
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
    sja1000_write(23, m->data[4]); // tx data 5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
    sja1000_write(24, m->data[5]); // tx data 6
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
    sja1000_write(25, m->data[6]); // tx data 7
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
    sja1000_write(26, m->data[7]); // tx data 8
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
    sja1000_write(CMR,( (0<<SRR) | (0<<CDO) | (0<<RRB) | (0<<AT) | (1<<TR)));
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
    do
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
        rec_buf = sja1000_read(SR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
    while ( (rec_buf & (1<<TBS))==0);           // loop until TBS high
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
    return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
	SEQUENTIAL I/O TO FLASH
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
	those functions are for continous writing and read
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
int nvram_open(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
{
18
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
   158
	return iat_init();
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
void nvram_close(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
{
18
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
   164
	iat_end();
3
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   165
}
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   166
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   167
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   168
void nvram_set_pos(UNS32 pos)
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   169
/* set the current position in the NVRAM to pos */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   170
{
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   171
}
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   172
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   173
18
2fc8aa46980b First version of NVRAM implemented on the file system for can_virtual
oremeq
parents: 3
diff changeset
   174
void nvram_new_firmware()
3
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   175
{
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   176
/*
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   177
	this function is called whenever a new firmware is about
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   178
	to be written in the NVRAM
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   179
*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   180
	data_addr = regs_page[1] + regs_page[4]*NVRAM_BLOCK_SIZE;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   181
	if (data_addr > NVRAM_MAX_SIZE)
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   182
		data_addr = NVRAM_BLOCK_SIZE;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
int _get_data_len(int type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
	int len = 0; /* number of bytes */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
	switch(type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
		case  boolean:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
			len = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
		case  int8:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
		case  uint8:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
			len = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
		case  int16:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
		case  uint16:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
			len = 2;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
		case  int24:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
		case  uint24:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
			len = 3;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
		case  int32:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
		case  uint32:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
		case  real32:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
			len = 4;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
		case  int40:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
		case  uint40:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
			len = 5;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
		case  int48:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
		case  uint48:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
			len = 6;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
		case  int56:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
		case  uint56:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
			len = 7;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
		case  int64:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
		case  uint64:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
		case  real64:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
			len = 8;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
#if 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
/* TO DO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
		case  visible_string:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
		case  octet_string:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
		case  unicode_string:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
		case  time_of_day:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
		case  time_difference:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
#endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
	return len;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
3
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   242
char nvram_write_data(int type, int access_attr, void *data)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
/* return 0 if successfull */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
	int len = _get_data_len(type);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
3
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   247
	if (data_len+len > NVRAM_BLOCK_SIZE)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
		iat_flash_write_page(data_addr);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
		data_len = 0;
3
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   251
		data_addr += NVRAM_BLOCK_SIZE; 
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   252
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   253
		/* wrap-around address pointer */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   254
		if (data_addr > NVRAM_MAX_SIZE)
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   255
			data_addr = NVRAM_BLOCK_SIZE;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   256
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   257
		data_num_pages++;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
	memcpy(((char *)data_page)+data_len, data, len);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
	data_len += len;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
3
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   268
char nvram_read_data(int type, int access_attr, void *data)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
/* return 0 if successful */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
	int len = _get_data_len(type);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
3
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   273
	if (data_len+len > NVRAM_BLOCK_SIZE)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
	{
3
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   275
		data_addr += NVRAM_BLOCK_SIZE;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   276
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   277
		/* wrap-around address pointer */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   278
		if (data_addr > NVRAM_MAX_SIZE)
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   279
			data_addr = NVRAM_BLOCK_SIZE;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   280
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
		iat_flash_read_page(data_addr);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
		data_len = 0;		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
	memcpy(data, ((char *)data_page)+data_len, len);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
	data_len += len;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
3
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   292
/*
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   293
	NVRAM registers at block 0
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   294
	pos        description
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   295
	0          version of the current dictionnary
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   296
	1          starting address for data block
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   297
	2          date of last writing
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   298
	3          address of the previous dictionnary          
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   299
	4          size in pages of the current dict
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   300
*/
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   301
void nvram_write_reg(UNS32 reg, UNS16 pos)
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   302
/* write reg at the position in the data block 0 */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   303
{
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   304
	regs_page[pos] = reg;
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   305
}
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   306
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   307
UNS32 nvram_read_reg(UNS16 pos)
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   308
/* read reg at the position in the data block 0 */
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   309
{
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   310
	return regs_page[pos];
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   311
}
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   312
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   313
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
	LED
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
3
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   318
void led_set_redgreen(UNS8 bits)
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   319
/* bits : each bit of this uns8 is assigned a led 
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   320
          0=off, 1=on
d9cf34cd6823 ADDED LED to TESTMASTERSLAVE. It looks nice!
oremeq
parents: 0
diff changeset
   321
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   323
	lpc2138_redgreenled_set(bits);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   324
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   325