Mercurial > nand-ecoscentric
annotate packages/devs/can/arm/lpc2xxx/current/src/can_accfilt_lpc2xxx.c @ 3345:b06697684f0a
* src/can_accfilt_lpc2xxx.c, src/can_lpc2xxx.c: Fix a compile issue of
the lpc2xxx driver that only occurs if support for extended 29-bit CAN
identifiers is enabled and support for message filtering is disabled.
[ Bugzilla 1001901 ]
* includes/can_lpc2xxx_baudrates.h: Added baudrate table for CAN clock
of 14.745600 MHz. [ Bugzilla 1001900 ]
| author | sergeig |
|---|---|
| date | Wed, 11 Sep 2013 21:00:16 +0000 |
| parents | 74dbf4c3f2e1 |
| children |
| rev | line source |
|---|---|
| 2409 | 1 //========================================================================== |
| 2 // | |
| 3 // devs/can/arm/lpc2xxx/current/src/can_accfilt_lpc2xxx.c | |
| 4 // | |
| 5 // Acceptance filter management for LPC2xxx CAN driver | |
| 6 // | |
| 7 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
9 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
| 2409 | 12 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
13 // eCos is free software; you can redistribute it and/or modify it under |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
14 // the terms of the GNU General Public License as published by the Free |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
15 // Software Foundation; either version 2 or (at your option) any later |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
16 // version. |
| 2409 | 17 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
18 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
21 // for more details. |
| 2409 | 22 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
23 // You should have received a copy of the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
24 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 2409 | 26 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
27 // As a special exception, if other files instantiate templates or use |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
28 // macros or inline functions from this file, or you compile this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
29 // and link it with other works to produce a work based on this file, |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
30 // this file does not by itself cause the resulting work to be covered by |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
31 // the GNU General Public License. However the source code for this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
32 // must still be made available in accordance with section (3) of the GNU |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
33 // General Public License v2. |
| 2409 | 34 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
35 // This exception does not invalidate any other reasons why a work based |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
36 // on this file might be covered by the GNU General Public License. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
37 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2509
diff
changeset
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
| 2409 | 39 //========================================================================== |
| 40 //#####DESCRIPTIONBEGIN#### | |
| 41 // | |
| 42 // Author(s): Uwe Kindler | |
| 43 // Contributors: Uwe Kindler | |
| 44 // Date: 2007-05-28 | |
| 45 // Purpose: Support LPC2xxx on-chip CAN acceptance filters | |
| 46 // Description: | |
| 47 // | |
| 48 //####DESCRIPTIONEND#### | |
| 49 // | |
| 50 //========================================================================== | |
| 51 | |
| 52 | |
| 53 //=========================================================================== | |
| 54 // Data types | |
| 55 //=========================================================================== | |
| 56 // | |
| 57 // Acceptance filter entry | |
| 58 // | |
| 59 typedef struct lpc2xxx_accfilt_entry | |
| 60 { | |
| 61 cyg_uint32 data; // the value inclusive channel number | |
| 62 cyg_uint32 id; | |
| 63 cyg_uint32 lower_id_bound; | |
| 64 cyg_uint32 upper_id_bound; | |
| 65 cyg_uint8 channel_no; | |
| 66 } lpc2xxx_accfilt_entry_t; | |
| 67 | |
| 68 | |
| 69 //=========================================================================== | |
| 70 // Declarations | |
| 71 //=========================================================================== | |
| 72 //-------------------------------------------------------------------------- | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
73 // On no-suffix and /00 devices, the CAN controllers are numbered 1 to n |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
74 // (n = 2 or 4) in the LUT tables. However, on /01 devices, the CAN controllers |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
75 // are numbered 0 to n�1 in the LUT tables. |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
76 // |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
77 // On the LPC2468 the LUT channel numbers are also numbered from 0 - 4. |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
78 // |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
79 #if defined(CYGHWR_HAL_ARM_LPC2XXX_SUFFIX_01) || (CYGHWR_HAL_ARM_LPC2XXX_VARIANT_VERSION == 4) |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
80 # define LPC2XXX_CAN_FIRST_IN_LUT (0) |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
81 #else |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
82 # define LPC2XXX_CAN_FIRST_IN_LUT (1) |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
83 #endif |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
84 |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
85 // |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
86 // This macro calculates the chanel number from the channel info. The channel |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
87 // number is numbered from 0 - 3 but in the LUT the channel number may differ |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
88 // depending on the device suffix. For some devices the channel number in |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
89 // LUT are numbered 0 - 3 and for other devices the channels in LUT are |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
90 // numbered 1 - 4. This macro abstrats this fact from the acceptance filter |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
91 // code |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
92 // |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
93 #define CAN_CHAN_NO_LUT(_info_) (CAN_CHAN_NO(_info_) + LPC2XXX_CAN_FIRST_IN_LUT) |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
94 |
|
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
95 //-------------------------------------------------------------------------- |
| 2409 | 96 // Lowlevel acceptance filter access |
| 97 // | |
| 98 #ifdef CYGOPT_IO_CAN_RUNTIME_MBOX_CFG | |
| 99 static bool lpc2xxx_can_accfilt_add(lpc2xxx_can_info_t *info, | |
| 100 cyg_uint32 lower_id, | |
| 101 cyg_uint32 upper_id, | |
| 102 cyg_can_id_type ext); | |
| 103 void lpc2xxx_can_accfilt_ram_insert_entry(cyg_uint32 TableAddress, cyg_uint16 EntryNo); | |
| 104 void lpc2xxx_can_accfilt_ram_remove_entry(cyg_uint32 TableAddress, cyg_uint16 EntryNo); | |
| 105 void lpc2xxx_can_accfilt_remove_all_ctrl_entries(lpc2xxx_can_info_t *info); | |
| 106 #else | |
| 107 static void lpc2xxx_can_accfilt_simple_rx_all(void); | |
| 108 #endif // CYGOPT_IO_CAN_RUNTIME_MBOX_CFG | |
| 109 void lpc2xxx_can_accfilt_reset(void); | |
| 110 | |
| 111 #ifdef CYGDBG_DEVS_CAN_LPC2XXX_DEBUG | |
| 112 void lpc2xxx_can_accfilt_dbg_dump(void); | |
| 113 void lpc2xxx_can_reg_dump(struct cyg_devtab_entry* devtab_entry); | |
| 114 #endif | |
| 115 | |
| 116 | |
| 117 #ifdef CYGOPT_IO_CAN_RUNTIME_MBOX_CFG | |
| 118 //=========================================================================== | |
| 119 // Calculate address of entry in certain table | |
| 120 //=========================================================================== | |
| 121 static cyg_uint32 lpc2xxx_can_accfilt_calc_entry_address(cyg_uint32 TableAddressRegister, cyg_uint16 EntryNo) | |
| 122 { | |
| 123 cyg_uint32 EntryAddress = 0xFFFFFFFF; | |
| 124 cyg_uint32 TableAddress; | |
| 125 | |
| 126 HAL_READ_UINT32(TableAddressRegister, TableAddress); | |
| 127 switch (TableAddressRegister) | |
| 128 { | |
| 129 #ifdef CYGOPT_IO_CAN_STD_CAN_ID | |
| 130 case CAN_ACCFILT_SFF_SA: | |
| 131 EntryAddress = ((EntryNo / 2) << 2) + TableAddress; | |
| 132 break; | |
| 133 | |
| 134 case CAN_ACCFILT_SFF_GRP_SA: | |
| 135 EntryAddress = TableAddress + (EntryNo << 2); | |
| 136 break; | |
| 137 #endif // CYGOPT_IO_CAN_STD_CAN_ID | |
| 138 | |
| 139 #ifdef CYGOPT_IO_CAN_EXT_CAN_ID | |
| 140 case CAN_ACCFILT_EFF_SA: | |
| 141 EntryAddress = TableAddress + (EntryNo << 2); | |
| 142 break; | |
| 143 | |
| 144 case CAN_ACCFILT_EFF_GRP_SA: | |
| 145 EntryAddress = TableAddress + (EntryNo << 3); | |
| 146 break; | |
| 147 #endif // CYGOPT_IO_CAN_EXT_CAN_ID | |
| 148 default: | |
| 149 CYG_ASSERT(0, "Wrong TableAddressRegister"); | |
| 150 } | |
| 151 | |
| 152 return EntryAddress; | |
| 153 } | |
| 154 | |
| 155 | |
| 156 //=========================================================================== | |
| 157 // Remove one single entry from acceptance filter table | |
| 158 //=========================================================================== | |
| 159 void lpc2xxx_can_accfilt_ram_remove_entry(cyg_uint32 Table, cyg_uint16 EntryNo) | |
| 160 { | |
| 161 cyg_int32 remove_address = lpc2xxx_can_accfilt_calc_entry_address(Table, EntryNo); | |
| 162 cyg_int32 entry_address; | |
| 163 lsc_buf_t lsc_val; | |
| 164 cyg_uint8 entry_size = sizeof(cyg_uint32); | |
| 165 cyg_uint32 sff_sa; | |
| 166 cyg_uint32 sff_grp_sa; | |
| 167 cyg_uint32 eff_sa; | |
| 168 cyg_uint32 eff_grp_sa; | |
| 169 cyg_int32 end_of_table; | |
| 170 | |
| 171 HAL_READ_UINT32(CAN_ACCFILT_SFF_SA, sff_sa); | |
| 172 HAL_READ_UINT32(CAN_ACCFILT_SFF_GRP_SA, sff_grp_sa); | |
| 173 HAL_READ_UINT32(CAN_ACCFILT_EFF_SA, eff_sa); | |
| 174 HAL_READ_UINT32(CAN_ACCFILT_EFF_GRP_SA, eff_grp_sa); | |
| 175 HAL_READ_UINT32(CAN_ACCFILT_ENDOFTABLE, end_of_table); | |
| 176 | |
| 177 // | |
| 178 // Do not try to remove from an empty table | |
| 179 // | |
| 180 if (!end_of_table) | |
| 181 { | |
| 182 return; | |
| 183 } | |
| 184 | |
| 185 entry_address = remove_address; | |
| 186 | |
| 187 if ((remove_address < eff_grp_sa) && (CAN_ACCFILT_EFF_GRP_SA != Table)) | |
| 188 { | |
| 189 if ((remove_address < eff_sa) && (CAN_ACCFILT_EFF_SA != Table)) | |
| 190 { | |
| 191 if ((remove_address < sff_grp_sa) && (CAN_ACCFILT_SFF_GRP_SA != Table)) | |
| 192 { | |
| 193 lsc_buf_t nextval; | |
| 194 | |
| 195 if (EntryNo % 2) | |
| 196 { | |
| 197 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + remove_address, lsc_val.dword); | |
| 198 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + remove_address + sizeof(cyg_uint32), nextval.dword); | |
| 199 lsc_val.column.upper = nextval.column.lower; | |
| 200 entry_address += sizeof(cyg_uint32); | |
| 201 } | |
| 202 | |
| 203 // | |
| 204 // Start copy immediatelly after removed entry | |
| 205 // | |
| 206 while (entry_address < sff_grp_sa) | |
| 207 { | |
| 208 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + entry_address, lsc_val.dword); | |
| 209 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + entry_address + sizeof(cyg_uint32), nextval.dword); | |
| 210 lsc_val.column.lower = lsc_val.column.upper; | |
| 211 lsc_val.column.upper = nextval.column.lower; | |
| 212 HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + entry_address, lsc_val.dword); | |
| 213 entry_address += sizeof(cyg_uint32); | |
| 214 } | |
| 215 | |
| 216 // | |
| 217 // now check if the lower identifier is disabled - if it is disabled, then | |
| 218 // also the upper identifier is invalid and we can remove the entry completely | |
| 219 // if the lower identifier is not disabled, then it is valid and we need | |
| 220 // to disable the upper identifier because it contains an invalid entry | |
| 221 // | |
| 222 if (lsc_val.column.lower & ACCFILT_STD_DIS) | |
| 223 { | |
| 224 sff_grp_sa -= sizeof(cyg_uint32); | |
| 225 entry_address = sff_grp_sa; | |
| 226 } | |
| 227 else | |
| 228 { | |
| 229 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + sff_grp_sa - sizeof(cyg_uint32), lsc_val.dword); | |
| 230 lsc_val.column.upper = 0xffff; | |
| 231 HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + sff_grp_sa - sizeof(cyg_uint32), lsc_val.dword); | |
| 232 entry_size = 0; // we do not need to remove anything | |
| 233 } | |
| 234 } // if (pLine < pStdGrpStart) | |
| 235 | |
| 236 eff_sa -= entry_size; | |
| 237 } // if (pLine < pExtIdStart) | |
| 238 | |
| 239 eff_grp_sa -= entry_size; | |
| 240 } // if (pLine < pExtGrpStart) | |
| 241 | |
| 242 // | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
243 // If no entry was removed then we can leave immediately without changing any |
| 2409 | 244 // table pointers because we only did a change inside the sff table |
| 245 // | |
| 246 if (!entry_size) | |
| 247 { | |
| 248 #ifdef CYGDBG_DEVS_CAN_LPC2XXX_DEBUG | |
| 249 lpc2xxx_can_accfilt_dbg_dump(); | |
| 250 #endif | |
| 251 return; | |
| 252 } | |
| 253 | |
| 254 if (CAN_ACCFILT_EFF_GRP_SA == Table) | |
| 255 { | |
| 256 // | |
| 257 // If we are in the area of extended groups then we need to remove | |
| 258 // 2 lines because lower and upper identifier need 1 line each | |
| 259 // | |
| 260 entry_size += sizeof(cyg_uint32); | |
| 261 } | |
| 262 | |
| 263 end_of_table -= entry_size; | |
| 264 | |
| 265 // | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
266 // Move all entries one or two dword downwards - that means we remove a line |
| 2409 | 267 // |
| 268 while (entry_address < end_of_table) | |
| 269 { | |
| 270 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + entry_address + entry_size, lsc_val.dword); | |
| 271 HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + entry_address, lsc_val.dword); | |
| 272 entry_address += sizeof(cyg_uint32); | |
| 273 } | |
| 274 | |
| 275 HAL_WRITE_UINT32(CAN_ACCFILT_SFF_SA, sff_sa); | |
| 276 HAL_WRITE_UINT32(CAN_ACCFILT_SFF_GRP_SA, sff_grp_sa); | |
| 277 HAL_WRITE_UINT32(CAN_ACCFILT_EFF_SA, eff_sa); | |
| 278 HAL_WRITE_UINT32(CAN_ACCFILT_EFF_GRP_SA, eff_grp_sa); | |
| 279 HAL_WRITE_UINT32(CAN_ACCFILT_ENDOFTABLE, end_of_table); | |
| 280 | |
| 281 #ifdef CYGDBG_DEVS_CAN_LPC2XXX_DEBUG | |
| 282 lpc2xxx_can_accfilt_dbg_dump(); | |
| 283 #endif | |
| 284 } | |
| 285 | |
| 286 //=========================================================================== | |
| 287 // Insert one empty line into ram - all entries behind this line will be | |
| 288 // moved one entry upwards | |
| 289 //=========================================================================== | |
| 290 void lpc2xxx_can_accfilt_ram_insert_entry(cyg_uint32 Table, cyg_uint16 EntryNo) | |
| 291 { | |
| 292 cyg_int16 insert_address = lpc2xxx_can_accfilt_calc_entry_address(Table, EntryNo); | |
| 293 cyg_int16 entry_address; | |
| 294 cyg_int16 copy_start = insert_address; | |
| 295 lsc_buf_t lsc_val; | |
| 296 cyg_uint8 entry_size = sizeof(cyg_uint32); | |
| 297 cyg_uint32 sff_sa; | |
| 298 cyg_uint32 sff_grp_sa; | |
| 299 cyg_uint32 eff_sa; | |
| 300 cyg_uint32 eff_grp_sa; | |
| 301 cyg_uint32 end_of_table; | |
| 302 | |
| 303 | |
| 304 HAL_READ_UINT32(CAN_ACCFILT_SFF_SA, sff_sa); | |
| 305 HAL_READ_UINT32(CAN_ACCFILT_SFF_GRP_SA, sff_grp_sa); | |
| 306 HAL_READ_UINT32(CAN_ACCFILT_EFF_SA, eff_sa); | |
| 307 HAL_READ_UINT32(CAN_ACCFILT_EFF_GRP_SA, eff_grp_sa); | |
| 308 HAL_READ_UINT32(CAN_ACCFILT_ENDOFTABLE, end_of_table); | |
| 309 | |
| 310 if ((insert_address <= eff_grp_sa) && (CAN_ACCFILT_EFF_GRP_SA != Table)) | |
| 311 { | |
| 312 if ((insert_address <= eff_sa) && (CAN_ACCFILT_EFF_SA != Table)) | |
| 313 { | |
| 314 if ((insert_address <= sff_grp_sa) && (CAN_ACCFILT_SFF_GRP_SA != Table)) | |
| 315 { | |
| 316 // | |
| 317 // If we are in the range of standard identifiers then we need to | |
| 318 // do some special copy procedure for this area because a standard entry | |
| 319 // is only 2 byte long. Copy only til start of area with standard groups | |
| 320 // | |
| 321 if (sff_grp_sa) | |
| 322 { | |
| 323 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + sff_grp_sa - sizeof(cyg_uint32), lsc_val.dword); // read last entry | |
| 324 // | |
| 325 // now check if the upper identifier is disabled - if it is disabled, then | |
| 326 // we have an odd number of std ids in the list. Then we do not need to | |
| 327 // insert a new line - we simply need to copy all entries 2 bytes upwards | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
328 // that means we only need to change the std id area and do not need to touch |
| 2409 | 329 // any other filter id area. |
| 330 // If the last entry is not disabled, then we have a valid filter here. | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
331 // Then we need to insert a complete new line, that means we also have to move |
| 2409 | 332 // all following entries and filter tables one dword upwards. |
| 333 // | |
| 334 if (lsc_val.words.low & ACCFILT_STD_DIS) | |
| 335 { | |
| 336 copy_start = end_of_table + sizeof(cyg_uint32); // we do not need to insert a new line and do not copy anything | |
| 337 entry_size = 0; | |
| 338 } | |
| 339 } | |
| 340 | |
| 341 if (entry_size) | |
| 342 { | |
| 343 copy_start = sff_grp_sa; // copy everything behind std id group | |
| 344 sff_grp_sa += entry_size; | |
| 345 } | |
| 346 } // if (pLine < pStdGrpStart) | |
| 347 | |
| 348 eff_sa += entry_size; | |
| 349 } // if (pLine < pExtIdStart) | |
| 350 | |
| 351 eff_grp_sa += entry_size; | |
| 352 } // if (pLine < pExtGrpStart) | |
| 353 | |
| 354 if (CAN_ACCFILT_EFF_GRP_SA == Table) | |
| 355 { | |
| 356 // | |
| 357 // If we are in the area of extended groups then we need to insert | |
| 358 // 2 lines because lower and upper identifier need 1 line each | |
| 359 // | |
| 360 entry_size += sizeof(cyg_uint32); // one entry is 2 dword long | |
| 361 } | |
| 362 | |
| 363 entry_address = end_of_table - sizeof(cyg_uint32); | |
| 364 end_of_table += entry_size; // add one additional entry | |
| 365 | |
| 366 // | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
367 // Move all entries one or two dwords upwards - that means we insert a new empty line |
| 2409 | 368 // |
| 369 while (entry_address >= copy_start) | |
| 370 { | |
| 371 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + (cyg_uint32)entry_address, lsc_val.dword); | |
| 372 HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + (cyg_uint32)entry_address + entry_size, lsc_val.dword); | |
| 373 entry_address -= sizeof(cyg_uint32); | |
| 374 } | |
| 375 | |
| 376 // | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
377 // For the std ID area we need a special procedure |
| 2409 | 378 // |
| 379 if (CAN_ACCFILT_SFF_SA == Table) | |
| 380 { | |
| 381 lsc_buf_t preval; | |
| 382 // | |
| 383 // Start copy with last entry of std id table | |
| 384 // | |
| 385 entry_address = sff_grp_sa - sizeof(cyg_uint32); | |
| 386 | |
| 387 while (entry_address > insert_address) | |
| 388 { | |
| 389 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + (cyg_uint32)entry_address, lsc_val.dword); | |
| 390 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + (cyg_uint32)entry_address - sizeof(cyg_uint32), preval.dword); | |
| 391 lsc_val.column.upper = lsc_val.column.lower; | |
| 392 lsc_val.column.lower = preval.column.upper; | |
| 393 HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + (cyg_uint32)entry_address, lsc_val.dword); | |
| 394 entry_address -= sizeof(cyg_uint32); | |
| 395 } | |
| 396 | |
| 397 // | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
398 // If we insert an entry into the lower column, then we need to move the |
| 2409 | 399 // content of the lower column into the upper column |
| 400 // | |
| 401 if (!(EntryNo % 2)) | |
| 402 { | |
| 403 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + (cyg_uint32)insert_address, lsc_val.dword); | |
| 404 lsc_val.column.upper = lsc_val.column.lower; | |
| 405 HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + (cyg_uint32)insert_address, lsc_val.dword); | |
| 406 } | |
| 407 | |
| 408 // | |
| 409 // If we inserted a new line, then we have an odd number of identifiers now | |
| 410 // and need to disable the last (the upper) entry | |
| 411 // | |
| 412 if (entry_size) | |
| 413 { | |
| 414 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + sff_grp_sa - sizeof(cyg_uint32) , lsc_val.dword); | |
| 415 lsc_val.column.upper = 0xFFFF; // disable the entry | |
| 416 HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + sff_grp_sa - sizeof(cyg_uint32) , lsc_val.dword); | |
| 417 } | |
| 418 } | |
| 419 | |
| 420 HAL_WRITE_UINT32(CAN_ACCFILT_SFF_SA, sff_sa); | |
| 421 HAL_WRITE_UINT32(CAN_ACCFILT_SFF_GRP_SA, sff_grp_sa); | |
| 422 HAL_WRITE_UINT32(CAN_ACCFILT_EFF_SA, eff_sa); | |
| 423 HAL_WRITE_UINT32(CAN_ACCFILT_EFF_GRP_SA, eff_grp_sa); | |
| 424 HAL_WRITE_UINT32(CAN_ACCFILT_ENDOFTABLE, end_of_table); | |
| 425 } | |
| 426 | |
| 427 | |
| 428 //=========================================================================== | |
| 429 // Query number of entries in a certain table | |
| 430 //=========================================================================== | |
| 431 static cyg_uint16 lpc2xxx_can_accfilt_get_table_entries(cyg_uint32 TableStartAddress) | |
| 432 { | |
| 433 cyg_uint32 start; | |
| 434 cyg_uint32 end; | |
| 435 | |
| 436 switch (TableStartAddress) | |
| 437 { | |
| 438 #ifdef CYGOPT_IO_CAN_STD_CAN_ID | |
| 439 case CAN_ACCFILT_SFF_SA: | |
| 440 HAL_READ_UINT32(CAN_ACCFILT_SFF_SA, start); | |
| 441 HAL_READ_UINT32(CAN_ACCFILT_SFF_GRP_SA, end); | |
| 442 if (end - start) | |
| 443 { | |
| 444 lsc_buf_t data; | |
| 445 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + end - sizeof(cyg_uint32), data.dword); | |
| 446 if (data.column.upper & ACCFILT_STD_DIS) | |
| 447 { | |
| 448 return (((end - start) >> 1) - 1); | |
| 449 } | |
| 450 } | |
| 451 return (end - start) >> 1; | |
| 452 | |
| 453 case CAN_ACCFILT_SFF_GRP_SA: | |
| 454 HAL_READ_UINT32(CAN_ACCFILT_SFF_GRP_SA, start); | |
| 455 HAL_READ_UINT32(CAN_ACCFILT_EFF_SA, end); | |
| 456 return (end - start) >> 2; | |
| 457 #endif // CYGOPT_IO_CAN_STD_CAN_ID | |
| 458 | |
| 459 #ifdef CYGOPT_IO_CAN_EXT_CAN_ID | |
| 460 case CAN_ACCFILT_EFF_SA: | |
| 461 HAL_READ_UINT32(CAN_ACCFILT_EFF_SA, start); | |
| 462 HAL_READ_UINT32(CAN_ACCFILT_EFF_GRP_SA, end); | |
| 463 return (end - start) >> 2; | |
| 464 | |
| 465 case CAN_ACCFILT_EFF_GRP_SA: | |
| 466 HAL_READ_UINT32(CAN_ACCFILT_EFF_GRP_SA, start); | |
| 467 HAL_READ_UINT32(CAN_ACCFILT_ENDOFTABLE, end); | |
| 468 return (end - start) >> 3; | |
| 469 #endif // CYGOPT_IO_CAN_EXT_CAN_ID | |
| 470 default: | |
| 471 CYG_FAIL("Invalid identifier table address"); | |
| 472 return 0; | |
| 473 } // switch (TableStartAddress) | |
| 474 } | |
| 475 | |
| 476 //=========================================================================== | |
| 477 // Query certain entry from table | |
| 478 //=========================================================================== | |
| 479 static void lpc2xxx_can_accfilt_get_entry(cyg_uint32 TableStartAddress, cyg_uint16 EntryNo, lpc2xxx_accfilt_entry_t *pEntry) | |
| 480 { | |
| 481 cyg_uint32 EntryAddress = lpc2xxx_can_accfilt_calc_entry_address(TableStartAddress, EntryNo); | |
| 482 lsc_buf_t Data; | |
| 483 | |
| 484 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + EntryAddress, Data.dword); | |
| 485 pEntry->data = Data.dword; | |
| 486 switch (TableStartAddress) | |
| 487 { | |
| 488 #ifdef CYGOPT_IO_CAN_STD_CAN_ID | |
| 489 case CAN_ACCFILT_SFF_SA: | |
| 490 { | |
| 491 cyg_uint16 column; | |
| 492 if (EntryNo % 2) | |
| 493 { | |
| 494 column = Data.column.upper; | |
| 495 } | |
| 496 else | |
| 497 { | |
| 498 column = Data.column.lower; | |
| 499 } | |
| 500 pEntry->id = ACCFILT_STD_GET_ID(column); | |
| 501 pEntry->channel_no = ACCFILT_STD_GET_CTRL(column); | |
| 502 } | |
| 503 break; | |
| 504 | |
| 505 case CAN_ACCFILT_SFF_GRP_SA: | |
| 506 pEntry->lower_id_bound = ACCFILT_STD_GET_ID(Data.column.lower); | |
| 507 pEntry->upper_id_bound = ACCFILT_STD_GET_ID(Data.column.upper); | |
| 508 pEntry->channel_no = ACCFILT_STD_GET_CTRL(Data.column.lower); | |
| 509 break; | |
| 510 #endif // #ifdef CYGOPT_IO_CAN_STD_CAN_ID | |
| 511 | |
| 512 #ifdef CYGOPT_IO_CAN_EXT_CAN_ID | |
| 513 case CAN_ACCFILT_EFF_SA: | |
| 514 pEntry->id = ACCFILT_EXT_GET_ID(Data.dword); | |
| 515 pEntry->channel_no = ACCFILT_EXT_GET_CTRL(Data.dword); | |
| 516 break; | |
| 517 | |
| 518 case CAN_ACCFILT_EFF_GRP_SA: | |
| 519 pEntry->lower_id_bound = ACCFILT_EXT_GET_ID(Data.dword); | |
| 520 pEntry->channel_no = ACCFILT_EXT_GET_CTRL(Data.dword); | |
| 521 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE+ EntryAddress + sizeof(cyg_uint32), Data.dword); | |
| 522 pEntry->upper_id_bound = ACCFILT_EXT_GET_ID(Data.dword); | |
| 523 break; | |
| 524 #endif // #ifedf CYGOPT_IO_CAN_EXT_CAN_ID | |
| 525 default: | |
| 526 CYG_FAIL("Invalid identifier table address"); | |
| 527 } // switch () | |
| 528 } | |
| 529 | |
| 530 | |
| 531 //=========================================================================== | |
| 532 // Set certain entry in table | |
| 533 //=========================================================================== | |
| 534 static void lpc2xxx_can_accfilt_set_entry(cyg_uint32 TableStartAddress, cyg_uint16 EntryNo, lpc2xxx_accfilt_entry_t *pEntry) | |
| 535 { | |
| 536 cyg_uint32 EntryAddress = lpc2xxx_can_accfilt_calc_entry_address(TableStartAddress, EntryNo); | |
| 537 lsc_buf_t Data; | |
| 538 | |
| 539 switch (TableStartAddress) | |
| 540 { | |
| 541 #ifdef CYGOPT_IO_CAN_STD_CAN_ID | |
| 542 case CAN_ACCFILT_SFF_SA: | |
| 543 { | |
| 544 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + EntryAddress, Data.dword); | |
| 545 if (EntryNo % 2) | |
| 546 { | |
| 547 Data.column.upper = (pEntry->channel_no << 13) | (pEntry->id & ACCFILT_STD_ID_MASK); | |
| 548 } | |
| 549 else | |
| 550 { | |
| 551 Data.column.lower = (pEntry->channel_no << 13) | (pEntry->id & ACCFILT_STD_ID_MASK); | |
| 552 } | |
| 553 } | |
| 554 break; | |
| 555 | |
| 556 case CAN_ACCFILT_SFF_GRP_SA: | |
| 557 Data.column.lower = (pEntry->channel_no << 13) | (pEntry->lower_id_bound & ACCFILT_STD_ID_MASK); | |
| 558 Data.column.upper = (pEntry->channel_no << 13) | (pEntry->upper_id_bound & ACCFILT_STD_ID_MASK); | |
| 559 break; | |
| 560 #endif // #ifdef CYGOPT_IO_CAN_STD_CAN_ID | |
| 561 | |
| 562 #ifdef CYGOPT_IO_CAN_EXT_CAN_ID | |
| 563 case CAN_ACCFILT_EFF_SA: | |
| 564 Data.dword = (pEntry->channel_no << 29) | (pEntry->id & ACCFILT_EXT_ID_MASK); | |
| 565 break; | |
| 566 | |
| 567 case CAN_ACCFILT_EFF_GRP_SA: | |
| 568 { | |
| 569 lsc_buf_t Data2; | |
| 570 | |
| 571 Data.dword = (pEntry->channel_no << 29) | (pEntry->lower_id_bound & ACCFILT_EXT_ID_MASK); | |
| 572 Data2.dword = (pEntry->channel_no << 29) | (pEntry->upper_id_bound & ACCFILT_EXT_ID_MASK); | |
| 573 HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + EntryAddress + sizeof(cyg_uint32), Data2.dword); | |
| 574 } | |
| 575 break; | |
| 576 #endif // #ifdef CYGOPT_IO_CAN_EXT_CAN_ID | |
| 577 | |
| 578 default: | |
| 579 CYG_FAIL("Invalid identifier table address"); | |
| 580 } // switch () | |
| 581 | |
| 582 HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + EntryAddress, Data.dword); | |
| 583 } | |
| 584 | |
| 585 | |
| 586 //=========================================================================== | |
| 587 // Add one entry to acceptance filter RAM | |
| 588 // If upper ID is > lower ID then we have to add a group filter - else we | |
| 589 // have to add a single message filter here | |
| 590 //=========================================================================== | |
| 591 static bool lpc2xxx_can_accfilt_add(lpc2xxx_can_info_t *info, | |
| 592 cyg_uint32 lower_id, | |
| 593 cyg_uint32 upper_id, | |
| 594 cyg_can_id_type ext) | |
| 595 { | |
| 596 cyg_uint32 accfilt_bck; // acceptance filter backup | |
| 597 cyg_uint32 end_of_table; | |
| 598 cyg_uint32 table; | |
| 599 lpc2xxx_accfilt_entry_t entry; | |
| 600 lpc2xxx_accfilt_entry_t new_entry; | |
| 601 | |
| 602 | |
| 603 // | |
| 604 // first step: disable acceptance filter and prepare it for modification | |
| 605 // | |
| 606 HAL_READ_UINT32(CAN_ACCFILT_AFMR, accfilt_bck); | |
| 607 HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, AFMR_OFF | AFMR_BYPASS); | |
| 608 | |
| 609 // | |
| 610 // Check if table is full | |
| 611 // | |
| 612 HAL_READ_UINT32(CAN_ACCFILT_ENDOFTABLE, end_of_table); | |
| 613 if (end_of_table >= ACCFILT_RAM_SIZE) | |
| 614 { | |
| 615 return false; | |
| 616 } | |
| 617 | |
| 618 new_entry.id = lower_id; | |
| 619 new_entry.lower_id_bound = lower_id; | |
| 620 new_entry.upper_id_bound = upper_id; | |
| 621 | |
| 622 // | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
623 // Here we rely on the ISR vector ordering for calculation of channel number |
| 2409 | 624 // Maybe this is not the right way for newer LPC parts |
| 625 // | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
626 new_entry.channel_no = CAN_CHAN_NO_LUT(info); |
| 2409 | 627 |
| 628 // | |
| 629 // If lower_id == upper_id then we know that we have to setup a single message filter | |
| 630 // here. If it is not equal the it is group of identifiers to receive | |
| 631 // | |
| 632 if ((lower_id == upper_id) || (lower_id > upper_id)) | |
| 633 { | |
| 634 // | |
| 635 // setup single message filter (standard or extended) here | |
| 636 // | |
| 637 #ifdef CYGOPT_IO_CAN_EXT_CAN_ID | |
| 638 if (ext) | |
| 639 { | |
| 640 table = CAN_ACCFILT_EFF_SA; | |
| 641 } | |
| 642 else | |
| 643 #endif // #ifdef CYGOPT_IO_CAN_EXT_CAN_ID | |
| 644 { | |
| 645 #ifdef CYGOPT_IO_CAN_STD_CAN_ID | |
| 646 table = CAN_ACCFILT_SFF_SA; | |
| 647 #endif // CYGOPT_IO_CAN_STD_CAN_ID | |
| 648 } | |
| 649 } | |
| 650 else | |
| 651 { | |
| 652 // | |
| 653 // setup single message filter (standard or extended) here | |
| 654 // | |
| 655 #ifdef CYGOPT_IO_CAN_EXT_CAN_ID | |
| 656 if (ext) | |
| 657 { | |
| 658 table = CAN_ACCFILT_EFF_GRP_SA; | |
| 659 } | |
| 660 else | |
| 661 #endif // #ifdef CYGOPT_IO_CAN_EXT_CAN_ID | |
| 662 { | |
| 663 #ifdef CYGOPT_IO_CAN_STD_CAN_ID | |
| 664 table = CAN_ACCFILT_SFF_GRP_SA; | |
| 665 #endif // #ifdef CYGOPT_IO_CAN_STD_CAN_ID | |
| 666 } | |
| 667 } | |
| 668 | |
| 669 cyg_uint16 entries = lpc2xxx_can_accfilt_get_table_entries(table); | |
| 670 cyg_uint16 i; | |
| 671 | |
| 672 | |
| 673 for (i = 0; i < entries; ++i) | |
| 674 { | |
| 675 lpc2xxx_can_accfilt_get_entry(table, i, &entry); | |
| 676 | |
| 677 if (entry.channel_no > new_entry.channel_no) | |
| 678 { | |
| 679 break; | |
| 680 } | |
| 681 | |
| 682 if ((entry.channel_no == new_entry.channel_no) | |
| 683 && (entry.id > new_entry.id)) | |
| 684 { | |
| 685 break; | |
| 686 } | |
| 687 } // for (i = 0; i < entries; ++i) | |
| 688 | |
| 689 lpc2xxx_can_accfilt_ram_insert_entry(table, i); | |
| 690 lpc2xxx_can_accfilt_set_entry(table, i, &new_entry); | |
| 691 | |
| 692 // | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
693 // finally restore the previous state of the acceptance filter |
| 2409 | 694 // |
| 695 HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, accfilt_bck); | |
| 696 return true; | |
| 697 } | |
| 698 | |
| 699 | |
| 700 //=========================================================================== | |
| 701 // Remove all entries from a certain controller | |
| 702 //=========================================================================== | |
| 703 void lpc2xxx_can_accfilt_remove_all_ctrl_entries(lpc2xxx_can_info_t *info) | |
| 704 { | |
| 705 cyg_uint32 accfilt_bck; // acceptance filter backup | |
| 706 cyg_uint16 i; | |
| 707 cyg_uint16 entries; | |
| 708 cyg_uint32 TableStartAddress = CAN_ACCFILT_SFF_SA; | |
| 709 lpc2xxx_accfilt_entry_t Entry; | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
710 cyg_uint8 channel_no = CAN_CHAN_NO_LUT(info); |
| 2409 | 711 cyg_uint16 entry_idx; |
| 712 | |
| 713 // | |
| 714 // first step: disable acceptance filter and prepare it for modification | |
| 715 // | |
| 716 HAL_READ_UINT32(CAN_ACCFILT_AFMR, accfilt_bck); | |
| 717 HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, AFMR_OFF | AFMR_BYPASS); | |
| 718 | |
| 719 // | |
| 720 // now remove all entries for a certain controller | |
| 721 // | |
| 722 for (TableStartAddress = CAN_ACCFILT_SFF_SA; TableStartAddress < CAN_ACCFILT_ENDOFTABLE; TableStartAddress += 4) | |
| 723 { | |
| 724 entries = lpc2xxx_can_accfilt_get_table_entries(TableStartAddress); | |
| 725 entry_idx = 0; | |
| 726 for (i = 0; i < entries; ++i) | |
| 727 { | |
| 728 lpc2xxx_can_accfilt_get_entry(TableStartAddress, entry_idx, &Entry); | |
| 729 if (Entry.channel_no == channel_no) | |
| 730 { | |
| 731 lpc2xxx_can_accfilt_ram_remove_entry(TableStartAddress, entry_idx); | |
| 732 } | |
| 733 else | |
| 734 { | |
| 735 entry_idx++; | |
| 736 } | |
| 737 } // for (i = 0; i < entries; ++i) | |
| 738 } // for (TableStartAddress = CAN_ACCFILT_SFF_SA ... | |
| 739 | |
| 740 // | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
741 // finally restore the previous state of the acceptance filter |
| 2409 | 742 // |
| 743 HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, accfilt_bck); | |
| 744 } | |
| 745 #endif // CYGOPT_IO_CAN_RUNTIME_MBOX_CFG | |
| 746 | |
| 747 | |
| 748 #ifndef CYGOPT_IO_CAN_RUNTIME_MBOX_CFG | |
| 749 //=========================================================================== | |
| 750 // Setup reception of all CAN identifiers | |
| 751 // If runtime acceptance filter configuration is not required then we simply | |
| 752 // setup the acceptance filter here to receive all CAN identifiers | |
| 753 //=========================================================================== | |
| 754 static void lpc2xxx_can_accfilt_simple_rx_all(void) | |
| 755 { | |
| 756 cyg_uint32 regval; | |
| 757 | |
| 758 // | |
| 759 // First check if it is really necessary to setup filters. If end of table is | |
| 760 // != 0 then the acceptance filter is already setup properly | |
| 761 // | |
| 762 HAL_READ_UINT32(CAN_ACCFILT_ENDOFTABLE, regval); | |
| 763 if (regval) | |
| 764 { | |
| 765 return; | |
| 766 } | |
| 767 | |
| 768 cyg_uint32 accfilt_bck; // acceptance filter backup | |
| 769 cyg_uint8 i = 0; // loop counter | |
| 770 lsc_buf_t accfilt_entry; // std group entry | |
| 771 #ifdef CYGOPT_IO_CAN_STD_CAN_ID | |
| 772 cyg_uint8 std_address = 0; // std group entry address | |
| 773 #ifdef CYGOPT_IO_CAN_EXT_CAN_ID | |
|
3345
b06697684f0a
* src/can_accfilt_lpc2xxx.c, src/can_lpc2xxx.c: Fix a compile issue of
sergeig
parents:
2729
diff
changeset
|
774 cyg_uint8 ext_address = LPC2XXX_INIT_CNT << 2; |
| 2409 | 775 #endif |
| 776 #else | |
| 777 cyg_uint8 ext_address = 0; | |
| 778 #endif | |
| 779 | |
| 780 // | |
| 781 // first step: disable acceptance filter and prepare it for modification | |
| 782 // | |
| 783 HAL_READ_UINT32(CAN_ACCFILT_AFMR, accfilt_bck); | |
| 784 HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, AFMR_OFF | AFMR_BYPASS); | |
| 785 | |
| 786 // | |
| 787 // Write table start adresses - we use only standard group and extended filter | |
| 788 // group | |
| 789 // | |
| 790 HAL_WRITE_UINT32(CAN_ACCFILT_SFF_SA, 0); | |
| 791 HAL_WRITE_UINT32(CAN_ACCFILT_SFF_GRP_SA, 0); | |
| 792 HAL_WRITE_UINT32(CAN_ACCFILT_EFF_SA, ext_address); | |
| 793 HAL_WRITE_UINT32(CAN_ACCFILT_EFF_GRP_SA, ext_address); | |
| 794 | |
| 795 // | |
| 796 // Now loop through all active CAN channels and setup the acceptance filter for | |
| 797 // each channel to receive all standard and extended CAN identifiers | |
| 798 // | |
| 799 while (lpc2xxx_global_can_info.active_channels[i]) | |
| 800 { | |
| 801 lpc2xxx_can_info_t *info = (lpc2xxx_can_info_t *)lpc2xxx_global_can_info.active_channels[i++]->dev_priv; | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
802 cyg_uint8 channel_no = CAN_CHAN_NO_LUT(info); |
| 2409 | 803 |
| 804 #ifdef CYGOPT_IO_CAN_STD_CAN_ID | |
| 805 accfilt_entry.column.lower = (channel_no << 13) | (0x000 & ACCFILT_STD_ID_MASK); | |
| 806 accfilt_entry.column.upper = (channel_no << 13) | (0x7FF & ACCFILT_STD_ID_MASK); | |
| 807 HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + std_address, accfilt_entry.dword); | |
| 808 std_address += sizeof(cyg_uint32); | |
| 809 #endif // CYGOPT_IO_CAN_STD_CAN_ID | |
| 810 | |
| 811 #ifdef CYGOPT_IO_CAN_EXT_CAN_ID | |
| 812 accfilt_entry.dword = (channel_no << 29) | (0x00000000 & ACCFILT_EXT_ID_MASK); | |
| 813 HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + ext_address, accfilt_entry.dword); | |
| 814 ext_address += sizeof(cyg_uint32); | |
| 815 accfilt_entry.dword = (channel_no << 29) | (0x1FFFFFFF & ACCFILT_EXT_ID_MASK); | |
| 816 HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + ext_address, accfilt_entry.dword); | |
| 817 ext_address += sizeof(cyg_uint32); | |
| 818 #endif // CYGOPT_IO_CAN_EXT_CAN_ID | |
| 819 } // while (lpc2xxx_global_can_info.active_channels[i]) | |
| 820 | |
| 821 // | |
| 822 // finally store end of table value and restore the previous state of the | |
| 823 // acceptance filter | |
| 824 // | |
| 825 HAL_WRITE_UINT32(CAN_ACCFILT_ENDOFTABLE, ext_address); | |
| 826 HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, accfilt_bck); | |
| 827 } | |
| 828 #endif // CYGOPT_IO_CAN_RUNTIME_MBOX_CFG | |
| 829 | |
| 830 | |
| 831 //=========================================================================== | |
| 832 // Reset acceptance filter to poweron defaults | |
| 833 //=========================================================================== | |
| 834 void lpc2xxx_can_accfilt_reset(void) | |
| 835 { | |
| 836 cyg_uint32 accfilt_bck; // acceptance filter backup | |
| 837 // | |
| 838 // first step: disable acceptance filter and prepare it for modification | |
| 839 // | |
| 840 HAL_READ_UINT32(CAN_ACCFILT_AFMR, accfilt_bck); | |
| 841 HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, AFMR_OFF | AFMR_BYPASS); | |
| 842 | |
| 843 // | |
| 844 // Now write zero to all addresses of acceptance filter table | |
| 845 // | |
| 846 HAL_WRITE_UINT32(CAN_ACCFILT_SFF_SA, 0); | |
| 847 HAL_WRITE_UINT32(CAN_ACCFILT_SFF_GRP_SA, 0); | |
| 848 HAL_WRITE_UINT32(CAN_ACCFILT_EFF_SA, 0); | |
| 849 HAL_WRITE_UINT32(CAN_ACCFILT_EFF_GRP_SA, 0); | |
| 850 HAL_WRITE_UINT32(CAN_ACCFILT_ENDOFTABLE, 0); | |
| 851 | |
| 852 // | |
|
2509
a52d470bc691
* cdl/can_lpc2xxx.cdl: Added CYGOPT_DEVS_CAN_LPC2XXX_ALIE to make
asl
parents:
2409
diff
changeset
|
853 // finally restore the previous state of the acceptance filter |
| 2409 | 854 // |
| 855 HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, accfilt_bck); | |
| 856 } | |
| 857 | |
| 858 | |
| 859 //=========================================================================== | |
| 860 // Dump content of acceptance filter lookup table | |
| 861 //=========================================================================== | |
| 862 #ifdef CYGDBG_DEVS_CAN_LPC2XXX_DEBUG | |
| 863 void lpc2xxx_can_accfilt_dbg_dump(void) | |
| 864 { | |
| 865 cyg_uint32 sff_sa; | |
| 866 cyg_uint32 sff_grp_sa; | |
| 867 cyg_uint32 eff_sa; | |
| 868 cyg_uint32 eff_grp_sa; | |
| 869 cyg_uint32 end_of_table; | |
| 870 cyg_uint32 entry_address; | |
| 871 lsc_buf_t data; | |
| 872 | |
| 873 | |
| 874 HAL_READ_UINT32(CAN_ACCFILT_SFF_SA, sff_sa); | |
| 875 HAL_READ_UINT32(CAN_ACCFILT_SFF_GRP_SA, sff_grp_sa); | |
| 876 HAL_READ_UINT32(CAN_ACCFILT_EFF_SA, eff_sa); | |
| 877 HAL_READ_UINT32(CAN_ACCFILT_EFF_GRP_SA, eff_grp_sa); | |
| 878 HAL_READ_UINT32(CAN_ACCFILT_ENDOFTABLE, end_of_table); | |
| 879 | |
| 880 entry_address = sff_sa; | |
| 881 | |
| 882 // | |
| 883 // Print lookup table registers | |
| 884 // | |
| 885 diag_printf("\n\nDUMP CAN ACCEPTANCE FILTER REGISTERS\n"); | |
| 886 diag_printf("----------------------------------------\n"); | |
| 887 diag_printf("SFF_sa:\t\t0x%08x\n", sff_sa); | |
| 888 diag_printf("SFF_GRP_sa:\t0x%08x\n", sff_grp_sa); | |
| 889 diag_printf("EFF_sa:\t\t0x%08x\n", eff_sa); | |
| 890 diag_printf("EFF_GRP_sa:\t0x%08x\n", eff_grp_sa); | |
| 891 diag_printf("EOT:\t\t0x%08x\n", end_of_table); | |
| 892 | |
| 893 // | |
| 894 // Print table of standard identifiers | |
| 895 // | |
| 896 diag_printf("\n\nDUMP CAN LOOKUP TABLE RAM"); | |
| 897 diag_printf("\nSFF_sa\t\tcolumn_lower\tcolumn_upper\traw_data\n"); | |
| 898 diag_printf("----------------------------------------------------------\n"); | |
| 899 while (entry_address < sff_grp_sa) | |
| 900 { | |
| 901 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + entry_address, data.dword); | |
| 902 diag_printf("0x%04x:\t\t0x%x\t\t0x%x\t\t0x%x\n", entry_address, data.column.lower, data.column.upper, data.dword); | |
| 903 entry_address += sizeof(cyg_uint32); | |
| 904 } | |
| 905 | |
| 906 // | |
| 907 // Print table of standard identifier groups | |
| 908 // | |
| 909 diag_printf("\nSFF_GRP_sa\tcolumn_lower\tcolumn_upper\traw_data\n"); | |
| 910 diag_printf("----------------------------------------------------------\n"); | |
| 911 while (entry_address < eff_sa) | |
| 912 { | |
| 913 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + entry_address, data.dword); | |
| 914 diag_printf("0x%04x:\t\t0x%x\t\t0x%x\t\t0x%x\n", entry_address, data.column.lower, data.column.upper, data.dword); | |
| 915 entry_address += sizeof(cyg_uint32); | |
| 916 } | |
| 917 | |
| 918 // | |
| 919 // Print table of extended identifiers | |
| 920 // | |
| 921 diag_printf("\nEFF_sa\t\t-\t\t-\t\traw_data\n"); | |
| 922 diag_printf("----------------------------------------------------------\n"); | |
| 923 while (entry_address < eff_grp_sa) | |
| 924 { | |
| 925 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + entry_address, data.dword); | |
| 926 diag_printf("0x%04x:\t\t\t\t\t\t0x%x\n", entry_address, data.dword); | |
| 927 entry_address += sizeof(cyg_uint32); | |
| 928 } | |
| 929 | |
| 930 // | |
| 931 // Print table of extended identifier groups | |
| 932 // | |
| 933 diag_printf("\nEFF_GRP_sa\t-\t\t-\t\traw_data\n"); | |
| 934 diag_printf("----------------------------------------------------------\n"); | |
| 935 while (entry_address < end_of_table) | |
| 936 { | |
| 937 HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + entry_address, data.dword); | |
| 938 diag_printf("0x%04x:\t\t\t\t\t\t0x%x\n", entry_address, data.dword); | |
| 939 entry_address += sizeof(cyg_uint32); | |
| 940 } | |
| 941 } | |
| 942 #endif // CYGDBG_DEVS_CAN_LPC2XXX_DEBUG | |
| 943 | |
| 944 //=========================================================================== | |
| 945 // Dump content of acceptance filter lookup table | |
| 946 //=========================================================================== | |
| 947 #ifdef CYGDBG_DEVS_CAN_LPC2XXX_DEBUG | |
| 948 void lpc2xxx_can_reg_dump(struct cyg_devtab_entry* devtab_entry) | |
| 949 { | |
| 950 can_channel *chan = (can_channel*)devtab_entry->priv; | |
| 951 cyg_uint32 reg_val; | |
| 952 CAN_DECLARE_INFO(chan); | |
| 953 | |
| 954 chan = chan; // avoid compiler warnings for unused variables | |
| 955 // | |
| 956 // Print table of extended identifier groups | |
| 957 // | |
| 958 diag_printf("\n\nCAN REGISTER DUMP\n"); | |
| 959 diag_printf("\nRegister\tValue\n"); | |
| 960 diag_printf("----------------------------------------------------------\n"); | |
| 961 HAL_READ_UINT32(CAN_CTRL_MOD(info), reg_val); | |
| 962 diag_printf("CANMOD\t\t0x%08x\n", reg_val); | |
| 963 HAL_READ_UINT32(CAN_CTRL_CMR(info), reg_val); | |
| 964 diag_printf("CANCMR\t\t0x%08x\n", reg_val); | |
| 965 HAL_READ_UINT32(CAN_CTRL_GSR(info), reg_val); | |
| 966 diag_printf("CANGSR\t\t0x%08x\n", reg_val); | |
| 967 HAL_READ_UINT32(CAN_CTRL_ICR(info), reg_val); | |
| 968 diag_printf("CANICR\t\t0x%08x\n", reg_val); | |
| 969 HAL_READ_UINT32(CAN_CTRL_IER(info), reg_val); | |
| 970 diag_printf("CANIER\t\t0x%08x\n", reg_val); | |
| 971 HAL_READ_UINT32(CAN_CTRL_BTR(info), reg_val); | |
| 972 diag_printf("CANBTR\t\t0x%08x\n", reg_val); | |
| 973 HAL_READ_UINT32(CAN_CTRL_EWL(info), reg_val); | |
| 974 diag_printf("CANEWL\t\t0x%08x\n", reg_val); | |
| 975 HAL_READ_UINT32(CAN_CTRL_SR(info), reg_val); | |
| 976 diag_printf("CANSR\t\t0x%08x\n", reg_val); | |
| 977 HAL_READ_UINT32(CAN_CTRL_RFS(info), reg_val); | |
| 978 diag_printf("CANRFS\t\t0x%08x\n", reg_val); | |
| 979 HAL_READ_UINT32(CAN_CTRL_RID(info), reg_val); | |
| 980 diag_printf("CANRID\t\t0x%08x\n", reg_val); | |
| 981 HAL_READ_UINT32(CAN_CTRL_RDA(info), reg_val); | |
| 982 diag_printf("CANRDA\t\t0x%08x\n", reg_val); | |
| 983 HAL_READ_UINT32(CAN_CTRL_RDB(info), reg_val); | |
| 984 diag_printf("CANRDB\t\t0x%08x\n", reg_val); | |
| 985 | |
| 986 diag_printf("\n\nCAN CENTRAL REGISTER DUMP\n"); | |
| 987 diag_printf("\nRegister\tValue\n"); | |
| 988 diag_printf("----------------------------------------------------------\n"); | |
| 989 HAL_READ_UINT32(CAN_CENTRAL_TXSR, reg_val); | |
| 990 diag_printf("CANTxSR\t\t0x%08x\n", reg_val); | |
| 991 HAL_READ_UINT32(CAN_CENTRAL_RXSR, reg_val); | |
| 992 diag_printf("CANRxSR\t\t0x%08x\n", reg_val); | |
| 993 HAL_READ_UINT32(CAN_CENTRAL_MSR, reg_val); | |
| 994 diag_printf("CANMSR\t\t0x%08x\n", reg_val); | |
| 995 | |
| 996 diag_printf("\n\nCAN ACCEPTANCE FILTER REGISTER DUMP\n"); | |
| 997 diag_printf("\nRegister\tValue\n"); | |
| 998 diag_printf("----------------------------------------------------------\n"); | |
| 999 HAL_READ_UINT32(CAN_ACCFILT_AFMR, reg_val); | |
| 1000 diag_printf("AFMR\t\t0x%08x\n", reg_val); | |
| 1001 HAL_READ_UINT32(CAN_ACCFILT_LUT_ERR, reg_val); | |
| 1002 diag_printf("LUTERR\t\t0x%08x\n", reg_val); | |
| 1003 HAL_READ_UINT32(CAN_ACCFILT_LUT_ERR_ADDR, reg_val); | |
| 1004 diag_printf("LUTERRADDR\t0x%08x\n", reg_val); | |
| 1005 } | |
| 1006 #endif // #ifdef CYGDBG_DEVS_CAN_LPC2XXX_DEBUG | |
| 1007 | |
| 1008 //--------------------------------------------------------------------------- | |
| 1009 // EOF can_accfilt_lpc2xxx.c |
