static void handle_message(struct cfw_message * msg, void * param) { switch (CFW_MESSAGE_ID(msg)) { case MSG_ID_LL_ERASE_BLOCK_REQ: handle_erase_block(msg); break; case MSG_ID_LL_READ_PARTITION_REQ: handle_read_partition(msg); break; case MSG_ID_LL_WRITE_PARTITION_REQ: handle_write_partition(msg); break; #ifdef CONFIG_SERVICES_QUARK_SE_STORAGE_CIRCULAR case MSG_ID_LL_CIR_STOR_INIT_REQ: handle_cir_stor_init(msg); break; case MSG_ID_LL_PUSH_REQ: handle_push(msg); break; case MSG_ID_LL_POP_REQ: handle_pop(msg); break; case MSG_ID_LL_PEEK_REQ: handle_peek(msg); break; case MSG_ID_LL_CLEAR_REQ: handle_clear(msg); break; #endif default: cfw_print_default_handle_error_msg(LOG_MODULE_MAIN, CFW_MESSAGE_ID(msg)); break; } cfw_msg_free(msg); }
int main(void) { int16_t command = -1; uint16_t freemem; // set for 8 MHz clock because of 3.3v regulator CPU_PRESCALE(1); // set for 16 MHz clock //CPU_PRESCALE(0); //disable JTAG MCUCR = (1<<JTD) | (1<<IVCE) | (0<<PUD); MCUCR = (1<<JTD) | (0<<IVSEL) | (0<<IVCE) | (0<<PUD); // set all i/o lines to input releaseports(); //Init SPI SPI_Init(SPI_SPEED_FCPU_DIV_2 | SPI_ORDER_MSB_FIRST | SPI_SCK_LEAD_RISING | SPI_SAMPLE_LEADING | SPI_MODE_MASTER); hwspi_init(); // Initialize the USB, and then wait for the host to set configuration. // If the Teensy is powered without a PC connected to the USB port, // this will wait forever. usb_init(); while (!usb_configured()) /* wait */ ; // Wait an extra second for the PC's operating system to load drivers // and do whatever it does to actually be ready for input _delay_ms(1000); while (1) { // discard anything that was received prior. Sometimes the // operating system or other software will send a modem // "AT command", which can still be buffered. usb_serial_flush_input(); while (usb_configured()) { // is user still connected? command = usb_serial_getchar(); if (command == -1) continue; switch (command) { case CMD_PING1: usb_serial_putchar(VERSION_MAJOR); break; case CMD_PING2: freemem = freeRam(); usb_serial_putchar(VERSION_MINOR); usb_serial_putchar((freemem >> 8) & 0xFF); usb_serial_putchar(freemem & 0xFF); break; case CMD_BOOTLOADER: bootloader(); break; case CMD_IO_LOCK: break; case CMD_IO_RELEASE: break; case CMD_PULLUPS_DISABLE: IO_PULLUPS = 0; break; case CMD_PULLUPS_ENABLE: IO_PULLUPS = 0xFF; break; case CMD_SPI_ID: handle_read_id(); break; case CMD_SPI_READBLOCK: handle_read_block(); break; case CMD_SPI_WRITESECTOR: handle_write_block(); break; case CMD_SPI_ERASEBLOCK: handle_erase_block(); break; case CMD_SPI_ERASECHIP: handle_erase_chip(); break; case CMD_SPI_3BYTE_ADDRESS: SPI_ADDRESS_LENGTH = 3; break; case CMD_SPI_4BYTE_ADDRESS: SPI_ADDRESS_LENGTH = 4; break; case CMD_SPI_3BYTE_CMDS: SPI_USE_3B_CMDS = 1; break; case CMD_SPI_4BYTE_CMDS: SPI_USE_3B_CMDS = 0; break; default: break; } } } }