uint32_t can_init_mailboxes(uint32_t x)
{
	/* Init CAN0 Mailbox 7 to Transmit Mailbox. */	
	/* CAN0 MB7 == COMMAND/MSG MB				*/
	//configASSERT(x);	//Check if this function was called naturally.
	
	reset_mailbox_conf(&can0_mailbox);
	can0_mailbox.ul_mb_idx = 7;			//Mailbox Number 7
	can0_mailbox.uc_obj_type = CAN_MB_TX_MODE;
	can0_mailbox.uc_tx_prio = 5;		//Transmission Priority (Can be Changed dynamically)
	can0_mailbox.uc_id_ver = 0;
	can0_mailbox.ul_id_msk = 0;
	can_mailbox_init(CAN0, &can0_mailbox);
	
	/* Init CAN1 Mailbox 0 to Reception Mailbox. */
	reset_mailbox_conf(&can1_mailbox);
	can1_mailbox.ul_mb_idx = 0;				// Mailbox 0
	can1_mailbox.uc_obj_type = CAN_MB_RX_MODE;
	can1_mailbox.ul_id_msk = CAN_MID_MIDvA_Msk | CAN_MID_MIDvB_Msk;	  // Compare the full 11 bits of the ID in both standard and extended.
	can1_mailbox.ul_id = CAN_MID_MIDvA(NODE0_ID);					  // The ID of CAN1 MB0 is currently NODE0_ID (standard).
	can_mailbox_init(CAN1, &can1_mailbox);
	
	can_enable_interrupt(CAN1, CAN_IER_MB0);
	
	/* Init CAN0 Mailbox 6 to Housekeeping Request Mailbox. */	
	reset_mailbox_conf(&can0_mailbox);
	can0_mailbox.ul_mb_idx = 6;			//Mailbox Number 6
	can0_mailbox.uc_obj_type = CAN_MB_TX_MODE;
	can0_mailbox.uc_tx_prio = HK_REQUEST_PRIO;		//Transmission Priority (Can be Changed dynamically)
	can0_mailbox.uc_id_ver = 0;
	can0_mailbox.ul_id_msk = 0;
	can_mailbox_init(CAN0, &can0_mailbox);

	return 1;
}
示例#2
0
/**
 *  \brief Test the communication between CAN1 Mailbox 3 and CAN0 Mailbox 3.
 */
static void test_4(void)
{
	can_reset_all_mailbox(CAN0);
	can_reset_all_mailbox(CAN1);

	puts("\n\rTest4: CAN1 Mailbox 3 requesting");
	puts("CAN0 Mailbox 3 to transmit a data frame" STRING_EOL);

	/* Init CAN0 Mailbox 3 to Producer Mailbox. */
	reset_mailbox_conf(&can0_mailbox);
	can0_mailbox.ul_mb_idx = TEST4_CAN0_MB_IDX;
	can0_mailbox.uc_obj_type = CAN_MB_PRODUCER_MODE;
	can0_mailbox.ul_id_msk = 0;
	can0_mailbox.ul_id = CAN_MID_MIDvA(TEST4_CAN0_MB_ID);
	can_mailbox_init(CAN0, &can0_mailbox);

	/* Prepare the response information when it receives a remote frame. */
	can0_mailbox.ul_datal = CAN_MSG_TOGGLE_LED_0;
	can0_mailbox.ul_datah = CAN_MSG_DUMMY_DATA;
	can0_mailbox.uc_length = MAX_CAN_FRAME_DATA_LEN;
	can_mailbox_write(CAN0, &can0_mailbox);

	can_global_send_transfer_cmd(CAN0, CAN_TCR_MB3);

	/* Init CAN1 Mailbox 3 to Consumer Mailbox. It sends a remote frame and waits for an answer. */
	reset_mailbox_conf(&can1_mailbox);
	can1_mailbox.ul_mb_idx = TEST4_CAN1_TX_MB_IDX;
	can1_mailbox.uc_obj_type = CAN_MB_CONSUMER_MODE;
	can1_mailbox.uc_tx_prio = TEST4_CAN1_TX_MB_PRIO;
	can1_mailbox.ul_id_msk = CAN_MID_MIDvA_Msk | CAN_MID_MIDvB_Msk;
	can1_mailbox.ul_id = CAN_MID_MIDvA(TEST4_CAN1_TX_MB_ID);
	can_mailbox_init(CAN1, &can1_mailbox);

	/* Enable CAN1 mailbox 3 interrupt. */
	can_enable_interrupt(CAN1, CAN_IER_MB3);

	can_global_send_transfer_cmd(CAN1, CAN_TCR_MB3);
	while (!g_ul_recv_status) {
	}

	if ((can1_mailbox.ul_datal == CAN_MSG_TOGGLE_LED_0) &&
		(can1_mailbox.uc_length == MAX_CAN_FRAME_DATA_LEN)) {
		puts("Test4 passed" STRING_EOL);
		decode_can_msg(&can1_mailbox);
	} else {
		puts("Test4 ERROR" STRING_EOL);
	}
}
示例#3
0
/**
 *  \brief Test the transmission from CAN0 Mailbox 0 to CAN1 Mailbox 0.
 */
static void test_1(void)
{
	can_reset_all_mailbox(CAN0);
	can_reset_all_mailbox(CAN1);

	puts("\n\rTest1: CAN0 Mailbox 0 transmitting to CAN1 Mailbox 0" STRING_EOL);

	/* Init CAN1 Mailbox 0 to Reception Mailbox. */
	reset_mailbox_conf(&can1_mailbox);
	can1_mailbox.ul_mb_idx = TEST1_CAN_COMM_MB_IDX;
	can1_mailbox.uc_obj_type = CAN_MB_RX_MODE;
	can1_mailbox.ul_id_msk = CAN_MAM_MIDvA_Msk | CAN_MAM_MIDvB_Msk;
	can1_mailbox.ul_id = CAN_MID_MIDvA(TEST1_CAN_TRANSFER_ID);
	can_mailbox_init(CAN1, &can1_mailbox);

	/* Init CAN0 Mailbox 0 to Transmit Mailbox. */
	reset_mailbox_conf(&can0_mailbox);
	can0_mailbox.ul_mb_idx = TEST1_CAN_COMM_MB_IDX;
	can0_mailbox.uc_obj_type = CAN_MB_TX_MODE;
	can0_mailbox.uc_tx_prio = TEST1_CAN0_TX_PRIO;
	can0_mailbox.uc_id_ver = 0;
	can0_mailbox.ul_id_msk = 0;
	can_mailbox_init(CAN0, &can0_mailbox);

	/* Write transmit information into mailbox. */
	can0_mailbox.ul_id = CAN_MID_MIDvA(TEST1_CAN_TRANSFER_ID);
	can0_mailbox.ul_datal = CAN_MSG_TOGGLE_LED_0;
	can0_mailbox.ul_datah = CAN_MSG_DUMMY_DATA;
	can0_mailbox.uc_length = MAX_CAN_FRAME_DATA_LEN;
	can_mailbox_write(CAN0, &can0_mailbox);

	/* Enable CAN1 mailbox 0 interrupt. */
	can_enable_interrupt(CAN1, CAN_IER_MB0);

	/* Send out the information in the mailbox. */
	can_global_send_transfer_cmd(CAN0, CAN_TCR_MB0);

	while (!g_ul_recv_status) {
	}

	if ((can1_mailbox.ul_datal == CAN_MSG_TOGGLE_LED_0) &&
		(can1_mailbox.uc_length == MAX_CAN_FRAME_DATA_LEN)) {
		puts("Test1 passed" STRING_EOL);
		decode_can_msg(&can1_mailbox);
	} else {
		puts("Test1 ERROR" STRING_EOL);
	}
}
uint32_t request_housekeeping(uint32_t ID)
{
	/* Save current can0_mailbox object */
	can_temp_t temp_mailbox;
	save_can_object(&can0_mailbox, &temp_mailbox);
	
	/* Init CAN0 Mailbox 6 to Housekeeping Request Mailbox. */	
	reset_mailbox_conf(&can0_mailbox);
	can0_mailbox.ul_mb_idx = 6;			//Mailbox Number 6
	can0_mailbox.uc_obj_type = CAN_MB_TX_MODE;
	can0_mailbox.uc_tx_prio = HK_REQUEST_PRIO;		//Transmission Priority (Can be Changed dynamically)
	can0_mailbox.uc_id_ver = 0;
	can0_mailbox.ul_id_msk = 0;
	can_mailbox_init(CAN0, &can0_mailbox);

	/* Write transmit information into mailbox. */
	can0_mailbox.ul_id = CAN_MID_MIDvA(ID);			// ID of the message being sent,
	can0_mailbox.ul_datal = HK_REQUEST;				// shifted over to the standard frame position.
	can0_mailbox.ul_datah = HK_REQUEST;
	can0_mailbox.uc_length = MAX_CAN_FRAME_DATA_LEN;
	can_mailbox_write(CAN0, &can0_mailbox);

	/* Send out the information in the mailbox. */
	can_global_send_transfer_cmd(CAN0, CAN_TCR_MB6);
	
	/* Restore the can0_mailbox object */
	restore_can_object(&can0_mailbox, &temp_mailbox);
		
	return 1;
}
/**
 * \brief Responds to he command from CAN0 and sends to CAN1
 **/
