Skip to content

Instantly share code, notes, and snippets.

@mindjiver
Created January 18, 2012 20:56
Show Gist options
  • Select an option

  • Save mindjiver/1635607 to your computer and use it in GitHub Desktop.

Select an option

Save mindjiver/1635607 to your computer and use it in GitHub Desktop.
TB reading
#define TBU_USER 0x10C /* Time Base Upper User for reading */
#define TBL_USER 0x10D /* Time Base Lower User for reading */
#define TBU_SUPER 0x11C /* Time Base Upper Supervisor for writing */
#define TBL_SUPER 0x11D /* Time Base Lower Supervisor for writing */
#define DEC 0x016 /* Decrement */
#define DECAR 0x036 /* Decrement Auto-Reload */
#define TSR 0x150 /* Time Status Register */
#define TCR 0x154 /* Timer Control Register */
#define IVR 0x03F /* Interrupt Vector Prefix Register */
/*
* Decrementer Timer (DEC)
* Fixed Interval Timer (FIT)
* Watch Dog Timer (WD)
*/
void timer(U32 timeout) {
// check status of TSR (Time Status Register) ?
// decrement exception is sent to interrupt mechanism.
// register exception handler for this.
U32 upper = 0x0;
U32 lower = 0x1;
asm("mfspr %0, %1" : "=r" (upper) : "r" (TBU_USER));
asm("mfspr %0, %1" : "=r" (lower) : "r" (TBL_USER));
printf("0x%u%u\n", upper, lower);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment