📄 eoscope.c
字号:
#include "eOscope.h"
#include "TIMaC1.h"
#include "KBDaC1.h"
#include "LCDaC1.h"
#include "CPLDaC1.h"
uint8_t u8Trigger = EOS_nScreenLimitHigh/2;
uint8_t u8TrigSemaphore = 1; /* ensure the first run of print trigger function */
uint16_t u8IndexTime = 7;
uint8_t u8TimeSemaphore = 1;
uint8_t u8OffsetSemaphore;
uint8_t ValueBuffer[EOS__nTraceLength];
uint8_t *pu8Buffer;
SIGNAL (SIG_INTERRUPT0)
{
// Here: we should disable FIFO_W through CPLD!!!. Maybe also ADC_CLK.
PORTD &= (~(1<<EOS__u8SerGate)); /* Disable FIFO_CLK */
}
void EOS__vFifoReadData (void)
{
uint8_t u8Index;
uint8_t temp_value = 0;
uint8_t temp_value2 = 0;
uint16_t u16Index;
for (u8Index = 0; u8Index < 6; u8Index++) /* Erase ADC pipeline */
{
EOS__u8FifoCtrlPort &= (~(1<<EOS__nFifoRead)); /* FIFO_R = 0 */
EOS__u8FifoCtrlPort |= (1<<EOS__nFifoRead); /* FIFO_R = 1 */
}
u8Index = 0;
/* Trigger procedure */
while (u8Index < EOS__nTraceLength)
{
u8Index++; /* Count the number of read cycles */
temp_value = EOS__u8FifoDataPin; /* Store old value */
EOS__u8FifoCtrlPort &= (~(1<<EOS__nFifoRead)); /* FIFO_R = 0 */
EOS__u8FifoCtrlPort |= (1<<EOS__nFifoRead); /* FIFO_R = 1 */
temp_value2 = EOS__u8FifoDataPin; /* Store next sample value */
if ((temp_value <= u8Trigger) && (temp_value2 > u8Trigger))
{
break;
}
}
for (u8Index = 0; u8Index < EOS__nTraceLength; u8Index++) /* Get samples from FIFO */
{
ValueBuffer[u8Index] = EOS__u8FifoDataPin;
EOS__u8FifoCtrlPort &= (~(1<<EOS__nFifoRead)); /* FIFO_R = 0 */
EOS__u8FifoCtrlPort |= (1<<EOS__nFifoRead); /* FIFO_R = 1 */
}
for (u16Index = u8Index; u16Index < EOS__nFifoLength ; u16Index++) /* Flush the rest of samples from FIFO*/
{
EOS__u8FifoCtrlPort &= (~(1<<EOS__nFifoRead)); /* FIFO_R = 0 */
EOS__u8FifoCtrlPort |= (1<<EOS__nFifoRead); /* FIFO_R = 1 */
}
PORTD |= (1<<PD6); /* Start a new aquisition */
}
void EOS__vFifoInitChip(void)
{
EOS__u8FifoDataDdr = 0x00; /* FIFO_DATA as input */
EOS__u8FifoCtrlDdr |= (1<<EOS__nFifoRead);
DDRD |= (1<<CPLD_nSerDATA); /* FIFO_READ as output */
EOS__u8FifoCtrlDdr |= (1<<EOS__nFifoReset); /* FIFO_READ as output */
EOS__u8FifoCtrlDdr &= (~(1<<EOS__nFifoFullFlag)); /* FIFO_FF as input */
EOS__u8FifoCtrlPort |= (1<<EOS__nFifoRead); /* FIFO_READ = 1 */
EOS__u8FifoCtrlPort |= (1<<EOS__nFifoReset); /* reset inactive */
EOS__u8FifoCtrlPort &= (~(1<<EOS__nFifoReset)); /* FIFO_RS = 0, reset is active */
EOS__u8FifoCtrlPort |= (1<<EOS__nFifoReset); /* reset inactive: FIFO_RS = 1, reset finished */
/* Set interrupt 0, on falling edge */
MCUCR &= (~(1<<ISC00));
MCUCR |= (1<<ISC01);
/* Activate INT0 */
GICR |= (1<<INT0);
}
void EOS__vCpldInit(void)
{
DDRD |= (1<<EOS__u8SerGate); /* Set pin as output: will be FIFO_CLK_GATE */
PORTD |= (1<<EOS__u8SerGate); /* Start the FIFO_CLK, so the aquisition process begins */
}
int main (void)
{
LCD_vInitScreen();
LCD_vClearScreen();
pu8Buffer = ValueBuffer;
LCD_vPrintLogo();
LCD_vPrintString();
EOS__vCpldInit();
EOS__vFifoInitChip();
/* Keyboard rate init */
TIM_vInitTimer3(300);
/* Initialize the PWM for trace offset level: the value is defined in TIMaC1.h file */
TIM_vInitPwmOnTimer1A();
/* Global interrupt enable */
sei();
u8TimeSemaphore = 1;
while (1)
{ if (!(PORTD & (1<<EOS__u8SerGate)))
{
EOS__vFifoReadData();
LCD_vPrintSignal();
}
if (u8TrigSemaphore != 0)
{
LCD_vPrintTrigger(u8Trigger);
u8TrigSemaphore = 0;
}
if (u8TimeSemaphore != 0)
{
LCD_vPrintString();
CPLD_vWriteDivider(TIM__stTimeBase[u8IndexTime].u8Prescaler,TIM__stTimeBase[u8IndexTime].u16Counter);
u8TimeSemaphore = 0;
}
}
return (1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -