mirror of
https://github.com/marqs85/ossc.git
synced 2026-04-20 13:16:50 +00:00
Some codebase reordering
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// Copyright (C) 2015-2016 Markus Hiienkari <mhiienka@niksula.hut.fi>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include <unistd.h>
|
||||
#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<length; i++)
|
||||
dstbuf[i] = ALT_CI_NIOS_CUSTOM_INSTR_BITSWAP_0(dstbuf[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<length; i++)
|
||||
pagedata[i] = ALT_CI_NIOS_CUSTOM_INSTR_BITSWAP_0(pagedata[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<length; i=i+PAGESIZE) {
|
||||
bytes_to_read = ((length-i < PAGESIZE) ? (length-i) : PAGESIZE);
|
||||
|
||||
retval = read_flash(i, bytes_to_read, tmpbuf);
|
||||
if (retval != 0)
|
||||
return -202;
|
||||
|
||||
crcval = crcCI(tmpbuf, bytes_to_read, (i==0));
|
||||
}
|
||||
|
||||
if (crcval != golden_crc) {
|
||||
sniprintf(menu_row1, LCD_ROW_LEN+1, "Flash verif fail");
|
||||
menu_row2[0] = '\0';
|
||||
return -203;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// Copyright (C) 2015-2016 Markus Hiienkari <mhiienka@niksula.hut.fi>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#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_ */
|
||||
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// Copyright (C) 2015-2016 Markus Hiienkari <mhiienka@niksula.hut.fi>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include <io.h>
|
||||
#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; i<size; i=i+4) {
|
||||
tmp = IORD_32DIRECT(sdcard_dev->base, 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);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// Copyright (C) 2015-2016 Markus Hiienkari <mhiienka@niksula.hut.fi>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#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_ */
|
||||
Reference in New Issue
Block a user