Hardware resource slice selection, using ncs2, according to the memory map of the lpc3250: four static memory banks, 16 MB each: emc_cs0 0xe000 0000 ~ 0xe0ff ffffemc_cs1 0xe100 0000 ~ 0xe1ff ffffemc_cs2 0xe200 0000 ~ 0xe2ff ffffemc_cs3 0xe300 0000 ~ The offset addresses of the ale and my cle on the 0xe3ff FFFF circuit are 0x02 and 0x01 respectively. However, due to the special characteristics of the lpc3250, the physical bus is configured as 16-bit or 32-bit, the address line A0 is always valid, so the address written to the bus needs to be processed. The bus where can is located is configured with a 16-Bit Width, so the actual address should shift the physical offset address to one left, so we get: ale -- 0xe200 0004 cle -- 0xe200 0002 interrupt -- gpio_01 Interrupt Processing gpio_01 can be used as the interrupt input pin and can choose to wake up the CPU. Wake up the CPU register: start_er_int [1], 0 -- disable, 1 -- enable. Interrupt enable register: sic2_en [1], 0 -- disable, 1 -- enable; interrupt polarity register: sic2_apr [1], 0 -- low level or descent edge, 1 -- high level or rising edge; interrupt type register: sic2_recognition [1], 0 -- level trigger, 1 -- edge trigger; IO direction register: p2_dir_set [26], 0 -- input, 1 -- output; input Status Register: p3_inp_state [11]; output register: p3_outp_set [26]; it is recommended that sja10000. Bus configuration: The following is the test code in ads: The SJA1000 uses bank2, and the bus configuration is as follows: # define waitwen2 0x02/* configure emcstaticwaitwen2 */# define waitoen2 0x02/* configure alias */# define waitrd2 0x1f/* configure emcstaticwaitrd2 */# define waitpage2 0x0f /* configure emcstaticwaitpage2 */# define waitwr2 0x1f/* configure alias */# define waitturn2 0x0f/* configure emcstaticwaitturn2 */# define bfine _16def 0x00000001/* 16bit bus * // ** | page mode | selected polarity | word Positioning status | extended wait | write buffer | write protection | * | Pm | PC | Pb | EW | B | p | * | 0: Disabled; 1: enabled | 0: low 1: high | 0: Disabled 1: Enable | 0: Disabled 1: enabled | 0: Disabled 1: enable | */# define b00000 (0x00 <03) | (0x00 <06) | (0x01 <07) | (0x00 <8) | (0x00 <19) | (0x00 <20) # define bcfg1 (0x00 <03) | (0x00 <06) | (0x01 <07) | (0x00 <8) | (0x00 <19) | (0x00 <20) # define bcfg2 (0x00 <03) | (0x00 <06) | (0x01 <07) | (0x00 <8) | (0x00 <19) | (0x00 <20) # define bcfg3 (0x00 <03) | (0x00 <06) | (0x01 <07) | (0x00 <8) | (0x00 <19) | (0x00 <20 )) # define staticcfg2 (bcfg_16def | bcfg2) emcstaticconfig2 = staticcfg2; required = waitwen2; required = waitoen2; required = waitrd2; required = waitpage2; required = waitwr2; required = waitturn2; implementation of bus configuration in Linux: 229/* Set bank2's EMC regs */230 _ raw_writel (staticcfg2, emcstaticconfig2 (bytes); 231 _ raw_writel (waitwen2, emcstaticwaitwen2 (lpc32xx_emc_base )); 232 _ raw_writel (waitoen2, callback (lpc32xx_emc_base); 233 _ raw_writel (waitrd2, callback (callback); 234 _ raw_writel (waitpage2, emcstaticwaitpage2 (callback )); 235 _ raw_writel (waitwr2, emcstaticwaitwr2 (lpc32 Xx_emc_base); 236 _ raw_writel (waitturn2, emcstaticwaitturn2 (lpc32xx_emc_base); to access static ing of registers, you must first perform Io ing on the can bank in the system kernel, because by default, the lpc32xx only performs Io ing on the I/O space of the On-chip peripherals: 598/* 599 * by chenxibing (abing) 600 */601 static struct map_desc smartarm3250_io_desc [] _ initdata = {602 {/* ncs2, can SJA1000 */603. virtual = io_p2v (emc_cs2_base), 604. PFN = _ phys_to_pfn (emc_cs2_base), 605. length = sz_1m, 606. type = mt_device607 }, 608 {/* ncs1, CF card */609. virtual = io_p2v (emc_cs1_base), 610. PFN = _ phys_to_pfn (emc_cs1_base), 611. length = sz_1m, 612. type = mt_device613} 614615}; Use io_p2v to convert the can register from the physical address to the virtual address: 106 # define sja_base emc_cs2_base // 0xe2000000107 # define sja1000_base io_p2v (sja_base) 108 # define sja1000_data (sja1000_base + 0x02) 109 # define sja1000_addr (sja1000_base + 0x04) use the _ raw_read/_ raw_write function to group Row access: 259 _ raw_writeb (0x09, sja1000_addr); 260 _ raw_writeb (1 <I, sja1000_data); 261 _ raw_writeb (0x09, sja1000_addr ); space without static Io ing cannot use io_p2v for physical virtual address conversion. For register access functions such as iowrite and _ raw_writel, the kernel of the new version has been changed to arch/ARM/include/ASM/Io. the H function is defined, for example, 49 # DEFINE _ raw_writeb (V, A) (_ chk_io_ptr (A), * (volatile unsigned char _ force *) () = (V) 50 # DEFINE _ raw_writew (V, A) (_ chk_io_ptr (A), * (volatile unsigned short _ force *) () = (V) 51 # DEFINE _ raw_writel (V, A) (_ chk_io_ptr (A), * (volatile unsigned int _ force *) () = (V) 52 53 # DEFINE _ raw_readb (A) (_ chk_io_ptr (), * (Volatile unsigned char _ force *) (a) 54 # DEFINE _ raw_readw (A) (_ chk_io_ptr (), * (volatile unsigned short _ force *) (a) 55 # DEFINE _ raw_readl (A) (_ chk_io_ptr (), * (volatile unsigned int _ force *) (a) 228/* 229 * IO {read, write} {8, 16, 32} macros230 */231 # ifndef ioread8133 # define ioread8 (p) ({unsigned int _ v = _ raw_readb (p); _ v ;}) 233 # define ioread16 (p) ({unsigned int _ v = le16_to_cp U (_ force _ le16) _ raw_readw (p); _ v;}) 234 # define ioread32 (P) ({unsigned int _ v = le32_to_cpu (_ force _ le32) _ raw_readl (p); _ v;}) 235236 # define iowrite8 (V, p) _ raw_writeb (V, p) 237 # define iowrite16 (V, p) _ raw_writew (_ force _) cpu_to_le16 (V), P) 238 # define iowrite32 (V, p) _ raw_writel (_ force _ u32) cpu_to_le32 (V), P) dynamic Io ing if the system does not perform static Io ing on the bank where the can is located, you cannot use io_p2v for virtual address conversion. You must use ioremap Dynamic Io ing of rows. Of course, the physical space after static Io ing can also use ioremap for dynamic Io ing: 98 # define sja_ale_padr 0xe2000004 // SJA1000 lock port physical address 99 # define sja_dat_padr 0xe2000002 // SJA1000 data port physical address 100 # define sja_src_len 0x02 // SJA1000 Data Length, 1 byte 45 void * sja1000_ale; 46 void * sja1000_dat; 238 // ing io239 sja1000_dat = ioremap (bytes, sja_src_len); 240 sja1000_ale = ioremap (bytes, sja_src_len ); then use the ioread series functions for access: 245 iowrite8 (0x09, sja1000_ale); 2 46 iowrite8 (1 <I, sja1000_dat); 247 iowrite8 (0x09, sja1000_ale); the driver can correctly send the problem and solve the problem, however, the recipient can only respond once and then does not respond again. It is very likely that the interruption is not properly handled. Is the interruption mark not cleared and cannot be interrupted again? What should I do if I/O interruption of the lpc3250 is handled? Solution: Clear the interrupt mark of gpio_01 In the interrupt service program and re-enable gpio_01 interruption. 340 static irqreturn_t can_interrupt (int irq, void * dev_id, struct pt_regs * regs) 341 {342 unsigned int * sic2_rsr; 343 unsigned int * sic2_er; 344345 sic2_er = io_p2v (sic2_base + intc_mask); 346 sic2_rsr = io_p2v (sic2_base + intc_raw_stat); 347348 intentry (); 349 wake_up_interruptible (& can_wait ); 350351 _ raw_writel (1 <1), sic2_rsr); // clear interrupt flag // clear the interrupt flag of gpio_01 352 _ raw_writel (1 <1), sic2_er ); // Re-enable gpio_01 interrupt // re-enable gpio_01 interrupt 353 return irq_handled; 354} In addition, the Code in the initialization function that can interrupt gpio_01 is required: 217 int can_init (void) 218 {219 int I, result; 220 int Bak, TMP; 221222 unsigned int * sic2_er; 223 sic2_er = io_p2v (sic2_base + intc_mask ); 224 _ raw_writel (1 <1), sic2_er); // enable gpio_01 interruption ......} in a simple test, when you test the can reception function, the host machine's frame interval cannot be 0. Otherwise, frames will be lost. You can set a relatively small interval, for example, 10 MB. There was almost no problem with sending the test program on the new team. However, after the sending program is closed, cantest still receives the data frame. I don't know why. In addition, the biggest problem is that the receiving program can occasionally accept the correct information. In many cases, the received data is wrong, and the frame ID is always wrong. Except for the ID issue, the other issues were hardware issues, and there was no problem with another board. The application must be interrupted using ir1__disabled | 1_flags: rc = request_irq (B-> IRQ, (handler_t) interrupt_handler, ir1__disabled | ir1__trigger_falling, B-> name, B );
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service