//------------------------------------------------------------------------------ // @fn can_isp_protocol_task //! //! This function initializes the CAN ISP PROTOCOL. //! //! @warning none //! //! @param none //! //! @return none //! //------------------------------------------------------------------------------ void can_isp_protocol_init(void) { isp_select_memory = MEM_DEFAULT; isp_select_page = PAGE_DEFAULT; isp_start_address = ADD_DEFAULT; isp_number_of_bytes = N_DEFAULT; isp_prog_on_going = FALSE; //DEG base_isp_id = (((U16)(get_conf_byte(CRIS))) << 3); //base_isp_id = (((U16)(get_conf_byte(CRIS))) << 4); if(base_isp_id > MAX_BASE_ISP_IAP_ID) base_isp_id = MIN_BASE_ISP_IAP_ID ; //- Init Rx data can_isp_rx_msg.pt_data = &can_isp_rx_buffer[0]; loc_buf_index = 0; //- Prepare Rx Command can_isp_rx_msg.msk.std = MAX_BASE_ISP_IAP_ID; can_isp_rx_msg.cmd = CMD_RX_DATA_MASKED; //- Init Tx data can_isp_tx_msg.pt_data = &can_isp_tx_buffer[0]; //- Prepare Tx Command can_isp_tx_msg.cmd = CMD_TX_DATA; }
static int show_vendor_caps_virtio(struct device *d, int where, int cap) { int length = BITS(cap, 0, 8); int type = BITS(cap, 8, 8); char *tname; if (length < 16) return 0; if (!config_fetch(d, where, length)) return 0; switch (type) { case 1: tname = "CommonCfg"; break; case 2: tname = "Notify"; break; case 3: tname = "ISR"; break; case 4: tname = "DeviceCfg"; break; default: tname = "<unknown>"; break; } printf("VirtIO: %s\n", tname); if (verbose < 2) return 1; printf("\t\tBAR=%d offset=%08x size=%08x", get_conf_byte(d, where + 4), get_conf_long(d, where + 8), get_conf_long(d, where + 12)); if (type == 2 && length >= 20) printf(" multiplier=%08x", get_conf_long(d, where+16)); printf("\n"); return 1; }
//check if alias is in EEPROM U16 alias; alias = (eeprom_rd_byte(0x0FF6)) << 8; alias |= eeprom_rd_byte(0x0FF7); if(alias != 0x0000) { if(alias != 0xFFFF) { put_conf_byte(NNB, (U8)(alias & 0x0F)); put_conf_byte(CRIS, (U8)((alias >> 4) & 0xFF)); } //else, just use the default values, that's fine. hwcb = 0; //force reboot into bootloader } u8_temp = get_conf_byte(BSB); if ( ((u8_temp!=BSB_DEFAULT)&&(hwcb==0)) || ((u8_temp==BSB_DEFAULT)&&(hwcb!=0)) ) { isp_jump_to ( (((U16)get_conf_byte(SA_H))<<8) | ((U16)get_conf_byte(SA_L)) ); // Start application } // else go to BOOT LOADER } //! --- Open CAN communication //turn on LED to indicate bootloader mode. PORTG &= ~_BV(PING0); can_communication_opened = 0; // Not opened //- Pull-up on TxCAN & RxCAN one by one to use bit-addressing
//------------------------------------------------------------------------------ // @fn can_isp_protocol_task //! //! This function manages the CAN ISP PROTOCOL. //! //! @warning none //! //! @param none //! //! @return 0: Re-evaluation of bit-timming asked //! 1: OK (for a new command) //! //------------------------------------------------------------------------------ Bool can_isp_protocol_task(void) { U8 u8_temp,i; //- Prepare Rx Command can_isp_rx_msg.dlc = 8; // Max can_isp_rx_msg.id.std = base_isp_id; //- Rx Command while (can_cmd(&can_isp_rx_msg) != CAN_CMD_ACCEPTED); //- Wait for Rx completed while (1) { u8_temp = can_get_status(&can_isp_rx_msg); if (u8_temp != CAN_STATUS_NOT_COMPLETED) break; // Out of: while(1... } if (u8_temp == CAN_STATUS_ERROR) { return(0); // Re-evaluation of bit-timming asked, out of the function } //flash BLUE to show packet received PORTG ^= _BV(PING0); //--- Switch following CAN ISP resquest received switch ((can_isp_rx_msg.id.std - base_isp_id)) { //- OPEN or CLOSE COMMUNICATION (0x00) ------------------------------------- case CAN_ID_SELECT_NODE: //- The length of the received frame needs to be tested because a //- confusion can appears in case of IAP network when a node //- acknowledges its "Open Communication". Else, this 2-byte //- response could be interpreted by a non-involved slave node //- as an "Open Communication"!!! if ( ((can_isp_rx_buffer[0]==get_conf_byte(NNB))||(can_isp_rx_buffer[0]==0xFF)) \ && (can_isp_rx_msg.dlc==1) ) { if (can_communication_opened == FALSE) { can_communication_opened = TRUE; isp_select_memory = MEM_DEFAULT; isp_select_page = PAGE_DEFAULT; } else { can_communication_opened = FALSE; isp_prog_on_going = FALSE; } //- Acknowledge frame can_isp_tx_msg.id.std = (base_isp_id + CAN_ID_SELECT_NODE); can_isp_tx_msg.dlc = 2; can_isp_tx_buffer[0] = BOOT_VERSION; can_isp_tx_buffer[1] = can_communication_opened; can_isp_send_frame(); PORTG ^= _BV(PING1); } //- Else nothing break; //- START PROGRAMMING (0x01) ------------------------------------- case CAN_ID_PROG_START: if (can_communication_opened) { //- FULL ERASE ------------------------------------------- if ( (can_isp_rx_buffer[0] == CAN_FULL_ERASE_1) && \ (can_isp_rx_buffer[1] == CAN_FULL_ERASE_2) && \ (can_isp_rx_buffer[2] == CAN_FULL_ERASE_3) ) { if (isp_memory_erase() == FALSE) { can_isp_send_error_frame(); break; //- Exit from: case ... } } //- START PROGRAMMING ------------------------------------ else if (can_isp_rx_buffer[0] == CAN_INIT_PROG) { isp_address_range ( ( (((U16)can_isp_rx_buffer[1])<<8) | ((U16)can_isp_rx_buffer[2]) ) , \ ( (((U16)can_isp_rx_buffer[3])<<8) | ((U16)can_isp_rx_buffer[4]) ) ) ; loc_buf_index = 0; isp_prog_on_going = TRUE; //- Save pointer and size for block programming using isp_start_address_copy = isp_start_address; isp_number_of_bytes_copy = isp_number_of_bytes; } //- ERROR WHEN START PROGRAMMING ------------------------- else { can_isp_send_error_frame(); break; //- Exit from: case ... } //- Acknowledge frame can_isp_tx_msg.id.std = (base_isp_id + CAN_ID_PROG_START); can_isp_tx_buffer[0] = COMMAND_OK; can_isp_tx_msg.dlc = 1; if(isp_prog_on_going == TRUE) { can_isp_tx_msg.dlc = 0; } can_isp_send_frame(); } //- Else nothing break; //- DATA PROGRAMMING (0x02) -------------------------------------- case CAN_ID_PROG_DATA: if (can_communication_opened) { if ( isp_prog_on_going == TRUE ) { //- BLOCK PROGRAMMING -------------------------------- for (i=0; i<can_isp_rx_msg.dlc; i++) { local_buffer[loc_buf_index] = can_isp_rx_buffer[i]; loc_buf_index++; u8_temp = 0x00; } if ( (loc_buf_index > ((U16)(LOCAL_BUFFER_SIZE - 0x08))) || \ (loc_buf_index == isp_number_of_bytes) ) { u8_temp = isp_prog_block(local_buffer, loc_buf_index); loc_buf_index = 0; } //- Acknowledge frame can_isp_tx_msg.id.std = (base_isp_id + CAN_ID_PROG_DATA); can_isp_tx_msg.dlc = 1; if (u8_temp == 0x00) { can_isp_tx_buffer[0] = OK_NEW_DATA; } else if (u8_temp == 0x01) { can_isp_tx_buffer[0] = OK_END_OF_DATA; isp_prog_on_going = FALSE; //- Restore pointer and size isp_start_address = isp_start_address_copy; isp_number_of_bytes = isp_number_of_bytes_copy; } else //- u8_temp == 0xFF, error (ex: SSB cause) { isp_prog_on_going = FALSE; can_isp_send_error_frame(); break; //- Exit from: case ... //- CARE: Pointer and size not restored } can_isp_send_frame(); } //- ERROR WHEN BLOCK PROGRAMMING ------------------------- else { can_isp_send_error_frame(); } } //- Else nothing break; //- DATA DISPLAY (0x03) ------------------------------------------ case CAN_ID_DISPLAY_DATA: if (can_communication_opened) { //- Prepare acknowledge frame can_isp_tx_msg.id.std = (base_isp_id + CAN_ID_DISPLAY_DATA); can_isp_tx_msg.dlc = 0; isp_address_range ( ( (((U16)can_isp_rx_buffer[1])<<8) | ((U16)can_isp_rx_buffer[2]) ) , \ ( (((U16)can_isp_rx_buffer[3])<<8) | ((U16)can_isp_rx_buffer[4]) ) ) ; //- Save pointer and size isp_start_address_copy = isp_start_address; isp_number_of_bytes_copy = isp_number_of_bytes; //- READ DATA -------------------------------------------- if (can_isp_rx_buffer[0] == CAN_READ_DATA) { can_isp_tx_msg.dlc = 8; //- default while (1) { //- Using of "can_isp_tx_buffer" to store the blocks u8_temp = isp_read_block(can_isp_tx_buffer,8); if (u8_temp == 0x00) { can_isp_send_frame(); //- Intermediate block } else if (u8_temp == 0x01) { can_isp_tx_msg.dlc = isp_number_of_bytes; can_isp_send_frame(); //- Last block break; //- Exit from: while ... } else //- u8_temp == 0xFF, error (ex: SSB cause) { can_isp_send_error_frame(); break; //- Exit from: while ... } } } //- BLANK CHECK ------------------------------------------ else if (can_isp_rx_buffer[0] == CAN_BLANK_CHECK) { if ( isp_blank_check() == FALSE ) { //- Prepare to send 1st failed address can_isp_tx_msg.dlc = 2; can_isp_tx_buffer[0] = (U8)(isp_start_address >>8); can_isp_tx_buffer[1] = (U8)(isp_start_address); } //- Acknowledge frame or send 1st failed address can_isp_send_frame(); } //- ERROR WHEN DATA DISPLAY ------------------------------ else { can_isp_send_error_frame(); break; //- Exit from: case ... } //- Restore pointer and size isp_start_address = isp_start_address_copy; isp_number_of_bytes = isp_number_of_bytes_copy; }