]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/c_can.c
To prevent future name collisions "chip_t" changed to "canchip_t"
[lincan.git] / lincan / src / c_can.c
index 6bef001f84c0d502508cc885ab355ac8ed685a11..94456bb08f309ae677857b711b81df72278d8c22 100644 (file)
@@ -6,7 +6,7 @@
  * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
  * email:pisa@cmp.felk.cvut.cz
  * This software is released under the GPL-License.
- * Version lincan-0.2  9 Jul 2003
+ * Version lincan-0.3  17 Jun 2004
  */
 
 #define __NO_VERSION__
@@ -28,11 +28,11 @@ can_spinlock_t c_can_if2lock=SPIN_LOCK_UNLOCKED; // spin lcok for the if2 regist
  * c_can_enable_configuration - enable chip configuration mode
  * @pchip: pointer to chip state structure
  */
-int c_can_enable_configuration(struct chip_t *pchip)
+int c_can_enable_configuration(struct canchip_t *pchip)
 {
    int i=0;
    u16 flags;
-   DEBUGMSG("(c%d)calling c_can_enable_configuration(...)\n", pchip->chip_nr);
+   DEBUGMSG("(c%d)calling c_can_enable_configuration(...)\n", pchip->chip_idx);
 /*
    DEBUGMSG("Trying disable_irq(...) : ");
    //disable IRQ
@@ -60,12 +60,12 @@ int c_can_enable_configuration(struct chip_t *pchip)
 }
 
 ///////////////////////////////////////////////////////////////////////
-int c_can_disable_configuration(struct chip_t *pchip)
+int c_can_disable_configuration(struct canchip_t *pchip)
 {
    int i=0;
    u16 flags;
 
-   DEBUGMSG("(c%d)calling c_can_disable_configuration(...)\n", pchip->chip_nr);
+   DEBUGMSG("(c%d)calling c_can_disable_configuration(...)\n", pchip->chip_idx);
    //read Control Register
    flags=c_can_read_reg_w(pchip, CCCR);
 
@@ -90,10 +90,10 @@ int c_can_disable_configuration(struct chip_t *pchip)
 }
 
 ///////////////////////////////////////////////////////////////////////
-int c_can_chip_config(struct chip_t *pchip)
+int c_can_chip_config(struct canchip_t *pchip)
 {
 
-   DEBUGMSG("(c%d)calling c_can_chip_config(...)\n", pchip->chip_nr);
+   DEBUGMSG("(c%d)calling c_can_chip_config(...)\n", pchip->chip_idx);
    // Validate pointer
    if ( NULL == pchip ) return -1;
 
@@ -140,7 +140,7 @@ int c_can_chip_config(struct chip_t *pchip)
 /*
  * Checks if the Busy-Bit in the IF1-Command-Request Register is set
  */
-int c_can_if1_busycheck(struct chip_t *pchip)
+int c_can_if1_busycheck(struct canchip_t *pchip)
 {
 
    int i=0;
@@ -166,7 +166,7 @@ int c_can_if1_busycheck(struct chip_t *pchip)
 /*
  * Checks if the Busy-Bit in the IF2-Command-Request Register is set
  */
-int c_can_if2_busycheck(struct chip_t *pchip)
+int c_can_if2_busycheck(struct canchip_t *pchip)
 {
 
    int i=0;
@@ -201,7 +201,7 @@ int c_can_if2_busycheck(struct chip_t *pchip)
  * param sampl_pt sample point in % (0-100) sets (TSEG1+2)/(TSEG1+TSEG2+3) ratio
  * param flags fields BTR1_SAM, OCMODE, OCPOL, OCTP, OCTN, CLK_OFF, CBP
  */
-int c_can_baud_rate(struct chip_t *pchip, int rate, int clock,
+int c_can_baud_rate(struct canchip_t *pchip, int rate, int clock,
                        int sjw, int sampl_pt, int flags)
 {
    int best_error = 1000000000, error;
@@ -210,7 +210,7 @@ int c_can_baud_rate(struct chip_t *pchip, int rate, int clock,
 
    unsigned short tempCR = 0;
 
-   DEBUGMSG("(c%d)calling c_can_baud_rate(...)\n", pchip->chip_nr);
+   DEBUGMSG("(c%d)calling c_can_baud_rate(...)\n", pchip->chip_idx);
 
    if (c_can_enable_configuration(pchip))
      return -ENODEV;
@@ -282,7 +282,7 @@ int c_can_mask(struct msgobj_t *pmsgobj,
    unsigned short readMaskCM;
    unsigned short writeMaskCM;
 
-   DEBUGMSG("(c%dm%d)calling c_can_mask(...)\n", pmsgobj->hostchip->chip_nr, pmsgobj->object);
+   DEBUGMSG("(c%dm%d)calling c_can_mask(...)\n", pmsgobj->hostchip->chip_idx, pmsgobj->object);
 
    readMaskCM = IFXCM_CNTRL | IFXCM_ARB | IFXCM_MASK;
    writeMaskCM = IFXCM_CNTRL | IFXCM_ARB | IFXCM_MASK | IFXCM_WRRD;
@@ -355,7 +355,7 @@ int c_can_use_mask(struct msgobj_t *pmsgobj,
    char *boolstring = "false";
    if (useflag) boolstring = "true";
 #endif
-   DEBUGMSG("(c%dm%d)calling c_can_use_mask(...)\n", pmsgobj->hostchip->chip_nr, pmsgobj->object);
+   DEBUGMSG("(c%dm%d)calling c_can_use_mask(...)\n", pmsgobj->hostchip->chip_idx, pmsgobj->object);
 
    readMaskCM = IFXCM_CNTRL | IFXCM_ARB;
    writeMaskCM = IFXCM_CNTRL | IFXCM_ARB | IFXCM_WRRD;;
@@ -406,14 +406,14 @@ int c_can_use_mask(struct msgobj_t *pmsgobj,
 }
 
 ///////////////////////////////////////////////////////////////////////
-int c_can_clear_objects(struct chip_t *pchip)
+int c_can_clear_objects(struct canchip_t *pchip)
 {
    unsigned short i = 0;
    unsigned short tempreg = 0;
 
    unsigned short maskCM = IFXCM_ARB;
 
-   DEBUGMSG("(c%d)calling c_can_clear_objects(...)\n", pchip->chip_nr);
+   DEBUGMSG("(c%d)calling c_can_clear_objects(...)\n", pchip->chip_idx);
 
    spin_lock( &c_can_if1lock );
    spin_lock( &c_can_if2lock );
@@ -460,12 +460,12 @@ int c_can_clear_objects(struct chip_t *pchip)
 }
 
 ///////////////////////////////////////////////////////////////////////
-int c_can_config_irqs(struct chip_t *pchip,
+int c_can_config_irqs(struct canchip_t *pchip,
                       u16 irqs)
 {
    u16 tempreg;
 
-   DEBUGMSG("(c%d)calling c_can_config_irqs(...)\n", pchip->chip_nr);
+   DEBUGMSG("(c%d)calling c_can_config_irqs(...)\n", pchip->chip_idx);
 
    /*
     CANMSG("c_can_config_irqs not implemented\n");
@@ -480,14 +480,14 @@ int c_can_config_irqs(struct chip_t *pchip,
 }
 
 ///////////////////////////////////////////////////////////////////////
-int c_can_pre_read_config(struct chip_t *pchip, struct msgobj_t *pmsgobj)
+int c_can_pre_read_config(struct canchip_t *pchip, struct msgobj_t *pmsgobj)
 {
    unsigned short readMaskCM = IFXCM_CNTRL | IFXCM_ARB;
    unsigned short writeMaskCM = IFXCM_CNTRL | IFXCM_ARB | IFXCM_WRRD;
    unsigned short mcreg = 0;
    u32 id=pmsgobj->rx_preconfig_id;
 
-   DEBUGMSG("(c%dm%d)calling c_can_pre_read_config(...)\n", pmsgobj->hostchip->chip_nr, pmsgobj->object);
+   DEBUGMSG("(c%dm%d)calling c_can_pre_read_config(...)\n", pmsgobj->hostchip->chip_idx, pmsgobj->object);
 
    spin_lock( &c_can_if1lock );
 
@@ -534,7 +534,7 @@ int c_can_pre_read_config(struct chip_t *pchip, struct msgobj_t *pmsgobj)
 }
 
 ///////////////////////////////////////////////////////////////////////
-int c_can_pre_write_config(struct chip_t *chip, struct msgobj_t *obj, 
+int c_can_pre_write_config(struct canchip_t *chip, struct msgobj_t *obj, 
                                struct canmsg_t *msg)
 {
        return 0; 
@@ -546,7 +546,7 @@ int c_can_pre_write_config(struct chip_t *chip, struct msgobj_t *obj,
  *In this version the method also sends the message.
  */
 
-int c_can_send_msg(struct chip_t *pchip, struct msgobj_t *pmsgobj,
+int c_can_send_msg(struct canchip_t *pchip, struct msgobj_t *pmsgobj,
                        struct canmsg_t *pmsg)
 {   
    unsigned short readMaskCM = IFXCM_CNTRL | IFXCM_ARB | IFXCM_DA | IFXCM_DB;
@@ -559,7 +559,7 @@ int c_can_send_msg(struct chip_t *pchip, struct msgobj_t *pmsgobj,
    unsigned short dataB1 = 0;
    unsigned short dataB2 = 0;
 
-   DEBUGMSG("(c%dm%d)calling c_can_send_msg(...)\n", pmsgobj->hostchip->chip_nr, pmsgobj->object);
+   DEBUGMSG("(c%dm%d)calling c_can_send_msg(...)\n", pmsgobj->hostchip->chip_idx, pmsgobj->object);
 
    spin_lock( &c_can_if2lock );
 
@@ -622,13 +622,13 @@ int c_can_send_msg(struct chip_t *pchip, struct msgobj_t *pmsgobj,
 }
 
 //////////////////////////////////////////////////////////////////////
-int c_can_remote_request(struct chip_t *pchip, struct msgobj_t *pmsgobj )
+int c_can_remote_request(struct canchip_t *pchip, struct msgobj_t *pmsgobj )
 {
    unsigned short readMaskCM = IFXCM_CNTRL;// | IFXCM_ARB;
    //unsigned short writeMaskCM = IFXCM_CNTRL | IFXCM_ARB | IFXCM_WRRD;
    unsigned short mcreg = 0;
 
-   DEBUGMSG("(c%dm%d)calling c_can_remote_request(...)\n", pmsgobj->hostchip->chip_nr, pmsgobj->object);
+   DEBUGMSG("(c%dm%d)calling c_can_remote_request(...)\n", pmsgobj->hostchip->chip_idx, pmsgobj->object);
 
    //Remote request is only available when the message object is in receiving mode
    if (!can_msgobj_test_fl(pmsgobj,RX_MODE))
@@ -660,13 +660,13 @@ int c_can_remote_request(struct chip_t *pchip, struct msgobj_t *pmsgobj )
 }
 
 ///////////////////////////////////////////////////////////////////////
-int c_can_set_btregs(struct chip_t *pchip,
+int c_can_set_btregs(struct canchip_t *pchip,
                      u16 btr0,
                     u16 btr1)
 {
    unsigned short tempCR = 0;
 
-   DEBUGMSG("(c%d)calling c_can_set_btregs(...)\n", pchip->chip_nr);
+   DEBUGMSG("(c%d)calling c_can_set_btregs(...)\n", pchip->chip_idx);
 
    // Validate pointer
    if ( NULL == pchip ) return -1;
@@ -691,11 +691,11 @@ int c_can_set_btregs(struct chip_t *pchip,
 /*
  * Starts the Chip, by setting the CAN Enable Bit
  */
-int c_can_start_chip(struct chip_t *pchip)
+int c_can_start_chip(struct canchip_t *pchip)
 {
    u16 flags = 0;
 
-   DEBUGMSG("(c%d)calling c_can_start_chip(...)\n", pchip->chip_nr);
+   DEBUGMSG("(c%d)calling c_can_start_chip(...)\n", pchip->chip_idx);
 
    // Validate pointer
    if ( NULL == pchip )
@@ -722,11 +722,11 @@ int c_can_start_chip(struct chip_t *pchip)
 /*
  * Stops the Chip, by deleting the CAN Enable Bit
  */
-int c_can_stop_chip(struct chip_t *pchip)
+int c_can_stop_chip(struct canchip_t *pchip)
 {
    u16 flags = 0;
 
-   DEBUGMSG("(c%d)calling c_can_stop_chip(...)\n", pchip->chip_nr);
+   DEBUGMSG("(c%d)calling c_can_stop_chip(...)\n", pchip->chip_idx);
 
    // Validate pointer
    if ( NULL == pchip )
@@ -746,11 +746,11 @@ int c_can_stop_chip(struct chip_t *pchip)
 /*
  *Check the TxOK bit of the Status Register and resets it afterwards.
  */
-int c_can_check_tx_stat(struct chip_t *pchip)
+int c_can_check_tx_stat(struct canchip_t *pchip)
 {
    unsigned long tempstat = 0;
 
-   DEBUGMSG("(c%d)calling c_can_check_tx_stat(...)\n", pchip->chip_nr);
+   DEBUGMSG("(c%d)calling c_can_check_tx_stat(...)\n", pchip->chip_idx);
 
    // Validate pointer
    if ( NULL == pchip ) return -1;
@@ -770,7 +770,7 @@ int c_can_check_tx_stat(struct chip_t *pchip)
 
 
 ///////////////////////////////////////////////////////////////////////
-int c_can_wakeup_tx(struct chip_t *chip, struct msgobj_t *obj)
+int c_can_wakeup_tx(struct canchip_t *chip, struct msgobj_t *obj)
 {
        can_preempt_disable();
        
@@ -785,7 +785,7 @@ int c_can_wakeup_tx(struct chip_t *chip, struct msgobj_t *obj)
 }
 
 ///////////////////////////////////////////////////////////////////////
-int c_can_filtch_rq(struct chip_t *chip, struct msgobj_t *obj)
+int c_can_filtch_rq(struct canchip_t *chip, struct msgobj_t *obj)
 {
        can_preempt_disable();
        
@@ -800,7 +800,7 @@ int c_can_filtch_rq(struct chip_t *chip, struct msgobj_t *obj)
 
 
 ///////////////////////////////////////////////////////////////////////
-void c_can_registerdump(struct chip_t *pchip)
+void c_can_registerdump(struct canchip_t *pchip)
 {
    CANMSG("------------------------------------\n");
    CANMSG("---------C-CAN Register Dump--------\n");
@@ -912,33 +912,10 @@ int c_can_register(struct chipspecops_t *chipspecops)
        return 0;
 }
 
-/*int c_can_register(struct chip_t *pchip)
+int c_can_fill_chipspecops(struct canchip_t *chip)
 {
-   DEBUGMSG("(c%d)call c_can_register\n", pchip->chip_nr);
-
-   // Validate pointer
-   if ( NULL == pchip ) return -1;
-
-   pchip->chip_config = c_can_chip_config;
-   pchip->set_baud_rate = c_can_baud_rate;
-   pchip->set_mask = c_can_mask;
-   pchip->set_use_mask = c_can_use_mask;
-   //pchip->set_message15_mask = c_can_extended_mask;
-   pchip->clear_objects = c_can_clear_objects;
-   pchip->config_irqs = c_can_config_irqs;
-   pchip->pre_read_config = c_can_pre_read_config;
-   //pchip->pre_write_config = c_can_pre_write_config;
-   pchip->send_msg = c_can_send_msg;
-   pchip->check_tx_stat = c_can_check_tx_stat;
-   pchip->remote_request = c_can_remote_request;
-   pchip->enable_configuration = c_can_enable_configuration;
-   pchip->disable_configuration = c_can_disable_configuration;
-   pchip->set_btregs = c_can_set_btregs;
-   pchip->start_chip = c_can_start_chip;
-   pchip->stop_chip = c_can_stop_chip;
-   pchip->register_dump = c_can_registerdump;
-
-   DEBUGMSG("-> ok\n");
-   return 0;
+       chip->chip_type="c_can";
+       chip->max_objects = 32;
+       c_can_register(chip->chipspecops);
+       return 0;
 }
-*/