📄 target.c
字号:
/* ************************************************************************ */
/* */
/* Volcano Communications technologies AB */
/* All rights reserved */
/* */
/* ************************************************************************ */
/* File: target.c */
/* Description: Target specific functions for COS08SCI LTP example appli- */
/* cation */
/* */
#include "target.h"
/* ************************************************************************ */
/* Perform initialisation of development system (if any) */
void init_environment(void)
{
} /* init_environment */
/* ************************************************************************ */
/* Perform initialisation of target. Initialise a free running counter at */
/* 1MHz. */
void init_target(void)
{
/* Initialise debug PIN */
INIT_SYNC_PIN();
/* TURN on internal clock generator, and set its frq to ~16 MHz*/
ICGMR = 53; /* CGMXCLK ~ 16,282 MHz */
ICGCR |= ICGCR_ICGON;
/* Wait till ICG becomes stable. */
while(!ICGCR_ICGS)
{
PET_WATCHDOG();
}
/* Initialise TIMA as free-run ctr.*/
TASC_TSTOP = TASC_TRST = 1; /* Stop and reset counter. */
TASC |= TASC_PS_VALUE; /* Set prescaler */
TASC_TSTOP = 0; /* Start timer */
/* If the line below is uncommented, ESCI runs from BUSCLOCK instead of CGMXCLK */
/* CONFIG2 = ESCIBD_SRC */
} /* init_target*/
/* ************************************************************************ */
/* Read timer channel A (free running counter at 1MHz) and return current */
/* value. */
l_u16 l_get_us_counter (void)
{
return(TACNTW);
} /* l_get_us_counter */
/* ************************************************************************ */
/* Restores interrupt level to the previous level, as indicated by the in- */
/* put previous. On the hc08 family the interrupt level can only be either */
/* "interrupts enabled" or "interrupts disabled". */
void l_sys_irq_restore(l_irqmask previous)
{
if (previous)
{
asm sei; /* disable_interrupt */
}
else
{
asm cli; /* enable_interrupt */
}
} /* v_ctl_ints_restore */
/* ************************************************************************ */
/* Disable interrupts, and return the previous value of the interrupt le- */
/* vel. */
l_irqmask l_sys_irq_disable(void)
{
l_irqmask x;
/* Hiware specific intrinsic function that returns the interrupt flag */
x = (l_irqmask) __isflag_int_enabled();
/* disable_interrupt */
asm("sei");
/* return previous interrupt flag (disabled = 0, enabled = 1) */
return(x);
} /* v_ctl_ints_disable */
/* ************************************************************************ */
/* Adjusts CPU internal clock generator based on bit-time measurements done */
/* by the LTP. */
/* Return value of L_IOCTL_RD_BIT_TIME if the CPU-clock is the nominal value */
#define L_NOMINAL_VALUE (BUS_CLOCK*1000)/(2UL*L_BPS_i1)
#define L_MAXIMUM_VALUE (L_NOMINAL_VALUE*23)/20
#define L_MINIMUM_VALUE (L_NOMINAL_VALUE*3)/20
void adjust_clock(void)
{
l_u16 bt, nm;
nm=L_NOMINAL_VALUE;
/* Set new clock */
bt=l_ifc_ioctl_i1(L_IOCTL_RD_BIT_TIME,L_NULL);
if (bt < L_MAXIMUM_VALUE
&& bt > L_MINIMUM_VALUE
&& bt != L_NOMINAL_VALUE)
{
if(bt < L_NOMINAL_VALUE)
{
ICGMR = ICGMR+1;
}
else
{
ICGMR = ICGMR-1;
}
}
/* Start internal clock generator */
ICGCR |= ICGCR_ICGON;
/* Wait till clock becomes stable */
while(!ICGCR_ICGS)
{;}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -