mirror of
https://git.code.sf.net/p/newrpl/sources
synced 2024-11-16 19:51:25 +01:00
Integrated clock speed management with usb driver
This commit is contained in:
parent
a1c16edda9
commit
01188420bb
9 changed files with 52 additions and 11 deletions
|
@ -122,13 +122,13 @@ void busy_handler()
|
|||
}
|
||||
halBusyEvent=-1;
|
||||
if(halFlags&HAL_SLOWLOCK) return;
|
||||
cpu_setspeed(HAL_FASTCLOCK);
|
||||
halCPUFastMode();
|
||||
halFlags|=HAL_FASTMODE;
|
||||
}
|
||||
|
||||
void halInitBusyHandler()
|
||||
{
|
||||
cpu_setspeed(HAL_SLOWCLOCK);
|
||||
halCPUSlowMode();
|
||||
halFlags=(halFlags&~HAL_AUTOOFFTIME)|SET_AUTOOFFTIME(DEFAULT_AUTOOFFTIME); // DEFAULT TO 2 MINUTES
|
||||
halBusyEvent=tmr_eventcreate(&busy_handler,500,0);
|
||||
}
|
||||
|
|
24
firmware/hal_cpu.c
Normal file
24
firmware/hal_cpu.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2014-2015, Claudio Lapilli and the newRPL Team
|
||||
* All rights reserved.
|
||||
* This file is released under the 3-clause BSD license.
|
||||
* See the file LICENSE.txt that shipped with this distribution.
|
||||
*/
|
||||
|
||||
|
||||
#include <newrpl.h>
|
||||
#include <ui.h>
|
||||
#include <libraries.h>
|
||||
|
||||
|
||||
void halCPUSlowMode()
|
||||
{
|
||||
if(usb_isconnected()) cpu_setspeed(HAL_USBCLOCK);
|
||||
else cpu_setspeed(HAL_SLOWCLOCK);
|
||||
}
|
||||
|
||||
void halCPUFastMode()
|
||||
{
|
||||
cpu_setspeed(HAL_FASTCLOCK);
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ BINT halWaitForKey()
|
|||
if(!keymsg) {
|
||||
// FIRST: ENTER LOW SPEED MODE
|
||||
if(halFlags&HAL_FASTMODE) {
|
||||
cpu_setspeed(HAL_SLOWCLOCK);
|
||||
halCPUSlowMode();
|
||||
halFlags&=~HAL_FASTMODE;
|
||||
}
|
||||
if(halFlags&HAL_HOURGLASS) {
|
||||
|
@ -88,7 +88,7 @@ BINT halWaitForKeyTimeout(BINT timeoutms)
|
|||
if(!keymsg) {
|
||||
// FIRST: ENTER LOW SPEED MODE
|
||||
if(halFlags&HAL_FASTMODE) {
|
||||
cpu_setspeed(HAL_SLOWCLOCK);
|
||||
halCPUSlowMode();
|
||||
halFlags&=~HAL_FASTMODE;
|
||||
}
|
||||
if(halFlags&HAL_HOURGLASS) {
|
||||
|
|
|
@ -60,7 +60,8 @@
|
|||
#define CLK_192MHZ 0x58011
|
||||
|
||||
// DEFAULT CLOCK SPEEDS
|
||||
#define HAL_SLOWCLOCK 48000000
|
||||
#define HAL_SLOWCLOCK 6000000
|
||||
#define HAL_USBCLOCK 48000000
|
||||
#define HAL_FASTCLOCK 192000000
|
||||
|
||||
|
||||
|
|
|
@ -1100,6 +1100,13 @@ void cpu_off_die();
|
|||
void cpu_flushwritebuffers();
|
||||
void cpu_flushTLB();
|
||||
|
||||
// LOW-LEVEL DRIVERS - USB
|
||||
int usb_hasdata();
|
||||
int usb_isconnected();
|
||||
int usb_isconfigured();
|
||||
void usb_releasedata();
|
||||
BYTEPTR usb_accessdata(int *blksize);
|
||||
|
||||
|
||||
|
||||
// LOW-LEVEL HARDWARE DRIVERS - KEYBOARD
|
||||
|
@ -1163,6 +1170,8 @@ void halEnterPowerOff();
|
|||
|
||||
void halPreparePowerOff();
|
||||
void halWakeUp();
|
||||
void halCPUSlowMode();
|
||||
void halCPUFastMode();
|
||||
|
||||
|
||||
// TIMER FUNCTIONS
|
||||
|
|
|
@ -672,6 +672,8 @@ void halWarmStart()
|
|||
// TODO: ADD RPL ENGINE CLEANUP HERE BEFORE RESET
|
||||
disable_interrupts();
|
||||
|
||||
usb_shutdown();
|
||||
|
||||
// PUT THE CPU IN A KNOWN SLOW SPEED
|
||||
cpu_setspeed(HAL_SLOWCLOCK);
|
||||
// DISABLE THE MMU
|
||||
|
@ -724,6 +726,8 @@ void halEnterPowerOff()
|
|||
{
|
||||
// TODO: ADD RPL ENGINE CLEANUP HERE BEFORE RESET
|
||||
|
||||
usb_shutdown();
|
||||
|
||||
// FILE SYSTEM SHUTDOWN
|
||||
|
||||
FSShutdown();
|
||||
|
|
|
@ -158,8 +158,7 @@ LCDPTR[0]&=0xFFFFFFFE;
|
|||
// THIS TRIES TO KEEP HCLK AS LOW AS POSSIBLE BUT PCLK ABOVE 20 MHz FOR USB OPERATION
|
||||
|
||||
if(FCLK<=24000000) *HWREG(CLK_REGS,0x14)=0; // SET HCLK=FCLK; PCLK=HCLK;
|
||||
else
|
||||
if(FCLK<=48000000) *HWREG(CLK_REGS,0x14)=1; // SET HCLK=FCLK; PCLK=HCLK/2;
|
||||
else if(FCLK<=48000000) *HWREG(CLK_REGS,0x14)=1; // SET HCLK=FCLK; PCLK=HCLK/2;
|
||||
else if(FCLK<=75000000) *HWREG(CLK_REGS,0x14)=2; // SET HCLK=FCLK/2; PCLK=HCLK;
|
||||
else *HWREG(CLK_REGS,0x14)=3; // SET HCLK=FCLK/2; PCLK=HCLK/2;
|
||||
|
||||
|
@ -189,7 +188,6 @@ return FCLK;
|
|||
}
|
||||
|
||||
|
||||
|
||||
// USER-FRIENDLY VERSION, ENSURE PROPER PLLCON IS USED
|
||||
int cpu_setspeed(int mhz)
|
||||
{
|
||||
|
|
|
@ -383,9 +383,13 @@ WORD __usb_rcvcrc __SYSTEM_GLOBAL__;
|
|||
|
||||
|
||||
//WORD __usb_intdata[1024] __SYSTEM_GLOBAL__;
|
||||
extern int __cpu_getPCLK();
|
||||
|
||||
void usb_hwsetup()
|
||||
{
|
||||
// MAKE SURE WE HAVE PCLK>20 MHz FOR USB COMMUNICATIONS TO WORK
|
||||
if(__cpu_getPCLK()<20000000) cpu_setspeed(HAL_USBCLOCK);
|
||||
|
||||
*CLKCON&=~0x40; // POWER DOWN USB HOST TO MAKE SURE HOST AND DEVICE AREN'T WORKING AT ONCE
|
||||
*CLKCON|=0x80; // POWER UP USB DEVICE
|
||||
|
||||
|
@ -1253,14 +1257,14 @@ int usb_isconfigured()
|
|||
|
||||
|
||||
// HIGH LEVEL FUNCTION TO SEE IF THERE'S ANY DATA FROM THE USB DRIVER
|
||||
int usb_havedata()
|
||||
int usb_hasdata()
|
||||
{
|
||||
if(__usb_drvstatus&USB_STATUS_DATAREADY) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// HIGH LEVEL FUNCTION TO ACCESS A BLOCK OF DATA
|
||||
BYTEPTR usb_accessdata(BINT *blksize)
|
||||
BYTEPTR usb_accessdata(int *blksize)
|
||||
{
|
||||
if(!(__usb_drvstatus&USB_STATUS_DATAREADY)) return 0;
|
||||
if(blksize) *blksize=__usb_rcvpartial;
|
||||
|
|
|
@ -217,7 +217,8 @@ SOURCES +=\
|
|||
newrpl/mul_real_arm.c \
|
||||
newrpl/rng.c \
|
||||
newrpl/solvers.c \
|
||||
firmware/sys/target_50g/usbdriver.c
|
||||
firmware/sys/target_50g/usbdriver.c \
|
||||
firmware/hal_cpu.c
|
||||
|
||||
|
||||
HEADERS += \
|
||||
|
|
Loading…
Reference in a new issue