/*------------------------------------------------------------------- ** ** Soluciones del examen de Programación de Sistemas y Dispositivos ** Curso 2022-23, Primera Convocatoria, 18 de enero de 2023 ** **-----------------------------------------------------------------*/ /*------------------------------------------------------------------- ** Ejercicio 1 **-----------------------------------------------------------------*/ #include #include #include #include #include #define MAXLEN 100 void timer0_isr( void ) __attribute__ ((interrupt ("IRQ"))); volatile boolean flag; volatile char s[MAXLEN]; void main( void ) { sys_init(); uart0_init(); timers_init(); flag = FALSE; timer0_open_ms( timer0_isr, 20, TIMER_INTERVAL ); while( 1 ) if( flag ) { uart0_puts( s ); flag = FALSE; } } void timer0_isr( void ) { static char *p = s; char ch; if( UFSTAT0 & 0xF ) { ch = URXH0; *p++ = ch; if( ch == '\n' ) { *p = '\0'; p = s; flag = TRUE; } } I_ISPC = BIT_TIMER0; } /*------------------------------------------------------------------- ** Ejercicio 2 **-----------------------------------------------------------------*/ #include #include extern uint8 lcd_buffer[]; void lcd_putWindow( uint8 *bmp, uint16 xleft, uint16 yup, uint16 xright, uint16 ydown ) { uint32 headerSize; uint16 x, ySrc, yDst; uint16 offsetSrc, offsetDst; headerSize = bmp[10] + (bmp[11] << 8) + (bmp[12] << 16) + (bmp[13] << 24); bmp = bmp + headerSize; for( ySrc=LCD_HEIGHT-ydown, yDst=ydown-1; ySrc #include void memcpy_dma( uint8 *dest, uint8 *src, uint16 n ) { ZDISRC0 = (0 << 30) | (1 << 28) | (uint32) src; // datos de 8b, dirección post-incrementada, origen: src ZDIDES0 = (2 << 30) | (1 << 28) | (uint32) dest; // recomendada, dirección post-incrementada, destino: dest ZDICNT0 = (2 << 28) | (1 << 26) | n; // tamaño: n ZDICNT0 |= (1 << 20); // enable DMA (según manual debe hacerse en escritura separada a la escritura del resto de registros) ZDCON0 = 1; // start DMA while( ZDCCNT0 & 0xFFFFF ); // espera a que termine la transferencia DMA } /*------------------------------------------------------------------- ** Ejercicio 4 **-----------------------------------------------------------------*/ #define LCD_COLS (LCD_WIDTH/2) #define LCD_ROWS (LCD_HEIGHT) extern uint8 lcd_buffer[]; void lcd_vflip( void ) { uint8 rowAux[LCD_COLS]; uint8 *rowA, *rowB; uint16 ySrc, yDst; for( ySrc=0, yDst=LCD_HEIGHT-1; ySrc<=LCD_ROWS/2; ySrc++, yDst-- ) { rowA = lcd_buffer + ySrc*LCD_COLS; rowB = lcd_buffer + (yDst-1)*LCD_COLS; memcpy_dma( rowAux, rowA, LCD_COLS ); // rowAux <- rowA memcpy_dma( rowA, rowB, LCD_COLS ); // rowA <- rowB memcpy_dma( rowB, rowAux, LCD_COLS ); // rowB <- rowAux } }