Exemple #1
0
void rf_cmd(const struct carl9170_cmd *cmd, struct carl9170_rsp *resp)
{
	uint32_t ret;

	fw.phy.ht_settings = cmd->rf_init.ht_settings;
	fw.phy.frequency = cmd->rf_init.freq;

	/*
	 * Is the clock controlled by the PHY?
	 */
	if ((fw.phy.ht_settings & EIGHTY_FLAG) == EIGHTY_FLAG)
		clock_set(AHB_80_88MHZ, true);
	else
		clock_set(AHB_40_44MHZ, true);

	ret = rf_init(le32_to_cpu(cmd->rf_init.delta_slope_coeff_exp),
		      le32_to_cpu(cmd->rf_init.delta_slope_coeff_man),
		      le32_to_cpu(cmd->rf_init.delta_slope_coeff_exp_shgi),
		      le32_to_cpu(cmd->rf_init.delta_slope_coeff_man_shgi),
		      le32_to_cpu(cmd->rf_init.finiteLoopCount),
		      cmd->hdr.cmd == CARL9170_CMD_RF_INIT);

	resp->hdr.len = sizeof(struct carl9170_rf_init_result);
	resp->rf_init_res.ret = cpu_to_le32(ret);
}
Exemple #2
0
void main()
{
 
    WDTCTL = WDTPW|WDTHOLD; //Stop watchdog timer
    if (CALBC1_1MHZ==0xFF)					// If calibration constant erased
    {											
      while(1);                               // do not load, trap CPU!!	
    }
    char p[24];
    setPins();
    clock_set();
    TimerA_UART_init();
    ADC10CTL0 |= ADC10ON;//ADC setup
    ADC10CTL1 |= INCH_0|ADC10SSEL_1|CONSEQ_1;  // set channel, ad source ACLK, sequence of channels
    ADC10AE0  |= BIT0;//|BIT1;
    ADC10CTL0 |= ENC|ADC10SC; //|ADC10IE;
    __enable_interrupt();
    for (;;)
    {
        // Wait for incoming character
        __bis_SR_register(LPM0_bits);
        //temp = (temp*35)/100; 
        itoa(temp,p,10);
        TimerA_UART_print(p);
        TimerA_UART_print("\r\n");
        //set_led(temp);
    }
}
Exemple #3
0
void __section(boot) __noreturn __visible start(void)
{
    clock_set(AHB_40MHZ_OSC, true);

    /* watchdog magic pattern check */
    if ((get(AR9170_PWR_REG_WATCH_DOG_MAGIC) & 0xffff0000) == 0x12340000) {
        /* watch dog warm start */
        incl(AR9170_PWR_REG_WATCH_DOG_MAGIC);
        usb_trigger_out();
    } else if ((get(AR9170_PWR_REG_WATCH_DOG_MAGIC) & 0xffff0000) == 0x98760000) {
        /* suspend/resume */
    }

    /* write the magic pattern for watch dog */
    andl(AR9170_PWR_REG_WATCH_DOG_MAGIC, 0xFFFF);
    orl(AR9170_PWR_REG_WATCH_DOG_MAGIC, 0x12340000);

    init();

#ifdef CONFIG_CARL9170FW_DEBUG

    BUG("TEST BUG");
    BUG_ON(0x2b || !0x2b);
    INFO("INFO MESSAGE");

    /* a set of unique characters to detect transfer data corruptions */
    DBG("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
        " ~`!1@2#3$4%%5^6&7*8(9)0_-+={[}]|\\:;\"'<,>.?/");
#endif /* CONFIG_CARL9170FW_DEBUG */

    /*
     * Tell the host, that the firmware has booted and is
     * now ready to process requests.
     */
    send_cmd_to_host(0, CARL9170_RSP_BOOT, 0x00, NULL);
    main_loop();
}
Exemple #4
0
static void *timebang_new(t_symbol *s, int ac, t_atom *av)
{
	int i;
    t_timebang *x = (t_timebang *)pd_new(timebang_class);

	x->x_clock = clock_new(x, (t_method)timebang_tick);

	if(ac > MAX_TIMES * 3)
	{
		post("timebang: too many creation arguments");
		ac = MAX_TIMES * 3;
	}

	x->x_notimes = 0;
	for(i = 0; i < ac; i += 3)
	{
		if (av[i].a_type == A_FLOAT) x->x_hour[x->x_notimes] = av[i].a_w.w_float;
		else { post ("timebang: first argument must be (int) hours"); return 0; }
		if (av[i+1].a_type == A_FLOAT) x->x_min[x->x_notimes] = av[i+1].a_w.w_float;
		else { post ("timebang: second argument must be (int) minutes"); return 0; }
		if (av[i+2].a_type == A_FLOAT) x->x_sec[x->x_notimes] = av[i+2].a_w.w_float;
		else { post ("timebang: third argument must be (int) seconds"); return 0; }
		x->x_over[x->x_notimes] = 0;
		x->x_notimes++;
	}
	post("timebang: read in %d times of day:", x->x_notimes);
	for(i = 0; i < x->x_notimes; i++)
	{
		x->x_outlet[i] = outlet_new(&x->x_ob, gensym("bang"));	/* create specific bang outlet for time */
		post("          %02d:%02d:%02d", x->x_hour[i], x->x_min[i], x->x_sec[i]);
	}

	clock_set(x->x_clock, 0);

    return (void *)x;
}
Exemple #5
0
void usb_stop(void) {
	udc_stop();
	clock_set(CLK_32KHZ);
}
Exemple #6
0
// starts usb driver if it is not running already
void usb_start(void) {
	if (!my_flag_autorize_cdc_transfert) {
		clock_set(CLK_24MHZ); // usb requires this speed
		udc_start();
	}
}
Exemple #7
0
///////////////////////////////////////////////////////////////////////
// Main function
//  The code works interrupt based, so the main loop just goes over
//  the state variables to check if action is required.
///////////////////////////////////////////////////////////////////////
void main()
{

	char input;
	char uart_hour;
	char uart_min;
	char uart_sec;
	char uart_day;
	char report_clock_was_set = 0;
	char switch_updated;
	char new_incoming;
    char new_update;
	char settings_retrieved = 0;
	char update_eeprom = 0;
	char i;
	switch_point swpoint;

	// Some hardware init first
	init();
		
	// Main loop
	while (1){

		// Set output LED indicator
		output_led = !output;
		
		// Act depending on the UART state
		if (uart_state == STRING_RECEIVED){
			uart_state = WAIT_FOR_DISCONNECT;
			if (rx_buffer[1] == '-' && rx_buffer[4] == ':') {
				// We have received a valid string with time information, parse it
				//uart_state = WAIT_FOR_DISCONNECT;

				// Get the info
				uart_day = rx_buffer[0] - 0x30;
				uart_hour = (rx_buffer[2] - 0x30) * 10 + (rx_buffer[3] - 0x30);
				uart_min  = (rx_buffer[5] - 0x30) * 10 + (rx_buffer[6] - 0x30);
				uart_sec  = (rx_buffer[8] - 0x30) * 10 + (rx_buffer[9] - 0x30);
				clock_set(uart_day, uart_hour, uart_min, uart_sec);
				report_clock_was_set = 1;
				check_timer_table    = 1;
			}  else if (rx_buffer[1] == '*') {
				update_eeprom = 1;
			}	
		}

		// Report status to incoming connection
		// When a user telnets into the XPORT, current internal time and
        // switch points are reported.
		if (uart_state == INCOMING && new_incoming){
			clock_print();
			print_switch_list();
			new_incoming = 0;
		}
		if (uart_state == IDLE) {
			new_incoming = 1;
		}

		// Update the switch status if there is need to, based on the current time
        // and the rules defined in the EEPROM
		if (check_timer_table){
			check_timer_table = 0;
			switch_updated |= update_switch_state(clock_get_day(), clock_get_hours(), clock_get_minutes());
		}

		// Check if we need to sync our internal clock to the web server.
		// This is done one minute after the odd hour mark when the UART is IDLE
		if ( (uart_state == IDLE) && (clock_get_minutes() == 0x01) && /*(clock_get_hours() & 0x01 == 0) &&*/ new_update) {
			new_update = 0;
			web_php_interface(REQUEST_TIME);
		}
		if (clock_get_minutes() == 0x00) {
			new_update = 1;      // Set at minute 0 so that we only request time once after the one minute mark
		}
		
		// Report to the web that the clock was set
		if (uart_state == IDLE && report_clock_was_set) {
			report_clock_was_set = 0;
			web_php_interface(REPORT_CLOCK_SET);
		}

		// Report to the web that the switch state changed
		if (uart_state == IDLE && switch_updated) {
			switch_updated = 0;
			web_php_interface(REPORT_SWITCH_STATE);
		}

		// Request the new settings from the web server
		if (uart_state == IDLE && request_settings) {
			request_settings = 0;
			web_php_interface(REQUEST_SETTINGS);
		}

		// We can only update the EEPROM after we're in IDLE state because interrupts get disabled during 
        // EEPROM write and we would otherwise miss UART RX interrupts.
		if (uart_state == IDLE && update_eeprom) {
			for (i=0; i<rx_buffer[0]; i++){
				swpoint.hour   = rx_buffer[2+(i*4)];
				swpoint.minute = rx_buffer[3+(i*4)];
				swpoint.mask   = rx_buffer[4+(i*4)];
				swpoint.action = rx_buffer[5+(i*4)];
				swpoint.position = i; 
				put_switch_point(swpoint);
			}
			eeprom_write(POINT_COUNT_ADDRESS, rx_buffer[0]);
			settings_retrieved = 1;
			update_eeprom = 0;
			
		}

		// Report that new settings were loaded
		if (uart_state == IDLE && settings_retrieved) {
			settings_retrieved = 0;
			web_php_interface(SETTINGS_RETRIEVED);
		}
	}
	
}
Exemple #8
0
/* 
 * Main - Call the ioctl functions 
 */