void command_in(void)
{
	pio_toggle_pin(LED0_GPIO);
	
	can_disable_interrupt(CAN0, CAN_IER_MB0);
	NVIC_DisableIRQ(CAN0_IRQn);
	
	can_reset_all_mailbox(CAN0);
	can_reset_all_mailbox(CAN1);

	/* Init CAN1 Mailbox 0 to Reception Mailbox. */
	reset_mailbox_conf(&can0_mailbox);
	can1_mailbox.ul_mb_idx = 1;
	can1_mailbox.uc_obj_type = CAN_MB_RX_MODE;
	can1_mailbox.ul_id_msk = CAN_MAM_MIDvA_Msk | CAN_MAM_MIDvB_Msk;
	can1_mailbox.ul_id = CAN_MID_MIDvA(7);
	can_mailbox_init(CAN1, &can1_mailbox);

	/* Init CAN0 Mailbox 0 to Transmit Mailbox. */
	reset_mailbox_conf(&can0_mailbox);
	can0_mailbox.ul_mb_idx = 1;
	can0_mailbox.uc_obj_type = CAN_MB_TX_MODE;
	can0_mailbox.uc_tx_prio = 15;
	can0_mailbox.uc_id_ver = 0;
	can0_mailbox.ul_id_msk = 0;
	can_mailbox_init(CAN0, &can0_mailbox);

	/* Write transmit information into mailbox. */
	can0_mailbox.ul_id = CAN_MID_MIDvA(7);
	can0_mailbox.ul_datal = COMMAND_OUT;
	can0_mailbox.ul_datah = CAN_MSG_DUMMY_DATA;
	can0_mailbox.uc_length = MAX_CAN_FRAME_DATA_LEN;
	can_mailbox_write(CAN0, &can0_mailbox);

	/* Enable CAN1 mailbox 0 interrupt. */
	can_enable_interrupt(CAN1, CAN_IER_MB1);

	/* Send out the information in the mailbox. */
	can_global_send_transfer_cmd(CAN0, CAN_TCR_MB1);

	/* potentially @non-terminating@ */
	while (!g_ul_recv_status) {
	}
}
uint32_t send_can_command(uint32_t low, uint32_t high, uint32_t ID, uint32_t PRIORITY)
{	
	/* We don't need to worry about saving and restoring the state of the can0_mailbox
	*  because the interrupt handlers should do that for us, and in the future only one
	*  task will be allowed in a CAN mailbox at any point in the through the use of
	*  mutex locks.
	*
	*  Another thing! Don't place this function in a for loop if you plan on using it to
	*  send from the same mailbox over and over again, make sure to yield in between calls
	*  if that is what you're trying to do. Also, be sure to release and acquire mutex locks
	*  in between each use of the CAN resource.
	*/
	
	
	/* Save current can0_mailbox object */
	can_temp_t temp_mailbox;
	save_can_object(&can0_mailbox, &temp_mailbox);
	
	/* Init CAN0 Mailbox 7 to Transmit Mailbox. */	
	/* CAN0 MB7 == COMMAND/MSG MB				*/
	reset_mailbox_conf(&can0_mailbox);
	can0_mailbox.ul_mb_idx = 7;			//Mailbox Number 7
	can0_mailbox.uc_obj_type = CAN_MB_TX_MODE;
	can0_mailbox.uc_tx_prio = 9;		//Transmission Priority (Can be Changed dynamically)
	can0_mailbox.uc_id_ver = 0;
	can0_mailbox.ul_id_msk = 0;
	can_mailbox_init(CAN0, &can0_mailbox);

	/* Write transmit information into mailbox. */
	can0_mailbox.ul_id = CAN_MID_MIDvA(ID);			// ID of the message being sent,
	can0_mailbox.ul_datal = low;					// shifted over to the standard frame position.
	can0_mailbox.ul_datah = high;
	can0_mailbox.uc_length = MAX_CAN_FRAME_DATA_LEN;
	can_mailbox_write(CAN0, &can0_mailbox);

	/* Send out the information in the mailbox. */
	can_global_send_transfer_cmd(CAN0, CAN_TCR_MB7);
	
	/* Restore the can0_mailbox object */
	restore_can_object(&can0_mailbox, &temp_mailbox);
	
	return 1;
}
示例#7
0
文件: main.c 项目: jfri2/Purdue_MLEC
int main (void) {
 
	/* Initializations */
	sysclk_init();
	board_init();
	
	pio_set(BUZ_PIO, BUZ_PIN);
	delay_ms(50);
	pio_clear(BUZ_PIO, BUZ_PIN);
	delay_ms(50);
	pio_set(BUZ_PIO, BUZ_PIN);
	delay_ms(50);
	pio_clear(BUZ_PIO, BUZ_PIN);

	pio_set(ULED3_PIO, ULED3_PIN);
	delay_ms(100);		
	pio_set(MAIN1_CONTACTOR_PIO, MAIN1_CONTACTOR_PIN);
	delay_ms(100);
	pio_clear(MAIN1_CONTACTOR_PIO, MAIN1_CONTACTOR_PIN);
	delay_ms(100);		
	pio_set(ASTR_CONTACTOR_PIO, ASTR_CONTACTOR_PIN);
	delay_ms(100);
	pio_clear(ASTR_CONTACTOR_PIO, ASTR_CONTACTOR_PIN);
	delay_ms(100);				
	pio_set(BSTR_CONTACTOR_PIO, BSTR_CONTACTOR_PIN);
	delay_ms(100);
	pio_clear(BSTR_CONTACTOR_PIO, BSTR_CONTACTOR_PIN);
	delay_ms(100);				
	pio_set(PCRG_CONTACTOR_PIO, PCRG_CONTACTOR_PIN);
	delay_ms(100);
	pio_clear(PCRG_CONTACTOR_PIO, PCRG_CONTACTOR_PIN);
	delay_ms(100);				
	pio_set(MAIN2_CONTACTOR_PIO, MAIN2_CONTACTOR_PIN);
	delay_ms(100);
	pio_clear(MAIN2_CONTACTOR_PIO, MAIN2_CONTACTOR_PIN);		
	pio_clear(ULED3_PIO, ULED3_PIN);
				
	can_mb_conf_t rlec_can_mailbox;
	can_mb_conf_t v_can_mailbox;
	
	/* Application */				
	while(1) {
		pio_clear(ULED3_PIO, ULED3_PIN);
		pio_set(ULED2_PIO, ULED2_PIN);
		usart_putchar(CONSOLE_USART, 's');		
			
		v_can_mailbox.ul_mb_idx = 0;
		v_can_mailbox.uc_obj_type = CAN_MB_TX_MODE;
		v_can_mailbox.uc_tx_prio = 15;	// previously 15
		v_can_mailbox.uc_id_ver = 0;
		v_can_mailbox.ul_id_msk = 0;		
		can_mailbox_init(V_CAN, &v_can_mailbox);
		
		v_can_mailbox.ul_id = CAN_MID_MIDvA(0x07);
		v_can_mailbox.ul_datal = 0x12345678;
		v_can_mailbox.ul_datah = 0x87654321;
		v_can_mailbox.uc_length = 8;
		can_mailbox_write(V_CAN, &v_can_mailbox);
					
		can_global_send_transfer_cmd(V_CAN, CAN_TCR_MB0);
		pio_clear(ULED2_PIO, ULED2_PIN);
		while (!(can_mailbox_get_status(CAN0, 0) & CAN_MSR_MRDY)) {
			pio_set(ULED3_PIO, ULED3_PIN);
		}
	}
}
示例#8
0
/**
 *  \brief Test the transmission from CAN0 Mailboxes 1 & 2 to CAN1 Mailbox 7 with overwrite.
 */
