;UART REGISTERS .equ REG_UART_DATA, 0x00 .equ REG_UART_IER, 0x01 .equ REG_UART_LCR, 0x03 .equ REG_UART_LSR, 0x05 ;ASCII CHARS .equ CHAR_FORM_FEED, 0x0C .equ CHAR_TAB, 0x09 .equ CHAR_CR, 0x0D .equ CHAR_LF, 0x0A #if defined(__CMODEL_SMALL__) #define PUTS(label) \ movi r0, label @\ call puts #elif defined(__CMODEL_MEDIUM__) #define PUTS(label) \ movi r0, _lo(label) @\ movi r13, _hi(label) @\ call puts #elif defined(__CMODEL_LARGE__) #define PUTS(label) \ movi r0, _lo(label) @\ movi r13, _hi(label) @\ movi r14, _higher(label) @\ movi r15, _highest(label) @\ call puts #endif .section .vectors,"ax" b __irq_wrapper .globl _reset _reset: movi r0, 66 call putc // Clear bss as EBR init ends at __bss_start movi r0, _lo(__bss_start) #if defined(__CMODEL_LARGE__) || defined(__CMODEL_MEDIUM__) movi r13, _hi(__bss_start) #endif #ifdef __CMODEL_LARGE__ movi r14, _higher(__bss_start) movi r15, _highest(__bss_start) #endif movi r1,0 3: cmpi r0, _lo(__bss_end) #if defined(__CMODEL_LARGE__) || defined(__CMODEL_MEDIUM__) bnz 1f cmpi r13, _hi(__bss_end) #endif #ifdef __CMODEL_LARGE__ bnz 1f cmpi r14, _higher(__bss_end) cmpi r15, _highest(__bss_end) #endif bz setup_stack_pointer 1: sspi r1, r0 addi r0, 1 #if defined(__CMODEL_LARGE__) || defined(__CMODEL_MEDIUM__) addic r13, 0 #endif #ifdef __CMODEL_LARGE__ addic r14, 0 addic r15, 0 #endif b 3b // Set stack point to top of scratch pad area setup_stack_pointer: #if defined (__CMODEL_SMALL__) movi r14, __stack #elif defined(__CMODEL_MEDIUM__) movi r8, _lo(__stack) movi r9, _hi(__stack) #elif defined(__CMODEL_LARGE__) movi r24, _lo(__stack) movi r25, _hi(__stack) movi r26, _higher(__stack) movi r27, _highest(__stack) #endif // Clear the frame pointer - Not all Lattice device // families support async reset of register DP dist RAM #if defined (__CMODEL_SMALL__) movi r15, 0 #elif defined(__CMODEL_MEDIUM__) movi r10, 0 movi r11, 0 #elif defined(__CMODEL_LARGE__) movi r28, 0 movi r29, 0 movi r30, 0 movi r31, 0 #endif // Enable all interrupts movi r0, 0xff wcsr im, r0 seti // Initialize UART movi r0, 0x00 ; IER export r0, REG_UART_IER movi r0, 0x03 ; LCR export r0, REG_UART_LCR // display menu on the screen display_menu: PUTS(menu_text) display_prompt: PUTS(prompt_text) wait_for_input: import r0, REG_UART_LSR andi r0, 0x01 cmpi r0, 0x01 bnz wait_for_input import r0, REG_UART_DATA cmpi r0, 'm' bz display_menu b display_prompt putc: putc_rdy: import r1, REG_UART_LSR andi r1, 0x20 cmpi r1, 0x20 bnz putc_rdy export r0, 0 ret puts: lspi r1, r0 ; Get next character testi r1, 0xff bz puts_done puts_rdy: import r2, REG_UART_LSR andi r2, 0x20 cmpi r2, 0x20 bnz puts_rdy export r1, 0 // Increment source string pointer addi r0, 1 #if defined(__CMODEL_LARGE__) || defined(__CMODEL_MEDIUM__) addic r13, 0 #endif #if defined(__CMODEL_LARGE__) addic r14, 0 addic r15, 0 #endif b puts puts_done: ret .section .rodata,"a" menu_text: .ascii "\r\n" .ascii "==============================================================\r\n" .ascii "LM8 Processor Control SoC Rev 1.0, December 2012\r\n" .ascii "\r\n" .ascii "m : Re-display Main Menu\r\n" .ascii "a : Read ADC Digital Data\r\n" .ascii "s : Read External SPI Flash IDCode\r\n" .ascii "t : Up-time counter\r\n" .ascii "r : I/O Control - Read Dip-Switches\r\n" .ascii "(0-9) : I/O Control - Write to LED\r\n" .ascii "\r\n" .ascii "Data Logging to SPI Flash\r\n" .ascii "~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n" .ascii "l : Log ADC Result\r\n" .ascii "e : Erase Flash Memory\r\n" .ascii "\r\n" .string "==============================================================\r\n" prompt_text: .ascii "\r\n" .string "> "