int main()
{	
	int         	choice = ' ';
	char        	line[80];
	char        	strVal[80];
	unsigned int 	val;
	unsigned int 	id;
		
	pwm_file_desc = open(PWM_DEVICE_NAME, 0);
	if (pwm_file_desc < 0) {
		printf("Can't open device file: %s\n", PWM_DEVICE_NAME);
		exit(-1);
	}
	
	pwm0 = pwm_data(0, 14, 10000, 500);
	pwm1 = pwm_data(1, 15, 10000, 500);
	
	while (choice != '9')
    {
        printf ("\nMenu\n"
                "===================\n"
                "   [1]    set clock\n"
                "   [2]    PWM init\n"
                "   [3]    PWM set cycle\n"
                "   [4]    PWM set duty\n"
                "   [5]    PWM start\n"
                "   [6]    PWM stop\n"
                ""
                "   [9]    quit\n"
                "Enter choice: "
               );
        fgets (line, sizeof (line), stdin);
        choice = line[0];
        printf ("\n");
        
         switch (choice)
        {
            case '1':
				printf("Enter clock divider [example 96]: ");
                fgets (strVal, sizeof (strVal), stdin);
                val = atoi(strVal);
                
                clock_set(val);
                
                break;
                
			case '2':
				printf("Enter PWM id [0, 1]: ");
                fgets (strVal, sizeof (strVal), stdin);
                id = atoi(strVal);
                
                printf("Enter GPIO [14, 15, etc]: ");
                fgets (strVal, sizeof (strVal), stdin);
                val = atoi(strVal);
				
				id ? pwm_init(pwm1, val) : pwm_init(pwm0, val);
				
                break;

			case '3':
				printf("Enter PWM id [0, 1]: ");
                fgets (strVal, sizeof (strVal), stdin);
                id = atoi(strVal);
                
                printf("Enter PWM cycle [10000]: ");
                fgets (strVal, sizeof (strVal), stdin);
                val = atoi(strVal);
                
                if (id == 0) {
					pwm0->cycle = val;
					pwm_set(pwm0);
				} else {
					pwm1->cycle = val;
					pwm_set(pwm1);
				}
               
                break;

			case '4':
				printf("Enter PWM id [0, 1]: ");
                fgets (strVal, sizeof (strVal), stdin);
                id = atoi(strVal);
                
                printf("Enter PWM duty [0..1000]: ");
                fgets (strVal, sizeof (strVal), stdin);
                val = atoi(strVal);
                
                if (id == 0) {
					pwm0->duty = val;
					pwm_set(pwm0);
				} else {
					pwm1->duty = val;
					pwm_set(pwm1);
				}
                
                break;

			case '5':
				printf("Enter PWM id [0, 1]: ");
                fgets (strVal, sizeof (strVal), stdin);
                id = atoi(strVal);
                
                id ? pwm_start(pwm1) : pwm_start(pwm0);
                
                break;
                
			case '6':
				printf("Enter PWM id [0, 1]: ");
                fgets (strVal, sizeof (strVal), stdin);
                id = atoi(strVal);
                
                id ? pwm_stop(pwm1) : pwm_stop(pwm0);
                
                break;
		}
	}
	
	close(pwm_file_desc);
	
	free(pwm0);
	free(pwm1);
	
	return 0;
}
Exemple #9
0
    /* set the clock to call back after a delay in msec */
