[Stylecheck] F0, F1, F4

There are remaining C99 comments.
This commit is contained in:
Frantisek Burian
2014-01-23 19:06:13 +01:00
parent 022cc475bf
commit 3f47411e24
22 changed files with 203 additions and 159 deletions

View File

@@ -31,7 +31,7 @@ static void clock_setup(void)
/* Enable clocks for USART2. */
rcc_periph_clock_enable(RCC_USART2);
/* Enable clocks for CRYP. */
rcc_periph_clock_enable(RCC_CRYP);
}
@@ -62,12 +62,12 @@ static void gpio_setup(void)
gpio_set_af(GPIOA, GPIO_AF7, GPIO2);
}
static uint64_t key[4] = {0x11223344,0x44556677,0x77889900, 0x99005522};
static uint64_t iv[4] = {0x01020304,0x02030405,0x09080706, 0x55245711};
static uint64_t key[4] = {0x11223344, 0x44556677, 0x77889900, 0x99005522};
static uint64_t iv[4] = {0x01020304, 0x02030405, 0x09080706, 0x55245711};
static uint8_t plaintext[8] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static uint8_t ciphertext[8] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static uint8_t plaintext2[8] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static uint8_t plaintext[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static uint8_t ciphertext[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static uint8_t plaintext2[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int main(void)
{
@@ -81,44 +81,45 @@ int main(void)
/* Blink the LED (PD12) on the board with every transmitted byte. */
while (1) {
gpio_toggle(GPIOD, GPIO12); /* LED on/off */
/* encode the plaintext message into ciphertext */
crypto_set_key(CRYPTO_KEY_128BIT,key);
crypto_set_key(CRYPTO_KEY_128BIT, key);
crypto_set_iv(iv); /* only in CBC or CTR mode */
crypto_set_datatype(CRYPTO_DATA_32BIT);
crypto_set_algorithm(ENCRYPT_DES_ECB);
crypto_start();
crypto_process_block((uint32_t*)plaintext,
(uint32_t*)ciphertext,
crypto_process_block((uint32_t *)plaintext,
(uint32_t *)ciphertext,
8 / sizeof(uint32_t));
crypto_stop();
/* decode the previously encoded message
from ciphertext to plaintext2 */
crypto_set_key(CRYPTO_KEY_128BIT,key);
crypto_set_key(CRYPTO_KEY_128BIT, key);
crypto_set_iv(iv); /* only in CBC or CTR mode */
crypto_set_datatype(CRYPTO_DATA_32BIT);
crypto_set_algorithm(DECRYPT_DES_ECB);
crypto_start();
crypto_process_block((uint32_t*)ciphertext,
(uint32_t*)plaintext2,
crypto_process_block((uint32_t *)ciphertext,
(uint32_t *)plaintext2,
8 / sizeof(uint32_t));
crypto_stop();
crypto_stop();
/* compare the two plaintexts if they are same */
iserr = 0;
for (i=0; i<8; i++)
{
if (plaintext[i] != plaintext2[i])
for (i = 0; i < 8; i++) {
if (plaintext[i] != plaintext2[i]) {
iserr = true;
}
}
if (iserr)
gpio_toggle(GPIOD,GPIO12); /* something went wrong. */
if (iserr) {
gpio_toggle(GPIOD, GPIO12); /* something went wrong. */
}
}
return 0;

View File

@@ -137,8 +137,8 @@ int main(void)
dac_setup();
/* green led for ticking */
gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_GREEN_PIN);
gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
LED_DISCO_GREEN_PIN);
while (1) {
uint16_t input_adc0 = read_adc_naiive(0);
@@ -148,9 +148,13 @@ int main(void)
uint16_t input_adc1 = read_adc_naiive(1);
printf("tick: %d: adc0= %u, target adc1=%d, adc1=%d\n",
j++, input_adc0, target, input_adc1);
gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); /* LED on/off */
for (i = 0; i < 1000000; i++) /* Wait a bit. */
/* LED on/off */
gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN);
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
__asm__("NOP");
}
}
return 0;

View File

@@ -64,12 +64,14 @@ int main(void)
/* Upon button press, blink more slowly. */
exti_line_state = GPIOA_IDR;
if ((exti_line_state & (1 << 0)) != 0) {
for (i = 0; i < 3000000; i++) /* Wait a bit. */
for (i = 0; i < 3000000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
for (i = 0; i < 3000000; i++) /* Wait a bit. */
for (i = 0; i < 3000000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
return 0;

View File

@@ -68,7 +68,8 @@ static void timer_setup(void)
timer_set_oc_mode(TIM2, TIM_OC1, TIM_OCM_TOGGLE);
timer_set_oc_value(TIM2, TIM_OC1, 500);
timer_disable_preload(TIM2);
/* Set the timer trigger output (for the DAC) to the channel 1 output compare */
/* Set the timer trigger output (for the DAC) to the channel 1 output
compare */
timer_set_master_mode(TIM2, TIM_CR2_MMS_COMPARE_OC1REF);
timer_enable_counter(TIM2);
}
@@ -86,8 +87,10 @@ static void dma_setup(void)
dma_set_peripheral_size(DMA1, DMA_STREAM5, DMA_SxCR_PSIZE_8BIT);
dma_enable_memory_increment_mode(DMA1, DMA_STREAM5);
dma_enable_circular_mode(DMA1, DMA_STREAM5);
dma_set_transfer_mode(DMA1, DMA_STREAM5, DMA_SxCR_DIR_MEM_TO_PERIPHERAL);
/* The register to target is the DAC1 8-bit right justified data register */
dma_set_transfer_mode(DMA1, DMA_STREAM5,
DMA_SxCR_DIR_MEM_TO_PERIPHERAL);
/* The register to target is the DAC1 8-bit right justified data
register */
dma_set_peripheral_address(DMA1, DMA_STREAM5, (uint32_t) &DAC_DHR8R1);
/* The array v[] is filled with the waveform data to be output */
dma_set_memory_address(DMA1, DMA_STREAM5, (uint32_t) waveform);
@@ -115,8 +118,7 @@ static void dac_setup(void)
void dma1_stream5_isr(void)
{
if (dma_get_interrupt_flag(DMA1, DMA_STREAM5, DMA_TCIF))
{
if (dma_get_interrupt_flag(DMA1, DMA_STREAM5, DMA_TCIF)) {
dma_clear_interrupt_flags(DMA1, DMA_STREAM5, DMA_TCIF);
/* Toggle PC1 just to keep aware of activity and frequency. */
gpio_toggle(GPIOC, GPIO1);
@@ -129,13 +131,18 @@ int main(void)
/* Fill the array with funky waveform data */
/* This is for dual channel 8-bit right aligned */
uint16_t i, x;
for (i=0; i<256; i++)
{
if (i<10) x=10;
else if (i<121) x=10+((i*i)>>7);
else if (i<170) x=i/2;
else if (i<246) x=i+(80-i/2);
else x=10;
for (i = 0; i < 256; i++) {
if (i < 10) {
x = 10;
} else if (i < 121) {
x = 10 + ((i*i) >> 7);
} else if (i < 170) {
x = i/2;
} else if (i < 246) {
x = i + (80 - i/2);
} else {
x = 10;
}
waveform[i] = x;
}
clock_setup();
@@ -144,9 +151,7 @@ int main(void)
dma_setup();
dac_setup();
while (1) {
}
while (1);
return 0;
}

View File

@@ -52,8 +52,9 @@ int main(void)
while (1) {
/* Toggle LEDs. */
gpio_toggle(GPIOD, GPIO12 | GPIO13 | GPIO14 | GPIO15);
for (i = 0; i < 6000000; i++) /* Wait a bit. */
for (i = 0; i < 6000000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
return 0;

View File

@@ -70,15 +70,15 @@ static char color[maxIter+1] = " .:++xxXXX%%%%%%################";
/* Main mandelbrot calculation */
static int iterate(float px, float py)
{
int it=0;
float x=0,y=0;
while(it<maxIter)
{
int it = 0;
float x = 0, y = 0;
while (it < maxIter) {
float nx = x*x;
float ny = y*y;
if( (nx + ny) > 4 )
if ((nx + ny) > 4) {
return it;
// Zn+1 = Zn^2 + P
}
/* Zn+1 = Zn^2 + P */
y = 2*x*y + py;
x = nx - ny + px;
it++;
@@ -88,12 +88,10 @@ static int iterate(float px, float py)
static void mandel(float cX, float cY, float scale)
{
int x,y;
for(x=-60;x<60;x++)
{
for(y=-50;y<50;y++)
{
int i = iterate(cX+x*scale, cY+y*scale);
int x, y;
for (x = -60; x < 60; x++) {
for (y = -50; y < 50; y++) {
int i = iterate(cX + x*scale, cY + y*scale);
usart_send_blocking(USART2, color[i]);
}
usart_send_blocking(USART2, '\r');
@@ -111,8 +109,8 @@ int main(void)
while (1) {
/* Blink the LED (PD12) on the board with each fractal drawn. */
gpio_toggle(GPIOD, GPIO12); /* LED on/off */
mandel(centerX,centerY,scale); /* draw mandelbrot */
gpio_toggle(GPIOD, GPIO12); /* LED on/off */
mandel(centerX, centerY, scale); /* draw mandelbrot */
/* Change scale and center */
centerX += 0.175f * scale;

View File

@@ -48,23 +48,24 @@ int main(void)
/* Manually: */
// GPIOD_BSRR = GPIO12; /* LED off */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
// GPIOD_BRR = GPIO12; /* LED on */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
/* Using API functions gpio_set()/gpio_clear(): */
// gpio_set(GPIOD, GPIO12); /* LED off */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
// gpio_clear(GPIOD, GPIO12); /* LED on */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
/* Using API function gpio_toggle(): */
gpio_toggle(GPIOD, GPIO12); /* LED on/off */
for (i = 0; i < 1000000; i++) /* Wait a bit. */
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
return 0;

View File

@@ -15,7 +15,6 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libopencm3/cm3/common.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
@@ -37,8 +36,9 @@ static void rng_setup(void)
/* Enable interupt */
/* Set the IE bit in the RNG_CR register. */
RNG_CR |= RNG_CR_IE;
/* Enable the random number generation by setting the RNGEN bit in the RNG_CR
register. This activates the analog part, the RNG_LFSR and the error detector.
/* Enable the random number generation by setting the RNGEN bit in
the RNG_CR register. This activates the analog part, the RNG_LFSR
and the error detector.
*/
RNG_CR |= RNG_CR_RNGEN;
}
@@ -46,43 +46,51 @@ static void rng_setup(void)
static void gpio_setup(void)
{
/* Setup onboard led */
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12 | GPIO13);
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
GPIO12 | GPIO13);
}
/* Tried to folow the guidelines in the stm32f4 user manual.*/
static uint32_t random_int(void)
{
static uint32_t last_value=0;
static uint32_t new_value=0;
static uint32_t last_value;
static uint32_t new_value;
uint32_t error_bits = 0;
error_bits = RNG_SR_SEIS | RNG_SR_CEIS;
while (new_value==last_value) {
while (new_value == last_value) {
/* Check for error flags and if data is ready. */
if ( ((RNG_SR & error_bits) == 0) && ( (RNG_SR & RNG_SR_DRDY) == 1 ) )
new_value=RNG_DR;
if (((RNG_SR & error_bits) == 0) &&
((RNG_SR & RNG_SR_DRDY) == 1)) {
new_value = RNG_DR;
}
}
last_value=new_value;
last_value = new_value;
return new_value;
}
int main(void)
{
int i,j;
int i, j;
rcc_setup();
gpio_setup();
rng_setup();
while(1){
while (1) {
uint32_t rnd;
rnd = random_int();
for(i=0;i!=32;++i){
if ( (rnd & (1 << i))!=0 )
for (i = 0; i != 32; i++) {
if ((rnd & (1 << i)) != 0) {
gpio_set(GPIOD, GPIO12);
else
} else {
gpio_clear(GPIOD, GPIO12);
}
/* Delay */
for(j=0;j!=5000000;++j)
for (j = 0; j != 5000000; j++) {
__asm__("nop");
}
}
}
}
}

View File

@@ -27,22 +27,22 @@
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/cm3/systick.h>
void msleep(uint32_t);
/* monotonically increasing number of milliseconds from reset
* overflows every 49 days if you're wondering
*/
volatile uint32_t system_millis;
/* Called when systick fires */
void sys_tick_handler(void) {
void sys_tick_handler(void)
{
system_millis++;
}
/* sleep for delay milliseconds */
void msleep(uint32_t delay) {
static void msleep(uint32_t delay)
{
uint32_t wake = system_millis + delay;
while (wake > system_millis) ;
while (wake > system_millis;
}
/* Set up a timer to create 1mS ticks. */
@@ -68,8 +68,8 @@ static void clock_setup(void)
static void gpio_setup(void)
{
/* Set GPIO11-15 (in GPIO port D) to 'output push-pull'. */
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
GPIO_PUPD_NONE, GPIO11 | GPIO12 | GPIO13 | GPIO14 | GPIO15);
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
GPIO11 | GPIO12 | GPIO13 | GPIO14 | GPIO15);
}
int main(void)

View File

@@ -75,8 +75,9 @@ int main(void)
usart_send_blocking(USART2, '\r');
usart_send_blocking(USART2, '\n');
}
for (i = 0; i < 3000000; i++) /* Wait a bit. */
for (i = 0; i < 3000000; i++) { /* Wait a bit. */
__asm__("NOP");
}
}
return 0;

View File

@@ -53,7 +53,7 @@ static const struct usb_endpoint_descriptor comm_endp[] = {{
.bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
.wMaxPacketSize = 16,
.bInterval = 255,
}};
} };
static const struct usb_endpoint_descriptor data_endp[] = {{
.bLength = USB_DT_ENDPOINT_SIZE,
@@ -69,7 +69,7 @@ static const struct usb_endpoint_descriptor data_endp[] = {{
.bmAttributes = USB_ENDPOINT_ATTR_BULK,
.wMaxPacketSize = 64,
.bInterval = 1,
}};
} };
static const struct {
struct usb_cdc_header_descriptor header;
@@ -121,7 +121,7 @@ static const struct usb_interface_descriptor comm_iface[] = {{
.extra = &cdcacm_functional_descriptors,
.extralen = sizeof(cdcacm_functional_descriptors)
}};
} };
static const struct usb_interface_descriptor data_iface[] = {{
.bLength = USB_DT_INTERFACE_SIZE,
@@ -135,7 +135,7 @@ static const struct usb_interface_descriptor data_iface[] = {{
.iInterface = 0,
.endpoint = data_endp,
}};
} };
static const struct usb_interface ifaces[] = {{
.num_altsetting = 1,
@@ -143,7 +143,7 @@ static const struct usb_interface ifaces[] = {{
}, {
.num_altsetting = 1,
.altsetting = data_iface,
}};
} };
static const struct usb_config_descriptor config = {
.bLength = USB_DT_CONFIGURATION_SIZE,
@@ -158,7 +158,7 @@ static const struct usb_config_descriptor config = {
.interface = ifaces,
};
static const char *usb_strings[] = {
static const char *const usb_strings[] = {
"Black Sphere Technologies",
"CDC-ACM Demo",
"DEMO",
@@ -167,8 +167,9 @@ static const char *usb_strings[] = {
/* Buffer to be used for control requests. */
uint8_t usbd_control_buffer[128];
static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf,
uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
static int cdcacm_control_request(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf, uint16_t *len,
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
{
(void)complete;
(void)buf;
@@ -184,8 +185,9 @@ static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *
return 1;
}
case USB_CDC_REQ_SET_LINE_CODING:
if (*len < sizeof(struct usb_cdc_line_coding))
if (*len < sizeof(struct usb_cdc_line_coding)) {
return 0;
}
return 1;
}
@@ -200,8 +202,7 @@ static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep)
int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64);
if (len) {
while (usbd_ep_write_packet(usbd_dev, 0x82, buf, len) == 0)
;
while (usbd_ep_write_packet(usbd_dev, 0x82, buf, len) == 0);
}
gpio_toggle(GPIOC, GPIO5);
@@ -211,7 +212,8 @@ static void cdcacm_set_config(usbd_device *usbd_dev, uint16_t wValue)
{
(void)wValue;
usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64,
cdcacm_data_rx_cb);
usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
@@ -235,9 +237,13 @@ int main(void)
GPIO9 | GPIO11 | GPIO12);
gpio_set_af(GPIOA, GPIO_AF10, GPIO9 | GPIO11 | GPIO12);
usbd_dev = usbd_init(&otgfs_usb_driver, &dev, &config, usb_strings, 3, usbd_control_buffer, sizeof(usbd_control_buffer));
usbd_dev = usbd_init(&otgfs_usb_driver, &dev, &config,
usb_strings, 3,
usbd_control_buffer, sizeof(usbd_control_buffer));
usbd_register_set_config_callback(usbd_dev, cdcacm_set_config);
while (1)
while (1) {
usbd_poll(usbd_dev);
}
}