1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys: add usb_board_reset module

This commit is contained in:
Alexandre Abadie 2020-02-12 15:16:10 +01:00
parent accbfbd0d1
commit 643187c1e4
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
3 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,56 @@
/*
* Copyright (C) 2020 Inria
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup sys_usb_board_reset Board reset via USB CDC ACM
* @ingroup sys
* @brief Trigger a board reset via USB CDC ACM
*
* @{
*
* @file
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
*/
#ifndef USB_BOARD_RESET_H
#define USB_BOARD_RESET_H
#ifdef __cplusplus
extern "C" {
#endif
#include <inttypes.h>
#include "usb/usbus/cdc/acm.h"
/**
* @brief USB coding callback used to trigger the board reset
*
* @param[in] cdcacm Pointer to the cdcacm device
* @param[in] baud Baudrate used by the client. Only 1200 baud is taken into account
* @param[in] bits Number of bit mode used by the client
* @param[in] parity Parity mode used by the client
* @param[in] stop Stop bit mode used by the client
*
* @return Always return 0
*/
int usb_board_reset_coding_cb(usbus_cdcacm_device_t *cdcacm,
uint32_t baud, uint8_t bits,
uint8_t parity, uint8_t stop);
/**
* @brief Trigger a simple reset, back to the application
*/
void usb_board_reset_in_application(void);
#ifdef __cplusplus
}
#endif
#endif /* USB_BOARD_RESET_H */
/** @} */

View File

@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,66 @@
/*
* Copyright (C) 2020 Inria
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup sys
* @{
* @file
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
* @}
*/
#define USB_H_USER_IS_RIOT_INTERNAL
#include "log.h"
#include "usb/usbus/cdc/acm.h"
#include "usb_board_reset.h"
#include "periph/pm.h"
#ifndef RESET_IN_BOOTLOADER_TRIGGER_BAUDRATE
#define RESET_IN_BOOTLOADER_TRIGGER_BAUDRATE (1200U)
#endif
#ifndef RESET_IN_APPLICATION_TRIGGER_BAUDRATE
#define RESET_IN_APPLICATION_TRIGGER_BAUDRATE (600U)
#endif
void usb_board_reset_in_bootloader(void);
int usb_board_reset_coding_cb(usbus_cdcacm_device_t *cdcacm,
uint32_t baud, uint8_t bits,
uint8_t parity, uint8_t stop)
{
(void)cdcacm;
(void)bits;
(void)parity;
(void)stop;
switch (baud) {
case RESET_IN_BOOTLOADER_TRIGGER_BAUDRATE:
LOG_DEBUG("[cdc-acm-stdio] reset in bootloader");
usb_board_reset_in_bootloader();
break;
case RESET_IN_APPLICATION_TRIGGER_BAUDRATE:
LOG_DEBUG("[cdc-acm-stdio] reset in application");
usb_board_reset_in_application();
break;
default:
(void)baud;
break;
}
return 0;
}
void usb_board_reset_in_application(void)
{
pm_reboot();
while (1) {}
}