void clock_delay(t_clock *x, double delaytime)
{
    clock_set(x, sys_time + sys_time_per_msec * delaytime);
}
Exemple #10
0
/* set the clock to call back after a delay in msec */
void clock_delay(t_clock *x, double delaytime)
{
    clock_set(x, (x->c_unit > 0 ?
                  pd_this->pd_systime + x->c_unit * delaytime :
                  pd_this->pd_systime - (x->c_unit*(TIMEUNITPERSECOND/sys_dacsr)) * delaytime));
}
Exemple #11
0
/* this is called from main() in s_entry.c */
int sys_main(int argc, char **argv)
{
    int i, noprefs;
    char *prefsfile = "";
    sys_externalschedlib = 0;
    sys_extraflags = 0;
#ifdef PD_DEBUG
    fprintf(stderr, "Pd: COMPILED FOR DEBUGGING\n");
#endif
    /* use Win32 "binary" mode by default since we don't want the
     * translation that Win32 does by default */
#ifdef _WIN32
# ifdef _MSC_VER /* MS Visual Studio */
    _set_fmode( _O_BINARY );
# else  /* MinGW */
    {
        extern int _fmode;
        _fmode = _O_BINARY;
    }
# endif /* _MSC_VER */
#endif  /* _WIN32 */
#ifndef _WIN32
    /* long ago Pd used setuid to promote itself to real-time priority.
    Just in case anyone's installation script still makes it setuid, we
    complain to stderr and lose setuid here. */
    if (getuid() != geteuid())
    {
        fprintf(stderr, "warning: canceling setuid privilege\n");
        setuid(getuid());
    }
#endif  /* _WIN32 */
    pd_init();                                  /* start the message system */
    sys_findprogdir(argv[0]);                   /* set sys_progname, guipath */
    for (i = noprefs = 0; i < argc; i++)    /* prescan for prefs override */
    {
        if (!strcmp(argv[i], "-noprefs"))
            noprefs = 1;
        else if (!strcmp(argv[i], "-prefsfile") && i < argc-1)
            prefsfile = argv[i+1];
    }
    if (!noprefs)       /* load preferences before parsing args to allow ... */
        sys_loadpreferences(prefsfile, 1);  /* args to override prefs */
    if (sys_argparse(argc-1, argv+1))           /* parse cmd line args */
        return (1);
    sys_afterargparse();                    /* post-argparse settings */
    if (sys_verbose || sys_version) fprintf(stderr, "%s compiled %s %s\n",
        pd_version, pd_compiletime, pd_compiledate);
    if (sys_version)    /* if we were just asked our version, exit here. */
        return (0);
    sys_setsignalhandlers();
    if (sys_dontstartgui)
        clock_set((sys_fakefromguiclk =
            clock_new(0, (t_method)sys_fakefromgui)), 0);
    else if (sys_startgui(sys_libdir->s_name)) /* start the gui */
        return (1);
    if (sys_hipriority)
        sys_setrealtime(sys_libdir->s_name); /* set desired process priority */
    if (sys_externalschedlib)
        return (sys_run_scheduler(sys_externalschedlibname,
            sys_extraflagsstring));
    else if (sys_batch)
        return (m_batchmain());
    else
    {
            /* open audio and MIDI */
        sys_reopen_midi();
        if (audio_shouldkeepopen())
            sys_reopen_audio();
            /* run scheduler until it quits */
        return (m_mainloop());
    }
}
Exemple #12
0
void CCI() 
{   
    
        //printf("You're in the CCI\n");
        int HH=0;
        int MM=0;
        int SS=0;
        int pri=0;
        int id=0;
        int U = 0;
        int dun = 0;
        
        msg_env* env = request_msg_env();
        msg_env* first = request_msg_env();
    
        while(1)
        {   
            // send the welcome message
/*
            if (first == NULL){
                terminate(1);
            }
            strcpy(first->msg_text, "Enter input for the CCI [s, ps, c [##:##:##], cd, ct, b, n [new_prio] [pid], e... , t]:\0");

            int F = 0;
            F = send_console_chars(first);

            if (F == 0){
                terminate(1);
            }
          
*/
         
            U = get_console_chars(env);   //keyboard input 
            //sleep(5);
            
            // only do this if there was input
            if (U==1)
            {
                env = receive_message();
                while (env->msg_type != CONSOLE_INPUT)
                {                
                        env = receive_message(); //***STOPS HERE TO WAIT FOR INPUT
                }
              
                char* input_txt = env->msg_text;
                
                // send envelope to Process A
                if (strcmp(input_txt,"s")==0) 
                { 
                    // printf("input was s\n");
                     //if the text in the field is "s"
                     env = request_msg_env(); //request an envelope
                     int Z =0;
                     Z = send_message(3,env); // send message to Process A
                }
                
                // display process status of all processes
                else if (strcmp(input_txt,"ps")==0) 
                { 
                    // printf("input was ps\n");
                     env = request_msg_env(); //request an envelope
                     int J=request_process_status(env);
                     if (J==0)
                        printf("Error with getting Process Status\n");                  
                }
                
                // allows time to be displayed on console and halts if getting ct
                else if (strcmp(input_txt,"cd")==0) 
                { 
                    // printf("input was cd\n");
                     
                    wallClockOut = 1;
                }
                else if (strcmp(input_txt,"ct")==0)
                {
                   // printf("input was ct\n");
                     wallClockOut = 0;
                }
    
                // set clock to any valid 24hr time
                else if (strncmp(input_txt,"c", 1)==0) 
                { 
                    // printf("input was c\n");
                     int HH = atoi(input_txt+2);
                     int MM = atoi(input_txt+5);
                     int SS = atoi(input_txt+8);
                     int R = clock_set(wallclock, HH, MM, SS);
                     
                     if (R==0)
                        printf("Error with setting clock in CCI\n");
                }
                
                // b displays past instances of send and receive messages
                else if (strcmp(input_txt,"b")==0) 
                { 
                   // printf("input was b\n");
                    env = request_msg_env(); //request an envelope
                    int U=get_trace_buffers(env);
                    
                    if (U==0)
                       printf("Error performing call on Trace Buffers\n");
               }
                
                // terminates RTX
                else if (strcmp(input_txt,"t")==0)
                { 
                    terminate(0);
                }
                
                // changes priority
                else if (strncmp(input_txt,"n",1)==0) 
                { 
                   //  printf("input was n\n");
                     int new_pri = atoi(input_txt+2);
                     int ID = atoi(input_txt+4);
                     int R = change_priority(new_pri, ID);
                     
                     if (R==0)
                            printf("Error with changing priority in CCI\n");
                }
                
                // echo the input back

                else if (strncmp(input_txt,"e", 1)==0) 
                { 
                   // printf("input was e\n");
                    env = request_msg_env(); //request an envelope
                    input_txt[0] = ' ';
                    strcat(input_txt, "\n\n");
                    strcpy(env->msg_text, "echo is: ");
                    strcpy(env->msg_text, input_txt);
                    int R = send_console_chars(env);
                    
                    if (R==0)
                            printf("Error with echoing to screen\n");
                }
                
                else 
                {
                     env = request_msg_env(); //request an envelope
                     char* temp = (char*) malloc(sizeof(SIZE));
                     sprintf(temp, "'%s' is not valid CCI input. Please try again.\n\n", input_txt);
                     strcpy(env->msg_text, temp);
                     int R = send_console_chars(env);
                    
                     if (R==0)
                         printf("Error with printing invalid input message\n");
                     
                    // printf("'%s' is not valid CCI input. Please try again.\n\n", input_txt);
                }

                
                dun = release_msg_env(env);

                if (dun == 0)
                {
                    env = request_msg_env(); //request an envelope
                    strcpy(env->msg_text, "ERROR IN DEALLOCATING ENVELOPE AT END OF CCI\n");
                    int R = send_console_chars(env);

                    if (R==0)
                          printf("Error with printing error message\n");
                }
                //else
                 //  printf("CCI finished, I think\n");
               
            }
         
        env = request_msg_env();
        
        // if there was no input
        release_processor();
        }
}