From 9c2cdd64cfd118965b7cd44f335b37d5e7b1b2e0 Mon Sep 17 00:00:00 2001 From: marqs Date: Wed, 25 May 2016 00:04:46 +0300 Subject: [PATCH] Some codebase reordering --- ossc.workspace | 4 +- software/ossc_sw.project | 7 + software/sys_controller/Makefile | 5 +- software/sys_controller/av_controller.c | 142 +----------------- software/sys_controller/memory/flash.c | 111 ++++++++++++++ software/sys_controller/memory/flash.h | 42 ++++++ software/sys_controller/memory/sdcard.c | 66 ++++++++ software/sys_controller/memory/sdcard.h | 34 +++++ .../sys_controller/{ => ossc}/sysconfig.h | 0 software/sys_controller_bsp/settings.bsp | 6 +- 10 files changed, 271 insertions(+), 146 deletions(-) create mode 100644 software/sys_controller/memory/flash.c create mode 100644 software/sys_controller/memory/flash.h create mode 100644 software/sys_controller/memory/sdcard.c create mode 100644 software/sys_controller/memory/sdcard.h rename software/sys_controller/{ => ossc}/sysconfig.h (100%) diff --git a/ossc.workspace b/ossc.workspace index e9773ea..17587fc 100644 --- a/ossc.workspace +++ b/ossc.workspace @@ -5,14 +5,14 @@ - + - + diff --git a/software/ossc_sw.project b/software/ossc_sw.project index 8a7ca77..5e35c03 100644 --- a/software/ossc_sw.project +++ b/software/ossc_sw.project @@ -60,6 +60,13 @@ + + + + + + + diff --git a/software/sys_controller/Makefile b/software/sys_controller/Makefile index 66e5d99..c5136c6 100644 --- a/software/sys_controller/Makefile +++ b/software/sys_controller/Makefile @@ -153,6 +153,8 @@ C_SRCS += tvp7002/tvp7002.c C_SRCS += tvp7002/video_modes.c C_SRCS += ths7353/ths7353.c C_SRCS += spi_charlcd/lcd.c +C_SRCS += memory/flash.c +C_SRCS += memory/sdcard.c CXX_SRCS := ASM_SRCS := @@ -192,9 +194,10 @@ BSP_ROOT_DIR := ../sys_controller_bsp/ # List of application specific include directories, library directories and library names APP_INCLUDE_DIRS += it6613 APP_INCLUDE_DIRS += tvp7002 -APP_INCLUDE_DIRS += ./ APP_INCLUDE_DIRS += ths7353 APP_INCLUDE_DIRS += spi_charlcd +APP_INCLUDE_DIRS += memory +APP_INCLUDE_DIRS += ossc APP_LIBRARY_DIRS := APP_LIBRARY_NAMES := diff --git a/software/sys_controller/av_controller.c b/software/sys_controller/av_controller.c index 8493863..22836fd 100644 --- a/software/sys_controller/av_controller.c +++ b/software/sys_controller/av_controller.c @@ -22,13 +22,13 @@ #include "system.h" #include "string.h" #include "altera_avalon_pio_regs.h" -#include "Altera_UP_SD_Card_Avalon_Interface_mod.h" -#include "altera_epcq_controller_mod.h" #include "i2c_opencores.h" #include "tvp7002.h" #include "ths7353.h" #include "video_modes.h" #include "lcd.h" +#include "flash.h" +#include "sdcard.h" #include "sysconfig.h" #include "it6613.h" #include "it6613_sys.h" @@ -281,10 +281,6 @@ typedef enum { extern mode_data_t video_modes[]; extern ypbpr_to_rgb_csc_t csc_coeffs[]; -extern alt_epcq_controller_dev epcq_controller_0; - -alt_epcq_controller_dev *epcq_controller_dev; -alt_up_sd_card_dev *sdcard_dev; alt_u8 target_typemask; alt_u8 target_type; @@ -292,146 +288,12 @@ alt_u8 stable_frames; char row1[LCD_ROW_LEN+1], row2[LCD_ROW_LEN+1], menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1]; -// EPCS16 pagesize is 256 bytes -// Flash is split 50-50 to FW and userdata, 1MB each -#define PAGESIZE 256 -#define PAGES_PER_SECTOR 256 -#define USERDATA_OFFSET 0x100000 -#define USERDATA_MAX_SIZE 0x1000 //4KB should be enough - -// SD controller uses 512-byte chunks -#define SD_BUFFER_SIZE 512 - -short int sd_fw_handle; - alt_u8 menu_active, menu_page; alt_u32 remote_code; alt_u8 remote_rpt, remote_rpt_prev; alt_u32 btn_code, btn_code_prev; avinput_t target_mode; -int check_flash() -{ - epcq_controller_dev = &epcq_controller_0; - - if ((epcq_controller_dev == NULL) || !(epcq_controller_dev->is_epcs && (epcq_controller_dev->page_size == PAGESIZE))) - return -1; - - //printf("Flash size in bytes: %d\nSector size: %d (%d pages)\nPage size: %d\n", epcq_controller_dev->size_in_bytes, epcq_controller_dev->sector_size, epcq_controller_dev->sector_size/epcq_controller_dev->page_size, epcq_controller_dev->page_size); - - return 0; -} - -int read_flash(alt_u32 offset, alt_u32 length, alt_u8 *dstbuf) -{ - int retval, i; - - retval = alt_epcq_controller_read(&epcq_controller_dev->dev, offset, dstbuf, length); - if (retval != 0) - return -1; - - for (i=0; i> 24; - - return 0; -} - -int write_flash_page(alt_u8 *pagedata, alt_u32 length, alt_u32 pagenum) -{ - int retval, i; - - if ((pagenum % PAGES_PER_SECTOR) == 0) { - printf("Erasing sector %u\n", (unsigned)(pagenum/PAGES_PER_SECTOR)); - retval = alt_epcq_controller_erase_block(&epcq_controller_dev->dev, pagenum*PAGESIZE); - - if (retval != 0) { - strncpy(menu_row1, "Flash erase", LCD_ROW_LEN+1); - sniprintf(menu_row1, LCD_ROW_LEN+1, "error %d", retval); - menu_row2[0] = '\0'; - printf("Flash erase error, sector %u\nRetval %d\n", (unsigned)(pagenum/PAGES_PER_SECTOR), retval); - return -200; - } - } - - // Bit-reverse bytes for flash - for (i=0; i> 24; - - retval = alt_epcq_controller_write_block(&epcq_controller_dev->dev, (pagenum/PAGES_PER_SECTOR)*PAGES_PER_SECTOR*PAGESIZE, pagenum*PAGESIZE, pagedata, length); - - if (retval != 0) { - strncpy(menu_row1, "Flash write", LCD_ROW_LEN+1); - strncpy(menu_row2, "error", LCD_ROW_LEN+1); - printf("Flash write error, page %u\nRetval %d\n", (unsigned)pagenum, retval); - return -201; - } - - return retval; -} - -int verify_flash(alt_u32 offset, alt_u32 length, alt_u32 golden_crc, alt_u8 *tmpbuf) -{ - alt_u32 crcval=0, i, bytes_to_read; - int retval; - - for (i=0; i 512)) { - sniprintf(menu_row1, LCD_ROW_LEN+1, "Invalid read cmd"); - menu_row2[0] = '\0'; - return -1; - } - - if (!Read_Sector_Data((offset/SD_BUFFER_SIZE), 0)) { - sniprintf(menu_row1, LCD_ROW_LEN+1, "SD read failure"); - menu_row2[0] = '\0'; - return -2; - } - - // Copy buffer to SW - for (i=0; ibase, i); - *((alt_u32*)(dstbuf+i)) = tmp; - } - - return 0; -} - -int check_sdcard(alt_u8 *databuf) -{ - sdcard_dev = alt_up_sd_card_open_dev(ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_NAME); - - if ((sdcard_dev == NULL) || !alt_up_sd_card_is_Present()) { - sniprintf(menu_row1, LCD_ROW_LEN+1, "No SD card det."); - menu_row2[0] = '\0'; - return 1; - } - - return read_sd_block(0, 512, databuf); -} - int check_fw_header(alt_u8 *databuf, fw_hdr *hdr) { alt_u32 crcval, tmp; diff --git a/software/sys_controller/memory/flash.c b/software/sys_controller/memory/flash.c new file mode 100644 index 0000000..427d589 --- /dev/null +++ b/software/sys_controller/memory/flash.c @@ -0,0 +1,111 @@ +// +// Copyright (C) 2015-2016 Markus Hiienkari +// +// This file is part of Open Source Scan Converter project. +// +// 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, see . +// + +#include +#include "flash.h" +#include "lcd.h" + +extern alt_epcq_controller_dev epcq_controller_0; +extern char menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1]; + +alt_epcq_controller_dev *epcq_controller_dev; + + +int check_flash() +{ + epcq_controller_dev = &epcq_controller_0; + + if ((epcq_controller_dev == NULL) || !(epcq_controller_dev->is_epcs && (epcq_controller_dev->page_size == PAGESIZE))) + return -1; + + //printf("Flash size in bytes: %d\nSector size: %d (%d pages)\nPage size: %d\n", epcq_controller_dev->size_in_bytes, epcq_controller_dev->sector_size, epcq_controller_dev->sector_size/epcq_controller_dev->page_size, epcq_controller_dev->page_size); + + return 0; +} + +int read_flash(alt_u32 offset, alt_u32 length, alt_u8 *dstbuf) +{ + int retval, i; + + retval = alt_epcq_controller_read(&epcq_controller_dev->dev, offset, dstbuf, length); + if (retval != 0) + return -1; + + for (i=0; i> 24; + + return 0; +} + +int write_flash_page(alt_u8 *pagedata, alt_u32 length, alt_u32 pagenum) +{ + int retval, i; + + if ((pagenum % PAGES_PER_SECTOR) == 0) { + printf("Erasing sector %u\n", (unsigned)(pagenum/PAGES_PER_SECTOR)); + retval = alt_epcq_controller_erase_block(&epcq_controller_dev->dev, pagenum*PAGESIZE); + + if (retval != 0) { + strncpy(menu_row1, "Flash erase", LCD_ROW_LEN+1); + sniprintf(menu_row1, LCD_ROW_LEN+1, "error %d", retval); + menu_row2[0] = '\0'; + printf("Flash erase error, sector %u\nRetval %d\n", (unsigned)(pagenum/PAGES_PER_SECTOR), retval); + return -200; + } + } + + // Bit-reverse bytes for flash + for (i=0; i> 24; + + retval = alt_epcq_controller_write_block(&epcq_controller_dev->dev, (pagenum/PAGES_PER_SECTOR)*PAGES_PER_SECTOR*PAGESIZE, pagenum*PAGESIZE, pagedata, length); + + if (retval != 0) { + strncpy(menu_row1, "Flash write", LCD_ROW_LEN+1); + strncpy(menu_row2, "error", LCD_ROW_LEN+1); + printf("Flash write error, page %u\nRetval %d\n", (unsigned)pagenum, retval); + return -201; + } + + return retval; +} + +int verify_flash(alt_u32 offset, alt_u32 length, alt_u32 golden_crc, alt_u8 *tmpbuf) +{ + alt_u32 crcval=0, i, bytes_to_read; + int retval; + + for (i=0; i +// +// This file is part of Open Source Scan Converter project. +// +// 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, see . +// + +#ifndef FLASH_H_ +#define FLASH_H_ + +#include "alt_types.h" +#include "sysconfig.h" +#include "altera_epcq_controller_mod.h" + +// EPCS16 pagesize is 256 bytes +// Flash is split 50-50 to FW and userdata, 1MB each +#define PAGESIZE 256 +#define PAGES_PER_SECTOR 256 +#define USERDATA_OFFSET 0x100000 +#define USERDATA_MAX_SIZE 0x1000 //4KB should be enough + +int check_flash(); + +int read_flash(alt_u32 offset, alt_u32 length, alt_u8 *dstbuf); + +int write_flash_page(alt_u8 *pagedata, alt_u32 length, alt_u32 pagenum); + +int verify_flash(alt_u32 offset, alt_u32 length, alt_u32 golden_crc, alt_u8 *tmpbuf); + +#endif /* FLASH_H_ */ diff --git a/software/sys_controller/memory/sdcard.c b/software/sys_controller/memory/sdcard.c new file mode 100644 index 0000000..63f1f4a --- /dev/null +++ b/software/sys_controller/memory/sdcard.c @@ -0,0 +1,66 @@ +// +// Copyright (C) 2015-2016 Markus Hiienkari +// +// This file is part of Open Source Scan Converter project. +// +// 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, see . +// + +#include +#include "sdcard.h" +#include "lcd.h" + +extern char menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1]; + +alt_up_sd_card_dev *sdcard_dev; + + +int read_sd_block(alt_u32 offset, alt_u32 size, alt_u8 *dstbuf) +{ + int i; + alt_u32 tmp; + + if ((offset % SD_BUFFER_SIZE) || (size > 512)) { + sniprintf(menu_row1, LCD_ROW_LEN+1, "Invalid read cmd"); + menu_row2[0] = '\0'; + return -1; + } + + if (!Read_Sector_Data((offset/SD_BUFFER_SIZE), 0)) { + sniprintf(menu_row1, LCD_ROW_LEN+1, "SD read failure"); + menu_row2[0] = '\0'; + return -2; + } + + // Copy buffer to SW + for (i=0; ibase, i); + *((alt_u32*)(dstbuf+i)) = tmp; + } + + return 0; +} + +int check_sdcard(alt_u8 *databuf) +{ + sdcard_dev = alt_up_sd_card_open_dev(ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_NAME); + + if ((sdcard_dev == NULL) || !alt_up_sd_card_is_Present()) { + sniprintf(menu_row1, LCD_ROW_LEN+1, "No SD card det."); + menu_row2[0] = '\0'; + return 1; + } + + return read_sd_block(0, 512, databuf); +} diff --git a/software/sys_controller/memory/sdcard.h b/software/sys_controller/memory/sdcard.h new file mode 100644 index 0000000..708732c --- /dev/null +++ b/software/sys_controller/memory/sdcard.h @@ -0,0 +1,34 @@ +// +// Copyright (C) 2015-2016 Markus Hiienkari +// +// This file is part of Open Source Scan Converter project. +// +// 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, see . +// + +#ifndef SDCARD_H_ +#define SDCARD_H_ + +#include "alt_types.h" +#include "sysconfig.h" +#include "Altera_UP_SD_Card_Avalon_Interface_mod.h" + +// SD controller uses 512-byte chunks +#define SD_BUFFER_SIZE 512 + +int read_sd_block(alt_u32 offset, alt_u32 size, alt_u8 *dstbuf); + +int check_sdcard(alt_u8 *databuf); + +#endif /* SDCARD_H_ */ diff --git a/software/sys_controller/sysconfig.h b/software/sys_controller/ossc/sysconfig.h similarity index 100% rename from software/sys_controller/sysconfig.h rename to software/sys_controller/ossc/sysconfig.h diff --git a/software/sys_controller_bsp/settings.bsp b/software/sys_controller_bsp/settings.bsp index 4291c0a..4e7fce4 100644 --- a/software/sys_controller_bsp/settings.bsp +++ b/software/sys_controller_bsp/settings.bsp @@ -2,9 +2,9 @@ hal default - May 24, 2016 1:04:38 AM - 1464041078241 - /home/markus/Code/ossc/software/sys_controller_bsp + May 24, 2016 11:37:31 PM + 1464122251538 + ./ settings.bsp ../../sys.sopcinfo default