void main(void) { int cdc_in; int uart_in; volatile UINT8 u8Error; PTBPE_PTBPE5 = 1; // DEMOFLEXISJMSD board PTBDD_PTBDD5 = _IN; // Initialize Button in hw_init(); /* MCU Initialization */ SPI_Init(); /* SPI Module Init */ u8Error=SD_Init(); /* SD Card Init */ FAT_Read_Master_Block(); /* FAT Driver Init */ cdc_in=uart_in=0xff+1; /* USB CMX Init */ usb_cfg_init(); cdc_init(); while(PTBD_PTBD5); /* Wait until button clic */ CDC_Send_String("\r\n\r\n\tSD Card Terminal\r\n"); while(1) { cdc_process(); /* USB CMX CDC process */ FAT_LS(); /* Simple function that shows the content*/ MiniCom(); /* User Interface call */ } }
void Comm2PC_Task(void) { CHAR8 c; /* configure USB and init CDC driver */ usb_cfg_init(); cdc_init(); /* This loop will receive and process characters from the USB. */ for(;;) { while((*cdc_kbhit)()) { c=(CHAR8)(*cdc_getch)(); Comm2PC_FSM(c); } cdc_process(); OSSemPend(USB_Sem,0); } }
/**************************************************************************** ************************** Function definitions **************************** ***************************************************************************/ void main(void) { int cdc_in; int uart_in; DC16_Init(); delay_ms(100); do_cool_LED_stuff(ALL_ON); // power-on test DC16_TX_Test(); do_cool_LED_stuff(ALL_OFF); cdc_in=uart_in=0xff+1; // USB CMX init cdc_init(); // sorry for this spaghetti-like state machine - i'm just a lowly electrical engineer :) while(1) { // initialize USB module if it hasn't started yet or has been shutdown // this will save power if the USB module isn't needed or used... if (!usb_enabled_flag && USB_DETECT) // when USB plugged in... { hw_init(); // setup usb & 48MHz clock using 12MHz external crystal (from \USB_CMX\target.c) usb_cfg_init(); SPI2BR = 0x11; // SPI baud rate, 3MHz @ 24MHz bus clock TPM2SC_PS = 0b010; // TPM2 timer prescaler = /4 usb_enabled_flag = 1; } else if (usb_enabled_flag && !USB_DETECT) // when USB removed, reduce clock speed to 12MHz... { usb_stop(); set_clock_12MHz(); usb_enabled_flag = 0; } if (!SW_MODE) // if button is pressed... { delay_ms(50); // poor man's debounce while (!SW_MODE) // while button is held down... { state_change_flag = 1; led_state = ALL_OFF; } } if (state_change_flag) // if there has been a change in state { if (power_on_flag && usb_enabled_flag && USB_DETECT) // this is only run once at power-on if USB is ready { power_on_flag = 0; Terminal_Send_String("\n\r"); Terminal_Send_String((unsigned char*)a_word_to_the_wise); Terminal_Send_String("\n\r\n\rWelcome to the debug terminal...\n\r\n\r"); } state_change_flag = 0; switch (state) // ...then set the new state { case SLEEP: state = RX; led_state = KNIGHT_RIDER; if (usb_enabled_flag && USB_DETECT) Terminal_Send_String("Entering RECEIVE mode.\n\r"); break; case RX: state = TX; led_state = TRANSMIT; if (usb_enabled_flag && USB_DETECT) Terminal_Send_String("Entering TRANSMIT mode.\n\r"); break; case TX: default: state = SLEEP; led_state = ALL_OFF; if (usb_enabled_flag && USB_DETECT) Terminal_Send_String("Going to SLEEP.\n\r"); break; } } switch (state) { case RX: DC16_RX_Mode(); break; case TX: DC16_TX_Mode(); break; case SLEEP: // sleepy time! default: DC16_Sleep_Mode(); } } }