Example #1
0
static void sram_action(Server *server, char **tokens, uint8_t count)
{
    static PROGMEM prog_char text[] = "+OK Free SRAM is ";

    write_pgmspace(text);
    Serial.print(StackCount());
    write_pgmspace(crlf_text);
}
Example #2
0
int main()
{
	int i = 0;
	Stack st;
	ElemType e;
	InitStack(&st);
	printf("Stack Count : %d\n",StackCount(st));
	
	for(i=0;i<10;i++)
	Push(&st,i);

	for(i=0;i<10;i++)
	{
		Pop(&st,&e);
		printf("%d ",e);
	}		
	return 0;
}
Example #3
0
int main(void){
  //while(1);
  wdt_disable();
  
  ///Configure the Torquer
  configure_torquer();
  char buf[100];
  uint16_t v;
    
  int ao;
  for(ao=0;ao<1;ao++) 
  _delay_ms(1000);  
    
  /// Initialise Interfaces - UART of Magnetometer and GPS and the SPI bus
  init_UART_MM();
  init_UART_GPS();
  init_SPI();
  init_TWI();
  
  send_preflight("Master\r", 7);
  
  ///Set Preflight pin as input
  cbi(DDR_PF, PIN_PF);
  
  ///* Switch on Global interrupts
  sei();
  
  ///Check if Preflight Pin is high
  while(1){
    
    ///* * Reset timer for 2 seconds
    timer_reset_two_sec();
    //get_HM_data();
    //send_preflight("Power\r", 6);
    
    
    ///* Preflight Checks
    if(0){
      ///* * Set the mode as preflight
      Mode = PREFLIGHT;
      /*slave_send(HM_DATA, "Hello", 5);
      _delay_ms(10);
      
      slave_send (BEGIN_TX_GS, NULL, 0);
      
      //power_up_peripheral(PCC);
      _delay_ms(10);
      
      ao = init_CC1020();
      
      if(ao) 
        send_preflight("CC Init\r", 8);
      else
        send_preflight("No Init\r", 8);
      while(1);*/
      /*power_up_peripheral(PGPS);
      while(1) {
        read_GPS();
      while(UCSR0B & _BV(RXCIE0));
      copy_gps_reading();
      sprintf(buf,"%ld %ld %ld\r", Current_state.gps.x/1000, Current_state.gps.y/1000, Current_state.gps.z/1000);
      
      send_preflight(buf, strlen(buf));
      sprintf(buf,"%ld %ld %ld\r", Current_state.gps.v_x/1000, Current_state.gps.v_y/1000, Current_state.gps.v_z/1000);
      
      send_preflight(buf, strlen(buf));
      _delay_ms(1000);
      }*/
      ///* * Magnetometer and Torquer test

	  ///* * Reading with one torquer on at once
      /*Current_state.pwm.x_dir = 0;
      Current_state.pwm.x = 10000;
      Current_state.pwm.y_dir = 0;
      Current_state.pwm.y = 30000;
      Current_state.pwm.z_dir = 1;
      Current_state.pwm.z = 20000;
      send_preflight("Read\r", 5);
      set_PWM();*/
      while(1) {
        read_SS();
        //send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading));
        for(v = 0; v < 6; v++)
        {
          sprintf(buf,"%u\r", (uint16_t)(((float)Current_state.ss.reading[v])*1.6*100/4096));
          send_preflight(buf, strlen(buf));
          sprintf(buf,"%x\r", Current_state.ss.reading[v]);
          send_preflight(buf, strlen(buf));
          
      }
      _delay_ms(1000);
    }
	  ///* * Set Torquer values to zero
      reset_PWM();
      while(1)
        read_MM();

      read_GPS();
      send_preflight((char *)&Current_state.gps, sizeof(struct GPS_reading));
      
      ///* * Sunsensor test
      read_SS();
      send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading));

      ///* Health Montoring
      get_HM_data();
      send_preflight((char *)&Current_state.hm, sizeof(struct HM_data));
	  
      ///Communication Task
      comm();
	  
	  ///* * Wait for 2 seconds to get over
      timer_wait_reset();
    }

  ///Normal Mode
  
    else{
    
      ///* Set default mode of Satellite
      Mode = DETUMBLING;
      
      ///* initialise Timer
      Time = 0;
      
      ///Loop begins
      while(1){
        //Fuses Pain, Nominal Mode checking
        send_preflight("Loop\r", 5);
        control();
        send_preflight("Control\r", 8);
        //power();
        comm();
        send_preflight("Comm\r", 5);
        v = StackCount();
        sprintf(buf, "Stack = %d\r", v);
        send_preflight(buf, strlen(buf));
        v = get_free_memory();
        sprintf(buf, "Stack(Method 2) = %d\r", v);
        send_preflight(buf, strlen(buf));
        Time += FRAME_TIME;
        timer_wait_reset();
      }
    }
  }
  return 0;
}
Example #4
0
/******************************************************************************
* 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 */
        }
    }
}