Esempio n. 1
0
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    can_parameter_struct            can_init_parameter;
    can_filter_parameter_struct     can_filter_parameter;

    receive_flag = RESET;
    /* configure Tamper key */
    gd_eval_keyinit(KEY_TAMPER, KEY_MODE_GPIO);
    /* configure GPIO */
    gpio_config();
    /* configure USART */
    gd_eval_COMinit(EVAL_COM2);
    /* configure NVIC */
    nvic_config();
    /* configure leds */
    led_config();
    /* set all leds off */
    gd_eval_ledoff(LED1);
    gd_eval_ledoff(LED2);
    gd_eval_ledoff(LED3);
    gd_eval_ledoff(LED4);
    /* initialize CAN */
    can_networking_init(can_init_parameter, can_filter_parameter);
    /* enable phy */
#ifdef CAN0_USED 
    can_phy_enable(CANX);
#endif
    /* enable CAN receive FIFO0 not empty interrupt */
    can_interrupt_enable(CANX, CAN_INTEN_RFNEIE0);
    
    /* initialize transmit message */
    transmit_message.can_tx_sfid = 0x321;
    transmit_message.can_tx_efid = 0x01;
    transmit_message.can_tx_ft = CAN_FT_DATA;
    transmit_message.can_tx_ff = CAN_FF_STANDARD;
    transmit_message.can_tx_dlen = 1;
    printf("please press the Tamper key to transmit data!\r\n");
    while(1){
        /* waiting for the Tamper key pressed */
        while(0 == gd_eval_keygetstate(KEY_TAMPER)){
            /* if transmit_number is 0x10, set it to 0x00 */
            if(transmit_number == 0x10){
                transmit_number = 0x00;
            }else{
                transmit_message.can_tx_data[0] = transmit_number++;
                printf("transmit data: %x\r\n", transmit_message.can_tx_data[0]);
                /* transmit message */
                can_transmit_message(CANX, &transmit_message);
                delay();
                /* waiting for Tamper key up */
                while(0 == gd_eval_keygetstate(KEY_TAMPER));
            }
        }
        if(SET == receive_flag){
            gd_eval_ledtoggle(LED1);
            receive_flag = RESET;
            printf("recive data: %x\r\n", receive_message.can_rx_data[0]);
        }
    } 
}
Esempio n. 2
0
/** Config the interrupt .
 *
 *  @param can_periph CAN0 or CAN1.
 *  @param interrupt The interrupt type.
 *  @param enable enable or disable.
 */
static void dev_can_interrupt_config(uint32_t can_periph, uint32_t interrupt, uint32_t enable)
{
    if (enable) {
        can_interrupt_enable(can_periph, interrupt);
    } else {
        can_interrupt_disable(can_periph, interrupt);
    }
}