void netv_transceiver(unsigned char netv_addr) { NETV_MESSAGE g_rMessage; // unsigned char buffer_size = 0; unsigned int offset = 0; while (netv_recv_message(&g_rMessage)) { if (g_rMessage.msg_dest == netv_addr || g_rMessage.msg_dest == 0xFF) { //Analyse for boot mode and I'm alive signal switch (g_rMessage.msg_type) { case NETV_TYPE_EMERGENCY: switch (g_rMessage.msg_cmd) { case NETV_EMERGENCY_CMD_PROGRAM: //indicate to the bootloader that we are gonna program //TODO Update Boot Config //netv_write_eeprom(0xFF,NETV_BOOT_MODE_ID); //TODO FIX THIS //software reset, from reset documentation! //mSYSTEMUnlock(); //Set arm reset //RSWRSTSET = 1; //Read register to trigger reset //volatile int *p = &RSWRST; //Wait until the reset happens //while(1); // Reset(); break; }//end switch msg_cmd break; case NETV_TYPE_EVENTS: switch (g_rMessage.msg_cmd) { case NETV_EVENTS_CMD_ALIVE: //Send i'm alive netv_send_im_alive(netv_addr); break; }//end switch msg_cmd break; case NETV_TYPE_REQUEST_DATA: //get the memory offset offset = g_rMessage.msg_cmd; switch (g_rMessage.msg_read_write) { case NETV_REQUEST_READ: //WE MUST RECEIVE A REMOTE REQUEST... if (g_rMessage.msg_remote == 1) { netv_read_data_flow_table_v2(offset, g_rMessage.msg_eeprom_ram, &g_rMessage.msg_data[0], MIN(g_rMessage.msg_data_length, 8)); g_rMessage.msg_remote = 0; while (netv_send_message(&g_rMessage)) { ; } } break; case NETV_REQUEST_WRITE: // We don't want to overwrite EEPROM table information // The message must not be a remote request if (g_rMessage.msg_remote == 0) { netv_write_data_flow_table_v2(offset, g_rMessage.msg_eeprom_ram, &g_rMessage.msg_data[0], MIN(g_rMessage.msg_data_length, 8)); } break; }//end sub-switch read_write break; } } //if dest // processe the received message netv_proc_message(&g_rMessage); }//while }
////////////////////////////////////////////////////////////////////// // netv_transceiver() ////////////////////////////////////////////////////////////////////// // // Description: MCP2510 unsigned charerrupt sub-routine // Handles all MCP2510 unsigned charerruptions until none are left // // Input: NONE // Output: NONE // Input/Output: NONE // Returned value: NONE // ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// void netv_transceiver(unsigned char netv_addr) { NETV_MESSAGE g_rMessage; // unsigned char buffer_size = 0; unsigned int offset = 0; while(netv_recv_message(&g_rMessage)) { //Analyse for boot mode and I'm alive signal switch(g_rMessage.msg_type){ case NETV_TYPE_EMERGENCY: switch(g_rMessage.msg_cmd){ case NETV_EMERGENCY_CMD_PROGRAM: //indicate to the bootloader that we are gonna program //TODO Update Boot Config //netv_write_eeprom(0xFF,NETV_BOOT_MODE_ID); //wait 10ms //FCY must be defined __delay_ms(10); //reset! asm("RESET"); //Reset(); break; }//end switch msg_cmd break; case NETV_TYPE_EVENTS: switch(g_rMessage.msg_cmd){ case NETV_EVENTS_CMD_ALIVE: //Send i'm alive netv_send_im_alive(netv_addr); break; }//end switch msg_cmd break; case NETV_TYPE_REQUEST_DATA: //get the memory offset offset = g_rMessage.msg_cmd; switch(g_rMessage.msg_read_write){ case NETV_REQUEST_READ: //WE MUST RECEIVE A REMOTE REQUEST... if (g_rMessage.msg_remote == 1) { netv_read_data_flow_table_v2(offset, g_rMessage.msg_eeprom_ram, &g_rMessage.msg_data[0], MIN(g_rMessage.msg_data_length,8)); g_rMessage.msg_remote = 0; while(netv_send_message(&g_rMessage)){;} } break; case NETV_REQUEST_WRITE: // We don't want to overwrite EEPROM table information // The message must not be a remote request if(g_rMessage.msg_remote == 0) { netv_write_data_flow_table_v2(offset, g_rMessage.msg_eeprom_ram, &g_rMessage.msg_data[0], MIN(g_rMessage.msg_data_length,8)); } break; }//end sub-switch read_write break; } // processe the received message netv_proc_message(&g_rMessage); } }