Better reset control.

This commit is contained in:
sorgelig
2017-06-23 11:22:06 +08:00
parent 7e715ec2f9
commit 296ebe90df
3 changed files with 28 additions and 11 deletions

View File

@@ -595,6 +595,8 @@ int fpga_get_buttons()
void reboot(int cold)
{
sync();
fpga_core_reset(1);
if(cold) writel(0, &reset_regs->tstscratch);
writel(2, &reset_regs->ctrl);
while (1);
@@ -615,6 +617,8 @@ char *getappname()
void app_restart()
{
sync();
fpga_core_reset(1);
char *appname = getappname();
printf("restarting the %s\n", appname);
execve(appname, NULL, NULL);
@@ -623,13 +627,18 @@ void app_restart()
reboot(0);
}
void fpga_core_reset(int run)
void fpga_core_reset(int reset)
{
fpga_gpo_write(run ? fpga_gpo_read() | 0x40000000 : fpga_gpo_read() & ~0x40000000);
uint32_t gpo = fpga_gpo_read() & ~0xC0000000;
fpga_gpo_write(reset ? gpo | 0x40000000 : gpo | 0x80000000);
}
int fpga_ready()
int is_fpga_ready(int quick)
{
if (quick)
{
return (fpga_gpi_read() >= 0);
}
return fpgamgr_test_fpga_ready();
}

View File

@@ -19,11 +19,11 @@ uint32_t fpga_gpi_read();
void fpga_set_led(uint32_t on);
int fpga_get_buttons();
void fpga_core_reset(int run);
void fpga_core_reset(int reset);
void fpga_core_write(uint32_t offset, uint32_t value);
uint32_t fpga_core_read(uint32_t offset);
int fpga_core_id();
int fpga_ready();
int is_fpga_ready(int quick);
int fpga_get_fio_size();
int fpga_get_io_version();

18
main.c
View File

@@ -19,6 +19,7 @@ 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 <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include "string.h"
@@ -110,6 +111,7 @@ int main(int argc, char *argv[])
uint8_t mmc_ok = 0;
fpga_io_init();
fpga_gpo_write(0);
DISKLED_OFF;
@@ -117,6 +119,13 @@ int main(int argc, char *argv[])
iprintf("\nARM Controller by Jakub Bednarski\n\n");
iprintf("Version %s\n\n", version + 5);
if (!is_fpga_ready(1))
{
printf("\nGPI[31]==1. FPGA is uninitialized or incompatible core loaded.\n");
printf("Quitting. Bye bye...\n");
exit(0);
}
FindStorage();
user_io_init();
@@ -125,16 +134,15 @@ int main(int argc, char *argv[])
while(1)
{
//printf("fpga_ready:%d\n", fpga_ready());
if(!fpga_ready())
if(!is_fpga_ready(1))
{
printf("FPGA is not ready. JTAG uploading?\n");
printf("Waiting for FPGA to be ready...\n");
//reset GPO to default value
fpga_gpo_write(0);
//enable reset in advance
fpga_core_reset(1);
while (!fpga_ready())
while (!is_fpga_ready(0))
{
sleep(1);
}