void main() { Proc_PID pid; int i; /* * Initialize variables specific to a given kernel. * IMPORTANT: Only variable assignments and nothing else can be * done in this routine. */ Main_InitVars(); /* * Initialize machine dependent info. MUST BE CALLED HERE!!!. */ Mach_Init(); Sync_Init(); /* * Initialize the debugger. */ Dbg_Init(); /* * Initialize the system module, particularly the fact that there is an * implicit DISABLE_INTR on every processor. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Sys_Init().\n"); } Sys_Init(); /* * Now allow memory to be allocated by the "Vm_BootAlloc" call. Memory * can be allocated by this method until "Vm_Init" is called. After this * then the normal memory allocator must be used. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Vm_BootInit().\n"); } Vm_BootInit(); /* * Initialize all devices. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Dev_Init().\n"); } Dev_Init(); /* * Initialize the mappings of keys to call dump routines. * Must be after Dev_Init. */ if (main_DoDumpInit) { if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Dump_Init().\n"); } Dump_Init(); } /* * Initialize the timer, signal, process, scheduling and synchronization * modules' data structures. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Proc_Init().\n"); } Proc_Init(); if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Sync_LockStatInit().\n"); } Sync_LockStatInit(); if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Timer_Init().\n"); } Timer_Init(); if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Sig_Init().\n"); } Sig_Init(); if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Sched_Init().\n"); } Sched_Init(); /* * Sys_Printfs are not allowed before this point. */ main_PanicOK++; printf("Sprite kernel: %s\n", SpriteVersion()); /* * Set up bins for the memory allocator. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Fs_Bin\n"); } Fs_Bin(); if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Net_Bin\n"); } Net_Bin(); /* * Initialize virtual memory. After this point must use the normal * memory allocator to allocate memory. If you use Vm_BootAlloc then * will get a panic into the debugger. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Vm_Init\n"); } Vm_Init(); /* * malloc can be called from this point on. */ /* * Initialize the main process. Must be called before any new * processes are created. * Dependencies: Proc_InitTable, Sched_Init, Vm_Init, Mem_Init */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Proc_InitMainProc\n"); } Proc_InitMainProc(); /* * Initialize the network and the routes. It would be nice if we * could call Net_Init earlier so that we can use the debugger earlier * but we must call Vm_Init first. VM could be changed so that we * could move the call earlier however. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Net_Init\n"); } Net_Init(); if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Net_RouteInit\n"); } Net_RouteInit(); /* * Enable server process manager. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Proc_ServerInit\n"); } Proc_ServerInit(); /* * Initialize the recovery module. Do before Rpc and after Vm_Init. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Recov_Init\n"); } Recov_Init(); /* * Initialize the data structures for the Rpc system. This uses * Vm_RawAlloc to so it must be called after Vm_Init. * Dependencies: Timer_Init, Vm_Init, Net_Init, Recov_Init */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Rpc_Init\n"); } Rpc_Init(); /* * Configure devices that may or may not exist. This needs to be * done after Proc_InitMainProc because the initialization routines * use SetJump which uses the proc table entry for the main process. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Dev_Config\n"); } Dev_Config(); /* * Initialize profiling after the timer and vm stuff is set up. * Dependencies: Timer_Init, Vm_Init */ if (main_DoProf) { Prof_Init(); } /* * Allow interrupts from now on. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Enabling interrupts\n"); } ENABLE_INTR(); if (main_Debug) { DBG_CALL; } /* * Sleep for a few seconds to calibrate the idle time ticks. */ Sched_TimeTicks(); /* * Start profiling, if desired. */ if (main_DoProf) { (void) Prof_Start(); } /* * Do an initial RPC to get a boot timestamp. This allows * servers to detect when we crash and reboot. This will set the * system clock too, although rdate is usually done from user level later. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Call Rpc_Start\n"); } Rpc_Start(); /* * Initialize the file system. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Call Fs_Init\n"); } Fs_Init(); /* * Before starting up any more processes get a current directory * for the main process. Subsequent new procs will inherit it. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Call Fs_ProcInit\n"); } Fs_ProcInit(); if (main_PrintInitRoutines) { Mach_MonPrintf("Bunch of call funcs\n"); } /* * Start the clock daemon and the routine that opens up the swap directory. */ Proc_CallFunc(Vm_Clock, (ClientData) NIL, 0); Proc_CallFunc(Vm_OpenSwapDirectory, (ClientData) NIL, 0); /* * Start the process that synchronizes the filesystem caches * with the data kept on disk. */ Proc_CallFunc(Fsutil_SyncProc, (ClientData) NIL, 0); /* * Create a few RPC server processes and the Rpc_Daemon process which * will create more server processes if needed. */ if (main_NumRpcServers > 0) { for (i=0 ; i<main_NumRpcServers ; i++) { (void) Rpc_CreateServer((int *) &pid); } } (void) Proc_NewProc((Address) Rpc_Daemon, PROC_KERNEL, FALSE, &pid, "Rpc_Daemon", FALSE); if (main_PrintInitRoutines) { Mach_MonPrintf("Creating Proc server procs\n"); } /* * Create processes to execute functions. */ (void) Proc_ServerProcCreate(FSCACHE_MAX_CLEANER_PROCS + VM_MAX_PAGE_OUT_PROCS); /* * Create a recovery process to monitor other hosts. Can't use * Proc_CallFunc's to do this because they can be used up waiting * for page faults against down servers. (Alternatively the VM * code could be fixed up to retry page faults later instead of * letting the Proc_ServerProc wait for recovery.) */ (void) Proc_NewProc((Address) Recov_Proc, PROC_KERNEL, FALSE, &pid, "Recov_Proc", FALSE); /* * Set up process migration recovery management. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Proc_MigInit\n"); } Proc_MigInit(); /* * Call the routine to start test kernel processes. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Calling Main_HookRoutine\n"); } Main_HookRoutine(); /* * Print out the amount of memory used. */ printf("MEMORY %d bytes allocated for kernel\n", vmMemEnd - mach_KernStart); /* * Start up the first user process. */ if (main_PrintInitRoutines) { Mach_MonPrintf("Creating Init\n"); } (void) Proc_NewProc((Address) Init, PROC_KERNEL, FALSE, &pid, "Init", FALSE); (void) Sync_WaitTime(time_OneYear); printf("Main exiting\n"); Proc_Exit(0); }
int main(void) { char buf[22]; int len; PLLCFG = (1<<5) | (4<<0); //PLL MSEL=0x4 (+1), PSEL=0x1 (/2) so 11.0592*5 = 55.296MHz, Fcco = (2x55.296)*2 = 221MHz which is within 156 to 320MHz PLLCON = 0x01; PLLFEED = 0xaa; PLLFEED = 0x55; // Feed complete while(!(PLLSTAT & (1<<10))); // Wait for PLL to lock PLLCON = 0x03; PLLFEED = 0xaa; PLLFEED = 0x55; // Feed complete VPBDIV = 0x01; // APB runs at the same frequency as the CPU (55.296MHz) MAMTIM = 0x03; // 3 cycles flash access recommended >40MHz MAMCR = 0x02; // Fully enable memory accelerator Sched_Init(); IO_Init(); Set_Heater(0); Set_Fan(0); Serial_Init(); I2C_Init(); EEPROM_Init(); NV_Init(); if( NV_GetConfig(REFLOW_BEEP_DONE_LEN) == 255 ) { NV_SetConfig(REFLOW_BEEP_DONE_LEN, 10); // Default 1 second beep length } printf("\nInitializing improved reflow oven..."); LCD_Init(); LCD_BMPDisplay(logobmp,0,0); // Setup watchdog WDTC = PCLKFREQ / 3; // Some margin (PCLKFREQ/4 would be exactly the period the WD is fed by sleep_work) WDMOD = 0x03; // Enable WDFEED = 0xaa; WDFEED = 0x55; uint8_t resetreason = RSIR; RSIR = 0x0f; // Clear it out printf("\nReset reason(s): %s%s%s%s", (resetreason&(1<<0))?"[POR]":"", (resetreason&(1<<1))?"[EXTR]":"", (resetreason&(1<<2))?"[WDTR]":"", (resetreason&(1<<3))?"[BODR]":""); // Request part number command[0] = IAP_READ_PART; iap_entry(command, result); const char* partstrptr = NULL; for(int i=0; i<NUM_PARTS; i++) { if(result[1] == partmap[i].id) { partstrptr = partmap[i].name; break; } } // Read part revision partrev=*(uint8_t*)PART_REV_ADDR; if(partrev==0 || partrev > 0x1a) { partrev = '-'; } else { partrev += 'A' - 1; } len = snprintf(buf,sizeof(buf),"%s rev %c",partstrptr,partrev); LCD_disp_str((uint8_t*)buf, len, 0, 64-6, FONT6X6); printf("\nRunning on an %s", buf); LCD_FB_Update(); Keypad_Init(); Buzzer_Init(); ADC_Init(); RTC_Init(); OneWire_Init(); Reflow_Init(); Sched_SetWorkfunc( MAIN_WORK, Main_Work ); Sched_SetState( MAIN_WORK, 1, TICKS_SECS( 2 ) ); // Enable in 2 seconds Buzzer_Beep( BUZZ_1KHZ, 255, TICKS_MS(100) ); while(1) { int32_t sleeptime; sleeptime=Sched_Do( 0 ); // No fast-forward support //printf("\n%d ticks 'til next activity"),sleeptime); } return 0; }