static void test_3(void)
{
	can_reset_all_mailbox(CAN0);
	can_reset_all_mailbox(CAN1);

	puts("\n\rTest3: CAN0 Mailboxes 1 & 2 transmitting to");
	puts("CAN1 Mailbox 7 with overwrite." STRING_EOL);

	/* Init CAN1 Mailbox 7 to Reception Mailbox with overwrite. */
	reset_mailbox_conf(&can1_mailbox);
	can1_mailbox.ul_mb_idx = TEST3_CAN1_RX_MB_IDX;
	can1_mailbox.uc_obj_type = CAN_MB_RX_OVER_WR_MODE;
	can1_mailbox.ul_id_msk = 0;
	can1_mailbox.ul_id = 0;
	can_mailbox_init(CAN1, &can1_mailbox);

	/* Init CAN0 Mailbox 1 to Transmit Mailbox. This message will be discarded. */
	reset_mailbox_conf(&can0_mailbox);
	can0_mailbox.ul_mb_idx = TEST3_CAN0_TX_MB1_IDX;
	can0_mailbox.uc_obj_type = CAN_MB_TX_MODE;
	can0_mailbox.uc_tx_prio = TEST3_CAN0_TX_MB1_PRIO;
	can0_mailbox.uc_id_ver = 0;
	can0_mailbox.ul_id_msk = 0;
	can_mailbox_init(CAN0, &can0_mailbox);

	/* Write transmit information into mailbox. */
	can0_mailbox.ul_id = CAN_MID_MIDvA(TEST3_CAN0_TX_MB1_ID);
	can0_mailbox.ul_datal = CAN_MSG_TOGGLE_LED_0;
	can0_mailbox.ul_datah = CAN_MSG_DUMMY_DATA;
	can0_mailbox.uc_length = MAX_CAN_FRAME_DATA_LEN;
	can_mailbox_write(CAN0, &can0_mailbox);

	/* Init CAN0 Mailbox 2 to Transmit Mailbox. This message will be received first. */
	reset_mailbox_conf(&can0_mailbox);
	can0_mailbox.ul_mb_idx = TEST3_CAN0_TX_MB2_IDX;
	can0_mailbox.uc_obj_type = CAN_MB_TX_MODE;
	can0_mailbox.uc_tx_prio = TEST3_CAN0_TX_MB2_PRIO;
	can0_mailbox.uc_id_ver = 0;
	can0_mailbox.ul_id_msk = 0;
	can_mailbox_init(CAN0, &can0_mailbox);

	/* Write transmit information into mailbox. */
	can0_mailbox.ul_id = CAN_MID_MIDvA(TEST3_CAN0_TX_MB2_ID);
	can0_mailbox.ul_datal = CAN_MSG_TOGGLE_LED_1;
	can0_mailbox.ul_datah = CAN_MSG_DUMMY_DATA;
	can0_mailbox.uc_length = MAX_CAN_FRAME_DATA_LEN;
	can_mailbox_write(CAN0, &can0_mailbox);

	/* Send out the information in mailbox 1 & 2 at the same time. */
	can_global_send_transfer_cmd(CAN0, (CAN_TCR_MB1 | CAN_TCR_MB2));

	puts("Wait for all the transmit mailboxes done." STRING_EOL);

	/* Enable CAN1 mailbox 7 interrupt. */
	can_enable_interrupt(CAN1, CAN_IER_MB7);

	while (!g_ul_recv_status) {
	}

	if ((can1_mailbox.ul_datal == CAN_MSG_TOGGLE_LED_0) &&
		(can1_mailbox.uc_length == MAX_CAN_FRAME_DATA_LEN)) {
		puts("Test3 passed" STRING_EOL);
		decode_can_msg(&can1_mailbox);
	} else {
		puts("Test3 ERROR" STRING_EOL);
	}
}