* This function configures chip and prepares it for message
* transmission and reception. The function resets chip,
* resets mask for acceptance of all messages by call to
* This function configures chip and prepares it for message
* transmission and reception. The function resets chip,
* resets mask for acceptance of all messages by call to
* computes and sets baudrate with use of function sja1000p_baud_rate().
* Return Value: negative value reports error.
* File: src/sja1000p.c
* computes and sets baudrate with use of function sja1000p_baud_rate().
* Return Value: negative value reports error.
* File: src/sja1000p.c
if (sja1000p_enable_configuration(chip))
return -ENODEV;
/* Set mode, clock out, comparator */
if (sja1000p_enable_configuration(chip))
return -ENODEV;
/* Set mode, clock out, comparator */
/* Ensure, that interrupts are disabled even on the chip level now */
can_write_reg(chip, sjaDISABLE_INTERRUPTS, SJAIER);
/* Set driver output configuration */
/* Ensure, that interrupts are disabled even on the chip level now */
can_write_reg(chip, sjaDISABLE_INTERRUPTS, SJAIER);
/* Set driver output configuration */
/* Simple check for chip presence */
for (i=0, n=0x5a; i<8; i++, n+=0xf) {
can_write_reg(chip,n,SJAACR0+i);
/* Simple check for chip presence */
for (i=0, n=0x5a; i<8; i++, n+=0xf) {
can_write_reg(chip,n,SJAACR0+i);
if (!chip->baudrate)
chip->baudrate=1000000;
if (sja1000p_baud_rate(chip,chip->baudrate,chip->clock,0,75,0))
return -ENODEV;
/* Enable hardware interrupts */
if (!chip->baudrate)
chip->baudrate=1000000;
if (sja1000p_baud_rate(chip,chip->baudrate,chip->clock,0,75,0))
return -ENODEV;
/* Enable hardware interrupts */
for(i=SJA_PeliCAN_AC_LEN; --i>=0;) {
can_write_reg(chip,code&0xff,SJAACR0+i);
can_write_reg(chip,mask&0xff,SJAAMR0+i);
for(i=SJA_PeliCAN_AC_LEN; --i>=0;) {
can_write_reg(chip,code&0xff,SJAACR0+i);
can_write_reg(chip,mask&0xff,SJAAMR0+i);
int best_error = 1000000000, error;
int best_tseg=0, best_brp=0, best_rate=0, brp=0;
int tseg=0, tseg1=0, tseg2=0;
int best_error = 1000000000, error;
int best_tseg=0, best_brp=0, best_rate=0, brp=0;
int tseg=0, tseg1=0, tseg2=0;
if(status & sjaSR_BS) {
/* Try to recover from error condition */
DEBUGMSG("sja1000p_pre_read_config bus-off recover 0x%x\n",status);
if(status & sjaSR_BS) {
/* Try to recover from error condition */
DEBUGMSG("sja1000p_pre_read_config bus-off recover 0x%x\n",status);
if(status & sjaSR_BS) {
/* Try to recover from error condition */
DEBUGMSG("sja1000p_pre_write_config bus-off recover 0x%x\n",status);
if(status & sjaSR_BS) {
/* Try to recover from error condition */
DEBUGMSG("sja1000p_pre_write_config bus-off recover 0x%x\n",status);
if(obj->tx_slot){
/* Do local transmitted message distribution if enabled */
if (processlocal){
/* fill CAN message timestamp */
can_filltimestamp(&obj->tx_slot->msg.timestamp);
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);
}
obj->tx_slot->msg.flags |= MSG_LOCAL;
canque_filter_msg2edges(obj->qends, &obj->tx_slot->msg);
}
can_msgobj_clear_fl(obj,TX_PENDING);
cmd=canque_test_outslot(obj->qends, &obj->tx_qedge, &obj->tx_slot);
if(cmd<0)
can_msgobj_clear_fl(obj,TX_PENDING);
cmd=canque_test_outslot(obj->qends, &obj->tx_qedge, &obj->tx_slot);
if(cmd<0)
* sja1000p_irq_handler: - interrupt service routine
* @irq: interrupt vector number, this value is system specific
* @chip: pointer to chip state structure
* sja1000p_irq_handler: - interrupt service routine
* @irq: interrupt vector number, this value is system specific
* @chip: pointer to chip state structure
* Interrupt handler is activated when state of CAN controller chip changes,
* there is message to be read or there is more space for new messages or
* error occurs. The receive events results in reading of the message from
* Interrupt handler is activated when state of CAN controller chip changes,
* there is message to be read or there is more space for new messages or
* error occurs. The receive events results in reading of the message from
// Some error happened
error_code=can_read_reg(chip,SJAECC);
sja1000_report_error(chip, status, irq_register, error_code);
// FIXME: chip should be brought to usable state. Transmission cancelled if in progress.
// Reset flag set to 0 if chip is already off the bus. Full state report
obj->ret=-1;
// Some error happened
error_code=can_read_reg(chip,SJAECC);
sja1000_report_error(chip, status, irq_register, error_code);
// FIXME: chip should be brought to usable state. Transmission cancelled if in progress.
// Reset flag set to 0 if chip is already off the bus. Full state report
obj->ret=-1;
can_msgobj_set_fl(obj,TX_PENDING);
can_msgobj_set_fl(obj,TX_REQUEST);
while(!can_msgobj_test_and_set_fl(obj,TX_LOCK)){
can_msgobj_set_fl(obj,TX_PENDING);
can_msgobj_set_fl(obj,TX_REQUEST);
while(!can_msgobj_test_and_set_fl(obj,TX_LOCK)){
can_msgobj_clear_fl(obj,TX_LOCK);
if(!can_msgobj_test_fl(obj,TX_REQUEST)) break;
DEBUGMSG("TX looping in sja1000p_wakeup_tx\n");
can_msgobj_clear_fl(obj,TX_LOCK);
if(!can_msgobj_test_fl(obj,TX_REQUEST)) break;
DEBUGMSG("TX looping in sja1000p_wakeup_tx\n");