/** De-Initialise the Uart. * * BLEUART_Deinit() * This function is called by the BLE stack (TRANSPORT layer) to de-initialise * the UART layer. Eventual thread shall be terminated here. * When this function succeed, the UART layer shall be fully de-initialised * * This function is called during the BLESTCK_Deinit() process, failure here * will issue a failure in BLESTCK_Deinit() * * @todo implement this function * * @see BLESTCK_Deinit() * * @return The status of the operation: * - BLESTATUS_SUCCESS indicates to the BLE stack that the UART have been * successfully initialized * - BLESTATUS_FAILED indicates to the BLE stack that the UART could not be * initialized * * @author Alexandre GIMARD */ BleStatus BLEUART_Deinit(void){ // Add here specific code to execute during Stack De-Initialisation // in order to de-initialise the transport drivers //> /*close spi interface*/ if(MQX_OK != fclose(spi_dev)) { #ifdef LOCAL_LOG SYSTEM_Log("Unable to close communication channel\n"); #endif return BLESTATUS_FAILED; } /*power off em9301 from 74HC595*/ if(MQX_OK != mux_74hc595_clear_bit(BSP_74HC595_0, BSP_74HC595_VBLE_3V3)) { return BLESTATUS_FAILED; } /*disable pin IRQ, destroy spi read task, semaphore*/ _bsp_int_disable(lwgpio_int_get_vector(&SPI_IRQ_PIN)); _int_install_isr(lwgpio_int_get_vector(&SPI_IRQ_PIN), _int_get_default_isr(), NULL); if(MQX_OK != _task_destroy(_task_get_id_from_name("SPI_READ"))) { return BLESTATUS_FAILED; } if(MQX_OK != _lwsem_destroy(&IRQ_SEM)) { return BLESTATUS_FAILED; } //< return BLESTATUS_SUCCESS; }
/** Initialise the Uart. * * BLEUART_Init() * This function is called by the BLE stack (TRANSPORT layer) to initialise * the UART layer. * The user should uses this function to open and setup parameters for the * UART line, eventually create Read Thread or setup RX and TX interrupts. * * When this function succeeds, the UART layer shall be fully functional * * This function is called during the BLESTCK_Init() process, failure here * will issue a failure in BLESTCK_Init() * * @todo implement this function * * @see BLESTCK_Init() * * @return The status of the operation: * - BLESTATUS_SUCCESS indicates to the BLE stack that the UART have been * successfully initialized * - BLESTATUS_FAILED indicates to the BLE stack that the UART could not be * initialized * * @author Alexandre GIMARD */ BleStatus BLEUART_Init(void){ // Add here specific code to execute during Stack Initialisation // in order to initialise the transport drivers //> _task_id task_id; TASK_TEMPLATE_STRUCT task_template; _mqx_uint priority; uint32_t para = 0x00; /*set up spi parameters*/ spi_dev = fopen("spi1:", NULL); ioctl (spi_dev, IO_IOCTL_SPI_SET_TRANSFER_MODE, ¶); ioctl (spi_dev, IO_IOCTL_SPI_SET_ATTRIBUTES, ¶); ioctl (spi_dev, IO_IOCTL_SPI_SET_DUMMY_PATTERN, ¶); para = 1000000; ioctl (spi_dev, IO_IOCTL_SPI_SET_BAUD, ¶); /*create SPI read task*/ task_template.TASK_TEMPLATE_INDEX = 0; task_template.TASK_ADDRESS = taskRead; task_template.TASK_STACKSIZE = 1000L; _task_get_priority(_task_get_id_from_name("main"), &priority); task_template.TASK_PRIORITY = priority - 1; task_template.TASK_NAME = "SPI read"; task_template.TASK_ATTRIBUTES = 0; task_template.CREATION_PARAMETER = (uint32)spi_dev; task_template.DEFAULT_TIME_SLICE = 0; task_id = _task_create_blocked(0, 0, (uint32)&task_template); if(task_id == 0) { return BLESTATUS_FAILED; } _task_ready(_task_get_td(task_id)); /*power on and select pcs pin from 74HC595*/ mux_74hc595_clear_bit(BSP_74HC595_0, BSP_74HC595_SPI_S0); mux_74hc595_clear_bit(BSP_74HC595_0, BSP_74HC595_SPI_S1); mux_74hc595_set_bit(BSP_74HC595_0, BSP_74HC595_VBLE_3V3); /*open flash file for system interface*/ flash_file = fopen("flashx:bank1", NULL); if(flash_file == NULL) { #ifdef LOCAL_LOG SYSTEM_Log("open flash file error.\n"); #endif return BLESTATUS_FAILED; } //< return BLESTATUS_SUCCESS; }
int32_t Shell_abort(int32_t argc, char *argv[] ) { SHELL_CONTEXT_PTR shell_ptr = Shell_get_context(argv); bool print_usage, shorthelp = FALSE; int32_t return_code = SHELL_EXIT_SUCCESS; _task_id task_id; uint32_t result; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if (argc == 2) { task_id = _task_get_id_from_name( argv[1] ); if (task_id == MQX_NULL_TASK_ID) { fprintf(shell_ptr->STDOUT, "No task named %s running.\n",argv[1]); return_code = SHELL_EXIT_ERROR; } else { result = _task_abort(task_id); if (result == MQX_OK) { fprintf(shell_ptr->STDOUT, "Task %s aborted.\n",argv[1]); } else { fprintf(shell_ptr->STDOUT, "Unable to abort task %s.\n",argv[1]); return_code = SHELL_EXIT_ERROR; } } } else { fprintf(shell_ptr->STDOUT, "Error, %s invoked with incorrect number of arguments\n", argv[0]); print_usage = TRUE; } } if (print_usage) { if (shorthelp) { fprintf(shell_ptr->STDOUT, "%s <taskname>\n", argv[0]); } else { fprintf(shell_ptr->STDOUT, "Usage: %s <taskname>\n", argv[0]); fprintf(shell_ptr->STDOUT, " <taskname> = MQX Task name\n"); } } return return_code; } /* Endbody */
int32_t Shell_kill(int32_t argc, char *argv[] ) { _task_id task_id; uint32_t result; bool print_usage, shorthelp = FALSE; int32_t return_code = SHELL_EXIT_SUCCESS; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if (argc == 2) { task_id = _task_get_id_from_name( argv[1] ); if (task_id == MQX_NULL_TASK_ID) { printf("No task named %s running.\n",argv[1]); return_code = SHELL_EXIT_ERROR; } else { result = _task_destroy(task_id); if (result == MQX_OK) { printf("Task %s killed.\n",argv[1]); } else { printf("Unable to kill task %s.\n",argv[1]); return_code = SHELL_EXIT_ERROR; } } } else { printf("Error, %s invoked with incorrect number of arguments\n", argv[0]); print_usage = TRUE; } } if (print_usage) { if (shorthelp) { printf("%s <taskid>\n", argv[0]); } else { printf("Usage: %s <taskname>\n", argv[0]); printf(" <taskname> = MQX Task name\n"); } } return return_code; } /* Endbody */
void watering_system_pump_water(uint32_t pumping_time){ if (_task_get_id_from_name("watering_pump_task") == MQX_NULL_TASK_ID) _task_create(0, WATERING_PUMP, pumping_time); }