* 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
*/
#include "../include/can.h"
int i82527_pre_read_config(struct chip_t *chip, struct msgobj_t *obj)
{
- if (extended) {
+ unsigned long id=obj->rx_preconfig_id;
+
+ can_msgobj_set_fl(obj,RX_MODE);
+
+ if (extended || can_msgobj_test_fl(obj,RX_MODE_EXT)) {
+ id<<=3;
+ canobj_write_reg(chip,obj,id,iMSGID3);
+ canobj_write_reg(chip,obj,id>>8,iMSGID2);
+ canobj_write_reg(chip,obj,id>>16,iMSGID1);
+ canobj_write_reg(chip,obj,id>>24,iMSGID0);
canobj_write_reg(chip,obj,MCFG_XTD,iMSGCFG);
- }
- else {
+ } else {
+ id<<=5;
+ canobj_write_reg(chip,obj,id,iMSGID1);
+ canobj_write_reg(chip,obj,id>>8,iMSGID0);
canobj_write_reg(chip,obj,0x00,iMSGCFG);
}
+
canobj_write_reg(chip,obj,(NEWD_RES|MLST_RES|TXRQ_RES|RMPD_RES), iMSGCTL1);
canobj_write_reg(chip,obj,(MVAL_SET|TXIE_RES|RXIE_SET|INTPD_RES),iMSGCTL0);
DEBUGMSG("i82527_pre_read_config: configured obj at 0x%08lx\n",obj->obj_base_addr);
-
return 0;
}
len = msg->length;
if(len > CAN_MSG_LENGTH) len = CAN_MSG_LENGTH;
+ can_msgobj_clear_fl(obj,RX_MODE);
+
canobj_write_reg(chip,obj,(MVAL_SET|TXIE_SET|RXIE_RES|INTPD_RES),iMSGCTL0);
canobj_write_reg(chip,obj,(RMPD_RES|TXRQ_RES|CPUU_SET|NEWD_RES),iMSGCTL1);
return 0;
}
-inline void i82527_irq_write_handler(struct chip_t *chip, struct msgobj_t *obj)
+static inline
+void i82527_irq_write_handler(struct chip_t *chip, struct msgobj_t *obj)
{
int cmd;
if(obj->tx_slot){
/* Do local transmitted message distribution if enabled */
if (processlocal){
+ /* fill CAN message timestamp */
+ can_filltimestamp(&obj->tx_slot->msg.timestamp);
+
obj->tx_slot->msg.flags |= MSG_LOCAL;
canque_filter_msg2edges(obj->qends, &obj->tx_slot->msg);
}
canque_free_outslot(obj->qends, obj->tx_qedge, obj->tx_slot);
obj->tx_slot=NULL;
return;
- }
+ }
+ return;
}
-inline void i82527_irq_read_handler(struct chip_t *chip, struct msgobj_t *obj, int objnum)
+static inline
+void i82527_irq_read_handler(struct chip_t *chip, struct msgobj_t *obj, int objnum)
{
int i;
unsigned long message_id;
}
+ /* fill CAN message timestamp */
+ can_filltimestamp(&obj->rx_msg.timestamp);
+
canque_filter_msg2edges(obj->qends, &obj->rx_msg);
if (msgctl1 & NEWD_SET)
i82527_irq_read_handler(chip, obj, message_id);
*/
-can_irqreturn_t i82527_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
+
+static inline
+void i82527_irq_update_filter(struct chip_t *chip, struct msgobj_t *obj)
+{
+ struct canfilt_t filt;
+
+ if(canqueue_ends_filt_conjuction(obj->qends, &filt)) {
+ obj->rx_preconfig_id=filt.id;
+ canobj_write_reg(chip,obj,(MVAL_RES|TXIE_RES|RXIE_RES|INTPD_RES),iMSGCTL0);
+ if(obj->object == 15) {
+ i82527_message15_mask(chip,filt.id,filt.mask);
+ }
+ if (filt.flags&MSG_EXT)
+ can_msgobj_set_fl(obj,RX_MODE_EXT);
+ else
+ can_msgobj_clear_fl(obj,RX_MODE_EXT);
+
+ i82527_pre_read_config(chip, obj);
+
+ CANMSG("i82527_irq_update_filter: obj at 0x%08lx\n",obj->obj_base_addr);
+ }
+}
+
+
+void i82527_irq_sync_activities(struct chip_t *chip, struct msgobj_t *obj)
+{
+ while(!can_msgobj_test_and_set_fl(obj,TX_LOCK)) {
+
+ if(can_msgobj_test_and_clear_fl(obj,TX_REQUEST)) {
+ if(canobj_read_reg(chip,obj,iMSGCTL1)&TXRQ_RES)
+ i82527_irq_write_handler(chip, obj);
+ }
+
+ if(!obj->tx_slot) {
+ if(can_msgobj_test_and_clear_fl(obj,FILTCH_REQUEST)) {
+ i82527_irq_update_filter(chip, obj);
+ }
+ }
+
+ can_msgobj_clear_fl(obj,TX_LOCK);
+ if(can_msgobj_test_fl(obj,TX_REQUEST))
+ continue;
+ if(can_msgobj_test_fl(obj,FILTCH_REQUEST) && !obj->tx_slot)
+ continue;
+ break;
+ }
+}
+
+int i82527_irq_handler(int irq, struct chip_t *chip)
{
unsigned char msgcfg;
unsigned irq_register;
unsigned object;
- struct chip_t *chip=(struct chip_t *)dev_id;
struct msgobj_t *obj;
/*put_reg=device->hwspecops->write_register;*/
if(!irq_register) {
DEBUGMSG("i82527: spurious IRQ\n");
- return CAN_IRQ_NONE;
+ return CANCHIP_IRQ_NONE;
}
if (irq_register == 0x01) {
DEBUGMSG("Status register: 0x%x\n",can_read_reg(chip, iSTAT));
continue;
- /*return CAN_IRQ_NONE;*/
+ /*return CANCHIP_IRQ_NONE;*/
}
if (irq_register == 0x02)
else if(irq_register < 14)
object = irq_register-3;
else
- return CAN_IRQ_NONE;
+ return CANCHIP_IRQ_NONE;
obj=chip->msgobj[object];
msgcfg = canobj_read_reg(chip,obj,iMSGCFG);
if (msgcfg & MCFG_DIR) {
can_msgobj_set_fl(obj,TX_REQUEST);
- while(!can_msgobj_test_and_set_fl(obj,TX_LOCK)){
- can_msgobj_clear_fl(obj,TX_REQUEST);
-
- if(canobj_read_reg(chip,obj,iMSGCTL1)&TXRQ_RES)
- i82527_irq_write_handler(chip, obj);
-
- can_msgobj_clear_fl(obj,TX_LOCK);
- if(!can_msgobj_test_fl(obj,TX_REQUEST)) break;
- }
+
+ /* calls i82527_irq_write_handler synchronized with other invocations */
+ i82527_irq_sync_activities(chip, obj);
}
else {
} while((irq_register=i82527_seg_read_reg(chip, iIRQ)) != 0);
- return CAN_IRQ_HANDLED;
+ return CANCHIP_IRQ_HANDLED;
}
void i82527_irq_rtr_handler(struct chip_t *chip, struct msgobj_t *obj,
wake_up(&rtr_search->rtr_wq);
}
+/**
+ * i82527_wakeup_tx: - wakeups TX processing
+ * @chip: pointer to chip state structure
+ * @obj: pointer to message object structure
+ *
+ * Function is responsible for initiating message transmition.
+ * It is responsible for clearing of object TX_REQUEST flag
+ *
+ * Return Value: negative value reports error.
+ * File: src/i82527.c
+ */
int i82527_wakeup_tx(struct chip_t *chip, struct msgobj_t *obj)
{
can_preempt_disable();
can_msgobj_set_fl(obj,TX_REQUEST);
- while(!can_msgobj_test_and_set_fl(obj,TX_LOCK)){
- can_msgobj_clear_fl(obj,TX_REQUEST);
- if(canobj_read_reg(chip,obj,iMSGCTL1)&TXRQ_RES)
- i82527_irq_write_handler(chip, obj);
+ /* calls i82527_irq_write_handler synchronized with other invocations
+ from kernel and IRQ context */
+ i82527_irq_sync_activities(chip, obj);
+
+ can_preempt_enable();
+ return 0;
+}
+
+int i82527_filtch_rq(struct chip_t *chip, struct msgobj_t *obj)
+{
+ can_preempt_disable();
- can_msgobj_clear_fl(obj,TX_LOCK);
- if(!can_msgobj_test_fl(obj,TX_REQUEST)) break;
- }
+ can_msgobj_set_fl(obj,FILTCH_REQUEST);
+
+ /* setups filter synchronized with other invocations from kernel and IRQ context */
+ i82527_irq_sync_activities(chip, obj);
can_preempt_enable();
return 0;
chipspecops->send_msg = i82527_send_msg;
chipspecops->check_tx_stat = i82527_check_tx_stat;
chipspecops->wakeup_tx = i82527_wakeup_tx;
+ chipspecops->filtch_rq = i82527_filtch_rq;
chipspecops->remote_request = i82527_remote_request;
chipspecops->enable_configuration = i82527_enable_configuration;
chipspecops->disable_configuration = i82527_disable_configuration;
chipspecops->irq_handler = i82527_irq_handler;
return 0;
}
+
+int i82527_fill_chipspecops(struct chip_t *chip)
+{
+ chip->chip_type="i82527";
+ chip->max_objects=15;
+ i82527_register(chip->chipspecops);
+ return 0;
+}