123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- #include "ch.h"
- #include "hal.h"
- #include "ccportab.h"
- #include "portab.h"
- #define ADC_GRP1_BUF_DEPTH 1
- #define ADC_GRP2_BUF_DEPTH 64
- #if CACHE_LINE_SIZE > 0
- CC_ALIGN(CACHE_LINE_SIZE)
- #endif
- adcsample_t samples1[CACHE_SIZE_ALIGN(adcsample_t, ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH)];
- #if CACHE_LINE_SIZE > 0
- CC_ALIGN(CACHE_LINE_SIZE)
- #endif
- adcsample_t samples2[CACHE_SIZE_ALIGN(adcsample_t, ADC_GRP2_NUM_CHANNELS * ADC_GRP2_BUF_DEPTH)];
- size_t n= 0, nx = 0, ny = 0;
- void adccallback(ADCDriver *adcp) {
- (void)adcp;
-
- n++;
- if (adcIsBufferComplete(adcp)) {
- nx += 1;
- }
- else {
- ny += 1;
- }
- if ((n % 200) == 0U) {
- palToggleLine(PORTAB_LINE_LED2);
- }
- }
- void adcerrorcallback(ADCDriver *adcp, adcerror_t err) {
- (void)adcp;
- (void)err;
- chSysHalt("it happened");
- }
- static THD_WORKING_AREA(waThread1, 128);
- static THD_FUNCTION(Thread1, arg) {
- (void)arg;
- chRegSetThreadName("blinker");
- while (true) {
- palSetLine(PORTAB_LINE_LED1);
- chThdSleepMilliseconds(500);
- palClearLine(PORTAB_LINE_LED1);
- chThdSleepMilliseconds(500);
- }
- }
- int main(void) {
-
- halInit();
- chSysInit();
-
- portab_setup();
-
- chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
-
- adcStart(&PORTAB_ADC1, &portab_adccfg1);
- adcSTM32EnableVREF(&PORTAB_ADC1);
- adcSTM32EnableTS(&PORTAB_ADC1);
-
- adcConvert(&PORTAB_ADC1, &portab_adcgrpcfg1, samples1, ADC_GRP1_BUF_DEPTH);
- cacheBufferInvalidate(samples1, sizeof (samples1) / sizeof (adcsample_t));
-
- gptStart(&PORTAB_GPT1, &portab_gptcfg1);
-
- adcStartConversion(&PORTAB_ADC1, &portab_adcgrpcfg2,
- samples2, ADC_GRP2_BUF_DEPTH);
- gptStartContinuous(&PORTAB_GPT1, 100U);
-
- while (true) {
- if (palReadLine(PORTAB_LINE_BUTTON) == PORTAB_BUTTON_PRESSED) {
- gptStopTimer(&PORTAB_GPT1);
- adcStopConversion(&PORTAB_ADC1);
- }
- chThdSleepMilliseconds(500);
- }
- return 0;
- }
|