Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 0:6c56fb4bc5f0 1 #include "mbed.h"
nexpaq 0:6c56fb4bc5f0 2
nexpaq 0:6c56fb4bc5f0 3 extern "C" {
nexpaq 0:6c56fb4bc5f0 4 volatile uint32_t msTicks;
nexpaq 0:6c56fb4bc5f0 5
nexpaq 0:6c56fb4bc5f0 6 void SysTick_Handler(void) {
nexpaq 0:6c56fb4bc5f0 7 msTicks++;
nexpaq 0:6c56fb4bc5f0 8 }
nexpaq 0:6c56fb4bc5f0 9
nexpaq 0:6c56fb4bc5f0 10 void Delay(uint32_t dlyTicks) {
nexpaq 0:6c56fb4bc5f0 11 uint32_t curTicks;
nexpaq 0:6c56fb4bc5f0 12
nexpaq 0:6c56fb4bc5f0 13 curTicks = msTicks;
nexpaq 0:6c56fb4bc5f0 14 while ((msTicks - curTicks) < dlyTicks);
nexpaq 0:6c56fb4bc5f0 15 }
nexpaq 0:6c56fb4bc5f0 16 }
nexpaq 0:6c56fb4bc5f0 17
nexpaq 0:6c56fb4bc5f0 18 int main() {
nexpaq 0:6c56fb4bc5f0 19 SysTick_Config(SystemCoreClock / 1000);
nexpaq 0:6c56fb4bc5f0 20
nexpaq 0:6c56fb4bc5f0 21 SIM->SCGC6 |= SIM_SCGC6_PIT_MASK; // Clock PIT
nexpaq 0:6c56fb4bc5f0 22 PIT->MCR = 0; // Enable PIT
nexpaq 0:6c56fb4bc5f0 23
nexpaq 0:6c56fb4bc5f0 24 // Timer 1
nexpaq 0:6c56fb4bc5f0 25 PIT->CHANNEL[1].LDVAL = 0xFFFFFFFF;
nexpaq 0:6c56fb4bc5f0 26 PIT->CHANNEL[1].TCTRL = 0x0; // Disable Interrupts
nexpaq 0:6c56fb4bc5f0 27 PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_CHN_MASK; // Chain to timer 0
nexpaq 0:6c56fb4bc5f0 28 PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_TEN_MASK; // Start timer 1
nexpaq 0:6c56fb4bc5f0 29
nexpaq 0:6c56fb4bc5f0 30 // Timer 2
nexpaq 0:6c56fb4bc5f0 31 PIT->CHANNEL[0].LDVAL = 0xFFFFFFFF;
nexpaq 0:6c56fb4bc5f0 32 PIT->CHANNEL[0].TCTRL = PIT_TCTRL_TEN_MASK; // Start timer 0, disable interrupts
nexpaq 0:6c56fb4bc5f0 33
nexpaq 0:6c56fb4bc5f0 34 DigitalOut led(LED_BLUE);
nexpaq 0:6c56fb4bc5f0 35 while (true) {
nexpaq 0:6c56fb4bc5f0 36 Delay(1000);
nexpaq 0:6c56fb4bc5f0 37 led = !led;
nexpaq 0:6c56fb4bc5f0 38
nexpaq 0:6c56fb4bc5f0 39 uint64_t ticks = (uint64_t)PIT->LTMR64H << 32;
nexpaq 0:6c56fb4bc5f0 40 ticks |= (uint64_t)PIT->LTMR64L;
nexpaq 0:6c56fb4bc5f0 41 printf("ticks: 0x%x%x\n", (uint32_t)(ticks>>32), (uint32_t)(ticks & 0xFFFFFFFF));
nexpaq 0:6c56fb4bc5f0 42
nexpaq 0:6c56fb4bc5f0 43 ticks = (~ticks) / 24;
nexpaq 0:6c56fb4bc5f0 44 uint32_t us = (uint32_t)(0xFFFFFFFF & ticks);
nexpaq 0:6c56fb4bc5f0 45
nexpaq 0:6c56fb4bc5f0 46 printf("us : 0x%x\n", us);
nexpaq 0:6c56fb4bc5f0 47 }
nexpaq 0:6c56fb4bc5f0 48 }