# HG changeset patch # User jeandet # Date 2013-09-17 22:58:27 # Node ID 68dfbccdd813b3e73996a8b1ddc6503fa8406300 # Parent 25c982b9ed9489b04bf49427db032609ecfd4eb5 Added Simulator target to run code on x86 and debug functions. Fixed some bugs on terminal widget. diff --git a/README b/README --- a/README +++ b/README @@ -17,7 +17,7 @@ #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #------------------------------------------------------------------------------- #-- Author : Alexis Jeandet -#-- Mail : alexis.jeandet@gmail.com +#-- Mail : alexis.jeandet@member.fsf.org #------------------------------------------------------------------------------- ________ @@ -30,9 +30,6 @@ own licence. If you reconize any of your Intallation: ~~~~~~~~~~~~ To install the libuc2 you just need to copy the libuc2 folder where you whant then you need to: - -add the libuc2 binary folder to the PATH, with linux you can append this to the end of your /etc/bashrc file: - PATH=$PATH:/opt/libuc2/bin - replace /opt/ by the path where is installed the libuc2. -set the libuc2 environement varriable, with linux you can append this to the end of your /etc/bashrc file: libuc2=/opt/libuc2 replace /opt/ by the path where is installed the libuc2. @@ -41,7 +38,7 @@ Intallation: Contributions: ~~~~~~~~~~~~~~ Feel free to modify everything in the libuc2, if you think that some of your improvement should be integrated in the -libuc2 you can send them to me at alexis.jeandet@lpp.polytechnique.fr or alexis.jeandet@gmail.fr. +libuc2 you can send them to me at alexis.jeandet@member.fsf.org or alexis.jeandet@gmail.fr. ______________ Documentation: diff --git a/bsp/src/OPLAYER/bsp.c b/bsp/src/OPLAYER/bsp.c --- a/bsp/src/OPLAYER/bsp.c +++ b/bsp/src/OPLAYER/bsp.c @@ -58,8 +58,8 @@ LCD_t lcd0={ terminal_t terminal0; -volatile int8_t* lcd0_CMD=(volatile int8_t*) 0x60000000; -volatile int8_t* lcd0_DATA=(volatile int8_t*)(0x61FFFFF0); +volatile uint8_t* lcd0_CMD=(volatile uint8_t*) 0x60000000; +volatile uint8_t* lcd0_DATA=(volatile uint8_t*)(0x61FFFFF0); float VREF0 =(float)3.3; volatile vs10XXDev audioCodec0; @@ -124,7 +124,18 @@ void bsp_GPIO_init() void bsp_uart_init() { - +// if(__opnfiles__[1]==NULL) +// { +// //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); +// streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); +// uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); +// uartmkstreamdev(uart,fd1); +// __opnfiles__[1] = fd1; +// } +// else +// { +// uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); +// } } /* @@ -172,7 +183,7 @@ int bsp_FSMC_init() p.FSMC_DataLatency = 0; //ili9328 -> data hold time > 15ns if(getCpuFreq()>66*1000*1000) - p.FSMC_DataLatency = 0; + p.FSMC_DataLatency = 1; p.FSMC_AccessMode = FSMC_AccessMode_A; FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; @@ -445,31 +456,38 @@ void bsp_lcd0_writeGRAM(void* buffer,uin void bsp_lcd0_readGRAM(void* buffer,uint32_t count) { - uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; - uint8_t* pt8 = (uint8_t*)(void*)® +// uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; +// int8_t* pt8 = (int8_t*)(void*)® #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ *lcd0_CMD=pt8[3]; *lcd0_CMD=pt8[2]; pt8 = (uint8_t*)(void*)buffer; - pt8[0] = *lcd0_DATA; - pt8[0] = *lcd0_DATA; for(int i=0;i<(int)count;i++) { pt8[(2*i) +1]=*lcd0_DATA; + __asm__("nop"); + __asm__("nop"); + __asm__("nop"); + __asm__("nop"); + __asm__("nop"); pt8[2*i]=*lcd0_DATA; } #else - - *lcd0_CMD=pt8[1]; - *lcd0_CMD=pt8[0]; - pt8 = (uint8_t*)(void*)buffer; - pt8[0] = *lcd0_DATA; - pt8[0] = *lcd0_DATA; - for(int i=0;i<(int)count;i++) - { - pt8[(2*i) +1]=*lcd0_DATA; - pt8[2*i]=*lcd0_DATA; - } +// lcd0_CMD=pt8[1]; +// lcd0_CMD=pt8[0]; +// pt8 = (int8_t*)(void*)buffer; +// for(int i=0;i<(int)count;i++) +// { +// pt8[(2*i) +1]=*lcd0_DATA; +// __asm__("nop"); +// __asm__("nop"); +// __asm__("nop"); +// __asm__("nop"); +// __asm__("nop"); +// pt8[2*i]=*lcd0_DATA; + //pt8[(2*i) +1]=(uint8_t)0; + //pt8[(2*i)]=(uint8_t)0; +// } #endif } @@ -477,9 +495,8 @@ void bsp_GTerm_init() { if(__opnfiles__[1]==NULL) { - //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); - terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1); + terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1); __opnfiles__[1] = fd1; } else diff --git a/bsp/src/SIMULATOR/SIMULATOR.pro b/bsp/src/SIMULATOR/SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/bsp/src/SIMULATOR/SIMULATOR.pro @@ -0,0 +1,19 @@ +TEMPLATE = lib + +TARGET=bsp + + + +BSP = SIMULATOR + +UCMODEL=simulator + +SOURCES += bsp.c + +HEADERS += bsp.h + + +BSPFILE = bsp.pri + + + diff --git a/bsp/src/SIMULATOR/bsp.c b/bsp/src/SIMULATOR/bsp.c new file mode 100644 --- /dev/null +++ b/bsp/src/SIMULATOR/bsp.c @@ -0,0 +1,282 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2011, Alexis Jeandet +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@gmail.com +-------------------------------------------------------------------------------*/ +#include "bsp.h" +#include +#include +#include + + +uint32_t OSC0 =8000000; +uint32_t INTOSC =16000000; +uint32_t RTCOSC =32768; +uint32_t currentCpuFreq=0; +extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; + + +LCD_IF_t lcdIF0={ + .init = &SDLCD_init, + .writereg = &SDLCD_writereg, + .readreg = &SDLCD_readreg, + .writeGRAM = &SDLCD_writeGRAM, + .readGRAM = &SDLCD_readGRAM +}; + +LCD_t lcd0={ + .interface = &lcdIF0, + .init = &ili9328init, + .paint = &ili9328paint, + .paintText = &ili9328paintText, + .paintFilRect = &ili9328paintFilRect, + .refreshenable = &ili9328refreshenable, + .width= 240, + .height = 320 +}; + +terminal_t terminal0; + +volatile int8_t* lcd0_CMD=(volatile int8_t*) 0x60000000; +volatile int8_t* lcd0_DATA=(volatile int8_t*)(0x61FFFFF0); + +float VREF0 =(float)3.3; +volatile vs10XXDev audioCodec0; + +sdcardDev sdcard2; +blkdevice sdcard2blkdev; +dikpartition sdcard2Part1; +FAT32fs sdcard2FAT32part1; +dikpartition sdcard2Part2; +FAT32fs sdcard2FAT32part2; +dikpartition sdcard2Part3; +FAT32fs sdcard2FAT32part3; +dikpartition sdcard2Part4; +FAT32fs sdcard2FAT32part4; + +int bsp_init() +{ + int i=0; + for(i=0;i<__MAX_OPENED_FILES__;i++) + { + __opnfiles__[i] = NULL; + } + bsp_GPIO_init(); + bsp_uart_init(); + bsp_iic_init(); + bsp_FSMC_init(); + bsp_GTerm_init(); + bsp_spi_init(); + bsp_SD_init(); + bsp_Audio_init(); + printf("\r=====================\n\r"); + printf( "=====================\n\r"); + printf(BSP); + printf(" initialised\n\r"); + printf( "=====================\n\r"); + return 1; +} + +void bsp_GPIO_init() +{ + +} + +void bsp_uart_init() +{ + +} + +/* +D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 +D5 PE8 D6 PE9 D7 PE10 +A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S +FSMC_NOE PD4 RD +*/ + +int bsp_FSMC_init() +{ + + return 1; +} + +void bsp_spi_init() +{ + +} + + +void bsp_iic_init() +{ + +} + + +void bsp_Audio_init() +{ + +} + +void bsp_SD_init() +{ + +} + +void vs1052setXCS(char val) +{ +} + +void vs1052setXDCS(char val) +{ +} + +void vs1052setRST(char val) +{ +} + +int vs10XXDREQ() +{ + return 1; +} + + +void bsppowersdcard(char onoff) //always ON +{ + +} + +char bspsdcardpresent() +{ + return 1; +} + +char bspsdcardwriteprotected() +{ + return 0; +} + +void bspsdcardselect(char YESNO) +{ + +} + + +void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) +{ + +} + +uint32_t bsp_lcd0_read_reg(uint32_t reg) +{ + return 0; +} + +void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) +{ + +} + +void bsp_lcd0_readGRAM(void* buffer,uint32_t count) +{ + +} + +void bsp_GTerm_init() +{ + SDLCD_mkscreen(240,320,16,LCDILI9328); + + if(__opnfiles__[1]==NULL) + { + streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); + terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1); + __opnfiles__[1] = fd1; + } + else + { + + } +} + + + + + + + +void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) +{ + int bpp = surface->format->BytesPerPixel; + /* Here p is the address to the pixel we want to set */ + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + switch(bpp) { + case 1: + *p = pixel; + break; + case 2: + *(Uint16 *)p = pixel; + break; + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { + p[0] = (pixel >> 16) & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = pixel & 0xff; + } else { + p[0] = pixel & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = (pixel >> 16) & 0xff; + } + break; + case 4: + *(Uint32 *)p = pixel; + break; + } +} + +Uint32 getpixel(SDL_Surface *surface, int x, int y) +{ + int bpp = surface->format->BytesPerPixel; + /* Here p is the address to the pixel we want to retrieve */ + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + switch(bpp) { + case 1: + return *p; + case 2: + return *(Uint16 *)p; + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + return p[0] << 16 | p[1] << 8 | p[2]; + else + return p[0] | p[1] << 8 | p[2] << 16; + case 4: + return *(Uint32 *)p; + default: + return 0; + } + /* shouldn’t happen, but avoids warnings */ +} + + + + + + + + + + diff --git a/bsp/src/SIMULATOR/bsp.h b/bsp/src/SIMULATOR/bsp.h new file mode 100644 --- /dev/null +++ b/bsp/src/SIMULATOR/bsp.h @@ -0,0 +1,139 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2011, Alexis Jeandet +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@gmail.com +-------------------------------------------------------------------------------*/ +#ifndef BSP_H +#define BSP_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define __MAX_OPENED_FILES__ 4 +#define __FS_ROOT_SIZE__ 4 + + +#define LED1 PC15 +#define LED2 PC14 + +#define BP3 PA0 + +#define LCD_RESET PD10 +#define LCD_BACKL PE11 + +#define VS1053SPI spi1 +#define VS1053xCS PA3 +#define VS1053xRESET PA2 +#define VS1053xDCS PA4 +#define VS1053DREQ PA1 +#define VS1053MISO PA6 +#define VS1053MOSI PA7 +#define VS1053SCK PA5 + + + +#define SDCARD2SPI spi3 +#define SDCARD2CS PB8 +#define SDCARD2CD PB9 +#define SDCARD2MISO PB4 +#define SDCARD2MOSI PB5 +#define SDCARD2SCK PB3 + +extern float VREF0; + +extern uint32_t currentCpuFreq; +extern LCD_t lcd0; + +extern volatile vs10XXDev audioCodec0; + +extern sdcardDev sdcard2; +extern blkdevice sdcard2blkdev; +extern dikpartition sdcard2Part1; +extern FAT32fs sdcard2FAT32part1; +extern dikpartition sdcard2Part2; +extern FAT32fs sdcard2FAT32part2; +extern dikpartition sdcard2Part3; +extern FAT32fs sdcard2FAT32part3; +extern dikpartition sdcard2Part4; +extern FAT32fs sdcard2FAT32part4; + +extern int bsp_init(); + +extern void bsp_GPIO_init(); +extern void bsp_uart_init(); +extern void bsp_iic_init(); +extern void bsp_spi_init(); +extern void bsp_SD_init(); +extern void bsp_Audio_init(); +extern void bsp_GTerm_init(); +extern int bsp_FSMC_init(); + +/* VS1053 */ +extern void vs1052setXCS(char val); +extern void vs1052setXDCS(char val); +extern void vs1052setRST(char val); +extern int vs10XXDREQ(); + +/* SD CARD */ +void bsppowersdcard(char onoff); +char bspsdcardpresent(); +void bspsdcardselect(char YESNO); +char bspsdcardwriteprotected(); + + +void bsp_lcd0_write_reg(uint32_t reg,uint32_t data); +uint32_t bsp_lcd0_read_reg(uint32_t reg); +void bsp_lcd0_writeGRAM(void *buffer, uint32_t count); +void bsp_lcd0_readGRAM(void *buffer, uint32_t count); + + +extern void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel); +extern Uint32 getpixel(SDL_Surface *surface, int x, int y); + +#endif + + + + + + + + + + + + + + + + + + + diff --git a/bsp/src/SIMULATOR/bsp.pri b/bsp/src/SIMULATOR/bsp.pri new file mode 100644 --- /dev/null +++ b/bsp/src/SIMULATOR/bsp.pri @@ -0,0 +1,6 @@ +CPU=simultor +DEFINES+=BSP=\\\"SIMULATOR\\\" + +UCMODEL=simulator + +LIBS+=-lSDLCD diff --git a/bsp/src/STM32F4Discovery/bsp.pri b/bsp/src/STM32F4Discovery/bsp.pri --- a/bsp/src/STM32F4Discovery/bsp.pri +++ b/bsp/src/STM32F4Discovery/bsp.pri @@ -1,3 +1,3 @@ CPU=stm32f4xxxG -DEFINES+=BSP=\\\"SOLAR_LFR_PSU\\\" +DEFINES+=BSP=\\\"STM32F4Discovery\\\" UCMODEL=stm32f4 diff --git a/bsp/src/bsp.pro b/bsp/src/bsp.pro --- a/bsp/src/bsp.pro +++ b/bsp/src/bsp.pro @@ -7,7 +7,8 @@ SUBDIRS += STM32F4Discovery \ BEAGLESYNTH \ STM32F4Eval \ STM32F4Discovery-EXT \ - OPLAYER + OPLAYER \ + SIMULATOR diff --git a/examples/SOLAR_PSU_HELLO/hello.pro b/examples/SOLAR_PSU_HELLO/hello.pro --- a/examples/SOLAR_PSU_HELLO/hello.pro +++ b/examples/SOLAR_PSU_HELLO/hello.pro @@ -5,8 +5,10 @@ CONFIG += cpu UCMODEL=stm32f4 BSP = OPLAYER -DEFINES += CPUFREQ=160000000 +DEFINES += CPUFREQ=180000000 + SOURCES += \ - main.c + main.c \ + test_lcd.c diff --git a/examples/SOLAR_PSU_HELLO/main.c b/examples/SOLAR_PSU_HELLO/main.c --- a/examples/SOLAR_PSU_HELLO/main.c +++ b/examples/SOLAR_PSU_HELLO/main.c @@ -14,9 +14,11 @@ #include #include #include +#include extern streamdevice* __opnfiles__[]; +extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); char buffer[512]; void randBoxesDemo() @@ -36,109 +38,27 @@ void randBoxesDemo() //delay_100us(10); //for(volatile int i=0;i<(1024*2);i++); } -void tryToplay1() -{ - extern FAT32fs sdcard2FAT32part1; - extern volatile vs10XXDev audioCodec0; - ucdirent root; - char direntName[]=" \n"; - uint32_t fileLba,nextLba; - int i=0; - spisetspeed(audioCodec0.SPIdev,2000000); - if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root)) - { - if(DIRENT_noErr==fat32getrootfirstent(&root)) - { - do{ - fat32getdirentname(&root,direntName); - printf("%s\n",direntName); - nextLba=fat32getdirentlba(&root); - printf("Streaming File\n"); - do - { - fileLba = nextLba; - if(sdcard2FAT32part1.part->phy->read(sdcard2FAT32part1.part->phy,buffer,fileLba,1)==RES_OK) - { - for(i=0;i<512;i+=32) - { - vs10XXstream32bytes(&audioCodec0,buffer+i); - } - } - }while ((fat32nextsectorlba(&sdcard2FAT32part1,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3))); - //vs10XXsoftReset(&audioCodec0); - while (gpiogetval(BP3))delay_100us(1000); - printf("looking for next file\n"); - }while (DIRENT_noErr==fat32nextdirent(&root)); - } - } - if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root)) - { - if(DIRENT_noErr==fat32getrootfirstent(&root)) - { - fat32getdirentname(&root,direntName); - printf("%s\n",direntName); - nextLba=fat32getdirentlba(&root); - printf("Streaming File\n"); - do - { - fileLba = nextLba; - if(sdcard2FAT32part2.part->phy->read(sdcard2FAT32part2.part->phy,buffer,fileLba,1)==RES_OK) - { - for(i=0;i<512;i+=32) - { - vs10XXstream32bytes(&audioCodec0,buffer+i); - } - } - }while ((fat32nextsectorlba(&sdcard2FAT32part2,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3))); - while (gpiogetval(BP3))delay_100us(1000); - } - } - if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part3,&root)) - { - if(DIRENT_noErr==fat32getrootfirstent(&root)) - { - fat32getdirentname(&root,direntName); - printf("%s\n",direntName); - nextLba=fat32getdirentlba(&root); - printf("Streaming File\n"); - do - { - fileLba = nextLba; - if(sdcard2FAT32part3.part->phy->read(sdcard2FAT32part3.part->phy,buffer,fileLba,1)==RES_OK) - { - for(i=0;i<512;i+=32) - { - vs10XXstream32bytes(&audioCodec0,buffer+i); - } - } - }while ((fat32nextsectorlba(&sdcard2FAT32part3,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3))); - while (gpiogetval(BP3))delay_100us(1000); - } - } - if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part4,&root)) - { - if(DIRENT_noErr==fat32getrootfirstent(&root)) - { - fat32getdirentname(&root,direntName); - printf("%s\n",direntName); - nextLba=fat32getdirentlba(&root); - printf("Streaming File\n"); - do - { - fileLba = nextLba; - if(sdcard2FAT32part4.part->phy->read(sdcard2FAT32part4.part->phy,buffer,fileLba,1)==RES_OK) - { - for(i=0;i<512;i+=32) - { - vs10XXstream32bytes(&audioCodec0,buffer+i); - } - } - }while ((fat32nextsectorlba(&sdcard2FAT32part4,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3))); - while (gpiogetval(BP3))delay_100us(1000); - } - } +void randTextDemo() +{ + int16_t x,y,w,h,t,r; + char buf[2]; + buf[1]='\0'; + x=rand()%240; + y=rand()%320; + if(x>y) + r=(rand()%(y))%(320-y); + else + r=(rand()%(x))%(240-x); + h=rand()%(320-y); + buf[0]=rand()%(255); + //ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); + ili9328paintText(&lcd0,buf,x,y,&ComicSansMS_18,rand()); + //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); + delay_100us(5000); + //for(volatile int i=0;i<(1024*2);i++); } + void tryToplay2() { @@ -160,18 +80,122 @@ void tryToplay2() } } +void playFile(ucdirent* file,FAT32fs* part) +{ + extern volatile vs10XXDev audioCodec0; + char direntName[]=" \n"; + uint32_t fileLba,nextLba; + int i=0; + fat32getdirentname(file,direntName); + gpioset(LCD_BACKL); + //printf("%s\n",direntName); + nextLba=fat32getdirentlba(file); + //printf("Streaming File\n"); + gpioclr(LCD_BACKL); + do + { + fileLba = nextLba; + if(sdcard2FAT32part1.part->phy->read(part->part->phy,buffer,fileLba,1)==RES_OK) + { + for(i=0;i<512;i+=32) + { + vs10XXstream32bytes(&audioCodec0,buffer+i); + } + } + }while ((fat32nextsectorlba(part,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3))); + vs10XXsoftReset(&audioCodec0); + while (gpiogetval(BP3))delay_100us(1000); +} + +void playAllparts() +{ + extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4; + ucdirent root; + if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root)) + { + printf("Reading on SDCARD2 part1\n"); + if(DIRENT_noErr==fat32getrootfirstent(&root)) + { + do{ + playFile(&root,&sdcard2FAT32part1); + }while (DIRENT_noErr==fat32nextdirent(&root)); + } + } + gpioset(LED2); + if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root)) + { + printf("Reading on SDCARD2 part2\n"); + if(DIRENT_noErr==fat32getrootfirstent(&root)) + { + do{ + playFile(&root,&sdcard2FAT32part2); + }while (DIRENT_noErr==fat32nextdirent(&root)); + } + } +} + int main() { + int i=0; + int color=0; + for(i=0;i<240;i++) + { + if(i>(240/3)) + { + color= (i<<5) + 0x1F; + } + else + { + color = i; + } + if(i>(2*240/3)) + { + color= (i<<10) + 0x3FF; + } + lcd0.paintFilRect(&lcd0,i,0,1,100,0,0,color); + } + while(1)printf("test "); +// for(i=0;i<240;i++) +// { +// if(i>(240/3)) +// { +// color= (i<<5) + 0x1F; +// } +// else +// { +// color = i; +// } +// if(i>(2*240/3)) +// { +// color= (i<<10) + 0x3FF; +// } +// lcd0.paintFilRect(&lcd0,i,220,1,100,0,0,color); +// } + for(i=0;i<240;i++) + { + ili9328setFrame(&lcd0,i,0,1,100); + lcd0.interface->readGRAM(buffer,100); + lcd0.paint(&lcd0,buffer,i,200,1,100); + } + while(1); +} + +int main2() +{ extern terminal_t terminal0; extern volatile vs10XXDev audioCodec0; + lcd0.paintText(&lcd0,"hello",20,50,&ComicSansMS_18 ,0xF0F0); + while (1) + randTextDemo(); printf("Volume=0x%x\n",vs10XXcmdread(&audioCodec0,VSVOL)); vs10XXcmdwrite(&audioCodec0,VSCLOCKF,0x2000); - vs10XXcmdwrite(&audioCodec0,VSVOL,0x2222); + delay_100us(1000); + vs10XXcmdwrite(&audioCodec0,VSVOL,0x2020); printf("VSCLOCKF=0x%x\n",vs10XXcmdread(&audioCodec0,VSCLOCKF)); printf("VSMODE=0x%x\n",vs10XXcmdread(&audioCodec0,VSMODE)); - terminal_clear(&terminal0); - // tryToplay2(); - tryToplay1(); + //terminal_clear(&terminal0); + gpioclr(LCD_BACKL); + playAllparts(); return 0; } diff --git a/examples/SOLAR_PSU_HELLO/test_lcd.c b/examples/SOLAR_PSU_HELLO/test_lcd.c new file mode 100644 --- /dev/null +++ b/examples/SOLAR_PSU_HELLO/test_lcd.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color) +{ + LCD->paintFilRect(LCD,x,y,w,h,0,0,color); +} diff --git a/examples/TEST_SIMULATOR/TEST_SIMULATOR.pro b/examples/TEST_SIMULATOR/TEST_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/examples/TEST_SIMULATOR/TEST_SIMULATOR.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +CONFIG += cpu + + +UCMODEL=simulator +BSP = SIMULATOR + +DEFINES += CPUFREQ=100000000 + +SOURCES += \ + main.c \ + test_lcd.c + diff --git a/examples/TEST_SIMULATOR/main.c b/examples/TEST_SIMULATOR/main.c new file mode 100644 --- /dev/null +++ b/examples/TEST_SIMULATOR/main.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern streamdevice* __opnfiles__[]; +extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); +char buffer[512]; + +void streamdevicePrint(streamdevice* dev, const char* format,...) +{ + char** str_buffer; + int i; + va_list ap; + va_start(ap,format); + vasprintf(str_buffer,format,ap); + va_end(ap); + i=strlen(*str_buffer); + dev->ops->write(dev,(void*)*str_buffer,1,i); + free(*str_buffer); +} + +void lcd_print() +{ + lcd0.paintFilRect(&lcd0,10,10,100,100,0,0,0x0F0F); + // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)"hello",1,5); +} + +int libuc2_main_task() +{ + char in[255]; + lcd_print(); + printf("hello world\n"); + streamdevicePrint(__opnfiles__[1],"test Hello %d %f \n ",1234567,8.96); +// while (scanf("%c",in)) +// { + sleep(3); +// } +} + + + + + diff --git a/examples/TEST_SIMULATOR/test_lcd.c b/examples/TEST_SIMULATOR/test_lcd.c new file mode 100644 --- /dev/null +++ b/examples/TEST_SIMULATOR/test_lcd.c @@ -0,0 +1,21 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color) +{ +// LCD->paintFilRect(LCD,x,y,w,h,0,0,color); +} diff --git a/examples/examples.pro b/examples/examples.pro --- a/examples/examples.pro +++ b/examples/examples.pro @@ -11,7 +11,8 @@ SUBDIRS += QtTest/test.pro \ BeagleSynthHelloSupMon \ TEST_CMSIS_FFT \ N25Q128_test \ - ssd2119Tests + ssd2119Tests \ + TEST_SIMULATOR diff --git a/lib/src/common/AUDIO/CS43L22/CS43L22.pro b/lib/src/common/AUDIO/CS43L22/CS43L22.pro --- a/lib/src/common/AUDIO/CS43L22/CS43L22.pro +++ b/lib/src/common/AUDIO/CS43L22/CS43L22.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS += ./CS43L22_STM32F4.pro +SUBDIRS += ./CS43L22_STM32F4.pro \ + ./CS43L22_SIMULATOR.pro diff --git a/lib/src/common/AUDIO/CS43L22/CS43L22_SIMULATOR.pro b/lib/src/common/AUDIO/CS43L22/CS43L22_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/AUDIO/CS43L22/CS43L22_SIMULATOR.pro @@ -0,0 +1,15 @@ +TEMPLATE = lib +TARGET = CS43L22 + +SOURCES += CS43L22.c + +INCLUDEPATH += ../../../includes \ + ../../CPU/CMSIS/Include + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + + diff --git a/lib/src/common/AUDIO/CS43L22/CS43L22_STM32F4.pro b/lib/src/common/AUDIO/CS43L22/CS43L22_STM32F4.pro --- a/lib/src/common/AUDIO/CS43L22/CS43L22_STM32F4.pro +++ b/lib/src/common/AUDIO/CS43L22/CS43L22_STM32F4.pro @@ -1,5 +1,4 @@ TEMPLATE = lib -OBJECTS_DIR = obj TARGET = CS43L22 SOURCES += CS43L22.c diff --git a/lib/src/common/AUDIO/VS10XX/VS10XX.pro b/lib/src/common/AUDIO/VS10XX/VS10XX.pro --- a/lib/src/common/AUDIO/VS10XX/VS10XX.pro +++ b/lib/src/common/AUDIO/VS10XX/VS10XX.pro @@ -1,15 +1,3 @@ -TEMPLATE = lib -OBJECTS_DIR = obj -TARGET = vs10XX - -SOURCES += VS10XX.c - - -HEADERS += ../../../includes/VS10XX.h -INCLUDEPATH += ../../../includes - -UCMODEL=stm32f4 - -target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL -INSTALLS += target - +TEMPLATE = subdirs +SUBDIRS += ./VS10XX_STM32F4.pro \ + ./VS10XX_SIMULATOR.pro diff --git a/lib/src/common/AUDIO/VS10XX/VS10XX_SIMULATOR.pro b/lib/src/common/AUDIO/VS10XX/VS10XX_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/AUDIO/VS10XX/VS10XX_SIMULATOR.pro @@ -0,0 +1,14 @@ +TEMPLATE = lib +TARGET = vs10XX + +SOURCES += VS10XX.c + + +HEADERS += ../../../includes/VS10XX.h +INCLUDEPATH += ../../../includes + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + diff --git a/lib/src/common/AUDIO/VS10XX/VS10XX_STM32F4.pro b/lib/src/common/AUDIO/VS10XX/VS10XX_STM32F4.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/AUDIO/VS10XX/VS10XX_STM32F4.pro @@ -0,0 +1,14 @@ +TEMPLATE = lib +TARGET = vs10XX + +SOURCES += VS10XX.c + + +HEADERS += ../../../includes/VS10XX.h +INCLUDEPATH += ../../../includes + +UCMODEL=stm32f4 + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + diff --git a/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X.pro b/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X.pro --- a/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X.pro +++ b/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X.pro @@ -1,16 +1,3 @@ -TEMPLATE = lib -OBJECTS_DIR = obj - -SOURCES += 24LC0X.c -HEADERS += ../../../includes/24LC0X.h \ - ../../../../includes/24LC0X.h - -INCLUDEPATH += ../../../includes \ - ../../CPU/STM32F4xx_StdPeriph_Driver/inc \ - ../../CPU/CMSIS/Include - - -UCMODEL=stm32f4 - -target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL -INSTALLS += target +TEMPLATE = subdirs +SUBDIRS += ./24LC0X_STM32F4.pro \ + ./24LC0X_SIMULATOR.pro diff --git a/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X_SIMULATOR.pro b/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X_SIMULATOR.pro @@ -0,0 +1,14 @@ +TEMPLATE = lib + +SOURCES += 24LC0X.c +HEADERS += ../../../includes/24LC0X.h \ + ../../../../includes/24LC0X.h + +INCLUDEPATH += ../../../includes \ + ../../CPU/CMSIS/Include + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target diff --git a/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X_STM32F4.pro b/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X_STM32F4.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X_STM32F4.pro @@ -0,0 +1,15 @@ +TEMPLATE = lib + +SOURCES += 24LC0X.c +HEADERS += ../../../includes/24LC0X.h \ + ../../../../includes/24LC0X.h + +INCLUDEPATH += ../../../includes \ + ../../CPU/STM32F4xx_StdPeriph_Driver/inc \ + ../../CPU/CMSIS/Include + + +UCMODEL=stm32f4 + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target diff --git a/lib/src/common/EEPROMS/N25Q128/N25Q128.pro b/lib/src/common/EEPROMS/N25Q128/N25Q128.pro --- a/lib/src/common/EEPROMS/N25Q128/N25Q128.pro +++ b/lib/src/common/EEPROMS/N25Q128/N25Q128.pro @@ -1,15 +1,5 @@ -TEMPLATE = lib -OBJECTS_DIR = obj - -SOURCES += N25Q128.c -HEADERS += ../../../includes/N25Q128.h - -INCLUDEPATH += ../../../includes \ - ../../CPU/STM32F4xx_StdPeriph_Driver/inc \ - ../../CPU/CMSIS/Include +TEMPLATE = subdirs -UCMODEL=stm32f4 - -target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL -INSTALLS += target +SUBDIRS += ./N25Q128_SIMULATOR.pro \ + ./N25Q128_STM32F4.pro diff --git a/lib/src/common/EEPROMS/N25Q128/N25Q128_SIMULATOR.pro b/lib/src/common/EEPROMS/N25Q128/N25Q128_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/EEPROMS/N25Q128/N25Q128_SIMULATOR.pro @@ -0,0 +1,13 @@ +TEMPLATE = lib + +SOURCES += N25Q128.c +HEADERS += ../../../includes/N25Q128.h + +INCLUDEPATH += ../../../includes \ + ../../CPU/CMSIS/Include + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target diff --git a/lib/src/common/EEPROMS/N25Q128/N25Q128_STM32F4.pro b/lib/src/common/EEPROMS/N25Q128/N25Q128_STM32F4.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/EEPROMS/N25Q128/N25Q128_STM32F4.pro @@ -0,0 +1,13 @@ +TEMPLATE = lib + +SOURCES += N25Q128.c +HEADERS += ../../../includes/N25Q128.h + +INCLUDEPATH += ../../../includes \ + ../../CPU/CMSIS/Include + + +UCMODEL=stm32f4 + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target diff --git a/lib/src/common/FILE_SYSTEM/DIRENT/DIRENT.pro b/lib/src/common/FILE_SYSTEM/DIRENT/DIRENT.pro --- a/lib/src/common/FILE_SYSTEM/DIRENT/DIRENT.pro +++ b/lib/src/common/FILE_SYSTEM/DIRENT/DIRENT.pro @@ -1,5 +1,6 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS += ./dirent_STM32F4.pro +SUBDIRS += ./dirent_STM32F4.pro \ + ./dirent_SIMULATOR.pro diff --git a/lib/src/common/FILE_SYSTEM/DIRENT/dirent_SIMULATOR.pro b/lib/src/common/FILE_SYSTEM/DIRENT/dirent_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/FILE_SYSTEM/DIRENT/dirent_SIMULATOR.pro @@ -0,0 +1,15 @@ +TEMPLATE = lib +OBJECTS_DIR = obj +TARGET = ucdirent + +SOURCES += \ + ucdirent.c + +INCLUDEPATH += ../../includes + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + diff --git a/lib/src/common/FILE_SYSTEM/FAT32/FAT32.pro b/lib/src/common/FILE_SYSTEM/FAT32/FAT32.pro --- a/lib/src/common/FILE_SYSTEM/FAT32/FAT32.pro +++ b/lib/src/common/FILE_SYSTEM/FAT32/FAT32.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS += ./fat32_STM32F4.pro +SUBDIRS += ./fat32_STM32F4.pro \ + ./fat32_SIMULATOR.pro diff --git a/lib/src/common/FILE_SYSTEM/FAT32/fat32.c b/lib/src/common/FILE_SYSTEM/FAT32/fat32.c --- a/lib/src/common/FILE_SYSTEM/FAT32/fat32.c +++ b/lib/src/common/FILE_SYSTEM/FAT32/fat32.c @@ -25,77 +25,80 @@ #include #include -char fat32buff[512]; +char fat32buff[512]__attribute__ ((aligned (4))); uint32_t lastSecAddrs=-1; FAT32fs* lastFATFS=0; int fat32open(FAT32fs* fs,dikpartition* part) { - char sector[512]; - fs->part = part; - if(!isFat32(fs->part->TypeCode))return FATBadpart; - if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr; + fs->valide = 0; + if(part->valide==0)return FATBadpart; + char sector[512]; + fs->part = part; + if(!isFat32(fs->part->TypeCode))return FATBadpart; + if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr; fs->BPB_BytsPerSec = fat32Ui8_2_Ui16(sector,BPB_BytsPerSecoff); fs->BPB_RsvdSecCnt = fat32Ui8_2_Ui16(sector,BPB_RsvdSecCntoff); fs->BPB_FATSz32 = fat32Ui8_2_Ui32(sector,BPB_FATSz32off); fs->BPB_RootClus = fat32Ui8_2_Ui32(sector,BPB_RootClusoff); - fs->BPB_SecPerClus = sector[BPB_SecPerClusoff]; - fs->BPB_NumFATs = sector[BPB_NumFATsoff]; - fs->fat_begin_lba = (unsigned int)fs->part->LBABegin + (unsigned int)(unsigned short)fs->BPB_RsvdSecCnt; - fs->cluster_begin_lba = (unsigned int)fs->fat_begin_lba + ((unsigned int)fs->BPB_NumFATs * (unsigned int)fs->BPB_FATSz32 ); - return FATnoErr; + fs->BPB_SecPerClus = sector[BPB_SecPerClusoff]; + fs->BPB_NumFATs = sector[BPB_NumFATsoff]; + fs->fat_begin_lba = (unsigned int)fs->part->LBABegin + (unsigned int)(unsigned short)fs->BPB_RsvdSecCnt; + fs->cluster_begin_lba = (unsigned int)fs->fat_begin_lba + ((unsigned int)fs->BPB_NumFATs * (unsigned int)fs->BPB_FATSz32 ); + fs->valide=1; + return FATnoErr; } int fat32mkdirent(FAT32fs* fs,ucdirent* dirent) { - if(fs==0) return DIRENT_BabArg; - if(dirent==0) return DIRENT_BabArg; - dirent->fs = (UHANDLE)fs; - dirent->getrootfirstent = &fat32getrootfirstent; - dirent->nextdirent = &fat32nextdirent; - return DIRENT_noErr; + if((fs==0) || (fs->valide==0)) return DIRENT_BabArg; + if(dirent==0) return DIRENT_BabArg; + dirent->fs = (UHANDLE)fs; + dirent->getrootfirstent = &fat32getrootfirstent; + dirent->nextdirent = &fat32nextdirent; + return DIRENT_noErr; } int fat32getrootfirstent(ucdirent* entry) { - if(entry==0) return DIRENT_BabArg; - entry->CurrentSec = ((FAT32fs*)entry->fs)->cluster_begin_lba; - entry->Currententry = 0; - return fat32nextdirent(entry); + if(entry==0) return DIRENT_BabArg; + entry->CurrentSec = ((FAT32fs*)entry->fs)->cluster_begin_lba; + entry->Currententry = 0; + return fat32nextdirent(entry); } int fat32getVolName(FAT32fs* fs,char* Name) { - if(fs==0) return DIRENT_BabArg; - if(Name==0) return DIRENT_BabArg; - int i=0; - ucdirent entry; - if(DIRENT_noErr==fat32mkdirent(fs,&entry)) - { - entry.CurrentSec = ((FAT32fs*)entry.fs)->cluster_begin_lba; - entry.Currententry = -1; - if(DIRENT_noErr!=fat32nextdirent(&entry))return DIRENT_ReadErr; - for(i=0;i<16;i++) - { - Name[i] = entry.DIR_Name[i]; - } - return DIRENT_noErr; - } - return DIRENT_ReadErr; + if((fs==0) || (fs->valide==0)) return DIRENT_BabArg; + if(Name==0) return DIRENT_BabArg; + int i=0; + ucdirent entry; + if(DIRENT_noErr==fat32mkdirent(fs,&entry)) + { + entry.CurrentSec = ((FAT32fs*)entry.fs)->cluster_begin_lba; + entry.Currententry = -1; + if(DIRENT_noErr!=fat32nextdirent(&entry))return DIRENT_ReadErr; + for(i=0;i<16;i++) + { + Name[i] = entry.DIR_Name[i]; + } + return DIRENT_noErr; + } + return DIRENT_ReadErr; } int fat32enterdirent(ucdirent* currententry,ucdirent* firstentry) { - if(firstentry==0) return DIRENT_BabArg; - if(currententry==0) return DIRENT_BabArg; + if(firstentry==0) return DIRENT_BabArg; + if(currententry==0) return DIRENT_BabArg; fat32mkdirent(((FAT32fs*)currententry->fs),firstentry); - firstentry->CurrentSec = fat32getdirentlba(currententry); - firstentry->Currententry = -1; - return fat32nextdirent(firstentry); + firstentry->CurrentSec = fat32getdirentlba(currententry); + firstentry->Currententry = -1; + return fat32nextdirent(firstentry); } @@ -104,21 +107,33 @@ int fat32nextdirent(ucdirent* entry) uint32_t n=0,res=DIRENT_noErr,k,j; k=(0xFF&((signed char)entry->Currententry)+1)*32; /*Restart at last dir entry*/ j=entry->CurrentSec;// /*Restart at last sector*/ - do - { + do + { + //printf("reading new secotr\n",k); fat32sectorreadout(((FAT32fs*)entry->fs),j); - for(k=k;k<(512);k+=32) /*512 Bytes per sector and 32 bytes per entry*/ - { + //printf("done\n",k); + /*512 Bytes per sector and 32 bytes per entry*/ + for(k=k;k<(512);k+=32) + { if((fat32buff[DIR_Nameoff+k]!=(char)0xE5)) /*0xE5 = free entry*/ - { + { + //printf("Fount dir entry = %d, 0x%X\n",0xff & ((int)fat32buff[DIR_Nameoff+k]),0xff & ((int)fat32buff[DIR_Attroff+k])); if(fat32buff[DIR_Nameoff+k]==(char)0) + { + //printf("end of directory reached\n",k); return DIRENT_EndOfDir; /*0x00 = end of dir*/ - else - if((fat32buff[DIR_Attroff + k]==(char)ATTR_DIRECTORY)||(fat32buff[DIR_Attroff + k]==(char)ATTR_ARCHIVE)||(fat32buff[DIR_Attroff + k]==(char)(ATTR_READ_ONLY))) - { - for(n=0;n<16;n++)entry->DIR_Name[n] = '\0'; - for(n=0;n<11;n++)entry->DIR_Name[n] = fat32buff[n+DIR_Nameoff + k]; - entry->DIR_Attr = (uint8_t)fat32buff[DIR_Attroff + k]; + } + else + { + uint8_t attribute=fat32buff[DIR_Attroff + k]; + if( (attribute==ATTR_DIRECTORY) + ||(attribute==ATTR_ARCHIVE) + ||(attribute==ATTR_READ_ONLY) + ||(attribute==ATTR_READ_ONLY)) + { + for(n=0;n<16;n++)entry->DIR_Name[n] = '\0'; + for(n=0;n<11;n++)entry->DIR_Name[n] = fat32buff[n+DIR_Nameoff + k]; + entry->DIR_Attr = attribute; entry->DIR_CrtTimeTenth = (uint8_t)fat32buff[DIR_CrtTimeTenthoff + k]; entry->DIR_CrtTime = fat32extract16b(fat32buff,(DIR_CrtTimeoff + k)); entry->DIR_CrtDate = fat32extract16b(fat32buff,(DIR_CrtDateoff + k)); @@ -127,23 +142,26 @@ int fat32nextdirent(ucdirent* entry) entry->DIR_WrtTime = fat32extract16b(fat32buff,(DIR_WrtTimeoff + k)); entry->DIR_FstClustLO = fat32extract16b(fat32buff, (DIR_FstClusLOoff + k)); entry->DIR_FileSize = fat32extract32b(fat32buff,(DIR_FileSizeoff + k)); - entry->CurrentSec = j; - entry->Currententry = (unsigned char)(k/32); - return DIRENT_noErr; - } - } - - } - j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k); - if(j!=DIRENT_noErr) - { - if(j==DIRENT_LastSect) return DIRENT_EndOfDir; /*Not clean but can avoid some bugs*/ - return j; - } - j=k; - k=0; - }while(res==DIRENT_noErr); - return res; + entry->CurrentSec = j; + entry->Currententry = (uint8_t)(0xFF&(k>>5)); + return DIRENT_noErr; + } + } + } + } + //printf("asking for next sector\n"); + //printf("current = 0x%X\n",j); + j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k); + //printf("got it 0x%x\n",k); + if(j!=DIRENT_noErr) + { + if(j==DIRENT_LastSect) return DIRENT_EndOfDir; /*Not clean but can avoid some bugs*/ + return j; + } + j=k; + k=0; + }while(res==DIRENT_noErr); + return res; } @@ -183,7 +201,7 @@ int fat32getdirentname(ucdirent* entry,c if(k==0) { //get previous sector - if(fat32prevsectorlba((FAT32fs*)entry->fs, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr; + if(fat32prevsectorlba2((FAT32fs*)entry->fs,entry, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr; fat32sectorreadout(((FAT32fs*)entry->fs),j); k=512-32; for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k]; @@ -226,7 +244,7 @@ uint32_t fat32getdirentlba(ucdirent* ent { uint32_t clusterNum = (uint32_t)((uint16_t)entry->DIR_FstClustLO) + ((uint32_t)((uint16_t)entry->DIR_FstClusHI) <<16); uint32_t lba=clusterlba(((FAT32fs*)entry->fs),clusterNum); - return lba; + return lba; } @@ -234,9 +252,9 @@ int fat32nextsectorlba(FAT32fs* fs,uint3 { if(((lastsector_lba + 1 - fs->cluster_begin_lba) & ((uint32_t)(fs->BPB_SecPerClus)-1))!=0) /*Is it the last sector of the cluster?*/ - { + { *nextsector_lba = lastsector_lba+1; /*if not just increment lba*/ - return DIRENT_noErr; + return DIRENT_noErr; } uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ @@ -246,17 +264,14 @@ int fat32nextsectorlba(FAT32fs* fs,uint3 *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i); if(*nextsector_lba==0xFFFFFFF7) { - - printf("DIRENT_BadSect\n"); return DIRENT_BadSect; } if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6) { - printf("DIRENT_LastSect\n"); return DIRENT_LastSect; } - *nextsector_lba = clusterlba(fs,*nextsector_lba); - return DIRENT_noErr; + *nextsector_lba = clusterlba(fs,*nextsector_lba); + return DIRENT_noErr; } @@ -268,25 +283,23 @@ int fat32prevsectorlba(FAT32fs* fs,uint3 *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/ return DIRENT_noErr; } - uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ + + uint32_t clusternum = fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ - do + while(fatsec>=fs->fat_begin_lba) { - fat32sectorreadout(fs,fatsec); fatsec--; - for(i=511;i>3;i-=4) + for(i=508;i>2;i-=4) { - *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i-3); + *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i); if (*nextsector_lba ==clusternum) { *nextsector_lba = clusterlba(fs,*nextsector_lba); return DIRENT_noErr; } - } - - }while(fatsec>=fs->fat_begin_lba); + } clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ @@ -305,8 +318,44 @@ int fat32prevsectorlba(FAT32fs* fs,uint3 } } + }while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32)); + return DIRENT_ReadErr; +} - }while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32)); + +int fat32prevsectorlba2(FAT32fs* fs,ucdirent* entry,uint32_t lastsector_lba,uint32_t *nextsector_lba) +{ + uint32_t i=0,fatsec=0; + if(((lastsector_lba - 1 - fs->cluster_begin_lba) & (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/ + { + *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/ + return DIRENT_noErr; + } + + uint32_t clusternum = fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ + uint32_t currentClusternum = fat32sectorlbatoclusternum(fs,(fat32getdirentlba(entry))); + fatsec=fat32clusterinfatsect(fs,currentClusternum); /*Get FAT sector number*/ + *nextsector_lba = fat32getdirentlba(entry); + while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32)) + { + uint32_t currentClusternum = fat32sectorlbatoclusternum(fs,(*nextsector_lba)); + fatsec=fat32clusterinfatsect(fs,currentClusternum); /*Get FAT sector number*/ + fat32sectorreadout(fs,fatsec); + i= fat32clusterinfatoff(currentClusternum); + if(i==clusternum) + { + return DIRENT_noErr; + } + *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i); + if(*nextsector_lba==0xFFFFFFF7) + { + return DIRENT_BadSect; + } + if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6) + { + return DIRENT_LastSect; + } + } return DIRENT_ReadErr; } @@ -332,5 +381,3 @@ int fat32prevsectorlba(FAT32fs* fs,uint3 - - diff --git a/lib/src/common/FILE_SYSTEM/FAT32/fat32_SIMULATOR.pro b/lib/src/common/FILE_SYSTEM/FAT32/fat32_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/FILE_SYSTEM/FAT32/fat32_SIMULATOR.pro @@ -0,0 +1,17 @@ +TEMPLATE = lib +OBJECTS_DIR = obj +TARGET = fat32 + +SOURCES += \ + fat32.c + +INCLUDEPATH += ../../../includes + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + +HEADERS += \ + ../../../includes/fat32.h + diff --git a/lib/src/common/FILE_SYSTEM/MBR/MBR.pro b/lib/src/common/FILE_SYSTEM/MBR/MBR.pro --- a/lib/src/common/FILE_SYSTEM/MBR/MBR.pro +++ b/lib/src/common/FILE_SYSTEM/MBR/MBR.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS += ./mbr_STM32F4.pro +SUBDIRS += ./mbr_STM32F4.pro \ + ./mbr_SIMULATOR.pro diff --git a/lib/src/common/FILE_SYSTEM/MBR/mbr.c b/lib/src/common/FILE_SYSTEM/MBR/mbr.c --- a/lib/src/common/FILE_SYSTEM/MBR/mbr.c +++ b/lib/src/common/FILE_SYSTEM/MBR/mbr.c @@ -19,7 +19,7 @@ -- Author : Alexis Jeandet -- Mail : alexis.jeandet@gmail.com -------------------------------------------------------------------------------*/ -#include "mbr.h" +#include #include @@ -33,6 +33,7 @@ int mbropen(blkdevice* phy,dikpartition* { printf("can't read MBR!\n"); printf("%x %x %x %x %x %x %x %x\n",mbr[0],mbr[1],mbr[2],mbr[3],mbr[4],mbr[5],mbr[6],mbr[7]); + part->valide = 0; return MBRReadErr; } if(((mbr[510]) == (char)0x55) && ((mbr[511]) == (char)0xAA)) @@ -41,9 +42,11 @@ int mbropen(blkdevice* phy,dikpartition* part->LBABegin = (unsigned int)mbr[(512-82+LBABeginoffset)+partNum*16] + ((unsigned int)mbr[(512-82+LBABeginoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+LBABeginoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+LBABeginoffset+3)+partNum*16]<<24); part->NumOfSec = (unsigned int)mbr[(512-82+NumOfSecoffset)+partNum*16] + ((unsigned int)mbr[(512-82+NumOfSecoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+3)+partNum*16]<<24); printf("MBR Ok\n"); + part->valide = 1; return MBRnoErr; } printf("Bad MBR MBR[510]=0x%.2X MBR[511]=0x%.2X!\n",0xff&mbr[510],0xff&mbr[511]); + part->valide = 0; return MBRBadMbr; } diff --git a/lib/src/common/FILE_SYSTEM/MBR/mbr_SIMULATOR.pro b/lib/src/common/FILE_SYSTEM/MBR/mbr_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/FILE_SYSTEM/MBR/mbr_SIMULATOR.pro @@ -0,0 +1,17 @@ +TEMPLATE = lib +OBJECTS_DIR = obj +TARGET = mbr + +SOURCES += \ + mbr.c + +INCLUDEPATH += ../../../includes + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + +HEADERS += \ + ../../../includes/mbr.h + diff --git a/lib/src/common/FILE_SYSTEM/MBR/mbr_STM32F4.pro b/lib/src/common/FILE_SYSTEM/MBR/mbr_STM32F4.pro --- a/lib/src/common/FILE_SYSTEM/MBR/mbr_STM32F4.pro +++ b/lib/src/common/FILE_SYSTEM/MBR/mbr_STM32F4.pro @@ -15,3 +15,6 @@ UCMODEL=stm32f4 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL INSTALLS += target +HEADERS += \ + ../../../includes/mbr.h + diff --git a/lib/src/common/FILE_SYSTEM/SDCARD/sdcard_STM32F4.pro b/lib/src/common/FILE_SYSTEM/SDCARD/sdcard_STM32F4.pro --- a/lib/src/common/FILE_SYSTEM/SDCARD/sdcard_STM32F4.pro +++ b/lib/src/common/FILE_SYSTEM/SDCARD/sdcard_STM32F4.pro @@ -1,5 +1,4 @@ TEMPLATE = lib -OBJECTS_DIR = obj TARGET = sdcard SOURCES += \ diff --git a/lib/src/common/GRAPHIC/CONTROLERS/ILI9328/ILI9328.pro b/lib/src/common/GRAPHIC/CONTROLERS/ILI9328/ILI9328.pro --- a/lib/src/common/GRAPHIC/CONTROLERS/ILI9328/ILI9328.pro +++ b/lib/src/common/GRAPHIC/CONTROLERS/ILI9328/ILI9328.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS += ./ili9328_STM32F4.pro +SUBDIRS += ./ili9328_STM32F4.pro \ + ./ili9328_SIMULATOR.pro diff --git a/lib/src/common/GRAPHIC/CONTROLERS/ILI9328/ili9328.c b/lib/src/common/GRAPHIC/CONTROLERS/ILI9328/ili9328.c --- a/lib/src/common/GRAPHIC/CONTROLERS/ILI9328/ili9328.c +++ b/lib/src/common/GRAPHIC/CONTROLERS/ILI9328/ili9328.c @@ -29,7 +29,6 @@ #include #endif -#define _delay_(del) for(volatile int _d_e_l_=0;_d_e_l_<(del);_d_e_l_++); #define ilipaintLine(LCD,X,Y,W,buffer,buffsize) \ for(int l=0;l<1;l++)\ @@ -339,6 +338,8 @@ void ili9328paintText(LCD_t* LCD,char* b uint8_t line=0; while(*buffer!='\0') { + if(*buffer<32)*buffer=32; + if(*buffer>127)*buffer=32; ili9328setFrame(LCD,Xpos+(charnum*w),Ypos-h,w,1); LCD->interface->readGRAM(tmp,w); for(int i=0;i<(h*w);i++) @@ -358,6 +359,7 @@ void ili9328paintText(LCD_t* LCD,char* b { line=font->table[(((*buffer)-32)*h*bpl)+tableoffset++]; } + tmp[pix]=0; if((line & (uint8_t)0x01)==(uint8_t)1)tmp[pix]=(uint16_t)color; pix++; line>>=1; diff --git a/lib/src/common/GRAPHIC/CONTROLERS/ILI9328/ili9328_SIMULATOR.pro b/lib/src/common/GRAPHIC/CONTROLERS/ILI9328/ili9328_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/GRAPHIC/CONTROLERS/ILI9328/ili9328_SIMULATOR.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +TARGET = ili9328 + +SOURCES += \ + ili9328.c + + +INCLUDEPATH += ../../../../includes \ + ../../../../includes/GRAPHIC/CONTROLERS \ + ../../../../includes/GRAPHIC/GUI/FONTS \ + ../../../../includes/GRAPHIC/GUI/Widgets + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + diff --git a/lib/src/common/GRAPHIC/CONTROLERS/SSD2119/SSD2119.pro b/lib/src/common/GRAPHIC/CONTROLERS/SSD2119/SSD2119.pro --- a/lib/src/common/GRAPHIC/CONTROLERS/SSD2119/SSD2119.pro +++ b/lib/src/common/GRAPHIC/CONTROLERS/SSD2119/SSD2119.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS += ./ssd2119_STM32F4.pro +SUBDIRS += ./ssd2119_STM32F4.pro \ + ./ssd2119_SIMULATOR.pro diff --git a/lib/src/common/GRAPHIC/CONTROLERS/SSD2119/ssd2119_SIMULATOR.pro b/lib/src/common/GRAPHIC/CONTROLERS/SSD2119/ssd2119_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/GRAPHIC/CONTROLERS/SSD2119/ssd2119_SIMULATOR.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +TARGET = ssd2119 + +SOURCES += \ + ssd2119.c + + +INCLUDEPATH += ../../../../includes \ + ../../../../includes/GRAPHIC/CONTROLERS \ + ../../../../includes/GRAPHIC/GUI/FONTS \ + ../../../../includes/GRAPHIC/GUI/Widgets + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + diff --git a/lib/src/common/GRAPHIC/CONTROLERS/SSD2119/ssd2119_STM32F4.pro b/lib/src/common/GRAPHIC/CONTROLERS/SSD2119/ssd2119_STM32F4.pro --- a/lib/src/common/GRAPHIC/CONTROLERS/SSD2119/ssd2119_STM32F4.pro +++ b/lib/src/common/GRAPHIC/CONTROLERS/SSD2119/ssd2119_STM32F4.pro @@ -1,5 +1,4 @@ TEMPLATE = lib -OBJECTS_DIR = obj TARGET = ssd2119 SOURCES += \ diff --git a/lib/src/common/GRAPHIC/GUI/FONTS/FONTS.pro b/lib/src/common/GRAPHIC/GUI/FONTS/FONTS.pro --- a/lib/src/common/GRAPHIC/GUI/FONTS/FONTS.pro +++ b/lib/src/common/GRAPHIC/GUI/FONTS/FONTS.pro @@ -1,5 +1,6 @@ TEMPLATE = subdirs -SUBDIRS += ./FONTS_STM32F4.pro +SUBDIRS += ./FONTS_STM32F4.pro \ + ./FONTS_SIMULATOR.pro diff --git a/lib/src/common/GRAPHIC/GUI/FONTS/FONTS_SIMULATOR.pro b/lib/src/common/GRAPHIC/GUI/FONTS/FONTS_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/GRAPHIC/GUI/FONTS/FONTS_SIMULATOR.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +TARGET = fonts + +SOURCES += \ + fonts8pts.c + + +INCLUDEPATH += ../../../../includes \ + ../../../../includes/GRAPHIC/CONTROLERS \ + ../../../../includes/GRAPHIC/GUI/FONTS \ + ../../../../includes/GRAPHIC/GUI/Widgets + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + diff --git a/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal.c b/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal.c --- a/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal.c +++ b/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal.c @@ -25,7 +25,7 @@ #include #include #include - +#include #define CHARXPOS(terminal,charwidth) (((terminal)->column * charwidth) + (terminal)->Xpos) #define CHARYPOS(terminal,charheight) ((terminal)->line * charheight + (terminal)->Ypos+charheight) @@ -46,19 +46,26 @@ int terminal_init(terminal_t* terminal,L terminal->font=font; terminal->line = 0; terminal->column = 0; - terminal->horizontalSpace=0; - terminal->verticalSpace=0; + terminal->horizontalSpace = 0; + terminal->verticalSpace = 0; int charw=terminal->font->Width + terminal->horizontalSpace; int charh=terminal->font->Height + terminal->verticalSpace; terminal->textColor=0xFFFF; terminal->backgroundColor=0x0000; terminal_setgeometry(terminal,5,5,terminal->LCD->width-(10),terminal->LCD->height-(10)); - strdev->_stream = (UHANDLE)terminal; strdev->ops = &TERMINAL_OPS; strdev->streamPt = 0; terminal_clear(terminal); terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal, charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); + terminal->buffer = (char*)malloc(terminal->lineCount*(terminal->columnCount + 1)); + terminal->firstLine = 0; + terminal->lastLine = 0; + terminal->empty = 1; + for(int i=1;i<=terminal->lineCount;i++) + { + terminal->buffer[i * terminal->columnCount]='\n'; + } return 1; } return 0; @@ -84,6 +91,11 @@ void terminal_setgeometry(terminal_t* te void terminal_clear(terminal_t* terminal) { + terminal->firstLine = 0; + terminal->lastLine = 0; + terminal->empty = 1; + terminal->line =0; + terminal->column=0; terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,terminal->Ypos,terminal->width,terminal->height,terminal->backgroundColor,0,terminal->backgroundColor); } @@ -103,12 +115,16 @@ void terminal_movecursor(terminal_t* ter int charw=terminal->font->Width + terminal->horizontalSpace; int charh=terminal->font->Height + terminal->verticalSpace; terminal->column += n; - if(terminal->column>terminal->columnCount) + if(terminal->column>(terminal->columnCount)) { terminal->line += (terminal->column)/terminal->columnCount; - terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal, charw),CHARYPOS(terminal,charh)-charh,charw*(terminal->columnCount-terminal->column),charh,terminal->backgroundColor,0,terminal->backgroundColor); terminal->line = terminal->line % terminal->lineCount; - terminal->column = terminal->column % terminal->columnCount; + terminal->column = (terminal->column % terminal->columnCount)-1; + int x=CHARXPOS(terminal, charw); + int y=CHARYPOS(terminal,charh)-charh; + int w=charw*(terminal->columnCount-terminal->column); + int h=charh; + terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal, charw),CHARYPOS(terminal,charh)-charh,charw*(terminal->columnCount-terminal->column-1),charh,terminal->backgroundColor,0,terminal->backgroundColor); } terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal,charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); } @@ -134,24 +150,66 @@ int terminal_writenc(terminal_t* termina { terminal->line= (terminal->line+1) % terminal->lineCount; terminal->column = 0; - terminal_clearCurentLine(terminal); + if(terminal->line==0) + terminal_clear(terminal); + else + terminal_clearCurentLine(terminal); }else { if(buffer[0]=='\t') { for(int i=0;i<1;i++)terminal_movecursor(terminal,1); }else if(terminal->column==0)terminal_clearCurentLine(terminal); - if(buffer[0]!='\r'){ - terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); - terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh),terminal->font,terminal->textColor); - terminal_movecursor(terminal,1); - } + if(buffer[0]!='\r'){ + terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); + terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh),terminal->font,terminal->textColor); + terminal_movecursor(terminal,1); + } } l++; } return n; } +void terminal_print_line(terminal_t* terminal,int line) +{ + int charw=terminal->font->Width + terminal->horizontalSpace; + int charh=terminal->font->Height + terminal->verticalSpace; + terminal_clearCurentLine(terminal); + terminal->LCD->paintText(terminal->LCD,terminal->buffer+(line*(terminal->columnCount + 1)),CHARXPOS(terminal,charw),CHARYPOS(terminal, charh),terminal->font,terminal->textColor); +} + +int terminal_writenc2(terminal_t* terminal,char* data, int n) +{ + int charw=terminal->font->Width + terminal->horizontalSpace; + int charh=terminal->font->Height + terminal->verticalSpace; + /* First copy to buffer*/ + int offset = (terminal->lastLine*(terminal->columnCount + 1)) + terminal->column; + for(int i=0;iempty=0; + terminal->buffer[offset] = data[i]; + if(data[i]=='\n') + { + offset = ((offset/(terminal->columnCount + 1) + 1) * (terminal->columnCount + 1)); + } + else + { + offset++; + } + } + if(!terminal->empty) + { + for(int i=terminal->firstLine;i<=terminal->lastLine;i++) + { + terminal_print_line(terminal,i); + } + } + return n; +} + + + int terminal_write(streamdevice* device,void* data,int size, int n) { return terminal_writenc((terminal_t*)device->_stream,(char*) data,size*n); diff --git a/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal.pro b/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal.pro --- a/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal.pro +++ b/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal.pro @@ -1,3 +1,5 @@ TEMPLATE = subdirs -SUBDIRS += ./Terminal_STM32F4.pro +SUBDIRS += ./Terminal_STM32F4.pro \ + ./Terminal_SIMULATOR.pro + diff --git a/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal_SIMULATOR.pro b/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/GRAPHIC/GUI/Widgets/Terminal/Terminal_SIMULATOR.pro @@ -0,0 +1,20 @@ +TEMPLATE = lib +TARGET = terminal + +SOURCES += \ + Terminal.c + + +INCLUDEPATH += ../../../../includes \ + ../../../../includes/GRAPHIC/CONTROLERS \ + ../../../../includes/GRAPHIC/GUI/FONTS \ + ../../../../includes/GRAPHIC/GUI/Widgets + +HEADERS += \ + ../../../../../includes/GRAPHIC/GUI/Widgets/terminal.h + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + diff --git a/lib/src/common/GRAPHIC/TC_CONTROLERS/STMPE811/STMPE811.pro b/lib/src/common/GRAPHIC/TC_CONTROLERS/STMPE811/STMPE811.pro --- a/lib/src/common/GRAPHIC/TC_CONTROLERS/STMPE811/STMPE811.pro +++ b/lib/src/common/GRAPHIC/TC_CONTROLERS/STMPE811/STMPE811.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS += ./STMPE811_STM32F4.pro +SUBDIRS += ./STMPE811_STM32F4.pro \ + ./STMPE811_SIMULATOR.pro diff --git a/lib/src/common/GRAPHIC/TC_CONTROLERS/STMPE811/STMPE811_SIMULATOR.pro b/lib/src/common/GRAPHIC/TC_CONTROLERS/STMPE811/STMPE811_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/GRAPHIC/TC_CONTROLERS/STMPE811/STMPE811_SIMULATOR.pro @@ -0,0 +1,23 @@ +TEMPLATE = lib +TARGET = STMPE811 + +SOURCES += \ + STMPE811.c + +INCLUDEPATH += ../../../../includes \ + ../../../../includes/GRAPHIC/CONTROLERS \ + ../../../../includes/GRAPHIC/TC_CONTROLERS \ + ../../../../includes/GRAPHIC/GUI/FONTS \ + ../../../../includes/GRAPHIC/GUI/Widgets + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + +HEADERS += \ + ../../../../includes/GRAPHIC/TC_CONTROLERS/STMPE811.h \ + ../../../../includes/GRAPHIC/TC_CONTROLERS/genericTC_Controler.h + + diff --git a/lib/src/common/GRAPHIC/TC_CONTROLERS/STMPE811/STMPE811_STM32F4.pro b/lib/src/common/GRAPHIC/TC_CONTROLERS/STMPE811/STMPE811_STM32F4.pro --- a/lib/src/common/GRAPHIC/TC_CONTROLERS/STMPE811/STMPE811_STM32F4.pro +++ b/lib/src/common/GRAPHIC/TC_CONTROLERS/STMPE811/STMPE811_STM32F4.pro @@ -1,5 +1,4 @@ TEMPLATE = lib -OBJECTS_DIR = obj TARGET = STMPE811 SOURCES += \ diff --git a/lib/src/common/POWER/ina226/ina226.pro b/lib/src/common/POWER/ina226/ina226.pro --- a/lib/src/common/POWER/ina226/ina226.pro +++ b/lib/src/common/POWER/ina226/ina226.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS += ./ina226_STM32F4.pro +SUBDIRS += ./ina226_STM32F4.pro \ + ./ina226_SIMULATOR.pro diff --git a/lib/src/common/POWER/ina226/ina226_SIMULATOR.pro b/lib/src/common/POWER/ina226/ina226_SIMULATOR.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/POWER/ina226/ina226_SIMULATOR.pro @@ -0,0 +1,14 @@ +TEMPLATE = lib +TARGET = ina226 + +SOURCES += ina226.c + +INCLUDEPATH += ../../../includes \ + ../../CPU/CMSIS/Include + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + diff --git a/lib/src/common/POWER/ina226/ina226_STM32F4.pro b/lib/src/common/POWER/ina226/ina226_STM32F4.pro --- a/lib/src/common/POWER/ina226/ina226_STM32F4.pro +++ b/lib/src/common/POWER/ina226/ina226_STM32F4.pro @@ -1,5 +1,4 @@ TEMPLATE = lib -OBJECTS_DIR = obj TARGET = ina226 SOURCES += ina226.c diff --git a/lib/src/includes/GRAPHIC/GUI/Widgets/terminal.h b/lib/src/includes/GRAPHIC/GUI/Widgets/terminal.h --- a/lib/src/includes/GRAPHIC/GUI/Widgets/terminal.h +++ b/lib/src/includes/GRAPHIC/GUI/Widgets/terminal.h @@ -33,6 +33,8 @@ typedef struct terminal_t uint16_t column; uint16_t lineCount; uint16_t columnCount; + uint16_t firstLine; + uint16_t lastLine; uint16_t Xpos; uint16_t Ypos; uint16_t width; @@ -41,8 +43,10 @@ typedef struct terminal_t uint32_t textColor; int8_t verticalSpace; int8_t horizontalSpace; + int8_t empty; LCD_t* LCD; sFONT* font; + char* buffer; }terminal_t; int terminal_init(terminal_t* terminal,LCD_t* LCD,sFONT* font,streamdevice* strdev); diff --git a/lib/src/includes/fat32.h b/lib/src/includes/fat32.h --- a/lib/src/includes/fat32.h +++ b/lib/src/includes/fat32.h @@ -28,41 +28,41 @@ #include /*BPB (Boot Sector) Offsets */ -#define BS_jmpBootoff 0 -#define BS_OEMNameoff 3 -#define BPB_BytsPerSecoff 11 -#define BPB_SecPerClusoff 13 -#define BPB_RsvdSecCntoff 14 -#define BPB_NumFATsoff 16 -#define BPB_RootEntCntoff 17 -#define BPB_TotSec16off 19 -#define BPB_Mediaoff 21 -#define BPB_FATSz16off 22 -#define BPB_SecPerTrkoff 24 -#define BPB_NumHeadsoff 26 -#define BPB_HiddSecoff 28 -#define BPB_TotSec32off 32 +#define BS_jmpBootoff 0 +#define BS_OEMNameoff 3 +#define BPB_BytsPerSecoff 11 +#define BPB_SecPerClusoff 13 +#define BPB_RsvdSecCntoff 14 +#define BPB_NumFATsoff 16 +#define BPB_RootEntCntoff 17 +#define BPB_TotSec16off 19 +#define BPB_Mediaoff 21 +#define BPB_FATSz16off 22 +#define BPB_SecPerTrkoff 24 +#define BPB_NumHeadsoff 26 +#define BPB_HiddSecoff 28 +#define BPB_TotSec32off 32 /*FAT16*/ -#define BS_DrvNumFAT16off 36 +#define BS_DrvNumFAT16off 36 #define BS_Reserved1FAT16off 37 -#define BS_BootSigFAT16off 38 -#define BS_VolIDFAT16off 39 -#define BS_VolLabFAT16off 43 +#define BS_BootSigFAT16off 38 +#define BS_VolIDFAT16off 39 +#define BS_VolLabFAT16off 43 #define BS_FilSysTypeFAT16off 54 /*FAT32*/ -#define BPB_FATSz32off 36 -#define BPB_ExtFlagsoff 40 -#define BPB_FSVeroff 42 -#define BPB_RootClusoff 44 -#define BPB_FSInfooff 48 -#define BPB_BkBootSecoff 50 -#define BPB_Reservedoff 52 -#define BS_DrvNumFAT32off 64 -#define BS_Reserved1FAT32off 65 -#define BS_BootSigFAT32off 66 -#define BS_VolIDFAT32off 67 -#define BS_VolLabFAT32off 71 -#define BS_FilSysTypeFAT32off 82 +#define BPB_FATSz32off 36 +#define BPB_ExtFlagsoff 40 +#define BPB_FSVeroff 42 +#define BPB_RootClusoff 44 +#define BPB_FSInfooff 48 +#define BPB_BkBootSecoff 50 +#define BPB_Reservedoff 52 +#define BS_DrvNumFAT32off 64 +#define BS_Reserved1FAT32off 65 +#define BS_BootSigFAT32off 66 +#define BS_VolIDFAT32off 67 +#define BS_VolLabFAT32off 71 +#define BS_FilSysTypeFAT32off 82 #define DIR_Nameoff 0 @@ -79,11 +79,15 @@ -#define FATBadpart 1 -#define FATBabArg 2 -#define FATReadErr 3 -#define FATnoErr 0 +#define FATBadpart 1 +#define FATBabArg 2 +#define FATReadErr 3 +#define FATnoErr 0 +/* + TODO : + intergrate a per BLKDEV or per partition buffer. +*/ typedef struct FAT32fs { uint16_t BPB_BytsPerSec; @@ -94,6 +98,7 @@ typedef struct FAT32fs uint32_t cluster_begin_lba; uint8_t BPB_SecPerClus; uint8_t BPB_NumFATs; + char valide; dikpartition* part; }FAT32fs; @@ -108,8 +113,24 @@ typedef struct FAT32fs #define castI16(val) ((int16_t)(val)) #define castI8(val) ((int8_t)(val)) -#define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24)))) -#define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8)))) +/* + TODO : + Should add global function for casting with endianness care. + have a look at REV, REV16, REVSH, and RBIT ARMV7m asm +*/ + +#if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ + #define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24)))) + #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8)))) + #define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )) + #define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 )) +#else + #define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24)))) + #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8)))) + #define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )) + #define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 )) +#endif + /* Get the first sector lba of given cluster number*/ #define clusterlba(fs,cluster_number) ((uint32_t)fs->cluster_begin_lba + (((uint32_t)cluster_number) - (2)) * (uint32_t)fs->BPB_SecPerClus) @@ -119,11 +140,9 @@ typedef struct FAT32fs #define fat32clusterinfatoff(cluster_number) (((cluster_number)&0x7F)*4) /*Get cluster index in FAT Table from sector address*/ -#define fat32masksectorlba(sectorlba,fs) (sectorlba & (castUI32(-1)^castUI32(fs->BPB_SecPerClus-1))) +#define fat32masksectorlba(sectorlba,fs) (sectorlba)//(sectorlba & (castUI32(-1)^castUI32(fs->BPB_SecPerClus-1))) #define fat32sectorlbatoclusternum(fs,sectorlba) (((fat32masksectorlba(castUI32(sectorlba),fs) -(castUI32(fs->cluster_begin_lba)))/castUI32(fs->BPB_SecPerClus))+castUI32(2)) -#define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )) -#define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 )) #ifdef FAT32_PRIVATE #define fat32sectorreadout(fs,fatsec) \ @@ -145,6 +164,7 @@ extern int fat32getrootfirstent(ucdirent extern int fat32nextdirent(ucdirent* entry); extern int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t* nextsector_lba); extern int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba); +extern int fat32prevsectorlba2(FAT32fs* fs,ucdirent* entry,uint32_t lastsector_lba,uint32_t *nextsector_lba); extern uint32_t fat32getdirentlba(ucdirent* entry); extern int fat32getdirentname(ucdirent* entry,char* nameBuffer); diff --git a/lib/src/includes/mbr.h b/lib/src/includes/mbr.h --- a/lib/src/includes/mbr.h +++ b/lib/src/includes/mbr.h @@ -39,6 +39,7 @@ typedef struct dikpartition { char TypeCode; + char valide; unsigned int LBABegin; unsigned int NumOfSec; blkdevice* phy; diff --git a/lib/src/lib.pro b/lib/src/lib.pro --- a/lib/src/lib.pro +++ b/lib/src/lib.pro @@ -4,6 +4,7 @@ CONFIG += ordered SUBDIRS += stm32f4 SUBDIRS += common +SUBDIRS += simulator headers.files = includes/*.h \ includes/GRAPHIC/CONTROLERS/*.h \ diff --git a/lib/src/simulator/CORE/core.c b/lib/src/simulator/CORE/core.c new file mode 100644 --- /dev/null +++ b/lib/src/simulator/CORE/core.c @@ -0,0 +1,126 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2011, Alexis Jeandet +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@gmail.com +-------------------------------------------------------------------------------*/ +#include +#include +#include +#include +#include +#include + +extern uint32_t OSC0; +extern uint32_t INTOSC; +extern uint32_t RTCOSC; + +volatile uint32_t tickCounter=0; + + +void SysTick_Handler(void) +{ + tickCounter+=1; +// if((tickCounter&0xFFF)==0x800) +// gpiosetval(PC15,!gpiogetval(PC15)); +} + +void delay_us(uint32_t value) +{ + usleep(value); +} + +void delay_100us(uint32_t value) +{ + usleep(value*100); +} + +uint32_t getAPB1Freq() +{ + return 0; +} + +uint32_t getAPB2Freq() +{ + return 0; +} + + +uint32_t getCpuFreq() +{ + return 0; +} + +void reset_AHB1() +{ +} + +void reset_AHB2() +{ + +} + +void reset_APB1() +{ + +} + +void reset_APB2() +{ + +} + + + + + +int optimizePLLcfg(uint32_t freq, uint32_t srcfreq,uint32_t PLLM,uint32_t* PLLP, uint32_t* PLLN,uint8_t* AHBPRindx) +{ + + return 1; +} + + +int setPll(uint32_t freq) +{ + + return freq; +} + +void configureSysTick() +{ + +} + +int setCpuFreq(uint32_t freq) +{ + + return 0; +} + + +void enable_FPU() +{ + +} + + + + + + diff --git a/lib/src/simulator/CORE/core.pro b/lib/src/simulator/CORE/core.pro new file mode 100644 --- /dev/null +++ b/lib/src/simulator/CORE/core.pro @@ -0,0 +1,13 @@ +TEMPLATE = lib +SOURCES += \ + core.c \ + threads.c \ + irq_handlers.c + +INCLUDEPATH += ../../includes + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target diff --git a/lib/src/simulator/CORE/irq_handlers.c b/lib/src/simulator/CORE/irq_handlers.c new file mode 100644 --- /dev/null +++ b/lib/src/simulator/CORE/irq_handlers.c @@ -0,0 +1,452 @@ +#include + +void NMI_Handler(void) +{ +printf("NMI_Handler\n"); +} + +void HardFault_Handler(void) +{ + printf("HardFault_Handler\n"); +} + +void MemManage_Handler(void) +{ +printf("MemManage_Handler\n"); +} + +void BusFault_Handler(void) +{ +printf("BusFault_Handler\n"); +} + +void UsageFault_Handler(void) +{ +printf("UsageFault_Handler\n"); +} + +void SVC_Handler(void) +{ +printf("SVC_Handler\n"); +} + +void DebugMon_Handler(void) +{ +printf("DebugMon_Handler\n"); +} + +void PendSV_Handler(void) +{ +printf("PendSV_Handler\n"); +} + +void WWDG_IRQHandler(void) +{ +printf("WWDG_IRQHandler\n"); +} + +void PVD_IRQHandler(void) +{ +printf("PVD_IRQHandler\n"); +} + +void TAMP_STAMP_IRQHandler(void) +{ +printf("TAMP_STAMP_IRQHandler\n"); +} + +void RTC_WKUP_IRQHandler(void) +{ +printf("RTC_WKUP_IRQHandler\n"); +} + +void FLASH_IRQHandler(void) +{ +printf("FLASH_IRQHandler\n"); +} + +void RCC_IRQHandler(void) +{ +printf("RCC_IRQHandler\n"); +} + +void EXTI0_IRQHandler(void) +{ +printf("EXTI0_IRQHandler\n"); +} + +void EXTI1_IRQHandler(void) +{ +printf("EXTI1_IRQHandler\n"); +} + +void EXTI2_IRQHandler(void) +{ +printf("EXTI2_IRQHandler\n"); +} + +void EXTI3_IRQHandler(void) +{ +printf("EXTI3_IRQHandler\n"); +} + +void EXTI4_IRQHandler(void) +{ +printf("EXTI4_IRQHandler\n"); +} + +void DMA1_Stream0_IRQHandler(void) +{ +printf("DMA1_Stream0_IRQHandler\n"); +} + +void DMA1_Stream1_IRQHandler(void) +{ +printf("DMA1_Stream1_IRQHandler\n"); +} + +void DMA1_Stream2_IRQHandler(void) +{ +printf("DMA1_Stream2_IRQHandler\n"); +} + +void DMA1_Stream3_IRQHandler(void) +{ +printf("DMA1_Stream3_IRQHandler\n"); +} + +void DMA1_Stream4_IRQHandler(void) +{ +printf("DMA1_Stream4_IRQHandler\n"); +} + +void DMA1_Stream5_IRQHandler(void) +{ +printf("DMA1_Stream5_IRQHandler\n"); +} + +void DMA1_Stream6_IRQHandler(void) +{ +printf("DMA1_Stream6_IRQHandler\n"); +} + +void ADC_IRQHandler(void) +{ +printf("ADC_IRQHandler\n"); +} + +void CAN1_TX_IRQHandler(void) +{ +printf("CAN1_TX_IRQHandler\n"); +} + +void CAN1_RX0_IRQHandler(void) +{ +printf("CAN1_RX0_IRQHandler\n"); +} + +void CAN1_RX1_IRQHandler(void) +{ +printf("CAN1_RX1_IRQHandler\n"); +} + +void CAN1_SCE_IRQHandler(void) +{ +printf("CAN1_SCE_IRQHandler\n"); +} + +void EXTI9_5_IRQHandler(void) +{ +printf("EXTI9_5_IRQHandler\n"); +} + +void TIM1_BRK_TIM9_IRQHandler(void) +{ +printf("TIM1_BRK_TIM9_IRQHandler\n"); +} + +void TIM1_UP_TIM10_IRQHandler(void) +{ +printf("TIM1_UP_TIM10_IRQHandler\n"); +} + +void TIM1_TRG_COM_TIM11_IRQHandlerIM11(void) +{ +printf("TIM1_TRG_COM_TIM11_IRQHandlerIM11"); +} + +void TIM1_CC_IRQHandler(void) +{ +printf("TIM1_CC_IRQHandler\n"); +} + +void TIM2_IRQHandler(void) +{ +printf("TIM2_IRQHandler\n"); +} + +void TIM3_IRQHandler(void) +{ +printf("TIM3_IRQHandler\n"); +} + +void TIM4_IRQHandler(void) +{ +printf("TIM4_IRQHandler\n"); +} + +void I2C1_EV_IRQHandler(void) +{ +printf("I2C1_EV_IRQHandler\n"); +} + +void I2C1_ER_IRQHandler(void) +{ +printf("I2C1_ER_IRQHandler\n"); +} + +void I2C2_EV_IRQHandler(void) +{ +printf("I2C2_EV_IRQHandler\n"); +} + +void I2C2_ER_IRQHandler(void) +{ +printf("I2C2_ER_IRQHandler\n"); +} + +void SPI1_IRQHandler(void) +{ +printf("SPI1_IRQHandler\n"); +} + +void SPI2_IRQHandler(void) +{ +printf("SPI2_IRQHandler\n"); +} + +void USART1_IRQHandler(void) +{ +printf("USART1_IRQHandler\n"); +} + +void USART2_IRQHandler(void) +{ +printf("USART2_IRQHandler\n"); +} + +void USART3_IRQHandler(void) +{ +printf("USART3_IRQHandler\n"); +} + +void EXTI15_10_IRQHandler(void) +{ +printf("EXTI15_10_IRQHandler\n"); +} + +void RTC_Alarm_IRQHandler(void) +{ +printf("RTC_Alarm_IRQHandler\n"); +} + +void OTG_FS_WKUP_IRQHandler(void) +{ +printf("OTG_FS_WKUP_IRQHandler\n"); +} + +void TIM8_BRK_TIM12_IRQHandler(void) +{ +printf("TIM8_BRK_TIM12_IRQHandler\n"); +} + +void TIM8_UP_TIM13_IRQHandler(void) +{ +printf("TIM8_UP_TIM13_IRQHandler\n"); +} + +void TIM8_TRG_COM_TIM14_IRQHandlerIM14(void) +{ +printf("TIM8_TRG_COM_TIM14_IRQHandlerIM14"); +} + +void TIM8_CC_IRQHandler(void) +{ +printf("TIM8_CC_IRQHandler\n"); +} + +void DMA1_Stream7_IRQHandler(void) +{ +printf("DMA1_Stream7_IRQHandler\n"); +} + +void FSMC_IRQHandler(void) +{ +printf("FSMC_IRQHandler\n"); +} + +void SDIO_IRQHandler(void) +{ +printf("SDIO_IRQHandler\n"); +} + +void TIM5_IRQHandler(void) +{ +printf("TIM5_IRQHandler\n"); +} + +void SPI3_IRQHandler(void) +{ +printf("SPI3_IRQHandler\n"); +} + +void UART4_IRQHandler(void) +{ +printf("UART4_IRQHandler\n"); +} + +void UART5_IRQHandler(void) +{ +printf("UART5_IRQHandler\n"); +} + +void TIM6_DAC_IRQHandler(void) +{ +printf("TIM6_DAC_IRQHandler\n"); +} + +void TIM7_IRQHandler(void) +{ +printf("TIM7_IRQHandler\n"); +} + +void DMA2_Stream0_IRQHandler(void) +{ +printf("DMA2_Stream0_IRQHandler\n"); +} + +void DMA2_Stream1_IRQHandler(void) +{ +printf("DMA2_Stream1_IRQHandler\n"); +} + +void DMA2_Stream2_IRQHandler(void) +{ +printf("DMA2_Stream2_IRQHandler\n"); +} + +void DMA2_Stream3_IRQHandler(void) +{ +printf("DMA2_Stream3_IRQHandler\n"); +} + +void DMA2_Stream4_IRQHandler(void) +{ +printf("DMA2_Stream4_IRQHandler\n"); +} + +void ETH_IRQHandler(void) +{ +printf("ETH_IRQHandler\n"); +} + +void ETH_WKUP_IRQHandler(void) +{ +printf("ETH_WKUP_IRQHandler\n"); +} + +void CAN2_TX_IRQHandler(void) +{ +printf("CAN2_TX_IRQHandler\n"); +} + +void CAN2_RX0_IRQHandler(void) +{ +printf("CAN2_RX0_IRQHandler\n"); +} + +void CAN2_RX1_IRQHandler(void) +{ +printf("CAN2_RX1_IRQHandler\n"); +} + +void CAN2_SCE_IRQHandler(void) +{ +printf("CAN2_SCE_IRQHandler\n"); +} + +void OTG_FS_IRQHandler(void) +{ +printf("OTG_FS_IRQHandler\n"); +} + +void DMA2_Stream5_IRQHandler(void) +{ +printf("DMA2_Stream5_IRQHandler\n"); +} + +void DMA2_Stream6_IRQHandler(void) +{ +printf("DMA2_Stream6_IRQHandler\n"); +} + +void DMA2_Stream7_IRQHandler(void) +{ +printf("DMA2_Stream7_IRQHandler\n"); +} + +void USART6_IRQHandler(void) +{ +printf("USART6_IRQHandler\n"); +} + +void I2C3_EV_IRQHandler(void) +{ +printf("I2C3_EV_IRQHandler\n"); +} + +void I2C3_ER_IRQHandler(void) +{ +printf("I2C3_ER_IRQHandler\n"); +} + +void OTG_HS_EP1_OUT_IRQHandler(void) +{ +printf("OTG_HS_EP1_OUT_IRQHandler\n"); +} + +void OTG_HS_EP1_IN_IRQHandler(void) +{ +printf("OTG_HS_EP1_IN_IRQHandler\n"); +} + +void OTG_HS_WKUP_IRQHandler(void) +{ +printf("OTG_HS_WKUP_IRQHandler\n"); +} + +void OTG_HS_IRQHandler(void) +{ +printf("OTG_HS_IRQHandler\n"); +} + +void DCMI_IRQHandler(void) +{ +printf("DCMI_IRQHandler\n"); +} + +void CRYP_IRQHandler(void) +{ +printf("CRYP_IRQHandler\n"); +} + +void HASH_RNG_IRQHandler(void) +{ +printf("HASH_RNG_IRQHandler\n"); +} + +void FPU_IRQHandler(void) +{ +printf("FPU_IRQHandler\n"); +} + diff --git a/lib/src/simulator/CORE/threads.c b/lib/src/simulator/CORE/threads.c new file mode 100644 --- /dev/null +++ b/lib/src/simulator/CORE/threads.c @@ -0,0 +1,81 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2013, Alexis Jeandet +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@gmail.com +-------------------------------------------------------------------------------*/ + + +#define __THREAD_PRIVATE__ +#include + +/* + For CM4 cf lazy Stacking and context switching form ARM + List of automatically saved registers: + R0 + R1 + R2 + R3 + R4 + R5 + R6 + R7 + R8 + R9 + R10 + R11 + R12 + R13(SP) + R14(LR) + R15(PC) + xPSR + S0 to S15 (if enabled) + + List of registers to save: + S16 to S31 +*/ + + +void __cpusavecontext(void* dataspace) +{ + +} + +void __cpurestorecontext(void* dataspace) +{ + +} + + + + + + + + + + + + + + + + + + + diff --git a/lib/src/simulator/CPU/cpu.c b/lib/src/simulator/CPU/cpu.c new file mode 100644 --- /dev/null +++ b/lib/src/simulator/CPU/cpu.c @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/lib/src/simulator/CPU/cpu.pri b/lib/src/simulator/CPU/cpu.pri new file mode 100644 --- /dev/null +++ b/lib/src/simulator/CPU/cpu.pri @@ -0,0 +1,14 @@ + + +LIBS += -L$$[QT_INSTALL_LIBS]/$$UCMODEL +LIBS += -lcpu + + + + + + + + + + diff --git a/lib/src/simulator/CPU/cpu.pro b/lib/src/simulator/CPU/cpu.pro new file mode 100644 --- /dev/null +++ b/lib/src/simulator/CPU/cpu.pro @@ -0,0 +1,25 @@ +TEMPLATE = lib + +UCMODEL=simulator + +prifile.files = cpu.pri startup.c fs.c +prifile.path = $$[QT_INSTALL_PREFIX]/mkspecs/features/$$UCMODEL + +INCLUDEPATH += ../../includes + +SOURCES += cpu.c + + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target prifile + + + + + + + + + + + diff --git a/lib/src/simulator/CPU/fs.c b/lib/src/simulator/CPU/fs.c new file mode 100644 --- /dev/null +++ b/lib/src/simulator/CPU/fs.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +const int32_t __max_opened_files__ = __MAX_OPENED_FILES__; +volatile streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; +const int32_t __fs_root_size__ = __FS_ROOT_SIZE__; +int32_t __fs_root__[__FS_ROOT_SIZE__]; + + +/* +void __init_fs() +{ + int i=0; + for(i=0;i<__fs_root_size__;i++) + { + __fs_root__[i]=(int32_t)NULL; + } + for(i=0;i<__max_opened_files__ ;i++) + { + __opnfiles__[i]._stream=NULL; + } +} +*/ diff --git a/lib/src/simulator/CPU/startup.c b/lib/src/simulator/CPU/startup.c new file mode 100644 --- /dev/null +++ b/lib/src/simulator/CPU/startup.c @@ -0,0 +1,7 @@ + + +int main(void) +{ + bsp_init(); + libuc2_main_task(); +} diff --git a/lib/src/simulator/GPIO/gpio.c b/lib/src/simulator/GPIO/gpio.c new file mode 100644 --- /dev/null +++ b/lib/src/simulator/GPIO/gpio.c @@ -0,0 +1,119 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2012, Alexis Jeandet +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@gmail.com +-------------------------------------------------------------------------------*/ +#include + + + +gpio_t gpioopen(uint32_t gpio) +{ + gpio &= -1^GPIOSPEEDMASK; + gpio |= gpiolowspeed; + gpio &= -1^GPIODIRMASK; + gpio |= gpioindir; + gpio &= -1^GPIOOUTTYPEMASK; + gpio |= gpiopushpulltype; + gpio &= -1^GPIOPULLTYPEMASK; + gpio |= gpionopulltype; + return gpio; +} + + +void gpioclose(gpio_t gpio) +{ +} + +void gpiosetconfig(gpio_t* gpio) +{ + gpiosetdir(gpio, (*gpio & GPIODIRMASK)); + gpiosetspeed(gpio, (*gpio & GPIOSPEEDMASK)); + gpiosetouttype(gpio, (*gpio & GPIOOUTTYPEMASK)); + gpiosetpulltype(gpio, (*gpio & GPIOPULLTYPEMASK)); +} + +extern void gpiosetspeed(gpio_t* gpio,gpiospeed_t speed) +{ + +} + + +void gpiosetdir(gpio_t* gpio,gpiodir_t dir) +{ + + +} + + +void gpiosetouttype(gpio_t* gpio, gpioouttype_t outtype) +{ + +} + + +void gpiosetpulltype(gpio_t* gpio,gpiopulltype_t pulltype) +{ + +} + +void gpioset(gpio_t gpio) +{ + +} + + +void gpioclr(gpio_t gpio) +{ + +} + +void gpiosetval(gpio_t gpio,int val) +{ + +} + +int gpiogetval(gpio_t gpio) +{ + return 0; +} + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/src/simulator/GPIO/gpio.pro b/lib/src/simulator/GPIO/gpio.pro new file mode 100644 --- /dev/null +++ b/lib/src/simulator/GPIO/gpio.pro @@ -0,0 +1,12 @@ +TEMPLATE = lib +SOURCES += gpio.c + +INCLUDEPATH += ../../includes + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + + diff --git a/lib/src/simulator/I2C/i2c.c b/lib/src/simulator/I2C/i2c.c new file mode 100644 --- /dev/null +++ b/lib/src/simulator/I2C/i2c.c @@ -0,0 +1,132 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2012, Alexis Jeandet +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@gmail.com +-------------------------------------------------------------------------------*/ + +#include +#include + + +int i2ctimeout=1000*1000; + + +i2c_t i2copen(int count) +{ + return -1; +} + +i2c_t i2copenandconfig(int count,uint32_t cfg,uint32_t speed,uint32_t SDA,uint32_t SCL) +{ + i2c_t dev = i2copen(count); + if(dev!=-1) + { + i2cclose(dev); + i2csetpins(dev,SDA,SCL); + i2copen(count); + i2csetspeed(dev,speed); + i2cenable(count); + } + return dev; +} + +int i2cclose(i2c_t dev) +{ + return 1; +} + +int i2csetpins(i2c_t dev, uint32_t SDA, uint32_t SCL) +{ + if((dev=i2c1)) + { + return 0; + } + return -1; +} + +int i2cenable(i2c_t dev) +{ + if((dev=i2c1)) + { + + return 0; + } + return -1; +} + +int i2cdisable(i2c_t dev) +{ + if((dev=i2c1)) + { + + return 0; + } + return -1; +} + + +int i2csetspeed(i2c_t dev,uint32_t speed) +{ + if((dev=i2c1)) + { + return 0; + } + return -1; +} + +int i2cbusy(i2c_t dev) +{ + if((dev=i2c1)) + { + return 0; /* Dev isn't busy */ + } + return -1; /* Error, dev is out of range */ +} + +int i2cwrite(i2c_t dev,char address,char* data,int count) +{ + if((dev=i2c1)) + { + + return 0; + } + return -1; +} + +int i2cread(i2c_t dev,char address,char* data,int count) +{ + if((dev=i2c1)) + { + return 0; + } + return -1; +} + + +int i2cStatusCheck(i2c_t dev,int32_t flagMask) +{ + int32_t flag; + if((dev=i2c1)) + { + return 0; + } + return -1; +} + + diff --git a/lib/src/simulator/I2C/i2c.pro b/lib/src/simulator/I2C/i2c.pro new file mode 100644 --- /dev/null +++ b/lib/src/simulator/I2C/i2c.pro @@ -0,0 +1,12 @@ +TEMPLATE = lib +SOURCES += i2c.c + +INCLUDEPATH += ../../includes + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + + diff --git a/lib/src/simulator/SDCARD/SDCARD.pro b/lib/src/simulator/SDCARD/SDCARD.pro new file mode 100644 --- /dev/null +++ b/lib/src/simulator/SDCARD/SDCARD.pro @@ -0,0 +1,15 @@ +TEMPLATE = lib +TARGET = sdcard +SOURCES += fakesdcard.c + +INCLUDEPATH += ../../includes +HEADERS += \ + ../../includes/sdcard.h + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + + diff --git a/lib/src/simulator/SDCARD/fakesdcard.c b/lib/src/simulator/SDCARD/fakesdcard.c new file mode 100644 --- /dev/null +++ b/lib/src/simulator/SDCARD/fakesdcard.c @@ -0,0 +1,115 @@ +#include +#include +#include + +FILE* sdcardimg; + + +void sdcardmake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,unsigned int ),void (*xmit_mmc) (UHANDLE,const char *,unsigned int ),void (*setspeed) (UHANDLE phy,unsigned int speed),unsigned int (*getspeed) (UHANDLE phy)) +{ + +} + + +int sdcardselect (blkdevice* _this) +{ + return 1; +} + + +void sdcarddeselect (blkdevice* _this) +{ + +} + +int sdcardwait_ready (sdcardDev* sdcard) +{ + return 1; +} + +void sdcardpower (blkdevice* _this) +{ + +} + +char sdcarddetect (blkdevice* _this) +{ + return 1; +} + +char sdcardwriteprotected (blkdevice* _this) +{ + return 0; +} + + + +int sdcardxmit_datablock (sdcardDev* sdcard,const char *buff,char token) +{ + return 1; +} + +int sdcardrcvr_datablock (sdcardDev* sdcard,char *buff,unsigned int btr) +{ + return 1; +} + +char sdcardsend_cmd (blkdevice* _this,char cmd,unsigned int arg) +{ + return 1; +} + +DSTATUS sdcarddisk_status (blkdevice* _this) +{} + +DSTATUS sdcarddisk_initialize (blkdevice* _this) +{} + +DRESULT sdcarddisk_read (blkdevice* _this,char *buff,unsigned long sector,char count) +{ + int res = fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET); + if(count*512== fread(buff,1,count*512,sdcardimg)) + return RES_OK; + return RES_ERROR; +} + +DRESULT sdcarddisk_write (blkdevice* _this,const char *buff,unsigned long sector,char count) +{ + fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET); + fwrite(buff,1,count*512,sdcardimg); + return RES_OK; +} + +DRESULT sdcarddisk_ioctl (blkdevice* _this,char ctrl,void *buff) +{} + + +void sdcardspimakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected) +{ + sdcardimg=fopen("sdcard.bin","rb"); +// sdcardimg=fopen("usbkey.bin","rb"); + if(sdcardimg!=NULL)printf("ok sdcard openned\n"); + else printf("Nok sdcard not openned\n"); + dev->phy=NULL; + dev->select= (blkdevselect_t)select; + dev->power = (blkdevpower_t)power; + dev->detect = (blkdevdetect_t)detect; + dev->writeprotected = (blkdevwriteprotected_t)writeprotected; + dev->write = sdcarddisk_write; + dev->read = sdcarddisk_read; + dev->ioctl = sdcarddisk_ioctl; + dev->initialize = sdcarddisk_initialize; + dev->status = sdcarddisk_status; + printf("sdcard opened\n"); +} + + + + + + + + + + + diff --git a/lib/src/simulator/SDLCD/SDLCD.c b/lib/src/simulator/SDLCD/SDLCD.c new file mode 100644 --- /dev/null +++ b/lib/src/simulator/SDLCD/SDLCD.c @@ -0,0 +1,237 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2013, Alexis Jeandet +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@gmail.com +-------------------------------------------------------------------------------*/ + +#include +#include +#include "SDLCD.h" + +SDL_Surface *screen; +SDL_Overlay *bmp; + +int SDLCD_Xpos=0; +int SDLCD_Ypos=0; +int SDLCD_XWinStrt=0; +int SDLCD_YWinStrt=0; +int SDLCD_XWinEnd=0; +int SDLCD_YWinEnd=0; + +void* SDLCD_buffer; +int SDLCD_bpp; +void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel); + +void SDLCD_mkscreen(int resx,int resy,int bpp,int lcdtype) +{ + int i=0; + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)) { + fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); + exit(1); + } + screen = SDL_SetVideoMode(resx, resy, bpp, 0); + if(!screen) { + fprintf(stderr, "SDL: could not set video mode - exiting\n"); + exit(1); + } + if ( SDL_MUSTLOCK(screen) ) { + if ( SDL_LockSurface(screen) < 0 ) { + fprintf(stderr, "Can’t lock screen: %s\n", SDL_GetError()); + return; + } + } + if ( SDL_MUSTLOCK(screen) ) { + SDL_UnlockSurface(screen); + } + SDL_UpdateRect(screen, 0, 0, resx, resy); + SDLCD_buffer = malloc(resx*resy*bpp/8); + SDLCD_bpp = bpp; + for(i=0;i<(resx*resy);i++) + { + SDLCD_putpixel(screen, i%resx, (i/resx), 0xFFFF); + } +} + + + +int SDLCD_init() +{ + +} + +void SDLCD_writereg(uint32_t reg,uint32_t data) +{ + switch (reg) { + case ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET: + SDLCD_Xpos = data; + break; + case ILI9328_REGISTER_VERTICALGRAMADDRESSSET: + SDLCD_Ypos = data; + break; + case ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION: + SDLCD_XWinStrt = data; + break; + case ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION: + SDLCD_XWinEnd = data; + break; + case ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION: + SDLCD_YWinStrt = data; + break; + case ILI9328_REGISTER_VERTICALADDRESSENDPOSITION: + SDLCD_YWinEnd = data; + break; + default: + break; + } +} + +uint32_t SDLCD_readreg(uint32_t reg) +{ + return 0; +} + + +void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) +{ + int bpp = surface->format->BytesPerPixel; + /* Here p is the address to the pixel we want to set */ + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + switch(bpp) { + case 1: + *p = pixel; + break; + case 2: + *(Uint16 *)p = pixel; + break; + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { + p[0] = (pixel >> 16) & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = pixel & 0xff; + } else { + p[0] = pixel & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = (pixel >> 16) & 0xff; + } + break; + case 4: + *(Uint32 *)p = pixel; + break; + } +} + +Uint32 SDLCD_getpixel(SDL_Surface *surface, int x, int y) +{ + int bpp = surface->format->BytesPerPixel; + /* Here p is the address to the pixel we want to retrieve */ + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + switch(bpp) { + case 1: + return *p; + case 2: + return *(Uint16 *)p; + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + return p[0] << 16 | p[1] << 8 | p[2]; + else + return p[0] | p[1] << 8 | p[2] << 16; + case 4: + return *(Uint32 *)p; + default: + return 0; + } + /* shouldn’t happen, but avoids warnings */ +} + +void SDLCD_writeGRAM(void* buffer,uint32_t count) +{ + int i=0; + u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; + u_int16_t* inptr=(u_int16_t*)buffer; + if ( SDL_MUSTLOCK(screen) ) { + if ( SDL_LockSurface(screen) < 0 ) { + fprintf(stderr, "Can’t lock screen: %s\n", SDL_GetError()); + return; + } + } + for(i=0;i=SDLCD_XWinEnd) + { + SDLCD_Xpos=SDLCD_XWinStrt; + SDLCD_Ypos+=1; + } + if(SDLCD_Ypos>=SDLCD_YWinEnd) + { + SDLCD_Ypos=SDLCD_YWinStrt; + } + } + if ( SDL_MUSTLOCK(screen) ) { + SDL_UnlockSurface(screen); + } + SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); +} + +void SDLCD_readGRAM(void* buffer,uint32_t count) +{ + int i=0; + u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; + u_int16_t* inptr=(u_int16_t*)buffer; + for(i=0;i=SDLCD_XWinEnd) + { + SDLCD_Xpos=SDLCD_XWinStrt; + SDLCD_Ypos+=1; + } + if(SDLCD_Ypos>=SDLCD_YWinEnd) + { + SDLCD_Ypos=SDLCD_YWinStrt; + } + } + +} + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/src/simulator/SDLCD/SDLCD.h b/lib/src/simulator/SDLCD/SDLCD.h new file mode 100644 --- /dev/null +++ b/lib/src/simulator/SDLCD/SDLCD.h @@ -0,0 +1,46 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2013, Alexis Jeandet +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@gmail.com +-------------------------------------------------------------------------------*/ + +#include +#include +#include + +#define LCDILI9328 9328 + +extern SDL_Surface *screen; +extern SDL_Overlay *bmp; + +extern void SDLCD_mkscreen(int resx,int resy,int bbp,int lcdtype); +extern int SDLCD_init(); +extern void SDLCD_writereg(uint32_t reg,uint32_t data); +extern uint32_t SDLCD_readreg(uint32_t reg); +extern void SDLCD_writeGRAM(void* buffer,uint32_t count); +extern void SDLCD_readGRAM(void* buffer,uint32_t count); + + + + + + + + + diff --git a/lib/src/simulator/SDLCD/SDLCD.pro b/lib/src/simulator/SDLCD/SDLCD.pro new file mode 100644 --- /dev/null +++ b/lib/src/simulator/SDLCD/SDLCD.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +SOURCES += SDLCD.c + +HEADERS += ./SDLCD.h + +INCLUDEPATH += ../../includes + +SDLCDHEADERS.files += \ + ./SDLCD.h + +SDLCDHEADERS.path = $$[QT_INSTALL_HEADERS]/simulator + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target SDLCDHEADERS + + diff --git a/lib/src/simulator/SPI/spi.c b/lib/src/simulator/SPI/spi.c new file mode 100644 --- /dev/null +++ b/lib/src/simulator/SPI/spi.c @@ -0,0 +1,255 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2011, Alexis Jeandet +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@gmail.com +-------------------------------------------------------------------------------*/ + +#include +#include + + + +spi_t spiopen(int count) +{ + + return -1; +} + +spi_t spiopenandconfig(int count, uint32_t cfg, uint32_t speed, uint32_t MOSIpin, uint32_t MISOpin, uint32_t SCKpin, uint32_t SCSpin) +{ + spi_t dev = spiopen(count); + if(dev!=-1) + { + spidisable(dev); + spisetpins(dev,MOSIpin, MISOpin, SCKpin, SCSpin); + spienable(dev); + spisetconfig(dev,cfg,speed); + } + return dev; +} + + +int spiclose(spi_t spidev) +{ + if((spidev<3)&&(spidev>=0)) + { + + return 1; + } + return -1; +} + +int spisetpins(spi_t spidev,uint32_t MOSIpin,uint32_t MISOpin,uint32_t SCKpin,uint32_t SCSpin) +{ + if((spidev<3)&&(spidev>=0)) + { + + return 1; + } + return -1; +} + + +int spienable(spi_t spidev) +{ + if((spidev<3)&&(spidev>=0)) + { + return 1; + } + return -1; +} + + +int spidisable(spi_t spidev) +{ + if((spidev<3)&&(spidev>=0)) + { + return 1; + } + return -1; +} + +int spisetconfig(spi_t spidev, uint32_t config, uint32_t speed) +{ + if((spidev<3)&&(spidev>=0)) + { + return 0; + } + return 1; +} + +int spisetspeed(spi_t spidev, uint32_t speed) +{ + if((spidev<3)&&(spidev>=0)) + { + return 1; + } + return -1; +} + +uint32_t spigetspeed(spi_t spidev) +{ + if((spidev<3)&&(spidev>=0)) + { + + return 0; + } + return -1; +} + +int spisetdatabits(spi_t spidev,spibits_t bitscnt) +{ + if((spidev<3)&&(spidev>=0)) + { + return 0; + } + return -1; +} + +int spisetbitorder(spi_t spidev,spibitorder_t order) +{ + if((spidev<3)&&(spidev>=0)) + { + return 1; + } + return -1; +} + +int spisetclkinhlevel(spi_t spidev,spiclkinhlvl_t level) +{ + if((spidev<3)&&(spidev>=0)) + { + return 1; + } + return -1; +} + +int spisetclkphase(spi_t spidev,spiclkphase_t phase) +{ + if((spidev<3)&&(spidev>=0)) + { + return 1; + } + return -1; +} + +int spiputw(spi_t spidev,uint16_t data) +{ + if((spidev<3)&&(spidev>=0)) + { + return 0; + } + return -1; +} +uint16_t spigetw(spi_t spidev) +{ + if((spidev<3)&&(spidev>=0)) + { + return 0; + } + return -1; +} + +int spiputs(spi_t spidev,char* s) +{ + while (*s) spiputw(spidev,*s++); + return 1; +} + +int spigets(spi_t spidev,char* s) +{ + do + { + (*s) = spigetw(spidev); + } + while(*s++); + return 1; +} + +int spiputnw(spi_t spidev,uint16_t* w,int n) +{ + while(n!=0) + { + spiputw(spidev,*w++); + n--; + } + return 1; +} + +int spigetnw(spi_t spidev,uint16_t* w,int n) +{ + while(n!=0) + { + *w++=spigetw(spidev); + n--; + } + return 1; +} + +int spiputnc(spi_t spidev,char* c,int n) +{ + while(n!=0) + { + spiputw(spidev,*c++); + n--; + } + return 1; +} + +int spigetnc(spi_t spidev,char* c,int n) +{ + while(n!=0) + { + *c++=spigetw(spidev); + n--; + } + return 1; +} + +int spiavailiabledata(spi_t spidev) +{ + return 0; +} + + +int spitransactionfinished(spi_t spidev) +{ + if((spidev<3)&&(spidev>=0)) + { + return 1; + } + return 0; +} + + + + + + + + + + + + + + + + + diff --git a/lib/src/simulator/SPI/spi.pro b/lib/src/simulator/SPI/spi.pro new file mode 100644 --- /dev/null +++ b/lib/src/simulator/SPI/spi.pro @@ -0,0 +1,14 @@ +TEMPLATE = lib +SOURCES += spi.c + +HEADERS += ../../includes/spi.h + +INCLUDEPATH += ../../includes + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + + diff --git a/lib/src/simulator/UART/uart.c b/lib/src/simulator/UART/uart.c new file mode 100644 --- /dev/null +++ b/lib/src/simulator/UART/uart.c @@ -0,0 +1,226 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2013, Alexis Jeandet +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@gmail.com +-------------------------------------------------------------------------------*/ + +#include +#include +#include + + + +int _uartstrsetpos(streamdevice* device,int pos); +int _uartstrread(streamdevice* device,void* data,int size, int n); +int _uartstrwrite(streamdevice* device,void* data,int size, int n); + +streamdevice_ops UART_OPS= +{ + .write = &_uartstrwrite, + .read = &_uartstrread, + .setpos= &_uartstrsetpos, + .close = NULL +}; + +uart_t uartopen(int count) +{ + return -1; +} + +uart_t uartopenandconfig(int count, uint32_t cfg, uint32_t speed, uint32_t TXpin, uint32_t RXpin, uint32_t RTSpin, uint32_t CTSpin) +{ + uart_t dev= uartopen(count); + uartsetconfig(dev,cfg,speed); + uartsetpins(dev,TXpin,RXpin,RTSpin,CTSpin); + return dev; +} + + +int uartclose(uart_t uart) +{ + return 1; +} + +int uartsetpins(uart_t uart,uint32_t TXpin,uint32_t RXpin,uint32_t RTSpin,uint32_t CTSpin) +{ + if(uart >5)return -1; + if(uart <0)return -1; + return 1; +} + +int uartsetconfig(uart_t uart, uint32_t cfg, uint32_t speed) +{ + int res=1; + uartdisable(uart); + uartsetspeed(uart,speed); + uartsetparity(uart,cfg & UARTPARITYMASK); + uartsetdatabits(uart,cfg & UARTBITSMASK); + uartsetstopbits(uart,cfg & UARTSTOPBITSMASK); + uartenable(uart); + return res; +} + +int uartenable(uart_t uart) +{ + if((uart<6)&&(uart>=0)) + { + return 1; + } + return -1; +} + +int uartdisable(uart_t uart) +{ + if((uart<6)&&(uart>=0)) + { + return 1; + } + return -1; +} + +int uartsetspeed(uart_t uart,uint32_t speed) +{ + if((uart<6)&&(uart>=0)) + { + return 1; + } + return -1; +} + +int uartsetparity(uart_t uart,uartparity_t parity) +{ + if((uart<6)&&(uart>=0)) + { + return 1; + } + return -1; +} + +int uartsetdatabits(uart_t uart,uartbits_t databits) +{ + if((uart<6)&&(uart>=0)) + { + return 1; + } + return -1; +} + +int uartsetstopbits(uart_t uart,uartstopbits_t stopbits) +{ + if((uart<6)&&(uart>=0)) + { + return 1; + } + return -1; +} + +int uartputc(uart_t uart,char c) +{ + if((uart<6)&&(uart>=0)) + { + return 1; + } + return -1; +} + +char uartgetc(uart_t uart) +{ + if((uart<6)&&(uart>=0)) + { + return 0; + } + return -1; +} + +int uartputs(uart_t uart,char* s) +{ + while (*s) uartputc(uart,*s++); + return 1; +} + +int uartgets(uart_t uart,char* s) +{ + do + { + (*s) = uartgetc(uart); + } + while(*s++); + return 1; +} + +int uartputnc(uart_t uart,char* c,int n) +{ + int l=0; + while(l=0)) + { + return 1; + } + return -1; +} + + +int _uartstrwrite(streamdevice* device,void* data,int size, int n) +{ + return uartputnc((uart_t) device->_stream,(char*) data,size*n); +} + +int _uartstrread(streamdevice* device,void* data,int size, int n) +{ + return uartgetnc((uart_t) device->_stream,(char*) data,size*n); +} + +int _uartstrsetpos(streamdevice* device,int pos) +{ + return 1; +} + +int uartmkstreamdev(uart_t uart,streamdevice* strdev) +{ + strdev->_stream = (UHANDLE)uart; + strdev->ops = &UART_OPS; + strdev->streamPt = 0; + return 1; +} + + + + + + diff --git a/lib/src/simulator/UART/uart.pro b/lib/src/simulator/UART/uart.pro new file mode 100644 --- /dev/null +++ b/lib/src/simulator/UART/uart.pro @@ -0,0 +1,12 @@ +TEMPLATE = lib +SOURCES += uart.c + +INCLUDEPATH += ../../includes + + +UCMODEL=simulator + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + + diff --git a/lib/src/simulator/simulator.pro b/lib/src/simulator/simulator.pro new file mode 100644 --- /dev/null +++ b/lib/src/simulator/simulator.pro @@ -0,0 +1,14 @@ +TEMPLATE = subdirs +CONFIG += ordered +SUBDIRS = CORE/core.pro \ + CPU/cpu.pro \ + GPIO/gpio.pro \ + UART/uart.pro \ + SPI/spi.pro \ + I2C/i2c.pro \ + SDCARD \ + SDLCD + + + + diff --git a/lib/src/stm32f4/CORE/core.c b/lib/src/stm32f4/CORE/core.c --- a/lib/src/stm32f4/CORE/core.c +++ b/lib/src/stm32f4/CORE/core.c @@ -25,6 +25,7 @@ #include #include #include +#include extern uint32_t OSC0; extern uint32_t INTOSC; @@ -36,6 +37,8 @@ volatile uint32_t tickCounter=0; void SysTick_Handler(void) { tickCounter+=1; + if((tickCounter&0xFFF)==0x800) + gpiosetval(PC15,!gpiogetval(PC15)); } void delay_us(uint32_t value) diff --git a/lib/src/stm32f4/CORE/core.pro b/lib/src/stm32f4/CORE/core.pro --- a/lib/src/stm32f4/CORE/core.pro +++ b/lib/src/stm32f4/CORE/core.pro @@ -3,7 +3,8 @@ OBJECTS_DIR = obj SOURCES += \ core.c \ - threads.c + threads.c \ + irq_handlers.c INCLUDEPATH += ../../includes \ ../CPU/STM32F4xx_StdPeriph_Driver/inc \ diff --git a/lib/src/stm32f4/CORE/irq_handlers.c b/lib/src/stm32f4/CORE/irq_handlers.c new file mode 100644 --- /dev/null +++ b/lib/src/stm32f4/CORE/irq_handlers.c @@ -0,0 +1,452 @@ +#include + +void NMI_Handler(void) +{ +printf("NMI_Handler\n"); +} + +void HardFault_Handler(void) +{ + printf("HardFault_Handler\n"); +} + +void MemManage_Handler(void) +{ +printf("MemManage_Handler\n"); +} + +void BusFault_Handler(void) +{ +printf("BusFault_Handler\n"); +} + +void UsageFault_Handler(void) +{ +printf("UsageFault_Handler\n"); +} + +void SVC_Handler(void) +{ +printf("SVC_Handler\n"); +} + +void DebugMon_Handler(void) +{ +printf("DebugMon_Handler\n"); +} + +void PendSV_Handler(void) +{ +printf("PendSV_Handler\n"); +} + +void WWDG_IRQHandler(void) +{ +printf("WWDG_IRQHandler\n"); +} + +void PVD_IRQHandler(void) +{ +printf("PVD_IRQHandler\n"); +} + +void TAMP_STAMP_IRQHandler(void) +{ +printf("TAMP_STAMP_IRQHandler\n"); +} + +void RTC_WKUP_IRQHandler(void) +{ +printf("RTC_WKUP_IRQHandler\n"); +} + +void FLASH_IRQHandler(void) +{ +printf("FLASH_IRQHandler\n"); +} + +void RCC_IRQHandler(void) +{ +printf("RCC_IRQHandler\n"); +} + +void EXTI0_IRQHandler(void) +{ +printf("EXTI0_IRQHandler\n"); +} + +void EXTI1_IRQHandler(void) +{ +printf("EXTI1_IRQHandler\n"); +} + +void EXTI2_IRQHandler(void) +{ +printf("EXTI2_IRQHandler\n"); +} + +void EXTI3_IRQHandler(void) +{ +printf("EXTI3_IRQHandler\n"); +} + +void EXTI4_IRQHandler(void) +{ +printf("EXTI4_IRQHandler\n"); +} + +void DMA1_Stream0_IRQHandler(void) +{ +printf("DMA1_Stream0_IRQHandler\n"); +} + +void DMA1_Stream1_IRQHandler(void) +{ +printf("DMA1_Stream1_IRQHandler\n"); +} + +void DMA1_Stream2_IRQHandler(void) +{ +printf("DMA1_Stream2_IRQHandler\n"); +} + +void DMA1_Stream3_IRQHandler(void) +{ +printf("DMA1_Stream3_IRQHandler\n"); +} + +void DMA1_Stream4_IRQHandler(void) +{ +printf("DMA1_Stream4_IRQHandler\n"); +} + +void DMA1_Stream5_IRQHandler(void) +{ +printf("DMA1_Stream5_IRQHandler\n"); +} + +void DMA1_Stream6_IRQHandler(void) +{ +printf("DMA1_Stream6_IRQHandler\n"); +} + +void ADC_IRQHandler(void) +{ +printf("ADC_IRQHandler\n"); +} + +void CAN1_TX_IRQHandler(void) +{ +printf("CAN1_TX_IRQHandler\n"); +} + +void CAN1_RX0_IRQHandler(void) +{ +printf("CAN1_RX0_IRQHandler\n"); +} + +void CAN1_RX1_IRQHandler(void) +{ +printf("CAN1_RX1_IRQHandler\n"); +} + +void CAN1_SCE_IRQHandler(void) +{ +printf("CAN1_SCE_IRQHandler\n"); +} + +void EXTI9_5_IRQHandler(void) +{ +printf("EXTI9_5_IRQHandler\n"); +} + +void TIM1_BRK_TIM9_IRQHandler(void) +{ +printf("TIM1_BRK_TIM9_IRQHandler\n"); +} + +void TIM1_UP_TIM10_IRQHandler(void) +{ +printf("TIM1_UP_TIM10_IRQHandler\n"); +} + +void TIM1_TRG_COM_TIM11_IRQHandlerIM11(void) +{ +printf("TIM1_TRG_COM_TIM11_IRQHandlerIM11"); +} + +void TIM1_CC_IRQHandler(void) +{ +printf("TIM1_CC_IRQHandler\n"); +} + +void TIM2_IRQHandler(void) +{ +printf("TIM2_IRQHandler\n"); +} + +void TIM3_IRQHandler(void) +{ +printf("TIM3_IRQHandler\n"); +} + +void TIM4_IRQHandler(void) +{ +printf("TIM4_IRQHandler\n"); +} + +void I2C1_EV_IRQHandler(void) +{ +printf("I2C1_EV_IRQHandler\n"); +} + +void I2C1_ER_IRQHandler(void) +{ +printf("I2C1_ER_IRQHandler\n"); +} + +void I2C2_EV_IRQHandler(void) +{ +printf("I2C2_EV_IRQHandler\n"); +} + +void I2C2_ER_IRQHandler(void) +{ +printf("I2C2_ER_IRQHandler\n"); +} + +void SPI1_IRQHandler(void) +{ +printf("SPI1_IRQHandler\n"); +} + +void SPI2_IRQHandler(void) +{ +printf("SPI2_IRQHandler\n"); +} + +void USART1_IRQHandler(void) +{ +printf("USART1_IRQHandler\n"); +} + +void USART2_IRQHandler(void) +{ +printf("USART2_IRQHandler\n"); +} + +void USART3_IRQHandler(void) +{ +printf("USART3_IRQHandler\n"); +} + +void EXTI15_10_IRQHandler(void) +{ +printf("EXTI15_10_IRQHandler\n"); +} + +void RTC_Alarm_IRQHandler(void) +{ +printf("RTC_Alarm_IRQHandler\n"); +} + +void OTG_FS_WKUP_IRQHandler(void) +{ +printf("OTG_FS_WKUP_IRQHandler\n"); +} + +void TIM8_BRK_TIM12_IRQHandler(void) +{ +printf("TIM8_BRK_TIM12_IRQHandler\n"); +} + +void TIM8_UP_TIM13_IRQHandler(void) +{ +printf("TIM8_UP_TIM13_IRQHandler\n"); +} + +void TIM8_TRG_COM_TIM14_IRQHandlerIM14(void) +{ +printf("TIM8_TRG_COM_TIM14_IRQHandlerIM14"); +} + +void TIM8_CC_IRQHandler(void) +{ +printf("TIM8_CC_IRQHandler\n"); +} + +void DMA1_Stream7_IRQHandler(void) +{ +printf("DMA1_Stream7_IRQHandler\n"); +} + +void FSMC_IRQHandler(void) +{ +printf("FSMC_IRQHandler\n"); +} + +void SDIO_IRQHandler(void) +{ +printf("SDIO_IRQHandler\n"); +} + +void TIM5_IRQHandler(void) +{ +printf("TIM5_IRQHandler\n"); +} + +void SPI3_IRQHandler(void) +{ +printf("SPI3_IRQHandler\n"); +} + +void UART4_IRQHandler(void) +{ +printf("UART4_IRQHandler\n"); +} + +void UART5_IRQHandler(void) +{ +printf("UART5_IRQHandler\n"); +} + +void TIM6_DAC_IRQHandler(void) +{ +printf("TIM6_DAC_IRQHandler\n"); +} + +void TIM7_IRQHandler(void) +{ +printf("TIM7_IRQHandler\n"); +} + +void DMA2_Stream0_IRQHandler(void) +{ +printf("DMA2_Stream0_IRQHandler\n"); +} + +void DMA2_Stream1_IRQHandler(void) +{ +printf("DMA2_Stream1_IRQHandler\n"); +} + +void DMA2_Stream2_IRQHandler(void) +{ +printf("DMA2_Stream2_IRQHandler\n"); +} + +void DMA2_Stream3_IRQHandler(void) +{ +printf("DMA2_Stream3_IRQHandler\n"); +} + +void DMA2_Stream4_IRQHandler(void) +{ +printf("DMA2_Stream4_IRQHandler\n"); +} + +void ETH_IRQHandler(void) +{ +printf("ETH_IRQHandler\n"); +} + +void ETH_WKUP_IRQHandler(void) +{ +printf("ETH_WKUP_IRQHandler\n"); +} + +void CAN2_TX_IRQHandler(void) +{ +printf("CAN2_TX_IRQHandler\n"); +} + +void CAN2_RX0_IRQHandler(void) +{ +printf("CAN2_RX0_IRQHandler\n"); +} + +void CAN2_RX1_IRQHandler(void) +{ +printf("CAN2_RX1_IRQHandler\n"); +} + +void CAN2_SCE_IRQHandler(void) +{ +printf("CAN2_SCE_IRQHandler\n"); +} + +void OTG_FS_IRQHandler(void) +{ +printf("OTG_FS_IRQHandler\n"); +} + +void DMA2_Stream5_IRQHandler(void) +{ +printf("DMA2_Stream5_IRQHandler\n"); +} + +void DMA2_Stream6_IRQHandler(void) +{ +printf("DMA2_Stream6_IRQHandler\n"); +} + +void DMA2_Stream7_IRQHandler(void) +{ +printf("DMA2_Stream7_IRQHandler\n"); +} + +void USART6_IRQHandler(void) +{ +printf("USART6_IRQHandler\n"); +} + +void I2C3_EV_IRQHandler(void) +{ +printf("I2C3_EV_IRQHandler\n"); +} + +void I2C3_ER_IRQHandler(void) +{ +printf("I2C3_ER_IRQHandler\n"); +} + +void OTG_HS_EP1_OUT_IRQHandler(void) +{ +printf("OTG_HS_EP1_OUT_IRQHandler\n"); +} + +void OTG_HS_EP1_IN_IRQHandler(void) +{ +printf("OTG_HS_EP1_IN_IRQHandler\n"); +} + +void OTG_HS_WKUP_IRQHandler(void) +{ +printf("OTG_HS_WKUP_IRQHandler\n"); +} + +void OTG_HS_IRQHandler(void) +{ +printf("OTG_HS_IRQHandler\n"); +} + +void DCMI_IRQHandler(void) +{ +printf("DCMI_IRQHandler\n"); +} + +void CRYP_IRQHandler(void) +{ +printf("CRYP_IRQHandler\n"); +} + +void HASH_RNG_IRQHandler(void) +{ +printf("HASH_RNG_IRQHandler\n"); +} + +void FPU_IRQHandler(void) +{ +printf("FPU_IRQHandler\n"); +} + diff --git a/lib/src/stm32f4/CPU/cpuinit.c b/lib/src/stm32f4/CPU/cpuinit.c --- a/lib/src/stm32f4/CPU/cpuinit.c +++ b/lib/src/stm32f4/CPU/cpuinit.c @@ -46,9 +46,9 @@ void cpu_init() while(1) { delay_100us(10000); - gpioset(LED1); + gpioset(LED2); delay_100us(10000); - gpioclr(LED1); + gpioclr(LED2); } } diff --git a/lib/src/stm32f4/CPU/stm32_flash.ld b/lib/src/stm32f4/CPU/stm32_flash.ld --- a/lib/src/stm32f4/CPU/stm32_flash.ld +++ b/lib/src/stm32f4/CPU/stm32_flash.ld @@ -36,8 +36,8 @@ ENTRY(Reset_Handler) _estack = 0x20020000; /* end of 128K RAM on AHB bus*/ /* Generate a link error if heap and stack don't fit into RAM */ -_Min_Heap_Size = 0; /* required amount of heap */ -_Min_Stack_Size = 0x1000; /* required amount of stack */ +_Min_Heap_Size = 0x2000; /* required amount of heap */ +_Min_Stack_Size = 0x2000; /* required amount of stack */ /* Specify the memory areas */ MEMORY diff --git a/lib/src/stm32f4/CPU/syscalls.c b/lib/src/stm32f4/CPU/syscalls.c --- a/lib/src/stm32f4/CPU/syscalls.c +++ b/lib/src/stm32f4/CPU/syscalls.c @@ -10,6 +10,7 @@ #include #include #include +#include #undef errno @@ -29,7 +30,13 @@ char **environ = __env; int _exit() { - while(1); + while(1) + { + delay_100us(10000); + gpioset(LED2); + delay_100us(10000); + gpioclr(LED2); + } } int _close(int file) @@ -48,7 +55,7 @@ int _write(int file, char *ptr, int len) { if(__opnfiles__[file]->ops->write(__opnfiles__[file],ptr,1,len)) return len; } - return 0; + return len; } int _execve(char *name, char **argv, char **env) { @@ -139,8 +146,15 @@ caddr_t _sbrk(int incr) { } prev_heap_end = heap_end; if (heap_end + incr > stack_ptr) { - _write (1, "Heap and stack collision\n", 25); - abort (); + printf("Heap and stack collision\n"); + //abort (); + while(1) + { + delay_100us(10000); + gpioset(LED2); + delay_100us(10000); + gpioclr(LED2); + } } heap_end += incr; return (caddr_t) prev_heap_end; @@ -220,8 +234,15 @@ caddr_t _sbrk_r (struct _reent *r, int i } prev_heap_end = heap_end; if (heap_end + incr > stack_ptr) { - _write (1, "Heap and stack collision\n", 25); - abort (); + printf( "Heap and stack collision\n"); + //abort (); + while(1) + { + delay_100us(10000); + gpioset(LED2); + delay_100us(10000); + gpioclr(LED2); + } } heap_end += incr; return (caddr_t) prev_heap_end; diff --git a/mkspecs/common/arm-none-eabi.conf b/mkspecs/common/arm-none-eabi.conf --- a/mkspecs/common/arm-none-eabi.conf +++ b/mkspecs/common/arm-none-eabi.conf @@ -4,11 +4,11 @@ CONFIG += QMAKE_CC = arm-none-eabi-gcc -QMAKE_CFLAGS += +QMAKE_CFLAGS += QMAKE_CFLAGS_DEPS += -M QMAKE_CFLAGS_WARN_ON += -Wall QMAKE_CFLAGS_WARN_OFF += -w -QMAKE_CFLAGS_RELEASE += -O2 +QMAKE_CFLAGS_RELEASE += -O3 QMAKE_CFLAGS_DEBUG += -g -O0 QMAKE_CXX = arm-none-eabi-g++ @@ -28,7 +28,7 @@ QMAKE_LINK_SHLIB = arm-none-eabi-gcc QMAKE_LINK_C = arm-none-eabi-gcc QMAKE_LINK_C_SHLIB = arm-none-eabi-gcc QMAKE_LFLAGS += -QMAKE_LFLAGS_RELEASE += +QMAKE_LFLAGS_RELEASE += -O3 QMAKE_LFLAGS_DEBUG += QMAKE_LFLAGS_APP += QMAKE_LFLAGS_SHLIB += diff --git a/mkspecs/common/simulator.conf b/mkspecs/common/simulator.conf new file mode 100644 --- /dev/null +++ b/mkspecs/common/simulator.conf @@ -0,0 +1,41 @@ +# +# qmake configuration for simulator +# + +CONFIG += +QMAKE_CC = gcc +QMAKE_CFLAGS += -g -O0 +QMAKE_CFLAGS_DEPS += -M +QMAKE_CFLAGS_WARN_ON += -Wall +QMAKE_CFLAGS_WARN_OFF += -w +QMAKE_CFLAGS_RELEASE += -O2 +QMAKE_CFLAGS_DEBUG += + +QMAKE_CXX = g++ +QMAKE_CXXFLAGS += $$QMAKE_CFLAGS s +QMAKE_CXXFLAGS_DEPS += $$QMAKE_CFLAGS_DEPS +QMAKE_CXXFLAGS_WARN_ON += $$QMAKE_CFLAGS_WARN_ON +QMAKE_CXXFLAGS_WARN_OFF += $$QMAKE_CFLAGS_WARN_OFF +QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_RELEASE +QMAKE_CXXFLAGS_DEBUG += $$QMAKE_CFLAGS_DEBUG +QMAKE_CXXFLAGS_SHLIB += $$QMAKE_CFLAGS_SHLIB +QMAKE_CXXFLAGS_STATIC_LIB += $$QMAKE_CFLAGS_STATIC_LIB +QMAKE_CXXFLAGS_YACC += $$QMAKE_CFLAGS_YACC +QMAKE_CXXFLAGS_HIDESYMS += $$QMAKE_CFLAGS_HIDESYMS + +QMAKE_LINK = gcc +QMAKE_LINK_SHLIB = gcc +QMAKE_LINK_C = gcc +QMAKE_LINK_C_SHLIB = gcc +QMAKE_LFLAGS += -g -O0 +QMAKE_LFLAGS_RELEASE += +QMAKE_LFLAGS_DEBUG += +QMAKE_LFLAGS_APP += +QMAKE_LFLAGS_SHLIB += +QMAKE_LFLAGS_PLUGIN += $$QMAKE_LFLAGS_SHLIB +QMAKE_LFLAGS_THREAD += + +QMAKE_AR = ar -ru +QMAKE_LIB = ar -ru +QMAKE_RANLIB = + diff --git a/mkspecs/features/simulator/cpu.pri b/mkspecs/features/simulator/cpu.pri new file mode 100644 --- /dev/null +++ b/mkspecs/features/simulator/cpu.pri @@ -0,0 +1,16 @@ + + +LIBS += -L$$[QT_INSTALL_LIBS]/$$UCMODEL +LIBS += -lcpu + + + + + + + + + + + + diff --git a/mkspecs/features/simulator/startup.c b/mkspecs/features/simulator/startup.c new file mode 100644 --- /dev/null +++ b/mkspecs/features/simulator/startup.c @@ -0,0 +1,7 @@ + + +int main(void) +{ + bsp_init(); + libuc2_main_task(); +} diff --git a/mkspecs/simulator/qmake.conf b/mkspecs/simulator/qmake.conf new file mode 100644 --- /dev/null +++ b/mkspecs/simulator/qmake.conf @@ -0,0 +1,57 @@ +# +# qmake configuration for stm32f4 +# +# + + +isEmpty(_simulator_conf){ +_simulator_conf="oneshot" + +QMAKE_CFLAGS= -std=c99 + +include(../common/simulator.conf) + +DEFINES += \"assert_param(expr)=((void)0)\" +INCLUDEPATH += $$PWD /usr/include/SDL + +DEFINES += BSP="\"\\\"$$BSP"\\\"\" + +CONFIG += cpu + +contains( TEMPLATE, app ) { + OBJECTS_DIR=obj-$$UCMODEL + DESTDIR=bin-$$UCMODEL + LIBS += -L$$[QT_INSTALL_PREFIX]/bsp/lib/$$BSP + LIBS += -lbsp -lSDLCD -lSDL -lz -lm + SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/simulator/startup.c + SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/simulator/fs.c + + + INCLUDEPATH+= $$[QT_INSTALL_PREFIX]/bsp/includes/$$BSP + +} + +contains( TEMPLATE, lib ) { + OBJECTS_DIR=obj-$$UCMODEL + DESTDIR=bin-$$UCMODEL + CONFIG+=staticlib +} + +include(../common/libuc2libs.conf) + +} + + + + + + + + + + + + + + + diff --git a/mkspecs/simulator/qplatformdefs.h b/mkspecs/simulator/qplatformdefs.h new file mode 100644 --- /dev/null +++ b/mkspecs/simulator/qplatformdefs.h @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the qmake spec of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//#include "../linux-g++/qplatformdefs.h" diff --git a/mkspecs/stm32f4/qmake.conf b/mkspecs/stm32f4/qmake.conf --- a/mkspecs/stm32f4/qmake.conf +++ b/mkspecs/stm32f4/qmake.conf @@ -23,8 +23,8 @@ DEFINES += BSP="\"\\\"$$BSP"\\\"\" CONFIG += cpu contains( TEMPLATE, app ) { - OBJECTS_DIR=obj - DESTDIR=bin + OBJECTS_DIR=obj-$$UCMODEL + DESTDIR=bin-$$UCMODEL unix:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" && arm-none-eabi-objcopy -O binary "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin && python $$[QT_INSTALL_BINS]/dfu.py -b 0x08000000:"$$DESTDIR/"$(QMAKE_TARGET).bin " $$DESTDIR/"$(QMAKE_TARGET).dfu" win32:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(DESTDIR_TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" && arm-none-eabi-objcopy -O binary "$(DESTDIR_TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin" @@ -46,12 +46,14 @@ contains( TEMPLATE, app ) { stflash.target = stflash stflash.commands = cd $$DESTDIR && sudo st-flash write $(QMAKE_TARGET).bin 0x08000000 dfu.target = dfu - dfu.commands = cd $$DESTDIR && sudo dfu-util d 0483:df11 -c 1 -i 0 -a 0 -s 0x08000000 -D $(QMAKE_TARGET).bin 0x08000000 + dfu.commands = cd $$DESTDIR && dfu-util d 0483:df11 -c 1 -i 0 -a 0 -s 0x08000000 -D $(QMAKE_TARGET).bin 0x08000000 QMAKE_EXTRA_TARGETS += stflash dfu } contains( TEMPLATE, lib ) { CONFIG+=staticlib + OBJECTS_DIR=obj-$$UCMODEL + DESTDIR=bin-$$UCMODEL message( "You can only build static library for stm32f4" ) }