static void init(void) { IRQ_ENABLE; kdbg_init(); timer_init(); LOG_INFO("TIMER init..ok\n"); /* * Init temperature sensor device. * - init the temperature driver * - init the spi communication channel */ tmp123_init(); // Init SPI connected to sensor temperature spimaster_init(&temp_sensor_bus, SER_SPI1); ser_setbaudrate(&temp_sensor_bus, 1000000L); LOG_INFO("TMP123 sensor init..ok\n"); // Init SPI bus to communicate to SD card spi_dma_init(&spi_dma); spi_dma_setclock(20000000L); LOG_INFO("SD SPI init..ok\n"); adc_init(); LOG_INFO("ADC init..ok\n"); }
/** * Setup all needed to test dataflash memory * */ int dataflash_testSetup(void) { kfile_testSetup(); LOG_INFO("KFILE setup..ok\n"); LOG_INFO("Check if kernel is enable (if enable you should see the assert message.)\n"); SILENT_ASSERT("bertos/drv/dataflash_test.c:119: Assertion failed: !CONFIG_KERN"); ASSERT(!CONFIG_KERN); /* * This test use a kfile_test module, * so should include source in your makefile. */ MOD_CHECK(kfile_test); timer_init(); LOG_INFO("Timer init..ok\n"); /* * Init SPI module and dataflash driver. */ // Open SPI comunication channel spimaster_init(&spi_fd, 0); LOG_INFO("SPI0 init..ok\n"); ser_setbaudrate(&spi_fd, 5000000UL); LOG_INFO("SPI0 set baudrate..ok\n"); //Init dataflash memory dataflash_hw_init(); LOG_INFO("DATAFLASH HW..ok\n"); if (dataflash_init(&dflash_fd, &spi_fd.fd, DATAFLASH_MEM_MODEL, DATAFLASH_FUNC_CS_SET, DATAFLASH_FUNC_RESET)) LOG_INFO("DATAFLASH init..ok\n"); else LOG_ERR("DATAFLASH init..fail\n"); //Fill tmp buffer with rand chars. for (int i = 0; i < DATAFLASH_TEST_STR_LEN; i++) { #if DATAFLASH_USE_RAND_FUNC #include <stdlib.h> //Rand() test_buf[i] = (uint8_t)rand(); #else test_buf[i] = (i & 0xff); #endif } LOG_INFO("Fill tmp buff..ok\n"); return 0; }
int main(void) { int status; char buf[256]; uint8_t commandbyte; uint8_t responsebyte; cpu_init(DEFAULT_CPU_FREQ); serial_stdio(CONSOLE_PORT); puts("\033[H\033[2JSTM32F1 SPI Master Test (" __DATE__ " " __TIME__ ")\n"); puts(revision); printf("\nCPU Freq:%ld Hz Compiler:%s\n\n", CPUFREQ, __VERSION__); if ((status = spimaster_init(SPI_PORT, 0, 281250, TRUE))) { fprintf(stderr, "ERROR: spimaster_init() failed at line %d, %s\n", status, strerror(errno)); assert(FALSE); } for (;;) { printf("Enter a value to send: "); fflush(stdout); fflush(stdin); gets(buf); commandbyte = atoi(buf); if ((status = spimaster_transfer(SPI_PORT, &commandbyte, 1, &responsebyte, 1))) { fprintf(stderr, "ERROR: spimaster_transfer() failed at line %d, %s\n", status, strerror(errno)); assert(FALSE); } printf("Response was %02X\n\n", responsebyte); } }
/* Main code - entry point to firmware */ void main(void) { /* FTDI:SDD Driver Declarations */ // UART Driver configuration context uart_context_t uartContext; // SPI Master configuration context spimaster_context_t spimContext; // GPIO Port A configuration context gpio_context_t gpioContextA; // GPIO Port B configuration context gpio_context_t gpioContextB; // USB Host configuration context usbhost_context_t usbhostContext; /* FTDI:EDD */ /* FTDI:SKI Kernel Initialisation */ vos_init(50, VOS_TICK_INTERVAL, VOS_NUMBER_DEVICES); vos_set_clock_frequency(VOS_48MHZ_CLOCK_FREQUENCY); vos_set_idle_thread_tcb_size(512); /* FTDI:EKI */ iomux_setup(); /* FTDI:SDI Driver Initialisation */ // Initialise UART uartContext.buffer_size = VOS_BUFFER_SIZE_128_BYTES; uart_init(VOS_DEV_UART,&uartContext); // Initialise SPI Master spimContext.buffer_size = VOS_BUFFER_SIZE_128_BYTES; spimaster_init(VOS_DEV_SPI_MASTER,&spimContext); // Initialise GPIO A gpioContextA.port_identifier = GPIO_PORT_A; gpio_init(VOS_DEV_GPIO_PORT_A,&gpioContextA); // Initialise GPIO B gpioContextB.port_identifier = GPIO_PORT_B; gpio_init(VOS_DEV_GPIO_PORT_B,&gpioContextB); // Initialise FAT File System Driver fatdrv_init(VOS_DEV_FAT_FILE_SYSTEM); // Initialise BOMS Device Driver boms_init(VOS_DEV_BOMS); // Initialise USB HID Device usbHostHID_init(VOS_DEV_USBHOST_HID_1); // Initialise USB HID Device usbHostHID_init(VOS_DEV_USBHOST_HID_2); // Initialise USB Host usbhostContext.if_count = 8; usbhostContext.ep_count = 16; usbhostContext.xfer_count = 2; usbhostContext.iso_xfer_count = 2; if(usbhost_init(VOS_DEV_USBHOST_1, VOS_DEV_USBHOST_2, &usbhostContext) != 0) while(1); //FAILED /* FTDI:EDI */ /* FTDI:SCT Thread Creation */ tcbFIRMWARE = vos_create_thread_ex(31, 2048, firmware, "Application", 0); /* FTDI:ECT */ vos_delay_msecs(100); vos_start_scheduler(); main_loop: vos_delay_msecs(100); goto main_loop; }
/****************************************************************************** * File: main.c * Author: Kevin Day * Date: February, 2005 * Description: * Main program for audi radio interface * * Copyright (c) 2005 Kevin Day * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * *******************************************************************************/ #include <avr/interrupt.h> #include <avr/pgmspace.h> #include <avr/io.h> #include <avr/wdt.h> #include "types.h" #include "tasks.h" #include "comms_generic.h" #include "timers.h" #include "adc.h" #include "persist.h" #include "hcms.h" #include "gpsavr.h" #include "hud.h" #include "spimaster.h" #include "avrcan.h" #include "avrms2.h" #include "swuart.h" #include "hwi2c.h" #include "adcgauges.h" #include "miscgpio.h" #include "sensors.h" #define LED_PORT PORTG #define LED_DIR DDRG #define LED_PIN PING #define LED_BIT 0 #define ANT_PORT PORTB #define ANT_DIR DDRB #define ANT_PIN PINB #define ANT_BIT 2 void debug_led(u8 val); static inline void start_blink_timer(); void bufferpool_init(); task_t* comms_task_create(); task_t *radio_input_task_create(); #define STACK_CANARY 0xC5 void StackPaint(void) __attribute__ ((naked)) __attribute__ ((section (".init1"))); void StackPaint(void) { #if 0 uint8_t *p = &_end; while(p <= &__stack) { *p = STACK_CANARY; p++; } #else __asm volatile (" ldi r30,lo8(_end)\n" " ldi r31,hi8(_end)\n" " ldi r24,lo8(0xc5)\n" /* STACK_CANARY = 0xc5 */ " ldi r25,hi8(__stack)\n" " rjmp .cmp\n" ".loop:\n" " st Z+,r24\n" ".cmp:\n" " cpi r30,lo8(__stack)\n" " cpc r31,r25\n" " brlo .loop\n" " breq .loop"::); #endif } extern uint8_t __heap_start; /* not _end because of .bufferpool */ extern uint8_t __stack; uint16_t StackCount(void) { const uint8_t *p = &__heap_start; uint16_t c = 0; while(*p == STACK_CANARY && p <= &__stack) { p++; c++; } return c; } #define ADC_CONTEXTS 8 adc_context_t adc_context[ADC_CONTEXTS]; u8 num_adc; u16 stack_high; #define DISPAVR_RESET_PIN 4 /* on port B */ int main() { u8 mcusr_rst = MCUSR; MCUSR = 0; wdt_disable(); wdt_enable(WDTO_2S); /* Disable JTAG so the ADC pins are available. * Don't do this if the JTAG reset flag is set -- * presumably the jtag pod is connected in that * case. */ if (! (mcusr_rst & (1<<JTRF))) { MCUCR |= (1<<JTD); } /* Assert remote AVR reset */ PORTB &= ~(1<<DISPAVR_RESET_PIN); DDRB |= (1<<DISPAVR_RESET_PIN); bufferpool_init(); init_persist_data(); systimer_init(); //fuel_gauge_init(&adc_context[num_adc++]); num_adc = sensors_init(&adc_context[num_adc], num_adc); adc_init_adc(ADC_DIV128, num_adc, adc_context); /* Deassert remote AVR reset */ PORTB |= (1<<DISPAVR_RESET_PIN); spimaster_init(); init_avrms2(); // swuart_init(); /* Enable interrupts */ sei(); /* Populate the tasklist in priority order */ tasklist[num_tasks++] = comms_task_create(); tasklist[num_tasks++] = gps_task_create(); tasklist[num_tasks++] = can_task_create(); tasklist[num_tasks++] = hud_task_create(); // tasklist[num_tasks++] = i2c_task_create(); tasklist[num_tasks++] = gpio_task_create(); // start_blink_timer(); /* non-preemptive static priority scheduler */ while(1) { wdt_reset(); u8 taskidx; u8 r; for(taskidx=0; taskidx<num_tasks; taskidx++) { r = tasklist[taskidx]->taskfunc(); if (r) break; } if (r == 0) { stack_high = StackCount(); /* only run this after all tasks run */ } } }