drivers/ecos_lpc2138_sja1000/canOpenDriver.c
author etisserant
Wed, 10 May 2006 21:05:57 +0200
changeset 1 b3dc740b4b04
parent 0 4472ee7c6c3e
child 3 d9cf34cd6823
permissions -rw-r--r--
Commit some Fix from Francis on sdo.c and abjacces.c. Fix endianisation problems while accessing OD. Also fix SDO abord handling bug.
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
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
	/* some actions to initialise the flash */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
	data_len = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
	data_addr = 0; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
	data_page = (unsigned int *)malloc(sizeof(unsigned int) * 64);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
	memset(data_page, 0, sizeof(unsigned int)*64);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
	if (data_page == NULL)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
		return -1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
void nvram_close(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
	/* some actions to end accessing the flash */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
	free(data_page);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
int _get_data_len(int type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
	int len = 0; /* number of bytes */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
	switch(type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
		case  boolean:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
			len = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
		case  int8:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
		case  uint8:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
			len = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
		case  int16:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
		case  uint16:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
			len = 2;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
		case  int24:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
		case  uint24:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
			len = 3;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
		case  int32:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
		case  uint32:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
		case  real32:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
			len = 4;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
		case  int40:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
		case  uint40:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
			len = 5;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
		case  int48:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
		case  uint48:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
			len = 6;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
		case  int56:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
		case  uint56:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
			len = 7;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
		case  int64:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
		case  uint64:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
		case  real64:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
			len = 8;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
#if 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
/* TO DO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
		case  visible_string:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
		case  octet_string:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
		case  unicode_string:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
		case  time_of_day:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
		case  time_difference:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
#endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
	return len;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
char nvram_write(int type, int access_attr, void *data)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
/* return 0 if successfull */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
	int len = _get_data_len(type);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
	if (data_len+len > 256)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
		iat_flash_write_page(data_addr);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
		data_len = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
		data_addr += 256;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
	memcpy(((char *)data_page)+data_len, data, len);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
	data_len += len;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
char nvram_read(int type, int access_attr, void *data)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
/* return 0 if successful */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
	int len = _get_data_len(type);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
	if (data_len+len > 256)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
		data_addr += 256;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
		iat_flash_read_page(data_addr);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
		data_len = 0;		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
	memcpy(data, ((char *)data_page)+data_len, len);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
	data_len += len;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
	LED
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
void led_set_redgreen(unsigned char bits)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
	lpc2138_redgreenled_set(bits);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284